https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ElemIndexHelper Class Reference

Helper for setting up a contiguous index for a given range of elements that are known by this processor. More...

#include <ElemIndexHelper.h>

Public Member Functions

 ElemIndexHelper (libMesh::MeshBase &mesh, const std::string &extra_elem_integer_name)
 Constructor.
 
void initialize (const libMesh::SimpleRange< libMesh::MeshBase::element_iterator > elems)
 Initializes the indices in a contiguous manner for the given element range.
 
bool hasIndex (const libMesh::Elem *elem) const
 Whether or not the element elem has an index set for it using this object.
 
libMesh::dof_id_type getIndex (const libMesh::Elem *elem) const
 Get the index associated with the element elem.
 
libMesh::dof_id_type maxIndex () const
 Gets the maximum index generated using this object.
 

Private Attributes

libMesh::MeshBase_mesh
 
unsigned int _extra_integer
 The extra elem integer that stores the index.
 
bool _initialized
 Whether or not this object is initialized.
 
libMesh::dof_id_type _max_index
 The max index generated.
 

Detailed Description

Helper for setting up a contiguous index for a given range of elements that are known by this processor.

The contiguous index is useful for indexing into alternate data structures for each element without the need for a map.

The index is stored on each elem for quick access.

Definition at line 29 of file ElemIndexHelper.h.

Constructor & Destructor Documentation

◆ ElemIndexHelper()

ElemIndexHelper::ElemIndexHelper ( libMesh::MeshBase mesh,
const std::string &  extra_elem_integer_name 
)

Constructor.

Parameters
meshThe mesh that contains the elements that are to be index into.
extra_elem_integer_nameA name for the extra element integer that will store the index.

Make sure to call initialize() after construction!

Definition at line 14 of file ElemIndexHelper.C.

16{
17 _extra_integer = mesh.add_elem_integer(extra_elem_integer_name);
18}
libMesh::MeshBase & _mesh
bool _initialized
Whether or not this object is initialized.
unsigned int _extra_integer
The extra elem integer that stores the index.
unsigned int add_elem_integer(std::string name, bool allocate_data=true, dof_id_type default_value=DofObject::invalid_id)
MeshBase & mesh
const unsigned int invalid_uint

Member Function Documentation

◆ getIndex()

libMesh::dof_id_type ElemIndexHelper::getIndex ( const libMesh::Elem elem) const
inline

Get the index associated with the element elem.

Definition at line 61 of file ElemIndexHelper.h.

62 {
63 mooseAssert(hasIndex(elem), "Elem not in indexed range");
65 }
bool hasIndex(const libMesh::Elem *elem) const
Whether or not the element elem has an index set for it using this object.
dof_id_type get_extra_integer(const unsigned int index) const

Referenced by RayTracingStudy::getInternalSidesets(), RayTracingStudy::internalSidesetSetup(), RayTracingStudy::nonPlanarSideSetup(), and RayTracingStudy::sideIsNonPlanar().

◆ hasIndex()

bool ElemIndexHelper::hasIndex ( const libMesh::Elem elem) const
inline

Whether or not the element elem has an index set for it using this object.

Definition at line 50 of file ElemIndexHelper.h.

51 {
52 mooseAssert(elem, "Null elem");
53 mooseAssert(_initialized, "Not initialized");
54 mooseAssert(_mesh.query_elem_ptr(elem->id()), "Not an elem of the mesh");
56 }
static constexpr dof_id_type invalid_id
dof_id_type id() const
virtual const Elem * query_elem_ptr(const dof_id_type i) const=0

Referenced by getIndex().

◆ initialize()

void ElemIndexHelper::initialize ( const libMesh::SimpleRange< libMesh::MeshBase::element_iterator elems)

Initializes the indices in a contiguous manner for the given element range.

Definition at line 21 of file ElemIndexHelper.C.

22{
23 // First, invalidate the integers for all elements that we know about
24 // so that we can tell when getting an index for an elem if said elem
25 // was not in the range
26 for (Elem * elem : _mesh.element_ptr_range())
27 elem->set_extra_integer(_extra_integer, DofObject::invalid_id);
28
29 // Set the index in a contiguous manner for all elements in the range
30 dof_id_type next_index = 0;
31 for (Elem * elem : elems)
32 elem->set_extra_integer(_extra_integer, next_index++);
33
34 // Store the max index so that users can use it to initialize data
35 // structures that will use these indices
36 _max_index = next_index - 1;
37
38 _initialized = true;
39}
libMesh::dof_id_type _max_index
The max index generated.
uint8_t dof_id_type

Referenced by RayTracingStudy::localElemIndexSetup().

◆ maxIndex()

libMesh::dof_id_type ElemIndexHelper::maxIndex ( ) const
inline

Gets the maximum index generated using this object.

Useful for initializing data structures that will be indexed using the indices provided by this object.

Definition at line 73 of file ElemIndexHelper.h.

73{ return _max_index; }

Referenced by RayTracingStudy::internalSidesetSetup(), and RayTracingStudy::nonPlanarSideSetup().

Member Data Documentation

◆ _extra_integer

unsigned int ElemIndexHelper::_extra_integer
private

The extra elem integer that stores the index.

Definition at line 79 of file ElemIndexHelper.h.

Referenced by ElemIndexHelper(), getIndex(), hasIndex(), and initialize().

◆ _initialized

bool ElemIndexHelper::_initialized
private

Whether or not this object is initialized.

Definition at line 81 of file ElemIndexHelper.h.

Referenced by hasIndex(), and initialize().

◆ _max_index

libMesh::dof_id_type ElemIndexHelper::_max_index
private

The max index generated.

Definition at line 83 of file ElemIndexHelper.h.

Referenced by initialize(), and maxIndex().

◆ _mesh

libMesh::MeshBase& ElemIndexHelper::_mesh
private

Definition at line 77 of file ElemIndexHelper.h.

Referenced by hasIndex(), and initialize().


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