Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Reporter Class Reference

Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a simulation. More...

#include <Reporter.h>

Inheritance diagram for Reporter:
[legend]

Classes

struct  UnusedWrapper
 Internal struct for storing a unused value. More...
 
struct  UnusedWrapperBase
 Internal base struct for use in storing unused values. More...
 

Public Member Functions

 Reporter (const MooseObject *moose_object)
 
virtual ~Reporter ()=default
 
virtual void store (nlohmann::json &json) const
 
virtual bool shouldStore () const
 
virtual void declareLateValues ()
 Method that can be overriden to declare "late" Reporter values. More...
 
void buildOutputHideVariableList (std::set< std::string > variable_names)
 Builds hide lists for output objects NOT listed in the 'outputs' parameter. More...
 
const std::set< OutputName > & getOutputs ()
 Get the list of output objects that this class is restricted. More...
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

template<typename T , typename... Args>
T & declareUnusedValue (Args &&... args)
 Declare a unused value with type T. More...
 
template<typename T , template< typename > class S = ReporterGeneralContext, typename... Args>
T & declareValue (const std::string &param_name, Args &&... args)
 Method to define a value that the Reporter object is to produced. More...
 
template<typename T , template< typename > class S = ReporterGeneralContext, typename... Args>
T & declareValue (const std::string &param_name, ReporterMode mode, Args &&... args)
 
template<typename T , template< typename > class S = ReporterGeneralContext, typename... Args>
T & declareValueByName (const ReporterValueName &value_name, Args &&... args)
 
template<typename T , template< typename > class S = ReporterGeneralContext, typename... Args>
T & declareValueByName (const ReporterValueName &value_name, ReporterMode mode, Args &&... args)
 
template<typename T , typename S , typename... Args>
T & declareValue (const std::string &param_name, Args &&... args)
 
template<typename T , typename S , typename... Args>
T & declareValue (const std::string &param_name, ReporterMode mode, Args &&... args)
 
template<typename T , typename S , typename... Args>
T & declareValueByName (const ReporterValueName &value_name, Args &&... args)
 
template<typename T , typename S , typename... Args>
T & declareValueByName (const ReporterValueName &value_name, ReporterMode mode, Args &&... args)
 

Private Member Functions

const ReporterValueName & getReporterValueName (const std::string &param_name) const
 

Private Attributes

const MooseObject_reporter_moose_object
 The MooseObject creating this Reporter. More...
 
const InputParameters_reporter_params
 Ref. to MooseObject params. More...
 
const std::string & _reporter_name
 The name of the MooseObject, from "_object_name" param. More...
 
FEProblemBase_reporter_fe_problem
 Needed for access to FEProblemBase::getReporterData. More...
 
ReporterData_reporter_data
 Data storage. More...
 
std::vector< std::unique_ptr< UnusedWrapperBase > > _unused_values
 Storage for unused values declared with declareUnusedValue(). More...
 

Detailed Description

Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a simulation.

These aggregate values are then available to other objects for use. They operate with the typical producer/consumer relationship. The Reporter object produces values that other objects consume.

Originally, MOOSE included a Postprocessor system that allowed for an object to produce a single scalar value for consumption by other objects. Then a companion system was created, the VectorPostprocessor system, that allowed for an object to produce many std::vector<Real> values. The Reporter system is the generalization of these two ideas and follows closely the original design of the VectorPostprocessor system.

In practice, the Reporter system provided the following features over the two previous systems.

  1. It can create arbitrary data types rather than only Real and std::vector<Real>
  2. It can create many values per object. This was possible for VectorPostprocessor objects but not for Postprocessors. Therefore, this allows a single Reporter to provide multiple values and consolidate similar items. For example, a "counter" object replaced several individual Postprocessor objects.
  3. The ReporterContext system allows for each data value to have special operation within a single object. Previously the VectorPostprocessor system had capability to perform broadcasting, but it was applied to all vectors in the object.

Definition at line 47 of file Reporter.h.

Constructor & Destructor Documentation

◆ Reporter()

Reporter::Reporter ( const MooseObject moose_object)

Definition at line 29 of file Reporter.C.

