https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
DisplacedProblem::UpdateDisplacedMeshThread Class Reference

#include <DisplacedProblem.h>

Inheritance diagram for DisplacedProblem::UpdateDisplacedMeshThread:
[legend]

Public Member Functions

 UpdateDisplacedMeshThread (FEProblemBase &fe_problem, DisplacedProblem &displaced_problem)
 
 UpdateDisplacedMeshThread (UpdateDisplacedMeshThread &x, Threads::split split)
 
virtual void onNode (NodeRange::const_iterator &nd) override
 
void join (const UpdateDisplacedMeshThread &y)
 
bool hasDisplacement ()
 Whether the displaced mesh is modified by the latest call to operator() More...
 
void operator() (const NodeRange &range)
 
virtual void pre ()
 Called before the node range loop. More...
 
virtual void post ()
 Called after the node range loop. More...
 
virtual void onNode (NodeRange::const_iterator &node_it)
 Called for each node. More...
 
virtual void postNode (NodeRange::const_iterator &node_it)
 Called after the node assembly is done (including surface assembling) More...
 
virtual void caughtMooseException (MooseException &e)
 Called if a MooseException is caught anywhere during the computation. More...
 
virtual bool keepGoing ()
 Whether or not the loop should continue. More...
 

Protected Member Functions

void init ()
 
virtual void printGeneralExecutionInformation () const
 Print information about the loop, mostly order of execution of objects. More...
 

Protected Attributes

DisplacedProblem_displaced_problem
 Diplaced problem. More...
 
MooseMesh_ref_mesh
 Original mesh. More...
 
const std::vector< const NumericVector< Number > * > & _nl_soln
 Solution vectors of the nonlinear systems on the displaced problem. More...
 
const NumericVector< Number > & _aux_soln
 Solution vector of the auxliary system on the displaced problem. More...
 
std::map< unsigned int, std::pair< const NumericVector< Number > *, std::shared_ptr< NumericVector< Number > > > > _sys_to_nonghost_and_ghost_soln
 
FEProblemBase_fe_problem
 
THREAD_ID _tid
 

Private Attributes

std::map< unsigned int, std::pair< std::vector< unsigned int >, std::vector< unsigned int > > > _sys_to_var_num_and_direction
 To locate the system numbers, variable numbers of all displacement variables. More...
 
bool _has_displacement
 A flag to be set by operator() for indicating whether the displaced mesh is indeed modified. More...
 

Detailed Description

Definition at line 410 of file DisplacedProblem.h.

Constructor & Destructor Documentation

◆ UpdateDisplacedMeshThread() [1/2]

DisplacedProblem::UpdateDisplacedMeshThread::UpdateDisplacedMeshThread ( FEProblemBase fe_problem,
DisplacedProblem displaced_problem 
)

Definition at line 1418 of file DisplacedProblem.C.

1425  _has_displacement(false)
1426 {
1427  this->init();
1428 }
const NumericVector< Number > & _aux_soln
Solution vector of the auxliary system on the displaced problem.
std::shared_ptr< DisplacedProblem > displaced_problem
bool _has_displacement
A flag to be set by operator() for indicating whether the displaced mesh is indeed modified...
std::vector< const NumericVector< Number > * > _nl_solution
The nonlinear system solutions.
const NumericVector< Number > * _aux_solution
The auxiliary system solution.
DisplacedProblem & _displaced_problem
Diplaced problem.
MooseMesh & refMesh()
const std::vector< const NumericVector< Number > * > & _nl_soln
Solution vectors of the nonlinear systems on the displaced problem.

◆ UpdateDisplacedMeshThread() [2/2]

DisplacedProblem::UpdateDisplacedMeshThread::UpdateDisplacedMeshThread ( UpdateDisplacedMeshThread x,
Threads::split  split 
)

Definition at line 1430 of file DisplacedProblem.C.

