www.mooseframework.org
TimeExtremeValue.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "TimeExtremeValue.h"
16 
17 #include <algorithm>
18 #include <limits>
19 
20 template <>
23 {
24  // Define the min/max enumeration
25  MooseEnum type_options("max=0 min=1 abs_max=2 abs_min=3", "max");
26 
27  // Define the parameters
29  params.addParam<MooseEnum>("value_type",
30  type_options,
31  "Type of extreme value to return."
32  "'max' returns the maximum value."
33  "'min' returns the minimum value."
34  "'abs_max' returns the maximum absolute value."
35  "'abs_min' returns the minimum absolute value.");
36  params.addRequiredParam<PostprocessorName>(
37  "postprocessor", "The name of the postprocessor used for reporting time extreme values");
38  params.addClassDescription(
39  "A postprocessor for reporting the extreme value of another postprocessor over time.");
40 
41  return params;
42 }
43 
45  : GeneralPostprocessor(parameters),
46  _postprocessor(getPostprocessorValue("postprocessor")),
47  _type((ExtremeType)(int)parameters.get<MooseEnum>("value_type")),
48  _value(declareRestartableData<Real>("value"))
49 {
50  if (!_app.isRecovering())
51  {
52  switch (_type)
53  {
54  case MAX:
55  _value = -std::numeric_limits<Real>::max();
56  break;
57 
58  case MIN:
59  _value = std::numeric_limits<Real>::max();
60  break;
61 
62  case ABS_MAX:
63  // the max absolute value of anything is greater than or equal to 0
64  _value = 0;
65  break;
66 
67  case ABS_MIN:
68  // the min absolute value of anything is less than this
69  _value = std::numeric_limits<Real>::max();
70  break;
71 
72  default:
73  mooseError("Unrecognzed _type == ", _type);
74  }
75  }
76 }
77 
78 void
80 {
81  switch (_type)
82  {
83  case MAX:
84  _value = std::max(_value, _postprocessor);
85  break;
86 
87  case MIN:
88  _value = std::min(_value, _postprocessor);
89  break;
90 
91  case ABS_MAX:
92  _value = std::max(_value, std::abs(_postprocessor));
93  break;
94 
95  case ABS_MIN:
96  _value = std::min(_value, std::abs(_postprocessor));
97  break;
98 
99  default:
100  mooseError("Unrecognzed _type == ", _type);
101  }
102 }
103 
104 Real
106 {
107  return _value;
108 }
ExtremeType _type
The extreme value type ("max", "min", etc.)
virtual Real getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:608
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void execute() override
Execute method.
InputParameters validParams< GeneralPostprocessor >()
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...
TimeExtremeValue(const InputParameters &parameters)
Class constructor.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
ExtremeType
What type of extreme value we are going to compute.
const PostprocessorValue & _postprocessor
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
Real & _value
The extreme value.
InputParameters validParams< TimeExtremeValue >()