Line data Source code
1 : /****************************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* */ 4 : /* MALAMUTE: MOOSE Application Library for Advanced Manufacturing UTilitiEs */ 5 : /* */ 6 : /* Copyright 2021 - 2024, Battelle Energy Alliance, LLC */ 7 : /* ALL RIGHTS RESERVED */ 8 : /****************************************************************************/ 9 : 10 : #include "StainlessSteelElectricalConductivity.h" 11 : 12 : #include "libmesh/utility.h" 13 : #include "NonlinearSystemBase.h" 14 : #include "TimeIntegrator.h" 15 : 16 : #include "metaphysicl/raw_type.h" 17 : 18 : registerMooseObject("MalamuteApp", StainlessSteelElectricalConductivity); 19 : registerMooseObject("MalamuteApp", ADStainlessSteelElectricalConductivity); 20 : 21 : template <bool is_ad> 22 : InputParameters 23 116 : StainlessSteelElectricalConductivityTempl<is_ad>::validParams() 24 : { 25 116 : InputParameters params = Material::validParams(); 26 116 : params.addClassDescription( 27 : "Calculates the electrical conductivity as a function of temperature for " 28 : "AISI 304 stainless steel in base SI units"); 29 232 : params.addRequiredCoupledVar("temperature", "Coupled temperature variable"); 30 232 : params.addParam<Real>("electrical_conductivity_scale_factor", 31 232 : 1.0, 32 : "The scaling factor for stainless steel electrical conductivity"); 33 116 : return params; 34 0 : } 35 : 36 : template <bool is_ad> 37 87 : StainlessSteelElectricalConductivityTempl<is_ad>::StainlessSteelElectricalConductivityTempl( 38 : const InputParameters & parameters) 39 : : Material(parameters), 40 87 : _temperature(coupledGenericValue<is_ad>("temperature")), 41 174 : _electrical_conductivity(declareGenericProperty<Real, is_ad>("electrical_conductivity")), 42 87 : _electrical_conductivity_dT(declareProperty<Real>("electrical_conductivity_dT")), 43 261 : _electrical_conductivity_scale_factor(getParam<Real>("electrical_conductivity_scale_factor")) 44 : { 45 87 : } 46 : 47 : template <bool is_ad> 48 : void 49 9897032 : StainlessSteelElectricalConductivityTempl<is_ad>::setDerivatives(GenericReal<is_ad> & prop, 50 : Real dprop_dT, 51 : const ADReal & ad_T) 52 : { 53 9897032 : if (ad_T < 0) 54 0 : prop.derivatives() = 0; 55 : else 56 19794064 : prop.derivatives() = dprop_dT * ad_T.derivatives(); 57 9897032 : } 58 : 59 : template <> 60 : void 61 0 : StainlessSteelElectricalConductivityTempl<false>::setDerivatives(Real &, Real, const ADReal &) 62 : { 63 0 : mooseError( 64 : "Mistaken call of setDerivatives in a non-AD StainlessSteelElectricalConductivity version"); 65 : } 66 : 67 : template <bool is_ad> 68 : void 69 324 : StainlessSteelElectricalConductivityTempl<is_ad>::jacobianSetup() 70 : { 71 324 : _check_temperature_now = false; 72 : int number_nonlinear_it = 73 324 : _fe_problem.getNonlinearSystemBase(/*nl_sys_num=*/0).getCurrentNonlinearIterationNumber(); 74 324 : if (number_nonlinear_it == 0) 75 144 : _check_temperature_now = true; 76 324 : } 77 : 78 : template <bool is_ad> 79 : void 80 9897116 : StainlessSteelElectricalConductivityTempl<is_ad>::computeQpProperties() 81 : { 82 9897116 : if (_check_temperature_now) 83 : { 84 107 : if (_temperature[_qp] < 296.8) 85 99 : mooseDoOnce(mooseWarning("The temperature in ", 86 : _name, 87 : " is below the calibration lower range limit at a value of ", 88 : MetaPhysicL::raw_value(_temperature[_qp]))); 89 8 : else if (_temperature[_qp] > 1029.0) 90 2 : mooseError("The temperature in ", 91 2 : _name, 92 : " is above the calibration upper range limit at a value of ", 93 2 : MetaPhysicL::raw_value(_temperature[_qp])); 94 : 95 103 : _check_temperature_now = false; 96 : } 97 : // Allow fall through to calculate the material properties 98 9897112 : computeElectricalConductivity(); 99 9897112 : } 100 : 101 : template <bool is_ad> 102 : void 103 9897112 : StainlessSteelElectricalConductivityTempl<is_ad>::computeElectricalConductivity() 104 : { 105 9897112 : GenericReal<is_ad> electrical_resistivity = 1.575e-15 * Utility::pow<3>(_temperature[_qp]) - 106 9897112 : 3.236e-12 * Utility::pow<2>(_temperature[_qp]) + 107 9897112 : 2.724e-09 * _temperature[_qp] + 1.364e-07; // in Ohm/m 108 : 109 19794144 : _electrical_conductivity[_qp] = 1.0 / electrical_resistivity; 110 9897112 : _electrical_conductivity[_qp] *= _electrical_conductivity_scale_factor; 111 : 112 : // Apply the chain rule to calculate the derivative 113 9897032 : const Real non_ad_temperature = MetaPhysicL::raw_value(_temperature[_qp]); 114 9897112 : const Real conductivity_dT_inner = 3.0 * 1.575e-15 * Utility::pow<2>(non_ad_temperature) - 115 9897112 : 2.0 * 3.236e-12 * non_ad_temperature + 2.724e-09; 116 9897112 : _electrical_conductivity_dT[_qp] = 117 9897112 : -1.0 * conductivity_dT_inner / 118 9897112 : Utility::pow<2>(MetaPhysicL::raw_value(electrical_resistivity)) * 119 9897112 : _electrical_conductivity_scale_factor; 120 : 121 : if (is_ad) 122 9897032 : setDerivatives( 123 : _electrical_conductivity[_qp], _electrical_conductivity_dT[_qp], _temperature[_qp]); 124 9897112 : } 125 : 126 : template class StainlessSteelElectricalConductivityTempl<false>; 127 : template class StainlessSteelElectricalConductivityTempl<true>;