https://mooseframework.inl.gov
Reporter.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 "Reporter.h"
11 #include "InputParameters.h"
12 #include "FEProblemBase.h"
13 #include "MooseApp.h"
14 
17 {
19  params += OutputInterface::validParams();
20 
21  params.registerBase("Reporter");
22  return params;
23 }
24 
25 // The OutputInterface automatic creation of the "variable" build list is disabled because the
26 // output names for the reporters are more than just the block name. The list is updated manually
27 // when each value is declared.
28 
29 Reporter::Reporter(const MooseObject * moose_object)
30  : OutputInterface(moose_object->parameters(), /*build_list=*/false),
31  _reporter_moose_object(*moose_object),
32  _reporter_params(_reporter_moose_object.parameters()),
33  _reporter_name(_reporter_params.get<std::string>("_object_name")),
34  _reporter_fe_problem(
35  *_reporter_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
36  _reporter_data(_reporter_fe_problem.getReporterData(ReporterData::WriteKey()))
37 {
38  // For the callback to declareLateValues()
40 }
41 
42 void
43 Reporter::store(nlohmann::json & json) const
44 {
45  json["type"] = _reporter_params.get<std::string>("_type");
46 }
47 
48 const ReporterValueName &
49 Reporter::getReporterValueName(const std::string & param_name) const
50 {
51  if (!_reporter_params.isParamValid(param_name))
53  "When getting a ReporterValueName, failed to get a parameter with the name \"",
54  param_name,
55  "\".",
56  "\n\nKnown parameters:\n",
58 
59  if (_reporter_params.isType<ReporterValueName>(param_name))
60  return _reporter_params.get<ReporterValueName>(param_name);
61 
62  _reporter_moose_object.mooseError("Supplied parameter with name \"",
63  param_name,
64  "\" of type \"",
65  _reporter_params.type(param_name),
66  "\" is not an expected type for getting a Reporter value.\n\n",
67  "The expected type is \"ReporterValueName\".");
68 }
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.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
A class to provide an common interface to objects requiring "outputs" option.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ReporterValueName & getReporterValueName(const std::string &param_name) const
Definition: Reporter.C:49
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:45
InputParameters emptyInputParameters()
virtual void store(nlohmann::json &json) const
Definition: Reporter.C:43
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
Reporter(const MooseObject *moose_object)
Definition: Reporter.C:29
const InputParameters & _reporter_params
Ref. to MooseObject params.
Definition: Reporter.h:181
bool isType(const std::string &name) const
static InputParameters validParams()
Definition: Reporter.C:16
std::string type(const std::string &name) const
Prints the type of the requested parameter by name.
const MooseObject & _reporter_moose_object
The MooseObject creating this Reporter.
Definition: Reporter.h:178
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
void registerInterfaceObject(T &interface)
Registers an interface object for accessing with getInterfaceObjects.
Definition: MooseApp.h:1652
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