LCOV - code coverage report
Current view: top level - src/mfem/mesh - MFEMMesh.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 909fe5 Lines: 41 43 95.3 %
Date: 2025-08-29 20:01: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        9524 : MFEMMesh::validParams()
      19             : {
      20        9524 :   InputParameters params = FileMesh::validParams();
      21       28572 :   params.addParam<unsigned int>(
      22             :       "serial_refine",
      23       19048 :       0,
      24             :       "Number of serial refinements to perform on the mesh. Equivalent to uniform_refine.");
      25       28572 :   params.addParam<unsigned int>(
      26             :       "uniform_refine",
      27       19048 :       0,
      28             :       "Number of serial refinements to perform on the mesh. Equivalent to serial_refine");
      29       28572 :   params.addParam<unsigned int>(
      30       19048 :       "parallel_refine", 0, "Number of parallel refinements to perform on the mesh.");
      31       38096 :   params.addParam<std::string>("displacement", "Optional variable to use for mesh displacement.");
      32             : 
      33        9524 :   params.addClassDescription("Class to read in and store an mfem::ParMesh from file.");
      34             : 
      35        9524 :   return params;
      36           0 : }
      37             : 
      38         445 : MFEMMesh::MFEMMesh(const InputParameters & parameters) : FileMesh(parameters) {}
      39             : 
      40         898 : MFEMMesh::~MFEMMesh() {}
      41             : 
      42             : void
      43         445 : MFEMMesh::buildMesh()
      44             : {
      45        2225 :   TIME_SECTION("buildMesh", 2, "Reading Mesh");
      46             : 
      47             :   // Build a dummy MOOSE mesh to enable this class to work with other MOOSE classes.
      48         445 :   buildDummyMooseMesh();
      49             : 
      50             :   // Build the MFEM ParMesh from a serial MFEM mesh
      51         445 :   mfem::Mesh mfem_ser_mesh(getFileName());
      52             : 
      53        1343 :   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         445 :   uniformRefinement(mfem_ser_mesh,
      59        1343 :                     isParamSetByUser("serial_refine") ? getParam<unsigned int>("serial_refine")
      60        1768 :                                                       : getParam<unsigned int>("uniform_refine"));
      61             : 
      62             :   // multi app should take the mpi comm from moose so is split correctly??
      63         445 :   auto comm = this->comm().get();
      64         445 :   _mfem_par_mesh = std::make_shared<mfem::ParMesh>(comm, mfem_ser_mesh);
      65             : 
      66             :   // Perform parallel refinements
      67         890 :   uniformRefinement(*_mfem_par_mesh, getParam<unsigned int>("parallel_refine"));
      68             : 
      69        1335 :   if (isParamSetByUser("displacement"))
      70             :   {
      71          39 :     _mesh_displacement_variable.emplace(getParam<std::string>("displacement"));
      72             :   }
      73         445 : }
      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         445 : MFEMMesh::buildDummyMooseMesh()
      86             : {
      87         445 :   MeshTools::Generation::build_point(static_cast<UnstructuredMesh &>(getMesh()));
      88         445 : }
      89             : 
      90             : void
      91         890 : MFEMMesh::uniformRefinement(mfem::Mesh & mesh, const unsigned int nref) const
      92             : {
      93         975 :   for (unsigned int i = 0; i < nref; ++i)
      94          85 :     mesh.UniformRefinement();
      95         890 : }
      96             : 
      97             : std::unique_ptr<MooseMesh>
      98           4 : MFEMMesh::safeClone() const
      99             : {
     100           4 :   return _app.getFactory().copyConstruct(*this);
     101             : }
     102             : 
     103             : #endif

Generated by: LCOV version 1.14