17 #include "libmesh/distributed_mesh.h" 18 #include "libmesh/elem.h" 29 params.
addClassDescription(
"Defines new sidesets using currently-defined sideset IDs inside or " 30 "outside of a bounding box.");
32 MooseEnum location(
"INSIDE OUTSIDE",
"INSIDE");
35 "bottom_left",
"The bottom left point (in x,y,z with spaces in-between).");
37 "top_right",
"The bottom left point (in x,y,z with spaces in-between).");
40 "Subdomain id to set for inside/outside the bounding box",
41 "The parameter 'block_id' is not used.");
43 params.
addParam<std::vector<BoundaryName>>(
45 "The list of boundaries on the specified block within the bounding box to be modified");
46 params.
deprecateParam(
"boundaries_old",
"included_boundaries",
"4/01/2025");
48 "boundary_new",
"Boundary on specified block within the bounding box to assign");
49 params.
addParam<
bool>(
"boundary_id_overlap",
51 "Set to true if boundaries need to overlap on sideset to be detected.");
53 "location", location,
"Control of where the subdomain id is to be set");
68 _boundary_id_overlap(parameters.
get<bool>(
"boundary_id_overlap"))
72 const std::vector<std::string> incompatible_params = {
"normal",
74 "include_only_external_sides",
75 "included_subdomains",
76 "included_neighbors"};
77 for (
const auto & param_name : incompatible_params)
79 paramError(param_name,
"Parameter should not be used with boundary_id_overlap = true.");
85 std::unique_ptr<MeshBase>
88 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
89 if (!
mesh->is_replicated())
90 mooseError(
"SideSetsFromBoundingBoxGenerator is not implemented for distributed meshes");
96 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
97 boundary_info.build_node_list_from_side_list();
99 bool found_element =
false;
100 bool found_side_sets =
false;
101 const bool inside = (
_location ==
"INSIDE");
119 const std::vector<Point> & face_normals =
_fe_face->get_normals();
122 for (
const auto & elem :
mesh->active_element_ptr_range())
130 found_element =
true;
132 for (
const auto & side :
make_range(elem->n_sides()))
136 const Point face_normal = face_normals[0];
142 boundary_info.remove_side(elem, side);
143 boundary_info.add_side(elem, side, boundary_id_new);
144 found_side_sets =
true;
149 if (!found_element && inside)
150 mooseError(
"No elements found within the bounding box");
152 if (!found_element && !inside)
153 mooseError(
"No elements found outside the bounding box");
155 if (!found_side_sets)
156 mooseError(
"No side sets found on active elements within the bounding box");
164 " Must be 2 boundary inputs or more.");
166 bool found_node =
false;
169 for (
auto node =
mesh->active_nodes_begin(); node !=
mesh->active_nodes_end(); ++node)
175 std::vector<boundary_id_type> node_boundary_ids;
176 boundary_info.boundary_ids(*node, node_boundary_ids);
179 std::sort(node_boundary_ids.begin(), node_boundary_ids.end());
184 if (std::includes(node_boundary_ids.begin(),
185 node_boundary_ids.end(),
189 boundary_info.add_node(*node, boundary_id_new);
196 mooseError(
"No nodes found within the bounding box");
199 mesh->set_isnt_prepared();
bool elemSideSatisfiesRequirements(const Elem *const elem, const unsigned int side, const MeshBase &mesh, const Point &normal, const Point &face_normal)
Determines whether the given element's side satisfies the following parameters: include_only_external...
std::unique_ptr< MeshBase > & _input
the mesh to add the sidesets to
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 ...
SideSetsFromBoundingBoxGenerator(const InputParameters ¶meters)
const BoundaryID INVALID_BOUNDARY_ID
Point _normal
if specified, then faces are only added if their normal is close to this
const InputParameters & parameters() const
Get the parameters of the object.
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.
const bool _replace
Whether or not to remove the old sidesets (all of them, if any) when adding sidesets.
std::vector< BoundaryName > _boundary_names
The list of new boundary names.
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.
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...
bool contains(std::string_view superstring, std::string_view substring)
static InputParameters validParams()
MooseEnum _location
ID location (inside of outside of box)
std::vector< boundary_id_type > _included_boundary_ids
A list of boundary ids that the side has to be part of, extracted from the included_boundaries parame...
const bool _boundary_id_overlap
Flag to determine if the provided boundaries need to overlap.
static InputParameters validParams()
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
libMesh::BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
Construct a valid bounding box from 2 arbitrary points.
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...
std::unique_ptr< libMesh::FEBase > _fe_face
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
void setup(MeshBase &mesh)
This method is used to construct the FE object so we can compute normals of faces.