1433  _displaced_problem(x._displaced_problem),
1434  _ref_mesh(x._ref_mesh),
1435  _nl_soln(x._nl_soln),
1436  _aux_soln(x._aux_soln),
1437  _sys_to_nonghost_and_ghost_soln(x._sys_to_nonghost_and_ghost_soln),
1438  _sys_to_var_num_and_direction(x._sys_to_var_num_and_direction),
1439  _has_displacement(x._has_displacement)
1440 {
1441 }
const NumericVector< Number > & _aux_soln
Solution vector of the auxliary system on the displaced problem.
std::map< unsigned int, std::pair< std::vector< unsigned int >, std::vector< unsigned int > > > _sys_to_var_num_and_direction
To locate the system numbers, variable numbers of all displacement variables.
std::map< unsigned int, std::pair< const NumericVector< Number > *, std::shared_ptr< NumericVector< Number > > > > _sys_to_nonghost_and_ghost_soln
bool _has_displacement
A flag to be set by operator() for indicating whether the displaced mesh is indeed modified...
DisplacedProblem & _displaced_problem
Diplaced problem.
tbb::split split
const std::vector< const NumericVector< Number > * > & _nl_soln
Solution vectors of the nonlinear systems on the displaced problem.

Member Function Documentation

◆ caughtMooseException()

virtual void ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::caughtMooseException ( MooseException e)
inlinevirtualinherited

Called if a MooseException is caught anywhere during the computation.

The single input parameter taken is a MooseException object.

Definition at line 56 of file ThreadedNodeLoop.h.

57  {
58  Threads::spin_mutex::scoped_lock lock(threaded_node_mutex);
59 
60  std::string what(e.what());
62  };
virtual const char * what() const
Get out the error message.
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class...
static Threads::spin_mutex threaded_node_mutex

◆ hasDisplacement()

bool DisplacedProblem::UpdateDisplacedMeshThread::hasDisplacement ( )
inline

Whether the displaced mesh is modified by the latest call to operator()

Definition at line 428 of file DisplacedProblem.h.

Referenced by DisplacedProblem::updateMesh().

429  {
430  mooseAssert(!Threads::in_threads,
431  "This function requires a MPI all-gathering operation that cannot be in a "
432  "threaded scope.");
434  return _has_displacement;
435  }
const Parallel::Communicator & comm() const
bool _has_displacement
A flag to be set by operator() for indicating whether the displaced mesh is indeed modified...
void max(const T &r, T &o, Request &req) const

◆ init()

void DisplacedProblem::UpdateDisplacedMeshThread::init ( )
protected

Definition at line 1444 of file DisplacedProblem.C.

Referenced by UpdateDisplacedMeshThread().

1445 {
1446  std::vector<std::string> & displacement_variables = _displaced_problem._displacements;
1447  unsigned int num_displacements = displacement_variables.size();
1448  auto & es = _displaced_problem.es();
1449 
1452 
1453  for (unsigned int i = 0; i < num_displacements; i++)
1454  {
1455  std::string displacement_name = displacement_variables[i];
1456 
1457  for (const auto sys_num : make_range(es.n_systems()))
1458  {
1459  auto & sys = es.get_system(sys_num);
1460  if (sys.has_variable(displacement_name))
1461  {
1462  auto & val = _sys_to_var_num_and_direction[sys.number()];
1463  val.first.push_back(sys.variable_number(displacement_name));
1464  val.second.push_back(i);
1465  break;
1466  }
1467  }
1468  }
1469 
1470  for (const auto & pr : _sys_to_var_num_and_direction)
1471  {
1472  auto & sys = es.get_system(pr.first);
1473  mooseAssert(sys.number() <= _nl_soln.size(),
1474  "The system number should always be less than or equal to the number of nonlinear "
1475  "systems. If it is equal, then this system is the auxiliary system");
1476  const NumericVector<Number> * const nonghost_soln =
1477  sys.number() < _nl_soln.size() ? _nl_soln[sys.number()] : &_aux_soln;
1479  sys.number(),
1480  std::make_pair(nonghost_soln,
1481  NumericVector<Number>::build(nonghost_soln->comm()).release()));
1482  }
1483 
1484  ConstNodeRange node_range(_ref_mesh.getMesh().nodes_begin(), _ref_mesh.getMesh().nodes_end());
1485 
1486  for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1487  {
1488  auto & sys = es.get_system(sys_num);
1489  AllNodesSendListThread send_list(
1490  this->_fe_problem, _ref_mesh, var_num_and_direction.first, sys);
1491  Threads::parallel_reduce(node_range, send_list);
1492  send_list.unique();
1493  auto & [soln, ghost_soln] = libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num);
1494  ghost_soln->init(
1495  soln->size(), soln->local_size(), send_list.send_list(), true, libMesh::GHOSTED);
1496  soln->localize(*ghost_soln, send_list.send_list());
1497  }
1498 
1499  _has_displacement = false;
1500 }
const NumericVector< Number > & _aux_soln
Solution vector of the auxliary system on the displaced problem.
unsigned int n_systems() const
void parallel_reduce(const Range &range, Body &body, const Partitioner &)
virtual EquationSystems & es() override
std::map< unsigned int, std::pair< std::vector< unsigned int >, std::vector< unsigned int > > > _sys_to_var_num_and_direction
To locate the system numbers, variable numbers of all displacement variables.
std::map< unsigned int, std::pair< const NumericVector< Number > *, std::shared_ptr< NumericVector< Number > > > > _sys_to_nonghost_and_ghost_soln
const T_sys & get_system(std::string_view name) const
bool _has_displacement
A flag to be set by operator() for indicating whether the displaced mesh is indeed modified...
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3443
std::vector< std::string > _displacements
DisplacedProblem & _displaced_problem
Diplaced problem.
IntRange< T > make_range(T beg, T end)
const std::vector< const NumericVector< Number > * > & _nl_soln
Solution vectors of the nonlinear systems on the displaced problem.

