https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ThreadedElementLoopBase< RangeType > Class Template Reference

Base class for assembly-like calculations. More...

#include <ThreadedElementLoopBase.h>

Inheritance diagram for ThreadedElementLoopBase< RangeType >:
[legend]

Public Member Functions

 ThreadedElementLoopBase (MooseMesh &mesh)
 
 ThreadedElementLoopBase (ThreadedElementLoopBase &x, Threads::split split)
 
virtual ~ThreadedElementLoopBase ()
 
virtual void operator() (const RangeType &range, bool bypass_threading=false)
 
virtual void pre ()
 Called before the element range loop. More...
 
virtual void post ()
 Called after the element range loop. More...
 
virtual void onElement (const Elem *elem)
 Assembly of the element (not including surface assembly) More...
 
virtual void preElement (const Elem *elem)
 Called before the element assembly. More...
 
virtual void postElement (const Elem *elem)
 Called after the element assembly is done (including surface assembling) More...
 
virtual void preBoundary (const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr)
 Called before the boundary assembly. More...
 
virtual void onBoundary (const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr)
 Called when doing boundary assembling. More...
 
virtual void preInternalSide (const Elem *elem, unsigned int side)
 Called before evaluations on an element internal side. More...
 
virtual void postInternalSide (const Elem *elem, unsigned int side)
 Called after evaluations on an element internal side. More...
 
virtual void onInternalSide (const Elem *elem, unsigned int side)
 Called when doing internal edge assembling. More...
 
virtual void onExternalSide (const Elem *elem, unsigned int side)
 Called when iterating over external sides (no side neighbor) More...
 
virtual void onInterface (const Elem *elem, unsigned int side, BoundaryID bnd_id)
 Called when doing interface assembling. More...
 
