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