https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PatternedMesh.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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 "PatternedMesh.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
20
23{
25 params.addRequiredParam<std::vector<MeshFileName>>("files",
26 "The name of the mesh files to read. "
27 " They are automatically assigned "
28 "ids starting with zero.");
29
30 params.addRangeCheckedParam<Real>(
31 "x_width", 0, "x_width>=0", "The tile width in the x direction");
32 params.addRangeCheckedParam<Real>(
33 "y_width", 0, "y_width>=0", "The tile width in the y direction");
34 params.addRangeCheckedParam<Real>(
35 "z_width", 0, "z_width>=0", "The tile width in the z direction");
36
37 // x boundary names
38 params.addParam<BoundaryName>("left_boundary", "left_boundary", "name of the left (x) boundary");
39 params.addParam<BoundaryName>(
40 "right_boundary", "right_boundary", "name of the right (x) boundary");
41
42 // y boundary names
43 params.addParam<BoundaryName>("top_boundary", "top_boundary", "name of the top (y) boundary");
44 params.addParam<BoundaryName>(
45 "bottom_boundary", "bottom_boundary", "name of the bottom (y) boundary");
46
47 params.addRequiredParam<std::vector<std::vector<unsigned int>>>(
48 "pattern", "A double-indexed array starting with the upper-left corner");
49
50 params.addClassDescription("Creates a 2D mesh from a specified set of unique 'tiles' meshes and "
51 "a two-dimensional pattern.");
52
53 return params;
54}
55
57 : MooseMesh(parameters),
58 _files(getParam<std::vector<MeshFileName>>("files")),
59 _pattern(getParam<std::vector<std::vector<unsigned int>>>("pattern")),
60 _x_width(getParam<Real>("x_width")),
61 _y_width(getParam<Real>("y_width")),
62 _z_width(getParam<Real>("z_width"))
63{
64 // The PatternedMesh class only works with ReplicatedMesh
65 errorIfDistributedMesh("PatternedMesh");
66
67 _meshes.reserve(_files.size());
68}
69
71 : MooseMesh(other_mesh),
72 _files(other_mesh._files),
73 _pattern(other_mesh._pattern),
74 _x_width(other_mesh._x_width),
75 _y_width(other_mesh._y_width),
76 _z_width(other_mesh._z_width)
77{
78}
79
80std::unique_ptr<MooseMesh>
82{
83 return _app.getFactory().copyConstruct(*this);
84}
85
86void
88{
89 // Read in all of the meshes
90 for (MooseIndex(_files) i = 0; i < _files.size(); ++i)
91 {
92 _meshes.emplace_back(std::make_unique<ReplicatedMesh>(_communicator));
93 auto & mesh = _meshes.back();
94
95 mesh->read(_files[i]);
96 }
97
98 // Create a mesh for all n-1 rows, the first row is the original mesh
99 _row_meshes.reserve(_pattern.size() - 1);
100 for (MooseIndex(_pattern) i = 0; i < _pattern.size() - 1; ++i)
101 _row_meshes.emplace_back(std::make_unique<ReplicatedMesh>(_communicator));
102
103 // Local pointers to simplify algorithm
104 std::vector<ReplicatedMesh *> row_meshes;
105 row_meshes.reserve(_pattern.size());
106 // First row is the original mesh
107 row_meshes.push_back(static_cast<ReplicatedMesh *>(&getMesh()));
108 // Copy the remaining raw pointers into the local vector
109 for (const auto & row_mesh : _row_meshes)
110 row_meshes.push_back(row_mesh.get());
111
112 BoundaryID left = getBoundaryID(getParam<BoundaryName>("left_boundary"));
113 BoundaryID right = getBoundaryID(getParam<BoundaryName>("right_boundary"));
114 BoundaryID top = getBoundaryID(getParam<BoundaryName>("top_boundary"));
115 BoundaryID bottom = getBoundaryID(getParam<BoundaryName>("bottom_boundary"));
116
117 // Build each row mesh
118 for (MooseIndex(_pattern) i = 0; i < _pattern.size(); ++i)
119 for (MooseIndex(_pattern) j = 0; j < _pattern[i].size(); ++j)
120 {
121 Real deltax = j * _x_width, deltay = i * _y_width;
122
123 // If this is the first cell of the row initialize the row mesh
124 if (j == 0)
125 {
126 row_meshes[i]->read(_files[_pattern[i][j]]);
127
128 MeshTools::Modification::translate(*row_meshes[i], deltax, -deltay, 0);
129
130 continue;
131 }
132
133 ReplicatedMesh & cell_mesh = *_meshes[_pattern[i][j]];
134
135 // Move the mesh into the right spot. -i because we are starting at the top
136 MeshTools::Modification::translate(cell_mesh, deltax, -deltay, 0);
137
138 row_meshes[i]->stitch_meshes(dynamic_cast<ReplicatedMesh &>(cell_mesh),
139 right,
140 left,
141 TOLERANCE,
142 /*clear_stitched_boundary_ids=*/true);
143
144 // Undo the translation
145 MeshTools::Modification::translate(cell_mesh, -deltax, deltay, 0);
146 }
147
148 // Now stitch together the rows
149 // We're going to stitch them all to row 0 (which is the real mesh)
150 for (MooseIndex(_pattern) i = 1; i < _pattern.size(); i++)
151 row_meshes[0]->stitch_meshes(
152 *row_meshes[i], bottom, top, TOLERANCE, /*clear_stitched_boundary_ids=*/true);
153}
boundary_id_type BoundaryID
registerMooseObject("MooseApp", PatternedMesh)
void ErrorVector unsigned int
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Definition Factory.h:358
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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 addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition MooseMesh.C:83
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition MooseMesh.C:1681
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition MooseMesh.C:3718
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
Reads one or more 2D mesh files and stitches them together based on a provided two-dimensional patter...
std::vector< std::unique_ptr< ReplicatedMesh > > _row_meshes
static InputParameters validParams()
virtual void buildMesh() override
Must be overridden by child classes.
const std::vector< std::vector< unsigned int > > & _pattern
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.
const Real _x_width
const std::vector< MeshFileName > & _files
PatternedMesh(const InputParameters &parameters)
std::vector< std::unique_ptr< ReplicatedMesh > > _meshes
const Real _y_width
const Parallel::Communicator & _communicator
MeshBase & mesh