https://mooseframework.inl.gov
ElementExtremeMaterialProperty.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 "metaphysicl/raw_type.h"
13 
14 #include <algorithm>
15 #include <limits>
16 
19 
20 template <bool is_ad>
23 {
25 
26  params.addRequiredParam<MaterialPropertyName>("mat_prop",
27  "Material property for which to find the extreme");
28  MooseEnum type_options("max=0 min=1");
29  params.addRequiredParam<MooseEnum>("value_type",
30  type_options,
31  "Type of extreme value to return: 'max' "
32  "returns the maximum value and 'min' returns "
33  "the minimum value.");
34 
35  params.addClassDescription(
36  "Determines the minimum or maximum of a material property over a volume.");
37 
38  return params;
39 }
40 
41 template <bool is_ad>
43  const InputParameters & parameters)
44  : ElementPostprocessor(parameters),
45 
46  _mat_prop(getGenericMaterialProperty<Real, is_ad>("mat_prop")),
47  _type((ExtremeType)(int)parameters.get<MooseEnum>("value_type")),
48  _value(_type == 0 ? -std::numeric_limits<Real>::max() : std::numeric_limits<Real>::max()),
49  _qp(0)
50 {
51 }
52 
53 template <bool is_ad>
54 void
56 {
57  switch (_type)
58  {
59  case MAX:
60  _value = -std::numeric_limits<Real>::max(); // start w/ the min
61  break;
62 
63  case MIN:
64  _value = std::numeric_limits<Real>::max(); // start w/ the max
65  break;
66  }
67 }
68 
69 template <bool is_ad>
70 void
72 {
73  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
74  computeQpValue();
75 }
76 
77 template <bool is_ad>
78 void
80 {
81  switch (_type)
82  {
83  case MAX:
84  _value = std::max(_value, MetaPhysicL::raw_value(_mat_prop[_qp]));
85  break;
86 
87  case MIN:
88  _value = std::min(_value, MetaPhysicL::raw_value(_mat_prop[_qp]));
89  break;
90  }
91 }
92 
93 template <bool is_ad>
94 Real
96 {
97  return _value;
98 }
99 
100 template <bool is_ad>
101 void
103 {
104  switch (_type)
105  {
106  case MAX:
107  gatherMax(_value);
108  break;
109  case MIN:
110  gatherMin(_value);
111  break;
112  }
113 }
114 
115 template <bool is_ad>
116 void
118 {
119  const auto & pps = static_cast<const ElementExtremeMaterialPropertyTempl<is_ad> &>(y);
120 
121  switch (_type)
122  {
123  case MAX:
124  _value = std::max(_value, pps._value);
125  break;
126  case MIN:
127  _value = std::min(_value, pps._value);
128  break;
129  }
130 }
131 
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
static InputParameters validParams()
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
auto max(const L &left, const R &right)
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
ExtremeType
Type of extreme value to compute.
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
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 execute() override
Execute method.
ElementExtremeMaterialPropertyTempl(const InputParameters &parameters)
virtual void threadJoin(const UserObject &y) override
Must override.
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...
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
auto min(const L &left, const R &right)
void ErrorVector unsigned int
Base class for user-specific data.
Definition: UserObject.h:40
Determines the minimum or maximum of a material property over a volume.
registerMooseObject("MooseApp", ElementExtremeMaterialProperty)