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" 30 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to repeat");
33 params.
addParam<BoundaryName>(
"left_boundary",
"left",
"name of the left (x) boundary");
34 params.
addParam<BoundaryName>(
"right_boundary",
"right",
"name of the right (x) boundary");
37 params.
addParam<BoundaryName>(
"top_boundary",
"top",
"name of the top (y) boundary");
38 params.
addParam<BoundaryName>(
"bottom_boundary",
"bottom",
"name of the bottom (y) boundary");
41 params.
addParam<BoundaryName>(
"front_boundary",
"front",
"name of the front (z) boundary");
42 params.
addParam<BoundaryName>(
"back_boundary",
"back",
"name of the back (z) boundary");
48 "x_tiles", 1,
"Number of tiles to stitch together (left to right) in the x-direction");
50 "y_tiles", 1,
"Number of tiles to stitch together (top to bottom) in the y-direction");
52 "z_tiles", 1,
"Number of tiles to stitch together (front to back) in the z-direction");
54 params.
addClassDescription(
"Use the supplied mesh and create a tiled grid by repeating this mesh " 55 "in the x, y, and z directions.");
65 std::unique_ptr<MeshBase>
68 std::unique_ptr<MeshBase> initial_mesh = std::move(
_input);
69 if (!initial_mesh->is_replicated())
70 mooseError(
"This MeshGenerator is not implemented for distributed meshes");
74 std::set<subdomain_id_type> sub_ids;
75 mesh->subdomain_ids(sub_ids);
77 for (
auto id : sub_ids)
79 BoundingBox sub_bbox = MeshTools::create_subdomain_bounding_box(*
mesh,
id);
80 bbox.union_with(sub_bbox);
83 _x_width = bbox.max()(0) - bbox.min()(0);
84 _y_width = bbox.max()(1) - bbox.min()(1);
85 _z_width = bbox.max()(2) - bbox.min()(2);
88 mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>(
"left_boundary"));
90 mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>(
"right_boundary"));
92 mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>(
"top_boundary"));
94 mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>(
"bottom_boundary"));
96 mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>(
"front_boundary"));
98 mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>(
"back_boundary"));
101 std::unique_ptr<MeshBase> clone =
mesh->clone();
104 for (
unsigned int i = 1; i < getParam<unsigned int>(
"x_tiles"); ++i)
106 MeshTools::Modification::translate(*clone,
_x_width, 0, 0);
107 mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
116 std::unique_ptr<MeshBase> clone =
mesh->clone();
119 for (
unsigned int i = 1; i < getParam<unsigned int>(
"y_tiles"); ++i)
121 MeshTools::Modification::translate(*clone, 0,
_y_width, 0);
122 mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
131 std::unique_ptr<MeshBase> clone =
mesh->clone();
134 for (
unsigned int i = 1; i < getParam<unsigned int>(
"z_tiles"); ++i)
136 MeshTools::Modification::translate(*clone, 0, 0,
_z_width);
137 mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
Real _x_width
The mesh width in the x, y and z directions.
registerMooseObject("MooseApp", TiledMeshGenerator)
TiledMeshGenerator(const InputParameters ¶meters)
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.
std::unique_ptr< MeshBase > & _input
Mesh that possibly comes from another generator.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()
static InputParameters validParams()
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
Take an input mesh and repeat it in the x,y and z directions.
MeshGenerators are objects that can modify or add to an existing mesh.