LCOV - code coverage report
Current view: top level - src/materials - RankTwoInvariant.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #31405 (292dce) with base fef103 Lines: 35 37 94.6 %
Date: 2025-09-04 07:57:23 Functions: 7 8 87.5 %
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 "RankTwoInvariant.h"
      11             : #include "RankTwoScalarTools.h"
      12             : 
      13             : #include "metaphysicl/raw_type.h"
      14             : 
      15             : registerMooseObject("SolidMechanicsApp", RankTwoInvariant);
      16             : registerMooseObject("SolidMechanicsApp", ADRankTwoInvariant);
      17             : 
      18             : template <bool is_ad>
      19             : InputParameters
      20        6984 : RankTwoInvariantTempl<is_ad>::validParams()
      21             : {
      22        6984 :   InputParameters params = Material::validParams();
      23        6984 :   params.addClassDescription("Compute a invariant property of a RankTwoTensor");
      24       13968 :   params.addRequiredParam<MaterialPropertyName>("rank_two_tensor",
      25             :                                                 "The rank two material tensor name");
      26       13968 :   params.addRequiredParam<MaterialPropertyName>(
      27             :       "property_name", "Name of the material property computed by this model");
      28       13968 :   MooseEnum mixedInvariants(
      29             :       "VonMisesStress EffectiveStrain Hydrostatic L2norm VolumetricStrain FirstInvariant "
      30             :       "SecondInvariant ThirdInvariant TriaxialityStress MaxShear StressIntensity MaxPrincipal "
      31             :       "MidPrincipal MinPrincipal");
      32             : 
      33       13968 :   params.addParam<MooseEnum>("invariant", mixedInvariants, "Type of invariant output");
      34             : 
      35        6984 :   return params;
      36        6984 : }
      37             : 
      38             : template <bool is_ad>
      39        5238 : RankTwoInvariantTempl<is_ad>::RankTwoInvariantTempl(const InputParameters & parameters)
      40             :   : Material(parameters),
      41        5238 :     _invariant(
      42       10476 :         getParam<MooseEnum>("invariant").template getEnum<RankTwoScalarTools::InvariantType>()),
      43        5238 :     _stateful(_invariant == RankTwoScalarTools::InvariantType::EffectiveStrain),
      44        5238 :     _tensor(getGenericMaterialProperty<RankTwoTensor, is_ad>("rank_two_tensor")),
      45        5259 :     _tensor_old(_stateful ? &getMaterialPropertyOld<RankTwoTensor>("rank_two_tensor") : nullptr),
      46       10476 :     _property(declareGenericProperty<Real, is_ad>("property_name")),
      47       10497 :     _property_old(_stateful ? &getMaterialPropertyOld<Real>("property_name") : nullptr)
      48             : {
      49        5238 : }
      50             : 
      51             : template <bool is_ad>
      52             : void
      53          80 : RankTwoInvariantTempl<is_ad>::initQpStatefulProperties()
      54             : {
      55          80 :   _property[_qp] = 0.0;
      56          80 : }
      57             : 
      58             : template <bool is_ad>
      59             : void
      60    44502884 : RankTwoInvariantTempl<is_ad>::computeQpProperties()
      61             : {
      62    44502884 :   switch (_invariant)
      63             :   {
      64             :     case RankTwoScalarTools::InvariantType::MaxPrincipal:
      65             :     case RankTwoScalarTools::InvariantType::MidPrincipal:
      66             :     case RankTwoScalarTools::InvariantType::MinPrincipal:
      67             :     {
      68             :       Point dummy_direction;
      69      110808 :       _property[_qp] = RankTwoScalarTools::getPrincipalComponent(
      70      110808 :           MetaPhysicL::raw_value(_tensor[_qp]), _invariant, dummy_direction);
      71             :       break;
      72             :     }
      73             : 
      74    44391100 :     case RankTwoScalarTools::InvariantType::VonMisesStress:
      75             :     case RankTwoScalarTools::InvariantType::Hydrostatic:
      76             :     case RankTwoScalarTools::InvariantType::L2norm:
      77             :     case RankTwoScalarTools::InvariantType::VolumetricStrain:
      78             :     case RankTwoScalarTools::InvariantType::FirstInvariant:
      79             :     case RankTwoScalarTools::InvariantType::SecondInvariant:
      80             :     case RankTwoScalarTools::InvariantType::ThirdInvariant:
      81             :     case RankTwoScalarTools::InvariantType::TriaxialityStress:
      82             :     case RankTwoScalarTools::InvariantType::MaxShear:
      83             :     case RankTwoScalarTools::InvariantType::StressIntensity:
      84             :     {
      85    44391100 :       _property[_qp] =
      86    44391100 :           RankTwoScalarTools::getInvariant(MetaPhysicL::raw_value(_tensor[_qp]), _invariant);
      87    44391100 :       break;
      88             :     }
      89             : 
      90         976 :     case RankTwoScalarTools::InvariantType::EffectiveStrain:
      91             :     {
      92             :       mooseAssert(_tensor_old, "The selected invariant requires the input material to be stateful");
      93             :       mooseAssert(_property_old,
      94             :                   "The selected invariant requires the output material to be stateful");
      95        1952 :       _property[_qp] = (*_property_old)[_qp] + RankTwoScalarTools::effectiveStrain(
      96         976 :                                                    MetaPhysicL::raw_value(_tensor[_qp]) -
      97         976 :                                                    MetaPhysicL::raw_value((*_tensor_old)[_qp]));
      98         976 :       break;
      99             :     }
     100             : 
     101           0 :     default:
     102           0 :       mooseError("Not a recognized invariant for RankTwoInvariant");
     103             :   }
     104    44502884 : }
     105             : 
     106             : template class RankTwoInvariantTempl<false>;
     107             : template class RankTwoInvariantTempl<true>;

Generated by: LCOV version 1.14