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
12ElemIndexHelper::ElemIndexHelper(MeshBase & mesh, const std::string & extra_elem_integer_name)
13 : _mesh(mesh), _extra_integer(invalid_uint), _initialized(false)
14{
15 _extra_integer = mesh.add_elem_integer(extra_elem_integer_name);
16}
17
18void
19ElemIndexHelper::initialize(const SimpleRange<MeshBase::element_iterator> elems)
20{
21 // First, invalidate the integers for all elements that we know about
22 // so that we can tell when getting an index for an elem if said elem
23 // was not in the range
24 for (Elem * elem : _mesh.element_ptr_range())
25 elem->set_extra_integer(_extra_integer, DofObject::invalid_id);
26
27 // Set the index in a contiguous manner for all elements in the range
28 dof_id_type next_index = 0;
29 for (Elem * elem : elems)
30 elem->set_extra_integer(_extra_integer, next_index++);
31
32 // Store the max index so that users can use it to initialize data
33 // structures that will use these indices
34 _max_index = next_index - 1;
35
36 _initialized = true;
37}
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.
MeshBase & mesh