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 3912 : 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 7804 : std::shared_ptr<mfem::ParMesh> getMFEMParMeshPtr() { return _mfem_par_mesh; } 41 : 42 : /** 43 : * Build MFEM ParMesh and a placeholder MOOSE mesh. 44 : */ 45 : void init() override; 46 : void buildMesh() override; 47 : std::vector<std::filesystem::path> 48 : writeRecoveryFiles(const std::filesystem::path & file_base) override; 49 : 50 : /** 51 : * Clones the mesh. 52 : */ 53 : std::unique_ptr<MooseMesh> safeClone() const override; 54 : 55 : /** 56 : * Returns true if mesh displacement is required. 57 : */ 58 3696 : bool shouldDisplace() const { return _mesh_displacement_variable.has_value(); } 59 : 60 : /** 61 : * Returns an optional reference to displacement variable name. 62 : */ 63 1732 : std::optional<std::reference_wrapper<std::string const>> getMeshDisplacementVariable() const 64 : { 65 1732 : return _mesh_displacement_variable; 66 : } 67 : 68 : /** 69 : * Displace the nodes of the mesh by the given displacement. 70 : * Does not update FE spaces for variables. 71 : */ 72 : void displace(mfem::GridFunction const & displacement); 73 : 74 1738 : bool isDistributedMesh() const override { return true; } 75 8568 : unsigned int dimension() const override { return _mfem_par_mesh->Dimension(); } 76 1676 : unsigned int spatialDimension() const override { return _mfem_par_mesh->SpaceDimension(); } 77 1676 : SubdomainID nSubdomains() const override { return _mfem_par_mesh->attributes.Size(); } 78 1676 : dof_id_type nActiveElem() const override { return _mfem_par_mesh->GetGlobalNE(); } 79 832 : dof_id_type nActiveLocalElem() const override { return _mfem_par_mesh->GetNE(); } 80 : 81 : private: 82 : /** 83 : * Builds a placeholder mesh when no MOOSE mesh is required. 84 : */ 85 : void buildDummyMooseMesh(); 86 : 87 : /** 88 : * Performs a uniform refinement on the chosen mesh nref times. 89 : */ 90 : void uniformRefinement(mfem::Mesh & mesh, const unsigned int nref) const; 91 : 92 : /** 93 : * Holds name of variable used for mesh displacement, if set. 94 : */ 95 : std::optional<std::string> _mesh_displacement_variable; 96 : 97 : /** 98 : * Smart pointers to mfem::ParMesh object. Do not access directly. 99 : * Use the accessors instead. 100 : */ 101 : std::shared_ptr<mfem::ParMesh> _mfem_par_mesh{nullptr}; 102 : }; 103 : 104 : inline const mfem::ParMesh & 105 : MFEMMesh::getMFEMParMesh() const 106 : { 107 : return const_cast<MFEMMesh *>(this)->getMFEMParMesh(); 108 : } 109 : 110 : #endif