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 displaceNodesWithoutDofs ()
 Displace the nodes of elements on which a displacement variable has no degrees of freedom, such as the face and interior nodes of TRI7 or TET14 elements with SECOND order displacements, by interpolating the displacement from the other element nodes.
 
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.
 
void printExecutionOrdering (const std::vector< T * > &objs, const bool print_header=true, const std::string &line_prefix="[DBG]") const
 Routine to output the ordering of objects within a vector of pointers to these 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 1421 of file DisplacedProblem.C.

1428 _has_displacement(false)
1429{
1430 this->init();
1431}
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 1433 of file DisplacedProblem.C.

1436 _displaced_problem(x._displaced_problem),
1437 _ref_mesh(x._ref_mesh),
1438 _nl_soln(x._nl_soln),
1439 _aux_soln(x._aux_soln),
1440 _sys_to_nonghost_and_ghost_soln(x._sys_to_nonghost_and_ghost_soln),
1441 _sys_to_var_num_and_direction(x._sys_to_var_num_and_direction),
1442 _has_displacement(x._has_displacement)
1443{
1444}
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.

◆ displaceNodesWithoutDofs()

void DisplacedProblem::UpdateDisplacedMeshThread::displaceNodesWithoutDofs ( )

Displace the nodes of elements on which a displacement variable has no degrees of freedom, such as the face and interior nodes of TRI7 or TET14 elements with SECOND order displacements, by interpolating the displacement from the other element nodes.

This is not threaded because multiple elements sharing a face node write to it.

Definition at line 1543 of file DisplacedProblem.C.

1544{
1545 auto & es = _displaced_problem.es();
1546 auto & displaced_mesh = _displaced_problem.mesh();
1547 std::vector<dof_id_type> dof_indices;
1548 std::vector<Number> elem_soln;
1549 std::vector<Number> nodal_soln;
1550
1551 for (const auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1552 {
1553 const auto & dof_map = es.get_system(sys_num).get_dof_map();
1554 const auto & soln = *libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num).second;
1555 const auto & [var_numbers, directions] = var_num_and_direction;
1556 for (const auto i : index_range(var_numbers))
1557 {
1558 const auto var_num = var_numbers[i];
1559 const auto & fe_type = dof_map.variable_type(var_num);
1560 // Only for Lagrange variables are all element degrees of freedom located at Node points, and
1561 // therefore in the ghosted solution built by init()
1562 if (fe_type.family != LAGRANGE)
1563 continue;
1564 // A Lagrange variable has degrees of freedom on every node of elements whose geometric
1565 // order does not exceed its own
1566 const auto & elem_orders = _ref_mesh.getMesh().elem_default_orders();
1567 if (elem_orders.empty() || *elem_orders.rbegin() <= fe_type.order)
1568 continue;
1569
1570 for (const Elem * const elem : _ref_mesh.getMesh().active_element_ptr_range())
1571 {
1572 const auto node_indices = elem->node_index_range();
1573 if (!dof_map.variable(var_num).active_on_subdomain(elem->subdomain_id()) ||
1574 std::all_of(node_indices.begin(),
1575 node_indices.end(),
1576 [elem, sys_num = sys_num, var_num](const unsigned int n)
1577 { return elem->node_ref(n).n_dofs(sys_num, var_num) > 0; }))
1578 continue;
1579
1580 // nodal_soln computes the displacement of a face node from the nodes of that face alone, so
1581 // every element sharing the face moves the node to the same position
1582 dof_map.dof_indices(elem, dof_indices, var_num);
1583 soln.get(dof_indices, elem_soln);
1584 FEInterface::nodal_soln(elem->dim(), fe_type, elem, elem_soln, nodal_soln);
1585
1586 for (const auto n : elem->node_index_range())
1587 {
1588 const Node & reference_node = elem->node_ref(n);
1589 if (reference_node.n_dofs(sys_num, var_num) > 0)
1590 continue;
1591
1592 Node & displaced_node = displaced_mesh.nodeRef(reference_node.id());
1593 const Real coord = reference_node(directions[i]) + nodal_soln[n];
1594 if (displaced_node(directions[i]) != coord)
1595 {
1596 displaced_node(directions[i]) = coord;
1597 _has_displacement = true;
1598 }
1599 }
1600 }
1601 }
1602 }
1603}
virtual MooseMesh & mesh() override
virtual EquationSystems & es() override
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3581
auto index_range(const T &sizable)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

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

◆ hasDisplacement()

bool DisplacedProblem::UpdateDisplacedMeshThread::hasDisplacement ( )
inline

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

Definition at line 437 of file DisplacedProblem.h.