30  : OutputInterface(moose_object->parameters(), /*build_list=*/false),
31  _reporter_moose_object(*moose_object),
33  _reporter_name(_reporter_params.get<std::string>("_object_name")),
35  *_reporter_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
37 {
38  // For the callback to declareLateValues()
40 }
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.
FEProblemBase & _reporter_fe_problem
Needed for access to FEProblemBase::getReporterData.
Definition: Reporter.h:187
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
OutputInterface(const InputParameters &parameters, bool build_list=true)
Handles &#39;outputs&#39; parameter for objects that desire control of variable outputs.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:45
const std::string & _reporter_name
The name of the MooseObject, from "_object_name" param.
Definition: Reporter.h:184
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
ReporterData & _reporter_data
Data storage.
Definition: Reporter.h:190
const InputParameters & _reporter_params
Ref. to MooseObject params.
Definition: Reporter.h:181
const MooseObject & _reporter_moose_object
The MooseObject creating this Reporter.
Definition: Reporter.h:178
const InputParameters & parameters() const
Get the parameters of the object.
void registerInterfaceObject(T &interface)
Registers an interface object for accessing with getInterfaceObjects.
Definition: MooseApp.h:1603

◆ ~Reporter()

virtual Reporter::~Reporter ( )
virtualdefault

Member Function Documentation

◆ buildOutputHideVariableList()

void OutputInterface::buildOutputHideVariableList ( std::set< std::string >  variable_names)
inherited

Builds hide lists for output objects NOT listed in the 'outputs' parameter.

Parameters
variable_namesA set of variables for which the 'outputs' parameter controls

By default this is called by the constructor and passes the block name as the list of variables. This needs to be called explicitly if the build_list flag is set to False in the constructor. The latter cases is needed by the Material object to work correctly with the automatic material output capability.

Definition at line 61 of file OutputInterface.C.

Referenced by ReporterTransferInterface::hideVariableHelper(), and OutputInterface::OutputInterface().

62 {
63  // Set of available names
64  const std::set<OutputName> & avail = _oi_output_warehouse.getOutputNames();
65 
66  // Check for 'none'; hide variables on all outputs
67  if (_oi_outputs.find("none") != _oi_outputs.end())
68  for (const auto & name : avail)
69  _oi_output_warehouse.addInterfaceHideVariables(name, variable_names);
70 
71  // Check for empty and 'all' in 'outputs' parameter; do not perform any variable restrictions in
72  // these cases
73  else if (_oi_outputs.empty() || _oi_outputs.find("all") != _oi_outputs.end())
74  return;
75 
76  // Limit the variable output to Output objects listed
77  else
78  {
79  // Create a list of outputs where the variable should be hidden
80  std::set<OutputName> hide;
81  std::set_difference(avail.begin(),
82  avail.end(),
83  _oi_outputs.begin(),
84  _oi_outputs.end(),
85  std::inserter(hide, hide.begin()));
86 
87  // If 'outputs' is specified add the object name to the list of items to hide
88  for (const auto & name : hide)
89  _oi_output_warehouse.addInterfaceHideVariables(name, variable_names);
90  }
91 }
OutputWarehouse & _oi_output_warehouse
Reference to the OutputWarehouse for populating the Output object hide lists.
std::set< OutputName > _oi_outputs
The set of Output object names listed in the &#39;outputs&#39; parameter.
const std::set< OutputName > & getOutputNames()
Get a complete set of all output object names.
void addInterfaceHideVariables(const std::string &output_name, const std::set< std::string > &variable_names)
Insert variable names for hiding via the OutoutInterface.

◆ declareLateValues()

virtual void Reporter::declareLateValues ( )
inlinevirtual

Method that can be overriden to declare "late" Reporter values.

Values are considered "late" when they need to be declared after all other Reporters have been instantiated. This is called by the "declare_late_reporters" task, which should be called right after the "add_reporters" task.

Reimplemented in AccumulateReporter.

Definition at line 71 of file Reporter.h.

71 {}

◆ declareUnusedValue()

template<typename T , typename... Args>
T & Reporter::declareUnusedValue ( Args &&...  args)
protected

Declare a unused value with type T.

This is useful when you have a reporter that has optional values. In this case, you want to create references to all reporter values. However, because some values are optional, you need something to fill into the reference. This helper will create a unused value. It also allows for the passing of arguments in the case that your value is not trivially default constructable (constructable by default without arguments).

