10#ifdef MOOSE_MFEM_ENABLED
14#include "libmesh/mesh_generation.h"
27 "Number of serial refinements to perform on the mesh. Equivalent to uniform_refine.");
31 "Number of serial refinements to perform on the mesh. Equivalent to serial_refine");
33 "parallel_refine", 0,
"Number of parallel refinements to perform on the mesh.");
34 params.
addParam<std::string>(
"displacement",
"Optional variable to use for mesh displacement.");
35 params.
addParam<
bool>(
"nonconforming",
37 "Ensures the mesh is non-conforming: necessary for refining quad/hex "
38 "meshes and load (re)balancing.");
39 params.
addParam<
bool>(
"reorder_mesh",
41 "Determines whether we reorder the mesh to improve dynamic partitioning. "
42 "Only Hilbert sorting is supported at present.");
68 std::ifstream input(checkpoint_file);
70 mooseError(
"Unable to open MFEM recovery mesh file '", checkpoint_file,
"'.");
82 TIME_SECTION(
"buildMesh", 2,
"Reading Mesh");
89 "Cannot define serial_refine and uniform_refine to be nonzero at the same time (they "
90 "are the same variable). Please choose one.\n");
94 : getParam<unsigned int>(
"uniform_refine"));
100 if (getParam<bool>(
"reorder_mesh"))
102 mfem::Array<int> ordering;
103 mfem_ser_mesh.GetHilbertElementOrdering(ordering);
104 mfem_ser_mesh.ReorderElements(ordering);
110 if (getParam<bool>(
"nonconforming"))
111 mfem_ser_mesh.EnsureNCMesh(
true);
127std::vector<std::filesystem::path>
132 mooseAssert(
_mfem_par_mesh,
"MFEM parallel mesh is not initialized");
134 const auto checkpoint_file =
135 file_base.string() +
".mfem.mesh." + std::to_string(this->
processor_id());
136 std::ofstream output(checkpoint_file);
138 mooseError(
"Unable to open MFEM recovery mesh file '", checkpoint_file,
"' for writing.");
141 return {checkpoint_file};
150 *nodes += displacement;
156 auto & dummy =
static_cast<UnstructuredMesh &
>(
getMesh());
157 MeshTools::Generation::build_point(dummy);
159 MeshTools::Generation::build_square(dummy, 1, 1, 0., 1., 0., 1., ElemType::QUAD9);
165 for (
unsigned int i = 0; i < nref; ++i)
166 mesh.UniformRefinement();
169std::unique_ptr<MooseMesh>
registerMooseObject("MooseApp", MFEMMesh)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
virtual std::string getFileName() const override
Returns the name of the mesh file read to produce this mesh if any or an empty string otherwise.
static InputParameters validParams()
MFEMMesh inherits a MOOSE mesh class which allows us to work with other MOOSE objects.
std::optional< std::string > _mesh_displacement_variable
Holds name of variable used for mesh displacement, if set.
std::unique_ptr< MooseMesh > safeClone() const override
Clones the mesh.
unsigned int dimension() const override
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
std::vector< std::filesystem::path > writeRecoveryFiles(const std::filesystem::path &file_base) override
Write the mesh files needed for recovery/checkpointing.
static InputParameters validParams()
void uniformRefinement(mfem::Mesh &mesh, const unsigned int nref) const
Performs a uniform refinement on the chosen mesh nref times.
void displace(mfem::GridFunction const &displacement)
Displace the nodes of the mesh by the given displacement.
void buildDummyMooseMesh()
Builds a placeholder mesh when no MOOSE mesh is required.
void init() override
Build MFEM ParMesh and a placeholder MOOSE mesh.
std::shared_ptr< mfem::ParMesh > _mfem_par_mesh
Smart pointers to mfem::ParMesh object.
MFEMMesh(const InputParameters ¶meters)
void buildMesh() override
Must be overridden by child classes.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
static const std::string & checkpointSuffix()
The file suffix for the checkpoint mesh.
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
std::string getRestartRecoverFileBase() const
The file_base for the recovery file.
bool isRecovering() const
Whether or not this is a "recover" calculation.
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 ...
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
virtual std::vector< std::filesystem::path > writeRecoveryFiles(const std::filesystem::path &file_base)
Write the mesh files needed for recovery/checkpointing.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
virtual void init()
Initialize the Mesh object.
bool allowRecovery() const
Returns whether this mesh is allowed to read a recovery file.
MooseApp & _app
The MOOSE application this is associated with.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const