16 #include "libmesh/elem.h" 23 MooseEnum location(
"INSIDE OUTSIDE",
"INSIDE");
27 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
28 params.
addClassDescription(
"Changes the subdomain ID of elements either (XOR) inside or outside " 29 "the specified box to the specified ID.");
31 "bottom_left",
"The bottom left point (in x,y,z with spaces in-between).");
33 "top_right",
"The bottom left point (in x,y,z with spaces in-between).");
35 "block_id",
"Subdomain id to set for inside/outside the bounding box");
37 "block_name",
"Subdomain name to set for inside/outside the bounding box (optional)");
39 "location", location,
"Control of where the subdomain id is to be set");
40 params.
addParam<std::vector<SubdomainName>>(
41 "restricted_subdomains",
42 "Only reset subdomain ID for given subdomains within the bounding box");
44 params.
addParam<std::string>(
"integer_name",
45 "Element integer to be assigned (default to subdomain ID)");
51 _input(getMesh(
"input")),
54 _has_restriction(isParamValid(
"restricted_subdomains")),
60 std::unique_ptr<MeshBase>
63 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
65 std::set<SubdomainID> restricted_ids;
68 auto names = getParam<std::vector<SubdomainName>>(
"restricted_subdomains");
69 for (
auto &
name : names)
73 paramError(
"restricted_subdomains",
"The block '",
name,
"' was not found in the mesh");
81 std::string integer_name = getParam<std::string>(
"integer_name");
83 if (!
mesh->has_elem_integer(integer_name))
84 mooseError(
"Mesh does not have an element integer names as ", integer_name);
86 unsigned int id =
mesh->get_elem_integer_index(integer_name);
89 for (
const auto & elem :
mesh->active_element_ptr_range())
94 bool contains =
_bounding_box.contains_point(elem->vertex_average());
102 for (
const auto & elem :
mesh->element_ptr_range())
107 bool contains =
_bounding_box.contains_point(elem->vertex_average());
114 mesh->subdomain_name(
_block_id) = getParam<SubdomainName>(
"block_name");
117 mesh->set_isnt_prepared();
MeshGenerator for defining a Subdomain inside or outside of a bounding box.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
SubdomainBoundingBoxGenerator(const InputParameters ¶meters)
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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.
std::unique_ptr< MeshBase > & _input
virtual const std::string & name() const
Get the name of the class.
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
subdomain_id_type _block_id
Block ID to assign to the region.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
bool hasSubdomainName(MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
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()
const bool _has_restriction
Whether or not we apply the bounding box only for certain subdomains.
static InputParameters validParams()
registerMooseObject("MooseApp", SubdomainBoundingBoxGenerator)
MooseEnum _location
ID location (inside of outside of box)
BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
Construct a valid bounding box from 2 arbitrary points.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
BoundingBox _bounding_box
Bounding box for testing element centroids against.
MeshGenerators are objects that can modify or add to an existing mesh.