www.mooseframework.org
StitchedMesh.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 "StitchedMesh.h"
11 #include "Parser.h"
12 #include "InputParameters.h"
13 
14 #include "libmesh/mesh_modification.h"
15 #include "libmesh/serial_mesh.h"
16 #include "libmesh/exodusII_io.h"
17 
19 
22 {
24  params.addRequiredParam<std::vector<MeshFileName>>(
25  "files",
26  "The name of the mesh files to read. These mesh files will be 'stitched' into the "
27  "current mesh in this order.");
28 
29  params.addRequiredParam<std::vector<BoundaryName>>(
30  "stitch_boundaries",
31  "Pairs of boundary names (one after the other) to stitch together for each step.");
32 
33  params.addParam<bool>(
34  "clear_stitched_boundary_ids",
35  true,
36  "Whether or not to erase the boundary IDs after they've been used for stitching.");
37 
38  params.addClassDescription(
39  "Reads in all of the given meshes and stitches them all together into one mesh.");
40 
41  return params;
42 }
43 
45  : MooseMesh(parameters),
46  _files(getParam<std::vector<MeshFileName>>("files")),
47  _clear_stitched_boundary_ids(getParam<bool>("clear_stitched_boundary_ids")),
48  _stitch_boundaries(getParam<std::vector<BoundaryName>>("stitch_boundaries"))
49 {
50  if (_files.empty())
51  mooseError("Must specify at least one mesh file for StitchedMesh");
52 
53  // The StitchedMesh class only works with ReplicatedMesh
54  errorIfDistributedMesh("StitchedMesh");
55 
56  if (_stitch_boundaries.size() % 2 != 0)
57  mooseError("There must be an even amount of stitch_boundaries in ", name());
58 
59  _stitch_boundaries_pairs.reserve(_stitch_boundaries.size() / 2);
60 
61  // Make pairs out of the boundary names
62  for (MooseIndex(_stitch_boundaries) i = 0; i < _stitch_boundaries.size(); i += 2)
64 }
65 
67  : MooseMesh(other_mesh),
68  _files(other_mesh._files),
69  _clear_stitched_boundary_ids(other_mesh._clear_stitched_boundary_ids),
70  _stitch_boundaries(other_mesh._stitch_boundaries)
71 {
72 }
73 
74 std::unique_ptr<MooseMesh>
76 {
77  return std::make_unique<StitchedMesh>(*this);
78 }
79 
80 void
82 {
83  // Get the original mesh
84  _original_mesh = static_cast<ReplicatedMesh *>(&getMesh());
85 
86  // Read the first mesh into the original mesh... then we'll stitch all of the others into that
87  _original_mesh->read(_files[0]);
88 
89  _meshes.reserve(_files.size() - 1);
90 
91  // Read in all of the other meshes
92  for (MooseIndex(_files) i = 1; i < _files.size(); ++i)
93  {
94  _meshes.emplace_back(std::make_unique<ReplicatedMesh>(_communicator));
95  auto & mesh = _meshes.back();
96 
97  mesh->read(_files[i]);
98  }
99 
100  // Stich 'em
101  for (MooseIndex(_meshes) i = 0; i < _meshes.size(); i++)
102  {
103  auto & boundary_pair = _stitch_boundaries_pairs[i];
104 
105  BoundaryID first = getBoundaryID(boundary_pair.first);
106  BoundaryID second = getBoundaryID(boundary_pair.second);
107 
108  _original_mesh->stitch_meshes(
109  *_meshes[i], first, second, TOLERANCE, _clear_stitched_boundary_ids);
110  }
111 }
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition: MooseMesh.C:78
const bool & _clear_stitched_boundary_ids
Whether or not to clear (remove) the stitched boundary IDs.
Definition: StitchedMesh.h:40
ReplicatedMesh * _original_mesh
Definition: StitchedMesh.h:49
registerMooseObject("MooseApp", StitchedMesh)
std::vector< std::unique_ptr< ReplicatedMesh > > _meshes
The meshes to be stitched together. The first entry will be the "real" mesh.
Definition: StitchedMesh.h:52
MeshBase & mesh
virtual void buildMesh() override
Must be overridden by child classes.
Definition: StitchedMesh.C:81
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & _communicator
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
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:23
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3367
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3198
StitchedMesh(const InputParameters &parameters)
Definition: StitchedMesh.C:44
boundary_id_type BoundaryID
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
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: StitchedMesh.C:75
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...
static InputParameters validParams()
Definition: StitchedMesh.C:21
const std::vector< BoundaryName > & _stitch_boundaries
The raw data from the input file.
Definition: StitchedMesh.h:43
const std::vector< MeshFileName > & _files
The mesh files to read.
Definition: StitchedMesh.h:37
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:1474
std::vector< std::pair< BoundaryName, BoundaryName > > _stitch_boundaries_pairs
A transformed version of _stitch_boundaries into a more logical "pairwise" structure.
Definition: StitchedMesh.h:46