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 "boundary_new",
"Boundary on specified block within the bounding box to assign");
44 params.
addParam<
bool>(
"boundary_id_overlap",
46 "Set to true if boundaries need to overlap on sideset to be detected.");
48 "location", location,
"Control of where the subdomain id is to be set");
63 _boundary_id_overlap(parameters.
get<bool>(
"boundary_id_overlap"))
67 const std::vector<std::string> incompatible_params = {
"normal",
69 "include_only_external_sides",
70 "included_subdomains",
71 "included_neighbors"};
72 for (
const auto & param_name : incompatible_params)
74 paramError(param_name,
"Parameter should not be used with boundary_id_overlap = true.");
80 std::unique_ptr<MeshBase>
83 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
84 if (!
mesh->is_replicated())
85 mooseError(
"SideSetsFromBoundingBoxGenerator is not implemented for distributed meshes");
91 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
92 boundary_info.build_node_list_from_side_list();
94 bool found_element =
false;
95 bool found_side_sets =
false;
96 const bool inside = (
_location ==
"INSIDE");
114 const std::vector<Point> & face_normals =
_fe_face->get_normals();
117 for (
const auto & elem :
mesh->active_element_ptr_range())
125 found_element =
true;
127 for (
const auto & side :
make_range(elem->n_sides()))
131 const Point face_normal = face_normals[0];
137 boundary_info.remove_side(elem, side);
138 boundary_info.add_side(elem, side, boundary_id_new);
139 found_side_sets =
true;
144 if (!found_element && inside)
145 mooseError(
"No elements found within the bounding box");
147 if (!found_element && !inside)
148 mooseError(
"No elements found outside the bounding box");
150 if (!found_side_sets)
151 mooseError(
"No side sets found on active elements within the bounding box");
159 " Must be 2 boundary inputs or more.");
161 bool found_node =
false;
164 for (
auto node =
mesh->active_nodes_begin(); node !=
mesh->active_nodes_end(); ++node)
170 std::vector<boundary_id_type> node_boundary_ids;
171 boundary_info.boundary_ids(*node, node_boundary_ids);
174 std::sort(node_boundary_ids.begin(), node_boundary_ids.end());
179 if (std::includes(node_boundary_ids.begin(),
180 node_boundary_ids.end(),
184 boundary_info.add_node(*node, boundary_id_new);
191 mooseError(
"No nodes found within the bounding box");
194 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.