LCOV - code coverage report
Current view: top level - src/materials - CombinedScalarDamage.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 35 36 97.2 %
Date: 2025-07-25 05:00:39 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         192 : CombinedScalarDamageTempl<is_ad>::validParams()
      18             : {
      19         192 :   InputParameters params = ScalarDamageBaseTempl<is_ad>::validParams();
      20             : 
      21         192 :   params.addClassDescription(
      22             :       "Scalar damage model which is computed as a function of multiple scalar damage models");
      23             : 
      24         384 :   params.addRequiredParam<std::vector<MaterialName>>("damage_models",
      25             :                                                      "Name of the damage models used to compute "
      26             :                                                      "the damage index");
      27             : 
      28         384 :   MooseEnum combination_type("Maximum Product", "Maximum");
      29         384 :   params.addParam<MooseEnum>(
      30             :       "combination_type", combination_type, "How the damage models are combined");
      31             : 
      32         192 :   return params;
      33         192 : }
      34             : 
      35             : template <bool is_ad>
      36         144 : CombinedScalarDamageTempl<is_ad>::CombinedScalarDamageTempl(const InputParameters & parameters)
      37             :   : ScalarDamageBaseTempl<is_ad>(parameters),
      38         144 :     _combination_type(
      39         288 :         this->template getParam<MooseEnum>("combination_type").template getEnum<CombinationType>()),
      40         576 :     _damage_models_names(this->template getParam<std::vector<MaterialName>>("damage_models"))
      41             : {
      42         144 : }
      43             : 
      44             : template <bool is_ad>
      45             : void
      46         144 : CombinedScalarDamageTempl<is_ad>::initialSetup()
      47             : {
      48         432 :   for (unsigned int i = 0; i < _damage_models_names.size(); ++i)
      49             :   {
      50         288 :     ScalarDamageBaseTempl<is_ad> * model = dynamic_cast<ScalarDamageBaseTempl<is_ad> *>(
      51         288 :         &this->getMaterialByName(_damage_models_names[i]));
      52             : 
      53         288 :     if (model)
      54         288 :       _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         144 : }
      61             : 
      62             : template <bool is_ad>
      63             : void
      64       11008 : CombinedScalarDamageTempl<is_ad>::updateQpDamageIndex()
      65             : {
      66       11008 :   switch (_combination_type)
      67             :   {
      68        8256 :     case CombinationType::Maximum:
      69        8256 :       _damage_index[_qp] = _damage_index_old[_qp];
      70       24768 :       for (unsigned int i = 0; i < _damage_models.size(); ++i)
      71       20736 :         _damage_index[_qp] = std::max(_damage_index[_qp], _damage_models[i]->getQpDamageIndex(_qp));
      72             :       break;
      73        2752 :     case CombinationType::Product:
      74        2752 :       _damage_index[_qp] = 1.0;
      75        8256 :       for (unsigned int i = 0; i < _damage_models.size(); ++i)
      76        8128 :         _damage_index[_qp] *= 1.0 - _damage_models[i]->getQpDamageIndex(_qp);
      77        4064 :       _damage_index[_qp] = 1.0 - _damage_index[_qp];
      78        2752 :       break;
      79             :   }
      80             : 
      81       16256 :   _damage_index[_qp] =
      82       22528 :       std::max(_damage_index_old[_qp], std::max(0.0, std::min(1.0, _damage_index[_qp])));
      83       11008 : }

Generated by: LCOV version 1.14