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 #pragma once
13 
14 #include "FileMesh.h"
15 
20 class MFEMMesh : public FileMesh
21 {
22 public:
24 
26 
27  virtual ~MFEMMesh();
28 
34  mfem::ParMesh & getMFEMParMesh() { return *_mfem_par_mesh; }
35  const mfem::ParMesh & getMFEMParMesh() const;
36 
40  std::shared_ptr<mfem::ParMesh> getMFEMParMeshPtr() { return _mfem_par_mesh; }
41 
45  void buildMesh() override;
46 
50  std::unique_ptr<MooseMesh> safeClone() const override;
51 
55  bool shouldDisplace() const { return _mesh_displacement_variable.has_value(); }
56 
60  std::optional<std::reference_wrapper<std::string const>> getMeshDisplacementVariable() const
61  {
63  }
64 
69  void displace(mfem::GridFunction const & displacement);
70 
71  bool isDistributedMesh() const override { return true; }
72  unsigned int dimension() const override { return _mfem_par_mesh->Dimension(); }
73  unsigned int spatialDimension() const override { return _mfem_par_mesh->SpaceDimension(); }
74  SubdomainID nSubdomains() const override { return _mfem_par_mesh->attributes.Size(); }
75  dof_id_type nActiveElem() const override { return _mfem_par_mesh->GetGlobalNE(); }
76  dof_id_type nActiveLocalElem() const override { return _mfem_par_mesh->GetNE(); }
77 
78 private:
82  void buildDummyMooseMesh();
83 
87  void uniformRefinement(mfem::Mesh & mesh, const unsigned int nref) const;
88 
92  std::optional<std::string> _mesh_displacement_variable;
93 
98  std::shared_ptr<mfem::ParMesh> _mfem_par_mesh{nullptr};
99 };
100 
101 inline const mfem::ParMesh &
103 {
104  return const_cast<MFEMMesh *>(this)->getMFEMParMesh();
105 }
106 
107 #endif
unsigned int dimension() const override
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition: MFEMMesh.h:72
bool isDistributedMesh() const override
Returns the final Mesh distribution type.
Definition: MFEMMesh.h:71
bool shouldDisplace() const
Returns true if mesh displacement is required.
Definition: MFEMMesh.h:55
std::optional< std::reference_wrapper< std::string const > > getMeshDisplacementVariable() const
Returns an optional reference to displacement variable name.
Definition: MFEMMesh.h:60
void uniformRefinement(mfem::Mesh &mesh, const unsigned int nref) const
Performs a uniform refinement on the chosen mesh nref times.
Definition: MFEMMesh.C:115
virtual ~MFEMMesh()
Definition: MFEMMesh.C:48
unsigned int spatialDimension() const override
Returns MeshBase::spatial_dimension.
Definition: MFEMMesh.h:73
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
std::optional< std::string > _mesh_displacement_variable
Holds name of variable used for mesh displacement, if set.
Definition: MFEMMesh.h:92
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
Definition: MFEMMesh.C:18
void buildDummyMooseMesh()
Builds a placeholder mesh when no MOOSE mesh is required.
Definition: MFEMMesh.C:108
dof_id_type nActiveLocalElem() const override
Definition: MFEMMesh.h:76
void buildMesh() override
Build MFEM ParMesh and a placeholder MOOSE mesh.
Definition: MFEMMesh.C:51
std::unique_ptr< MooseMesh > safeClone() const override
Clones the mesh.
Definition: MFEMMesh.C:122
std::shared_ptr< mfem::ParMesh > getMFEMParMeshPtr()
Copy a shared_ptr to the mfem::ParMesh object.
Definition: MFEMMesh.h:40
SubdomainID nSubdomains() const override
Definition: MFEMMesh.h:74
MFEMMesh(const InputParameters &parameters)
Definition: MFEMMesh.C:46
std::shared_ptr< mfem::ParMesh > _mfem_par_mesh
Smart pointers to mfem::ParMesh object.
Definition: MFEMMesh.h:98
mfem::ParMesh & getMFEMParMesh()
Accessors for the _mfem_par_mesh object.
Definition: MFEMMesh.h:34
void displace(mfem::GridFunction const &displacement)
Displace the nodes of the mesh by the given displacement.
Definition: MFEMMesh.C:99
MFEMMesh inherits a MOOSE mesh class which allows us to work with other MOOSE objects.
Definition: MFEMMesh.h:20
dof_id_type nActiveElem() const override
Definition: MFEMMesh.h:75
uint8_t dof_id_type