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 414 of file DisplacedProblem.h.

Constructor & Destructor Documentation

◆ UpdateDisplacedMeshThread() [1/2]

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

Definition at line 1433 of file DisplacedProblem.C.

1440 _has_displacement(false)
1441{
1442 this->init();
1443}
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 1445 of file DisplacedProblem.C.

1448 _displaced_problem(x._displaced_problem),
1449 _ref_mesh(x._ref_mesh),
1450 _nl_soln(x._nl_soln),
1451 _aux_soln(x._aux_soln),
1452 _sys_to_nonghost_and_ghost_soln(x._sys_to_nonghost_and_ghost_soln),
1453 _sys_to_var_num_and_direction(x._sys_to_var_num_and_direction),
1454 _has_displacement(x._has_displacement)
1455{
1456}
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 432 of file DisplacedProblem.h.

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

Referenced by DisplacedProblem::updateMesh().

◆ init()

void DisplacedProblem::UpdateDisplacedMeshThread::init ( )
protected

Definition at line 1459 of file DisplacedProblem.C.

1460{
1461 std::vector<std::string> & displacement_variables = _displaced_problem._displacements;
1462 unsigned int num_displacements = displacement_variables.size();
1463 auto & es = _displaced_problem.es();
1464
1467
1468 for (unsigned int i = 0; i < num_displacements; i++)
1469 {
1470 std::string displacement_name = displacement_variables[i];
1471
1472 for (const auto sys_num : make_range(es.n_systems()))
1473 {
1474 auto & sys = es.get_system(sys_num);
1475 if (sys.has_variable(displacement_name))
1476 {
1477 auto & val = _sys_to_var_num_and_direction[sys.number()];
1478 val.first.push_back(sys.variable_number(displacement_name));
1479 val.second.push_back(i);
1480 break;
1481 }
1482 }
1483 }
1484
1485 for (const auto & pr : _sys_to_var_num_and_direction)
1486 {
1487 auto & sys = es.get_system(pr.first);
1488 mooseAssert(sys.number() <= _nl_soln.size(),
1489 "The system number should always be less than or equal to the number of nonlinear "
1490 "systems. If it is equal, then this system is the auxiliary system");
1491 const NumericVector<Number> * const nonghost_soln =
1492 sys.number() < _nl_soln.size() ? _nl_soln[sys.number()] : &_aux_soln;
1494 sys.number(),
1495 std::make_pair(nonghost_soln,
1496 NumericVector<Number>::build(nonghost_soln->comm()).release()));
1497 }
1498
1499 ConstNodeRange node_range(_ref_mesh.getMesh().nodes_begin(), _ref_mesh.getMesh().nodes_end());
1500
1501 for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1502 {
1503 auto & sys = es.get_system(sys_num);
1504 AllNodesSendListThread send_list(
1505 this->_fe_problem, _ref_mesh, var_num_and_direction.first, sys);
1506 Threads::parallel_reduce(node_range, send_list);
1507 send_list.unique();
1508 auto & [soln, ghost_soln] = libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num);
1509 ghost_soln->init(
1510 soln->size(), soln->local_size(), send_list.send_list(), true, libMesh::GHOSTED);
1511 soln->localize(*ghost_soln, send_list.send_list());
1512 }
1513
1514 _has_displacement = false;
1515}
virtual EquationSystems & es() override
std::vector< std::string > _displacements
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
const T_sys & get_system(std::string_view name) const
virtual numeric_index_type size() const=0
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
IntRange< T > make_range(T beg, T end)

Referenced by UpdateDisplacedMeshThread().

◆ join()

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

Definition at line 423 of file DisplacedProblem.h.

424 {
425 if (y._has_displacement)
426 _has_displacement = true;
427 }

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

1519{
1520 Node & displaced_node = *(*nd);
1521
1522 Node & reference_node = _ref_mesh.nodeRef(displaced_node.id());
1523
1524 for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1525 {
1526 auto & var_numbers = var_num_and_direction.first;
1527 auto & directions = var_num_and_direction.second;
1528 for (const auto i : index_range(var_numbers))
1529 {
1530 const auto direction = directions[i];
1531 if (reference_node.n_dofs(sys_num, var_numbers[i]) > 0)
1532 {
1533 Real coord = reference_node(direction) +
1534 (*libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num).second)(
1535 reference_node.dof_number(sys_num, var_numbers[i], 0));
1536 if (displaced_node(direction) != coord)
1537 {
1538 displaced_node(direction) = coord;
1539 _has_displacement = true;
1540 }
1541 }
1542 }
1543 }
1544}
virtual const Node & nodeRef(const dof_id_type i) const
Definition MooseMesh.C:841
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
unsigned int n_dofs(const unsigned int s, const unsigned int var=libMesh::invalid_uint) const
dof_id_type id() const
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 451 of file DisplacedProblem.h.

◆ _displaced_problem

DisplacedProblem& DisplacedProblem::UpdateDisplacedMeshThread::_displaced_problem
protected

Diplaced problem.

Definition at line 445 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 467 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 449 of file DisplacedProblem.h.

◆ _ref_mesh

MooseMesh& DisplacedProblem::UpdateDisplacedMeshThread::_ref_mesh
protected

Original mesh.

Definition at line 447 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 458 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 463 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: