www.mooseframework.org
UpdateDisplacedMeshThread.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 
17 #include "AllNodesSendListThread.h"
18 #include "DisplacedProblem.h"
19 #include "MooseMesh.h"
20 
21 #include "libmesh/numeric_vector.h"
22 
24  DisplacedProblem & displaced_problem)
25  : ThreadedNodeLoop<NodeRange, NodeRange::const_iterator>(fe_problem),
26  _displaced_problem(displaced_problem),
27  _ref_mesh(_displaced_problem.refMesh()),
28  _nl_soln(*_displaced_problem._nl_solution),
29  _aux_soln(*_displaced_problem._aux_solution),
30  _nl_ghosted_soln(NumericVector<Number>::build(_nl_soln.comm()).release()),
31  _aux_ghosted_soln(NumericVector<Number>::build(_aux_soln.comm()).release()),
32  _var_nums(0),
33  _var_nums_directions(0),
34  _aux_var_nums(0),
35  _aux_var_nums_directions(0),
36  _num_var_nums(0),
37  _num_aux_var_nums(0),
38  _nonlinear_system_number(_displaced_problem._displaced_nl.sys().number()),
39  _aux_system_number(_displaced_problem._displaced_aux.sys().number())
40 {
41  this->init();
42 }
43 
45  Threads::split split)
46  : ThreadedNodeLoop<NodeRange, NodeRange::const_iterator>(x, split),
49  _nl_soln(x._nl_soln),
61 {
62 }
63 
64 void
66 {
67  std::vector<std::string> & displacement_variables = _displaced_problem._displacements;
68  unsigned int num_displacements = displacement_variables.size();
69 
70  _var_nums.clear();
71  _var_nums_directions.clear();
72 
73  _aux_var_nums.clear();
75 
76  for (unsigned int i = 0; i < num_displacements; i++)
77  {
78  std::string displacement_name = displacement_variables[i];
79 
80  if (_displaced_problem._displaced_nl.sys().has_variable(displacement_name))
81  {
82  _var_nums.push_back(
83  _displaced_problem._displaced_nl.sys().variable_number(displacement_name));
84  _var_nums_directions.push_back(i);
85  }
86  else if (_displaced_problem._displaced_aux.sys().has_variable(displacement_name))
87  {
88  _aux_var_nums.push_back(
89  _displaced_problem._displaced_aux.sys().variable_number(displacement_name));
90  _aux_var_nums_directions.push_back(i);
91  }
92  else
93  mooseError("Undefined variable '", displacement_name, "' used for displacements!");
94  }
95 
96  _num_var_nums = _var_nums.size();
98 
99  ConstNodeRange node_range(_ref_mesh.getMesh().nodes_begin(), _ref_mesh.getMesh().nodes_end());
100 
101  {
102  AllNodesSendListThread nl_send_list(
104  Threads::parallel_reduce(node_range, nl_send_list);
105  nl_send_list.unique();
106  _nl_ghosted_soln->init(
107  _nl_soln.size(), _nl_soln.local_size(), nl_send_list.send_list(), GHOSTED);
108  _nl_soln.localize(*_nl_ghosted_soln, nl_send_list.send_list());
109  }
110 
111  {
112  AllNodesSendListThread aux_send_list(
114  Threads::parallel_reduce(node_range, aux_send_list);
115  aux_send_list.unique();
116  _aux_ghosted_soln->init(
117  _aux_soln.size(), _aux_soln.local_size(), aux_send_list.send_list(), GHOSTED);
118  _aux_soln.localize(*_aux_ghosted_soln, aux_send_list.send_list());
119  }
120 }
121 
122 void
123 UpdateDisplacedMeshThread::onNode(NodeRange::const_iterator & nd)
124 {
125  Node & displaced_node = *(*nd);
126 
127  Node & reference_node = _ref_mesh.nodeRef(displaced_node.id());
128 
129  for (unsigned int i = 0; i < _num_var_nums; i++)
130  {
131  unsigned int direction = _var_nums_directions[i];
132  if (reference_node.n_dofs(_nonlinear_system_number, _var_nums[i]) > 0)
133  displaced_node(direction) =
134  reference_node(direction) +
135  (*_nl_ghosted_soln)(reference_node.dof_number(_nonlinear_system_number, _var_nums[i], 0));
136  }
137 
138  for (unsigned int i = 0; i < _num_aux_var_nums; i++)
139  {
140  unsigned int direction = _aux_var_nums_directions[i];
141  if (reference_node.n_dofs(_aux_system_number, _aux_var_nums[i]) > 0)
142  displaced_node(direction) =
143  reference_node(direction) +
144  (*_aux_ghosted_soln)(reference_node.dof_number(_aux_system_number, _aux_var_nums[i], 0));
145  }
146 }
147 
148 void
150 {
151 }
std::vector< unsigned int > _aux_var_nums_directions
virtual TransientExplicitSystem & sys()
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void join(const UpdateDisplacedMeshThread &)
DisplacedSystem _displaced_aux
DisplacedSystem _displaced_nl
const NumericVector< Number > & _nl_soln
static PetscErrorCode Vec x
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::vector< unsigned int > _var_nums
const NumericVector< Number > & _aux_soln
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
std::shared_ptr< NumericVector< Number > > _nl_ghosted_soln
std::vector< std::string > _displacements
UpdateDisplacedMeshThread(FEProblemBase &fe_problem, DisplacedProblem &displaced_problem)
std::shared_ptr< NumericVector< Number > > _aux_ghosted_soln
std::vector< unsigned int > _var_nums_directions
std::vector< unsigned int > _aux_var_nums
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:398
MPI_Comm comm
virtual void onNode(NodeRange::const_iterator &nd) override
Called for each node.