LCOV - code coverage report
Current view: top level - src/materials - ComputeInstantaneousThermalExpansionFunctionEigenstrain.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 28 30 93.3 %
Date: 2025-07-25 05:00:39 Functions: 8 8 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 "ComputeInstantaneousThermalExpansionFunctionEigenstrain.h"
      11             : #include "Function.h"
      12             : #include "CastDualNumber.h"
      13             : #include "RankTwoTensor.h"
      14             : 
      15             : registerMooseObject("SolidMechanicsApp", ComputeInstantaneousThermalExpansionFunctionEigenstrain);
      16             : registerMooseObject("SolidMechanicsApp", ADComputeInstantaneousThermalExpansionFunctionEigenstrain);
      17             : 
      18             : template <bool is_ad>
      19             : InputParameters
      20         384 : ComputeInstantaneousThermalExpansionFunctionEigenstrainTempl<is_ad>::validParams()
      21             : {
      22         384 :   InputParameters params = ComputeThermalExpansionEigenstrainBaseTempl<is_ad>::validParams();
      23         384 :   params.addClassDescription("Computes eigenstrain due to thermal expansion using a function that "
      24             :                              "describes the instantaneous thermal expansion as a function of "
      25             :                              "temperature");
      26         768 :   params.addRequiredParam<FunctionName>("thermal_expansion_function",
      27             :                                         "Function describing the instantaneous thermal expansion "
      28             :                                         "coefficient as a function of temperature");
      29         384 :   params.suppressParameter<bool>("use_old_temperature");
      30         384 :   return params;
      31           0 : }
      32             : 
      33             : template <bool is_ad>
      34         288 : ComputeInstantaneousThermalExpansionFunctionEigenstrainTempl<is_ad>::
      35             :     ComputeInstantaneousThermalExpansionFunctionEigenstrainTempl(const InputParameters & parameters)
      36             :   : ComputeThermalExpansionEigenstrainBaseTempl<is_ad>(parameters),
      37         288 :     _thermal_expansion_function(this->getFunction("thermal_expansion_function")),
      38         288 :     _thermal_strain(this->template declareGenericProperty<Real, is_ad>(
      39         288 :         this->_base_name + "InstantaneousThermalExpansionFunction_thermal_strain")),
      40         576 :     _thermal_strain_old(this->template getMaterialPropertyOld<Real>(
      41             :         this->_base_name + "InstantaneousThermalExpansionFunction_thermal_strain")),
      42         864 :     _step_one(this->template declareRestartableData<bool>("step_one", true))
      43             : {
      44         288 :   if (this->_use_old_temperature)
      45           0 :     this->paramError("use_old_temperature",
      46             :                      "The old temperature value cannot be used in this incremental update model.");
      47         288 : }
      48             : 
      49             : template <bool is_ad>
      50             : void
      51       22848 : ComputeInstantaneousThermalExpansionFunctionEigenstrainTempl<is_ad>::initQpStatefulProperties()
      52             : {
      53       22848 :   _thermal_strain[_qp] = 0;
      54       22848 : }
      55             : 
      56             : template <bool is_ad>
      57             : ValueAndDerivative<is_ad>
      58     2314496 : ComputeInstantaneousThermalExpansionFunctionEigenstrainTempl<is_ad>::computeThermalStrain()
      59             : {
      60     2314496 :   if (this->_t_step > 1)
      61       20448 :     _step_one = false;
      62             : 
      63             :   const auto & old_temp =
      64     2314496 :       (_step_one ? this->_stress_free_temperature[_qp] : this->_temperature_old[_qp]);
      65     2314496 :   const auto delta_T = this->_temperature[_qp] - old_temp;
      66             : 
      67     2314496 :   const auto alpha_current_temp = _thermal_expansion_function.value(this->_temperature[_qp]);
      68     2314496 :   const auto alpha_old_temp = _thermal_expansion_function.value(old_temp);
      69             : 
      70     2314496 :   const auto thermal_strain =
      71     6504768 :       _thermal_strain_old[_qp] + delta_T * 0.5 * (alpha_current_temp + alpha_old_temp);
      72             : 
      73             :   // Store thermal strain for use in the next timestep (casts ValueAndDerivative<is_ad>
      74             :   // to GenericReal<is_ad>).
      75     2314496 :   _thermal_strain[_qp] = dual_number_cast<GenericReal<is_ad>>(thermal_strain);
      76             : 
      77     2314496 :   return thermal_strain;
      78             : }
      79             : 
      80             : template class ComputeInstantaneousThermalExpansionFunctionEigenstrainTempl<false>;
      81             : template class ComputeInstantaneousThermalExpansionFunctionEigenstrainTempl<true>;

Generated by: LCOV version 1.14