LCOV - code coverage report
Current view: top level - src/materials - ComputeThermalExpansionEigenstrainBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 52 59 88.1 %
Date: 2025-07-25 05:00:39 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://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        3232 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::validParams()
      16             : {
      17        3232 :   InputParameters params = ComputeEigenstrainBaseTempl<is_ad>::validParams();
      18        6464 :   params.addCoupledVar("temperature", "Coupled temperature");
      19        6464 :   params.addRequiredCoupledVar("stress_free_temperature",
      20             :                                "Reference temperature at which there is no "
      21             :                                "thermal expansion for thermal eigenstrain "
      22             :                                "calculation");
      23        6464 :   params.addParam<bool>("use_old_temperature",
      24        6464 :                         false,
      25             :                         "Flag to optionally use the temperature value from the previous timestep.");
      26        6464 :   params.addParam<MaterialPropertyName>("mean_thermal_expansion_coefficient_name",
      27             :                                         "Name of the mean coefficient of thermal expansion.");
      28        3232 :   return params;
      29           0 : }
      30             : 
      31             : template <bool is_ad>
      32        2424 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::ComputeThermalExpansionEigenstrainBaseTempl(
      33             :     const InputParameters & parameters)
      34             :   : DerivativeMaterialInterface<ComputeEigenstrainBaseTempl<is_ad>>(parameters),
      35        2424 :     _temperature(_temperature_buffer),
      36        2424 :     _use_old_temperature(this->template getParam<bool>("use_old_temperature")),
      37        2424 :     _temperature_old(this->_fe_problem.isTransient() ? this->coupledValueOld("temperature")
      38             :                                                      : this->_zero),
      39        2424 :     _deigenstrain_dT((is_ad || this->isCoupledConstant("temperature"))
      40        1992 :                          ? nullptr
      41       11952 :                          : &this->template declarePropertyDerivative<RankTwoTensor>(
      42        1992 :                                _eigenstrain_name, this->coupledName("temperature"))),
      43        2424 :     _stress_free_temperature(this->coupledValue("stress_free_temperature")),
      44        2424 :     _temperature_prop(this->template coupledGenericValue<is_ad>("temperature")),
      45        2424 :     _mean_thermal_expansion_coefficient(
      46        2424 :         this->isParamValid("mean_thermal_expansion_coefficient_name")
      47        2496 :             ? &this->template declareProperty<Real>(this->template getParam<MaterialPropertyName>(
      48             :                   "mean_thermal_expansion_coefficient_name"))
      49        2424 :             : nullptr)
      50             : {
      51        2424 :   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        2424 : }
      56             : 
      57             : template <bool is_ad>
      58             : void
      59      274320 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::subdomainSetup()
      60             : {
      61             :   // call parent class subdomain setup, which ultimately calls Material::subdomainSetup()
      62      274320 :   ComputeEigenstrainBaseTempl<is_ad>::subdomainSetup();
      63             : 
      64             :   // make sure we have enouch space to hold the augmented temperature values
      65      274320 :   const auto nqp = this->_fe_problem.getMaxQps();
      66      274320 :   _temperature_buffer.resize(nqp);
      67      274320 : }
      68             : 
      69             : template <bool is_ad>
      70             : void
      71     1524122 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::computeProperties()
      72             : {
      73             :   // we need to convert the temperature variable to a ChainedReal in the is_ad == false case
      74    11797852 :   for (_qp = 0; _qp < this->_qrule->n_points(); ++_qp)
      75             :     if constexpr (is_ad)
      76     4465632 :       _temperature_buffer[_qp] =
      77     8931264 :           _use_old_temperature ? _temperature_old[_qp] : _temperature_prop[_qp];
      78             :     else
      79             :     {
      80     5808098 :       if (_use_old_temperature)
      81           0 :         _temperature_buffer[_qp] = {_temperature_old[_qp], 0};
      82             :       else
      83     5808098 :         _temperature_buffer[_qp] = {_temperature_prop[_qp], 1};
      84             :     }
      85             : 
      86     1524122 :   ComputeEigenstrainBaseTempl<is_ad>::computeProperties();
      87     1524122 : }
      88             : 
      89             : template <bool is_ad>
      90             : void
      91    10272194 : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::computeQpEigenstrain()
      92             : {
      93    10272194 :   _eigenstrain[_qp].zero();
      94    10272194 :   const auto thermal_strain = computeThermalStrain();
      95             : 
      96             :   if constexpr (is_ad)
      97             :   {
      98     4464608 :     _eigenstrain[_qp].addIa(thermal_strain);
      99     4464608 :     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     5807586 :     _eigenstrain[_qp].addIa(thermal_strain.value());
     111     5807586 :     if (_mean_thermal_expansion_coefficient)
     112             :     {
     113      408576 :       if (_temperature[_qp].value() == _stress_free_temperature[_qp])
     114           0 :         (*_mean_thermal_expansion_coefficient)[_qp] = 0.0;
     115             :       else
     116      408576 :         (*_mean_thermal_expansion_coefficient)[_qp] =
     117      408576 :             thermal_strain.value() / (_temperature[_qp].value() - _stress_free_temperature[_qp]);
     118             :     }
     119     5807586 :     if (_deigenstrain_dT)
     120             :     {
     121     5807586 :       (*_deigenstrain_dT)[_qp].zero();
     122     5807586 :       if (!_use_old_temperature)
     123     5807586 :         (*_deigenstrain_dT)[_qp].addIa(thermal_strain.derivatives());
     124             :     }
     125             :   }
     126    10272194 : }
     127             : 
     128             : template class ComputeThermalExpansionEigenstrainBaseTempl<false>;
     129             : template class ComputeThermalExpansionEigenstrainBaseTempl<true>;

Generated by: LCOV version 1.14