https://mooseframework.inl.gov
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ReporterInterface Class Reference

Interface to allow object to consume Reporter values. More...

#include <ReporterInterface.h>

Inheritance diagram for ReporterInterface:
[legend]

Public Member Functions

 ReporterInterface (const MooseObject *moose_object)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

const ReporterContextBasegetReporterContextBaseByName (const ReporterName &reporter_name) const
 Get the reporter context to allow non-typed operations with the data. More...
 
const ReporterNamegetReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 A method that can be overridden to update the UO dependencies. More...
 
template<typename T >
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 doco-normal-methods-begin Returns read-only reference to a Reporter value that is provided by an input parameter. More...
 
template<typename T >
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
template<typename T >
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 Returns read-only reference to a Reporter value that is provided by name directly. More...
 
template<typename T >
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
bool hasReporterValue (const std::string &param_name) const
 Return True if the Reporter value exists. More...
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
template<typename T >
bool hasReporterValue (const std::string &param_name) const
 
template<typename T >
bool hasReporterValueByName (const ReporterName &reporter_name) const
 

Private Member Functions

bool reportersAdded () const
 
template<typename T >
void possiblyCheckHasReporter (const ReporterName &reporter_name, const std::string &param_name="") const
 Helpers for "possibly" checking if a Reporter value exists. More...
 

Private Attributes

const InputParameters_ri_params
 Parameters for the MooseObject inherting from this interface. More...
 
FEProblemBase_ri_fe_problem_base
 Provides access to FEProblemBase::getReporterData. More...
 
const ReporterData_ri_reporter_data
 The ReporterData. More...
 
const MooseObject_ri_moose_object
 The MooseObject needing this interface. More...
 

Detailed Description

Interface to allow object to consume Reporter values.

Definition at line 22 of file ReporterInterface.h.

Constructor & Destructor Documentation

◆ ReporterInterface()

ReporterInterface::ReporterInterface ( const MooseObject moose_object)

Definition at line 20 of file ReporterInterface.C.

21  : _ri_params(moose_object->parameters()),
24  _ri_moose_object(*moose_object)
25 {
26 }
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
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...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
const InputParameters & _ri_params
Parameters for the MooseObject inherting from this interface.
const ReporterData & _ri_reporter_data
The ReporterData.
FEProblemBase & _ri_fe_problem_base
Provides access to FEProblemBase::getReporterData.

Member Function Documentation

◆ addReporterDependencyHelper()

virtual void ReporterInterface::addReporterDependencyHelper ( const ReporterName )
inlineprotectedvirtual

A method that can be overridden to update the UO dependencies.

This is needed because the get methods for this interface cannot be virtual because of the template parameter. See GeneralUserObject for how it is utilized.

Reimplemented in UserObject.

Definition at line 105 of file ReporterInterface.h.

Referenced by getReporterValueByName().

105 {}

◆ getReporterContextBaseByName()

const ReporterContextBase & ReporterInterface::getReporterContextBaseByName ( const ReporterName reporter_name) const
protected

Get the reporter context to allow non-typed operations with the data.

Parameters
reporter_nameA ReporterName object that for the desired Reporter context.
Returns
ReporterContextBase of the reporter value

Definition at line 49 of file ReporterInterface.C.

Referenced by WebServerControl::startServer().

50 {
51  if (!reportersAdded())
53  "Cannot call getReporterContextBaseByName() until all Reporters have been constructed.");
54 
55  return _ri_reporter_data.getReporterContextBase(reporter_name);
56 }
bool reportersAdded() const
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
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:267
const ReporterData & _ri_reporter_data
The ReporterData.
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130

◆ getReporterName()

const ReporterName & ReporterInterface::getReporterName ( const std::string &  param_name) const
protected
Returns
The ReporterName associated with the parametre param_name.

Performs error checking to mak sure that the parameter is valid.

Definition at line 59 of file ReporterInterface.C.

Referenced by getReporterValue(), and hasReporterValue().

60 {
61  if (!_ri_params.isParamValid(param_name))
63  "When getting a Reporter, failed to get a parameter with the name \"",
64  param_name,
65  "\".",
66  "\n\nKnown parameters:\n",
68 
69  if (_ri_params.isType<ReporterName>(param_name))
70  return _ri_params.get<ReporterName>(param_name);
71 
72  _ri_moose_object.mooseError("Supplied parameter with name \"",
73  param_name,
74  "\" of type \"",
75  _ri_params.type(param_name),
76  "\" is not an expected type for getting a Reporter.\n\n",
77  "The expected type is \"ReporterName\".");
78 }
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 & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
bool isType(const std::string &name) const
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
const InputParameters & _ri_params
Parameters for the MooseObject inherting from this interface.
std::string type(const std::string &name) const
Prints the type of the requested parameter by name.
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:267
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ getReporterValue() [1/2]

