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 "ArrheniusMaterialProperty.h" 11 : 12 : #include "PhysicalConstants.h" 13 : 14 : #include "libmesh/utility.h" 15 : 16 : registerMooseObject("MiscApp", ArrheniusMaterialProperty); 17 : registerMooseObject("MiscApp", ADArrheniusMaterialProperty); 18 : 19 : template <bool is_ad> 20 : InputParameters 21 160 : ArrheniusMaterialPropertyTempl<is_ad>::validParams() 22 : { 23 160 : InputParameters params = Material::validParams(); 24 : 25 160 : params.addClassDescription( 26 : "Arbitrary material property of the sum of an arbitary number ($i$) of " 27 : "Arrhenius functions $A_i * \\exp{-Q_i / (RT)}$, where $A_i$ is the frequency " 28 : "factor, $Q_i$ is the activation energy, and $R$ is the gas constant."); 29 : 30 320 : params.addRequiredParam<std::string>("property_name", 31 : "Specify the name of this material property"); 32 320 : params.addRequiredCoupledVar("temperature", "Coupled temperature"); 33 320 : params.addRequiredParam<std::vector<Real>>("frequency_factor", 34 : "List of Arrhenius pre-exponential coefficients"); 35 320 : params.addRequiredParam<std::vector<Real>>("activation_energy", "List of activation energies"); 36 320 : params.addRangeCheckedParam<Real>("gas_constant", 37 : PhysicalConstants::ideal_gas_constant, 38 : "gas_constant>0", 39 : "Gas constant for Arrhenius function"); 40 480 : params.addRangeCheckedParam<Real>( 41 : "initial_temperature", 42 320 : 1.0, 43 : "initial_temperature > 0", 44 : "Initial temperature utilized for initialization of stateful properties"); 45 : 46 160 : return params; 47 0 : } 48 : 49 : template <bool is_ad> 50 123 : ArrheniusMaterialPropertyTempl<is_ad>::ArrheniusMaterialPropertyTempl( 51 : const InputParameters & parameters) 52 : : Material(parameters), 53 123 : _diffusivity( 54 246 : this->template declareGenericProperty<Real, is_ad>(getParam<std::string>("property_name"))), 55 369 : _diffusivity_dT(this->template declareGenericProperty<Real, is_ad>( 56 : getParam<std::string>("property_name") + "_dT")), 57 123 : _temperature(this->template coupledGenericValue<is_ad>("temperature")), 58 246 : _D_0(getParam<std::vector<Real>>("frequency_factor")), 59 246 : _Q(getParam<std::vector<Real>>("activation_energy")), 60 246 : _R(getParam<Real>("gas_constant")), 61 123 : _number(_D_0.size()), 62 369 : _initial_temperature(this->template getParam<Real>("initial_temperature")) 63 : { 64 123 : if (_number != _Q.size()) 65 0 : paramError("frequency_factor", 66 : "frequency_factor and activation_energy must have the same number of entries"); 67 123 : if (_number == 0) 68 0 : paramError("frequency_factor", 69 : "At least one frequency_factor and activation_energy parameter must be given"); 70 123 : } 71 : 72 : template <bool is_ad> 73 : void 74 0 : ArrheniusMaterialPropertyTempl<is_ad>::initQpStatefulProperties() 75 : { 76 0 : _diffusivity[_qp] = 0.0; 77 0 : _diffusivity_dT[_qp] = 0.0; 78 : 79 0 : for (unsigned int i = 0; i < _number; ++i) 80 : { 81 0 : _diffusivity[_qp] += _D_0[i] * std::exp(-_Q[i] / _R / _initial_temperature); 82 0 : _diffusivity_dT[_qp] -= _D_0[i] * std::exp(-_Q[i] / _R / _initial_temperature) * _Q[i]; 83 : } 84 : 85 0 : _diffusivity_dT[_qp] /= _R * Utility::pow<2>(_initial_temperature); 86 0 : } 87 : 88 : template <bool is_ad> 89 : void 90 358 : ArrheniusMaterialPropertyTempl<is_ad>::computeQpProperties() 91 : { 92 358 : const GenericReal<is_ad> temp = std::max(_temperature[_qp], 1e-30); 93 : 94 358 : _diffusivity[_qp] = 0.0; 95 358 : _diffusivity_dT[_qp] = 0.0; 96 : 97 1074 : for (unsigned int i = 0; i < _number; ++i) 98 : { 99 1436 : _diffusivity[_qp] += _D_0[i] * std::exp(-_Q[i] / _R / temp); 100 1436 : _diffusivity_dT[_qp] += _D_0[i] * std::exp(-_Q[i] / _R / temp) * _Q[i]; 101 : } 102 : 103 538 : _diffusivity_dT[_qp] /= (_R * Utility::pow<2>(temp)); 104 358 : }