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 "MFEMObject.h" 15 : #include "libmesh/ignore_warnings.h" 16 : #include "mfem/fem/fespacehierarchy.hpp" 17 : #include "libmesh/restore_warnings.h" 18 : 19 : /** 20 : * Builds and owns a mfem::ParFiniteElementSpaceHierarchy from a base FESpace by 21 : * applying a sequence of h- and/or p-refinements. 22 : * 23 : * The `refinements` parameter is a vector of strings. Each entry is either: 24 : * - "h" - add one uniformly h-refined level (same FEC, refined mesh) 25 : * - "N" - add one p-refined level at polynomial order N (N must be strictly 26 : * greater than the current finest level's order) 27 : * 28 : * Total number of levels: refinements.size() + 1. 29 : * 30 : * The returned shared_ptr (getHierarchyShared()) may be co-owned by 31 : * MFEMGeometricMultigridSolver and stored in ProblemData::fespace_hierarchies 32 : * to guarantee the hierarchy outlives any solver that references it. 33 : */ 34 : class MFEMFESpaceHierarchy : public MFEMObject 35 : { 36 : public: 37 : static InputParameters validParams(); 38 : 39 : MFEMFESpaceHierarchy(const InputParameters & parameters); 40 : 41 : /// Returns a shared_ptr to the ParFiniteElementSpaceHierarchy. Safe for co-ownership. 42 9 : std::shared_ptr<mfem::ParFiniteElementSpaceHierarchy> getHierarchyShared() const 43 : { 44 9 : return _hierarchy; 45 : } 46 : 47 : /// Returns a reference to the ParFiniteElementSpaceHierarchy. 48 9 : mfem::ParFiniteElementSpaceHierarchy & getHierarchy() const { return *_hierarchy; } 49 : 50 9 : bool isScalar() const { return _is_scalar; } 51 : 52 : bool isVector() const { return _is_vector; } 53 : 54 : private: 55 : void buildHierarchy(); 56 : 57 : /// The hierarchy - shared_ptr so that MFEMGeometricMultigridSolver and ProblemData can co-own. 58 : std::shared_ptr<mfem::ParFiniteElementSpaceHierarchy> _hierarchy; 59 : 60 : /// FECs for p-refined levels. MFEM does not own them, so we keep them alive here. 61 : /// The lifetime of these is tied to this object which is kept alive by the MOOSE warehouse. 62 : std::vector<std::unique_ptr<mfem::FiniteElementCollection>> _level_fecs; 63 : 64 : bool _is_scalar = false; 65 : bool _is_vector = false; 66 : }; 67 : 68 : #endif