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)");
60 : _app.actionWarehouse().
mesh().
get()),
61 _save_with_name(getParam<
std::string>(
"save_with_name")),
62 _data_only(getParam<bool>(data_only_param))
68 system.
dataDrivenError(*
this,
"does not support data-driven generation");
70 system.dataDrivenError(*
this,
"has 'save_with_name' set");
74 "save_with_name",
"The user-defined mesh name: '",
_save_with_name,
"' is a reserved name");
75 if (getParam<bool>(
"nemesis") && !getParam<bool>(
"output"))
76 paramError(
"nemesis",
"Should only be set to true if 'output=true'");
82 params.
set<
bool>(
"_has_generate_data") =
true;
88 return params.
get<
bool>(
"_has_generate_data");
91 const MeshGeneratorName *
93 const bool allow_invalid)
const 99 mooseError(
"Failed to get a parameter with the name \"",
101 "\" when getting a MeshGenerator.",
102 "\n\nKnown parameters:\n",
106 "Parameter of type \"",
108 "\" is not an expected type for getting a MeshGenerator (should be of type " 109 "\"MeshGeneratorName\")");
111 else if (!valid_param)
114 const auto &
name = getParam<MeshGeneratorName>(param_name);
120 const std::vector<MeshGeneratorName> &
124 mooseError(
"Failed to get a parameter with the name \"",
126 "\" when getting MeshGenerators.",
127 "\n\nKnown parameters:\n",
129 if (!
_pars.
isType<std::vector<MeshGeneratorName>>(param_name))
131 "Parameter of type \"",
133 "\" is not an expected type for getting MeshGenerators (should be of type " 134 "\"std::vector<MeshGeneratorName>\")");
136 const auto & names = getParam<std::vector<MeshGeneratorName>>(param_name);
137 for (
const auto &
name : names)
145 const std::string & param_name)
const 147 mooseAssert(!mesh_generator_name.empty(),
"Empty name");
150 mooseError(
"Cannot get a mesh outside of construction");
151 if (!mg_sys.hasMeshGenerator(mesh_generator_name) && !
isNullMeshName(mesh_generator_name))
153 std::stringstream error;
154 error <<
"The requested MeshGenerator with name '" << mesh_generator_name <<
"' ";
155 if (mg_sys.hasMeshGeneratorParams(mesh_generator_name))
156 error <<
"was found, but has not been constructed yet.\n\nThis can occur when your " 157 "dependencies are not properly defined and we cannot infer the proper construction " 158 "order of your MeshGenerators.\n\nThe most likely case is a sub generator whose " 159 "input(s) are not declared as a sub dependency in the generator creating them.";
161 error <<
"was not found.\nMesh generators that can be found: " 164 if (param_name.size())
171 std::unique_ptr<MeshBase> &
180 std::vector<std::unique_ptr<MeshBase> *>
186 std::unique_ptr<MeshBase> &
199 std::vector<std::unique_ptr<MeshBase> *>
202 std::vector<std::unique_ptr<MeshBase> *> meshes;
203 for (
const auto &
name : mesh_generator_names)
232 const std::vector<MeshGeneratorName> & mesh_generator_names)
234 for (
const auto &
name : mesh_generator_names)
238 std::unique_ptr<MeshBase>
241 mooseAssert(
_mesh,
"Need a MooseMesh object");
245 std::unique_ptr<ReplicatedMesh>
248 mooseAssert(
_mesh,
"Need a MooseMesh object");
252 std::unique_ptr<DistributedMesh>
255 mooseAssert(
_mesh,
"Need a MooseMesh object");
259 std::unique_ptr<MeshBase>
262 libmesh_parallel_only(
comm());
263 mooseAssert(
comm().verify(
type() +
name()),
"Inconsistent execution ordering");
273 mooseError(
"A mesh was not generated by this generator (it was nullptr).");
278 "The mesh from input ",
282 "' was not moved.\n\nThe MeshGenerator system requires that the memory from all input " 283 "meshes\nare managed by the requesting MeshGenerator during the generate phase.\n\nThis " 284 "is achieved with a std::move() operation within the generate() method.");
286 if (getParam<bool>(
"show_info"))
288 const auto mesh_info =
mesh->get_info( 2);
292 std::stringstream oss;
295 for (std::size_t i = 0; i <
split.size() - 1; ++i)
296 oss << COLOR_CYAN <<
"" <<
type() <<
" '" <<
name() <<
"': " << COLOR_DEFAULT <<
split[i]
298 _console << oss.str() << std::flush;
304 if (!
mesh->is_prepared())
305 mesh->prepare_for_use();
307 if (!getParam<bool>(
"nemesis"))
311 if (
mesh->mesh_dimension() == 1)
335 const std::string & name,
339 mooseError(
"Can only call addMeshSubgenerator() during MeshGenerator construction");
373 const bool direct )
const 377 [&
name, &direct](
const auto & mg)
379 return mg->name() ==
name ||
380 (!direct && mg->isParentMeshGenerator(
name,
false));
386 const bool direct )
const 390 [&
name, &direct](
const auto & mg)
392 return mg->name() ==
name ||
393 (!direct && mg->isChildMeshGenerator(
name,
false));
414 return getParam<bool>(
"output");
427 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
void write_as_dimension(unsigned dim)
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
Build a replicated mesh.
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.
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::string stringify(const T &t)
conversion to string
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.
virtual void write(const std::string &fname) override
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.
virtual void write(const std::string &base_filename) override
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.
void set_hdf5_writing(bool write_hdf5)
void set_hdf5_writing(bool write_hdf5)
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.