template<typename T >
const T & ReporterInterface::getReporterValue ( const std::string &  param_name,
const std::size_t  time_index = 0 
)
protected

doco-normal-methods-begin Returns read-only reference to a Reporter value that is provided by an input parameter.

Template Parameters
TThe C++ type of the Reporter value being consumed
Parameters
param_nameThe name of the parameter that gives the name of the Reporter, which must be a ReporterName parameter (i.e., getParam<ReporterName>(param_name)).
modeThe mode that the object will consume the Reporter value time_index (optional) If zero is provided the current value is returned. Use a positive index to return previous values (1 = older, 2 = older, etc.). The maximum number of old values is dictated by the ReporterData object.

Definition at line 141 of file ReporterInterface.h.

142 {
143  return getReporterValue<T>(param_name, REPORTER_MODE_UNSET, time_index);
144 }
const ReporterMode REPORTER_MODE_UNSET

◆ getReporterValue() [2/2]

template<typename T >
const T & ReporterInterface::getReporterValue ( const std::string &  param_name,
ReporterMode  mode,
const std::size_t  time_index = 0 
)
protected

Definition at line 148 of file ReporterInterface.h.

151 {
152  const auto & reporter_name = getReporterName(param_name);
153 
154  possiblyCheckHasReporter<T>(reporter_name, param_name);
155 
156  return getReporterValueByName<T>(reporter_name, mode, time_index);
157 }
const ReporterName & getReporterName(const std::string &param_name) const

◆ getReporterValueByName() [1/2]

template<typename T >
const T & ReporterInterface::getReporterValueByName ( const ReporterName reporter_name,
const std::size_t  time_index = 0 
)
protected

Returns read-only reference to a Reporter value that is provided by name directly.

Template Parameters
TThe C++ type of the Reporter value being consumed
Parameters
reporter_nameA ReporterName object that for the desired Reporter value.
modeThe mode that the object will consume the Reporter value time_index (optional) If zero is provided the current value is returned. Use a positive index to return previous values (1 = older, 2 = older, etc.). The maximum number of old values is dictated by the ReporterData object.

Definition at line 161 of file ReporterInterface.h.

163 {
164  return getReporterValueByName<T>(reporter_name, REPORTER_MODE_UNSET, time_index);
165 }
const ReporterMode REPORTER_MODE_UNSET

◆ getReporterValueByName() [2/2]

template<typename T >
const T & ReporterInterface::getReporterValueByName ( const ReporterName reporter_name,
ReporterMode  mode,
const std::size_t  time_index = 0 
)
protected

Definition at line 169 of file ReporterInterface.h.

172 {
173  possiblyCheckHasReporter<T>(reporter_name);
174 
175  addReporterDependencyHelper(reporter_name);
176 
177  return _ri_reporter_data.getReporterValue<T>(reporter_name, _ri_moose_object, mode, time_index);
178 }
virtual void addReporterDependencyHelper(const ReporterName &)
A method that can be overridden to update the UO dependencies.
const T & getReporterValue(const ReporterName &reporter_name, const MooseObject &consumer, const ReporterMode &mode, const std::size_t time_index=0) const
Method for returning read only references to Reporter values.
Definition: ReporterData.h:388
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
const ReporterData & _ri_reporter_data
The ReporterData.

◆ hasReporterValue() [1/2]

bool ReporterInterface::hasReporterValue ( const std::string &  param_name) const
protected

Return True if the Reporter value exists.

Template Parameters
TThe C++ type of the Reporter value being consumed
Parameters
reporter_nameA ReporterName object that for the desired Reporter value.

Definition at line 29 of file ReporterInterface.C.

30 {
31  if (!reportersAdded())
33  "Cannot call hasReporterValue() until all Reporters have been constructed.");
34 
35  return hasReporterValueByName(getReporterName(param_name));
36 }
const ReporterName & getReporterName(const std::string &param_name) const
bool reportersAdded() const
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
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:267
bool hasReporterValueByName(const ReporterName &reporter_name) const

◆ hasReporterValue() [2/2]

