https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Reporter.h
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
10#pragma once
11
12// Moose includes
13#include "MooseTypes.h"
14#include "OutputInterface.h"
15#include "ReporterData.h"
16#include "InputParameters.h"
17
18// System includes
19#include <type_traits>
20
21// Forward declarations
22class FEProblemBase;
23
48{
49public:
51 Reporter(const MooseObject * moose_object);
52 virtual ~Reporter() = default;
53
54#ifdef MOOSE_KOKKOS_ENABLED
58 Reporter(const Reporter & object, const Moose::Kokkos::FunctorCopy & key);
59#endif
60
61 virtual void store(nlohmann::json & json) const;
62
69 virtual bool shouldStore() const { return true; }
70
79 virtual void declareLateValues() {}
80
81protected:
83
122 template <typename T, template <typename> class S = ReporterGeneralContext, typename... Args>
123 T & declareValue(const std::string & param_name, Args &&... args);
124 template <typename T, template <typename> class S = ReporterGeneralContext, typename... Args>
125 T & declareValue(const std::string & param_name, ReporterMode mode, Args &&... args);
126 template <typename T, template <typename> class S = ReporterGeneralContext, typename... Args>
127 T & declareValueByName(const ReporterValueName & value_name, Args &&... args);
128 template <typename T, template <typename> class S = ReporterGeneralContext, typename... Args>
129 T & declareValueByName(const ReporterValueName & value_name, ReporterMode mode, Args &&... args);
130
131 template <typename T, typename S, typename... Args>
132 T & declareValue(const std::string & param_name, Args &&... args);
133 template <typename T, typename S, typename... Args>
134 T & declareValue(const std::string & param_name, ReporterMode mode, Args &&... args);
135 template <typename T, typename S, typename... Args>
136 T & declareValueByName(const ReporterValueName & value_name, Args &&... args);
137 template <typename T, typename S, typename... Args>
138 T & declareValueByName(const ReporterValueName & value_name, ReporterMode mode, Args &&... args);
140
151 template <typename T, typename... Args>
152 T & declareUnusedValue(Args &&... args);
153
154private:
162 {
165 };
166
172 template <typename T>
174 {
176 };
177
183 const ReporterValueName & getReporterValueName(const std::string & param_name) const;
184
187
190
192 const std::string & _reporter_name;
193
196
199
201 std::vector<std::unique_ptr<UnusedWrapperBase>> _unused_values;
202};
203
204template <typename T, template <typename> class S, typename... Args>
205T &
206Reporter::declareValue(const std::string & param_name, Args &&... args)
207{
208 return declareValue<T, S<T>>(param_name, REPORTER_MODE_UNSET, args...);
209}
210
211template <typename T, template <typename> class S, typename... Args>
212T &
213Reporter::declareValue(const std::string & param_name, ReporterMode mode, Args &&... args)
214{
215 return declareValue<T, S<T>>(param_name, mode, args...);
216}
217
218template <typename T, typename S, typename... Args>
219T &
220Reporter::declareValue(const std::string & param_name, Args &&... args)
221{
222 return declareValue<T, S>(param_name, REPORTER_MODE_UNSET, args...);
223}
224
225template <typename T, typename S, typename... Args>
226T &
227Reporter::declareValue(const std::string & param_name, ReporterMode mode, Args &&... args)
228{
229 return declareValueByName<T, S>(getReporterValueName(param_name), mode, args...);
230}
231
232template <typename T, template <typename> class S, typename... Args>
233T &
234Reporter::declareValueByName(const ReporterValueName & value_name, Args &&... args)
235{
236 return declareValueByName<T, S<T>>(value_name, REPORTER_MODE_UNSET, args...);
237}
238
239template <typename T, template <typename> class S, typename... Args>
240T &
241Reporter::declareValueByName(const ReporterValueName & value_name,
242 ReporterMode mode,
243 Args &&... args)
244{
245 return declareValueByName<T, S<T>>(value_name, mode, args...);
246}
247
248template <typename T, typename S, typename... Args>
249T &
250Reporter::declareValueByName(const ReporterValueName & value_name, Args &&... args)
251{
252 return declareValueByName<T, S>(value_name, REPORTER_MODE_UNSET, args...);
253}
254
255template <typename T, typename S, typename... Args>
256T &
257Reporter::declareValueByName(const ReporterValueName & value_name,
258 ReporterMode mode,
259 Args &&... args)
260{
261 const ReporterName state_name(_reporter_name, value_name);
262
263 buildOutputHideVariableList({state_name.getCombinedName()});
264
265 // Only thread 0 will declare the reporter value. The rest will get a reference
266 // to an UnusedValue
269 : 0;
270 if (tid)
271 return declareUnusedValue<T>();
273 state_name, mode, _reporter_moose_object, args...);
274}
275
276template <typename T, typename... Args>
277T &
279{
280 _unused_values.emplace_back(std::make_unique<UnusedWrapper<T>>(std::forward(args)...));
281 UnusedWrapper<T> * wrapper = dynamic_cast<UnusedWrapper<T> *>(_unused_values.back().get());
282 return wrapper->value;
283}
unsigned int THREAD_ID
Definition MooseTypes.h:237
const ReporterMode REPORTER_MODE_UNSET
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
A class to provide an common interface to objects requiring "outputs" option.
void buildOutputHideVariableList(std::set< std::string > variable_names)
Builds hide lists for output objects NOT listed in the 'outputs' parameter.
This is a helper class for managing the storage of declared Reporter object values.
T & declareReporterValue(const ReporterName &reporter_name, const ReporterMode &mode, const MooseObject &producer, Args &&... args)
Method for returning a writable reference to the current Reporter value.
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
The Reporter system is comprised of objects that can contain any number of data values.
Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a si...
Definition Reporter.h:48
T & declareValueByName(const ReporterValueName &value_name, Args &&... args)
Definition Reporter.h:234
const std::string & _reporter_name
The name of the MooseObject, from "_object_name" param.
Definition Reporter.h:192
const InputParameters & _reporter_params
Ref. to MooseObject params.
Definition Reporter.h:189
virtual void declareLateValues()
Method that can be overriden to declare "late" Reporter values.
Definition Reporter.h:79
virtual void store(nlohmann::json &json) const
Definition Reporter.C:55
const ReporterValueName & getReporterValueName(const std::string &param_name) const
Definition Reporter.C:61
ReporterData & _reporter_data
Data storage.
Definition Reporter.h:198
static InputParameters validParams()
Definition Reporter.C:16
T & declareValue(const std::string &param_name, Args &&... args)
Method to define a value that the Reporter object is to produced.
Definition Reporter.h:206
T & declareValue(const std::string &param_name, ReporterMode mode, Args &&... args)
const MooseObject & _reporter_moose_object
The MooseObject creating this Reporter.
Definition Reporter.h:186
T & declareUnusedValue(Args &&... args)
Declare a unused value with type T.
Definition Reporter.h:278
FEProblemBase & _reporter_fe_problem
Needed for access to FEProblemBase::getReporterData.
Definition Reporter.h:195
T & declareValueByName(const ReporterValueName &value_name, ReporterMode mode, Args &&... args)
virtual bool shouldStore() const
Definition Reporter.h:69
virtual ~Reporter()=default
std::vector< std::unique_ptr< UnusedWrapperBase > > _unused_values
Storage for unused values declared with declareUnusedValue().
Definition Reporter.h:201
Internal base struct for use in storing unused values.
Definition Reporter.h:162
virtual ~UnusedWrapperBase()
Needed for polymorphism.
Definition Reporter.h:164
Internal struct for storing a unused value.
Definition Reporter.h:174