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 
28 {
29 public:
31 
33  static const std::string data_driven_generator_param;
35  static const std::string allow_data_driven_param;
36 
40  void executeMeshGenerators();
41 
58  void addMeshGenerator(const std::string & type,
59  const std::string & name,
60  const InputParameters & params);
61 
74  const MeshGenerator &
75  appendMeshGenerator(const std::string & type, const std::string & name, InputParameters params);
76 
81  [[nodiscard]] std::unique_ptr<libMesh::MeshBase> &
82  getMeshGeneratorOutput(const MeshGeneratorName & name);
83 
103 
111  std::vector<std::string> getMeshGeneratorNames() const;
112 
116  [[nodiscard]] std::unique_ptr<libMesh::MeshBase> getSavedMesh(const std::string & name);
117 
121  std::vector<std::string> getSavedMeshNames() const;
122 
126  bool hasMeshGenerator(const MeshGeneratorName & name) const;
127 
131  const MeshGenerator & getMeshGenerator(const std::string & name) const;
132 
141  bool hasMeshGeneratorParams(const MeshGeneratorName & name) const;
142 
146  bool appendingMeshGenerators() const;
147 
152  static std::string mainMeshGeneratorName() { return "main"; };
153 
157  bool hasBreakMeshByBlockGenerator() const { return _has_bmbb; }
158 
162  bool hasDataDrivenAllowed() const;
163 
170  void dataDrivenError(const MeshGenerator & generator, const std::string & message) const;
171 
173  MeshGeneratorName getFinalMeshGeneratorName() const { return _final_generator_name; }
174 
176  void setVerbose(const bool verbose) { _verbose = verbose; }
177 
178 private:
187  std::vector<std::pair<std::string, MeshGeneratorName>>
189  const bool allow_empty = false) const;
190 
196 
201  std::shared_ptr<MeshGenerator> createMeshGenerator(const std::string & name);
202 
210  MeshGenerator & getMeshGeneratorInternal(const std::string & name)
211  {
212  return const_cast<MeshGenerator &>(std::as_const(*this).getMeshGenerator(name));
213  }
214 
218  const std::string & getDataDrivenGeneratorName() const;
219 
222 
225  std::unordered_map<std::string, std::pair<std::string, InputParameters>> _mesh_generator_params;
226 
228  std::map<std::string, std::shared_ptr<MeshGenerator>> _mesh_generators;
229 
231  std::vector<std::vector<MeshGenerator *>> _ordered_mesh_generators;
232 
234  std::map<std::string, std::list<std::unique_ptr<libMesh::MeshBase>>> _mesh_generator_outputs;
235 
238 
240  std::map<std::string, std::unique_ptr<libMesh::MeshBase>> _save_in_meshes;
241 
243  std::optional<std::string> _data_driven_generator_name;
244 
246  bool _has_bmbb;
247 
249  bool _verbose;
250 };
std::string name(const ElemQuality q)
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.
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:85
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 hasBreakMeshByBlockGenerator() const
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().
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.
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.
bool _has_bmbb
Whether any of the mesh generators are a BreakMeshByBlockGenerator.
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
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.
std::vector< std::vector< MeshGenerator * > > _ordered_mesh_generators
Holds the ordered mesh generators from createMeshGeneratorOrder() until they are executed in executeM...