17 #include "libmesh/distributed_mesh.h" 18 #include "libmesh/elem.h" 29 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
30 params.
addClassDescription(
"Defines new sidesets using currently-defined sideset IDs inside or " 31 "outside of a bounding box.");
33 MooseEnum location(
"INSIDE OUTSIDE",
"INSIDE");
36 "bottom_left",
"The bottom left point (in x,y,z with spaces in-between).");
38 "top_right",
"The bottom left point (in x,y,z with spaces in-between).");
41 "Subdomain id to set for inside/outside the bounding box",
42 "The parameter 'block_id' is not used.");
45 "Boundary id on specified block within the bounding box to select",
46 "boundary_id_old is deprecated, use boundaries_old with names or ids");
49 "Boundary id on specified block within the bounding box to assign",
50 "boundary_id_new is deprecated, use boundary_new with a name or id");
51 params.
addParam<std::vector<BoundaryName>>(
53 "The list of boundaries on the specified block within the bounding box to be modified");
54 params.
addParam<BoundaryName>(
"boundary_new",
55 "Boundary on specified block within the bounding box to assign");
56 params.
addParam<
bool>(
"boundary_id_overlap",
58 "Set to true if boundaries need to overlap on sideset to be detected.");
60 "location", location,
"Control of where the subdomain id is to be set");
68 _input(getMesh(
"input")),
72 _boundary_id_overlap(parameters.
get<bool>(
"boundary_id_overlap"))
79 mooseError(
"Either boundaries_old or boundary_id_old (deprecated) must be specified.");
86 mooseError(
"Either boundary_new or boundary_id_new (deprecated) must be specified.");
89 std::unique_ptr<MeshBase>
92 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
93 if (!
mesh->is_replicated())
94 mooseError(
"SideSetsFromBoundingBoxGenerator is not implemented for distributed meshes");
97 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
98 boundary_info.build_node_list_from_side_list();
100 bool found_element =
false;
101 bool found_side_sets =
false;
102 const bool inside = (
_location ==
"INSIDE");
108 for (std::size_t i = 0; i < boundary_ids.size(); ++i)
111 "boundaries",
"The boundary '",
_boundaries_old[i],
"' was not found within the mesh");
129 for (
const auto & elem :
mesh->active_element_ptr_range())
132 bool contains =
_bounding_box.contains_point(elem->vertex_average());
135 if (contains == inside)
137 found_element =
true;
139 for (
unsigned int side = 0; side < elem->n_sides(); side++)
141 for (
auto boundary_id : boundary_ids)
143 if (boundary_info.has_boundary_id(elem, side, boundary_id))
146 boundary_info.add_side(elem, side, boundary_id_new);
147 found_side_sets =
true;
151 if (!found_element && inside)
152 mooseError(
"No elements found within the bounding box");
154 if (!found_element && !inside)
155 mooseError(
"No elements found outside the bounding box");
157 if (!found_side_sets)
158 mooseError(
"No side sets found on active elements within the bounding box");
163 if (boundary_ids.size() < 2)
166 " Must be 2 boundary inputs or more.");
168 bool found_node =
false;
171 for (
auto node =
mesh->active_nodes_begin(); node !=
mesh->active_nodes_end(); ++node)
177 std::vector<boundary_id_type> node_boundary_ids;
178 boundary_info.boundary_ids(*node, node_boundary_ids);
181 std::sort(node_boundary_ids.begin(), node_boundary_ids.end());
182 std::sort(boundary_ids.begin(), boundary_ids.end());
186 if (std::includes(node_boundary_ids.begin(),
187 node_boundary_ids.end(),
188 boundary_ids.begin(),
191 boundary_info.add_node(*node, boundary_id_new);
198 mooseError(
"No nodes found within the bounding box");
201 mesh->set_isnt_prepared();
SideSetsFromBoundingBoxGenerator(const InputParameters ¶meters)
const BoundaryID INVALID_BOUNDARY_ID
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
BoundaryName _boundary_new
New boundary to assign.
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.
MeshGenerator for defining sidesets inside or outside of a bounding box.
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
Gets the boundary ID associated with the given BoundaryName.
std::unique_ptr< MeshBase > & _input
std::vector< BoundaryName > _boundaries_old
List of boundary names to select.
BoundingBox _bounding_box
Bounding box for testing element centroids against.
registerMooseObject("MooseApp", SideSetsFromBoundingBoxGenerator)
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.
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()
MooseEnum _location
ID location (inside of outside of box)
const bool _boundary_id_overlap
Flag to determine if the provided boundaries need to overlap.
static InputParameters validParams()
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.
const InputParameters & parameters() const
Get the parameters of the object.
BoundaryID getNextFreeBoundaryID(MeshBase &input_mesh)
Checks input mesh and returns the largest boundary ID in the mesh plus one, which is a boundary ID in...
MeshGenerators are objects that can modify or add to an existing mesh.