LCOV - code coverage report
Current view: top level - src/materials - ComputeThermalExpansionEigenstrainBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose tensor_mechanics: d6b47a Lines: 52 59 88.1 %
Date: 2024-02-27 11:53:14 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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        1592 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::validParams()
      16             : {
      17        1592 :   InputParameters params = ComputeEigenstrainBaseTempl<is_ad>::validParams();
      18        3184 :   params.addCoupledVar("temperature", "Coupled temperature");
      19        3184 :   params.addRequiredCoupledVar("stress_free_temperature",
      20             :                                "Reference temperature at which there is no "
      21             :                                "thermal expansion for thermal eigenstrain "
      22             :                                "calculation");
      23        3184 :   params.addParam<bool>("use_old_temperature",
      24        3184 :                         false,
      25             :                         "Flag to optionally use the temperature value from the previous timestep.");
      26        3184 :   params.addParam<MaterialPropertyName>("mean_thermal_expansion_coefficient_name",
      27             :                                         "Name of the mean coefficient of thermal expansion.");
      28        1592 :   return params;
      29           0 : }
      30             : 
      31             : template <bool is_ad>
      32        1194 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::ComputeThermalExpansionEigenstrainBaseTempl(
      33             :     const InputParameters & parameters)
      34             :   : DerivativeMaterialInterface<ComputeEigenstrainBaseTempl<is_ad>>(parameters),
      35        1194 :     _temperature(_temperature_buffer),
      36        1194 :     _use_old_temperature(this->template getParam<bool>("use_old_temperature")),
      37        1194 :     _temperature_old(this->_fe_problem.isTransient() ? this->coupledValueOld("temperature")
      38             :                                                      : this->_zero),
      39        1194 :     _deigenstrain_dT((is_ad || this->isCoupledConstant("temperature"))
      40         978 :                          ? nullptr
      41        5868 :                          : &this->template declarePropertyDerivative<RankTwoTensor>(
      42         978 :                                _eigenstrain_name, this->coupledName("temperature"))),
      43        1194 :     _stress_free_temperature(this->coupledValue("stress_free_temperature")),
      44        1194 :     _temperature_prop(this->template coupledGenericValue<is_ad>("temperature")),
      45        1194 :     _mean_thermal_expansion_coefficient(
      46        1194 :         this->isParamValid("mean_thermal_expansion_coefficient_name")
      47        1230 :             ? &this->template declareProperty<Real>(this->template getParam<MaterialPropertyName>(
      48             :                   "mean_thermal_expansion_coefficient_name"))
      49        1194 :             : nullptr)
      50             : {
      51        1194 :   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        1194 : }
      56             : 
      57             : template <bool is_ad>
      58             : void
      59      140269 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::subdomainSetup()
      60             : {
      61             :   // call parent class subdomain setup, which ultimately calls Material::subdomainSetup()
      62      140269 :   ComputeEigenstrainBaseTempl<is_ad>::subdomainSetup();
      63             : 
      64             :   // make sure we have enouch space to hold the augmented temperature values
      65      140269 :   const auto nqp = this->_fe_problem.getMaxQps();
      66      140269 :   _temperature_buffer.resize(nqp);
      67      140269 : }
      68             : 
      69             : template <bool is_ad>
      70             : void
      71      756717 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::computeProperties()
      72             : {
      73             :   // we need to convert the temperature variable to a ChainedReal in the is_ad == false case
      74     5836514 :   for (_qp = 0; _qp < this->_qrule->n_points(); ++_qp)
      75             :     if constexpr (is_ad)
      76     2242000 :       _temperature_buffer[_qp] =
      77     4484000 :           _use_old_temperature ? _temperature_old[_qp] : _temperature_prop[_qp];
      78             :     else
      79             :     {
      80     2837797 :       if (_use_old_temperature)
      81           0 :         _temperature_buffer[_qp] = {_temperature_old[_qp], 0};
      82             :       else
      83     2837797 :         _temperature_buffer[_qp] = {_temperature_prop[_qp], 1};
      84             :     }
      85             : 
      86      756717 :   ComputeEigenstrainBaseTempl<is_ad>::computeProperties();
      87      756717 : }
      88             : 
      89             : template <bool is_ad>
      90             : void
      91     5079029 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::computeQpEigenstrain()
      92             : {
      93     5079029 :   _eigenstrain[_qp].zero();
      94     5079029 :   const auto thermal_strain = computeThermalStrain();
      95             : 
      96             :   if constexpr (is_ad)
      97             :   {
      98     2241488 :     _eigenstrain[_qp].addIa(thermal_strain);
      99     2241488 :     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     2837541 :     _eigenstrain[_qp].addIa(thermal_strain.value());
     111     2837541 :     if (_mean_thermal_expansion_coefficient)
     112             :     {
     113      207360 :       if (_temperature[_qp].value() == _stress_free_temperature[_qp])
     114           0 :         (*_mean_thermal_expansion_coefficient)[_qp] = 0.0;
     115             :       else
     116      207360 :         (*_mean_thermal_expansion_coefficient)[_qp] =
     117      207360 :             thermal_strain.value() / (_temperature[_qp].value() - _stress_free_temperature[_qp]);
     118             :     }
     119     2837541 :     if (_deigenstrain_dT)
     120             :     {
     121     2837541 :       (*_deigenstrain_dT)[_qp].zero();
     122     2837541 :       if (!_use_old_temperature)
     123     2837541 :         (*_deigenstrain_dT)[_qp].addIa(thermal_strain.derivatives());
     124             :     }
     125             :   }
     126     5079029 : }
     127             : 
     128             : template class ComputeThermalExpansionEigenstrainBaseTempl<false>;
     129             : template class ComputeThermalExpansionEigenstrainBaseTempl<true>;

Generated by: LCOV version 1.14