https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
32void
34{
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
57void
59{
60 unsigned int ind = static_cast<unsigned int>(_t_step);
61 for (auto & val : _accumulated_values)
62 val->accumulate(ind);
63}
registerMooseObject("MooseApp", AccumulateReporter)
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
virtual void declareLateValues() override
Method that can be overriden to declare "late" Reporter values.
AccumulateReporter(const InputParameters &parameters)
bool declareAccumulateHelper(const ReporterName &rname)
Helper for declaring an accumulative reporter value This will fill in _accumulated_values if the repo...
virtual void execute() override
Execute method.
std::vector< std::unique_ptr< AccumulatedValueBase > > _accumulated_values
Vector of accumulated value objects.
static InputParameters validParams()
A MultiMooseEnum object to hold "execute_on" flags.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
Reporter object that has a single execution of the "execute" method for each execute flag.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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:457
virtual std::string type() const =0
Return the type of the data stored.
This is a helper class for managing the storage of declared Reporter object values.
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
int & _t_step
The number of the time step.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.