13#include "libmesh/replicated_mesh.h"
14#include "libmesh/distributed_mesh.h"
15#include "libmesh/boundary_info.h"
16#include "libmesh/mesh_modification.h"
17#include "libmesh/bounding_box.h"
18#include "libmesh/mesh_tools.h"
19#include "libmesh/point.h"
35 "The meshes we want to stitch together");
37 params.
addParam<Real>(
"bottom_height", 0,
"The height of the bottom of the final mesh");
40 params.
addParam<BoundaryName>(
"top_boundary",
"top",
"name of the top (y) boundary");
41 params.
addParam<BoundaryName>(
"bottom_boundary",
"bottom",
"name of the bottom (y) boundary");
44 params.
addParam<BoundaryName>(
"front_boundary",
"front",
"name of the front (z) boundary");
45 params.
addParam<BoundaryName>(
"back_boundary",
"back",
"name of the back (z) boundary");
55 _mesh_ptrs(getMeshes(
"inputs")),
56 _input_names(getParam<
std::vector<MeshGeneratorName>>(
"inputs")),
57 _bottom_height(getParam<Real>(
"bottom_height"))
61std::unique_ptr<MeshBase>
64 std::unique_ptr<ReplicatedMesh>
mesh = dynamic_pointer_cast<ReplicatedMesh>(*
_mesh_ptrs[0]);
66 mooseError(
"StackGenerator only works with ReplicatedMesh : mesh from Meshgenerator ",
68 "is not a ReplicatedMesh.");
70 int dim =
static_cast<int>(
_dim);
72 if (
dim !=
int(
mesh->mesh_dimension()))
74 "incompatible mesh dimensions: dim=",
76 " and first mesh dimension is ",
77 mesh->mesh_dimension());
80 std::vector<std::unique_ptr<ReplicatedMesh>> meshes;
85 meshes.push_back(dynamic_pointer_cast<ReplicatedMesh>(*
_mesh_ptrs[i]));
88 for (MooseIndex(meshes) i = 0; i < meshes.size(); ++i)
90 if (meshes[i] ==
nullptr)
91 mooseError(
"StackGenerator only works with ReplicatedMesh : mesh from Meshgenerator ",
93 "is not a ReplicatedMesh.");
94 if (
static_cast<int>(meshes[i]->mesh_dimension()) !=
dim)
99 std::vector<BoundaryName> boundary_names = {getParam<BoundaryName>(
"top_boundary"),
100 getParam<BoundaryName>(
"bottom_boundary")};
102 boundary_names = {getParam<BoundaryName>(
"front_boundary"),
103 getParam<BoundaryName>(
"back_boundary")};
105 std::vector<boundary_id_type> ids =
108 mooseAssert(ids.size() == boundary_names.size(),
109 "Unexpected number of ids returned for MooseMeshUtils::getBoundaryIDs");
111 boundary_id_type first = ids[0], second = ids[1];
114 std::vector<Real> heights;
116 for (MooseIndex(meshes) i = 0; i < meshes.size(); ++i)
131 for (MooseIndex(meshes) i = 0; i < meshes.size(); ++i)
136 MeshTools::Modification::translate(*meshes[i], 0, heights[i], 0);
139 MeshTools::Modification::translate(*meshes[i], 0, 0, heights[i]);
142 mesh->stitch_meshes(*meshes[i], first, second, TOLERANCE,
true);
145 return dynamic_pointer_cast<MeshBase>(
mesh);
152 return bbox.max()(
dim - 1) - bbox.min()(
dim - 1);
registerMooseObject("MooseApp", StackGenerator)
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...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Take several 3D meshes and stitch them on top of each other like a stack.
const Real _bottom_height
Height (z) of the bottom of the final mesh.
const std::vector< MeshGeneratorName > & _input_names
The meshgenerators to read.
const std::vector< std::unique_ptr< MeshBase > * > _mesh_ptrs
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
StackGenerator(const InputParameters ¶meters)
Real computeWidth(const MeshBase &mesh, const int &dim)
static InputParameters validParams()
const MooseEnum _dim
The dimension of the mesh.
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.