17#include "libmesh/replicated_mesh.h"
18#include "libmesh/unstructured_mesh.h"
19#include "libmesh/mesh_modification.h"
20#include "libmesh/point.h"
21#include "libmesh/node.h"
31 "Combine multiple meshes (or copies of one mesh) together into one (disjoint) mesh. Can "
32 "optionally translate those meshes before combining them.");
36 "The input MeshGenerators. This can either be N generators or 1 generator. If only 1 is "
37 "given then 'positions' must also be given.");
41 "The (optional) position of each given mesh. If N 'inputs' were given then this must either "
42 "be left blank or N positions must be given. If 1 input was given then this MUST be "
45 params.
addParam<std::vector<FileName>>(
46 "positions_file",
"Alternative way to provide the position of each given mesh.");
48 params.
addParam<
bool>(
"avoid_merging_subdomains",
50 "Whether to prevent merging subdomains by offsetting ids. The first mesh "
51 "in the input will keep the same subdomains ids, the others will have "
52 "offsets. All subdomain names will remain valid");
53 params.
addParam<
bool>(
"avoid_merging_boundaries",
55 "Whether to prevent merging sidesets by offsetting ids. The first mesh "
56 "in the input will keep the same boundary ids, the others will have "
57 "offsets. All boundary names will remain valid");
64 _meshes(getMeshes(
"inputs")),
65 _input_names(getParam<
std::vector<MeshGeneratorName>>(
"inputs")),
66 _avoid_merging_subdomains(getParam<bool>(
"avoid_merging_subdomains")),
67 _avoid_merging_boundaries(getParam<bool>(
"avoid_merging_boundaries"))
70 paramError(
"input_names",
"You need to specify at least one MeshGenerator as an input.");
73 mooseError(
"Both 'positions' and 'positions_file' cannot be specified simultaneously in "
80 "If only one input mesh is given, then 'positions' or 'positions_file' must also "
89 _positions = getParam<std::vector<Point>>(
"positions");
93 paramError(
"positions",
"If only one input mesh is given, then 'positions' cannot be empty.");
99 "If more than one input mesh is provided then the number of positions provided must "
100 "exactly match the number of input meshes.");
104 std::vector<FileName> positions_file = getParam<std::vector<FileName>>(
"positions_file");
107 if ((
_input_names.size() == 1) && positions_file.empty())
109 "If only one input mesh is given, then 'positions_file' cannot be empty.");
111 for (
const auto & f : positions_file)
120 if (data.size() && (
_input_names.size() != data.size()))
122 "If more than one input mesh is provided then the number of positions must "
123 "exactly match the number of input meshes.");
125 for (
const auto & d : data)
131std::unique_ptr<MeshBase>
143 auto mesh = dynamic_pointer_cast<UnstructuredMesh>(*
_meshes[0]);
151 MeshTools::Modification::translate(
158 auto other_mesh = dynamic_pointer_cast<UnstructuredMesh>(*
_meshes[i]);
165 if (!other_mesh->preparation().has_cached_elem_data)
166 other_mesh->cache_elem_data();
171 MeshTools::Modification::translate(
183 mesh->unset_is_prepared();
184 return dynamic_pointer_cast<MeshBase>(
mesh);
188 auto input_mesh = dynamic_pointer_cast<UnstructuredMesh>(*
_meshes[0]);
191 if (!input_mesh->preparation().has_cached_elem_data)
192 input_mesh->cache_elem_data();
200 auto final_mesh = dynamic_pointer_cast<UnstructuredMesh>(copy);
205 MeshTools::Modification::translate(
219 copy = input_mesh->clone();
220 auto translated_mesh = dynamic_pointer_cast<UnstructuredMesh>(copy);
222 if (!translated_mesh)
228 MeshTools::Modification::translate(
240 for (
auto translated_node_ptr : translated_mesh->node_ptr_range())
242 auto & translated_node = *translated_node_ptr;
243 auto & input_node = input_mesh->node_ref(translated_node_ptr->id());
245 for (MooseIndex(LIBMESH_DIM) i = 0; i < LIBMESH_DIM; i++)
246 translated_node(i) = input_node(i);
250 final_mesh->unset_is_prepared();
251 return dynamic_pointer_cast<MeshBase>(final_mesh);
registerMooseObject("MooseApp", CombinerGenerator)
Collects multiple meshes into a single (unconnected) mesh.
std::vector< Point > _positions
The (offsets) positions for each mesh.
const bool _avoid_merging_subdomains
Boolean to control whether to prevent merging subdomains.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
CombinerGenerator(const InputParameters ¶meters)
void fillPositions()
Fill the offset positions for each mesh.
const std::vector< std::unique_ptr< MeshBase > * > _meshes
static InputParameters validParams()
const std::vector< MeshGeneratorName > & _input_names
The mesh generators to use.
const bool _avoid_merging_boundaries
Boolean to control whether to prevent merging boundaries.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
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 ...
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...
const std::string & _name
The name of this class.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Utility class for reading delimited data (e.g., CSV data).
const std::vector< Point > getDataAsPoints() const
Get the data in Point format.
void setFormatFlag(FormatFlag value)
void read()
Perform the actual data reading.
const Parallel::Communicator & _communicator
void copyIntoMesh(MeshGenerator &mg, UnstructuredMesh &destination, const UnstructuredMesh &source, const bool avoid_merging_subdomains, const bool avoid_merging_boundaries, const Parallel::Communicator &communicator)
Helper function for copying one mesh into another.