https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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()
 
void operator() (const NodeRange &range)
 
virtual void pre ()
 Called before the node range loop.
 
virtual void post ()
 Called after the node range loop.
 
virtual void onNode (NodeRange::const_iterator &node_it)
 Called for each node.
 
virtual void postNode (NodeRange::const_iterator &node_it)
 Called after the node assembly is done (including surface assembling)
 
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.
 

Protected Member Functions

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

Protected Attributes

DisplacedProblem & _displaced_problem
 Diplaced problem.
 
MooseMesh & _ref_mesh
 Original mesh.
 
const std::vector< const NumericVector< Number > * > & _nl_soln
 Solution vectors of the nonlinear systems on the displaced problem.
 
const NumericVector< Number > & _aux_soln
 Solution vector of the auxliary system on the displaced problem.
 
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.
 
bool _has_displacement
 A flag to be set by operator() for indicating whether the displaced mesh is indeed modified.
 

Detailed Description

Definition at line 411 of file DisplacedProblem.h.

Constructor & Destructor Documentation

◆ UpdateDisplacedMeshThread() [1/2]

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

Definition at line 1419 of file DisplacedProblem.C.

1426 _has_displacement(false)
1427{
1428 this->init();
1429}
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.
const NumericVector< Number > & _aux_soln
Solution vector of the auxliary system on the displaced problem.
DisplacedProblem & _displaced_problem
Diplaced problem.
const std::vector< const NumericVector< Number > * > & _nl_soln
Solution vectors of the nonlinear systems on the displaced problem.
MooseMesh & refMesh()
std::vector< const NumericVector< Number > * > _nl_solution
The nonlinear system solutions.
const NumericVector< Number > * _aux_solution
The auxiliary system solution.

◆ UpdateDisplacedMeshThread() [2/2]

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

Definition at line 1431 of file DisplacedProblem.C.

1434 _displaced_problem(x._displaced_problem),
1435 _ref_mesh(x._ref_mesh),
1436 _nl_soln(x._nl_soln),
1437 _aux_soln(x._aux_soln),
1438 _sys_to_nonghost_and_ghost_soln(x._sys_to_nonghost_and_ghost_soln),
1439 _sys_to_var_num_and_direction(x._sys_to_var_num_and_direction),
1440 _has_displacement(x._has_displacement)
1441{
1442}
std::map< unsigned int, std::pair< const NumericVector< Number > *, std::shared_ptr< NumericVector< Number > > > > _sys_to_nonghost_and_ghost_soln
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.

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 };
static Threads::spin_mutex threaded_node_mutex
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
virtual const char * what() const
Get out the error message.

◆ hasDisplacement()

bool DisplacedProblem::UpdateDisplacedMeshThread::hasDisplacement ( )
inline

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

Definition at line 429 of file DisplacedProblem.h.

430 {
431 mooseAssert(!Threads::in_threads,
432 "This function requires a MPI all-gathering operation that cannot be in a "
433 "threaded scope.");
435 return _has_displacement;
436 }
void max(const T &r, T &o, Request &req) const
const Parallel::Communicator & comm() const

Referenced by DisplacedProblem::updateMesh(), and DisplacedProblem::updateMesh().

◆ init()

void DisplacedProblem::UpdateDisplacedMeshThread::init ( )
protected

Definition at line 1445 of file DisplacedProblem.C.

