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 42957 : ElementExtremeMaterialPropertyTempl<is_ad>::validParams() 23 : { 24 42957 : InputParameters params = ElementPostprocessor::validParams(); 25 : 26 42957 : params.addRequiredParam<MaterialPropertyName>("mat_prop", 27 : "Material property for which to find the extreme"); 28 42957 : MooseEnum type_options("max=0 min=1"); 29 42957 : 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 42957 : params.addClassDescription( 36 : "Determines the minimum or maximum of a material property over a volume."); 37 : 38 85914 : return params; 39 42957 : } 40 : 41 : template <bool is_ad> 42 84 : ElementExtremeMaterialPropertyTempl<is_ad>::ElementExtremeMaterialPropertyTempl( 43 : const InputParameters & parameters) 44 : : ElementPostprocessor(parameters), 45 : 46 84 : _mat_prop(getGenericMaterialProperty<Real, is_ad>("mat_prop")), 47 84 : _type((ExtremeType)(int)parameters.get<MooseEnum>("value_type")), 48 84 : _value(_type == 0 ? -std::numeric_limits<Real>::max() : std::numeric_limits<Real>::max()), 49 84 : _qp(0) 50 : { 51 84 : } 52 : 53 : template <bool is_ad> 54 : void 55 1482 : ElementExtremeMaterialPropertyTempl<is_ad>::initialize() 56 : { 57 1482 : switch (_type) 58 : { 59 741 : case MAX: 60 741 : _value = -std::numeric_limits<Real>::max(); // start w/ the min 61 741 : break; 62 : 63 741 : case MIN: 64 741 : _value = std::numeric_limits<Real>::max(); // start w/ the max 65 741 : break; 66 : } 67 1482 : } 68 : 69 : template <bool is_ad> 70 : void 71 1548 : ElementExtremeMaterialPropertyTempl<is_ad>::execute() 72 : { 73 3096 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 74 1548 : computeQpValue(); 75 1548 : } 76 : 77 : template <bool is_ad> 78 : void 79 1548 : ElementExtremeMaterialPropertyTempl<is_ad>::computeQpValue() 80 : { 81 1548 : switch (_type) 82 : { 83 774 : case MAX: 84 774 : _value = std::max(_value, MetaPhysicL::raw_value(_mat_prop[_qp])); 85 774 : break; 86 : 87 774 : case MIN: 88 774 : _value = std::min(_value, MetaPhysicL::raw_value(_mat_prop[_qp])); 89 774 : break; 90 : } 91 1548 : } 92 : 93 : template <bool is_ad> 94 : Real 95 72 : ElementExtremeMaterialPropertyTempl<is_ad>::getValue() const 96 : { 97 72 : return _value; 98 : } 99 : 100 : template <bool is_ad> 101 : void 102 48 : ElementExtremeMaterialPropertyTempl<is_ad>::finalize() 103 : { 104 48 : switch (_type) 105 : { 106 24 : case MAX: 107 24 : gatherMax(_value); 108 24 : break; 109 24 : case MIN: 110 24 : gatherMin(_value); 111 24 : break; 112 : } 113 48 : } 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>;