virtual void subdomainChanged ()
 Called every time the current subdomain changes (i.e. More...
 
virtual void neighborSubdomainChanged ()
 Called every time the neighbor subdomain changes (i.e. More...
 
virtual void caughtMooseException (MooseException &)
 Called if a MooseException is caught anywhere during the computation. More...
 
virtual bool keepGoing ()
 Whether or not the loop should continue. More...
 

Protected Member Functions

virtual void printGeneralExecutionInformation () const
 Print information about the loop ordering. More...
 
virtual void printBlockExecutionInformation () const
 Print information about the particular ordering of objects on each block. More...
 
virtual void printBoundaryExecutionInformation (const unsigned int) const
 Print information about the particular ordering of objects on each boundary. More...
 
void resetExecPrintedSets () const
 Resets the set of blocks and boundaries visited. More...
 
virtual bool shouldComputeInternalSide (const Elem &elem, const Elem &neighbor) const
 Whether to compute the internal side for the provided element-neighbor pair. More...
 

Protected Attributes

MooseMesh_mesh
 
THREAD_ID _tid
 
SubdomainID _subdomain
 The subdomain for the current element. More...
 
SubdomainID _old_subdomain
 The subdomain for the last element. More...
 
SubdomainID _neighbor_subdomain
 The subdomain for the current neighbor. More...
 
SubdomainID _old_neighbor_subdomain
 The subdomain for the last neighbor. More...
 
std::set< SubdomainID_blocks_exec_printed
 Keep track of which blocks were visited. More...
 
std::set< BoundaryID_boundaries_exec_printed
 Keep track of which boundaries were visited. More...
 

Detailed Description

template<typename RangeType>
class ThreadedElementLoopBase< RangeType >

Base class for assembly-like calculations.

Definition at line 26 of file ThreadedElementLoopBase.h.

Constructor & Destructor Documentation

◆ ThreadedElementLoopBase() [1/2]

template<typename RangeType >
ThreadedElementLoopBase< RangeType >::ThreadedElementLoopBase ( MooseMesh mesh)

Definition at line 208 of file ThreadedElementLoopBase.h.

208  : _mesh(mesh)
209 {
210 }

◆ ThreadedElementLoopBase() [2/2]

template<typename RangeType >
ThreadedElementLoopBase< RangeType >::ThreadedElementLoopBase ( ThreadedElementLoopBase< RangeType > &  x,
Threads::split  split 
)

Definition at line 213 of file ThreadedElementLoopBase.h.

215  : _mesh(x._mesh)
216 {
217 }

◆ ~ThreadedElementLoopBase()

template<typename RangeType >
ThreadedElementLoopBase< RangeType >::~ThreadedElementLoopBase ( )
virtual

Definition at line 220 of file ThreadedElementLoopBase.h.

221 {
222 }

Member Function Documentation

◆ caughtMooseException()

template<typename RangeType>
virtual void ThreadedElementLoopBase< RangeType >::caughtMooseException ( MooseException )
inlinevirtual

Called if a MooseException is caught anywhere during the computation.

The single input parameter taken is a MooseException object.

Reimplemented in ThreadedElementLoop< RangeType >, ThreadedElementLoop< ConstElemRange >, ThreadedElementLoop< libMesh::ConstElemRange >, ThreadedElementLoop< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 155 of file ThreadedElementLoopBase.h.

155 {};

◆ keepGoing()

template<typename RangeType>
virtual bool ThreadedElementLoopBase< RangeType >::keepGoing ( )
inlinevirtual

Whether or not the loop should continue.

Returns
true to keep going, false to stop.

Reimplemented in ThreadedElementLoop< RangeType >, ThreadedElementLoop< ConstElemRange >, ThreadedElementLoop< libMesh::ConstElemRange >, ThreadedElementLoop< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 162 of file ThreadedElementLoopBase.h.

162 { return true; }

◆ neighborSubdomainChanged()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::neighborSubdomainChanged ( )
virtual

Called every time the neighbor subdomain changes (i.e.

the subdomain of this neighbor is not the same as the subdomain of the last neighbor). Beware of over-using this! You might think that you can do some expensive stuff in here and get away with it... but there are applications that have TONS of subdomains....

Reimplemented in ThreadedElementLoop< RangeType >, ThreadedElementLoop< ConstElemRange >, ThreadedElementLoop< libMesh::ConstElemRange >, ThreadedElementLoop< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 423 of file ThreadedElementLoopBase.h.

424 {
425 }

◆ onBoundary()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::onBoundary ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id,
const Elem *  lower_d_elem = nullptr 
)
virtual

Called when doing boundary assembling.

Parameters
elem- The element we are checking is on the boundary.
side- The side of the element in question.
bnd_id- ID of the boundary we are at
lower_d_elem- Lower dimensional element (e.g. Mortar)

Reimplemented in ComputeUserObjectsThread, NonlinearThread, ProjectMaterialProperties, ComputeIndicatorThread, ComputeMaterialsObjectThread, and ComputeMarkerThread.

Definition at line 376 of file ThreadedElementLoopBase.h.

380 {
381 }

◆ onElement()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::onElement ( const Elem *  elem)
virtual

◆ onExternalSide()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::onExternalSide ( const Elem *  elem,
unsigned int  side 
)
virtual

Called when iterating over external sides (no side neighbor)

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Reimplemented in ComputeUserObjectsThread.

Definition at line 403 of file ThreadedElementLoopBase.h.

404 {
405 }

◆ onInterface()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::onInterface ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtual

Called when doing interface assembling.

Parameters
elem- Element we are on
side- local side number of the element 'elem'
bnd_id- ID of the interface we are at

Reimplemented in ComputeUserObjectsThread, NonlinearThread, and ComputeMaterialsObjectThread.

Definition at line 409 of file ThreadedElementLoopBase.h.

412 {
413 }

◆ onInternalSide()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::onInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtual

Called when doing internal edge assembling.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Reimplemented in ComputeUserObjectsThread, NonlinearThread, ProjectMaterialProperties, ComputeIndicatorThread, ComputeMaterialsObjectThread, and ComputeMarkerThread.

Definition at line 397 of file ThreadedElementLoopBase.h.

398 {
399 }

◆ operator()()

template<typename RangeType>
void ThreadedElementLoopBase< RangeType >::operator() ( const RangeType &  range,
bool  bypass_threading = false 
)
virtual

Reimplemented in NonlinearThread, and ComputeJacobianForScalingThread.

Definition at line 226 of file ThreadedElementLoopBase.h.

Referenced by NonlinearThread::operator()().

227 {
228  try
229  {
230  try
231  {
232  ParallelUniqueId puid;
233  _tid = bypass_threading ? 0 : puid.id;
234 
235  pre();
237 
240  typename RangeType::const_iterator el = range.begin();
241  for (el = range.begin(); el != range.end(); ++el)
242  {
243  if (!keepGoing())
244  break;
245 
246  const Elem * elem = *el;
247 
248  preElement(elem);
249 
251  _subdomain = elem->subdomain_id();
252  if (_subdomain != _old_subdomain)
253  {
256  }
257 
258  onElement(elem);
259 
260  if (_mesh.interiorLowerDBlocks().count(elem->subdomain_id()) > 0 ||
261  _mesh.boundaryLowerDBlocks().count(elem->subdomain_id()) > 0)
262  {
263  postElement(elem);
264  continue;
265  }
266 
267  for (unsigned int side = 0; side < elem->n_sides(); side++)
268  {
269  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
270  const Elem * lower_d_elem = _mesh.getLowerDElem(elem, side);
271 
272  if (boundary_ids.size() > 0)
273  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
274  it != boundary_ids.end();
275  ++it)
276  {
277  preBoundary(elem, side, *it, lower_d_elem);
279  onBoundary(elem, side, *it, lower_d_elem);
280  }
281 
282  const Elem * neighbor = elem->neighbor_ptr(side);
283  if (neighbor)
284  {
285  preInternalSide(elem, side);
286 
288  _neighbor_subdomain = neighbor->subdomain_id();
291 
292  if (shouldComputeInternalSide(*elem, *neighbor))
293  onInternalSide(elem, side);
294 
295  if (boundary_ids.size() > 0)
296  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
297  it != boundary_ids.end();
298  ++it)
299  onInterface(elem, side, *it);
300 
301  postInternalSide(elem, side);
302  }
303  else
304  onExternalSide(elem, side);
305  } // sides
306 
307  postElement(elem);
308  } // range
309 
310  post();
312  }
313  catch (MetaPhysicL::LogicError & e)
314  {
316  }
317  catch (std::exception & e)
318  {
319  // Continue if we find a libMesh degenerate map exception, but
320  // just re-throw for any real error
321  if (!strstr(e.what(), "Jacobian") && !strstr(e.what(), "singular") &&
322  !strstr(e.what(), "det != 0"))
323  throw; // not "throw e;" - that destroys type info!
324 
325  mooseException("We caught a libMesh degeneracy exception in ThreadedElementLoopBase:\n",
326  e.what());
327  }
328  }
329  catch (MooseException & e)
330  {
332  }
333 }
virtual void onExternalSide(const Elem *elem, unsigned int side)
Called when iterating over external sides (no side neighbor)
virtual bool keepGoing()
Whether or not the loop should continue.
void resetExecPrintedSets() const
Resets the set of blocks and boundaries visited.
virtual bool shouldComputeInternalSide(const Elem &elem, const Elem &neighbor) const
Whether to compute the internal side for the provided element-neighbor pair.
virtual void onElement(const Elem *elem)
Assembly of the element (not including surface assembly)
const std::set< SubdomainID > & interiorLowerDBlocks() const
Definition: MooseMesh.h:1421
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition: MooseError.C:141
virtual void printBoundaryExecutionInformation(const unsigned int) const
Print information about the particular ordering of objects on each boundary.
virtual void pre()
Called before the element range loop.
const Elem * getLowerDElem(const Elem *, unsigned short int) const
Returns a const pointer to a lower dimensional element that corresponds to a side of a higher dimensi...
Definition: MooseMesh.C:1751
virtual void subdomainChanged()
Called every time the current subdomain changes (i.e.
virtual void neighborSubdomainChanged()
Called every time the neighbor subdomain changes (i.e.
virtual void preInternalSide(const Elem *elem, unsigned int side)
Called before evaluations on an element internal side.
virtual void postInternalSide(const Elem *elem, unsigned int side)
Called after evaluations on an element internal side.
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:20
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr)
Called when doing boundary assembling.
virtual void postElement(const Elem *elem)
Called after the element assembly is done (including surface assembling)
virtual void printGeneralExecutionInformation() const
Print information about the loop ordering.
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing interface assembling.
SubdomainID _old_neighbor_subdomain
The subdomain for the last neighbor.
const std::set< SubdomainID > & boundaryLowerDBlocks() const
Definition: MooseMesh.h:1425
virtual void onInternalSide(const Elem *elem, unsigned int side)
Called when doing internal edge assembling.
Provides a way for users to bail out of the current solve.
virtual void caughtMooseException(MooseException &)
Called if a MooseException is caught anywhere during the computation.
SubdomainID _subdomain
The subdomain for the current element.
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
SubdomainID _old_subdomain
The subdomain for the last element.
virtual void post()
Called after the element range loop.
virtual void printBlockExecutionInformation() const
Print information about the particular ordering of objects on each block.
virtual void preElement(const Elem *elem)
Called before the element assembly.
virtual void preBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr)
Called before the boundary assembly.
SubdomainID _neighbor_subdomain
The subdomain for the current neighbor.