Definition at line 270 of file Reporter.h.

271 {
272  _unused_values.emplace_back(std::make_unique<UnusedWrapper<T>>(std::forward(args)...));
273  UnusedWrapper<T> * wrapper = dynamic_cast<UnusedWrapper<T> *>(_unused_values.back().get());
274  return wrapper->value;
275 }
std::vector< std::unique_ptr< UnusedWrapperBase > > _unused_values
Storage for unused values declared with declareUnusedValue().
Definition: Reporter.h:193

◆ declareValue() [1/4]

template<typename T , typename S , typename... Args>
T & Reporter::declareValue ( const std::string &  param_name,
Args &&...  args 
)
protected

Method to define a value that the Reporter object is to produced.

Template Parameters
TThe C++ type of the value to be produced
S(optional) Context type for performing special operations. For example using the ReporterBroadcastContext will automatically broadcast the produced value from the root processor.
Parameters
nameA unique name for the value to be produced.
mode(optional) The mode that indicates how the value produced is represented in parallel, there is more information about this below
args(optional) Any number of optional arguments passed into the ReporterContext given by the S template parameter. If S = ReporterContext then the first argument can be used as the default value (see ReporterContext.h).

The 'mode' indicates how the value that is produced is represented in parallel. It is the responsibility of the Reporter object to get it to that state. The ReporterContext objects are designed to help with this. The mode can be one of the following:

ReporterMode::ROOT Indicates that the value produced is complete/correct on the
                   root processor for the object.
ReporterMode::REPLICATED Indicates that the value produced is complete/correct on
                         all processors AND that the value is the same on all
                         processors
ReporterMode::DISTRIBUTED Indicates that the value produced is complete/correct on
                          all processors AND that the value is NOT the same on all
                          processors

WARNING! Using the "default value" in ReporterContext: The Reporter system, like the systems before it, allow for objects that consume values to be constructed prior to the produce objects. When a value is requested either by a producer (Reporter) or consumer (ReporterInterface) the data is allocated. As such the assigned default value from the producer should not be relied upon on the consumer side during object construction.

NOTE: The ReporterContext is just a mechanism to allow for handling of values in special ways. In practice it might be better to have specific methods for these special cases. For example, a declareBroadcastValue, etc. Please refer to the ReporterData object for more information on how the data system operates for Reporter values.

Definition at line 198 of file Reporter.h.

199 {
200  return declareValue<T, S<T>>(param_name, REPORTER_MODE_UNSET, args...);
201 }
const ReporterMode REPORTER_MODE_UNSET

◆ declareValue() [2/4]

template<typename T , typename S , typename... Args>
T & Reporter::declareValue ( const std::string &  param_name,
ReporterMode  mode,
Args &&...  args 
)
protected

Definition at line 205 of file Reporter.h.

206 {
207  return declareValue<T, S<T>>(param_name, mode, args...);
208 }

◆ declareValue() [3/4]

template<typename T , typename S , typename... Args>
T& Reporter::declareValue ( const std::string &  param_name,
Args &&...  args 
)
protected

◆ declareValue() [4/4]

template<typename T , typename S , typename... Args>
T& Reporter::declareValue ( const std::string &  param_name,
ReporterMode  mode,
Args &&...  args 
)
protected

◆ declareValueByName() [1/4]

template<typename T , typename S , typename... Args>
T & Reporter::declareValueByName ( const ReporterValueName &  value_name,
Args &&...  args 
)
protected

Definition at line 226 of file Reporter.h.

227 {
228  return declareValueByName<T, S<T>>(value_name, REPORTER_MODE_UNSET, args...);
229 }
const ReporterMode REPORTER_MODE_UNSET

◆ declareValueByName() [2/4]

template<typename T , typename S , typename... Args>
T & Reporter::declareValueByName ( const ReporterValueName &  value_name,
ReporterMode  mode,
Args &&...  args 
)
protected

Definition at line 233 of file Reporter.h.

236 {
237  return declareValueByName<T, S<T>>(value_name, mode, args...);
238 }

◆ declareValueByName() [3/4]

template<typename T , typename S , typename... Args>
T& Reporter::declareValueByName ( const ReporterValueName &  value_name,
Args &&...  args 
)
protected

