www.mooseframework.org
TimeExtremeValue.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 
10 #include "TimeExtremeValue.h"
11 
12 #include <algorithm>
13 #include <limits>
14 
16 
17 template <>
20 {
21  // Define the min/max enumeration
22  MooseEnum type_options("max=0 min=1 abs_max=2 abs_min=3", "max");
23 
24  // Define the parameters
26  params.addParam<MooseEnum>("value_type",
27  type_options,
28  "Type of extreme value to return."
29  "'max' returns the maximum value."
30  "'min' returns the minimum value."
31  "'abs_max' returns the maximum absolute value."
32  "'abs_min' returns the minimum absolute value.");
33  params.addRequiredParam<PostprocessorName>(
34  "postprocessor", "The name of the postprocessor used for reporting time extreme values");
35  params.addClassDescription(
36  "A postprocessor for reporting the extreme value of another postprocessor over time.");
37 
38  return params;
39 }
40 
42  : GeneralPostprocessor(parameters),
43  _postprocessor(getPostprocessorValue("postprocessor")),
44  _type((ExtremeType)(int)parameters.get<MooseEnum>("value_type")),
45  _value(declareRestartableData<Real>("value"))
46 {
47  if (!_app.isRecovering())
48  {
49  switch (_type)
50  {
51  case MAX:
52  _value = -std::numeric_limits<Real>::max();
53  break;
54 
55  case MIN:
56  _value = std::numeric_limits<Real>::max();
57  break;
58 
59  case ABS_MAX:
60  // the max absolute value of anything is greater than or equal to 0
61  _value = 0;
62  break;
63 
64  case ABS_MIN:
65  // the min absolute value of anything is less than this
66  _value = std::numeric_limits<Real>::max();
67  break;
68 
69  default:
70  mooseError("Unrecognzed _type == ", _type);
71  }
72  }
73 }
74 
75 void
77 {
78  switch (_type)
79  {
80  case MAX:
81  _value = std::max(_value, _postprocessor);
82  break;
83 
84  case MIN:
85  _value = std::min(_value, _postprocessor);
86  break;
87 
88  case ABS_MAX:
89  _value = std::max(_value, std::abs(_postprocessor));
90  break;
91 
92  case ABS_MIN:
93  _value = std::min(_value, std::abs(_postprocessor));
94  break;
95 
96  default:
97  mooseError("Unrecognzed _type == ", _type);
98  }
99 }
100 
101 Real
103 {
104  return _value;
105 }
registerMooseObject("MooseApp", TimeExtremeValue)
ExtremeType _type
The extreme value type ("max", "min", etc.)
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
virtual Real getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void execute() override
Execute method.
InputParameters validParams< GeneralPostprocessor >()
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...
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:31
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:177
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...
Real & _value
The extreme value.
InputParameters validParams< TimeExtremeValue >()
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:859
A postprocessor for reporting the max/min value of another postprocessor over time.