LCOV - code coverage report
Current view: top level - src/materials - StrainEnergyRateDensity.C (source / functions) Hit Total Coverage
Test: idaholab/moose tensor_mechanics: d6b47a Lines: 30 31 96.8 %
Date: 2024-02-27 11:53:14 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://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 "StrainEnergyRateDensity.h"
      11             : #include "RankTwoTensor.h"
      12             : #include "MooseMesh.h"
      13             : 
      14             : registerMooseObject("TensorMechanicsApp", StrainEnergyRateDensity);
      15             : registerMooseObject("TensorMechanicsApp", ADStrainEnergyRateDensity);
      16             : 
      17             : template <bool is_ad>
      18             : InputParameters
      19         121 : StrainEnergyRateDensityTempl<is_ad>::validParams()
      20             : {
      21         121 :   InputParameters params = Material::validParams();
      22         121 :   params.addClassDescription("Computes the strain energy density rate using a combination of the "
      23             :                              "elastic and inelastic components of the strain increment, which is a "
      24             :                              "valid assumption for monotonic behavior.");
      25         242 :   params.addParam<std::string>("base_name",
      26             :                                "Optional parameter that allows the user to define "
      27             :                                "multiple mechanics material systems on the same "
      28             :                                "block, i.e. for multiple phases");
      29         242 :   params.addRequiredRangeCheckedParam<std::vector<MaterialName>>(
      30             :       "inelastic_models",
      31             :       "inelastic_models_size=1",
      32             :       "The material objects to use to calculate the strain energy rate density.");
      33         121 :   return params;
      34           0 : }
      35             : 
      36             : template <bool is_ad>
      37          90 : StrainEnergyRateDensityTempl<is_ad>::StrainEnergyRateDensityTempl(
      38             :     const InputParameters & parameters)
      39             :   : DerivativeMaterialInterface<Material>(parameters),
      40          90 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      41          90 :     _strain_energy_rate_density(declareProperty<Real>(_base_name + "strain_energy_rate_density")),
      42          90 :     _stress(getGenericMaterialProperty<RankTwoTensor, is_ad>(_base_name + "stress")),
      43          90 :     _strain_rate(getGenericMaterialProperty<RankTwoTensor, is_ad>(_base_name + "strain_rate")),
      44         270 :     _num_models(getParam<std::vector<MaterialName>>("inelastic_models").size())
      45             : {
      46          90 : }
      47             : 
      48             : template <bool is_ad>
      49             : void
      50          90 : StrainEnergyRateDensityTempl<is_ad>::initialSetup()
      51             : {
      52         180 :   std::vector<MaterialName> models = getParam<std::vector<MaterialName>>("inelastic_models");
      53             : 
      54             :   // Store inelastic models as generic StressUpdateBase.
      55         180 :   for (unsigned int i = 0; i < _num_models; ++i)
      56             :   {
      57          90 :     GenericStressUpdateBase<is_ad> * inelastic_model_stress_update =
      58          90 :         dynamic_cast<GenericStressUpdateBase<is_ad> *>(&getMaterialByName(models[i]));
      59             : 
      60          90 :     if (inelastic_model_stress_update)
      61          90 :       _inelastic_models.push_back(inelastic_model_stress_update);
      62             :   }
      63          90 : }
      64             : 
      65             : template <bool is_ad>
      66             : void
      67        7384 : StrainEnergyRateDensityTempl<is_ad>::initQpStatefulProperties()
      68             : {
      69        7384 :   _strain_energy_rate_density[_qp] = 0.0;
      70        7384 : }
      71             : 
      72             : template <bool is_ad>
      73             : void
      74      263432 : StrainEnergyRateDensityTempl<is_ad>::computeQpProperties()
      75             : {
      76      526864 :   for (unsigned int i = 0; i < _inelastic_models.size(); ++i)
      77             :   {
      78      263432 :     _inelastic_models[i]->setQp(_qp);
      79      263432 :     _strain_energy_rate_density[_qp] = MetaPhysicL::raw_value(
      80      263432 :         _inelastic_models[i]->computeStrainEnergyRateDensity(_stress, _strain_rate));
      81             :   }
      82      263432 : }

Generated by: LCOV version 1.14