LCOV - code coverage report
Current view: top level - src/materials - NonlocalDamage.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: 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 "NonlocalDamage.h"
      11             : 
      12             : registerMooseObject("SolidMechanicsApp", NonlocalDamage);
      13             : registerMooseObject("SolidMechanicsApp", ADNonlocalDamage);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17          48 : NonlocalDamageTempl<is_ad>::validParams()
      18             : {
      19          48 :   InputParameters params = ScalarDamageBaseTempl<is_ad>::validParams();
      20          48 :   params.addClassDescription(
      21             :       "Nonlocal damage model. Given an RadialAverage UO this creates a new damage index that can "
      22             :       "be used as for ComputeDamageStress without havign to change existing local damage models.");
      23          96 :   params.addRequiredParam<UserObjectName>("average_UO", "Radial Average user object");
      24          96 :   params.addRequiredParam<MaterialName>("local_damage_model",
      25             :                                         "Name of the local damage model used to compute "
      26             :                                         "the nonlocal damage index");
      27          48 :   return params;
      28           0 : }
      29             : 
      30             : template <bool is_ad>
      31          36 : NonlocalDamageTempl<is_ad>::NonlocalDamageTempl(const InputParameters & parameters)
      32             :   : ScalarDamageBaseTempl<is_ad>(parameters),
      33             :     GuaranteeConsumer(this),
      34          36 :     _average(this->template getUserObject<RadialAverage>("average_UO").getAverage()),
      35          36 :     _local_damage_model_name(this->template getParam<MaterialName>("local_damage_model")),
      36          36 :     _prev_elem(nullptr)
      37             : {
      38          36 : }
      39             : template <bool is_ad>
      40             : void
      41          36 : NonlocalDamageTempl<is_ad>::initialSetup()
      42             : {
      43          36 :   _local_damage_model = dynamic_cast<ScalarDamageBaseTempl<is_ad> *>(
      44          36 :       &this->getMaterialByName(_local_damage_model_name));
      45             : 
      46          36 :   if (!_local_damage_model)
      47           0 :     this->paramError("damage_model",
      48             :                      "Damage Model " + _local_damage_model_name +
      49             :                          " is not compatible with NonlocalDamage model");
      50          36 : }
      51             : 
      52             : template <bool is_ad>
      53             : void
      54       16000 : NonlocalDamageTempl<is_ad>::initQpStatefulProperties()
      55             : {
      56        8000 :   ScalarDamageBaseTempl<is_ad>::initQpStatefulProperties();
      57       16000 : }
      58             : 
      59             : template <bool is_ad>
      60             : void
      61     2118000 : NonlocalDamageTempl<is_ad>::updateQpDamageIndex()
      62             : {
      63             :   // First update underlying local damage model
      64     2118000 :   _local_damage_model->getQpDamageIndex(_qp);
      65             :   // Now update the nonlocal damage model
      66             :   // Only update iterator when we change to another element. This is for
      67             :   // computational costs related to map lookup.
      68     2118000 :   if (_prev_elem != _current_elem)
      69             :   {
      70      264750 :     _average_damage = _average.find(_current_elem->id());
      71      264750 :     _prev_elem = _current_elem;
      72             :   }
      73             :   // Check that we found the new element
      74     2118000 :   if (_average_damage != _average.end())
      75             :     // return max of the old damage or new average damage
      76     2110000 :     _damage_index[_qp] = std::max(_average_damage->second[_qp], _damage_index_old[_qp]);
      77             :   else
      78             :     // during startup the map is not made yet or
      79             :     // if AMR is used then the new element will not be found but it should
      80             :     // already have an old nonlocal damage value that needs to perserved
      81        8000 :     _damage_index[_qp] = std::max(0.0, _damage_index_old[_qp]);
      82     2118000 : }
      83             : 
      84             : template class NonlocalDamageTempl<false>;
      85             : template class NonlocalDamageTempl<true>;

Generated by: LCOV version 1.14