◆ join()

void DisplacedProblem::UpdateDisplacedMeshThread::join ( const UpdateDisplacedMeshThread y)
inline

Definition at line 419 of file DisplacedProblem.h.

420  {
421  if (y._has_displacement)
422  _has_displacement = true;
423  }
bool _has_displacement
A flag to be set by operator() for indicating whether the displaced mesh is indeed modified...

◆ keepGoing()

virtual bool ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::keepGoing ( )
inlinevirtualinherited

Whether or not the loop should continue.

Returns
true to keep going, false to stop.

Definition at line 69 of file ThreadedNodeLoop.h.

69 { return !_fe_problem.hasException(); }
virtual bool hasException()
Whether or not an exception has occurred.

◆ onNode() [1/2]

Called for each node.

Definition at line 136 of file ThreadedNodeLoop.h.

137 {
138 }

◆ onNode() [2/2]

void DisplacedProblem::UpdateDisplacedMeshThread::onNode ( NodeRange::const_iterator nd)
overridevirtual

Definition at line 1503 of file DisplacedProblem.C.

1504 {
1505  Node & displaced_node = *(*nd);
1506 
1507  Node & reference_node = _ref_mesh.nodeRef(displaced_node.id());
1508 
1509  for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1510  {
1511  auto & var_numbers = var_num_and_direction.first;
1512  auto & directions = var_num_and_direction.second;
1513  for (const auto i : index_range(var_numbers))
1514  {
1515  const auto direction = directions[i];
1516  if (reference_node.n_dofs(sys_num, var_numbers[i]) > 0)
1517  {
1518  Real coord = reference_node(direction) +
1519  (*libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num).second)(
1520  reference_node.dof_number(sys_num, var_numbers[i], 0));
1521  if (displaced_node(direction) != coord)
1522  {
1523  displaced_node(direction) = coord;
1524  _has_displacement = true;
1525  }
1526  }
1527  }
1528  }
1529 }
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
std::map< unsigned int, std::pair< std::vector< unsigned int >, std::vector< unsigned int > > > _sys_to_var_num_and_direction
To locate the system numbers, variable numbers of all displacement variables.
std::map< unsigned int, std::pair< const NumericVector< Number > *, std::shared_ptr< NumericVector< Number > > > > _sys_to_nonghost_and_ghost_soln
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:831
bool _has_displacement
A flag to be set by operator() for indicating whether the displaced mesh is indeed modified...
unsigned int n_dofs(const unsigned int s, const unsigned int var=libMesh::invalid_uint) const
dof_id_type id() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto index_range(const T &sizable)

◆ operator()()

void ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::operator() ( const NodeRange range)
inherited

Definition at line 94 of file ThreadedNodeLoop.h.

