https://mooseframework.inl.gov
MeshGeneratorSystem.h
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 #pragma once
11 
12 #include "InputParameters.h"
13 #include "PerfGraphInterface.h"
14 
15 #include "libmesh/parallel_object.h"
16 #include "libmesh/mesh_base.h"
17 
18 class MooseApp;
19 class MeshGeneratorMesh;
20 class MeshGenerator;
21 namespace CSG
22 {
23 class CSGBase;
24 }
25 
32 {
33 public:
35 
37  static const std::string data_driven_generator_param;
39  static const std::string allow_data_driven_param;
40 
44  void executeMeshGenerators();
45 
62  void addMeshGenerator(const std::string & type,
63  const std::string & name,
64  const InputParameters & params);
65 
78  const MeshGenerator &
79  appendMeshGenerator(const std::string & type, const std::string & name, InputParameters params);
80 
85  [[nodiscard]] std::unique_ptr<libMesh::MeshBase> &
86  getMeshGeneratorOutput(const MeshGeneratorName & name);
87 
107 
115  std::vector<std::string> getMeshGeneratorNames() const;
116 
120  [[nodiscard]] std::unique_ptr<libMesh::MeshBase> getSavedMesh(const std::string & name);
121 
125  std::vector<std::string> getSavedMeshNames() const;
126 
130  void setCSGOnly();
131 
135  bool getCSGOnly() const { return _csg_only; }
136 
137  const std::vector<std::vector<MeshGenerator *>> & getOrderedMeshGenerators() const
138  {
139  mooseAssert(_ordered_mesh_generators.size(), "Mesh generator order has not been set");
141  }
142 
146  bool hasMeshGenerator(const MeshGeneratorName & name) const;
147 
151  const MeshGenerator & getMeshGenerator(const std::string & name) const;
152 
161  bool hasMeshGeneratorParams(const MeshGeneratorName & name) const;
162 
166  bool appendingMeshGenerators() const;
167 
172  static std::string mainMeshGeneratorName() { return "main"; };
173 
177  bool hasDataDrivenAllowed() const;
178 
185  void dataDrivenError(const MeshGenerator & generator, const std::string & message) const;
186 
188  MeshGeneratorName getFinalMeshGeneratorName() const { return _final_generator_name; }
189 
191  void setVerbose(const bool verbose) { _verbose = verbose; }
192 
201  void saveOutputCSGBase(const MeshGeneratorName generator_name,
202  std::unique_ptr<CSG::CSGBase> & csg_base);
203 
210  std::unique_ptr<CSG::CSGBase> & getCSGBaseGeneratorOutput(const MeshGeneratorName & name);
211 
212 private:
221  std::vector<std::pair<std::string, MeshGeneratorName>>
223  const bool allow_empty = false) const;
224 
230 
235  std::shared_ptr<MeshGenerator> createMeshGenerator(const std::string & name);
236 
244  MeshGenerator & getMeshGeneratorInternal(const std::string & name)
245  {
246  return const_cast<MeshGenerator &>(std::as_const(*this).getMeshGenerator(name));
247  }
248 
252  const std::string & getDataDrivenGeneratorName() const;
253 
256 
259  std::unordered_map<std::string, std::pair<std::string, InputParameters>> _mesh_generator_params;
260 
262  std::map<std::string, std::shared_ptr<MeshGenerator>> _mesh_generators;
263 
265  std::vector<std::vector<MeshGenerator *>> _ordered_mesh_generators;
266 
268  std::map<std::string, std::list<std::unique_ptr<libMesh::MeshBase>>> _mesh_generator_outputs;
269 
272 
274  std::map<std::string, std::unique_ptr<libMesh::MeshBase>> _save_in_meshes;
275 
277  std::optional<std::string> _data_driven_generator_name;
278 
280  bool _verbose;
281 
283  bool _csg_only;
284 
286  std::map<std::string, std::list<std::unique_ptr<CSG::CSGBase>>> _csg_base_outputs;
287 };
std::string name(const ElemQuality q)
std::unique_ptr< CSG::CSGBase > & getCSGBaseGeneratorOutput(const MeshGeneratorName &name)
Returns the output CSGBase object associated with a particular mesh generator name.
std::string _final_generator_name
The final mesh generator name to use.
MeshGeneratorSystem(MooseApp &app)
void setVerbose(const bool verbose)
Set the verbose flag.
std::shared_ptr< MeshGenerator > createMeshGenerator(const std::string &name)
Internal method for actually constructing a mesh generator after it has been declared externally in a...
std::unique_ptr< libMesh::MeshBase > & getMeshGeneratorOutput(const MeshGeneratorName &name)
Get a reference to a pointer that will be the output of the MeshGenerator named name.
void setCSGOnly()
Set whether mesh generator system is running in CSG-only mode to true.
std::map< std::string, std::unique_ptr< libMesh::MeshBase > > _save_in_meshes
Holds the map of save in mesh -> name.
bool hasDataDrivenAllowed() const
MeshGeneratorName getFinalMeshGeneratorName() const
Get the name of the final mesh generator.
std::unique_ptr< libMesh::MeshBase > getSavedMesh(const std::string &name)
Get the saved mesh by name.
std::vector< std::string > getMeshGeneratorNames() const
Get names of all mesh generators Note: This function should be called after all mesh generators are a...
Base class for MOOSE-based applications.
Definition: MooseApp.h:108
void executeMeshGenerators()
Execute and clear the Mesh Generators data structure.
std::optional< std::string > _data_driven_generator_name
The name of the data driven generator, if any.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool _verbose
Whether to print the names of the mesh generators being executed or not.
void addMeshGenerator(const std::string &type, const std::string &name, const InputParameters &params)
Add a mesh generator that will act on the meshes in the system.
const MeshGenerator & appendMeshGenerator(const std::string &type, const std::string &name, InputParameters params)
Append a mesh generator that will act on the current final mesh generator in the system.
MooseApp & _app
The MooseApp that owns this system.
void createAddedMeshGenerators()
Creates (constructs) all of the MeshGenerators that have been declared using addMeshGenerator().
bool getCSGOnly() const
Get whether mesh generator system is running in CSG-only mode.
bool _csg_only
Whether mesh generator system is running in CSG-only mode.
void saveOutputCSGBase(const MeshGeneratorName generator_name, std::unique_ptr< CSG::CSGBase > &csg_base)
Saves the CSGBase object to the global map storage, _csg_base_output, for a particular mesh generator...
std::map< std::string, std::list< std::unique_ptr< libMesh::MeshBase > > > _mesh_generator_outputs
Holds the output for each mesh generator - including duplicates needed downstream.
Interface for objects interacting with the PerfGraph.
std::vector< std::string > getSavedMeshNames() const
Get all user-defined saved meshes except main and main_displaced.
static std::string mainMeshGeneratorName()
The name reserved for the "main" mesh generator which is the one used for the numerical solver downst...
std::map< std::string, std::shared_ptr< MeshGenerator > > _mesh_generators
Owning storage for mesh generators, map of name -> MeshGenerator.
Mesh generated from parameters.
std::map< std::string, std::list< std::unique_ptr< CSG::CSGBase > > > _csg_base_outputs
Holds the output CSGBase object for each mesh generator - including duplicates when needed by multipl...
void createMeshGeneratorOrder()
Order all of the _mesh_generators into _ordered_mesh_generators for later execution in executeMeshGen...
static const std::string data_driven_generator_param
The name of the string parameter that sets the data driven generator.
bool hasMeshGenerator(const MeshGeneratorName &name) const
void dataDrivenError(const MeshGenerator &generator, const std::string &message) const
Reports an error with the context of the data driven parameter, coming from the generator generator w...
const MeshGenerator & getMeshGenerator(const std::string &name) const
System that manages MeshGenerators.
bool appendingMeshGenerators() const
Whether or not mesh generators are currently being appended (append_mesh_generator task) ...
static const std::string allow_data_driven_param
The name of the boolean parameter on the MooseApp that will enable data driven generation.
const std::string & getDataDrivenGeneratorName() const
MeshGenerator & getMeshGeneratorInternal(const std::string &name)
Get a MeshGenerator with the name name.
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:33
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model...
Definition: CSGBase.h:51
std::unordered_map< std::string, std::pair< std::string, InputParameters > > _mesh_generator_params
The MeshGenerators declared using addMeshGenerator(), cleared after createMeshGenerators() Key is the...
bool hasMeshGeneratorParams(const MeshGeneratorName &name) const
Whether or not we know about the parameters for a MeshGenerator with the given name.
std::vector< std::pair< std::string, MeshGeneratorName > > getMeshGeneratorParamDependencies(const InputParameters &params, const bool allow_empty=false) const
Gets the MeshGeneratorNames that are referenced in an object&#39;s parameters.
const std::vector< std::vector< MeshGenerator * > > & getOrderedMeshGenerators() const
std::vector< std::vector< MeshGenerator * > > _ordered_mesh_generators
Holds the ordered mesh generators from createMeshGeneratorOrder() until they are executed in executeM...