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 
16 {
18 
19  params.addRequiredParam<PostprocessorName>("postprocessor", "The name of the postprocessor");
20  params.addParam<bool>("change_with_respect_to_initial",
21  false,
22  "Compute change with respect to initial value instead of previous value");
23  params.addParam<bool>(
24  "compute_relative_change", false, "Compute magnitude of relative change instead of change");
25  params.addParam<bool>("take_absolute_value", false, "Option to take absolute value of change");
26 
27  params.addClassDescription("Computes the change or relative change in a post-processor value "
28  "over a timestep or the entire transient");
29 
30  return params;
31 }
32 
34  : GeneralPostprocessor(parameters),
35  _change_with_respect_to_initial(getParam<bool>("change_with_respect_to_initial")),
36  _compute_relative_change(getParam<bool>("compute_relative_change")),
37  _take_absolute_value(getParam<bool>("take_absolute_value")),
38  _pps_value(getPostprocessorValue("postprocessor")),
39  _pps_value_old(getPostprocessorValueOld("postprocessor")),
40  _pps_value_initial(declareRestartableData<Real>("pps_value_initial")),
41  _value(0.0)
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 void
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  _value = std::fabs(change);
100  else
101  _value = change;
102 }
103 
104 Real
106 {
107  return _value;
108 }
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
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
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()
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.
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.
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
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:210
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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:39
Real _value
This post-processor value.
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28