LCOV - code coverage report
Current view: top level - include/mfem/mesh - MFEMMesh.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 13 13 100.0 %
Date: 2025-08-08 20:01:16 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14