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 "StrainEnergyDensity.h" 11 : #include "RankTwoTensor.h" 12 : #include "MooseMesh.h" 13 : 14 : registerMooseObject("SolidMechanicsApp", StrainEnergyDensity); 15 : registerMooseObject("SolidMechanicsApp", ADStrainEnergyDensity); 16 : 17 : template <bool is_ad> 18 : InputParameters 19 1588 : StrainEnergyDensityTempl<is_ad>::validParams() 20 : { 21 1588 : InputParameters params = Material::validParams(); 22 1588 : params.addClassDescription("Computes the strain energy density using a combination of the " 23 : "elastic and inelastic components of the strain increment, which is a " 24 : "valid assumption for monotonic behavior."); 25 3176 : 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 3176 : params.addParam<std::string>("stress_name", 30 : "stress", 31 : "Optional parameter that allows the user to use " 32 : "different stresses on the same material system. " 33 : "For example, when we have a degraded_stress and an intact_stress, " 34 : "we want to compute the degraded strain energy density and " 35 : "the intact strain energy density."); 36 3176 : params.addParam<bool>( 37 : "incremental", 38 : "Optional flag for error checking if an incremental or total model should be used."); 39 1588 : return params; 40 0 : } 41 : 42 : template <bool is_ad> 43 1191 : StrainEnergyDensityTempl<is_ad>::StrainEnergyDensityTempl(const InputParameters & parameters) 44 : : DerivativeMaterialInterface<Material>(parameters), 45 1191 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 46 2382 : _stress_name(getParam<std::string>("stress_name")), 47 1191 : _strain_energy_density(declareProperty<Real>(_base_name + "strain_energy_density")), 48 2382 : _strain_energy_density_old(getMaterialPropertyOld<Real>(_base_name + "strain_energy_density")), 49 1191 : _stress(getGenericMaterialProperty<RankTwoTensor, is_ad>(_base_name + _stress_name)), 50 2382 : _stress_old(getMaterialPropertyOld<RankTwoTensor>(_base_name + _stress_name)), 51 1191 : _mechanical_strain( 52 1191 : getGenericMaterialProperty<RankTwoTensor, is_ad>(_base_name + "mechanical_strain")), 53 1191 : _strain_increment( 54 2382 : getGenericOptionalMaterialProperty<RankTwoTensor, is_ad>(_base_name + "strain_increment")) 55 : { 56 1191 : } 57 : 58 : template <bool is_ad> 59 : void 60 1177 : StrainEnergyDensityTempl<is_ad>::initialSetup() 61 : { 62 : // optional error checking 63 2354 : if (isParamValid("incremental")) 64 : { 65 2354 : auto incremental = getParam<bool>("incremental"); 66 1177 : if (incremental && !_strain_increment) 67 2 : mooseError("StrainEnergyDensity: Specified incremental = true, but material model is " 68 : "not incremental."); 69 1175 : if (!incremental && _strain_increment) 70 2 : mooseError("StrainEnergyDensity: Specified incremental = false, but material model is " 71 : "incremental."); 72 : } 73 1173 : } 74 : template <bool is_ad> 75 : void 76 651220 : StrainEnergyDensityTempl<is_ad>::initQpStatefulProperties() 77 : { 78 651220 : _strain_energy_density[_qp] = 0.0; 79 651220 : } 80 : 81 : template <bool is_ad> 82 : void 83 21694416 : StrainEnergyDensityTempl<is_ad>::computeQpProperties() 84 : { 85 : 86 21694416 : if (_strain_increment) 87 21132936 : _strain_energy_density[_qp] = 88 21132936 : _strain_energy_density_old[_qp] + 89 21132936 : MetaPhysicL::raw_value(_stress[_qp]) 90 42265872 : .doubleContraction(MetaPhysicL::raw_value(_strain_increment[_qp])) / 91 21132936 : 2.0 + 92 21132936 : _stress_old[_qp].doubleContraction(MetaPhysicL::raw_value(_strain_increment[_qp])) / 2.0; 93 : else 94 561480 : _strain_energy_density[_qp] = 95 561480 : MetaPhysicL::raw_value(_stress[_qp]) 96 561480 : .doubleContraction((MetaPhysicL::raw_value(_mechanical_strain[_qp]))) / 97 : 2.0; 98 21694416 : } 99 : 100 : template class StrainEnergyDensityTempl<false>; 101 : template class StrainEnergyDensityTempl<true>;