https://mooseframework.inl.gov
ChangeOverFixedPointPostprocessor.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 // moose includes
12 #include "Transient.h"
13 
15 
18 {
20 
21  params.addRequiredParam<PostprocessorName>("postprocessor", "The name of the postprocessor");
22  params.addParam<bool>("change_with_respect_to_initial",
23  false,
24  "Compute change with respect to value at the beginning of the FixedPoint "
25  "iterations instead of previous value");
26  params.addParam<bool>(
27  "compute_relative_change", false, "Compute magnitude of relative change instead of change");
28  params.addParam<bool>("take_absolute_value", false, "Option to take absolute value of change");
29 
30  params.addClassDescription("Computes the change or relative change in a post-processor value "
31  "over a single or multiple fixed point iterations");
32 
33  return params;
34 }
35 
37  const InputParameters & parameters)
38  : GeneralPostprocessor(parameters),
39  _change_with_respect_to_initial(getParam<bool>("change_with_respect_to_initial")),
40  _compute_relative_change(getParam<bool>("compute_relative_change")),
41  _take_absolute_value(getParam<bool>("take_absolute_value")),
42  _pps_value(getPostprocessorValue("postprocessor")),
43  _pps_value_old(0),
44  _pps_value_initial(declareRestartableData<Real>("pps_value_initial")),
45  _t_step_old(-1),
46  _value(0.0)
47 {
49  {
50  // ensure dependent post-processor is executed on initial
51  const PostprocessorName & pp_name = getParam<PostprocessorName>("postprocessor");
52  const UserObject & pp = _fe_problem.getUserObject<UserObject>(pp_name);
53  if (!pp.getExecuteOnEnum().isValueSet(EXEC_INITIAL))
54  mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
55  "the dependent post-processor ('" +
56  pp_name + "') must include 'initial'");
57 
58  // ensure THIS post-processor is executed on initial
60  mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
61  "the ChangeOverFixedPointPostprocessor ('" +
62  name() + "') must include 'initial'");
63  }
64 }
65 
66 void
68 {
69 }
70 
71 void
73 {
74 }
75 
76 void
78 {
79  // detect the beginning of a new FixedPoint iteration process
80  // it can either a new time step or a failed time step
81  bool new_time_step = false;
83  {
84  // new time step
85  if (_t_step != _t_step_old)
86  {
87  new_time_step = true;
89 
90  // copy initial value in case difference is measured against initial value
91  // or for a reset if the time step fails
93  }
94  // failed time step
95  else
97  }
98 
99  // determine value which change is measured against
100  Real base_value;
102  base_value = _pps_value_initial;
103  else
104  {
105  // for a new time step, initial value is the reference
106  if (new_time_step)
107  base_value = _pps_value_initial;
108  else
109  base_value = _pps_value_old;
110  }
111 
112  // Update previous value
114 
115  // compute change in value
116  Real change;
118  change = (_pps_value - base_value) / base_value;
119  else
120  change = _pps_value - base_value;
121 
123  _value = std::fabs(change);
124  else
125  _value = change;
126 }
127 
128 Real
130 {
131  return _value;
132 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
Get the user object by its name.
Real _pps_value_old
post-processor value at the previous fixed point iteration
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
unsigned int numFixedPointIts() const
Get the number of fixed point iterations performed Because this returns the number of fixed point ite...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
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...
static InputParameters validParams()
int & _t_step
The number of the time step.
Real _value
The value of this post-processor.
const PostprocessorValue & _pps_value
current post-processor value
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition: MooseApp.C:2118
const ExecFlagEnum & _execute_enum
Execute settings for this object.
ChangeOverFixedPointPostprocessor(const InputParameters &parameters)
virtual void execute() override
Execute method.
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:211
FixedPointSolve & fixedPointSolve()
Definition: Executioner.h:124
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
Computes the change in a post-processor value, or the magnitude of its relative change, over a time step or over the entire transient.
Real & _pps_value_initial
initial post-processor value
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...
const bool _take_absolute_value
option to take the absolute value of the change
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...
const bool _change_with_respect_to_initial
option to compute change with respect to initial value instead of previous time value ...
const bool _compute_relative_change
option to compute the magnitude of relative change instead of change
registerMooseObject("MooseApp", ChangeOverFixedPointPostprocessor)
Base class for user-specific data.
Definition: UserObject.h:40
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28