https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
 
 Reporter (const Reporter &object, const Moose::Kokkos::FunctorCopy &key)
 Special constructor used for Kokkos functor copy during parallel dispatch.
 
virtual void store (nlohmann::json &json) const
 
virtual bool shouldStore () const
 
virtual void declareLateValues ()
 Method that can be overriden to declare "late" Reporter values.
 
void buildOutputHideVariableList (std::set< std::string > variable_names)
 Builds hide lists for output objects NOT listed in the 'outputs' parameter.
 
const std::set< OutputName > & getOutputs ()
 Get the list of output objects that this class is restricted.
 

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.
 
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.
 
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.
 
const InputParameters_reporter_params
 Ref. to MooseObject params.
 
const std::string & _reporter_name
 The name of the MooseObject, from "_object_name" param.
 
FEProblemBase_reporter_fe_problem
 Needed for access to FEProblemBase::getReporterData.
 
ReporterData_reporter_data
 Data storage.
 
std::vector< std::unique_ptr< UnusedWrapperBase > > _unused_values
 Storage for unused values declared with declareUnusedValue().
 
MooseApp_oi_moose_app
 Reference the the MooseApp; neede for access to the OutputWarehouse.
 
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 'outputs' parameter.
 

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() [1/2]

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),
37{
38 // For the callback to declareLateValues()
40}
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
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.
void registerInterfaceObject(T &interface)
Registers an interface object for accessing with getInterfaceObjects.
Definition MooseApp.h:1779
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition MooseBase.h:87
A class to provide an common interface to objects requiring "outputs" option.
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
ReporterData & _reporter_data
Data storage.
Definition Reporter.h:198
const MooseObject & _reporter_moose_object
The MooseObject creating this Reporter.
Definition Reporter.h:186
FEProblemBase & _reporter_fe_problem
Needed for access to FEProblemBase::getReporterData.
Definition Reporter.h:195

◆ ~Reporter()

virtual Reporter::~Reporter ( )
virtualdefault

◆ Reporter() [2/2]

Reporter::Reporter ( const Reporter object,
const Moose::Kokkos::FunctorCopy key 
)

Special constructor used for Kokkos functor copy during parallel dispatch.

Definition at line 43 of file Reporter.C.

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 68 of file OutputInterface.C.

69{
70 // Set of available names
71 const std::set<OutputName> & avail = _oi_output_warehouse.getOutputNames();
72
73 // Check for 'none'; hide variables on all outputs
74 if (_oi_outputs.find("none") != _oi_outputs.end())
75 for (const auto & name : avail)
76 _oi_output_warehouse.addInterfaceHideVariables(name, variable_names);
77
78 // Check for empty and 'all' in 'outputs' parameter; do not perform any variable restrictions in
79 // these cases
80 else if (_oi_outputs.empty() || _oi_outputs.find("all") != _oi_outputs.end())
81 return;
82
83 // Limit the variable output to Output objects listed
84 else
85 {
86 // Create a list of outputs where the variable should be hidden
87 std::set<OutputName> hide;
88 std::set_difference(avail.begin(),
89 avail.end(),
90 _oi_outputs.begin(),
91 _oi_outputs.end(),
92 std::inserter(hide, hide.begin()));
93
94 // If 'outputs' is specified add the object name to the list of items to hide
95 for (const auto & name : hide)
96 _oi_output_warehouse.addInterfaceHideVariables(name, variable_names);
97 }
98}
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 'outputs' parameter.
const std::set< OutputName > & getOutputNames()
Get a complete set of all output object names.
std::string name(const ElemQuality q)

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

◆ 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 79 of file Reporter.h.

79{}

◆ 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 278 of file Reporter.h.

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}
std::vector< std::unique_ptr< UnusedWrapperBase > > _unused_values
Storage for unused values declared with declareUnusedValue().
Definition Reporter.h:201

◆ 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 206 of file Reporter.h.

