15 #include "libmesh/node.h" 23 MooseEnum location(
"INSIDE OUTSIDE",
"INSIDE");
25 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
27 "Assigns all of the nodes either inside or outside of a bounding box to a new nodeset.");
29 "The name of the nodeset to create");
32 "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
35 "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
36 params.
addParam<
MooseEnum>(
"location", location,
"Control of where the nodeset is to be set");
43 _input(getMesh(
"input")),
44 _location(getParam<
MooseEnum>(
"location")),
50 std::unique_ptr<MeshBase>
53 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
56 std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>(
"new_boundary");
57 std::vector<BoundaryID> boundary_ids =
59 if (boundary_ids.size() != 1)
60 mooseError(
"Only one boundary ID can be assigned to a nodeset using a bounding box!");
63 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
65 bool found_node =
false;
66 const bool inside = (
_location ==
"INSIDE");
69 for (
auto & node :
as_range(
mesh->active_nodes_begin(),
mesh->active_nodes_end()))
72 boundary_info.add_node(node, boundary_ids[0]);
81 mooseError(
"No nodes found within the bounding box");
83 boundary_info.nodeset_name(boundary_ids[0]) = boundary_names[0];
85 mesh->set_isnt_prepared();
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const Parallel::Communicator & comm() const
Selects a set of nodes and assigns a nodeset name to them based on the bounding box specified...
BoundingBoxNodeSetGenerator(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.
registerMooseObject("MooseApp", BoundingBoxNodeSetGenerator)
MooseEnum _location
Select nodes on the 'inside' or the 'outside' of the bounding box.
std::unique_ptr< MeshBase > & _input
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
static InputParameters validParams()
BoundingBox _bounding_box
Bounding box for testing element centroids against. Note that.
void max(const T &r, T &o, Request &req) const
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.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()