LCOV - code coverage report
Current view: top level - src/materials - ScalarDamageBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose tensor_mechanics: d6b47a Lines: 54 55 98.2 %
Date: 2024-02-27 11:53:14 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://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 "ScalarDamageBase.h"
      11             : #include "MooseUtils.h"
      12             : 
      13             : template <bool is_ad>
      14             : InputParameters
      15         484 : ScalarDamageBaseTempl<is_ad>::validParams()
      16             : {
      17         484 :   InputParameters params = DamageBaseTempl<is_ad>::validParams();
      18         484 :   params.addClassDescription("Base class for damage model based on a scalar damage parameter");
      19         968 :   params.addParam<bool>(
      20             :       "use_old_damage",
      21         968 :       false,
      22             :       "Whether to use the damage index from the previous step in the stress computation");
      23        1452 :   params.addRangeCheckedParam<Real>(
      24             :       "residual_stiffness_fraction",
      25         968 :       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        1452 :   params.addRangeCheckedParam<Real>(
      30             :       "maximum_damage_increment",
      31         968 :       0.1,
      32             :       "maximum_damage_increment>0 & maximum_damage_increment<1",
      33             :       "maximum damage increment allowed for simulations with adaptive time step");
      34        1452 :   params.addRangeCheckedParam<Real>("maximum_damage",
      35         968 :                                     1.0,
      36             :                                     "maximum_damage>=0 & maximum_damage<=1",
      37             :                                     "Maximum value allowed for damage index");
      38         968 :   params.addParam<MaterialPropertyName>(
      39             :       "damage_index_name",
      40             :       "damage_index",
      41             :       "name of the material property where the damage index is stored");
      42         484 :   return params;
      43           0 : }
      44             : 
      45             : template <bool is_ad>
      46         363 : ScalarDamageBaseTempl<is_ad>::ScalarDamageBaseTempl(const InputParameters & parameters)
      47             :   : DamageBaseTempl<is_ad>(parameters),
      48         726 :     _damage_index_name(this->template getParam<MaterialPropertyName>("damage_index_name")),
      49         363 :     _damage_index(
      50         363 :         this->template declareGenericPropertyByName<Real, is_ad>(_base_name + _damage_index_name)),
      51         726 :     _damage_index_old(this->template getMaterialPropertyOld<Real>(_base_name + _damage_index_name)),
      52         363 :     _damage_index_older(
      53         363 :         this->template getMaterialPropertyOlder<Real>(_base_name + _damage_index_name)),
      54         726 :     _use_old_damage(this->template getParam<bool>("use_old_damage")),
      55         726 :     _residual_stiffness_fraction(this->template getParam<Real>("residual_stiffness_fraction")),
      56         726 :     _maximum_damage_increment(this->template getParam<Real>("maximum_damage_increment")),
      57        1089 :     _maximum_damage(this->template getParam<Real>("maximum_damage"))
      58             : {
      59         363 : }
      60             : 
      61             : template <bool is_ad>
      62             : void
      63       13696 : ScalarDamageBaseTempl<is_ad>::initQpStatefulProperties()
      64             : {
      65       17696 :   _damage_index[_qp] = 0.0;
      66       13696 : }
      67             : 
      68             : template <bool is_ad>
      69             : const GenericReal<is_ad> &
      70     1080000 : ScalarDamageBaseTempl<is_ad>::getQpDamageIndex(unsigned int qp)
      71             : {
      72             :   setQp(qp);
      73     1093824 :   updateDamage();
      74     1093824 :   return _damage_index[_qp];
      75             : }
      76             : 
      77             : template <bool is_ad>
      78             : void
      79     2283322 : ScalarDamageBaseTempl<is_ad>::updateDamage()
      80             : {
      81     2283322 :   updateQpDamageIndex();
      82     2283320 :   _damage_index[_qp] = std::min(_maximum_damage, _damage_index[_qp]);
      83     2283320 : }
      84             : 
      85             : template <bool is_ad>
      86             : void
      87     1189496 : 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     1189496 :   stress_new *=
      92     1189496 :       std::max((1.0 - (_use_old_damage ? _damage_index_old[_qp] : _damage_index[_qp])), 0.0);
      93     1189496 : }
      94             : 
      95             : template <bool is_ad>
      96             : void
      97        5488 : ScalarDamageBaseTempl<is_ad>::computeUndamagedOldStress(RankTwoTensor & stress_old)
      98             : {
      99        5488 :   Real damage_index_old =
     100        5488 :       std::max((1.0 - (_use_old_damage ? _damage_index_older[_qp] : _damage_index_old[_qp])), 0.0);
     101             : 
     102        5488 :   if (damage_index_old > 0.0)
     103        5488 :     stress_old /= damage_index_old;
     104        5488 : }
     105             : 
     106             : template <bool is_ad>
     107             : void
     108      699104 : ScalarDamageBaseTempl<is_ad>::updateJacobianMultForDamage(RankFourTensor & jacobian_mult)
     109             : {
     110      709824 :   jacobian_mult *= std::max((1.0 - (_use_old_damage ? _damage_index_old[_qp]
     111      606224 :                                                     : MetaPhysicL::raw_value(_damage_index[_qp]))),
     112      699104 :                             _residual_stiffness_fraction);
     113      699104 : }
     114             : 
     115             : template <bool is_ad>
     116             : Real
     117     1189496 : ScalarDamageBaseTempl<is_ad>::computeTimeStepLimit()
     118             : {
     119             :   Real current_damage_increment =
     120     1189496 :       (MetaPhysicL::raw_value(_damage_index[_qp]) - _damage_index_old[_qp]);
     121     1189496 :   if (MooseUtils::absoluteFuzzyEqual(current_damage_increment, 0.0))
     122             :     return std::numeric_limits<Real>::max();
     123             : 
     124      907688 :   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