◆ declareValueByName() [4/4]

template<typename T , typename S , typename... Args>
T& Reporter::declareValueByName ( const ReporterValueName &  value_name,
ReporterMode  mode,
Args &&...  args 
)
protected

◆ getOutputs()

const std::set< OutputName > & OutputInterface::getOutputs ( )
inherited

Get the list of output objects that this class is restricted.

Returns
A set of OutputNames

Definition at line 94 of file OutputInterface.C.

95 {
96  return _oi_outputs;
97 }
std::set< OutputName > _oi_outputs
The set of Output object names listed in the &#39;outputs&#39; parameter.

◆ getReporterValueName()

const ReporterValueName & Reporter::getReporterValueName ( const std::string &  param_name) const
private
Returns
The ReporterValueName associated with the parameter param_name.

Performs error checking on if the parameter is valid.

Definition at line 49 of file Reporter.C.

50 {
51  if (!_reporter_params.isParamValid(param_name))
53  "When getting a ReporterValueName, failed to get a parameter with the name \"",
54  param_name,
55  "\".",
56  "\n\nKnown parameters:\n",
58 
59  if (_reporter_params.isType<ReporterValueName>(param_name))
60  return _reporter_params.get<ReporterValueName>(param_name);
61 
62  _reporter_moose_object.mooseError("Supplied parameter with name \"",
63  param_name,
64  "\" of type \"",
65  _reporter_params.type(param_name),
66  "\" is not an expected type for getting a Reporter value.\n\n",
67  "The expected type is \"ReporterValueName\".");
68 }
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.
const InputParameters & _reporter_params
Ref. to MooseObject params.
Definition: Reporter.h:181
bool isType(const std::string &name) const
std::string type(const std::string &name) const
Prints the type of the requested parameter by name.
const MooseObject & _reporter_moose_object
The MooseObject creating this Reporter.
Definition: Reporter.h:178
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ shouldStore()

virtual bool Reporter::shouldStore ( ) const
inlinevirtual
Returns
Whether or not this Reporter should store its value at this specific time.

Basic Reporters (those that are not GeneralReporters) will store at all times when requested.

Reimplemented in GeneralReporter, ElementReporter, and NodalReporter.

Definition at line 61 of file Reporter.h.

61 { return true; }

◆ store()

void Reporter::store ( nlohmann::json &  json) const
virtual

Definition at line 43 of file Reporter.C.

44 {
45  json["type"] = _reporter_params.get<std::string>("_type");
46 }
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.
const InputParameters & _reporter_params
Ref. to MooseObject params.
Definition: Reporter.h:181

◆ validParams()

InputParameters Reporter::validParams ( )
static

Definition at line 16 of file Reporter.C.

Referenced by ElementReporter::validParams(), NodalReporter::validParams(), GeneralReporter::validParams(), and Executioner::validParams().

17 {
19  params += OutputInterface::validParams();
20 
21  params.registerBase("Reporter");
22  return params;
23 }
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...

Member Data Documentation

◆ _reporter_data

ReporterData& Reporter::_reporter_data
private

Data storage.

Definition at line 190 of file Reporter.h.

◆ _reporter_fe_problem

FEProblemBase& Reporter::_reporter_fe_problem
private

Needed for access to FEProblemBase::getReporterData.

Definition at line 187 of file Reporter.h.

◆ _reporter_moose_object

const MooseObject& Reporter::_reporter_moose_object
private

The MooseObject creating this Reporter.

Definition at line 178 of file Reporter.h.

Referenced by getReporterValueName(), and Reporter().

◆ _reporter_name

const std::string& Reporter::_reporter_name
private

The name of the MooseObject, from "_object_name" param.

Definition at line 184 of file Reporter.h.

◆ _reporter_params

const InputParameters& Reporter::_reporter_params
private

Ref. to MooseObject params.

Definition at line 181 of file Reporter.h.

Referenced by getReporterValueName(), and store().

◆ _unused_values

std::vector<std::unique_ptr<UnusedWrapperBase> > Reporter::_unused_values
private

Storage for unused values declared with declareUnusedValue().

Definition at line 193 of file Reporter.h.

Referenced by declareUnusedValue().


The documentation for this class was generated from the following files: