LCOV - code coverage report
Current view: top level - src/materials - CombinedScalarDamage.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #31613 (c7d555) with base 7323e9 Lines: 34 35 97.1 %
Date: 2025-11-06 14:18:25 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 "CombinedScalarDamage.h"
      11             : 
      12             : registerMooseObject("SolidMechanicsApp", CombinedScalarDamage);
      13             : registerMooseObject("SolidMechanicsApp", ADCombinedScalarDamage);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17         224 : CombinedScalarDamageTempl<is_ad>::validParams()
      18             : {
      19         224 :   InputParameters params = ScalarDamageBaseTempl<is_ad>::validParams();
      20             : 
      21         224 :   params.addClassDescription(
      22             :       "Scalar damage model which is computed as a function of multiple scalar damage models");
      23             : 
      24         448 :   params.addRequiredParam<std::vector<MaterialName>>("damage_models",
      25             :                                                      "Name of the damage models used to compute "
      26             :                                                      "the damage index");
      27             : 
      28         448 :   MooseEnum combination_type("Maximum Product", "Maximum");
      29         448 :   params.addParam<MooseEnum>(
      30             :       "combination_type", combination_type, "How the damage models are combined");
      31             : 
      32         224 :   return params;
      33         224 : }
      34             : 
      35             : template <bool is_ad>
      36         168 : CombinedScalarDamageTempl<is_ad>::CombinedScalarDamageTempl(const InputParameters & parameters)
      37             :   : ScalarDamageBaseTempl<is_ad>(parameters),
      38         168 :     _combination_type(
      39         336 :         this->template getParam<MooseEnum>("combination_type").template getEnum<CombinationType>()),
      40         672 :     _damage_models_names(this->template getParam<std::vector<MaterialName>>("damage_models"))
      41             : {
      42         168 : }
      43             : 
      44             : template <bool is_ad>
      45             : void
      46         168 : CombinedScalarDamageTempl<is_ad>::initialSetup()
      47             : {
      48         504 :   for (unsigned int i = 0; i < _damage_models_names.size(); ++i)
      49             :   {
      50         336 :     ScalarDamageBaseTempl<is_ad> * model = dynamic_cast<ScalarDamageBaseTempl<is_ad> *>(
      51         336 :         &this->getMaterialByName(_damage_models_names[i]));
      52             : 
      53         336 :     if (model)
      54         336 :       _damage_models.push_back(model);
      55             :     else
      56           0 :       this->paramError("damage_model",
      57             :                        "Damage Model " + _damage_models_names[i] +
      58             :                            " is not compatible with CombinedScalarDamage");
      59             :   }
      60         168 : }
      61             : 
      62             : template <bool is_ad>
      63             : void
      64       13952 : CombinedScalarDamageTempl<is_ad>::updateQpDamageIndex()
      65             : {
      66             :   using std::max, std::min;
      67             : 
      68       13952 :   switch (_combination_type)
      69             :   {
      70       10464 :     case CombinationType::Maximum:
      71       10464 :       _damage_index[_qp] = _damage_index_old[_qp];
      72       31392 :       for (unsigned int i = 0; i < _damage_models.size(); ++i)
      73       26280 :         _damage_index[_qp] = max(_damage_index[_qp], _damage_models[i]->getQpDamageIndex(_qp));
      74             :       break;
      75        3488 :     case CombinationType::Product:
      76        3488 :       _damage_index[_qp] = 1.0;
      77       10464 :       for (unsigned int i = 0; i < _damage_models.size(); ++i)
      78       10304 :         _damage_index[_qp] *= 1.0 - _damage_models[i]->getQpDamageIndex(_qp);
      79        5152 :       _damage_index[_qp] = 1.0 - _damage_index[_qp];
      80        3488 :       break;
      81             :   }
      82             : 
      83       28544 :   _damage_index[_qp] = max(_damage_index_old[_qp], max(0.0, min(1.0, _damage_index[_qp])));
      84       13952 : }

Generated by: LCOV version 1.14