www.mooseframework.org
Public Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | List of all members
ComputeNodalUserObjectsThread Class Reference

#include <ComputeNodalUserObjectsThread.h>

Inheritance diagram for ComputeNodalUserObjectsThread:
[legend]

Public Member Functions

 ComputeNodalUserObjectsThread (FEProblemBase &fe_problem, const TheWarehouse::Query &query)
 
 ComputeNodalUserObjectsThread (ComputeNodalUserObjectsThread &x, Threads::split split)
 
virtual ~ComputeNodalUserObjectsThread ()
 
void subdomainChanged ()
 
virtual void onNode (ConstNodeRange::const_iterator &node_it) override
 Called for each node. More...
 
void join (const ComputeNodalUserObjectsThread &)
 
void printGeneralExecutionInformation () const override
 Print information about the loop, mostly order of execution of objects. More...
 
void operator() (const ConstNodeRange &range)
 
virtual void pre ()
 Called before the node range loop. More...
 
virtual void post ()
 Called after the node range loop. More...
 
virtual void postNode (ConstNodeRange::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 Attributes

FEProblemBase_fe_problem
 
THREAD_ID _tid
 

Private Attributes

const TheWarehouse::Query _query
 
AuxiliarySystem_aux_sys
 
std::set< SubdomainID_block_ids
 

Static Private Attributes

static Threads::spin_mutex writable_variable_mutex
 

Detailed Description

Definition at line 19 of file ComputeNodalUserObjectsThread.h.

Constructor & Destructor Documentation

◆ ComputeNodalUserObjectsThread() [1/2]

ComputeNodalUserObjectsThread::ComputeNodalUserObjectsThread ( FEProblemBase fe_problem,
const TheWarehouse::Query query 
)

◆ ComputeNodalUserObjectsThread() [2/2]

ComputeNodalUserObjectsThread::ComputeNodalUserObjectsThread ( ComputeNodalUserObjectsThread x,
Threads::split  split 
)

◆ ~ComputeNodalUserObjectsThread()

ComputeNodalUserObjectsThread::~ComputeNodalUserObjectsThread ( )
virtual

Definition at line 39 of file ComputeNodalUserObjectsThread.C.

39 {}

Member Function Documentation

◆ caughtMooseException()

virtual void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::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

◆ join()

void ComputeNodalUserObjectsThread::join ( const ComputeNodalUserObjectsThread )

Definition at line 135 of file ComputeNodalUserObjectsThread.C.

136 {
137 }

◆ keepGoing()

virtual bool ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::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()

void ComputeNodalUserObjectsThread::onNode ( ConstNodeRange::const_iterator &  node_it)
overridevirtual

Called for each node.

Reimplemented from ThreadedNodeLoop< ConstNodeRange, ConstNodeRange::const_iterator >.

Definition at line 60 of file ComputeNodalUserObjectsThread.C.

61 {
62  const Node * node = *node_it;
63 
64  const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
65  if (_block_ids != block_ids)
66  {
67  _block_ids.clear();
68  _block_ids.insert(block_ids.begin(), block_ids.end());
70  }
71 
73 
74  std::vector<NodalUserObject *> objs;
75 
76  // Boundary Restricted
77  std::vector<BoundaryID> nodeset_ids;
78  _fe_problem.mesh().getMesh().get_boundary_info().boundary_ids(node, nodeset_ids);
79  for (const auto & bnd : nodeset_ids)
80  {
81  _query.clone()
83  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
84  .condition<AttribBoundaries>(bnd, true)
85  .queryInto(objs);
86  for (const auto & uo : objs)
87  {
88  uo->execute();
89 
90  // update the aux solution vector if writable coupled variables are used
91  if (uo->hasWritableCoupledVariables())
92  {
93  Threads::spin_mutex::scoped_lock lock(writable_variable_mutex);
94  for (auto * var : uo->getWritableCoupledVariables())
95  var->insert(_aux_sys.solution());
96  }
97  }
98  }
99 
100  // Block Restricted
101  // NodalUserObjects may be block restricted, in this case by default the execute() method is
102  // called for each subdomain that the node "belongs". This may be disabled in the NodalUserObject
103  // by setting "unique_node_execute = true".
104 
105  // To enforce the unique execution this vector is populated and checked if the unique flag is
106  // enabled.
107  std::set<NodalUserObject *> computed;
108  for (const auto & block : block_ids)
109  {
110  _query.clone()
112  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
113  .condition<AttribSubdomains>(block)
114  .queryInto(objs);
115 
116  for (const auto & uo : objs)
117  if (!uo->isUniqueNodeExecute() || computed.count(uo) == 0)
118  {
119  uo->execute();
120 
121  // update the aux solution vector if writable coupled variables are used
122  if (uo->hasWritableCoupledVariables())
123  {
124  Threads::spin_mutex::scoped_lock lock(writable_variable_mutex);
125  for (auto * var : uo->getWritableCoupledVariables())
126  var->insert(_aux_sys.solution());
127  }
128 
129  computed.insert(uo);
130  }
131  }
132 }
MooseMesh & mesh()
Definition: SystemBase.h:100
virtual void reinitNode(const Node *node, const THREAD_ID tid) override
NumericVector< Number > & solution()
Definition: SystemBase.h:182
static Threads::spin_mutex writable_variable_mutex
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition: MooseMesh.C:1281
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3199
AttribBoundaries tracks all boundary IDs associated with an object.
Definition: Attributes.h:188
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
Definition: TheWarehouse.h:292
virtual MooseMesh & mesh() override
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Definition: TheWarehouse.h:284

◆ operator()()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::operator() ( const ConstNodeRange 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.
Provides a way for users to bail out of the current solve.
virtual void pre()
Called before the node range loop.
virtual void post()
Called after the node range loop.
virtual void postNode(ConstNodeRange::const_iterator &node_it)
Called after the node assembly is done (including surface assembling)
virtual void onNode(ConstNodeRange::const_iterator &node_it)
Called for each node.

◆ post()

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

Called after the node range loop.

Reimplemented in ComputeNodalAuxVarsThread< AuxKernelType >.

Definition at line 130 of file ThreadedNodeLoop.h.

131 {
132 }

◆ postNode()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::postNode ( ConstNodeRange::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< ConstNodeRange , ConstNodeRange::const_iterator >::pre ( )
virtualinherited

Called before the node range loop.

Reimplemented in ComputeNodalKernelJacobiansThread, and ComputeNodalKernelsThread.

Definition at line 124 of file ThreadedNodeLoop.h.

125 {
126 }

◆ printGeneralExecutionInformation()

void ComputeNodalUserObjectsThread::printGeneralExecutionInformation ( ) const
overridevirtual

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

Reimplemented from ThreadedNodeLoop< ConstNodeRange, ConstNodeRange::const_iterator >.

Definition at line 140 of file ComputeNodalUserObjectsThread.C.

141 {
143  return;
144 
145  // Get all nodal UOs
146  std::vector<MooseObject *> nodal_uos;
147  _query.clone()
149  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
150  .queryInto(nodal_uos);
151 
152  if (nodal_uos.size())
153  {
154  const auto & console = _fe_problem.console();
155  const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
156  console << "[DBG] Computing nodal user objects on " << execute_on << std::endl;
157  mooseDoOnce(
158  console << "[DBG] Ordering on nodes:" << std::endl;
159  console << "[DBG] - boundary restricted user objects" << std::endl;
160  console << "[DBG] - block restricted user objects" << std::endl;
161  console << "[DBG] Nodal UOs executed on each node will differ based on these restrictions"
162  << std::endl;);
163 
164  auto message = ConsoleUtils::mooseObjectVectorToString(nodal_uos);
165  message = "Order of execution:\n" + message;
166  console << ConsoleUtils::formatString(message, "[DBG]") << std::endl;
167  }
168 }
std::string mooseObjectVectorToString(const std::vector< MooseObject *> &objs, const std::string &sep=" ")
Routine to output the name of MooseObjects in a string.
Definition: ConsoleUtils.C:438
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
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...
Definition: ConsoleUtils.C:422
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
Definition: TheWarehouse.h:292
const ConsoleStream & console() const
Return console handle.
Definition: Problem.h:48
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Definition: TheWarehouse.h:284

◆ subdomainChanged()

void ComputeNodalUserObjectsThread::subdomainChanged ( )

Definition at line 42 of file ComputeNodalUserObjectsThread.C.

Referenced by onNode().

43 {
44  std::vector<NodalUserObject *> objs;
45  _query.clone()
47  .condition<AttribInterfaces>(Interfaces::NodalUserObject)
48  .queryInto(objs);
49 
50  std::set<TagID> needed_vector_tags;
51  for (const auto obj : objs)
52  {
53  auto & vector_tags = obj->getFEVariableCoupleableVectorTags();
54  needed_vector_tags.insert(vector_tags.begin(), vector_tags.end());
55  }
57 }
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
Definition: TheWarehouse.h:292
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Definition: TheWarehouse.h:284
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override

Member Data Documentation

◆ _aux_sys

AuxiliarySystem& ComputeNodalUserObjectsThread::_aux_sys
private

Definition at line 40 of file ComputeNodalUserObjectsThread.h.

Referenced by onNode().

◆ _block_ids

std::set<SubdomainID> ComputeNodalUserObjectsThread::_block_ids
private

Definition at line 41 of file ComputeNodalUserObjectsThread.h.

Referenced by onNode().

◆ _fe_problem

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

◆ _query

const TheWarehouse::Query ComputeNodalUserObjectsThread::_query
private

◆ _tid

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

◆ writable_variable_mutex

Threads::spin_mutex ComputeNodalUserObjectsThread::writable_variable_mutex
staticprivate

Definition at line 43 of file ComputeNodalUserObjectsThread.h.

Referenced by onNode().


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