www.mooseframework.org
UpdateDisplacedMeshThread.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 #include "AllNodesSendListThread.h"
13 #include "DisplacedProblem.h"
14 #include "MooseMesh.h"
15 
16 #include "libmesh/numeric_vector.h"
17 #include "libmesh/transient_system.h"
18 #include "libmesh/explicit_system.h"
19 
21  DisplacedProblem & displaced_problem)
22  : ThreadedNodeLoop<NodeRange, NodeRange::const_iterator>(fe_problem),
23  _displaced_problem(displaced_problem),
24  _ref_mesh(_displaced_problem.refMesh()),
25  _nl_soln(*_displaced_problem._nl_solution),
26  _aux_soln(*_displaced_problem._aux_solution),
27  _nl_ghosted_soln(NumericVector<Number>::build(_nl_soln.comm()).release()),
28  _aux_ghosted_soln(NumericVector<Number>::build(_aux_soln.comm()).release()),
29  _var_nums(0),
30  _var_nums_directions(0),
31  _aux_var_nums(0),
32  _aux_var_nums_directions(0),
33  _num_var_nums(0),
34  _num_aux_var_nums(0),
35  _nonlinear_system_number(_displaced_problem._displaced_nl.sys().number()),
36  _aux_system_number(_displaced_problem._displaced_aux.sys().number())
37 {
38  this->init();
39 }
40 
43  : ThreadedNodeLoop<NodeRange, NodeRange::const_iterator>(x, split),
44  _displaced_problem(x._displaced_problem),
45  _ref_mesh(x._ref_mesh),
46  _nl_soln(x._nl_soln),
47  _aux_soln(x._aux_soln),
48  _nl_ghosted_soln(x._nl_ghosted_soln),
49  _aux_ghosted_soln(x._aux_ghosted_soln),
50  _var_nums(x._var_nums),
51  _var_nums_directions(x._var_nums_directions),
52  _aux_var_nums(x._aux_var_nums),
53  _aux_var_nums_directions(x._aux_var_nums_directions),
54  _num_var_nums(x._num_var_nums),
55  _num_aux_var_nums(x._num_aux_var_nums),
56  _nonlinear_system_number(x._nonlinear_system_number),
57  _aux_system_number(x._aux_system_number)
58 {
59 }
60 
61 void
63 {
64  std::vector<std::string> & displacement_variables = _displaced_problem._displacements;
65  unsigned int num_displacements = displacement_variables.size();
66 
67  _var_nums.clear();
68  _var_nums_directions.clear();
69 
70  _aux_var_nums.clear();
72 
73  for (unsigned int i = 0; i < num_displacements; i++)
74  {
75  std::string displacement_name = displacement_variables[i];
76 
77  if (_displaced_problem._displaced_nl.sys().has_variable(displacement_name))
78  {
79  _var_nums.push_back(
80  _displaced_problem._displaced_nl.sys().variable_number(displacement_name));
81  _var_nums_directions.push_back(i);
82  }
83  else if (_displaced_problem._displaced_aux.sys().has_variable(displacement_name))
84  {
85  _aux_var_nums.push_back(
86  _displaced_problem._displaced_aux.sys().variable_number(displacement_name));
87  _aux_var_nums_directions.push_back(i);
88  }
89  else
90  mooseError("Undefined variable '", displacement_name, "' used for displacements!");
91  }
92 
93  _num_var_nums = _var_nums.size();
95 
96  ConstNodeRange node_range(_ref_mesh.getMesh().nodes_begin(), _ref_mesh.getMesh().nodes_end());
97 
98  {
99  AllNodesSendListThread nl_send_list(
101  Threads::parallel_reduce(node_range, nl_send_list);
102  nl_send_list.unique();
103  _nl_ghosted_soln->init(
104  _nl_soln.size(), _nl_soln.local_size(), nl_send_list.send_list(), true, GHOSTED);
105  _nl_soln.localize(*_nl_ghosted_soln, nl_send_list.send_list());
106  }
107 
108  {
109  AllNodesSendListThread aux_send_list(
111  Threads::parallel_reduce(node_range, aux_send_list);
112  aux_send_list.unique();
113  _aux_ghosted_soln->init(
114  _aux_soln.size(), _aux_soln.local_size(), aux_send_list.send_list(), true, GHOSTED);
115  _aux_soln.localize(*_aux_ghosted_soln, aux_send_list.send_list());
116  }
117 }
118 
119 void
120 UpdateDisplacedMeshThread::onNode(NodeRange::const_iterator & nd)
121 {
122  Node & displaced_node = *(*nd);
123 
124  Node & reference_node = _ref_mesh.nodeRef(displaced_node.id());
125 
126  for (unsigned int i = 0; i < _num_var_nums; i++)
127  {
128  unsigned int direction = _var_nums_directions[i];
129  if (reference_node.n_dofs(_nonlinear_system_number, _var_nums[i]) > 0)
130  displaced_node(direction) =
131  reference_node(direction) +
132  (*_nl_ghosted_soln)(reference_node.dof_number(_nonlinear_system_number, _var_nums[i], 0));
133  }
134 
135  for (unsigned int i = 0; i < _num_aux_var_nums; i++)
136  {
137  unsigned int direction = _aux_var_nums_directions[i];
138  if (reference_node.n_dofs(_aux_system_number, _aux_var_nums[i]) > 0)
139  displaced_node(direction) =
140  reference_node(direction) +
141  (*_aux_ghosted_soln)(reference_node.dof_number(_aux_system_number, _aux_var_nums[i], 0));
142  }
143 }
144 
145 void
147 {
148 }
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:207
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.
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:436
std::vector< unsigned int > _var_nums
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:736
const NumericVector< Number > & _aux_soln
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
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
MPI_Comm comm
virtual void onNode(NodeRange::const_iterator &nd) override
Called for each node.