www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | 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 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...
 

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

Private Member Functions

virtual bool shouldComputeInternalSide (const Elem &elem, const Elem &neighbor) const
 Whether to compute the internal side for the provided element-neighbor pair. More...
 

Detailed Description

template<typename RangeType>
class ThreadedElementLoopBase< RangeType >

Base class for assembly-like calculations.

Definition at line 23 of file ThreadedElementLoopBase.h.

Constructor & Destructor Documentation

◆ ThreadedElementLoopBase() [1/2]

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

Definition at line 198 of file ThreadedElementLoopBase.h.

198  : _mesh(mesh)
199 {
200 }

◆ ThreadedElementLoopBase() [2/2]

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

Definition at line 203 of file ThreadedElementLoopBase.h.

205  : _mesh(x._mesh)
206 {
207 }

◆ ~ThreadedElementLoopBase()

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

Definition at line 210 of file ThreadedElementLoopBase.h.

211 {
212 }

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< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 144 of file ThreadedElementLoopBase.h.

144 {};

◆ 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< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 151 of file ThreadedElementLoopBase.h.

151 { 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< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 398 of file ThreadedElementLoopBase.h.

399 {
400 }

◆ 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 357 of file ThreadedElementLoopBase.h.

361 {
362 }

◆ onElement()

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

◆ 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 384 of file ThreadedElementLoopBase.h.

387 {
388 }

◆ 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 378 of file ThreadedElementLoopBase.h.

379 {
380 }

◆ operator()()

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

Reimplemented in NonlinearThread, and ComputeJacobianForScalingThread.

Definition at line 216 of file ThreadedElementLoopBase.h.

Referenced by NonlinearThread::operator()().

217 {
218  try
219  {
220  try
221  {
222  ParallelUniqueId puid;
223  _tid = bypass_threading ? 0 : puid.id;
224 
225  pre();
227 
230  typename RangeType::const_iterator el = range.begin();
231  for (el = range.begin(); el != range.end(); ++el)
232  {
233  if (!keepGoing())
234  break;
235 
236  const Elem * elem = *el;
237 
238  preElement(elem);
239 
241  _subdomain = elem->subdomain_id();
242  if (_subdomain != _old_subdomain)
243  {
246  }
247 
248  onElement(elem);
249 
250  if (elem->subdomain_id() == Moose::INTERNAL_SIDE_LOWERD_ID ||
251  elem->subdomain_id() == Moose::BOUNDARY_SIDE_LOWERD_ID)
252  {
253  postElement(elem);
254  continue;
255  }
256 
257  for (unsigned int side = 0; side < elem->n_sides(); side++)
258  {
259  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
260  const Elem * lower_d_elem = _mesh.getLowerDElem(elem, side);
261 
262  if (boundary_ids.size() > 0)
263  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
264  it != boundary_ids.end();
265  ++it)
266  {
267  preBoundary(elem, side, *it, lower_d_elem);
269  onBoundary(elem, side, *it, lower_d_elem);
270  }
271 
272  const Elem * neighbor = elem->neighbor_ptr(side);
273  if (neighbor)
274  {
275  preInternalSide(elem, side);
276 
278  _neighbor_subdomain = neighbor->subdomain_id();
281 
282  if (shouldComputeInternalSide(*elem, *neighbor))
283  onInternalSide(elem, side);
284 
285  if (boundary_ids.size() > 0)
286  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
287  it != boundary_ids.end();
288  ++it)
289  onInterface(elem, side, *it);
290 
291  postInternalSide(elem, side);
292  }
293  } // sides
294 
295  postElement(elem);
296  } // range
297 
298  post();
300  }
301  catch (libMesh::LogicError & e)
302  {
303  mooseException("We caught a libMesh error in ThreadedElementLoopBase:", e.what());
304  }
305  catch (MetaPhysicL::LogicError & e)
306  {
308  }
309  }
310  catch (MooseException & e)
311  {
313  }
314 }
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)
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition: MooseError.C:98
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:1483
const SubdomainID BOUNDARY_SIDE_LOWERD_ID
Definition: MooseTypes.C:21
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:22
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.
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.
const SubdomainID INTERNAL_SIDE_LOWERD_ID
Definition: MooseTypes.C:20
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. ...
Definition: MooseMesh.C:2719
SubdomainID _subdomain
The subdomain for the current element.
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 342 of file ThreadedElementLoopBase.h.

343 {
344 }

◆ 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 372 of file ThreadedElementLoopBase.h.

373 {
374 }

◆ pre()

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

Called before the element range loop.

Reimplemented in ComputeDiracThread.

Definition at line 318 of file ThreadedElementLoopBase.h.

319 {
320 }

◆ 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< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 348 of file ThreadedElementLoopBase.h.

352 {
353 }

◆ preElement()

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

Called before the element assembly.

Parameters
elem- active element

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

Definition at line 336 of file ThreadedElementLoopBase.h.

337 {
338 }

◆ 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< DistElemRange >, and ThreadedElementLoop< ConstElemPointerRange >.

Definition at line 366 of file ThreadedElementLoopBase.h.

367 {
368 }

◆ 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 173 of file ThreadedElementLoopBase.h.

173 {}

◆ 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 176 of file ThreadedElementLoopBase.h.

176 {}

◆ 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 429 of file ThreadedElementLoopBase.h.

430 {
431  _blocks_exec_printed.clear();
432  _boundaries_exec_printed.clear();
433 }
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
privatevirtual

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, and FlagElementsThread.

Definition at line 404 of file ThreadedElementLoopBase.h.

406 {
407  auto level = [this](const auto & elem_arg)
408  {
409  if (_mesh.doingPRefinement())
410  return elem_arg.p_level();
411  else
412  return elem_arg.level();
413  };
414  const auto elem_id = elem.id(), neighbor_id = neighbor.id();
415  const auto elem_level = level(elem), neighbor_level = level(neighbor);
416 
417  // When looping over elements and then sides, we need to make sure that we do not duplicate
418  // effort, e.g. if a face is shared by element 1 and element 2, then we do not want to do compute
419  // work both when we are visiting element 1 *and* then later when visiting element 2. Our rule is
420  // to only compute when we are visiting the element that has the lower element id when element and
421  // neighbor are of the same adaptivity level, and then if they are not of the same level, then
422  // we only compute when we are visiting the finer element
423  return (neighbor.active() && (neighbor_level == elem_level) && (elem_id < neighbor_id)) ||
424  (neighbor_level < elem_level);
425 }
void doingPRefinement(bool doing_p_refinement)
Indicate whether the kind of adaptivity we&#39;re doing is p-refinement.
Definition: MooseMesh.h:1325

◆ 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 392 of file ThreadedElementLoopBase.h.

393 {
394 }

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 179 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 182 of file ThreadedElementLoopBase.h.

◆ _mesh

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

Definition at line 154 of file ThreadedElementLoopBase.h.

◆ _neighbor_subdomain

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

The subdomain for the current neighbor.

Definition at line 164 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 167 of file ThreadedElementLoopBase.h.

◆ _old_subdomain

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

The subdomain for the last element.

Definition at line 161 of file ThreadedElementLoopBase.h.

◆ _subdomain

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

The subdomain for the current element.

Definition at line 158 of file ThreadedElementLoopBase.h.

◆ _tid

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

Definition at line 155 of file ThreadedElementLoopBase.h.


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