https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RestartableDataReporter.C
Go to the documentation of this file.
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
11
12#include "MooseUtils.h"
13
15
18{
20 params.addClassDescription("Reports restartable data and restartable meta data.");
21
22 MultiMooseEnum entries("value type declared loaded stored has_context", "value type");
24 "entries", entries, "The entries to output for each restartable value");
25
26 params.addParam<bool>("allow_unimplemented",
27 false,
28 "Set to true to allow the empty output of data that does not have a JSON "
29 "output implementation");
30
31 params.addParam<std::string>(
32 "map", "", "The data map to use; if unset, use system restartable data");
33
34 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 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 return params;
44}
45
47 : GeneralReporter(parameters),
48 _data_params(getDataParams()),
49 _allow_unimplemented(getParam<bool>("allow_unimplemented")),
50 _include(getParam<std::vector<std::string>>("include")),
51 _exclude(getParam<std::vector<std::string>>("exclude")),
52 _values(declareValueByName<std::map<std::string, RestartableDataReporter::Value>>(
53 "values",
54 getParam<std::string>("map").size() ? REPORTER_MODE_ROOT : REPORTER_MODE_DISTRIBUTED)),
55 _data_map(getParam<std::string>("map").size()
56 ? _app.getRestartableDataMap(getParam<std::string>("map"))
57 : _app.getRestartableData()[0])
58{
59}
60
63{
64 const auto & entries = getParam<MultiMooseEnum>("entries");
65
67 params.value = entries.isValueSet("value");
68 params.type = entries.isValueSet("type");
69 params.name = false;
70 params.declared = entries.isValueSet("declared");
71 params.loaded = entries.isValueSet("loaded");
72 params.stored = entries.isValueSet("stored");
73 params.has_context = entries.isValueSet("has_context");
74
75 return params;
76}
77
78void
80{
81 _values.clear();
82
83 for (const auto & value : _data_map)
84 {
85 mooseAssert(!_values.count(value.name()), "Non-unique name");
86
87 // Don't output JSON entries
88 if (typeid(nlohmann::json) == value.typeId())
89 continue;
90 // Don't output Reporter data due to recursion
91 if (MooseUtils::globCompare(value.name(),
93 continue;
94 // Does not match include patterns
95 if (_include.size() &&
96 std::find_if(_include.begin(),
97 _include.end(),
98 [&value](const auto & pattern)
99 { return MooseUtils::globCompare(value.name(), pattern); }) == _include.end())
100 continue;
101 // Matches exclude patterns
102 if (std::find_if(_exclude.begin(),
103 _exclude.end(),
104 [&value](const auto & pattern)
105 { return MooseUtils::globCompare(value.name(), pattern); }) != _exclude.end())
106 continue;
107
109 entry.value = &value;
110 entry.params = _data_params;
111
112 if (!value.hasStoreJSON())
113 {
115 mooseError("The method for outputting restartable data of type '",
116 value.type(),
117 "' is not implemented.\n\nTo omit data values that are not able to be "
118 "output, set Reporters/",
119 name(),
120 "/"
121 "allow_unimplemented=true,\nor skip the data with Reporters/",
122 name(),
123 "/[include/exclude].");
124 entry.params.value = false;
125 }
126
127 _values.emplace(value.name(), entry);
128 }
129}
130
131void
132to_json(nlohmann::json & json, const RestartableDataReporter::Value & value)
133{
134 mooseAssert(value.value, "Not set");
135 value.value->store(json, value.params);
136}
137
138template <>
139void
140dataStore(std::ostream & stream, RestartableDataReporter::Value & v, void * context)
141{
142 dataStore(stream, v.params, context);
143}
144
145template <>
146void
147dataLoad(std::istream & stream, RestartableDataReporter::Value & v, void * context)
148{
149 v.value = nullptr;
150 dataLoad(stream, v.params, context);
151}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ReporterMode REPORTER_MODE_DISTRIBUTED
const ReporterMode REPORTER_MODE_ROOT
void dataLoad(std::istream &stream, RestartableDataReporter::Value &v, void *context)
registerMooseObject("MooseApp", RestartableDataReporter)
void to_json(nlohmann::json &json, const RestartableDataReporter::Value &value)
void dataStore(std::ostream &stream, RestartableDataReporter::Value &v, void *context)
Reporter object that has a single execution of the "execute" method for each execute flag.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
static const std::string REPORTER_RESTARTABLE_DATA_PREFIX
The prefix for reporter data in the restartable system.
Reports restartable data and restartable meta data.
const std::vector< std::string > _include
The include patterns to match.
const RestartableDataMap & _data_map
The map of data that we're going to output.
RestartableDataValue::StoreJSONParams getDataParams() const
Internal method for setting _data_params.
static InputParameters validParams()
const bool _allow_unimplemented
Whether or not to error on the output of types with unimplemented output methods.
const std::vector< std::string > _exclude
The exclude patterns to match.
std::map< std::string, RestartableDataReporter::Value > & _values
The values we are to output.
const RestartableDataValue::StoreJSONParams _data_params
The parameters to pass to the output of a single value.
RestartableDataReporter(const InputParameters &parameters)
virtual void execute() override
Execute method.
bool globCompare(const std::string &candidate, const std::string &pattern, std::size_t c, std::size_t p)
Definition MooseUtils.C:943
Helper struct for storing a single piece of restartable data.
const RestartableDataValue * value
RestartableDataValue::StoreJSONParams params
Struct that represents parameters for how to store the JSON value via store.