LCOV - code coverage report
Current view: top level - src/materials - GraphiteThermal.C (source / functions) Hit Total Coverage
Test: idaholab/malamute: 0e4c8a Lines: 67 71 94.4 %
Date: 2025-08-02 07:01:39 Functions: 7 14 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /****************************************************************************/
       2             : /*                        DO NOT MODIFY THIS HEADER                         */
       3             : /*                                                                          */
       4             : /* MALAMUTE: MOOSE Application Library for Advanced Manufacturing UTilitiEs */
       5             : /*                                                                          */
       6             : /*           Copyright 2021 - 2024, Battelle Energy Alliance, LLC           */
       7             : /*                           ALL RIGHTS RESERVED                            */
       8             : /****************************************************************************/
       9             : 
      10             : #include "GraphiteThermal.h"
      11             : 
      12             : #include "libmesh/utility.h"
      13             : #include "NonlinearSystemBase.h"
      14             : #include "TimeIntegrator.h"
      15             : 
      16             : #include "metaphysicl/raw_type.h"
      17             : 
      18             : registerMooseObject("MalamuteApp", GraphiteThermal);
      19             : registerMooseObject("MalamuteApp", ADGraphiteThermal);
      20             : 
      21             : template <bool is_ad>
      22             : InputParameters
      23         132 : GraphiteThermalTempl<is_ad>::validParams()
      24             : {
      25         132 :   InputParameters params = Material::validParams();
      26         132 :   params.addClassDescription(
      27             :       "Calculates the thermal conductivity and the heat capacity as a function of temperature for "
      28             :       "AT 101 graphite in base SI units");
      29         264 :   params.addRequiredCoupledVar("temperature", "Coupled temperature variable");
      30         264 :   params.addParam<Real>("thermal_conductivity_scale_factor",
      31         264 :                         1.0,
      32             :                         "The scaling factor for graphite thermal conductivity");
      33         264 :   params.addParam<Real>(
      34         264 :       "heat_capacity_scale_factor", 1.0, "The scaling factor for graphite heat capacity");
      35         132 :   return params;
      36           0 : }
      37             : 
      38             : template <bool is_ad>
      39          99 : GraphiteThermalTempl<is_ad>::GraphiteThermalTempl(const InputParameters & parameters)
      40             :   : Material(parameters),
      41          99 :     _temperature(coupledGenericValue<is_ad>("temperature")),
      42         198 :     _thermal_conductivity(declareGenericProperty<Real, is_ad>("thermal_conductivity")),
      43          99 :     _thermal_conductivity_dT(declareProperty<Real>("thermal_conductivity_dT")),
      44         198 :     _heat_capacity(declareGenericProperty<Real, is_ad>("heat_capacity")),
      45          99 :     _heat_capacity_dT(declareProperty<Real>("heat_capacity_dT")),
      46         198 :     _thermal_conductivity_scale_factor(getParam<Real>("thermal_conductivity_scale_factor")),
      47         297 :     _heat_capacity_scale_factor(getParam<Real>("heat_capacity_scale_factor"))
      48             : {
      49          99 : }
      50             : 
      51             : template <bool is_ad>
      52             : void
      53     5038992 : GraphiteThermalTempl<is_ad>::setDerivatives(GenericReal<is_ad> & prop,
      54             :                                             Real dprop_dT,
      55             :                                             const ADReal & ad_T)
      56             : {
      57     5038992 :   if (ad_T < 0)
      58           0 :     prop.derivatives() = 0;
      59             :   else
      60    10077984 :     prop.derivatives() = dprop_dT * ad_T.derivatives();
      61     5038992 : }
      62             : 
      63             : template <>
      64             : void
      65           0 : GraphiteThermalTempl<false>::setDerivatives(Real &, Real, const ADReal &)
      66             : {
      67           0 :   mooseError("Mistaken call of setDerivatives in a non-AD GraphiteThermal version");
      68             : }
      69             : 
      70             : template <bool is_ad>
      71             : void
      72         867 : GraphiteThermalTempl<is_ad>::jacobianSetup()
      73             : {
      74         867 :   _check_temperature_now = false;
      75             :   int number_nonlinear_it =
      76         867 :       _fe_problem.getNonlinearSystemBase(/*nl_sys_num=*/0).getCurrentNonlinearIterationNumber();
      77         867 :   if (number_nonlinear_it == 0)
      78         333 :     _check_temperature_now = true;
      79         867 : }
      80             : 
      81             : template <bool is_ad>
      82             : void
      83     2519500 : GraphiteThermalTempl<is_ad>::computeQpProperties()
      84             : {
      85             :   // select the most conservative calibation range limits to check against:
      86     2519500 :   if (_check_temperature_now)
      87             :   {
      88         133 :     if (_temperature[_qp] < 495.4) // heat capacity calibration
      89          62 :       mooseDoOnce(mooseWarning("The temperature in ",
      90             :                                _name,
      91             :                                " is below the calibration lower range limit at a value of ",
      92             :                                MetaPhysicL::raw_value(_temperature[_qp])));
      93          71 :     else if (_temperature[_qp] > 3312.0) // thermal conductivity calibration range
      94           2 :       mooseError("The temperature in ",
      95           2 :                  _name,
      96             :                  " is above the calibration upper range limit at a value of ",
      97           2 :                  MetaPhysicL::raw_value(_temperature[_qp]));
      98             : 
      99         129 :     _check_temperature_now = false;
     100             :   }
     101             :   // Allow fall through to calculate the thermal material properties
     102     2519496 :   computeThermalConductivity();
     103     2519496 :   computeHeatCapacity();
     104     2519496 : }
     105             : 
     106             : template <bool is_ad>
     107             : void
     108     2519496 : GraphiteThermalTempl<is_ad>::computeThermalConductivity()
     109             : {
     110     5038992 :   _thermal_conductivity[_qp] = -4.418e-12 * Utility::pow<4>(_temperature[_qp]) +
     111     2519496 :                                2.904e-8 * Utility::pow<3>(_temperature[_qp]) -
     112     2519496 :                                4.688e-5 * Utility::pow<2>(_temperature[_qp]) -
     113     2519496 :                                0.0316 * _temperature[_qp] + 119.659; // in W/(m-K)
     114     2519496 :   _thermal_conductivity_dT[_qp] =
     115     2519496 :       4.0 * -4.418e-12 * Utility::pow<3>(MetaPhysicL::raw_value(_temperature[_qp])) +
     116     2519496 :       3.0 * 2.904e-8 * Utility::pow<2>(MetaPhysicL::raw_value(_temperature[_qp])) -
     117     2519496 :       2.0 * 4.688e-5 * MetaPhysicL::raw_value(_temperature[_qp]) - 0.0316; // in W/(m-K)
     118             : 
     119     2519496 :   _thermal_conductivity[_qp] *= _thermal_conductivity_scale_factor;
     120     2519496 :   _thermal_conductivity_dT[_qp] *= _thermal_conductivity_scale_factor;
     121             : 
     122             :   if (is_ad)
     123     2519496 :     setDerivatives(_thermal_conductivity[_qp], _thermal_conductivity_dT[_qp], _temperature[_qp]);
     124     2519496 : }
     125             : 
     126             : template <bool is_ad>
     127             : void
     128     2519496 : GraphiteThermalTempl<is_ad>::computeHeatCapacity()
     129             : {
     130     2519496 :   const Real nonad_temperature = MetaPhysicL::raw_value(_temperature[_qp]);
     131             : 
     132     2519496 :   if (nonad_temperature < 2004)
     133             :   {
     134     5034168 :     _heat_capacity[_qp] = 3.852e-7 * Utility::pow<3>(_temperature[_qp]) -
     135     2517084 :                           1.921e-3 * Utility::pow<2>(_temperature[_qp]) +
     136     5034168 :                           3.318 * _temperature[_qp] + 16.282; // in J/(K-kg)
     137     2517084 :     _heat_capacity_dT[_qp] = 3.852e-7 * 3.0 * Utility::pow<2>(nonad_temperature) -
     138     2517084 :                              1.921e-3 * 2.0 * nonad_temperature + 3.318;
     139             :   }
     140             :   else
     141             :   {
     142        4824 :     _heat_capacity[_qp] = 5.878e-2 * _temperature[_qp] + 1931.166; // in J/(K-kg)
     143        2412 :     _heat_capacity_dT[_qp] = 5.878e-2;
     144             :   }
     145             : 
     146     2519496 :   _heat_capacity[_qp] *= _heat_capacity_scale_factor;
     147     2519496 :   _heat_capacity_dT[_qp] *= _heat_capacity_scale_factor;
     148             : 
     149             :   if (is_ad)
     150     2519496 :     setDerivatives(_heat_capacity[_qp], _heat_capacity_dT[_qp], _temperature[_qp]);
     151     2519496 : }
     152             : 
     153             : template class GraphiteThermalTempl<false>;
     154             : template class GraphiteThermalTempl<true>;

Generated by: LCOV version 1.14