15 #include "libmesh/unstructured_mesh.h" 24 MooseEnum algorithm(
"BINARY EXHAUSTIVE",
"BINARY");
26 params.
addRequiredParam<std::vector<MeshGeneratorName>>(
"inputs",
"The input MeshGenerators.");
28 "clear_stitched_boundary_ids",
true,
"Whether or not to clear the stitched boundary IDs");
30 "stitch_boundaries_pairs",
31 "Pairs of boundaries to be stitched together between the 1st mesh in inputs and each " 36 "Control the use of binary search for the nodes of the stitched surfaces.");
37 params.
addParam<
bool>(
"prevent_boundary_ids_overlap",
39 "Whether to re-number boundaries in stitched meshes to prevent merging of " 40 "unrelated boundaries");
42 "Allows multiple mesh files to be stitched together to form a single mesh.");
49 _mesh_ptrs(getMeshes(
"inputs")),
50 _input_names(getParam<
std::vector<MeshGeneratorName>>(
"inputs")),
51 _clear_stitched_boundary_ids(getParam<bool>(
"clear_stitched_boundary_ids")),
52 _stitch_boundaries_pairs(
53 getParam<
std::vector<
std::vector<
std::string>>>(
"stitch_boundaries_pairs")),
55 _prevent_boundary_ids_overlap(getParam<bool>(
"prevent_boundary_ids_overlap"))
59 std::unique_ptr<MeshBase>
65 mooseError(
"StitchedMeshGenerator is only implemented for unstructured meshes");
68 std::vector<std::unique_ptr<UnstructuredMesh>> meshes(
_mesh_ptrs.size() - 1);
72 meshes[i - 1] = dynamic_pointer_cast<UnstructuredMesh>(*
_mesh_ptrs[i]);
75 for (MooseIndex(meshes) i = 0; i < meshes.size(); i++)
83 first = MooseUtils::convert<boundary_id_type>(boundary_pair[0],
true);
87 first =
mesh->get_boundary_info().get_id_by_name(boundary_pair[0]);
89 if (first == BoundaryInfo::invalid_id)
91 std::stringstream error;
93 error <<
"Boundary " << boundary_pair[0] <<
" doesn't exist on mesh '" <<
_input_names[0]
94 <<
"' in generator " <<
name() <<
"\n";
95 error <<
"Boundary (sideset) names that do exist: \n";
96 error <<
" ID : Name\n";
98 auto & sideset_id_name_map =
mesh->get_boundary_info().get_sideset_name_map();
100 for (
auto & ss_name_map_pair : sideset_id_name_map)
101 error <<
" " << ss_name_map_pair.first <<
" : " << ss_name_map_pair.second <<
"\n";
103 error <<
"\nBoundary (nodeset) names that do exist: \n";
104 error <<
" ID : Name\n";
106 auto & nodeset_id_name_map =
mesh->get_boundary_info().get_nodeset_name_map();
108 for (
auto & ns_name_map_pair : nodeset_id_name_map)
109 error <<
" " << ns_name_map_pair.first <<
" : " << ns_name_map_pair.second <<
"\n";
111 paramError(
"stitch_boundaries_pairs", error.str());
117 second = MooseUtils::convert<boundary_id_type>(boundary_pair[1],
true);
121 second = meshes[i]->get_boundary_info().get_id_by_name(boundary_pair[1]);
123 if (second == BoundaryInfo::invalid_id)
125 meshes[i]->print_info();
127 std::stringstream error;
129 error <<
"Boundary " << boundary_pair[1] <<
" doesn't exist on mesh '" <<
_input_names[i]
130 <<
"' in generator " <<
name() <<
"\n";
131 error <<
"Boundary (sideset) names that do exist: \n";
132 error <<
" ID : Name\n";
134 auto & sideset_id_name_map = meshes[i]->get_boundary_info().get_sideset_name_map();
136 for (
auto & ss_name_map_pair : sideset_id_name_map)
137 error <<
" " << ss_name_map_pair.first <<
" : " << ss_name_map_pair.second <<
"\n";
139 error <<
"\nBoundary (nodeset) names that do exist: \n";
140 error <<
" ID : Name\n";
142 auto & nodeset_id_name_map =
mesh->get_boundary_info().get_nodeset_name_map();
144 for (
auto & ns_name_map_pair : nodeset_id_name_map)
145 error <<
" " << ns_name_map_pair.first <<
" : " << ns_name_map_pair.second <<
"\n";
147 paramError(
"stitch_boundaries_pairs", error.str());
151 const bool use_binary_search = (
_algorithm ==
"BINARY");
160 if (!
mesh->is_prepared())
161 mesh->prepare_for_use();
162 if (!meshes[i]->is_prepared())
163 meshes[i]->prepare_for_use();
165 const auto & base_mesh_bids =
mesh->get_boundary_info().get_global_boundary_ids();
166 const auto stitched_mesh_bids = meshes[i]->get_boundary_info().get_global_boundary_ids();
168 bool overlap_found =
false;
169 for (
const auto & bid : stitched_mesh_bids)
170 if (base_mesh_bids.count(bid))
171 overlap_found =
true;
175 const auto max_boundary_id = *base_mesh_bids.rbegin();
177 for (
const auto bid : stitched_mesh_bids)
179 const auto new_bid = max_boundary_id + (new_index++);
180 meshes[i]->get_boundary_info().renumber_id(bid, new_bid);
187 mesh->stitch_meshes(*meshes[i],
196 mesh->set_isnt_prepared();
const bool _prevent_boundary_ids_overlap
Whether to renumber all boundaries in stitched meshes to prevent accidental merging of sidesets with ...
static InputParameters validParams()
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
virtual const std::string & name() const
Get the name of the class.
std::vector< std::vector< std::string > > _stitch_boundaries_pairs
A transformed version of _stitch_boundaries into a more logical "pairwise" structure.
std::vector< std::unique_ptr< MeshBase > * > _mesh_ptrs
boundary_id_type BoundaryID
StitchedMeshGenerator(const InputParameters ¶meters)
const bool & _clear_stitched_boundary_ids
Whether or not to clear (remove) the stitched boundary IDs.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
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 std::vector< MeshGeneratorName > & _input_names
The mesh generator inputs to read.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
registerMooseObject("MooseApp", StitchedMeshGenerator)
MeshGenerators are objects that can modify or add to an existing mesh.
Allows multiple mesh files to be "stitched" together to form a single mesh.
MooseEnum _algorithm
Type of algorithm used to find matching nodes (binary or exhaustive)