www.mooseframework.org
StitchedMesh.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 "StitchedMesh.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>>(
29  "files",
30  "The name of the mesh files to read. These mesh files will be 'stitched' into the "
31  "current mesh in this order.");
32 
33  params.addRequiredParam<std::vector<BoundaryName>>(
34  "stitch_boundaries",
35  "Pairs of boundary names (one after the other) to stitch together for each step.");
36 
37  params.addParam<bool>(
38  "clear_stitched_boundary_ids",
39  true,
40  "Whether or not to erase the boundary IDs after they've been used for stitching.");
41 
42  params.addClassDescription(
43  "Reads in all of the given meshes and stitches them all together into one mesh.");
44 
45  return params;
46 }
47 
49  : MooseMesh(parameters),
50  _files(getParam<std::vector<MeshFileName>>("files")),
51  _clear_stitched_boundary_ids(getParam<bool>("clear_stitched_boundary_ids")),
52  _stitch_boundaries(getParam<std::vector<BoundaryName>>("stitch_boundaries"))
53 {
54  if (_files.empty())
55  mooseError("Must specify at least one mesh file for StitchedMesh");
56 
57  // The StitchedMesh class only works with ReplicatedMesh
58  errorIfDistributedMesh("StitchedMesh");
59 
60  // Get the original mesh
61  _original_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());
62  if (!_original_mesh)
63  mooseError("StitchedMesh does not support DistributedMesh");
64 
65  if (_stitch_boundaries.size() % 2 != 0)
66  mooseError("There must be an even amount of stitch_boundaries in ", name());
67 
68  _stitch_boundaries_pairs.reserve(_stitch_boundaries.size() / 2);
69 
70  // Make pairs out of the boundary names
71  for (auto i = beginIndex(_stitch_boundaries); i < _stitch_boundaries.size(); i += 2)
73 }
74 
76  : MooseMesh(other_mesh),
77  _files(other_mesh._files),
80 {
81 }
82 
84 
85 MooseMesh &
87 {
88  return *(new StitchedMesh(*this));
89 }
90 
91 void
93 {
94  // Read the first mesh into the original mesh... then we'll stitch all of the others into that
95  _original_mesh->read(_files[0]);
96 
97  _meshes.reserve(_files.size() - 1);
98 
99  // Read in all of the other meshes
100  for (auto i = beginIndex(_files, 1); i < _files.size(); ++i)
101  {
102  _meshes.emplace_back(libmesh_make_unique<ReplicatedMesh>(_communicator));
103  auto & mesh = _meshes.back();
104 
105  mesh->read(_files[i]);
106  }
107 
108  // Stich 'em
109  for (auto i = beginIndex(_meshes); i < _meshes.size(); i++)
110  {
111  auto & boundary_pair = _stitch_boundaries_pairs[i];
112 
113  BoundaryID first = getBoundaryID(boundary_pair.first);
114  BoundaryID second = getBoundaryID(boundary_pair.second);
115 
116  _original_mesh->stitch_meshes(
117  *_meshes[i], first, second, TOLERANCE, _clear_stitched_boundary_ids);
118  }
119 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
const bool & _clear_stitched_boundary_ids
Whether or not to clear (remove) the stitched boundary IDs.
Definition: StitchedMesh.h:52
ReplicatedMesh * _original_mesh
Definition: StitchedMesh.h:61
virtual MooseMesh & clone() const override
Clone method.
Definition: StitchedMesh.C:86
std::vector< std::unique_ptr< ReplicatedMesh > > _meshes
The meshes to be stitched together. The first entry will be the "real" mesh.
Definition: StitchedMesh.h:64
virtual void buildMesh() override
Must be overridden by child classes.
Definition: StitchedMesh.C:92
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:2526
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...
Reads an arbitrary set of meshes and attempts to "stitch" (join) them along boundaries.
Definition: StitchedMesh.h:35
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:968
InputParameters validParams< MooseMesh >()
Definition: MooseMesh.C:65
InputParameters validParams< StitchedMesh >()
Definition: StitchedMesh.C:25
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
StitchedMesh(const InputParameters &parameters)
Definition: StitchedMesh.C:48
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
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
const std::vector< BoundaryName > & _stitch_boundaries
The raw data from the input file.
Definition: StitchedMesh.h:55
const std::vector< MeshFileName > & _files
The mesh files to read.
Definition: StitchedMesh.h:49
std::vector< std::pair< BoundaryName, BoundaryName > > _stitch_boundaries_pairs
A transformed version of _stitch_boundaries into a more logical "pairwise" structure.
Definition: StitchedMesh.h:58
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
virtual ~StitchedMesh()
Definition: StitchedMesh.C:83