https://mooseframework.inl.gov
ReporterInterface.C
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 
10 #include "ReporterInterface.h"
11 
12 #include "FEProblemBase.h"
13 
16 {
17  return emptyInputParameters();
18 }
19 
21  : _ri_params(moose_object->parameters()),
22  _ri_fe_problem_base(*_ri_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
23  _ri_reporter_data(_ri_fe_problem_base.getReporterData()),
24  _ri_moose_object(*moose_object)
25 {
26 }
27 
28 #ifdef MOOSE_KOKKOS_ENABLED
31  : _ri_params(object._ri_params),
32  _ri_fe_problem_base(object._ri_fe_problem_base),
33  _ri_reporter_data(object._ri_reporter_data),
34  _ri_moose_object(object._ri_moose_object)
35 {
36 }
37 #endif
38 
39 bool
40 ReporterInterface::hasReporterValue(const std::string & param_name) const
41 {
42  if (!reportersAdded())
44  "Cannot call hasReporterValue() until all Reporters have been constructed.");
45 
46  return hasReporterValueByName(getReporterName(param_name));
47 }
48 
49 bool
51 {
52  if (!reportersAdded())
54  "Cannot call hasReporterValueByName() until all Reporters have been constructed.");
55 
56  return _ri_reporter_data.hasReporterValue(reporter_name);
57 }
58 
59 const ReporterContextBase &
61 {
62  if (!reportersAdded())
64  "Cannot call getReporterContextBaseByName() until all Reporters have been constructed.");
65 
66  return _ri_reporter_data.getReporterContextBase(reporter_name);
67 }
68 
69 const ReporterName &
70 ReporterInterface::getReporterName(const std::string & param_name) const
71 {
72  if (!_ri_params.isParamValid(param_name))
74  "When getting a Reporter, failed to get a parameter with the name \"",
75  param_name,
76  "\".",
77  "\n\nKnown parameters:\n",
79 
80  if (_ri_params.isType<ReporterName>(param_name))
81  return _ri_params.get<ReporterName>(param_name);
82 
83  _ri_moose_object.mooseError("Supplied parameter with name \"",
84  param_name,
85  "\" of type \"",
86  _ri_params.type(param_name),
87  "\" is not an expected type for getting a Reporter.\n\n",
88  "The expected type is \"ReporterName\".");
89 }
90 
91 bool
93 {
95 }
static InputParameters validParams()
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.
bool isTaskComplete(const std::string &task) const
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
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.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:87
InputParameters emptyInputParameters()
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.
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.
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:216
ReporterInterface(const MooseObject *moose_object)
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: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
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.
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.