13 #include "libmesh/elem.h" 22 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
25 "Coordinates of planes along the axis. The origin are at x/y/z=0 depending on the axis");
26 params.
addParam<std::vector<unsigned int>>(
"num_ids_per_plane",
"Number of unique ids per plane");
29 params.
addRequiredParam<std::string>(
"id_name",
"Name of extra integer ID set");
30 params.
addParam<
Real>(
"tolerance", 1.0E-4,
"Tolerance for plane coordinate check");
31 params.
addClassDescription(
"Adds an extra element integer that identifies planes in a mesh.");
37 _input(getMesh(
"input")),
38 _axis_index(getParam<
MooseEnum>(
"plane_axis")),
39 _element_id_name(getParam<
std::string>(
"id_name"))
42 _planes = getParam<std::vector<Real>>(
"plane_coordinates");
46 std::vector<Real> base_planes = getParam<std::vector<Real>>(
"plane_coordinates");
47 std::vector<unsigned int> sublayers = getParam<std::vector<unsigned int>>(
"num_ids_per_plane");
48 if (base_planes.size() != sublayers.size() + 1)
50 "Sizes of 'plane_coordinates' and 'num_ids_per_plane' disagree");
51 _planes.push_back(base_planes[0]);
52 for (
unsigned int i = 0; i < sublayers.size(); ++i)
54 Real layer_size = (base_planes[i + 1] - base_planes[i]) / (
Real)sublayers[i];
56 paramError(
"plane_coordinates",
"Plane coordinates must be in increasing order");
58 for (
unsigned int j = 0; j < sublayers[i]; ++j)
63 paramError(
"plane_coordinates",
"Size of 'plane_coordinates' should be at least two");
66 std::unique_ptr<MeshBase>
69 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
71 paramError(
"plane_axis",
"Plane axis must be contained in the mesh. Check mesh dimension");
72 unsigned int extra_id_index = 0;
79 "id_name",
"An element integer with the name '",
_element_id_name,
"' already exists");
83 const Real tol = getParam<Real>(
"tolerance");
84 for (
auto & elem :
mesh->active_element_ptr_range())
86 const int layer_id =
getPlaneID(elem->vertex_average());
87 for (
unsigned int i = 0; i < elem->n_nodes(); ++i)
89 const Point & p = elem->point(i) - (elem->point(i) - elem->vertex_average()) * tol;
91 mooseError(
"Element at ", elem->vertex_average(),
" is cut by the planes");
93 elem->set_extra_integer(extra_id_index, layer_id);
103 mooseError(
"The planes do not cover element at ", p);
106 for (
unsigned int layer_id = 0; layer_id <
_planes.size() - 1; ++layer_id)
Assigns plane extra ID for existing 3D meshes.
const unsigned int _axis_index
index of plane axis
PlaneIDMeshGenerator(const InputParameters ¶meters)
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
std::unique_ptr< MeshBase > & _input
input mesh for adding reporting ID
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("MooseApp", PlaneIDMeshGenerator)
bool absoluteFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within an absolute ...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
static InputParameters validParams()
void paramWarning(const std::string ¶m, Args... args) const
Emits a warning prefixed with the file and line number of the given param (from the input file) along...
MeshGenerators are objects that can modify or add to an existing mesh.
std::vector< Real > _planes
coordinates of planes
const std::string _element_id_name
name of integer ID
int getPlaneID(const Point &p) const
get plane ID for given plane coordiantes
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.