Line data Source code
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 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 : 27 : /** 28 : * MFEMMesh 29 : * 30 : * MFEMMesh inherits a MOOSE mesh class which allows us to work with 31 : * other MOOSE objects. It contains a pointer to the parallel MFEM mesh. 32 : */ 33 : class MFEMMesh : public FileMesh 34 : { 35 : public: 36 : static InputParameters validParams(); 37 : 38 : MFEMMesh(const InputParameters & parameters); 39 : 40 : virtual ~MFEMMesh(); 41 : 42 : /** 43 : * Accessors for the _mfem_par_mesh object. If the mesh has 44 : * not been build, the methods will call the appropriate protected methods to 45 : * build them. 46 : */ 47 1074 : mfem::ParMesh & getMFEMParMesh() { return *_mfem_par_mesh; } 48 : const mfem::ParMesh & getMFEMParMesh() const; 49 : 50 : /** 51 : * Copy a shared_ptr to the mfem::ParMesh object. 52 : */ 53 1292 : std::shared_ptr<mfem::ParMesh> getMFEMParMeshPtr() { return _mfem_par_mesh; } 54 : 55 : /** 56 : * Build MFEM ParMesh and a placeholder MOOSE mesh. 57 : */ 58 : void buildMesh() override; 59 : 60 : /** 61 : * Clones the mesh. 62 : */ 63 : std::unique_ptr<MooseMesh> safeClone() const override; 64 : 65 : /** 66 : * Returns true if mesh displacement is required. 67 : */ 68 110 : bool shouldDisplace() const { return _mesh_displacement_variable.has_value(); } 69 : 70 : /** 71 : * Returns an optional reference to displacement variable name. 72 : */ 73 142 : std::optional<std::reference_wrapper<std::string const>> getMeshDisplacementVariable() const 74 : { 75 142 : return _mesh_displacement_variable; 76 : } 77 : 78 : /** 79 : * Displace the nodes of the mesh by the given displacement. 80 : * Does not update FE spaces for variables. 81 : */ 82 : void displace(mfem::GridFunction const & displacement); 83 : 84 134 : bool isDistributedMesh() const override { return true; } 85 464 : unsigned int dimension() const override { return _mfem_par_mesh->Dimension(); } 86 134 : unsigned int spatialDimension() const override { return _mfem_par_mesh->SpaceDimension(); } 87 134 : SubdomainID nSubdomains() const override { return _mfem_par_mesh->attributes.Size(); } 88 134 : dof_id_type nActiveElem() const override { return _mfem_par_mesh->GetGlobalNE(); } 89 36 : dof_id_type nActiveLocalElem() const override { return _mfem_par_mesh->GetNE(); } 90 : 91 : private: 92 : /** 93 : * Builds a placeholder mesh when no MOOSE mesh is required. 94 : */ 95 : void buildDummyMooseMesh(); 96 : 97 : /** 98 : * Performs a uniform refinement on the chosen mesh nref times. 99 : */ 100 : void uniformRefinement(mfem::Mesh & mesh, const unsigned int nref) const; 101 : 102 : /** 103 : * Holds name of variable used for mesh displacement, if set. 104 : */ 105 : std::optional<std::string> _mesh_displacement_variable; 106 : 107 : /** 108 : * Smart pointers to mfem::ParMesh object. Do not access directly. 109 : * Use the accessors instead. 110 : */ 111 : std::shared_ptr<mfem::ParMesh> _mfem_par_mesh{nullptr}; 112 : }; 113 : 114 : inline const mfem::ParMesh & 115 274 : MFEMMesh::getMFEMParMesh() const 116 : { 117 274 : return const_cast<MFEMMesh *>(this)->getMFEMParMesh(); 118 : } 119 : 120 : #endif