https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ElemIndexHelper.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "ElemIndexHelper.h"
11
12using namespace libMesh;
13
14ElemIndexHelper::ElemIndexHelper(MeshBase & mesh, const std::string & extra_elem_integer_name)
15 : _mesh(mesh), _extra_integer(invalid_uint), _initialized(false)
16{
17 _extra_integer = mesh.add_elem_integer(extra_elem_integer_name);
18}
19
20void
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}
ElemIndexHelper(libMesh::MeshBase &mesh, const std::string &extra_elem_integer_name)
Constructor.
libMesh::MeshBase & _mesh
libMesh::dof_id_type _max_index
The max index generated.
bool _initialized
Whether or not this object is initialized.
void initialize(const libMesh::SimpleRange< libMesh::MeshBase::element_iterator > elems)
Initializes the indices in a contiguous manner for the given element range.
unsigned int _extra_integer
The extra elem integer that stores the index.
static constexpr dof_id_type invalid_id
unsigned int add_elem_integer(std::string name, bool allocate_data=true, dof_id_type default_value=DofObject::invalid_id)
MeshBase & mesh
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
const unsigned int invalid_uint
uint8_t dof_id_type