LCOV - code coverage report
Current view: top level - src/materials - ScalarDamageBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 54 55 98.2 %
Date: 2025-07-25 05:00:39 Functions: 17 18 94.4 %
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 "ScalarDamageBase.h"
      11             : #include "MooseUtils.h"
      12             : 
      13             : template <bool is_ad>
      14             : InputParameters
      15         968 : ScalarDamageBaseTempl<is_ad>::validParams()
      16             : {
      17         968 :   InputParameters params = DamageBaseTempl<is_ad>::validParams();
      18         968 :   params.addClassDescription("Base class for damage model based on a scalar damage parameter");
      19        1936 :   params.addParam<bool>(
      20             :       "use_old_damage",
      21        1936 :       false,
      22             :       "Whether to use the damage index from the previous step in the stress computation");
      23        2904 :   params.addRangeCheckedParam<Real>(
      24             :       "residual_stiffness_fraction",
      25        1936 :       1.e-8,
      26             :       "residual_stiffness_fraction>=0 & residual_stiffness_fraction<1",
      27             :       "Minimum fraction of original material stiffness retained for fully "
      28             :       "damaged material (when damage_index=1)");
      29        2904 :   params.addRangeCheckedParam<Real>(
      30             :       "maximum_damage_increment",
      31        1936 :       0.1,
      32             :       "maximum_damage_increment>0 & maximum_damage_increment<1",
      33             :       "maximum damage increment allowed for simulations with adaptive time step");
      34        2904 :   params.addRangeCheckedParam<Real>("maximum_damage",
      35        1936 :                                     1.0,
      36             :                                     "maximum_damage>=0 & maximum_damage<=1",
      37             :                                     "Maximum value allowed for damage index");
      38        1936 :   params.addParam<MaterialPropertyName>(
      39             :       "damage_index_name",
      40             :       "damage_index",
      41             :       "name of the material property where the damage index is stored");
      42         968 :   return params;
      43           0 : }
      44             : 
      45             : template <bool is_ad>
      46         726 : ScalarDamageBaseTempl<is_ad>::ScalarDamageBaseTempl(const InputParameters & parameters)
      47             :   : DamageBaseTempl<is_ad>(parameters),
      48        1452 :     _damage_index_name(this->template getParam<MaterialPropertyName>("damage_index_name")),
      49         726 :     _damage_index(
      50         726 :         this->template declareGenericPropertyByName<Real, is_ad>(_base_name + _damage_index_name)),
      51        1452 :     _damage_index_old(this->template getMaterialPropertyOld<Real>(_base_name + _damage_index_name)),
      52         726 :     _damage_index_older(
      53         726 :         this->template getMaterialPropertyOlder<Real>(_base_name + _damage_index_name)),
      54        1452 :     _use_old_damage(this->template getParam<bool>("use_old_damage")),
      55        1452 :     _residual_stiffness_fraction(this->template getParam<Real>("residual_stiffness_fraction")),
      56        1452 :     _maximum_damage_increment(this->template getParam<Real>("maximum_damage_increment")),
      57        2178 :     _maximum_damage(this->template getParam<Real>("maximum_damage"))
      58             : {
      59         726 : }
      60             : 
      61             : template <bool is_ad>
      62             : void
      63       25536 : ScalarDamageBaseTempl<is_ad>::initQpStatefulProperties()
      64             : {
      65       33536 :   _damage_index[_qp] = 0.0;
      66       25536 : }
      67             : 
      68             : template <bool is_ad>
      69             : const GenericReal<is_ad> &
      70     2118000 : ScalarDamageBaseTempl<is_ad>::getQpDamageIndex(unsigned int qp)
      71             : {
      72             :   setQp(qp);
      73     2140016 :   updateDamage();
      74     2140016 :   return _damage_index[_qp];
      75             : }
      76             : 
      77             : template <bool is_ad>
      78             : void
      79     4463012 : ScalarDamageBaseTempl<is_ad>::updateDamage()
      80             : {
      81     4463012 :   updateQpDamageIndex();
      82     4463008 :   _damage_index[_qp] = std::min(_maximum_damage, _damage_index[_qp]);
      83     4463008 : }
      84             : 
      85             : template <bool is_ad>
      86             : void
      87     2322992 : ScalarDamageBaseTempl<is_ad>::updateStressForDamage(GenericRankTwoTensor<is_ad> & stress_new)
      88             : {
      89             :   // Avoid multiplying by a small negative number, which could occur if damage_index
      90             :   // is slightly greater than 1.0
      91     2322992 :   stress_new *=
      92     2322992 :       std::max((1.0 - (_use_old_damage ? _damage_index_old[_qp] : _damage_index[_qp])), 0.0);
      93     2322992 : }
      94             : 
      95             : template <bool is_ad>
      96             : void
      97        9920 : ScalarDamageBaseTempl<is_ad>::computeUndamagedOldStress(RankTwoTensor & stress_old)
      98             : {
      99        9920 :   Real damage_index_old =
     100        9920 :       std::max((1.0 - (_use_old_damage ? _damage_index_older[_qp] : _damage_index_old[_qp])), 0.0);
     101             : 
     102        9920 :   if (damage_index_old > 0.0)
     103        9920 :     stress_old /= damage_index_old;
     104        9920 : }
     105             : 
     106             : template <bool is_ad>
     107             : void
     108     1364848 : ScalarDamageBaseTempl<is_ad>::updateJacobianMultForDamage(RankFourTensor & jacobian_mult)
     109             : {
     110     1382488 :   jacobian_mult *= std::max((1.0 - (_use_old_damage ? _damage_index_old[_qp]
     111     1187568 :                                                     : MetaPhysicL::raw_value(_damage_index[_qp]))),
     112     1364848 :                             _residual_stiffness_fraction);
     113     1364848 : }
     114             : 
     115             : template <bool is_ad>
     116             : Real
     117     2322992 : ScalarDamageBaseTempl<is_ad>::computeTimeStepLimit()
     118             : {
     119             :   Real current_damage_increment =
     120     2322992 :       (MetaPhysicL::raw_value(_damage_index[_qp]) - _damage_index_old[_qp]);
     121     2322992 :   if (MooseUtils::absoluteFuzzyEqual(current_damage_increment, 0.0))
     122             :     return std::numeric_limits<Real>::max();
     123             : 
     124     1773304 :   return _dt * _maximum_damage_increment / current_damage_increment;
     125             : }
     126             : 
     127             : template class ScalarDamageBaseTempl<false>;
     128             : template class ScalarDamageBaseTempl<true>;

Generated by: LCOV version 1.14