LCOV - code coverage report
Current view: top level - src/mfem/problem - SolutionStateData.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 329044 Lines: 53 53 100.0 %
Date: 2026-08-03 21:12:22 Functions: 4 4 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 "DataIO.h"
      13             : #include "MFEMProblemData.h"
      14             : 
      15             : #include "libmesh/int_range.h"
      16             : 
      17             : using libMesh::make_range;
      18             : 
      19             : namespace
      20             : {
      21             : void
      22        1456 : storeGridFunction(std::ostream & stream, mfem::ParGridFunction & gridfunction, void * context)
      23             : {
      24        1456 :   const auto size = gridfunction.Size();
      25        1456 :   dataStore(stream, size, context);
      26             : 
      27        1456 :   const auto * values = gridfunction.HostRead();
      28    13888583 :   for (const auto i : make_range(size))
      29             :   {
      30    13887127 :     auto value = values[i];
      31    13887127 :     dataStore(stream, value, context);
      32             :   }
      33        1456 : }
      34             : 
      35             : void
      36          42 : loadGridFunction(std::istream & stream, mfem::ParGridFunction & gridfunction, void * context)
      37             : {
      38          42 :   int size = 0;
      39          42 :   dataLoad(stream, size, context);
      40             :   mooseAssert(size == gridfunction.Size(),
      41             :               "MFEM restartable GridFunction size mismatch during restore.");
      42             : 
      43          42 :   auto * values = gridfunction.HostWrite();
      44     1274432 :   for (const auto i : make_range(size))
      45     1274390 :     dataLoad(stream, values[i], context);
      46          42 : }
      47             : }
      48             : 
      49             : template <>
      50             : void
      51         643 : dataStore(std::ostream & stream, Moose::MFEM::SolutionState & /*state*/, void * context)
      52             : {
      53         643 :   auto * const data = static_cast<MFEMProblemData *>(context);
      54             : 
      55         643 :   auto num_gridfunctions = data->gridfunctions.size();
      56         643 :   dataStore(stream, num_gridfunctions, context);
      57        2069 :   for (const auto & [name, gridfunction] : data->gridfunctions)
      58             :   {
      59        1426 :     auto stored_name = name;
      60        1426 :     dataStore(stream, stored_name, context);
      61        1426 :     storeGridFunction(stream, *gridfunction, context);
      62        1426 :   }
      63             : 
      64         643 :   auto num_complex_gridfunctions = data->cmplx_gridfunctions.size();
      65         643 :   dataStore(stream, num_complex_gridfunctions, context);
      66         658 :   for (const auto & [name, gridfunction] : data->cmplx_gridfunctions)
      67             :   {
      68          15 :     auto stored_name = name;
      69          15 :     dataStore(stream, stored_name, context);
      70          15 :     storeGridFunction(stream, gridfunction->real(), context);
      71          15 :     storeGridFunction(stream, gridfunction->imag(), context);
      72          15 :   }
      73         643 : }
      74             : 
      75             : template <>
      76             : void
      77          11 : dataLoad(std::istream & stream, Moose::MFEM::SolutionState & /*state*/, void * context)
      78             : {
      79          11 :   auto * const data = static_cast<MFEMProblemData *>(context);
      80             : 
      81          11 :   int num_gridfunctions = 0;
      82          11 :   dataLoad(stream, num_gridfunctions, context);
      83          51 :   for (int i = 0; i < num_gridfunctions; ++i)
      84             :   {
      85          40 :     std::string name;
      86          40 :     dataLoad(stream, name, context);
      87          40 :     auto & gf = data->gridfunctions.GetRef(name);
      88          40 :     loadGridFunction(stream, gf, context);
      89          40 :   }
      90             : 
      91          11 :   int num_complex_gridfunctions = 0;
      92          11 :   dataLoad(stream, num_complex_gridfunctions, context);
      93          12 :   for (int i = 0; i < num_complex_gridfunctions; ++i)
      94             :   {
      95           1 :     std::string name;
      96           1 :     dataLoad(stream, name, context);
      97           1 :     auto & gf = data->cmplx_gridfunctions.GetRef(name);
      98           1 :     loadGridFunction(stream, gf.real(), context);
      99           1 :     loadGridFunction(stream, gf.imag(), context);
     100           1 :   }
     101          11 : }
     102             : 
     103             : #endif

Generated by: LCOV version 1.14