https://mooseframework.inl.gov
MFEMMesh.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #ifdef MOOSE_MFEM_ENABLED
11 
12 //* This file is part of the MOOSE framework
13 //* https://mooseframework.inl.gov
14 //*
15 //* All rights reserved, see COPYRIGHT for full restrictions
16 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
17 //*
18 //* Licensed under LGPL 2.1, please see LICENSE for details
19 //* https://www.gnu.org/licenses/lgpl-2.1.html
20 
21 #pragma once
22 #include "FileMesh.h"
23 #include "libmesh/ignore_warnings.h"
24 #include <mfem.hpp>
25 #include "libmesh/restore_warnings.h"
26 
31 class MFEMMesh : public FileMesh
32 {
33 public:
35 
37 
38  virtual ~MFEMMesh();
39 
45  mfem::ParMesh & getMFEMParMesh() { return *_mfem_par_mesh; }
46  const mfem::ParMesh & getMFEMParMesh() const;
47 
51  std::shared_ptr<mfem::ParMesh> getMFEMParMeshPtr() { return _mfem_par_mesh; }
52 
56  void buildMesh() override;
57 
61  std::unique_ptr<MooseMesh> safeClone() const override;
62 
66  bool shouldDisplace() const { return _mesh_displacement_variable.has_value(); }
67 
71  std::optional<std::reference_wrapper<std::string const>> getMeshDisplacementVariable() const
72  {
74  }
75 
80  void displace(mfem::GridFunction const & displacement);
81 
82  bool isDistributedMesh() const override { return true; }
83  unsigned int dimension() const override { return _mfem_par_mesh->Dimension(); }
84  unsigned int spatialDimension() const override { return _mfem_par_mesh->SpaceDimension(); }
85  SubdomainID nSubdomains() const override { return _mfem_par_mesh->attributes.Size(); }
86  dof_id_type nActiveElem() const override { return _mfem_par_mesh->GetGlobalNE(); }
87  dof_id_type nActiveLocalElem() const override { return _mfem_par_mesh->GetNE(); }
88 
89 private:
93  void buildDummyMooseMesh();
94 
98  void uniformRefinement(mfem::Mesh & mesh, const unsigned int nref) const;
99 
103  std::optional<std::string> _mesh_displacement_variable;
104 
109  std::shared_ptr<mfem::ParMesh> _mfem_par_mesh{nullptr};
110 };
111 
112 inline const mfem::ParMesh &
114 {
115  return const_cast<MFEMMesh *>(this)->getMFEMParMesh();
116 }
117 
118 #endif
unsigned int dimension() const override
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition: MFEMMesh.h:83
bool isDistributedMesh() const override
Returns the final Mesh distribution type.
Definition: MFEMMesh.h:82
bool shouldDisplace() const
Returns true if mesh displacement is required.
Definition: MFEMMesh.h:66
std::optional< std::reference_wrapper< std::string const > > getMeshDisplacementVariable() const
Returns an optional reference to displacement variable name.
Definition: MFEMMesh.h:71
void uniformRefinement(mfem::Mesh &mesh, const unsigned int nref) const
Performs a uniform refinement on the chosen mesh nref times.
Definition: MFEMMesh.C:100
virtual ~MFEMMesh()
Definition: MFEMMesh.C:49
unsigned int spatialDimension() const override
Returns MeshBase::spatial_dimension.
Definition: MFEMMesh.h:84
std::optional< std::string > _mesh_displacement_variable
Holds name of variable used for mesh displacement, if set.
Definition: MFEMMesh.h:103
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
Definition: MFEMMesh.C:27
void buildDummyMooseMesh()
Builds a placeholder mesh when no MOOSE mesh is required.
Definition: MFEMMesh.C:94
dof_id_type nActiveLocalElem() const override
Definition: MFEMMesh.h:87
void buildMesh() override
Build MFEM ParMesh and a placeholder MOOSE mesh.
Definition: MFEMMesh.C:52
std::unique_ptr< MooseMesh > safeClone() const override
Clones the mesh.
Definition: MFEMMesh.C:107
std::shared_ptr< mfem::ParMesh > getMFEMParMeshPtr()
Copy a shared_ptr to the mfem::ParMesh object.
Definition: MFEMMesh.h:51
SubdomainID nSubdomains() const override
Definition: MFEMMesh.h:85
MFEMMesh(const InputParameters &parameters)
Definition: MFEMMesh.C:47
std::shared_ptr< mfem::ParMesh > _mfem_par_mesh
Smart pointers to mfem::ParMesh object.
Definition: MFEMMesh.h:109
mfem::ParMesh & getMFEMParMesh()
Accessors for the _mfem_par_mesh object.
Definition: MFEMMesh.h:45
void displace(mfem::GridFunction const &displacement)
Displace the nodes of the mesh by the given displacement.
Definition: MFEMMesh.C:85
MFEMMesh inherits a MOOSE mesh class which allows us to work with other MOOSE objects.
Definition: MFEMMesh.h:31
const InputParameters & parameters() const
Get the parameters of the object.
dof_id_type nActiveElem() const override
Definition: MFEMMesh.h:86
uint8_t dof_id_type