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)");
58 : _app.actionWarehouse().
mesh().
get()),
59 _save_with_name(getParam<
std::string>(
"save_with_name")),
60 _data_only(getParam<bool>(data_only_param))
66 system.
dataDrivenError(*
this,
"does not support data-driven generation");
68 system.dataDrivenError(*
this,
"has 'save_with_name' set");
72 "save_with_name",
"The user-defined mesh name: '",
_save_with_name,
"' is a reserved name");
78 params.
set<
bool>(
"_has_generate_data") =
true;
84 return params.
get<
bool>(
"_has_generate_data");
87 const MeshGeneratorName *
89 const bool allow_invalid)
const 95 mooseError(
"Failed to get a parameter with the name \"",
97 "\" when getting a MeshGenerator.",
98 "\n\nKnown parameters:\n",
102 "Parameter of type \"",
104 "\" is not an expected type for getting a MeshGenerator (should be of type " 105 "\"MeshGeneratorName\")");
107 else if (!valid_param)
110 const auto &
name = getParam<MeshGeneratorName>(param_name);
116 const std::vector<MeshGeneratorName> &
120 mooseError(
"Failed to get a parameter with the name \"",
122 "\" when getting MeshGenerators.",
123 "\n\nKnown parameters:\n",
125 if (!
_pars.
isType<std::vector<MeshGeneratorName>>(param_name))
127 "Parameter of type \"",
129 "\" is not an expected type for getting MeshGenerators (should be of type " 130 "\"std::vector<MeshGeneratorName>\")");
132 const auto & names = getParam<std::vector<MeshGeneratorName>>(param_name);
133 for (
const auto &
name : names)
141 const std::string & param_name)
const 143 mooseAssert(!mesh_generator_name.empty(),
"Empty name");
146 mooseError(
"Cannot get a mesh outside of construction");
147 if (!mg_sys.hasMeshGenerator(mesh_generator_name) && !
isNullMeshName(mesh_generator_name))
149 std::stringstream error;
150 error <<
"The requested MeshGenerator with name '" << mesh_generator_name <<
"' ";
151 if (mg_sys.hasMeshGeneratorParams(mesh_generator_name))
152 error <<
"was found, but has not been constructed yet.\n\nThis can occur when your " 153 "dependencies are not properly defined and we cannot infer the proper construction " 154 "order of your MeshGenerators.\n\nThe most likely case is a sub generator whose " 155 "input(s) are not declared as a sub dependency in the generator creating them.";
157 error <<
"was not found.";
158 if (param_name.size())
165 std::unique_ptr<MeshBase> &
174 std::vector<std::unique_ptr<MeshBase> *>
180 std::unique_ptr<MeshBase> &
193 std::vector<std::unique_ptr<MeshBase> *>
196 std::vector<std::unique_ptr<MeshBase> *> meshes;
197 for (
const auto &
name : mesh_generator_names)
226 const std::vector<MeshGeneratorName> & mesh_generator_names)
228 for (
const auto &
name : mesh_generator_names)
232 std::unique_ptr<MeshBase>
235 mooseAssert(
_mesh,
"Need a MooseMesh object");
239 std::unique_ptr<ReplicatedMesh>
242 mooseAssert(
_mesh,
"Need a MooseMesh object");
246 std::unique_ptr<DistributedMesh>
249 mooseAssert(
_mesh,
"Need a MooseMesh object");
253 std::unique_ptr<MeshBase>
256 libmesh_parallel_only(
comm());
257 mooseAssert(
comm().verify(
type() +
name()),
"Inconsistent execution ordering");
267 mooseError(
"A mesh was not generated by this generator (it was nullptr).");
272 "The mesh from input ",
276 "' was not moved.\n\nThe MeshGenerator system requires that the memory from all input " 277 "meshes\nare managed by the requesting MeshGenerator during the generate phase.\n\nThis " 278 "is achieved with a std::move() operation within the generate() method.");
280 if (getParam<bool>(
"show_info"))
282 const auto mesh_info =
mesh->get_info( 2);
286 std::stringstream oss;
289 for (std::size_t i = 0; i <
split.size() - 1; ++i)
290 oss << COLOR_CYAN <<
"" <<
type() <<
" '" <<
name() <<
"': " << COLOR_DEFAULT <<
split[i]
292 _console << oss.str() << std::flush;
298 if (!
mesh->is_prepared())
299 mesh->prepare_for_use();
301 if (!getParam<bool>(
"nemesis"))
303 ExodusII_IO exio(*
mesh);
305 if (
mesh->mesh_dimension() == 1)
306 exio.write_as_dimension(3);
309 exio.set_hdf5_writing(
false);
311 exio.write(
name() +
"_in.e");
315 Nemesis_IO nemesis_io(*
mesh);
318 nemesis_io.set_hdf5_writing(
false);
320 nemesis_io.write(
name() +
"_in.e");
329 const std::string & name,
333 mooseError(
"Can only call addMeshSubgenerator() during MeshGenerator construction");
367 const bool direct )
const 371 [&
name, &direct](
const auto & mg)
373 return mg->name() ==
name ||
374 (!direct && mg->isParentMeshGenerator(
name,
false));
380 const bool direct )
const 384 [&
name, &direct](
const auto & mg)
386 return mg->name() ==
name ||
387 (!direct && mg->isChildMeshGenerator(
name,
false));
408 return getParam<bool>(
"output");
421 mooseError(
"This MeshGenerator does not have a generateData() implementation.");
virtual bool constructingMeshGenerators() const
Whether this app is constructing mesh generators.
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< MeshBase > & getMeshByName(const MeshGeneratorName &mesh_generator_name)
Like getMesh(), but takes the name of another MeshGenerator directly.
std::set< std::string > _null_mesh_names
The declared "null" mesh names that will not represent a mesh in input; see declareNullMeshName() ...
RestartableDataValue & setMeshPropertyHelper(const std::string &data_name)
Helper for getting a writable reference to a mesh property, used in declareMeshProperty and setMeshPr...
static const std::string data_only_param
The name of the private parameter for setting data only.
const MeshGenerator & getMeshGenerator(const std::string &name) const
bool isChildMeshGenerator(const MeshGeneratorName &name, const bool direct=true) const
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
Build a replicated mesh.
std::unique_ptr< MeshBase > & getMeshGeneratorOutput(const MeshGeneratorName &name)
Get a reference to a pointer that will be the output of the MeshGenerator named name.
const std::string & _save_with_name
A user-defined name to save the mesh.
bool hasSaveMesh() const
Return whether or not to save the current mesh.
static const RestartableDataMapName MESH_META_DATA
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
virtual void generateData()
Generate the mesh data.
Base class for MOOSE-based applications.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
const Parallel::Communicator & comm() const
const std::set< const MeshGenerator *, Comparator > & getChildMeshGenerators() const
Gets the MeshGenerators that are children to this MeshGenerator.
std::unique_ptr< MeshBase > _null_mesh
A nullptr to use for when inputs aren't specified.
MeshGenerator(const InputParameters ¶meters)
bool hasGenerateData() const
virtual const std::string & name() const
Get the name of the class.
std::set< const MeshGenerator *, Comparator > _child_mesh_generators
The MeshGenerators that are children to this MeshGenerator.
bool isNullMeshName(const MeshGeneratorName &name) const
MooseMesh *const _mesh
Pointer to the owning mesh.
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
Python like split functions for strings.
void addChildMeshGenerator(const MeshGenerator &mg, const AddParentChildKey)
Adds the MeshGenerator mg as a child.
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
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 addParentMeshGenerator(const MeshGenerator &mg, const AddParentChildKey)
Adds the MeshGenerator mg as a parent.
bool isParentMeshGenerator(const MeshGeneratorName &name, const bool direct=true) const
RestartableDataValue & getRestartableMetaData(const std::string &name, const RestartableDataMapName &metaname, THREAD_ID tid)
std::unique_ptr< T > buildTypedMesh(unsigned int dim=libMesh::invalid_uint)
Shortcut method to construct a unique pointer to a libMesh mesh instance.
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...
Every object that can be built by the factory should be derived from this class.
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 ...
void declareMeshesForSubByName(const std::vector< MeshGeneratorName > &mesh_generator_names)
Like declareMeshForSubByName(), but for multiple generators.
std::set< MeshGeneratorName > _requested_mesh_generators_for_sub
The names of the MeshGenerators that were requested in the declareMeshForSub methods.
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...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
virtual std::unique_ptr< MeshBase > generate()=0
Generate / modify the mesh.
const std::string & type() const
Get the type of this class.
std::set< MeshGeneratorName > _requested_mesh_generators
The names of the MeshGenerators that were requested in the getMesh methods.
std::vector< std::unique_ptr< MeshBase > * > getMeshesByName(const std::vector< MeshGeneratorName > &mesh_generator_names)
Like getMeshByName(), but for multiple generators.
std::vector< std::unique_ptr< MeshBase > * > getMeshes(const std::string ¶m_name)
Like getMesh(), but for multiple generators.
MooseApp & _app
The MOOSE application this is associated with.
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 ...
static InputParameters validParams()
std::unique_ptr< MeshBase > generateInternal()
Internal generation method - this is what is actually called within MooseApp to execute the MeshGener...
std::set< const MeshGenerator *, Comparator > _sub_mesh_generators
The sub MeshGenerators constructed by this MeshGenerator.
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.
Class that is used as a parameter to add[Parent/Child]() that allows only MeshGeneratorSystem methods...
const std::set< const MeshGenerator *, Comparator > & getParentMeshGenerators() const
Gets the MeshGenerators that are parents to this MeshGenerator.
void checkGetMesh(const MeshGeneratorName &mesh_generator_name, const std::string ¶m_name) const
Helper for performing error checking in the getMesh methods.
std::set< const MeshGenerator *, Comparator > _parent_mesh_generators
The MeshGenerators that are parents to this MeshGenerator.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
static void setHasGenerateData(InputParameters ¶ms)
Sets that a mesh generator has a generateData() implementation.
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 ConsoleStream _console
An instance of helper class to write streams to the Console objects.
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...
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
static InputParameters validParams()
void declareMeshesForSub(const std::string ¶m_name)
Like declareMeshForSub(), but for multiple generators.
void declareNullMeshName(const MeshGeneratorName &name)
Registers the name name as a "null" mesh, which is a MeshGenerator used in InputParameters that will ...
const std::string & getSavedMeshName() const
Return the name of the saved mesh.
void declareMeshForSubByName(const MeshGeneratorName &mesh_generator_name)
Like declareMeshForSub(), but takes the name of another MeshGenerator directly.
MeshGenerators are objects that can modify or add to an existing mesh.
const std::vector< MeshGeneratorName > & getMeshGeneratorNamesFromParam(const std::string ¶m_name) const
Helper for getting a std::vector<MeshGeneratorName> parameter.
Abstract definition of a RestartableData value.
const MeshGeneratorName * getMeshGeneratorNameFromParam(const std::string ¶m_name, const bool allow_invalid) const
Helper for getting a MeshGeneratorName parameter.