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 1415 of file DisplacedProblem.C.

1422 _has_displacement(false)
1423{
1424 this->init();
1425}
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 1427 of file DisplacedProblem.C.

1430 _displaced_problem(x._displaced_problem),
1431 _ref_mesh(x._ref_mesh),
1432 _nl_soln(x._nl_soln),
1433 _aux_soln(x._aux_soln),
1434 _sys_to_nonghost_and_ghost_soln(x._sys_to_nonghost_and_ghost_soln),
1435 _sys_to_var_num_and_direction(x._sys_to_var_num_and_direction),
1436 _has_displacement(x._has_displacement)
1437{
1438}
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 1441 of file DisplacedProblem.C.

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

1501{
1502 Node & displaced_node = *(*nd);
1503
1504 Node & reference_node = _ref_mesh.nodeRef(displaced_node.id());
1505
1506 for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1507 {
1508 auto & var_numbers = var_num_and_direction.first;
1509 auto & directions = var_num_and_direction.second;
1510 for (const auto i : index_range(var_numbers))
1511 {
1512 const auto direction = directions[i];
1513 if (reference_node.n_dofs(sys_num, var_numbers[i]) > 0)
1514 {
1515 Real coord = reference_node(direction) +
1516 (*libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num).second)(
1517 reference_node.dof_number(sys_num, var_numbers[i], 0));
1518 if (displaced_node(direction) != coord)
1519 {
1520 displaced_node(direction) = coord;
1521 _has_displacement = true;
1522 }
1523 }
1524 }
1525 }
1526}
virtual const Node & nodeRef(const dof_id_type i) const
Definition MooseMesh.C:844
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}
Provides a way for users to bail out of the current solve.
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: