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 #include "MooseApp.h"
14 
15 #include "libmesh/mesh_modification.h"
16 #include "libmesh/serial_mesh.h"
17 #include "libmesh/exodusII_io.h"
18 
19 registerMooseObject("MooseApp", TiledMesh);
20 
23 {
25  params.addRequiredParam<MeshFileName>("file", "The name of the mesh file to read");
26 
27  params.addParam<Real>("x_width", 0, "The tile width in the x direction");
28  params.addParam<Real>("y_width", 0, "The tile width in the y direction");
29  params.addParam<Real>("z_width", 0, "The tile width in the z direction");
30 
31  // x boundary names
32  params.addParam<BoundaryName>("left_boundary", "left_boundary", "name of the left (x) boundary");
33  params.addParam<BoundaryName>(
34  "right_boundary", "right_boundary", "name of the right (x) boundary");
35 
36  // y boundary names
37  params.addParam<BoundaryName>("top_boundary", "top_boundary", "name of the top (y) boundary");
38  params.addParam<BoundaryName>(
39  "bottom_boundary", "bottom_boundary", "name of the bottom (y) boundary");
40 
41  // z boundary names
42  params.addParam<BoundaryName>(
43  "front_boundary", "front_boundary", "name of the front (z) boundary");
44  params.addParam<BoundaryName>("back_boundary", "back_boundary", "name of the back (z) boundary");
45 
46  // The number of tiles is 1 in each direction unless otherwise specified.
47  // An x_tiles value of 1 means do not stitch any extra meshes together in
48  // the x-direction.
49  params.addParam<unsigned int>(
50  "x_tiles", 1, "Number of tiles to stitch together (left to right) in the x-direction");
51  params.addParam<unsigned int>(
52  "y_tiles", 1, "Number of tiles to stitch together (top to bottom) in the y-direction");
53  params.addParam<unsigned int>(
54  "z_tiles", 1, "Number of tiles to stitch together (front to back) in the z-direction");
55 
56  params.addClassDescription("Use the supplied mesh and create a tiled grid by repeating this mesh "
57  "in the x,y, and z directions.");
58 
59  return params;
60 }
61 
63  : MooseMesh(parameters),
64  _x_width(getParam<Real>("x_width")),
65  _y_width(getParam<Real>("y_width")),
66  _z_width(getParam<Real>("z_width"))
67 {
68  // The TiledMesh class only works with ReplicatedMesh
69  errorIfDistributedMesh("TiledMesh");
70 }
71 
72 TiledMesh::TiledMesh(const TiledMesh & other_mesh)
73  : MooseMesh(other_mesh),
74  _x_width(other_mesh._x_width),
75  _y_width(other_mesh._y_width),
76  _z_width(other_mesh._z_width)
77 {
78 }
79 
80 std::unique_ptr<MooseMesh>
82 {
83  return _app.getFactory().copyConstruct(*this);
84 }
85 
86 std::string
88 {
89  return getParam<MeshFileName>("file");
90 }
91 
92 void
94 {
95  // stitch_meshes() is only implemented for ReplicatedMesh. So make sure
96  // we have one here before continuing.
97  ReplicatedMesh * serial_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());
98 
99  if (!serial_mesh)
100  mooseError("Error, TiledMesh calls stitch_meshes() which only works on ReplicatedMesh.");
101  else
102  {
103  std::string mesh_file(getParam<MeshFileName>("file"));
104 
105  if (mesh_file.rfind(".exd") < mesh_file.size() || mesh_file.rfind(".e") < mesh_file.size())
106  {
107  ExodusII_IO ex(*this);
108  ex.read(mesh_file);
109  serial_mesh->prepare_for_use();
110  }
111  else
112  serial_mesh->read(mesh_file);
113 
114  BoundaryID left = getBoundaryID(getParam<BoundaryName>("left_boundary"));
115  BoundaryID right = getBoundaryID(getParam<BoundaryName>("right_boundary"));
116  BoundaryID top = getBoundaryID(getParam<BoundaryName>("top_boundary"));
117  BoundaryID bottom = getBoundaryID(getParam<BoundaryName>("bottom_boundary"));
118  BoundaryID front = getBoundaryID(getParam<BoundaryName>("front_boundary"));
119  BoundaryID back = getBoundaryID(getParam<BoundaryName>("back_boundary"));
120 
121  {
122  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
123 
124  // Build X Tiles
125  for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
126  {
127  MeshTools::Modification::translate(*clone, _x_width, 0, 0);
128  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
129  right,
130  left,
131  TOLERANCE,
132  /*clear_stitched_boundary_ids=*/true);
133  }
134  }
135  {
136  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
137 
138  // Build Y Tiles
139  for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
140  {
141  MeshTools::Modification::translate(*clone, 0, _y_width, 0);
142  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
143  top,
144  bottom,
145  TOLERANCE,
146  /*clear_stitched_boundary_ids=*/true);
147  }
148  }
149  {
150  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
151 
152  // Build Z Tiles
153  for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
154  {
155  MeshTools::Modification::translate(*clone, 0, 0, _z_width);
156  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
157  front,
158  back,
159  TOLERANCE,
160  /*clear_stitched_boundary_ids=*/true);
161  }
162  }
163  }
164 }
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition: MooseMesh.C:79
virtual MooseMesh & clone() const
Clone method.
Definition: MooseMesh.C:2570
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:87
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
Definition: TiledMesh.C:22
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Definition: Factory.h:310
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...
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition: MooseApp.h:396
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3368
const Real _y_width
Definition: TiledMesh.h:30
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3199
const Real _x_width
Definition: TiledMesh.h:29
boundary_id_type BoundaryID
TiledMesh(const InputParameters &parameters)
Definition: TiledMesh.C:62
virtual void buildMesh() override
Must be overridden by child classes.
Definition: TiledMesh.C:93
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
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:81
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:1475