https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ExtremeValueBase.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
16
17#include <limits>
18
19template <class T>
23 InputParameters params = T::validParams();
25 "value_type",
26 MooseEnum("max=0 min=1 max_abs=2", "max"),
27 "Type of extreme value to return. 'max' "
28 "returns the maximum value. 'min' returns "
29 "the minimum value. 'max_abs' returns the maximum of the absolute value.");
30 return params;
31}
32
33template <class T>
35 : T(parameters), _type(parameters.get<MooseEnum>("value_type").getEnum<ExtremeType>())
36{
37}
38
39template <class T>
40void
42{
43 if (_type == ExtremeType::MAX || _type == ExtremeType::MAX_ABS)
44 _proxy_value =
45 std::make_pair(-std::numeric_limits<Real>::max(), -std::numeric_limits<Real>::max());
46 else if (_type == ExtremeType::MIN)
47 _proxy_value =
48 std::make_pair(std::numeric_limits<Real>::max(), std::numeric_limits<Real>::max());
49}
50
51template <class T>
52void
54{
55 const auto pv = getProxyValuePair();
56
57 if ((_type == ExtremeType::MAX && pv > _proxy_value) ||
58 (_type == ExtremeType::MIN && pv < _proxy_value))
59 _proxy_value = pv;
60 else if (_type == ExtremeType::MAX_ABS && std::abs(pv.first) > _proxy_value.first)
61 _proxy_value = std::make_pair(std::abs(pv.first), pv.second);
62}
63
64template <class T>
65Real
67{
68 return _proxy_value.second;
69}
70
71template <class T>
72void
74{
75 if (_type == ExtremeType::MAX || _type == ExtremeType::MAX_ABS)
76 this->gatherProxyValueMax(_proxy_value.first, _proxy_value.second);
77 else if (_type == ExtremeType::MIN)
78 this->gatherProxyValueMin(_proxy_value.first, _proxy_value.second);
79}
80
81template <class T>
82void
84{
85 const auto & pps = static_cast<const ExtremeValueBase<T> &>(y);
86
87 if (((_type == ExtremeType::MAX || _type == ExtremeType::MAX_ABS) &&
88 pps._proxy_value > _proxy_value) ||
89 (_type == ExtremeType::MIN && pps._proxy_value < _proxy_value))
90 _proxy_value = pps._proxy_value;
91}
92
ExtremeType
Type of extreme value we are going to compute.
virtual void initialize() override
virtual void computeExtremeValue()
Get the extreme value with a functor element argument.
std::pair< libMesh::Real, libMesh::Real > _proxy_value
Extreme value and proxy value at the same point.
virtual void finalize() override
virtual void threadJoin(const UserObject &y) override
virtual libMesh::Real getValue() const override
static InputParameters validParams()
ExtremeValueBase(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Base class for user-specific data.
Definition UserObject.h:20