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 "ComputeThermalExpansionEigenstrainBase.h" 11 : #include "RankTwoTensor.h" 12 : 13 : template <bool is_ad> 14 : InputParameters 15 3636 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::validParams() 16 : { 17 3636 : InputParameters params = ComputeEigenstrainBaseTempl<is_ad>::validParams(); 18 7272 : params.addCoupledVar("temperature", "Coupled temperature"); 19 7272 : params.addRequiredCoupledVar("stress_free_temperature", 20 : "Reference temperature at which there is no " 21 : "thermal expansion for thermal eigenstrain " 22 : "calculation"); 23 7272 : params.addParam<bool>("use_old_temperature", 24 7272 : false, 25 : "Flag to optionally use the temperature value from the previous timestep."); 26 7272 : params.addParam<MaterialPropertyName>("mean_thermal_expansion_coefficient_name", 27 : "Name of the mean coefficient of thermal expansion."); 28 3636 : return params; 29 0 : } 30 : 31 : template <bool is_ad> 32 2727 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::ComputeThermalExpansionEigenstrainBaseTempl( 33 : const InputParameters & parameters) 34 : : DerivativeMaterialInterface<ComputeEigenstrainBaseTempl<is_ad>>(parameters), 35 2727 : _temperature(_temperature_buffer), 36 2727 : _use_old_temperature(this->template getParam<bool>("use_old_temperature")), 37 2727 : _temperature_old(this->_fe_problem.isTransient() ? this->coupledValueOld("temperature") 38 : : this->_zero), 39 2727 : _deigenstrain_dT((is_ad || this->isCoupledConstant("temperature")) 40 2238 : ? nullptr 41 13428 : : &this->template declarePropertyDerivative<RankTwoTensor>( 42 2238 : _eigenstrain_name, this->coupledName("temperature"))), 43 2727 : _stress_free_temperature(this->coupledValue("stress_free_temperature")), 44 2727 : _temperature_prop(this->template coupledGenericValue<is_ad>("temperature")), 45 2727 : _mean_thermal_expansion_coefficient( 46 2727 : this->isParamValid("mean_thermal_expansion_coefficient_name") 47 2811 : ? &this->template declareProperty<Real>(this->template getParam<MaterialPropertyName>( 48 : "mean_thermal_expansion_coefficient_name")) 49 2727 : : nullptr) 50 : { 51 2727 : if (_use_old_temperature && !this->_fe_problem.isTransient()) 52 0 : this->paramError( 53 : "use_old_temperature", 54 : "The old state of the temperature variable is only available in a transient simulation."); 55 2727 : } 56 : 57 : template <bool is_ad> 58 : void 59 314621 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::subdomainSetup() 60 : { 61 : // call parent class subdomain setup, which ultimately calls Material::subdomainSetup() 62 314621 : ComputeEigenstrainBaseTempl<is_ad>::subdomainSetup(); 63 : 64 : // make sure we have enouch space to hold the augmented temperature values 65 314621 : const auto nqp = this->_fe_problem.getMaxQps(); 66 314621 : _temperature_buffer.resize(nqp); 67 314621 : } 68 : 69 : template <bool is_ad> 70 : void 71 1774218 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::computeProperties() 72 : { 73 : // we need to convert the temperature variable to a ChainedReal in the is_ad == false case 74 13759832 : for (_qp = 0; _qp < this->_qrule->n_points(); ++_qp) 75 : if constexpr (is_ad) 76 4498220 : _temperature_buffer[_qp] = 77 8996440 : _use_old_temperature ? _temperature_old[_qp] : _temperature_prop[_qp]; 78 : else 79 : { 80 7487394 : if (_use_old_temperature) 81 0 : _temperature_buffer[_qp] = {_temperature_old[_qp], 0}; 82 : else 83 7487394 : _temperature_buffer[_qp] = {_temperature_prop[_qp], 1}; 84 : } 85 : 86 1774218 : ComputeEigenstrainBaseTempl<is_ad>::computeProperties(); 87 1774218 : } 88 : 89 : template <bool is_ad> 90 : void 91 11983822 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::computeQpEigenstrain() 92 : { 93 11983822 : _eigenstrain[_qp].zero(); 94 11983822 : const auto thermal_strain = computeThermalStrain(); 95 : 96 : if constexpr (is_ad) 97 : { 98 4497068 : _eigenstrain[_qp].addIa(thermal_strain); 99 4497068 : if (_mean_thermal_expansion_coefficient) 100 : { 101 0 : if (_temperature[_qp] == _stress_free_temperature[_qp]) 102 0 : (*_mean_thermal_expansion_coefficient)[_qp] = 0.0; 103 : else 104 0 : (*_mean_thermal_expansion_coefficient)[_qp] = MetaPhysicL::raw_value( 105 : thermal_strain / (_temperature[_qp] - _stress_free_temperature[_qp])); 106 : } 107 : } 108 : else 109 : { 110 7486754 : _eigenstrain[_qp].addIa(thermal_strain.value()); 111 7486754 : if (_mean_thermal_expansion_coefficient) 112 : { 113 522368 : if (_temperature[_qp].value() == _stress_free_temperature[_qp]) 114 0 : (*_mean_thermal_expansion_coefficient)[_qp] = 0.0; 115 : else 116 522368 : (*_mean_thermal_expansion_coefficient)[_qp] = 117 522368 : thermal_strain.value() / (_temperature[_qp].value() - _stress_free_temperature[_qp]); 118 : } 119 7486754 : if (_deigenstrain_dT) 120 : { 121 7486754 : (*_deigenstrain_dT)[_qp].zero(); 122 7486754 : if (!_use_old_temperature) 123 7486754 : (*_deigenstrain_dT)[_qp].addIa(thermal_strain.derivatives()); 124 : } 125 : } 126 11983822 : } 127 : 128 : template class ComputeThermalExpansionEigenstrainBaseTempl<false>; 129 : template class ComputeThermalExpansionEigenstrainBaseTempl<true>;