https://mooseframework.inl.gov
Loading...
Searching...
No Matches
StitchedMesh.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 "StitchedMesh.h"
11#include "Parser.h"
12#include "InputParameters.h"
13
14#include "MooseApp.h"
15
16#include "libmesh/mesh_modification.h"
17#include "libmesh/serial_mesh.h"
18#include "libmesh/exodusII_io.h"
19
21
24{
26 params.addRequiredParam<std::vector<MeshFileName>>(
27 "files",
28 "The name of the mesh files to read. These mesh files will be 'stitched' into the "
29 "current mesh in this order.");
30
31 params.addRequiredParam<std::vector<BoundaryName>>(
32 "stitch_boundaries",
33 "Pairs of boundary names (one after the other) to stitch together for each step.");
34
35 params.addParam<bool>(
36 "clear_stitched_boundary_ids",
37 true,
38 "Whether or not to erase the boundary IDs after they've been used for stitching.");
39
41 "Reads in all of the given meshes and stitches them all together into one mesh.");
42
43 return params;
44}
45
47 : MooseMesh(parameters),
48 _files(getParam<std::vector<MeshFileName>>("files")),
49 _clear_stitched_boundary_ids(getParam<bool>("clear_stitched_boundary_ids")),
50 _stitch_boundaries(getParam<std::vector<BoundaryName>>("stitch_boundaries"))
51{
52 if (_files.empty())
53 mooseError("Must specify at least one mesh file for StitchedMesh");
54
55 // The StitchedMesh class only works with ReplicatedMesh
56 errorIfDistributedMesh("StitchedMesh");
57
58 if (_stitch_boundaries.size() % 2 != 0)
59 mooseError("There must be an even amount of stitch_boundaries in ", name());
60
62
63 // Make pairs out of the boundary names
64 for (MooseIndex(_stitch_boundaries) i = 0; i < _stitch_boundaries.size(); i += 2)
66}
67
69 : MooseMesh(other_mesh),
70 _files(other_mesh._files),
71 _clear_stitched_boundary_ids(other_mesh._clear_stitched_boundary_ids),
72 _stitch_boundaries(other_mesh._stitch_boundaries)
73{
74}
75
76std::unique_ptr<MooseMesh>
78{
79 return _app.getFactory().copyConstruct(*this);
80}
81
82void
84{
85 // Get the original mesh
86 _original_mesh = static_cast<ReplicatedMesh *>(&getMesh());
87
88 // Read the first mesh into the original mesh... then we'll stitch all of the others into that
89 _original_mesh->read(_files[0]);
90
91 _meshes.reserve(_files.size() - 1);
92
93 // Read in all of the other meshes
94 for (MooseIndex(_files) i = 1; i < _files.size(); ++i)
95 {
96 _meshes.emplace_back(std::make_unique<ReplicatedMesh>(_communicator));
97 auto & mesh = _meshes.back();
98
99 mesh->read(_files[i]);
100 }
101
102 // Stich 'em
103 for (MooseIndex(_meshes) i = 0; i < _meshes.size(); i++)
104 {
105 auto & boundary_pair = _stitch_boundaries_pairs[i];
106
107 BoundaryID first = getBoundaryID(boundary_pair.first);
108 BoundaryID second = getBoundaryID(boundary_pair.second);
109
110 _original_mesh->stitch_meshes(
111 *_meshes[i], first, second, TOLERANCE, _clear_stitched_boundary_ids);
112 }
113}
boundary_id_type BoundaryID
registerMooseObject("MooseApp", StitchedMesh)
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.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
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 an arbitrary set of meshes and attempts to "stitch" (join) them along boundaries.
const std::vector< BoundaryName > & _stitch_boundaries
The raw data from the input file.
virtual void buildMesh() override
Must be overridden by child classes.
ReplicatedMesh * _original_mesh
static InputParameters validParams()
StitchedMesh(const InputParameters &parameters)
const std::vector< MeshFileName > & _files
The mesh files to read.
std::vector< std::pair< BoundaryName, BoundaryName > > _stitch_boundaries_pairs
A transformed version of _stitch_boundaries into a more logical "pairwise" structure.
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 bool & _clear_stitched_boundary_ids
Whether or not to clear (remove) the stitched boundary IDs.
std::vector< std::unique_ptr< ReplicatedMesh > > _meshes
The meshes to be stitched together. The first entry will be the "real" mesh.
const Parallel::Communicator & _communicator
MeshBase & mesh