1446{
1447 std::vector<std::string> & displacement_variables = _displaced_problem._displacements;
1448 unsigned int num_displacements = displacement_variables.size();
1449 auto & es = _displaced_problem.es();
1450
1453
1454 for (unsigned int i = 0; i < num_displacements; i++)
1455 {
1456 std::string displacement_name = displacement_variables[i];
1457
1458 for (const auto sys_num : make_range(es.n_systems()))
1459 {
1460 auto & sys = es.get_system(sys_num);
1461 if (sys.has_variable(displacement_name))
1462 {
1463 auto & val = _sys_to_var_num_and_direction[sys.number()];
1464 val.first.push_back(sys.variable_number(displacement_name));
1465 val.second.push_back(i);
1466 break;
1467 }
1468 }
1469 }
1470
1471 for (const auto & pr : _sys_to_var_num_and_direction)
1472 {
1473 auto & sys = es.get_system(pr.first);
1474 mooseAssert(sys.number() <= _nl_soln.size(),
1475 "The system number should always be less than or equal to the number of nonlinear "
1476 "systems. If it is equal, then this system is the auxiliary system");
1477 const NumericVector<Number> * const nonghost_soln =
1478 sys.number() < _nl_soln.size() ? _nl_soln[sys.number()] : &_aux_soln;
1480 sys.number(),
1481 std::make_pair(nonghost_soln,
1482 NumericVector<Number>::build(nonghost_soln->comm()).release()));
1483 }
1484
1485 ConstNodeRange node_range(_ref_mesh.getMesh().nodes_begin(), _ref_mesh.getMesh().nodes_end());
1486
1487 for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1488 {
1489 auto & sys = es.get_system(sys_num);
1490 AllNodesSendListThread send_list(
1491 this->_fe_problem, _ref_mesh, var_num_and_direction.first, sys);
1492 Threads::parallel_reduce(node_range, send_list, this->_fe_problem.numThreads());
1493 send_list.unique();
1494 auto & [soln, ghost_soln] = libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num);
1495 ghost_soln->init(
1496 soln->size(), soln->local_size(), send_list.send_list(), true, libMesh::GHOSTED);
1497 soln->localize(*ghost_soln, send_list.send_list());
1498 }
1499
1500 _has_displacement = false;
1501}
virtual EquationSystems & es() override
std::vector< std::string > _displacements
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3512
THREAD_ID numThreads() const
Definition SubProblem.C:81
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
StoredRange< MeshBase::const_node_iterator, const Node * > ConstNodeRange
IntRange< T > make_range(T beg, T end)

Referenced by UpdateDisplacedMeshThread().

◆ join()

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

Definition at line 420 of file DisplacedProblem.h.

421 {
422 if (y._has_displacement)
423 _has_displacement = true;
424 }

◆ 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]

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

Definition at line 1504 of file DisplacedProblem.C.

1505{
1506 Node & displaced_node = *(*nd);
1507
1508 Node & reference_node = _ref_mesh.nodeRef(displaced_node.id());
1509
1510 for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1511 {
1512 auto & var_numbers = var_num_and_direction.first;
1513 auto & directions = var_num_and_direction.second;
1514 for (const auto i : index_range(var_numbers))
1515 {
1516 const auto direction = directions[i];
1517 if (reference_node.n_dofs(sys_num, var_numbers[i]) > 0)
1518 {
1519 Real coord = reference_node(direction) +
1520 (*libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num).second)(
1521 reference_node.dof_number(sys_num, var_numbers[i], 0));
1522 // A non-finite displacement (e.g. after a failed linear solve) would corrupt every
1523 // downstream geometric operation. Throw so the solve can be stopped and the step cut.
1524 if (!std::isfinite(coord))
1525 throw MooseException("Non-finite displaced coordinate in direction ",
1526 direction,
1527 " at node ",
1528 displaced_node.id(),
1529 ".");
1530 if (displaced_node(direction) != coord)
1531 {
1532 displaced_node(direction) = coord;
1533 _has_displacement = true;
1534 }
1535 }
1536 }
1537 }
1538}
Provides a way for users to bail out of the current solve.
virtual const Node & nodeRef(const dof_id_type i) const
Definition MooseMesh.C:846
auto index_range(const T &sizable)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ onNode() [2/2]

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

Called for each node.

Definition at line 43 of file ThreadedNodeLoop.h.

137{
138}

◆ operator()()

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

Definition at line 28 of file ThreadedNodeLoop.h.

95{
96 try
97 {
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 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.
virtual bool keepGoing()
Whether or not the loop should continue.
virtual void pre()
Called before the node range loop.
virtual void post()
Called after the node range loop.
virtual void caughtMooseException(MooseException &e)
Called if a MooseException is caught anywhere during the computation.

◆ post()

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

Called after the node range loop.

Definition at line 38 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 50 of file ThreadedNodeLoop.h.

143{
144}

◆ pre()

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

Called before the node range loop.

Definition at line 33 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 448 of file DisplacedProblem.h.

◆ _displaced_problem

DisplacedProblem& DisplacedProblem::UpdateDisplacedMeshThread::_displaced_problem
protected

Diplaced problem.

Definition at line 442 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 464 of file DisplacedProblem.h.

Referenced by hasDisplacement(), and 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 446 of file DisplacedProblem.h.

◆ _ref_mesh

MooseMesh& DisplacedProblem::UpdateDisplacedMeshThread::_ref_mesh
protected

Original mesh.

Definition at line 444 of file DisplacedProblem.h.

Referenced by hasDisplacement().

◆ _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 455 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 460 of file DisplacedProblem.h.

◆ _tid

THREAD_ID ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::_tid
protectedinherited

Definition at line 73 of file ThreadedNodeLoop.h.


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