https://mooseframework.inl.gov
ExtraElementIntegerDivision.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 
11 #include "MooseMesh.h"
12 
13 #include "libmesh/mesh_base.h"
14 #include "libmesh/elem.h"
15 
17 
20 {
22  params.addClassDescription(
23  "Divide the mesh by increasing extra element IDs. The division will be contiguously "
24  "numbered even if the extra element ids are not");
25  params.addRequiredParam<ExtraElementIDName>("extra_id_name",
26  "The name of the extra element ID in the mesh");
27  return params;
28 }
29 
31  : MeshDivision(parameters), _extra_id_name(getParam<ExtraElementIDName>("extra_id_name"))
32 {
33  if (!_mesh.getMesh().has_elem_integer(_extra_id_name))
34  paramError("extra_id_name", "The source element ID does not exist on the input mesh");
35  _extra_id = _mesh.getMesh().get_elem_integer_index(_extra_id_name);
36 
38  _mesh_fully_indexed = true;
39 }
40 
41 void
43 {
44  // The ExtraElementID may not be contiguously numbered so we gather them all first
45  std::set<libMesh::dof_id_type> extra_ids;
46  for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range())
47  extra_ids.insert(elem->get_extra_integer(_extra_id));
48  _mesh.comm().set_union(extra_ids);
49  setNumDivisions(extra_ids.size());
50 
51  unsigned int i = 0;
52  for (const auto extra_id : extra_ids)
53  _extra_ids_to_division_index[extra_id] = i++;
54 }
55 
56 unsigned int
58 {
59  return libmesh_map_find(_extra_ids_to_division_index, elem.get_extra_integer(_extra_id));
60 }
61 
62 unsigned int
64 {
65  const auto & pl = _mesh.getMesh().sub_point_locator();
66  // There could be more than one elem if we are on the edge between two elements
67  std::set<const Elem *> candidates;
68  (*pl)(pt, candidates);
69 
70  // By convention we will use the element with the lowest extra element id
71  // There could be other conventions: use lowest element if for example
72  const Elem * elem = nullptr;
74  for (const auto elem_ptr : candidates)
75  if (elem_ptr->get_extra_integer(_extra_id) < min_extra_id)
76  {
77  elem = elem_ptr;
78  min_extra_id = elem_ptr->get_extra_integer(_extra_id);
79  }
80 
81  return libmesh_map_find(_extra_ids_to_division_index, elem->get_extra_integer(_extra_id));
82 }
const ExtraElementIDName & _extra_id_name
Name of the extra element id to use to subdivide.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
virtual unsigned int divisionIndex(const Point &pt) const override
Return the index of the division to which the point belongs.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unordered_map< unsigned int, unsigned int > _extra_ids_to_division_index
Map from extra element ids to division index. Created on calls to initialize()
const Parallel::Communicator & comm() const
Base class for MeshDivision objects.
Definition: MeshDivision.h:35
unsigned int _extra_id
Extra element ID used for the subdivision.
const MooseMesh & _mesh
Mesh that is being divided.
Definition: MeshDivision.h:74
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
auto max(const L &left, const R &right)
Divides the mesh based on the extra element IDs.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3448
bool _mesh_fully_indexed
Whether the mesh is fully covered / indexed, all elements and points have a valid index...
Definition: MeshDivision.h:77
void setNumDivisions(const unsigned int ndivs)
Set the number of divisions.
Definition: MeshDivision.h:65
virtual void initialize() override
Set up any data members that would be necessary to obtain the division indices.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
static InputParameters validParams()
ExtraElementIntegerDivision(const InputParameters &parameters)
static InputParameters validParams()
Class constructor.
Definition: MeshDivision.C:14
registerMooseObject("MooseApp", ExtraElementIntegerDivision)
uint8_t dof_id_type
void set_union(T &data, const unsigned int root_id) const