10#ifdef MOOSE_MFEM_ENABLED
14#include "libmesh/mesh_generation.h"
25 "Number of serial refinements to perform on the mesh. Equivalent to uniform_refine.");
29 "Number of serial refinements to perform on the mesh. Equivalent to serial_refine");
31 "parallel_refine", 0,
"Number of parallel refinements to perform on the mesh.");
32 params.
addParam<std::string>(
"displacement",
"Optional variable to use for mesh displacement.");
33 params.
addParam<
bool>(
"nonconforming",
35 "Ensures the mesh is non-conforming: necessary for refining quad/hex "
36 "meshes and load (re)balancing.");
37 params.
addParam<
bool>(
"reorder_mesh",
39 "Determines whether we reorder the mesh to improve dynamic partitioning. "
40 "Only Hilbert sorting is supported at present.");
62 std::ifstream input(checkpoint_file);
64 mooseError(
"Unable to open MFEM recovery mesh file '", checkpoint_file,
"'.");
76 TIME_SECTION(
"buildMesh", 2,
"Building MFEM Mesh");
83 "Cannot set both serial_refine and uniform_refine at the same time.");
87 : getParam<unsigned int>(
"uniform_refine"));
93 if (getParam<bool>(
"reorder_mesh"))
95 mfem::Array<int> ordering;
96 mfem_ser_mesh.GetHilbertElementOrdering(ordering);
97 mfem_ser_mesh.ReorderElements(ordering);
103 if (getParam<bool>(
"nonconforming"))
104 mfem_ser_mesh.EnsureNCMesh(
true);
118std::vector<std::filesystem::path>
123 mooseAssert(
_mfem_par_mesh,
"MFEM parallel mesh is not initialized");
125 const auto checkpoint_file =
126 file_base.string() +
".mfem.mesh." + std::to_string(this->
processor_id());
127 std::ofstream output(checkpoint_file);
129 mooseError(
"Unable to open MFEM recovery mesh file '", checkpoint_file,
"' for writing.");
132 return {checkpoint_file};
147 auto & dummy = cast_ref<UnstructuredMesh &>(
getMesh());
148 MeshTools::Generation::build_point(dummy);
150 MeshTools::Generation::build_square(dummy, 1, 1, 0., 1., 0., 1., ElemType::QUAD9);
156 for (
unsigned int i = 0; i < nref; ++i)
157 mesh.UniformRefinement();
std::optional< std::string > _mesh_displacement_variable
Holds name of variable used for mesh displacement, if set.
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.
virtual mfem::Mesh buildSerialMFEMMesh()=0
Build and return the serial mfem::Mesh for this object.
void buildDummyMooseMesh()
Builds a dimension-compatible libMesh placeholder after initializing the MFEM mesh.
void init() override
Initialize the MFEM ParMesh and placeholder MOOSE mesh.
std::shared_ptr< mfem::ParMesh > _mfem_par_mesh
Smart pointer to mfem::ParMesh object.
void buildMesh() override final
Must be overridden by child classes.
MFEMMesh(const InputParameters ¶meters)
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.
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...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
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.
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
void setParallelType(ParallelType parallel_type)
Allow to change parallel type.
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