95 {
96  try
97  {
98  ParallelUniqueId puid;
99  _tid = puid.id;
100 
101  pre();
103 
104  for (IteratorType nd = range.begin(); nd != range.end(); ++nd)
105  {
106  if (!keepGoing())
107  break;
108 
109  onNode(nd);
110 
111  postNode(nd);
112  }
113 
114  post();
115  }
116  catch (MooseException & e)
117  {
119  }
120 }
virtual void printGeneralExecutionInformation() const
Print information about the loop, mostly order of execution of objects.
virtual void caughtMooseException(MooseException &e)
Called if a MooseException is caught anywhere during the computation.
virtual bool keepGoing()
Whether or not the loop should continue.
const_iterator end() const
Provides a way for users to bail out of the current solve.
virtual void pre()
Called before the node range loop.
const_iterator begin() const
virtual void post()
Called after the node range loop.
virtual void postNode(NodeRange::const_iterator &node_it)
Called after the node assembly is done (including surface assembling)
virtual void onNode(NodeRange::const_iterator &node_it)
Called for each node.

◆ post()

void ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::post ( )
virtualinherited

Called after the node range loop.

Definition at line 130 of file ThreadedNodeLoop.h.

131 {
132 }

◆ postNode()

void ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::postNode ( NodeRange::const_iterator node_it)
virtualinherited

Called after the node assembly is done (including surface assembling)

Parameters
node- active node

Definition at line 142 of file ThreadedNodeLoop.h.

143 {
144 }

◆ pre()

void ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::pre ( )
virtualinherited

Called before the node range loop.

Definition at line 124 of file ThreadedNodeLoop.h.

125 {
126 }

◆ printGeneralExecutionInformation()

virtual void ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::printGeneralExecutionInformation ( ) const
inlineprotectedvirtualinherited

Print information about the loop, mostly order of execution of objects.

Definition at line 76 of file ThreadedNodeLoop.h.

76 {}

Member Data Documentation

◆ _aux_soln

const NumericVector<Number>& DisplacedProblem::UpdateDisplacedMeshThread::_aux_soln
protected

Solution vector of the auxliary system on the displaced problem.

Definition at line 447 of file DisplacedProblem.h.

◆ _displaced_problem

DisplacedProblem& DisplacedProblem::UpdateDisplacedMeshThread::_displaced_problem
protected

Diplaced problem.

Definition at line 441 of file DisplacedProblem.h.

◆ _fe_problem

FEProblemBase& ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::_fe_problem
protectedinherited

Definition at line 72 of file ThreadedNodeLoop.h.

◆ _has_displacement

bool DisplacedProblem::UpdateDisplacedMeshThread::_has_displacement
private

A flag to be set by operator() for indicating whether the displaced mesh is indeed modified.

Definition at line 463 of file DisplacedProblem.h.

Referenced by join().

◆ _nl_soln

const std::vector<const NumericVector<Number> *>& DisplacedProblem::UpdateDisplacedMeshThread::_nl_soln
protected

Solution vectors of the nonlinear systems on the displaced problem.

Definition at line 445 of file DisplacedProblem.h.

◆ _ref_mesh

MooseMesh& DisplacedProblem::UpdateDisplacedMeshThread::_ref_mesh
protected

Original mesh.

Definition at line 443 of file DisplacedProblem.h.

◆ _sys_to_nonghost_and_ghost_soln

std::map<unsigned int, std::pair<const NumericVector<Number> *, std::shared_ptr<NumericVector<Number> > > > DisplacedProblem::UpdateDisplacedMeshThread::_sys_to_nonghost_and_ghost_soln
protected

Definition at line 454 of file DisplacedProblem.h.

◆ _sys_to_var_num_and_direction

std::map<unsigned int, std::pair<std::vector<unsigned int>, std::vector<unsigned int> > > DisplacedProblem::UpdateDisplacedMeshThread::_sys_to_var_num_and_direction
private

To locate the system numbers, variable numbers of all displacement variables.

Definition at line 459 of file DisplacedProblem.h.

◆ _tid

Definition at line 73 of file ThreadedNodeLoop.h.


The documentation for this class was generated from the following files: