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 
25 template <>
28 {
30 
31  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to repeat");
32 
33  // x boundary names
34  params.addParam<BoundaryName>("left_boundary", "left", "name of the left (x) boundary");
35  params.addParam<BoundaryName>("right_boundary", "right", "name of the right (x) boundary");
36 
37  // y boundary names
38  params.addParam<BoundaryName>("top_boundary", "top", "name of the top (y) boundary");
39  params.addParam<BoundaryName>("bottom_boundary", "bottom", "name of the bottom (y) boundary");
40 
41  // z boundary names
42  params.addParam<BoundaryName>("front_boundary", "front", "name of the front (z) boundary");
43  params.addParam<BoundaryName>("back_boundary", "back", "name of the back (z) boundary");
44 
45  // The number of tiles is 1 in each direction unless otherwise specified.
46  // An x_tiles value of 1 means do not stitch any extra meshes together in
47  // the x-direction.
48  params.addParam<unsigned int>(
49  "x_tiles", 1, "Number of tiles to stitch together (left to right) in the x-direction");
50  params.addParam<unsigned int>(
51  "y_tiles", 1, "Number of tiles to stitch together (top to bottom) in the y-direction");
52  params.addParam<unsigned int>(
53  "z_tiles", 1, "Number of tiles to stitch together (front to back) in the z-direction");
54 
55  params.addClassDescription("Use the supplied mesh and create a tiled grid by repeating this mesh "
56  "in the x,y, and z directions.");
57 
58  return params;
59 }
60 
62  : MeshGenerator(parameters), _input(getMesh("input"))
63 {
64  if (dynamic_pointer_cast<DistributedMesh>(_input) != nullptr)
65  mooseError("TiledMeshGenerator only works with ReplicatedMesh.");
66 }
67 
68 std::unique_ptr<MeshBase>
70 {
71  std::unique_ptr<MeshBase> initial_mesh = std::move(_input);
72  std::unique_ptr<ReplicatedMesh> mesh = dynamic_pointer_cast<ReplicatedMesh>(initial_mesh);
73 
74  // Getting the x,y,z widths
75  std::set<subdomain_id_type> sub_ids;
76  mesh->subdomain_ids(sub_ids);
77  BoundingBox bbox(Point(std::numeric_limits<Real>::max(),
78  std::numeric_limits<Real>::max(),
79  std::numeric_limits<Real>::max()),
80  Point(std::numeric_limits<Real>::lowest(),
81  std::numeric_limits<Real>::lowest(),
82  std::numeric_limits<Real>::lowest()));
83  for (auto id : sub_ids)
84  {
85  BoundingBox sub_bbox = MeshTools::create_subdomain_bounding_box(*mesh, id);
86  bbox.union_with(sub_bbox);
87  }
88 
89  _x_width = bbox.max()(0) - bbox.min()(0);
90  _y_width = bbox.max()(1) - bbox.min()(1);
91  _z_width = bbox.max()(2) - bbox.min()(2);
92 
93  boundary_id_type left =
94  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("left_boundary"));
95  boundary_id_type right =
96  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("right_boundary"));
97  boundary_id_type top =
98  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("top_boundary"));
99  boundary_id_type bottom =
100  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("bottom_boundary"));
101  boundary_id_type front =
102  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("front_boundary"));
103  boundary_id_type back =
104  mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("back_boundary"));
105 
106  {
107  std::unique_ptr<MeshBase> clone = mesh->clone();
108 
109  // Build X Tiles
110  for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
111  {
112  MeshTools::Modification::translate(*clone, _x_width, 0, 0);
113  mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
114  right,
115  left,
116  TOLERANCE,
117  /*clear_stitched_boundary_ids=*/true);
118  }
119  }
120 
121  {
122  std::unique_ptr<MeshBase> clone = mesh->clone();
123 
124  // Build Y Tiles
125  for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
126  {
127  MeshTools::Modification::translate(*clone, 0, _y_width, 0);
128  mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
129  top,
130  bottom,
131  TOLERANCE,
132  /*clear_stitched_boundary_ids=*/true);
133  }
134  }
135 
136  {
137  std::unique_ptr<MeshBase> clone = mesh->clone();
138 
139  // Build Z Tiles
140  for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
141  {
142  MeshTools::Modification::translate(*clone, 0, 0, _z_width);
143  mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
144  front,
145  back,
146  TOLERANCE,
147  /*clear_stitched_boundary_ids=*/true);
148  }
149  }
150 
151  return dynamic_pointer_cast<MeshBase>(mesh);
152 }
Real _x_width
The mesh width in the x, y and z directions.
registerMooseObject("MooseApp", TiledMeshGenerator)
TiledMeshGenerator(const InputParameters &parameters)
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.
InputParameters validParams< TiledMeshGenerator >()
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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...
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...
InputParameters validParams< MeshGenerator >()
Definition: MeshGenerator.C:16
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:30