template<typename T >
bool ReporterInterface::hasReporterValue ( const std::string &  param_name) const
protected

Definition at line 182 of file ReporterInterface.h.

183 {
184  if (!reportersAdded())
186  "Cannot call hasReporterValue() until all Reporters have been constructed.");
187 
188  return hasReporterValueByName<T>(getReporterName(param_name));
189 }
const ReporterName & getReporterName(const std::string &param_name) const
bool reportersAdded() const
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
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:267

◆ hasReporterValueByName() [1/2]

bool ReporterInterface::hasReporterValueByName ( const ReporterName reporter_name) const
protected

Definition at line 39 of file ReporterInterface.C.

Referenced by hasReporterValue(), AdvancedOutput::initShowHideLists(), and WebServerControl::startServer().

40 {
41  if (!reportersAdded())
43  "Cannot call hasReporterValueByName() until all Reporters have been constructed.");
44 
45  return _ri_reporter_data.hasReporterValue(reporter_name);
46 }
bool reportersAdded() const
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
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:267
const ReporterData & _ri_reporter_data
The ReporterData.
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:445

◆ hasReporterValueByName() [2/2]

template<typename T >
bool ReporterInterface::hasReporterValueByName ( const ReporterName reporter_name) const
protected

Definition at line 193 of file ReporterInterface.h.

194 {
195  if (!reportersAdded())
197  "Cannot call hasReporterValueByName() until all Reporters have been constructed.");
198 
199  return _ri_reporter_data.hasReporterValue<T>(reporter_name);
200 }
bool reportersAdded() const
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
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:267
const ReporterData & _ri_reporter_data
The ReporterData.
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:445

◆ possiblyCheckHasReporter()

template<typename T >
void ReporterInterface::possiblyCheckHasReporter ( const ReporterName reporter_name,
const std::string &  param_name = "" 
) const
private

Helpers for "possibly" checking if a Reporter value exists.

This is only able to check for existance after all Reporters have been added (after the task creating them has been called). If called before said task, this will do nothing, hence the "possibly". This allows us to have errors reported directly by the object requesting the Reporter instead of through a system with less context.

Definition at line 204 of file ReporterInterface.h.

206 {
207  if (reportersAdded() && !hasReporterValueByName<T>(reporter_name))
208  {
209  std::stringstream oss;
210  oss << "A Reporter value with the name \"" << reporter_name << "\" and type \""
211  << MooseUtils::prettyCppType<T>() << "\" was not found.";
212 
213  if (_ri_params.isParamValid(param_name))
214  _ri_moose_object.paramError(param_name, oss.str());
215  else
216  _ri_moose_object.mooseError(oss.str());
217  }
218 }
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
bool reportersAdded() const
const MooseObject & _ri_moose_object
The MooseObject needing this interface.
const InputParameters & _ri_params
Parameters for the MooseObject inherting from this interface.
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:267
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ reportersAdded()

bool ReporterInterface::reportersAdded ( ) const
private
Returns
True if all Reporters have been added (the task associated with adding them is complete)

Definition at line 81 of file ReporterInterface.C.

Referenced by getReporterContextBaseByName(), hasReporterValue(), hasReporterValueByName(), and possiblyCheckHasReporter().

82 {
84 }
bool isTaskComplete(const std::string &task) const
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:83
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:204
FEProblemBase & _ri_fe_problem_base
Provides access to FEProblemBase::getReporterData.

◆ validParams()

InputParameters ReporterInterface::validParams ( )
static

Definition at line 15 of file ReporterInterface.C.

Referenced by Executioner::validParams(), and UserObject::validParams().

16 {
17  return emptyInputParameters();
18 }
InputParameters emptyInputParameters()

Member Data Documentation

◆ _ri_fe_problem_base

FEProblemBase& ReporterInterface::_ri_fe_problem_base
private

Provides access to FEProblemBase::getReporterData.

Definition at line 130 of file ReporterInterface.h.

Referenced by reportersAdded().

◆ _ri_moose_object

const MooseObject& ReporterInterface::_ri_moose_object
private

◆ _ri_params

const InputParameters& ReporterInterface::_ri_params
private

Parameters for the MooseObject inherting from this interface.

Definition at line 127 of file ReporterInterface.h.

Referenced by getReporterName(), and possiblyCheckHasReporter().

◆ _ri_reporter_data

const ReporterData& ReporterInterface::_ri_reporter_data
private

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