www.mooseframework.org
PatternedMesh.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 "PatternedMesh.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<std::vector<MeshFileName>>("files",
29  "The name of the mesh files to read. "
30  " They are automatically assigned "
31  "ids starting with zero.");
32 
33  params.addRangeCheckedParam<Real>(
34  "x_width", 0, "x_width>=0", "The tile width in the x direction");
35  params.addRangeCheckedParam<Real>(
36  "y_width", 0, "y_width>=0", "The tile width in the y direction");
37  params.addRangeCheckedParam<Real>(
38  "z_width", 0, "z_width>=0", "The tile width in the z direction");
39 
40  // x boundary names
41  params.addParam<BoundaryName>("left_boundary", "left_boundary", "name of the left (x) boundary");
42  params.addParam<BoundaryName>(
43  "right_boundary", "right_boundary", "name of the right (x) boundary");
44 
45  // y boundary names
46  params.addParam<BoundaryName>("top_boundary", "top_boundary", "name of the top (y) boundary");
47  params.addParam<BoundaryName>(
48  "bottom_boundary", "bottom_boundary", "name of the bottom (y) boundary");
49 
50  params.addRequiredParam<std::vector<std::vector<unsigned int>>>(
51  "pattern", "A double-indexed array starting with the upper-left corner");
52 
53  params.addClassDescription("Creates a 2D mesh from a specified set of unique 'tiles' meshes and "
54  "a two-dimensional pattern.");
55 
56  return params;
57 }
58 
60  : MooseMesh(parameters),
61  _files(getParam<std::vector<MeshFileName>>("files")),
62  _pattern(getParam<std::vector<std::vector<unsigned int>>>("pattern")),
63  _x_width(getParam<Real>("x_width")),
64  _y_width(getParam<Real>("y_width")),
65  _z_width(getParam<Real>("z_width"))
66 {
67  // The PatternedMesh class only works with ReplicatedMesh
68  errorIfDistributedMesh("PatternedMesh");
69 
70  _meshes.reserve(_files.size());
71 
72  // Read in all of the meshes
73  for (auto i = beginIndex(_files); i < _files.size(); ++i)
74  {
75  _meshes.emplace_back(libmesh_make_unique<ReplicatedMesh>(_communicator));
76  auto & mesh = _meshes.back();
77 
78  mesh->read(_files[i]);
79  }
80 
81  _original_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());
82  if (!_original_mesh)
83  mooseError("PatternedMesh does not support DistributedMesh");
84 
85  // Create a mesh for all n-1 rows, the first row is the original mesh
86  _row_meshes.reserve(_pattern.size() - 1);
87  for (auto i = beginIndex(_pattern); i < _pattern.size() - 1; ++i)
88  _row_meshes.emplace_back(libmesh_make_unique<ReplicatedMesh>(_communicator));
89 }
90 
92  : MooseMesh(other_mesh),
93  _files(other_mesh._files),
94  _pattern(other_mesh._pattern),
95  _x_width(other_mesh._x_width),
96  _y_width(other_mesh._y_width),
97  _z_width(other_mesh._z_width)
98 {
99 }
100 
102 
103 MooseMesh &
105 {
106  return *(new PatternedMesh(*this));
107 }
108 
109 void
111 {
112  // Local pointers to simplify algorithm
113  std::vector<ReplicatedMesh *> row_meshes;
114  row_meshes.reserve(_pattern.size());
115  // First row is the original mesh
116  row_meshes.push_back(_original_mesh);
117  // Copy the remaining raw pointers into the local vector
118  for (const auto & row_mesh : _row_meshes)
119  row_meshes.push_back(row_mesh.get());
120 
121  BoundaryID left = getBoundaryID(getParam<BoundaryName>("left_boundary"));
122  BoundaryID right = getBoundaryID(getParam<BoundaryName>("right_boundary"));
123  BoundaryID top = getBoundaryID(getParam<BoundaryName>("top_boundary"));
124  BoundaryID bottom = getBoundaryID(getParam<BoundaryName>("bottom_boundary"));
125 
126  // Build each row mesh
127  for (auto i = beginIndex(_pattern); i < _pattern.size(); ++i)
128  for (auto j = beginIndex(_pattern[i]); j < _pattern[i].size(); ++j)
129  {
130  Real deltax = j * _x_width, deltay = i * _y_width;
131 
132  // If this is the first cell of the row initialize the row mesh
133  if (j == 0)
134  {
135  row_meshes[i]->read(_files[_pattern[i][j]]);
136 
137  MeshTools::Modification::translate(*row_meshes[i], deltax, -deltay, 0);
138 
139  continue;
140  }
141 
142  ReplicatedMesh & cell_mesh = *_meshes[_pattern[i][j]];
143 
144  // Move the mesh into the right spot. -i because we are starting at the top
145  MeshTools::Modification::translate(cell_mesh, deltax, -deltay, 0);
146 
147  row_meshes[i]->stitch_meshes(dynamic_cast<ReplicatedMesh &>(cell_mesh),
148  right,
149  left,
150  TOLERANCE,
151  /*clear_stitched_boundary_ids=*/true);
152 
153  // Undo the translation
154  MeshTools::Modification::translate(cell_mesh, -deltax, deltay, 0);
155  }
156 
157  // Now stitch together the rows
158  // We're going to stitch them all to row 0 (which is the real mesh)
159  for (auto i = beginIndex(_pattern, 1); i < _pattern.size(); i++)
160  row_meshes[0]->stitch_meshes(
161  *row_meshes[i], bottom, top, TOLERANCE, /*clear_stitched_boundary_ids=*/true);
162 }
std::vector< std::unique_ptr< ReplicatedMesh > > _meshes
Definition: PatternedMesh.h:63
InputParameters validParams< PatternedMesh >()
Definition: PatternedMesh.C:25
const Real _y_width
Definition: PatternedMesh.h:69
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
PatternedMesh(const InputParameters &parameters)
Definition: PatternedMesh.C:59
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2473
const Real _z_width
Definition: PatternedMesh.h:70
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...
const std::vector< MeshFileName > & _files
Definition: PatternedMesh.h:54
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:929
Reads one or more 2D mesh files and stitches them together based on a provided two-dimensional patter...
Definition: PatternedMesh.h:41
virtual MooseMesh & clone() const override
Clone method.
InputParameters validParams< MooseMesh >()
Definition: MooseMesh.C:65
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
const Real _x_width
Definition: PatternedMesh.h:68
virtual ~PatternedMesh()
const std::vector< std::vector< unsigned int > > & _pattern
Definition: PatternedMesh.h:57
std::vector< std::unique_ptr< ReplicatedMesh > > _row_meshes
Definition: PatternedMesh.h:66
ReplicatedMesh * _original_mesh
Definition: PatternedMesh.h:60
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
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
virtual void buildMesh() override
Must be overridden by child classes.
boundary_id_type BoundaryID
Definition: MooseTypes.h:75