www.mooseframework.org
ChangeOverTimePostprocessor.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
11 
13 
14 template <>
17 {
19 
20  params.addRequiredParam<PostprocessorName>("postprocessor", "The name of the postprocessor");
21  params.addParam<bool>("change_with_respect_to_initial",
22  false,
23  "Compute change with respect to initial value instead of previous value");
24  params.addParam<bool>(
25  "compute_relative_change", false, "Compute magnitude of relative change instead of change");
26  params.addParam<bool>("take_absolute_value", false, "Option to take absolute value of change");
27 
28  params.addClassDescription("Computes the change or relative change in a post-processor value "
29  "over a timestep or the entire transient");
30 
31  return params;
32 }
33 
35  : GeneralPostprocessor(parameters),
36  _change_with_respect_to_initial(getParam<bool>("change_with_respect_to_initial")),
37  _compute_relative_change(getParam<bool>("compute_relative_change")),
38  _take_absolute_value(getParam<bool>("take_absolute_value")),
39  _pps_value(getPostprocessorValue("postprocessor")),
40  _pps_value_old(getPostprocessorValueOld("postprocessor")),
41  _pps_value_initial(declareRestartableData<Real>("pps_value_initial"))
42 {
44  {
45  // ensure dependent post-processor is executed on initial
46  const PostprocessorName & pp_name = getParam<PostprocessorName>("postprocessor");
47  const UserObject & pp = _fe_problem.getUserObject<UserObject>(pp_name);
48  if (!pp.getExecuteOnEnum().contains(EXEC_INITIAL))
49  mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
50  "the dependent post-processor ('" +
51  pp_name + "') must include 'initial'");
52 
53  // ensure THIS post-processor is executed on initial
55  mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
56  "the ChangeOverTimePostprocessor ('" +
57  name() + "') must include 'initial'");
58  }
59 }
60 
61 void
63 {
64 }
65 
66 void
68 {
69 }
70 
71 Real
73 {
74  // copy initial value in case difference is measured against initial value
75  if (_t_step == 0)
77 
78  // determine value which change is measured against
79  Real base_value;
81  base_value = _pps_value_initial;
82  else
83  {
84  // Currently post-processors do not copy the values to old and older;
85  // _pps_value_old will therefore always be zero for _t_step = 0.
86  if (_t_step == 0)
87  base_value = _pps_value;
88  else
89  base_value = _pps_value_old;
90  }
91 
92  Real change;
94  change = (_pps_value - base_value) / base_value;
95  else
96  change = _pps_value - base_value;
97 
99  return std::fabs(change);
100  else
101  return change;
102 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
Get the user object by its name.
Computes the change in a post-processor value, or the magnitude of its relative change, over a time step or over the entire transient.
registerMooseObject("MooseApp", ChangeOverTimePostprocessor)
virtual void execute() override
Execute method.
const bool _compute_relative_change
option to compute the magnitude of relative change instead of change
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< GeneralPostprocessor >()
const PostprocessorValue & _pps_value_old
old post-processor value
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
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...
const PostprocessorValue & _pps_value
current post-processor value
virtual Real getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
bool contains(const std::string &value) const
Contains methods for seeing if a value is in the MultiMooseEnum.
int & _t_step
The number of the time step.
const bool _take_absolute_value
option to take the absolute value of the change
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
const bool _change_with_respect_to_initial
option to compute change with respect to initial value instead of previous time value ...
ChangeOverTimePostprocessor(const InputParameters &parameters)
const ExecFlagEnum & _execute_enum
Execute settings for this oejct.
Real & _pps_value_initial
initial post-processor value
InputParameters validParams< ChangeOverTimePostprocessor >()
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:141
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
Base class for user-specific data.
Definition: UserObject.h:37
const ExecFlagType EXEC_INITIAL