LCOV - code coverage report
Current view: top level - src/mfem/outputs - MFEMDataCollection.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fa5e60 Lines: 42 45 93.3 %
Date: 2026-06-24 08:03:36 Functions: 5 5 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 "MFEMDataCollection.h"
      13             : 
      14             : InputParameters
      15        7552 : MFEMDataCollection::validParams()
      16             : {
      17        7552 :   InputParameters params = FileOutput::validParams();
      18       15104 :   params.addClassDescription("Output for controlling MFEMDataCollection inherited data.");
      19       30208 :   params.addParam<std::string>("submesh",
      20             :                                "Submesh to output variables on. Leave blank to use base mesh.");
      21       30208 :   params.addParam<std::vector<VariableName>>(
      22             :       "show", {}, "A list of variables that should be included in the collection.");
      23       22656 :   params.addParam<std::vector<VariableName>>(
      24             :       "hide", {}, "A list of variables that should NOT be included in the collection.");
      25        7552 :   return params;
      26           0 : }
      27             : 
      28         629 : MFEMDataCollection::MFEMDataCollection(const InputParameters & parameters)
      29             :   : FileOutput(parameters),
      30         629 :     _problem_data(static_cast<MFEMProblem *>(_problem_ptr)->getProblemData()),
      31         629 :     _pmesh(parameters.isParamValid("submesh")
      32        1369 :                ? _problem_data.submeshes.GetRef(getParam<std::string>("submesh"))
      33         518 :                : const_cast<mfem::ParMesh &>(*_problem_data.pmesh.get())),
      34        1258 :     _shown(getParam<std::vector<VariableName>>("show")),
      35        1887 :     _hidden(getParam<std::vector<VariableName>>("hide"))
      36             : {
      37         629 : }
      38             : 
      39             : void
      40         629 : MFEMDataCollection::registerFields()
      41             : {
      42             :   // Save real fields
      43         629 :   mfem::DataCollection & dc(getDataCollection());
      44             : 
      45        2572 :   for (auto const & [gf_name, gf_ptr] : _problem_data.gridfunctions)
      46             :   {
      47        3886 :     if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) ||
      48        3886 :         std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end())
      49           7 :       continue;
      50        1936 :     else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh())
      51        1357 :       dc.RegisterField(gf_name, gf_ptr.get());
      52             :     else
      53         579 :       mooseInfo("The variable ",
      54             :                 gf_name,
      55             :                 " is not defined on the same mesh as the output DataCollection.");
      56             :   }
      57             : 
      58             :   // Save complex fields
      59         685 :   for (auto const & [gf_name, gf_ptr] : _problem_data.cmplx_gridfunctions)
      60             :   {
      61         112 :     if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) ||
      62         112 :         std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end())
      63           0 :       continue;
      64          56 :     else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh())
      65             :     {
      66          56 :       dc.RegisterField(gf_name + "_real", &gf_ptr->real());
      67          56 :       dc.RegisterField(gf_name + "_imag", &gf_ptr->imag());
      68             :     }
      69             :     else
      70           0 :       mooseInfo("The variable ",
      71             :                 gf_name,
      72             :                 " is not defined on the same mesh as the output DataCollection.");
      73             :   }
      74         629 : }
      75             : 
      76             : void
      77          27 : MFEMDataCollection::setFileBaseInternal(const std::string & file_base)
      78             : {
      79          27 :   FileOutput::setFileBaseInternal(file_base);
      80          27 :   getDataCollection().SetPrefixPath(_file_base);
      81          27 : }
      82             : 
      83             : void
      84        1462 : MFEMDataCollection::output()
      85             : {
      86        1462 :   mfem::DataCollection & dc(getDataCollection());
      87             :   // Write fields to disk
      88        1462 :   dc.SetCycle(getFileNumber());
      89        1462 :   dc.SetTime(time());
      90        1462 :   dc.Save();
      91        1462 :   ++_file_num;
      92        1462 : }
      93             : 
      94             : #endif

Generated by: LCOV version 1.14