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