◆ post()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::post ( )
virtual

◆ postElement()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::postElement ( const Elem *  elem)
virtual

Called after the element assembly is done (including surface assembling)

Parameters
elem- active element

Reimplemented in ComputeJacobianBlocksThread, NonlinearThread, ComputeIndicatorThread, ComputeDiracThread, ComputeJacobianThread, and ComputeMarkerThread.

Definition at line 361 of file ThreadedElementLoopBase.h.

362 {
363 }

◆ postInternalSide()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::postInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtual

Called after evaluations on an element internal side.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Reimplemented in ComputeJacobianBlocksThread.

Definition at line 391 of file ThreadedElementLoopBase.h.

392 {
393 }

◆ pre()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::pre ( )
virtual

Called before the element range loop.

Reimplemented in ComputeDiracThread.

Definition at line 337 of file ThreadedElementLoopBase.h.

338 {
339 }

◆ preBoundary()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::preBoundary ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id,
const Elem *  lower_d_elem = nullptr 
)
virtual

Called before the boundary assembly.

Parameters
elem- The element we are checking is on the boundary.
side- The side of the element in question.
bnd_id- ID of the boundary we are at
lower_d_elem- Lower dimensional element (e.g. Mortar)

Reimplemented in ThreadedElementLoop< RangeType >, ThreadedElementLoop< ConstElemRange >, ThreadedElementLoop< libMesh::ConstElemRange >, ThreadedElementLoop< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 367 of file ThreadedElementLoopBase.h.

