LCOV - code coverage report
Current view: top level - src/materials - IsotropicPlasticityStressUpdate.C (source / functions) Hit Total Coverage
Test: idaholab/moose tensor_mechanics: d6b47a Lines: 81 94 86.2 %
Date: 2024-02-27 11:53:14 Functions: 18 24 75.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 "IsotropicPlasticityStressUpdate.h"
      11             : 
      12             : #include "Function.h"
      13             : #include "ElasticityTensorTools.h"
      14             : 
      15             : registerMooseObject("TensorMechanicsApp", ADIsotropicPlasticityStressUpdate);
      16             : registerMooseObject("TensorMechanicsApp", IsotropicPlasticityStressUpdate);
      17             : 
      18             : template <bool is_ad>
      19             : InputParameters
      20         216 : IsotropicPlasticityStressUpdateTempl<is_ad>::validParams()
      21             : {
      22         216 :   InputParameters params = RadialReturnStressUpdateTempl<is_ad>::validParams();
      23         216 :   params.addClassDescription("This class uses the discrete material in a radial return isotropic "
      24             :                              "plasticity model.  This class is one of the basic radial return "
      25             :                              "constitutive models, yet it can be used in conjunction with other "
      26             :                              "creep and plasticity materials for more complex simulations.");
      27             :   // Linear strain hardening parameters
      28         432 :   params.addParam<FunctionName>("yield_stress_function",
      29             :                                 "Yield stress as a function of temperature");
      30         432 :   params.addParam<Real>("yield_stress", "The point at which plastic strain begins accumulating");
      31         432 :   params.addParam<FunctionName>("hardening_function",
      32             :                                 "True stress as a function of plastic strain");
      33         432 :   params.addParam<Real>("hardening_constant", "Hardening slope");
      34         432 :   params.addCoupledVar("temperature", 0.0, "Coupled Temperature");
      35         432 :   params.addDeprecatedParam<std::string>(
      36             :       "plastic_prepend",
      37             :       "",
      38             :       "String that is prepended to the plastic_strain Material Property",
      39             :       "This has been replaced by the 'base_name' parameter");
      40         216 :   params.set<std::string>("effective_inelastic_strain_name") = "effective_plastic_strain";
      41             : 
      42         216 :   return params;
      43           0 : }
      44             : 
      45             : template <bool is_ad>
      46         163 : IsotropicPlasticityStressUpdateTempl<is_ad>::IsotropicPlasticityStressUpdateTempl(
      47             :     const InputParameters & parameters)
      48             :   : RadialReturnStressUpdateTempl<is_ad>(parameters),
      49         163 :     _plastic_prepend(this->template getParam<std::string>("plastic_prepend")),
      50         163 :     _yield_stress_function(this->isParamValid("yield_stress_function")
      51         163 :                                ? &this->getFunction("yield_stress_function")
      52             :                                : nullptr),
      53         650 :     _yield_stress(this->isParamValid("yield_stress") ? this->template getParam<Real>("yield_stress")
      54             :                                                      : 0),
      55         163 :     _hardening_constant(this->isParamValid("hardening_constant")
      56         435 :                             ? this->template getParam<Real>("hardening_constant")
      57             :                             : 0),
      58         163 :     _hardening_function(this->isParamValid("hardening_function")
      59         190 :                             ? &this->getFunction("hardening_function")
      60             :                             : nullptr),
      61         163 :     _yield_condition(-1.0), // set to a non-physical value to catch uninitalized yield condition
      62         163 :     _hardening_slope(0.0),
      63         163 :     _plastic_strain(this->template declareGenericProperty<RankTwoTensor, is_ad>(
      64         163 :         _base_name + _plastic_prepend + "plastic_strain")),
      65         326 :     _plastic_strain_old(this->template getMaterialPropertyOld<RankTwoTensor>(
      66             :         _base_name + _plastic_prepend + "plastic_strain")),
      67         163 :     _hardening_variable(
      68         163 :         this->template declareGenericProperty<Real, is_ad>(_base_name + "hardening_variable")),
      69         163 :     _hardening_variable_old(
      70         163 :         this->template getMaterialPropertyOld<Real>(_base_name + "hardening_variable")),
      71         326 :     _temperature(this->template coupledGenericValue<is_ad>("temperature"))
      72             : {
      73         326 :   if (parameters.isParamSetByUser("yield_stress") && _yield_stress <= 0.0)
      74           1 :     mooseError("Yield stress must be greater than zero");
      75             : 
      76             :   // Both of these parameters are given default values by derived classes, which makes them valid
      77         647 :   if (_yield_stress_function == nullptr && !this->isParamValid("yield_stress"))
      78           1 :     mooseError("Either yield_stress or yield_stress_function must be given");
      79         235 :   if (!parameters.isParamValid("hardening_constant") && !this->isParamValid("hardening_function"))
      80           1 :     mooseError("Either hardening_constant or hardening_function must be defined");
      81             : 
      82         396 :   if (parameters.isParamSetByUser("hardening_constant") && this->isParamValid("hardening_function"))
      83           1 :     mooseError(
      84             :         "Only the hardening_constant or only the hardening_function can be defined but not both");
      85         159 : }
      86             : 
      87             : template <bool is_ad>
      88             : void
      89         576 : IsotropicPlasticityStressUpdateTempl<is_ad>::initQpStatefulProperties()
      90             : {
      91         576 :   _hardening_variable[_qp] = 0.0;
      92         576 :   _plastic_strain[_qp].zero();
      93         576 : }
      94             : 
      95             : template <bool is_ad>
      96             : void
      97           0 : IsotropicPlasticityStressUpdateTempl<is_ad>::propagateQpStatefulProperties()
      98             : {
      99           0 :   _hardening_variable[_qp] = _hardening_variable_old[_qp];
     100           0 :   _plastic_strain[_qp] = _plastic_strain_old[_qp];
     101             : 
     102           0 :   RadialReturnStressUpdateTempl<is_ad>::propagateQpStatefulPropertiesRadialReturn();
     103           0 : }
     104             : 
     105             : template <bool is_ad>
     106             : void
     107     2789742 : IsotropicPlasticityStressUpdateTempl<is_ad>::computeStressInitialize(
     108             :     const GenericReal<is_ad> & effective_trial_stress,
     109             :     const GenericRankFourTensor<is_ad> & elasticity_tensor)
     110             : {
     111           0 :   RadialReturnStressUpdateTempl<is_ad>::computeStressInitialize(effective_trial_stress,
     112             :                                                                 elasticity_tensor);
     113             : 
     114     2789742 :   computeYieldStress(elasticity_tensor);
     115             : 
     116     2789742 :   _yield_condition = effective_trial_stress - _hardening_variable_old[_qp] - _yield_stress;
     117     2789742 :   _hardening_variable[_qp] = _hardening_variable_old[_qp];
     118     2789742 :   _plastic_strain[_qp] = _plastic_strain_old[_qp];
     119     2789742 : }
     120             : 
     121             : template <bool is_ad>
     122             : GenericReal<is_ad>
     123     5360146 : IsotropicPlasticityStressUpdateTempl<is_ad>::computeResidual(
     124             :     const GenericReal<is_ad> & effective_trial_stress, const GenericReal<is_ad> & scalar)
     125             : {
     126             :   mooseAssert(_yield_condition != -1.0,
     127             :               "the yield stress was not updated by computeStressInitialize");
     128             : 
     129     5360146 :   if (_yield_condition > 0.0)
     130             :   {
     131     5038366 :     _hardening_slope = computeHardeningDerivative(scalar);
     132     5038366 :     _hardening_variable[_qp] = computeHardeningValue(scalar);
     133             : 
     134     5038366 :     return (effective_trial_stress - _hardening_variable[_qp] - _yield_stress) /
     135     5038366 :                _three_shear_modulus -
     136     5038366 :            scalar;
     137             :   }
     138             : 
     139        5366 :   return 0.0;
     140             : }
     141             : 
     142             : template <bool is_ad>
     143             : GenericReal<is_ad>
     144     5318812 : IsotropicPlasticityStressUpdateTempl<is_ad>::computeDerivative(
     145             :     const GenericReal<is_ad> & /*effective_trial_stress*/, const GenericReal<is_ad> & /*scalar*/)
     146             : {
     147     5318812 :   if (_yield_condition > 0.0)
     148     5024708 :     return -1.0 - _hardening_slope / _three_shear_modulus;
     149             : 
     150        5366 :   return 1.0;
     151             : }
     152             : 
     153             : template <bool is_ad>
     154             : void
     155     2787456 : IsotropicPlasticityStressUpdateTempl<is_ad>::iterationFinalize(const GenericReal<is_ad> & scalar)
     156             : {
     157     2787456 :   if (_yield_condition > 0.0)
     158     2465676 :     _hardening_variable[_qp] = computeHardeningValue(scalar);
     159     2787456 : }
     160             : 
     161             : template <bool is_ad>
     162             : void
     163     2913288 : IsotropicPlasticityStressUpdateTempl<is_ad>::computeStressFinalize(
     164             :     const GenericRankTwoTensor<is_ad> & plastic_strain_increment)
     165             : {
     166     2913288 :   _plastic_strain[_qp] += plastic_strain_increment;
     167     2913288 : }
     168             : 
     169             : template <bool is_ad>
     170             : GenericReal<is_ad>
     171     7432486 : IsotropicPlasticityStressUpdateTempl<is_ad>::computeHardeningValue(
     172             :     const GenericReal<is_ad> & scalar)
     173             : {
     174     7432486 :   if (_hardening_function)
     175             :   {
     176       54944 :     const Real strain_old = this->_effective_inelastic_strain_old[_qp];
     177       54944 :     return _hardening_function->value(strain_old + scalar) - _yield_stress;
     178             :   }
     179             : 
     180     7377542 :   return _hardening_variable_old[_qp] + _hardening_slope * scalar;
     181             : }
     182             : 
     183             : template <bool is_ad>
     184             : GenericReal<is_ad>
     185     4990754 : IsotropicPlasticityStressUpdateTempl<is_ad>::computeHardeningDerivative(
     186             :     const GenericReal<is_ad> & /*scalar*/)
     187             : {
     188     4990754 :   if (_hardening_function)
     189             :   {
     190       35744 :     const Real strain_old = this->_effective_inelastic_strain_old[_qp];
     191       35744 :     return _hardening_function->timeDerivative(strain_old);
     192             :   }
     193             : 
     194     4955010 :   return _hardening_constant;
     195             : }
     196             : 
     197             : template <bool is_ad>
     198             : void
     199     2789742 : IsotropicPlasticityStressUpdateTempl<is_ad>::computeYieldStress(
     200             :     const GenericRankFourTensor<is_ad> & /*elasticity_tensor*/)
     201             : {
     202     2789742 :   if (_yield_stress_function)
     203             :   {
     204           0 :     static const MooseADWrapper<Point, is_ad> p;
     205           0 :     _yield_stress = _yield_stress_function->value(_temperature[_qp], p);
     206             : 
     207           0 :     if (_yield_stress <= 0.0)
     208           0 :       mooseError("In ",
     209           0 :                  this->_name,
     210             :                  ": The calculated yield stress (",
     211           0 :                  _yield_stress,
     212             :                  ") is less than zero");
     213             :   }
     214     2789742 : }
     215             : 
     216             : template class IsotropicPlasticityStressUpdateTempl<false>;
     217             : template class IsotropicPlasticityStressUpdateTempl<true>;

Generated by: LCOV version 1.14