https://mooseframework.inl.gov
AccumulateReporter.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 "AccumulateReporter.h"
11 
13 
16 {
18  params.addClassDescription("Reporter which accumulates the value of a inputted reporter value "
19  "over time into a vector reporter value of the same type.");
20  params.addRequiredParam<std::vector<ReporterName>>("reporters", "The reporters to accumulate.");
21 
22  params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
23  params.suppressParameter<ExecFlagEnum>("execute_on");
24  return params;
25 }
26 
28  : GeneralReporter(parameters)
29 {
30 }
31 
32 void
34 {
35  const ReporterData & rdata = _fe_problem.getReporterData();
36  for (const auto & rname : getParam<std::vector<ReporterName>>("reporters"))
37  {
38  if (!rdata.hasReporterValue(rname))
39  paramError("reporters", "Reporter ", rname, " does not exist.");
40 
41  if (!declareAccumulateHelper<int>(rname) && !declareAccumulateHelper<Real>(rname) &&
42  !declareAccumulateHelper<dof_id_type>(rname) &&
43  !declareAccumulateHelper<std::string>(rname) &&
44  !declareAccumulateHelper<std::vector<int>>(rname) &&
45  !declareAccumulateHelper<std::vector<Real>>(rname) &&
46  !declareAccumulateHelper<std::vector<std::string>>(rname) &&
47  !declareAccumulateHelper<std::vector<dof_id_type>>(rname))
48  paramError("reporters",
49  "Reporter value ",
50  rname,
51  " is of unsupported type ",
52  rdata.getReporterContextBase(rname).type(),
53  ".");
54  }
55 }
56 
57 void
59 {
60  unsigned int ind = static_cast<unsigned int>(_t_step);
61  for (auto & val : _accumulated_values)
62  val->accumulate(ind);
63 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
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
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:384
virtual void declareLateValues() override
Method that can be overriden to declare "late" Reporter values.
Reporter object that has a single execution of the "execute" method for for each execute flag...
virtual std::string type() const =0
Return the type of the data stored.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:36
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
int & _t_step
The number of the time step.
virtual void execute() override
Execute method.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:211
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
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
AccumulateReporter(const InputParameters &parameters)
std::vector< std::unique_ptr< AccumulatedValueBase > > _accumulated_values
Vector of accumulated value objects.
registerMooseObject("MooseApp", AccumulateReporter)
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130
bool declareAccumulateHelper(const ReporterName &rname)
Helper for declaring an accumulative reporter value This will fill in _accumulated_values if the repo...
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:30
This is a helper class for managing the storage of declared Reporter object values.
Definition: ReporterData.h:48