207{
208 return declareValue<T, S<T>>(param_name, REPORTER_MODE_UNSET, args...);
209}
const ReporterMode REPORTER_MODE_UNSET

◆ declareValue() [2/4]

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

◆ declareValue() [3/4]

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

Definition at line 213 of file Reporter.h.

214{
215 return declareValue<T, S<T>>(param_name, mode, args...);
216}

◆ 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 234 of file Reporter.h.

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

◆ declareValueByName() [2/4]

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

◆ declareValueByName() [3/4]

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

Definition at line 241 of file Reporter.h.

244{
245 return declareValueByName<T, S<T>>(value_name, mode, args...);
246}

◆ 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 101 of file OutputInterface.C.

102{
103 return _oi_outputs;
104}

◆ 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 61 of file Reporter.C.

62{
63 if (!_reporter_params.isParamValid(param_name))
65 "When getting a ReporterValueName, failed to get a parameter with the name \"",
66 param_name,
67 "\".",
68 "\n\nKnown parameters:\n",
70
71 if (_reporter_params.isType<ReporterValueName>(param_name))
72 return _reporter_params.get<ReporterValueName>(param_name);
73
74 _reporter_moose_object.mooseError("Supplied parameter with name \"",
75 param_name,
76 "\" of type \"",
77 _reporter_params.type(param_name),
78 "\" is not an expected type for getting a Reporter value.\n\n",
79 "The expected type is \"ReporterValueName\".");
80}
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.
std::string type(const std::string &name) const
Prints the type of the requested parameter by name.
bool isType(const std::string &name) const
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271

◆ 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 ElementReporter, GeneralReporter, and NodalReporter.

Definition at line 69 of file Reporter.h.

69{ return true; }

◆ store()

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

Definition at line 55 of file Reporter.C.

56{
57 json["type"] = _reporter_moose_object.type();
58}
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93

◆ validParams()

InputParameters Reporter::validParams ( )
static

Definition at line 16 of file Reporter.C.

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

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

Member Data Documentation

◆ _oi_moose_app

MooseApp& OutputInterface::_oi_moose_app
privateinherited

Reference the the MooseApp; neede for access to the OutputWarehouse.

Definition at line 72 of file OutputInterface.h.

◆ _oi_output_warehouse

OutputWarehouse& OutputInterface::_oi_output_warehouse
privateinherited

Reference to the OutputWarehouse for populating the Output object hide lists.

Definition at line 75 of file OutputInterface.h.

Referenced by OutputInterface::buildOutputHideVariableList().

◆ _oi_outputs

std::set<OutputName> OutputInterface::_oi_outputs
privateinherited

The set of Output object names listed in the 'outputs' parameter.

Definition at line 78 of file OutputInterface.h.

Referenced by OutputInterface::buildOutputHideVariableList(), and OutputInterface::getOutputs().

◆ _reporter_data

ReporterData& Reporter::_reporter_data
private

Data storage.

Definition at line 198 of file Reporter.h.

◆ _reporter_fe_problem

FEProblemBase& Reporter::_reporter_fe_problem
private

Needed for access to FEProblemBase::getReporterData.

Definition at line 195 of file Reporter.h.

◆ _reporter_moose_object

const MooseObject& Reporter::_reporter_moose_object
private

The MooseObject creating this Reporter.

Definition at line 186 of file Reporter.h.

Referenced by getReporterValueName(), Reporter(), and store().

◆ _reporter_name

const std::string& Reporter::_reporter_name
private

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

Definition at line 192 of file Reporter.h.

◆ _reporter_params

const InputParameters& Reporter::_reporter_params
private

Ref. to MooseObject params.

Definition at line 189 of file Reporter.h.

Referenced by getReporterValueName().

◆ _unused_values

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

Storage for unused values declared with declareUnusedValue().

Definition at line 201 of file Reporter.h.

Referenced by declareUnusedValue().


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