https://mooseframework.inl.gov
ReporterInterface.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 #pragma once
10 
11 #include "MooseTypes.h"
12 #include "ReporterData.h"
13 #include "MooseObject.h"
14 
15 // Forward declarations
16 class FEProblemBase;
17 class InputParameters;
18 
23 {
24 public:
26  ReporterInterface(const MooseObject * moose_object);
27 
28 protected:
30 
41  template <typename T>
42  const T & getReporterValue(const std::string & param_name, const std::size_t time_index = 0);
43  template <typename T>
44  const T & getReporterValue(const std::string & param_name,
45  ReporterMode mode,
46  const std::size_t time_index = 0);
47  // doco-normal-methods-end
49 
51 
60  template <typename T>
61  const T & getReporterValueByName(const ReporterName & reporter_name,
62  const std::size_t time_index = 0);
63  template <typename T>
64  const T & getReporterValueByName(const ReporterName & reporter_name,
65  ReporterMode mode,
66  const std::size_t time_index = 0);
68 
70 
75  bool hasReporterValue(const std::string & param_name) const;
76  bool hasReporterValueByName(const ReporterName & reporter_name) const;
77  template <typename T>
78  bool hasReporterValue(const std::string & param_name) const;
79  template <typename T>
80  bool hasReporterValueByName(const ReporterName & reporter_name) const;
81 
83 
89  const ReporterName & getReporterName(const std::string & param_name) const;
90 
97  virtual void addReporterDependencyHelper(const ReporterName & /*state_name*/) {}
98 
99 private:
104  bool reportersAdded() const;
105 
114  template <typename T>
115  void possiblyCheckHasReporter(const ReporterName & reporter_name,
116  const std::string & param_name = "") const;
117 
120 
123 
126 
129 };
130 
131 template <typename T>
132 const T &
133 ReporterInterface::getReporterValue(const std::string & param_name, const std::size_t time_index)
134 {
135  return getReporterValue<T>(param_name, REPORTER_MODE_UNSET, time_index);
136 }
137 
138 template <typename T>
139 const T &
140 ReporterInterface::getReporterValue(const std::string & param_name,
141  ReporterMode mode,
142  const std::size_t time_index)
143 {
144  const auto & reporter_name = getReporterName(param_name);
145 
146  possiblyCheckHasReporter<T>(reporter_name, param_name);
147 
148  return getReporterValueByName<T>(reporter_name, mode, time_index);
149 }
150 
151 template <typename T>
152 const T &
154  const std::size_t time_index)
155 {
156  return getReporterValueByName<T>(reporter_name, REPORTER_MODE_UNSET, time_index);
157 }
158 
159 template <typename T>
160 const T &
162  ReporterMode mode,
163  const std::size_t time_index)
164 {
165  possiblyCheckHasReporter<T>(reporter_name);
166 
167  addReporterDependencyHelper(reporter_name);
168 
169  return _ri_reporter_data.getReporterValue<T>(reporter_name, _ri_moose_object, mode, time_index);
170 }
171 
172 template <typename T>
173 bool
174 ReporterInterface::hasReporterValue(const std::string & param_name) const
175 {
176  if (!reportersAdded())
178  "Cannot call hasReporterValue() until all Reporters have been constructed.");
179 
180  return hasReporterValueByName<T>(getReporterName(param_name));
181 }
182 
183 template <typename T>
184 bool
186 {
187  if (!reportersAdded())
189  "Cannot call hasReporterValueByName() until all Reporters have been constructed.");
190 
191  return _ri_reporter_data.hasReporterValue<T>(reporter_name);
192 }
193 
194 template <typename T>
195 void
197  const std::string & param_name /* = "" */) const
198 {
199  if (reportersAdded() && !hasReporterValueByName<T>(reporter_name))
200  {
201  std::stringstream oss;
202  oss << "A Reporter value with the name \"" << reporter_name << "\" and type \""
203  << MooseUtils::prettyCppType<T>() << "\" was not found.";
204 
205  if (_ri_params.isParamValid(param_name))
206  _ri_moose_object.paramError(param_name, oss.str());
207  else
208  _ri_moose_object.mooseError(oss.str());
209  }
210 }
virtual void addReporterDependencyHelper(const ReporterName &)
A method that can be overridden to update the UO dependencies.
static InputParameters validParams()
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.
const ReporterMode REPORTER_MODE_UNSET
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ReporterName & getReporterName(const std::string &param_name) const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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 inpu...
bool reportersAdded() const
bool hasReporterValue(const std::string &param_name) const
Return True if the Reporter value exists.
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
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
Interface to allow object to consume Reporter values.
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 ...
ReporterInterface(const MooseObject *moose_object)
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.
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
MooseEnumItem that automatically creates the ID and doesn&#39;t allow the ID to be assigned.
Definition: ReporterMode.h:44
void possiblyCheckHasReporter(const ReporterName &reporter_name, const std::string &param_name="") const
Helpers for "possibly" checking if a Reporter value exists.
bool hasReporterValueByName(const ReporterName &reporter_name) const
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30
FEProblemBase & _ri_fe_problem_base
Provides access to FEProblemBase::getReporterData.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
This is a helper class for managing the storage of declared Reporter object values.
Definition: ReporterData.h:48