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 : #pragma once 13 : #include "libmesh/ignore_warnings.h" 14 : #include "mfem.hpp" 15 : #include "libmesh/restore_warnings.h" 16 : #include "MFEMGeneralUserObject.h" 17 : 18 : /** 19 : * Constructs and stores an mfem::ParFiniteElementSpace object. Access using the 20 : * getFESpace() accessor. 21 : */ 22 : class MFEMFESpace : public MFEMGeneralUserObject 23 : { 24 : public: 25 : static InputParameters validParams(); 26 : 27 : MFEMFESpace(const InputParameters & parameters); 28 : 29 : // Note: The simplest way to handle the boilerplate of constructing 30 : // FiniteElementCollection and FiniteElementSpace objects in the 31 : // base class while deferring their arguments to the subclasses was 32 : // to build them after construction was finished. Rather than 33 : // requiring the user to call an additional Init() function (which 34 : // could easily be forgotten) instead they get built lazily, when 35 : // required. 36 : 37 : /// Returns a shared pointer to the constructed fespace. 38 569 : inline std::shared_ptr<mfem::ParFiniteElementSpace> getFESpace() const 39 : { 40 569 : if (!_fespace) 41 291 : buildFESpace(getVDim()); 42 561 : return _fespace; 43 : } 44 : 45 : /// Returns a shared pointer to the constructed fec. 46 572 : inline std::shared_ptr<mfem::FiniteElementCollection> getFEC() const 47 : { 48 572 : if (!_fec) 49 291 : buildFEC(getFECName()); 50 564 : return _fec; 51 : } 52 : 53 : virtual bool isScalar() const = 0; 54 : 55 : virtual bool isVector() const = 0; 56 : 57 : protected: 58 : /// Type of ordering of the vector dofs when _vdim > 1. 59 : const int _ordering; 60 : 61 : /// Get the name of the desired FECollection. 62 : virtual std::string getFECName() const = 0; 63 : 64 : /// Get the number of degrees of freedom per basis function needed 65 : /// in this finite element space. 66 : virtual int getVDim() const = 0; 67 : 68 : /// Get the quadrature basis enum associated with the given name. 69 : int getBasis(const std::string & basis_name) const; 70 : 71 : private: 72 : /// Constructs the fec from the fec name. 73 : void buildFEC(const std::string & fec_name) const; 74 : 75 : /// Stores the constructed fecollection 76 : mutable std::shared_ptr<mfem::FiniteElementCollection> _fec{nullptr}; 77 : 78 : /// Constructs the fespace. 79 : void buildFESpace(const int vdim) const; 80 : /// Stores the constructed fespace. 81 : mutable std::shared_ptr<mfem::ParFiniteElementSpace> _fespace{nullptr}; 82 : 83 : /// Mesh FESpace is defined with respect to. May differ from main problem mesh if 84 : /// FESpace is defined on an MFEMSubMesh. 85 : mfem::ParMesh & _pmesh; 86 : }; 87 : 88 : #endif