LCOV - code coverage report
Current view: top level - src/reporters - RestartableDataReporter.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 73 73 100.0 %
Date: 2026-05-29 20:35:17 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             : #include "RestartableDataReporter.h"
      11             : 
      12             : #include "MooseUtils.h"
      13             : 
      14             : registerMooseObject("MooseApp", RestartableDataReporter);
      15             : 
      16             : InputParameters
      17        6316 : RestartableDataReporter::validParams()
      18             : {
      19        6316 :   InputParameters params = GeneralReporter::validParams();
      20       12632 :   params.addClassDescription("Reports restartable data and restartable meta data.");
      21             : 
      22       12632 :   MultiMooseEnum entries("value type declared loaded stored has_context", "value type");
      23       25264 :   params.addParam<MultiMooseEnum>(
      24             :       "entries", entries, "The entries to output for each restartable value");
      25             : 
      26       18948 :   params.addParam<bool>("allow_unimplemented",
      27       12632 :                         false,
      28             :                         "Set to true to allow the empty output of data that does not have a JSON "
      29             :                         "output implementation");
      30             : 
      31       25264 :   params.addParam<std::string>(
      32             :       "map", "", "The data map to use; if unset, use system restartable data");
      33             : 
      34       25264 :   params.addParam<std::vector<std::string>>(
      35             :       "include",
      36             :       {},
      37             :       "The data name patterns to include (* for matching all, ? for matching a single character)");
      38       18948 :   params.addParam<std::vector<std::string>>(
      39             :       "exclude",
      40             :       {},
      41             :       "The data name patterns to exclude (* for matching all, ? for matching a single character)");
      42             : 
      43       12632 :   return params;
      44        6316 : }
      45             : 
      46          97 : RestartableDataReporter::RestartableDataReporter(const InputParameters & parameters)
      47             :   : GeneralReporter(parameters),
      48          97 :     _data_params(getDataParams()),
      49         194 :     _allow_unimplemented(getParam<bool>("allow_unimplemented")),
      50         194 :     _include(getParam<std::vector<std::string>>("include")),
      51         194 :     _exclude(getParam<std::vector<std::string>>("exclude")),
      52          97 :     _values(declareValueByName<std::map<std::string, RestartableDataReporter::Value>>(
      53             :         "values",
      54         291 :         getParam<std::string>("map").size() ? REPORTER_MODE_ROOT : REPORTER_MODE_DISTRIBUTED)),
      55         194 :     _data_map(getParam<std::string>("map").size()
      56         218 :                   ? _app.getRestartableDataMap(getParam<std::string>("map"))
      57         170 :                   : _app.getRestartableData()[0])
      58             : {
      59          97 : }
      60             : 
      61             : RestartableDataValue::StoreJSONParams
      62          97 : RestartableDataReporter::getDataParams() const
      63             : {
      64         194 :   const auto & entries = getParam<MultiMooseEnum>("entries");
      65             : 
      66          97 :   RestartableDataValue::StoreJSONParams params;
      67         194 :   params.value = entries.isValueSet("value");
      68          97 :   params.type = entries.isValueSet("type");
      69          97 :   params.name = false;
      70         194 :   params.declared = entries.isValueSet("declared");
      71         194 :   params.loaded = entries.isValueSet("loaded");
      72         194 :   params.stored = entries.isValueSet("stored");
      73          97 :   params.has_context = entries.isValueSet("has_context");
      74             : 
      75          97 :   return params;
      76             : }
      77             : 
      78             : void
      79         144 : RestartableDataReporter::execute()
      80             : {
      81         144 :   _values.clear();
      82             : 
      83        5659 :   for (const auto & value : _data_map)
      84             :   {
      85             :     mooseAssert(!_values.count(value.name()), "Non-unique name");
      86             : 
      87             :     // Don't output JSON entries
      88        5518 :     if (typeid(nlohmann::json) == value.typeId())
      89        5057 :       continue;
      90             :     // Don't output Reporter data due to recursion
      91        5410 :     if (MooseUtils::globCompare(value.name(),
      92       10820 :                                 ReporterName::REPORTER_RESTARTABLE_DATA_PREFIX + "/*"))
      93         108 :       continue;
      94             :     // Does not match include patterns
      95       15290 :     if (_include.size() && std::find_if(_include.begin(),
      96             :                                         _include.end(),
      97        4994 :                                         [&value](const auto & pattern) {
      98        4994 :                                           return MooseUtils::globCompare(value.name(), pattern);
      99       15290 :                                         }) == _include.end())
     100        4819 :       continue;
     101             :     // Matches exclude patterns
     102         483 :     if (std::find_if(_exclude.begin(),
     103             :                      _exclude.end(),
     104          44 :                      [&value](const auto & pattern)
     105        1010 :                      { return MooseUtils::globCompare(value.name(), pattern); }) != _exclude.end())
     106          22 :       continue;
     107             : 
     108         461 :     RestartableDataReporter::Value entry;
     109         461 :     entry.value = &value;
     110         461 :     entry.params = _data_params;
     111             : 
     112         461 :     if (!value.hasStoreJSON())
     113             :     {
     114          25 :       if (!_allow_unimplemented)
     115           3 :         mooseError("The method for outputting restartable data of type '",
     116           3 :                    value.type(),
     117             :                    "' is not implemented.\n\nTo omit data values that are not able to be "
     118             :                    "output, set Reporters/",
     119           3 :                    name(),
     120             :                    "/"
     121             :                    "allow_unimplemented=true,\nor skip the data with Reporters/",
     122           3 :                    name(),
     123             :                    "/[include/exclude].");
     124          22 :       entry.params.value = false;
     125             :     }
     126             : 
     127         458 :     _values.emplace(value.name(), entry);
     128             :   }
     129         141 : }
     130             : 
     131             : void
     132         374 : to_json(nlohmann::json & json, const RestartableDataReporter::Value & value)
     133             : {
     134             :   mooseAssert(value.value, "Not set");
     135         374 :   value.value->store(json, value.params);
     136         374 : }
     137             : 
     138             : template <>
     139             : void
     140          25 : dataStore(std::ostream & stream, RestartableDataReporter::Value & v, void * context)
     141             : {
     142          25 :   dataStore(stream, v.params, context);
     143          25 : }
     144             : 
     145             : template <>
     146             : void
     147          25 : dataLoad(std::istream & stream, RestartableDataReporter::Value & v, void * context)
     148             : {
     149          25 :   v.value = nullptr;
     150          25 :   dataLoad(stream, v.params, context);
     151          25 : }

Generated by: LCOV version 1.14