www.mooseframework.org
TiledMesh.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 "TiledMesh.h"
11 #include "Parser.h"
12 #include "InputParameters.h"
13 
14 #include "libmesh/mesh_modification.h"
15 #include "libmesh/serial_mesh.h"
16 #include "libmesh/exodusII_io.h"
17 
18 registerMooseObject("MooseApp", TiledMesh);
19 
22 {
24  params.addRequiredParam<MeshFileName>("file", "The name of the mesh file to read");
25 
26  params.addParam<Real>("x_width", 0, "The tile width in the x direction");
27  params.addParam<Real>("y_width", 0, "The tile width in the y direction");
28  params.addParam<Real>("z_width", 0, "The tile width in the z direction");
29 
30  // x boundary names
31  params.addParam<BoundaryName>("left_boundary", "left_boundary", "name of the left (x) boundary");
32  params.addParam<BoundaryName>(
33  "right_boundary", "right_boundary", "name of the right (x) boundary");
34 
35  // y boundary names
36  params.addParam<BoundaryName>("top_boundary", "top_boundary", "name of the top (y) boundary");
37  params.addParam<BoundaryName>(
38  "bottom_boundary", "bottom_boundary", "name of the bottom (y) boundary");
39 
40  // z boundary names
41  params.addParam<BoundaryName>(
42  "front_boundary", "front_boundary", "name of the front (z) boundary");
43  params.addParam<BoundaryName>("back_boundary", "back_boundary", "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  : MooseMesh(parameters),
63  _x_width(getParam<Real>("x_width")),
64  _y_width(getParam<Real>("y_width")),
65  _z_width(getParam<Real>("z_width"))
66 {
67  // The TiledMesh class only works with ReplicatedMesh
68  errorIfDistributedMesh("TiledMesh");
69 }
70 
71 TiledMesh::TiledMesh(const TiledMesh & other_mesh)
72  : MooseMesh(other_mesh),
73  _x_width(other_mesh._x_width),
74  _y_width(other_mesh._y_width),
75  _z_width(other_mesh._z_width)
76 {
77 }
78 
79 std::unique_ptr<MooseMesh>
81 {
82  return std::make_unique<TiledMesh>(*this);
83 }
84 
85 std::string
87 {
88  return getParam<MeshFileName>("file");
89 }
90 
91 void
93 {
94  // stitch_meshes() is only implemented for ReplicatedMesh. So make sure
95  // we have one here before continuing.
96  ReplicatedMesh * serial_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());
97 
98  if (!serial_mesh)
99  mooseError("Error, TiledMesh calls stitch_meshes() which only works on ReplicatedMesh.");
100  else
101  {
102  std::string mesh_file(getParam<MeshFileName>("file"));
103 
104  if (mesh_file.rfind(".exd") < mesh_file.size() || mesh_file.rfind(".e") < mesh_file.size())
105  {
106  ExodusII_IO ex(*this);
107  ex.read(mesh_file);
108  serial_mesh->prepare_for_use();
109  }
110  else
111  serial_mesh->read(mesh_file);
112 
113  BoundaryID left = getBoundaryID(getParam<BoundaryName>("left_boundary"));
114  BoundaryID right = getBoundaryID(getParam<BoundaryName>("right_boundary"));
115  BoundaryID top = getBoundaryID(getParam<BoundaryName>("top_boundary"));
116  BoundaryID bottom = getBoundaryID(getParam<BoundaryName>("bottom_boundary"));
117  BoundaryID front = getBoundaryID(getParam<BoundaryName>("front_boundary"));
118  BoundaryID back = getBoundaryID(getParam<BoundaryName>("back_boundary"));
119 
120  {
121  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
122 
123  // Build X Tiles
124  for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
125  {
126  MeshTools::Modification::translate(*clone, _x_width, 0, 0);
127  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
128  right,
129  left,
130  TOLERANCE,
131  /*clear_stitched_boundary_ids=*/true);
132  }
133  }
134  {
135  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
136 
137  // Build Y Tiles
138  for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
139  {
140  MeshTools::Modification::translate(*clone, 0, _y_width, 0);
141  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
142  top,
143  bottom,
144  TOLERANCE,
145  /*clear_stitched_boundary_ids=*/true);
146  }
147  }
148  {
149  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
150 
151  // Build Z Tiles
152  for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
153  {
154  MeshTools::Modification::translate(*clone, 0, 0, _z_width);
155  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
156  front,
157  back,
158  TOLERANCE,
159  /*clear_stitched_boundary_ids=*/true);
160  }
161  }
162  }
163 }
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition: MooseMesh.C:78
virtual MooseMesh & clone() const
Clone method.
Definition: MooseMesh.C:2569
virtual std::string getFileName() const override
Returns the name of the mesh file read to produce this mesh if any or an empty string otherwise...
Definition: TiledMesh.C:86
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
Definition: TiledMesh.C:21
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 errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3367
const Real _y_width
Definition: TiledMesh.h:30
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3198
const Real _x_width
Definition: TiledMesh.h:29
boundary_id_type BoundaryID
TiledMesh(const InputParameters &parameters)
Definition: TiledMesh.C:61
virtual void buildMesh() override
Must be overridden by child classes.
Definition: TiledMesh.C:92
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
const Real _z_width
Definition: TiledMesh.h:31
virtual std::unique_ptr< MooseMesh > safeClone() const override
A safer version of the clone() method that hands back an allocated object wrapped in a smart pointer...
Definition: TiledMesh.C:80
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...
registerMooseObject("MooseApp", TiledMesh)
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:1474