371 {
372 }

◆ preElement()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::preElement ( const Elem *  elem)
virtual

◆ preInternalSide()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::preInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtual

Called before evaluations on an element internal side.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Reimplemented in ThreadedElementLoop< RangeType >, ThreadedElementLoop< ConstElemRange >, ThreadedElementLoop< libMesh::ConstElemRange >, ThreadedElementLoop< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 385 of file ThreadedElementLoopBase.h.

386 {
387 }

◆ printBlockExecutionInformation()

template<typename RangeType>
virtual void ThreadedElementLoopBase< RangeType >::printBlockExecutionInformation ( ) const
inlineprotectedvirtual

Print information about the particular ordering of objects on each block.

Reimplemented in NonlinearThread, ComputeUserObjectsThread, ComputeIndicatorThread, ComputeDiracThread, ComputeElemAuxVarsThread< AuxKernelType >, and ComputeMarkerThread.

Definition at line 184 of file ThreadedElementLoopBase.h.

184 {}

◆ printBoundaryExecutionInformation()

template<typename RangeType>
virtual void ThreadedElementLoopBase< RangeType >::printBoundaryExecutionInformation ( const unsigned  int) const
inlineprotectedvirtual

Print information about the particular ordering of objects on each boundary.

Reimplemented in NonlinearThread.

Definition at line 187 of file ThreadedElementLoopBase.h.

187 {}

◆ printGeneralExecutionInformation()

template<typename RangeType>
virtual void ThreadedElementLoopBase< RangeType >::printGeneralExecutionInformation ( ) const
inlineprotectedvirtual

◆ resetExecPrintedSets()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::resetExecPrintedSets ( ) const
protected

Resets the set of blocks and boundaries visited.

Definition at line 454 of file ThreadedElementLoopBase.h.

455 {
456  _blocks_exec_printed.clear();
457  _boundaries_exec_printed.clear();
458 }
std::set< SubdomainID > _blocks_exec_printed
Keep track of which blocks were visited.
std::set< BoundaryID > _boundaries_exec_printed
Keep track of which boundaries were visited.

◆ shouldComputeInternalSide()

template<typename RangeType >
bool ThreadedElementLoopBase< RangeType >::shouldComputeInternalSide ( const Elem &  elem,
const Elem &  neighbor 
) const
protectedvirtual

