https://mooseframework.inl.gov
ChangeOverTimePostprocessor.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 
11 #include "MooseUtils.h"
12 
14 
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  params.addParam<bool>("divide_by_dt",
28  false,
29  "If true, divide by the time step size. This may only be enabled if "
30  "'change_with_respect_to_initial' is 'false'.");
31 
32  params.addClassDescription("Computes the change or relative change in a post-processor value "
33  "over a timestep or the entire transient");
34 
35  return params;
36 }
37 
39  : GeneralPostprocessor(parameters),
40  _change_with_respect_to_initial(getParam<bool>("change_with_respect_to_initial")),
41  _compute_relative_change(getParam<bool>("compute_relative_change")),
42  _take_absolute_value(getParam<bool>("take_absolute_value")),
43  _divide_by_dt(getParam<bool>("divide_by_dt")),
44  _pps_value(getPostprocessorValue("postprocessor")),
45  _pps_value_old(getPostprocessorValueOld("postprocessor")),
46  _pps_value_initial(declareRestartableData<Real>("pps_value_initial")),
47  _value(0.0)
48 {
50  {
51  // ensure dependent post-processor is executed on initial
52  const PostprocessorName & pp_name = getParam<PostprocessorName>("postprocessor");
53  const UserObject & pp = _fe_problem.getUserObject<UserObject>(pp_name);
54  if (!pp.getExecuteOnEnum().isValueSet(EXEC_INITIAL))
55  mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
56  "the dependent post-processor ('" +
57  pp_name + "') must include 'initial'");
58 
59  // ensure THIS post-processor is executed on initial
61  mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
62  "the ChangeOverTimePostprocessor ('" +
63  name() + "') must include 'initial'");
64 
65  // The quantity (y_n - y_{n-1})/dt_n has obvious physical relevance, but the
66  // quantity (y_n - y_0)/dt_n has no obvious physical relevance, so we assume
67  // that this is a mistake and do not allow it. This could be a warning instead if later needed.
68  if (_divide_by_dt)
69  mooseError(
70  "The parameter 'divide_by_dt' may only be set to 'true' if "
71  "'change_with_respect_to_initial' is 'false', since this is assumed to be unintended.");
72  }
73 }
74 
75 void
77 {
78 }
79 
80 void
82 {
83 }
84 
85 void
87 {
88  // copy initial value in case difference is measured against initial value
89  if (_t_step == 0)
91 
92  // determine value which change is measured against
93  Real base_value;
95  base_value = _pps_value_initial;
96  else
97  {
98  // Currently post-processors do not copy the values to old and older;
99  // _pps_value_old will therefore always be zero for _t_step = 0.
100  if (_t_step == 0)
101  base_value = _pps_value;
102  else
103  base_value = _pps_value_old;
104  }
105 
106  Real change;
108  change = (_pps_value - base_value) / base_value;
109  else
110  change = _pps_value - base_value;
111 
113  _value = std::fabs(change);
114  else
115  _value = change;
116 
117  // Guard against division by zero; _dt=0 on INITIAL
118  if (_divide_by_dt && !MooseUtils::absoluteFuzzyEqual(_dt, 0.0))
119  _value /= _dt;
120 }
121 
122 Real
124 {
125  return _value;
126 }
static InputParameters validParams()
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
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...
const PostprocessorValue & _pps_value_old
old post-processor value
Real & _dt
Time step size.
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
const bool _divide_by_dt
option to divide by the time step size
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
static InputParameters validParams()
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
int & _t_step
The number of the time step.
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
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.
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
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 object.
Real & _pps_value_initial
initial post-processor value
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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
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 optional parameter and a documentation string to the InputParameters object...
Base class for user-specific data.
Definition: UserObject.h:19
Real _value
This post-processor value.
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:30