LCOV - code coverage report
Current view: top level - src/mfem/mesh - MFEMMesh.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 41 43 95.3 %
Date: 2025-11-03 17:23:24 Functions: 9 9 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             : #include "MFEMMesh.h"
      13             : #include "libmesh/mesh_generation.h"
      14             : 
      15             : registerMooseObject("MooseApp", MFEMMesh);
      16             : 
      17             : InputParameters
      18       10486 : MFEMMesh::validParams()
      19             : {
      20       10486 :   InputParameters params = FileMesh::validParams();
      21       31458 :   params.addParam<unsigned int>(
      22             :       "serial_refine",
      23       20972 :       0,
      24             :       "Number of serial refinements to perform on the mesh. Equivalent to uniform_refine.");
      25       31458 :   params.addParam<unsigned int>(
      26             :       "uniform_refine",
      27       20972 :       0,
      28             :       "Number of serial refinements to perform on the mesh. Equivalent to serial_refine");
      29       31458 :   params.addParam<unsigned int>(
      30       20972 :       "parallel_refine", 0, "Number of parallel refinements to perform on the mesh.");
      31       41944 :   params.addParam<std::string>("displacement", "Optional variable to use for mesh displacement.");
      32             : 
      33       10486 :   params.addClassDescription("Class to read in and store an mfem::ParMesh from file.");
      34             : 
      35       10486 :   return params;
      36           0 : }
      37             : 
      38         623 : MFEMMesh::MFEMMesh(const InputParameters & parameters) : FileMesh(parameters) {}
      39             : 
      40         901 : MFEMMesh::~MFEMMesh() {}
      41             : 
      42             : void
      43         623 : MFEMMesh::buildMesh()
      44             : {
      45        3115 :   TIME_SECTION("buildMesh", 2, "Reading Mesh");
      46             : 
      47             :   // Build a dummy MOOSE mesh to enable this class to work with other MOOSE classes.
      48         623 :   buildDummyMooseMesh();
      49             : 
      50             :   // Build the MFEM ParMesh from a serial MFEM mesh
      51         623 :   mfem::Mesh mfem_ser_mesh(getFileName());
      52             : 
      53        1885 :   if (isParamSetByUser("serial_refine") && isParamSetByUser("uniform_refine"))
      54           0 :     paramError(
      55             :         "Cannot define serial_refine and uniform_refine to be nonzero at the same time (they "
      56             :         "are the same variable). Please choose one.\n");
      57             : 
      58         623 :   uniformRefinement(mfem_ser_mesh,
      59        1885 :                     isParamSetByUser("serial_refine") ? getParam<unsigned int>("serial_refine")
      60        2468 :                                                       : getParam<unsigned int>("uniform_refine"));
      61             : 
      62             :   // multi app should take the mpi comm from moose so is split correctly??
      63         623 :   auto comm = this->comm().get();
      64         623 :   _mfem_par_mesh = std::make_shared<mfem::ParMesh>(comm, mfem_ser_mesh);
      65             : 
      66             :   // Perform parallel refinements
      67        1246 :   uniformRefinement(*_mfem_par_mesh, getParam<unsigned int>("parallel_refine"));
      68             : 
      69        1869 :   if (isParamSetByUser("displacement"))
      70             :   {
      71          39 :     _mesh_displacement_variable.emplace(getParam<std::string>("displacement"));
      72             :   }
      73         623 : }
      74             : 
      75             : void
      76          13 : MFEMMesh::displace(mfem::GridFunction const & displacement)
      77             : {
      78          13 :   _mfem_par_mesh->EnsureNodes();
      79          13 :   mfem::GridFunction * nodes = _mfem_par_mesh->GetNodes();
      80             : 
      81          13 :   *nodes += displacement;
      82          13 : }
      83             : 
      84             : void
      85         623 : MFEMMesh::buildDummyMooseMesh()
      86             : {
      87         623 :   MeshTools::Generation::build_point(static_cast<UnstructuredMesh &>(getMesh()));
      88         623 : }
      89             : 
      90             : void
      91        1246 : MFEMMesh::uniformRefinement(mfem::Mesh & mesh, const unsigned int nref) const
      92             : {
      93        1334 :   for (unsigned int i = 0; i < nref; ++i)
      94          88 :     mesh.UniformRefinement();
      95        1246 : }
      96             : 
      97             : std::unique_ptr<MooseMesh>
      98           8 : MFEMMesh::safeClone() const
      99             : {
     100           8 :   return _app.getFactory().copyConstruct(*this);
     101             : }
     102             : 
     103             : #endif

Generated by: LCOV version 1.14