17#include "libmesh/exodusII_io.h"
18#include "libmesh/nemesis_io.h"
29 "Whether or not to show mesh info after generating the mesh "
30 "(bounding box, element types, sidesets, nodesets, subdomains, etc)");
34 "Keep the mesh from this mesh generator in memory with the name specified");
37 "output",
false,
"Whether or not to output the mesh file after generating the mesh");
40 "Whether or not to output the mesh file in the nemesis"
41 "format (only if output = true)");
61 : _app.actionWarehouse().
mesh().get()),
62 _save_with_name(getParam<
std::string>(
"save_with_name")),
63 _data_only(getParam<bool>(data_only_param))
70 system.
dataDrivenError(*
this,
"does not support data-driven generation");
72 system.dataDrivenError(*
this,
"has 'save_with_name' set");
76 "save_with_name",
"The user-defined mesh name: '",
_save_with_name,
"' is a reserved name");
77 if (getParam<bool>(
"nemesis") && !getParam<bool>(
"output"))
78 paramError(
"nemesis",
"Should only be set to true if 'output=true'");
84 params.
set<
bool>(
"_has_generate_data") =
true;
90 return params.
get<
bool>(
"_has_generate_data");
96 params.
set<
bool>(
"_has_generate_csg") =
true;
102 return params.
get<
bool>(
"_has_generate_csg");
105const MeshGeneratorName *
107 const bool allow_invalid)
const
113 mooseError(
"Failed to get a parameter with the name \"",
115 "\" when getting a MeshGenerator.",
116 "\n\nKnown parameters:\n",
120 "Parameter of type \"",
122 "\" is not an expected type for getting a MeshGenerator (should be of type "
123 "\"MeshGeneratorName\")");
125 else if (!valid_param)
128 const auto &
name = getParam<MeshGeneratorName>(param_name);
134const std::vector<MeshGeneratorName> &
138 mooseError(
"Failed to get a parameter with the name \"",
140 "\" when getting MeshGenerators.",
141 "\n\nKnown parameters:\n",
143 if (!
_pars.
isType<std::vector<MeshGeneratorName>>(param_name))
145 "Parameter of type \"",
147 "\" is not an expected type for getting MeshGenerators (should be of type "
148 "\"std::vector<MeshGeneratorName>\")");
150 const auto & names = getParam<std::vector<MeshGeneratorName>>(param_name);
151 for (
const auto &
name : names)
159 const std::string & param_name)
const
161 mooseAssert(!mesh_generator_name.empty(),
"Empty name");
164 mooseError(
"Cannot get a mesh outside of construction");
165 if (!mg_sys.hasMeshGenerator(mesh_generator_name) && !
isNullMeshName(mesh_generator_name))
167 std::stringstream error;
168 error <<
"The requested MeshGenerator with name '" << mesh_generator_name <<
"' ";
169 if (mg_sys.hasMeshGeneratorParams(mesh_generator_name))
170 error <<
"was found, but has not been constructed yet.\n\nThis can occur when your "
171 "dependencies are not properly defined and we cannot infer the proper construction "
172 "order of your MeshGenerators.\n\nThe most likely case is a sub generator whose "
173 "input(s) are not declared as a sub dependency in the generator creating them.";
175 error <<
"was not found.\nMesh generators that can be found: "
178 if (param_name.size())
185std::unique_ptr<MeshBase> &
194std::vector<std::unique_ptr<MeshBase> *>
200std::unique_ptr<MeshBase> &
213std::vector<std::unique_ptr<MeshBase> *>
216 std::vector<std::unique_ptr<MeshBase> *> meshes;
217 for (
const auto &
name : mesh_generator_names)
222std::unique_ptr<CSG::CSGBase> &
231std::unique_ptr<CSG::CSGBase> &
243std::vector<std::unique_ptr<CSG::CSGBase> *>
249std::vector<std::unique_ptr<CSG::CSGBase> *>
252 std::vector<std::unique_ptr<CSG::CSGBase> *> csg_bases;
253 for (
const auto &
name : mesh_generator_names)
282 const std::vector<MeshGeneratorName> & mesh_generator_names)
284 for (
const auto &
name : mesh_generator_names)
288std::unique_ptr<MeshBase>
291 mooseAssert(
_mesh,
"Need a MooseMesh object");
295std::unique_ptr<ReplicatedMesh>
298 mooseAssert(
_mesh,
"Need a MooseMesh object");
302std::unique_ptr<DistributedMesh>
305 mooseAssert(
_mesh,
"Need a MooseMesh object");
309std::unique_ptr<MeshBase>
312 libmesh_parallel_only(
comm());
313 mooseAssert(
comm().verify(
type() +
name()),
"Inconsistent execution ordering");
323 mooseError(
"A mesh was not generated by this generator (it was nullptr).");
328 "The mesh from input ",
332 "' was not moved.\n\nThe MeshGenerator system requires that the memory from all input "
333 "meshes\nare managed by the requesting MeshGenerator during the generate phase.\n\nThis "
334 "is achieved with a std::move() operation within the generate() method.");
336 if (getParam<bool>(
"show_info"))
338 if (!
mesh->is_prepared())
339 mesh->prepare_for_use();
341 const auto mesh_info =
mesh->get_info( 2);
345 std::stringstream oss;
348 for (std::size_t i = 0; i < split.size() - 1; ++i)
349 oss << COLOR_CYAN <<
"" <<
type() <<
" '" <<
name() <<
"': " << COLOR_DEFAULT << split[i]
351 _console << oss.str() << std::flush;
357 if (!
mesh->is_prepared())
358 mesh->prepare_for_use();
360 if (!getParam<bool>(
"nemesis"))
364 if (
mesh->mesh_dimension() == 1)
389std::unique_ptr<CSG::CSGBase>
392 mooseAssert(
isDataOnly(),
"Trying to use csg-only mode while not in data-driven mode");
394 mooseAssert(csg_obj,
"Null CSG object");
398 "The CSGBase object from input ",
402 "' was not moved.\n\nThe MeshGenerator system requires that the memory from all input "
403 "meshes\nare managed by the requesting MeshGenerator during the generate phase.\n\nThis "
404 "is achieved with a std::move() operation within the generateCSG() method.");
411 const std::string & name,
415 mooseError(
"Can only call addMeshSubgenerator() during MeshGenerator construction");
449 const bool direct )
const
453 [&
name, &direct](
const auto & mg)
455 return mg->name() ==
name ||
456 (!direct && mg->isParentMeshGenerator(
name,
false));
462 const bool direct )
const
466 [&
name, &direct](
const auto & mg)
468 return mg->name() ==
name ||
469 (!direct && mg->isChildMeshGenerator(
name,
false));
490 return getParam<bool>(
"output");
503 mooseError(
"This MeshGenerator does not have a generateData() implementation.");
506[[nodiscard]] std::unique_ptr<CSG::CSGBase>
510 mooseError(
"This MeshGenerator does not have a generateCSG() implementation.");
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
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::unique_ptr< CSG::CSGBase > & getCSGBaseGeneratorOutput(const MeshGeneratorName &name)
Returns the output CSGBase object associated with a particular mesh generator name.
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...
Class that is used as a parameter to add[Parent/Child]() that allows only MeshGeneratorSystem methods...
MeshGenerators are objects that can modify or add to an existing mesh.
virtual std::unique_ptr< MeshBase > generate()=0
Generate / modify the mesh.
void declareMeshForSub(const std::string ¶m_name)
Declares that a MeshGenerator referenced in the InputParameters is to be used as a dependency of a su...
std::set< const MeshGenerator *, Comparator > _child_mesh_generators
The MeshGenerators that are children to this MeshGenerator.
const std::string & getSavedMeshName() const
Return the name of the saved mesh.
std::vector< std::unique_ptr< MeshBase > * > getMeshes(const std::string ¶m_name)
Like getMesh(), but for multiple generators.
bool hasSaveMesh() const
Return whether or not to save the current mesh.
virtual std::unique_ptr< CSG::CSGBase > generateCSG()
Generate the CSG representation of the mesh (or meshing operation) created by this mesh generator.
std::set< MeshGeneratorName > _requested_mesh_generators
The names of the MeshGenerators that were requested in the getMesh methods.
void addMeshSubgenerator(const std::string &type, const std::string &name, Ts... extra_input_parameters)
Construct a "subgenerator", a different MeshGenerator subclass that will be added to the same MooseAp...
std::unique_ptr< MeshBase > & getMesh(const std::string ¶m_name, const bool allow_invalid=false)
Takes the name of a MeshGeneratorName parameter and then gets a pointer to the Mesh that MeshGenerato...
std::vector< std::unique_ptr< CSG::CSGBase > * > getCSGBasesByName(const std::vector< MeshGeneratorName > &mesh_generator_names)
Like getCSGBaseByName(), but for multiple generators.
std::unique_ptr< MeshBase > _null_mesh
A nullptr to use for when inputs aren't specified.
std::unique_ptr< MeshBase > & getMeshByName(const MeshGeneratorName &mesh_generator_name)
Like getMesh(), but takes the name of another MeshGenerator directly.
const std::string & _save_with_name
A user-defined name to save the mesh.
std::set< MeshGeneratorName > _requested_mesh_generators_for_sub
The names of the MeshGenerators that were requested in the declareMeshForSub methods.
MooseMesh *const _mesh
Pointer to the owning mesh.
bool hasGenerateCSG() const
std::unique_ptr< CSG::CSGBase > generateInternalCSG()
Internal generation method for CSG object generation.
std::unique_ptr< MeshBase > generateInternal()
Internal generation method - this is what is actually called within MooseApp to execute the MeshGener...
static void setHasGenerateCSG(InputParameters ¶ms)
Sets that a mesh generator has a generateCSG() implementation.
const std::vector< MeshGeneratorName > & getMeshGeneratorNamesFromParam(const std::string ¶m_name) const
Helper for getting a std::vector<MeshGeneratorName> parameter.
bool isParentMeshGenerator(const MeshGeneratorName &name, const bool direct=true) const
std::unique_ptr< DistributedMesh > buildDistributedMesh(unsigned int dim=libMesh::invalid_uint)
Build a distributed mesh that has correct remote element removal behavior and geometric ghosting func...
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
Build a replicated mesh.
std::vector< std::pair< std::string, std::unique_ptr< CSG::CSGBase > * > > _requested_csg_bases
The CSGBase objects that were requested by this MeshGenerator; used to verify that any input meshes t...
std::vector< std::unique_ptr< CSG::CSGBase > * > getCSGBases(const std::string ¶m_name)
Like getCSGBase(), but for multiple generators.
static InputParameters validParams()
std::set< const MeshGenerator *, Comparator > _sub_mesh_generators
The sub MeshGenerators constructed by this MeshGenerator.
static const std::string data_only_param
The name of the private parameter for setting data only.
MeshGenerator(const InputParameters ¶meters)
std::unique_ptr< CSG::CSGBase > & getCSGBase(const std::string ¶m_name)
Takes the name of a MeshGeneratorName parameter and then gets a pointer to the CSGBase object that Me...
bool isNullMeshName(const MeshGeneratorName &name) const
const std::set< const MeshGenerator *, Comparator > & getChildMeshGenerators() const
Gets the MeshGenerators that are children to this MeshGenerator.
const std::set< const MeshGenerator *, Comparator > & getParentMeshGenerators() const
Gets the MeshGenerators that are parents to this MeshGenerator.
RestartableDataValue & setMeshPropertyHelper(const std::string &data_name)
Helper for getting a writable reference to a mesh property, used in declareMeshProperty and setMeshPr...
std::vector< std::unique_ptr< MeshBase > * > getMeshesByName(const std::vector< MeshGeneratorName > &mesh_generator_names)
Like getMeshByName(), but for multiple generators.
std::unique_ptr< CSG::CSGBase > & getCSGBaseByName(const MeshGeneratorName &mesh_generator_name)
Like getCSGBase(), but takes the name of another MeshGenerator directly.
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Build a MeshBase object whose underlying type will be determined by the Mesh input file block.
const MeshGeneratorName * getMeshGeneratorNameFromParam(const std::string ¶m_name, const bool allow_invalid) const
Helper for getting a MeshGeneratorName parameter.
void declareMeshesForSub(const std::string ¶m_name)
Like declareMeshForSub(), but for multiple generators.
static void setHasGenerateData(InputParameters ¶ms)
Sets that a mesh generator has a generateData() implementation.
std::vector< std::pair< std::string, std::unique_ptr< MeshBase > * > > _requested_meshes
The meshes that were requested by this MeshGenerator; used to verify that any input meshes that are r...
void declareMeshesForSubByName(const std::vector< MeshGeneratorName > &mesh_generator_names)
Like declareMeshForSubByName(), but for multiple generators.
void declareMeshForSubByName(const MeshGeneratorName &mesh_generator_name)
Like declareMeshForSub(), but takes the name of another MeshGenerator directly.
std::unique_ptr< CSG::CSGBase > _null_csg_base
A nullptr to use for when inputs aren't specified.
std::set< std::string > _null_mesh_names
The declared "null" mesh names that will not represent a mesh in input; see declareNullMeshName()
bool isChildMeshGenerator(const MeshGeneratorName &name, const bool direct=true) const
std::set< const MeshGenerator *, Comparator > _parent_mesh_generators
The MeshGenerators that are parents to this MeshGenerator.
bool hasGenerateData() const
void declareNullMeshName(const MeshGeneratorName &name)
Registers the name name as a "null" mesh, which is a MeshGenerator used in InputParameters that will ...
void checkGetMesh(const MeshGeneratorName &mesh_generator_name, const std::string ¶m_name) const
Helper for performing error checking in the getMesh methods.
void addChildMeshGenerator(const MeshGenerator &mg, const AddParentChildKey)
Adds the MeshGenerator mg as a child.
void addParentMeshGenerator(const MeshGenerator &mg, const AddParentChildKey)
Adds the MeshGenerator mg as a parent.
virtual void generateData()
Generate the mesh data.
Base class for MOOSE-based applications.
void addMeshGenerator(const std::string &type, const std::string &name, const InputParameters ¶ms)
Add a mesh generator that will act on the meshes in the system.
virtual bool constructingMeshGenerators() const
Whether this app is constructing mesh generators.
RestartableDataValue & getRestartableMetaData(const std::string &name, const RestartableDataMapName &metaname, THREAD_ID tid)
const MeshGenerator & getMeshGenerator(const std::string &name) const
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
static const RestartableDataMapName MESH_META_DATA
const std::string & type() const
Get the type of this class.
const std::string & name() const
Get the name of the class.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
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...
const InputParameters & _pars
The object's parameters.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
static const std::string app_param
The name of the parameter that contains the MooseApp.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
std::unique_ptr< T > buildTypedMesh(unsigned int dim=libMesh::invalid_uint)
Shortcut method to construct a unique pointer to a libMesh mesh instance.
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Method to construct a libMesh::MeshBase object that is normally set and used by the MooseMesh object ...
Every object that can be built by the factory should be derived from this class.
static InputParameters validParams()
MooseApp & _app
The MOOSE application this is associated with.
Abstract definition of a RestartableData value.
void set_max_name_length(unsigned int max_length)
virtual void write(const std::string &fname) override
void set_hdf5_writing(bool write_hdf5)
void write_as_dimension(unsigned dim)
void set_hdf5_writing(bool write_hdf5)
virtual void write(const std::string &base_filename) override
const Parallel::Communicator & comm() const
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count)
std::string stringify(const T &t)
conversion to string