438 {
439 mooseAssert(!Threads::in_threads,
440 "This function requires a MPI all-gathering operation that cannot be in a "
441 "threaded scope.");
443 return _has_displacement;
444 }
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 1447 of file DisplacedProblem.C.

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

429 {
430 if (y._has_displacement)
431 _has_displacement = true;
432 }

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

1507{
1508 Node & displaced_node = *(*nd);
1509
1510 Node & reference_node = _ref_mesh.nodeRef(displaced_node.id());
1511
1512 for (auto & [sys_num, var_num_and_direction] : _sys_to_var_num_and_direction)
1513 {
1514 auto & var_numbers = var_num_and_direction.first;
1515 auto & directions = var_num_and_direction.second;
1516 for (const auto i : index_range(var_numbers))
1517 {
1518 const auto direction = directions[i];
1519 if (reference_node.n_dofs(sys_num, var_numbers[i]) > 0)
1520 {
1521 Real coord = reference_node(direction) +
1522 (*libmesh_map_find(_sys_to_nonghost_and_ghost_soln, sys_num).second)(
1523 reference_node.dof_number(sys_num, var_numbers[i], 0));
1524 // A non-finite displacement (e.g. after a failed linear solve) would corrupt every
1525 // downstream geometric operation. Throw so the solve can be stopped and the step cut.
1526 if (!std::isfinite(coord))
1527 throw MooseException("Non-finite displaced coordinate in direction ",
1528 direction,
1529 " at node ",
1530 displaced_node.id(),
1531 ".");
1532 if (displaced_node(direction) != coord)
1533 {
1534 displaced_node(direction) = coord;
1535 _has_displacement = true;
1536 }
1537 }
1538 }
1539 }
1540}
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:856

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

153{
154}

◆ operator()()

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

Definition at line 28 of file ThreadedNodeLoop.h.

111{
112 try
113 {
114 ParallelUniqueId puid;
115 _tid = puid.id;
116
117 pre();
119
120 for (IteratorType nd = range.begin(); nd != range.end(); ++nd)
121 {
122 if (!keepGoing())
123 break;
124
125 onNode(nd);
126
127 postNode(nd);
128 }
129
130 post();
131 }
132 catch (MooseException & e)
133 {
135 }
136}
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.

147{
148}

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

159{
160}

◆ pre()

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

Called before the node range loop.

Definition at line 33 of file ThreadedNodeLoop.h.

141{
142}

◆ printExecutionOrdering()

void ThreadedNodeLoop< NodeRange , NodeRange::const_iterator >::printExecutionOrdering ( const std::vector< T * > &  objs,
const bool  print_header = true,
const std::string &  line_prefix = "[DBG]" 
) const
protectedinherited

Routine to output the ordering of objects within a vector of pointers to these objects.

These objects must implement the name() routine, and it must return a string or compatible type.

Template Parameters
Tthe object type
Parameters
objsthe vector with all the objects (should be pointers)
print_headerwhether to print a header about the timing of execution and the type of objects
line_prefixprefix to prepend to each line of the console output

Definition at line 90 of file ThreadedNodeLoop.h.

167{
168 if (!objs.size())
169 return;
170
171 auto & console = _fe_problem.console();
172 const auto objects_type = MooseUtils::prettyCppType(objs[0]);
173 std::vector<MooseObject *> moose_objs;
174 moose_objs.reserve(objs.size());
175 for (auto obj_ptr : objs)
176 moose_objs.push_back(cast_ptr<MooseObject *>(obj_ptr));
177 const auto names = ConsoleUtils::mooseObjectVectorToString(moose_objs);
178
179 // Print string with a DBG prefix and with sufficient line breaks
180 std::string message = print_header ? "Executing " + objects_type + " on " +
182 : "";
183 message += (print_header ? "Order of execution:\n" : "") + names;
184 console << ConsoleUtils::formatString(message, line_prefix) << std::endl;
185}
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
const std::string & name() const
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
const ConsoleStream & console() const
Return console handle.
Definition Problem.h:48
std::string formatString(std::string message, const std::string &prefix)
Add new lines and prefixes to a string for pretty display in output NOTE: This makes a copy of the st...
std::string mooseObjectVectorToString(const std::vector< MooseObject * > &objs, const std::string &sep=" ")
Routine to output the name of MooseObjects in a string.
std::string prettyCppType(const std::string &cpp_type)
Tnew cast_ptr(Told *oldvar)

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

◆ _displaced_problem

DisplacedProblem& DisplacedProblem::UpdateDisplacedMeshThread::_displaced_problem
protected

Diplaced problem.

Definition at line 450 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 472 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 454 of file DisplacedProblem.h.

◆ _ref_mesh

MooseMesh& DisplacedProblem::UpdateDisplacedMeshThread::_ref_mesh
protected

Original mesh.

Definition at line 452 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 463 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 468 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: