Line data Source code
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 : 10 : #include "ElementExtremeMaterialProperty.h" 11 : 12 : #include "metaphysicl/raw_type.h" 13 : 14 : #include <algorithm> 15 : #include <limits> 16 : 17 : registerMooseObject("MooseApp", ElementExtremeMaterialProperty); 18 : registerMooseObject("MooseApp", ADElementExtremeMaterialProperty); 19 : 20 : template <bool is_ad> 21 : InputParameters 22 42945 : ElementExtremeMaterialPropertyTempl<is_ad>::validParams() 23 : { 24 42945 : InputParameters params = ElementPostprocessor::validParams(); 25 : 26 42945 : params.addRequiredParam<MaterialPropertyName>("mat_prop", 27 : "Material property for which to find the extreme"); 28 42945 : MooseEnum type_options("max=0 min=1"); 29 42945 : 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 42945 : params.addClassDescription( 36 : "Determines the minimum or maximum of a material property over a volume."); 37 : 38 85890 : return params; 39 42945 : } 40 : 41 : template <bool is_ad> 42 78 : ElementExtremeMaterialPropertyTempl<is_ad>::ElementExtremeMaterialPropertyTempl( 43 : const InputParameters & parameters) 44 : : ElementPostprocessor(parameters), 45 : 46 78 : _mat_prop(getGenericMaterialProperty<Real, is_ad>("mat_prop")), 47 78 : _type((ExtremeType)(int)parameters.get<MooseEnum>("value_type")), 48 78 : _value(_type == 0 ? -std::numeric_limits<Real>::max() : std::numeric_limits<Real>::max()), 49 78 : _qp(0) 50 : { 51 78 : } 52 : 53 : template <bool is_ad> 54 : void 55 1320 : ElementExtremeMaterialPropertyTempl<is_ad>::initialize() 56 : { 57 1320 : switch (_type) 58 : { 59 660 : case MAX: 60 660 : _value = -std::numeric_limits<Real>::max(); // start w/ the min 61 660 : break; 62 : 63 660 : case MIN: 64 660 : _value = std::numeric_limits<Real>::max(); // start w/ the max 65 660 : break; 66 : } 67 1320 : } 68 : 69 : template <bool is_ad> 70 : void 71 1376 : ElementExtremeMaterialPropertyTempl<is_ad>::execute() 72 : { 73 2752 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 74 1376 : computeQpValue(); 75 1376 : } 76 : 77 : template <bool is_ad> 78 : void 79 1376 : ElementExtremeMaterialPropertyTempl<is_ad>::computeQpValue() 80 : { 81 1376 : switch (_type) 82 : { 83 688 : case MAX: 84 688 : _value = std::max(_value, MetaPhysicL::raw_value(_mat_prop[_qp])); 85 688 : break; 86 : 87 688 : case MIN: 88 688 : _value = std::min(_value, MetaPhysicL::raw_value(_mat_prop[_qp])); 89 688 : break; 90 : } 91 1376 : } 92 : 93 : template <bool is_ad> 94 : Real 95 66 : ElementExtremeMaterialPropertyTempl<is_ad>::getValue() const 96 : { 97 66 : return _value; 98 : } 99 : 100 : template <bool is_ad> 101 : void 102 44 : ElementExtremeMaterialPropertyTempl<is_ad>::finalize() 103 : { 104 44 : switch (_type) 105 : { 106 22 : case MAX: 107 22 : gatherMax(_value); 108 22 : break; 109 22 : case MIN: 110 22 : gatherMin(_value); 111 22 : break; 112 : } 113 44 : } 114 : 115 : template <bool is_ad> 116 : void 117 4 : ElementExtremeMaterialPropertyTempl<is_ad>::threadJoin(const UserObject & y) 118 : { 119 4 : const auto & pps = static_cast<const ElementExtremeMaterialPropertyTempl<is_ad> &>(y); 120 : 121 4 : switch (_type) 122 : { 123 2 : case MAX: 124 2 : _value = std::max(_value, pps._value); 125 2 : break; 126 2 : case MIN: 127 2 : _value = std::min(_value, pps._value); 128 2 : break; 129 : } 130 4 : } 131 : 132 : template class ElementExtremeMaterialPropertyTempl<false>; 133 : template class ElementExtremeMaterialPropertyTempl<true>;