Whether to compute the internal side for the provided element-neighbor pair.

Typically this will return true if the element id is less than the neighbor id when the elements are equal level, or when the element is more refined than the neighbor, and then false otherwise. One type of loop where the logic will be different is when projecting stateful material properties

Reimplemented in ProjectMaterialProperties, NonlinearThread, and FlagElementsThread.

Definition at line 429 of file ThreadedElementLoopBase.h.

Referenced by NonlinearThread::shouldComputeInternalSide().

431 {
432  auto level = [this](const auto & elem_arg)
433  {
434  if (_mesh.doingPRefinement())
435  return elem_arg.p_level();
436  else
437  return elem_arg.level();
438  };
439  const auto elem_id = elem.id(), neighbor_id = neighbor.id();
440  const auto elem_level = level(elem), neighbor_level = level(neighbor);
441 
442  // When looping over elements and then sides, we need to make sure that we do not duplicate
443  // effort, e.g. if a face is shared by element 1 and element 2, then we do not want to do compute
444  // work both when we are visiting element 1 *and* then later when visiting element 2. Our rule is
445  // to only compute when we are visiting the element that has the lower element id when element and
446  // neighbor are of the same adaptivity level, and then if they are not of the same level, then
447  // we only compute when we are visiting the finer element
448  return (neighbor.active() && (neighbor_level == elem_level) && (elem_id < neighbor_id)) ||
449  (neighbor_level < elem_level);
450 }
void doingPRefinement(bool doing_p_refinement)
Indicate whether the kind of adaptivity we&#39;re doing is p-refinement.
Definition: MooseMesh.h:1365

◆ subdomainChanged()

template<typename RangeType >
void ThreadedElementLoopBase< RangeType >::subdomainChanged ( )
virtual

Called every time the current subdomain changes (i.e.

the subdomain of this element is not the same as the subdomain of the last element). Beware of over-using this! You might think that you can do some expensive stuff in here and get away with it... but there are applications that have TONS of subdomains....

Reimplemented in ComputeUserObjectsThread, NonlinearThread, ComputeDiracThread, ProjectMaterialProperties, ComputeIndicatorThread, ComputeMaterialsObjectThread, ComputeElemAuxVarsThread< AuxKernelType >, and ComputeMarkerThread.

Definition at line 417 of file ThreadedElementLoopBase.h.

418 {
419 }

Member Data Documentation

◆ _blocks_exec_printed

template<typename RangeType>
std::set<SubdomainID> ThreadedElementLoopBase< RangeType >::_blocks_exec_printed
mutableprotected

Keep track of which blocks were visited.

Definition at line 190 of file ThreadedElementLoopBase.h.

◆ _boundaries_exec_printed

template<typename RangeType>
std::set<BoundaryID> ThreadedElementLoopBase< RangeType >::_boundaries_exec_printed
mutableprotected

Keep track of which boundaries were visited.

Definition at line 193 of file ThreadedElementLoopBase.h.

◆ _mesh

template<typename RangeType>
MooseMesh& ThreadedElementLoopBase< RangeType >::_mesh
protected

Definition at line 165 of file ThreadedElementLoopBase.h.

◆ _neighbor_subdomain

template<typename RangeType>
SubdomainID ThreadedElementLoopBase< RangeType >::_neighbor_subdomain
protected

The subdomain for the current neighbor.

Definition at line 175 of file ThreadedElementLoopBase.h.

◆ _old_neighbor_subdomain

template<typename RangeType>
SubdomainID ThreadedElementLoopBase< RangeType >::_old_neighbor_subdomain
protected

The subdomain for the last neighbor.

Definition at line 178 of file ThreadedElementLoopBase.h.

◆ _old_subdomain

template<typename RangeType>
SubdomainID ThreadedElementLoopBase< RangeType >::_old_subdomain
protected

The subdomain for the last element.

Definition at line 172 of file ThreadedElementLoopBase.h.

◆ _subdomain

template<typename RangeType>
SubdomainID ThreadedElementLoopBase< RangeType >::_subdomain
protected

The subdomain for the current element.

Definition at line 169 of file ThreadedElementLoopBase.h.

◆ _tid

template<typename RangeType>
THREAD_ID ThreadedElementLoopBase< RangeType >::_tid
protected

Definition at line 166 of file ThreadedElementLoopBase.h.


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