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

Generated by: LCOV version 1.14