https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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
39}
40
41void
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
56unsigned int
58{
59 return libmesh_map_find(_extra_ids_to_division_index, elem.get_extra_integer(_extra_id));
60}
61
62unsigned 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;
73 libMesh::dof_id_type min_extra_id = std::numeric_limits<int>::max();
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}
registerMooseObject("MooseApp", ExtraElementIntegerDivision)
Divides the mesh based on the extra element IDs.
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()
unsigned int _extra_id
Extra element ID used for the subdivision.
ExtraElementIntegerDivision(const InputParameters &parameters)
virtual void initialize() override
Set up any data members that would be necessary to obtain the division indices.
virtual unsigned int divisionIndex(const Point &pt) const override
Return the index of the division to which the point belongs.
const ExtraElementIDName & _extra_id_name
Name of the extra element id to use to subdivide.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
Base class for MeshDivision objects.
static InputParameters validParams()
Class constructor.
void setNumDivisions(const unsigned int ndivs)
Set the number of divisions.
const MooseMesh & _mesh
Mesh that is being divided.
bool _mesh_fully_indexed
Whether the mesh is fully covered / indexed, all elements and points have a valid index.
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:457
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
void set_union(T &data, const unsigned int root_id) const
const Parallel::Communicator & comm() const
uint8_t dof_id_type