https://mooseframework.inl.gov
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 
12 #include "ElementPostprocessor.h"
16 
17 #include <limits>
18 
19 template <class T>
22 {
24  params.addParam<MooseEnum>(
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 
33 template <class T>
35  : T(parameters), _type(parameters.get<MooseEnum>("value_type").getEnum<ExtremeType>())
36 {
37 }
38 
39 template <class T>
40 void
42 {
43  if (_type == ExtremeType::MAX || _type == ExtremeType::MAX_ABS)
44  _proxy_value =
46  else if (_type == ExtremeType::MIN)
47  _proxy_value =
49 }
50 
51 template <class T>
52 void
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 
64 template <class T>
65 Real
67 {
68  return _proxy_value.second;
69 }
70 
71 template <class T>
72 void
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 
81 template <class T>
82 void
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 
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
virtual Real getValue() const override
virtual void threadJoin(const UserObject &y) override
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
virtual void finalize() override
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams()
auto max(const L &left, const R &right)
ExtremeType
Type of extreme value we are going to compute.
ExtremeValueBase(const InputParameters &parameters)
static InputParameters validParams()
std::pair< Real, Real > _proxy_value
Extreme value and proxy value at the same point.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeExtremeValue()
Get the extreme value with a functor element argument.
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...
virtual void initialize() override
Base class for user-specific data.
Definition: UserObject.h:40