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 #ifdef MOOSE_KOKKOS_ENABLED
29 
33 #endif
34 
35 protected:
37 
48  template <typename T>
49  const T & getReporterValue(const std::string & param_name, const std::size_t time_index = 0);
50  template <typename T>
51  const T & getReporterValue(const std::string & param_name,
52  ReporterMode mode,
53  const std::size_t time_index = 0);
54  // doco-normal-methods-end
56 
58 
67  template <typename T>
68  const T & getReporterValueByName(const ReporterName & reporter_name,
69  const std::size_t time_index = 0);
70  template <typename T>
71  const T & getReporterValueByName(const ReporterName & reporter_name,
72  ReporterMode mode,
73  const std::size_t time_index = 0);
75 
77 
82  bool hasReporterValue(const std::string & param_name) const;
83  bool hasReporterValueByName(const ReporterName & reporter_name) const;
84  template <typename T>
85  bool hasReporterValue(const std::string & param_name) const;
86  template <typename T>
87  bool hasReporterValueByName(const ReporterName & reporter_name) const;
88 
90 
96  const ReporterContextBase &
97  getReporterContextBaseByName(const ReporterName & reporter_name) const;
98 
104  const ReporterName & getReporterName(const std::string & param_name) const;
105 
112  virtual void addReporterDependencyHelper(const ReporterName & /*state_name*/) {}
113 
114 private:
119  bool reportersAdded() const;
120 
129  template <typename T>
130  void possiblyCheckHasReporter(const ReporterName & reporter_name,
131  const std::string & param_name = "") const;
132 
135 
138 
141 
144 };
145 
146 template <typename T>
147 const T &
148 ReporterInterface::getReporterValue(const std::string & param_name, const std::size_t time_index)
149 {
150  return getReporterValue<T>(param_name, REPORTER_MODE_UNSET, time_index);
151 }
152 
153 template <typename T>
154 const T &
155 ReporterInterface::getReporterValue(const std::string & param_name,
156  ReporterMode mode,
157  const std::size_t time_index)
158 {
159  const auto & reporter_name = getReporterName(param_name);
160 
161  possiblyCheckHasReporter<T>(reporter_name, param_name);
162 
163  return getReporterValueByName<T>(reporter_name, mode, time_index);
164 }
165 
166 template <typename T>
167 const T &
169  const std::size_t time_index)
170 {
171  return getReporterValueByName<T>(reporter_name, REPORTER_MODE_UNSET, time_index);
172 }
173 
174 template <typename T>
175 const T &
177  ReporterMode mode,
178  const std::size_t time_index)
179 {
180  possiblyCheckHasReporter<T>(reporter_name);
181 
182  addReporterDependencyHelper(reporter_name);
183 
184  return _ri_reporter_data.getReporterValue<T>(reporter_name, _ri_moose_object, mode, time_index);
185 }
186 
187 template <typename T>
188 bool
189 ReporterInterface::hasReporterValue(const std::string & param_name) const
190 {
191  if (!reportersAdded())
193  "Cannot call hasReporterValue() until all Reporters have been constructed.");
194 
195  return hasReporterValueByName<T>(getReporterName(param_name));
196 }
197 
198 template <typename T>
199 bool
201 {
202  if (!reportersAdded())
204  "Cannot call hasReporterValueByName() until all Reporters have been constructed.");
205 
206  return _ri_reporter_data.hasReporterValue<T>(reporter_name);
207 }
208 
209 template <typename T>
210 void
212  const std::string & param_name /* = "" */) const
213 {
214  if (reportersAdded() && !hasReporterValueByName<T>(reporter_name))
215  {
216  std::stringstream oss;
217  oss << "A Reporter value with the name \"" << reporter_name << "\" and type \""
218  << MooseUtils::prettyCppType<T>() << "\" was not found.";
219 
220  if (_ri_params.isParamValid(param_name))
221  _ri_moose_object.paramError(param_name, oss.str());
222  else
223  _ri_moose_object.mooseError(oss.str());
224  }
225 }
virtual void addReporterDependencyHelper(const ReporterName &)
A method that can be overridden to update the UO dependencies.
static InputParameters validParams()
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:467
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
const ReporterContextBase & getReporterContextBaseByName(const ReporterName &reporter_name) const
Get the reporter context to allow non-typed operations with the data.
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
This is a helper class to aid with parallel communication of compute Reporter values as well as provi...
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:394
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.
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 and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
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:458
MooseEnumItem that automatically creates the ID and doesn&#39;t allow the ID to be assigned.
Definition: ReporterMode.h:45
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