www.mooseframework.org
TiledMesh.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "TiledMesh.h"
16 #include "Parser.h"
17 #include "InputParameters.h"
18 
19 #include "libmesh/mesh_modification.h"
20 #include "libmesh/serial_mesh.h"
21 #include "libmesh/exodusII_io.h"
22 
23 template <>
26 {
28  params.addRequiredParam<MeshFileName>("file", "The name of the mesh file to read");
29 
30  params.addParam<Real>("x_width", 0, "The tile width in the x direction");
31  params.addParam<Real>("y_width", 0, "The tile width in the y direction");
32  params.addParam<Real>("z_width", 0, "The tile width in the z direction");
33 
34  // x boundary names
35  params.addParam<BoundaryName>("left_boundary", "left_boundary", "name of the left (x) boundary");
36  params.addParam<BoundaryName>(
37  "right_boundary", "right_boundary", "name of the right (x) boundary");
38 
39  // y boundary names
40  params.addParam<BoundaryName>("top_boundary", "top_boundary", "name of the top (y) boundary");
41  params.addParam<BoundaryName>(
42  "bottom_boundary", "bottom_boundary", "name of the bottom (y) boundary");
43 
44  // z boundary names
45  params.addParam<BoundaryName>(
46  "front_boundary", "front_boundary", "name of the front (z) boundary");
47  params.addParam<BoundaryName>("back_boundary", "back_boundary", "name of the back (z) boundary");
48 
49  // The number of tiles is 1 in each direction unless otherwise specified.
50  // An x_tiles value of 1 means do not stitch any extra meshes together in
51  // the x-direction.
52  params.addParam<unsigned int>(
53  "x_tiles", 1, "Number of tiles to stitch together (left to right) in the x-direction");
54  params.addParam<unsigned int>(
55  "y_tiles", 1, "Number of tiles to stitch together (top to bottom) in the y-direction");
56  params.addParam<unsigned int>(
57  "z_tiles", 1, "Number of tiles to stitch together (front to back) in the z-direction");
58 
59  params.addClassDescription("Use the supplied mesh and create a tiled grid by repeating this mesh "
60  "in the x,y, and z directions.");
61 
62  return params;
63 }
64 
66  : MooseMesh(parameters),
67  _x_width(getParam<Real>("x_width")),
68  _y_width(getParam<Real>("y_width")),
69  _z_width(getParam<Real>("z_width"))
70 {
71  // The TiledMesh class only works with ReplicatedMesh
72  errorIfDistributedMesh("TiledMesh");
73 }
74 
75 TiledMesh::TiledMesh(const TiledMesh & other_mesh)
76  : MooseMesh(other_mesh),
77  _x_width(other_mesh._x_width),
78  _y_width(other_mesh._y_width),
79  _z_width(other_mesh._z_width)
80 {
81 }
82 
83 MooseMesh &
85 {
86  return *(new TiledMesh(*this));
87 }
88 
89 void
91 {
92  // stitch_meshes() is only implemented for ReplicatedMesh. So make sure
93  // we have one here before continuing.
94  ReplicatedMesh * serial_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());
95 
96  if (!serial_mesh)
97  mooseError("Error, TiledMesh calls stitch_meshes() which only works on ReplicatedMesh.");
98  else
99  {
100  std::string mesh_file(getParam<MeshFileName>("file"));
101 
102  if (mesh_file.rfind(".exd") < mesh_file.size() || mesh_file.rfind(".e") < mesh_file.size())
103  {
104  ExodusII_IO ex(*this);
105  ex.read(mesh_file);
106  serial_mesh->prepare_for_use();
107  }
108  else
109  serial_mesh->read(mesh_file);
110 
111  BoundaryID left = getBoundaryID(getParam<BoundaryName>("left_boundary"));
112  BoundaryID right = getBoundaryID(getParam<BoundaryName>("right_boundary"));
113  BoundaryID top = getBoundaryID(getParam<BoundaryName>("top_boundary"));
114  BoundaryID bottom = getBoundaryID(getParam<BoundaryName>("bottom_boundary"));
115  BoundaryID front = getBoundaryID(getParam<BoundaryName>("front_boundary"));
116  BoundaryID back = getBoundaryID(getParam<BoundaryName>("back_boundary"));
117 
118  {
119  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
120 
121  // Build X Tiles
122  for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
123  {
124  MeshTools::Modification::translate(*clone, _x_width, 0, 0);
125  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
126  right,
127  left,
128  TOLERANCE,
129  /*clear_stitched_boundary_ids=*/true);
130  }
131  }
132  {
133  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
134 
135  // Build Y Tiles
136  for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
137  {
138  MeshTools::Modification::translate(*clone, 0, _y_width, 0);
139  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
140  top,
141  bottom,
142  TOLERANCE,
143  /*clear_stitched_boundary_ids=*/true);
144  }
145  }
146  {
147  std::unique_ptr<MeshBase> clone = serial_mesh->clone();
148 
149  // Build Z Tiles
150  for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
151  {
152  MeshTools::Modification::translate(*clone, 0, 0, _z_width);
153  serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
154  front,
155  back,
156  TOLERANCE,
157  /*clear_stitched_boundary_ids=*/true);
158  }
159  }
160  }
161 }
virtual MooseMesh & clone() const =0
Clone method.
virtual MooseMesh & clone() const override
Clone method.
Definition: TiledMesh.C:84
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2473
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...
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:929
const Real _y_width
Definition: TiledMesh.h:37
InputParameters validParams< MooseMesh >()
Definition: MooseMesh.C:65
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
const Real _x_width
Definition: TiledMesh.h:36
TiledMesh(const InputParameters &parameters)
Definition: TiledMesh.C:65
virtual void buildMesh() override
Must be overridden by child classes.
Definition: TiledMesh.C:90
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
InputParameters validParams< TiledMesh >()
Definition: TiledMesh.C:25
const Real _z_width
Definition: TiledMesh.h:38
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
boundary_id_type BoundaryID
Definition: MooseTypes.h:75