www.mooseframework.org
TiledMeshGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "TiledMeshGenerator.h"
11 #include "CastUniquePointer.h"
12 
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"
20 
21 #include <typeinfo>
22 
24 
27 {
29 
30  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to repeat");
31 
32  // x boundary names
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");
35 
36  // y boundary names
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");
39 
40  // z boundary names
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");
43 
44  // The number of tiles is 1 in each direction unless otherwise specified.
45  // An x_tiles value of 1 means do not stitch any extra meshes together in
46  // the x-direction.
47  params.addParam<unsigned int>(
48  "x_tiles", 1, "Number of tiles to stitch together (left to right) in the x-direction");
49  params.addParam<unsigned int>(
50  "y_tiles", 1, "Number of tiles to stitch together (top to bottom) in the y-direction");
51  params.addParam<unsigned int>(
52  "z_tiles", 1, "Number of tiles to stitch together (front to back) in the z-direction");
53 
54  params.addClassDescription("Use the supplied mesh and create a tiled grid by repeating this mesh "
55  "in the x, y, and z directions.");
56 
57  return params;
58 }
59 
61  : MeshGenerator(parameters), _input(getMesh("input"))
62 {
63 }
64 
65 std::unique_ptr<MeshBase>
67 {
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");
71  std::unique_ptr<ReplicatedMesh> mesh = dynamic_pointer_cast<ReplicatedMesh>(initial_mesh);
72 
73  // Getting the x,y,z widths
74  std::set<subdomain_id_type> sub_ids;
75  mesh->subdomain_ids(sub_ids);
76  BoundingBox bbox;
77  for (auto id : sub_ids)
78  {
79  BoundingBox sub_bbox = MeshTools::create_subdomain_bounding_box(*mesh, id);
80  bbox.union_with(sub_bbox);
81  }
82 
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);
86 
87  boundary_id_type left =
88  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("left_boundary"));
89  boundary_id_type right =
90  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("right_boundary"));
91  boundary_id_type top =
92  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("top_boundary"));
93  boundary_id_type bottom =
94  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("bottom_boundary"));
95  boundary_id_type front =
96  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("front_boundary"));
97  boundary_id_type back =
98  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("back_boundary"));
99 
100  {
101  std::unique_ptr<MeshBase> clone = mesh->clone();
102 
103  // Build X Tiles
104  for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
105  {
106  MeshTools::Modification::translate(*clone, _x_width, 0, 0);
107  mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
108  right,
109  left,
110  TOLERANCE,
111  /*clear_stitched_boundary_ids=*/true);
112  }
113  }
114 
115  {
116  std::unique_ptr<MeshBase> clone = mesh->clone();
117 
118  // Build Y Tiles
119  for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
120  {
121  MeshTools::Modification::translate(*clone, 0, _y_width, 0);
122  mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
123  top,
124  bottom,
125  TOLERANCE,
126  /*clear_stitched_boundary_ids=*/true);
127  }
128  }
129 
130  {
131  std::unique_ptr<MeshBase> clone = mesh->clone();
132 
133  // Build Z Tiles
134  for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
135  {
136  MeshTools::Modification::translate(*clone, 0, 0, _z_width);
137  mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
138  front,
139  back,
140  TOLERANCE,
141  /*clear_stitched_boundary_ids=*/true);
142  }
143  }
144 
145  return dynamic_pointer_cast<MeshBase>(mesh);
146 }
Real _x_width
The mesh width in the x, y and z directions.
registerMooseObject("MooseApp", TiledMeshGenerator)
TiledMeshGenerator(const InputParameters &parameters)
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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()
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
int8_t boundary_id_type
static InputParameters validParams()
Definition: MeshGenerator.C:23
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
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.
Definition: MeshGenerator.h:32