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 "ADStressDivergenceTensors.h" 11 : #include "RankTwoTensor.h" 12 : #include "SymmetricRankTwoTensor.h" 13 : #include "libmesh/quadrature.h" 14 : 15 : registerMooseObject("SolidMechanicsApp", ADStressDivergenceTensors); 16 : registerMooseObject("SolidMechanicsApp", ADSymmetricStressDivergenceTensors); 17 : 18 : template <typename R2> 19 : InputParameters 20 6792 : ADStressDivergenceTensorsTempl<R2>::validParams() 21 : { 22 6792 : InputParameters params = ADKernel::validParams(); 23 6792 : params.addClassDescription("Stress divergence kernel with automatic differentiation for the " 24 : "Cartesian coordinate system"); 25 13584 : params.addRequiredParam<unsigned int>("component", 26 : "An integer corresponding to the direction " 27 : "the variable this kernel acts in. (0 for x, " 28 : "1 for y, 2 for z)"); 29 13584 : params.addRequiredCoupledVar("displacements", 30 : "The string of displacements suitable for the problem statement"); 31 13584 : params.addParam<std::string>("base_name", "Material property base name"); 32 13584 : params.addCoupledVar("out_of_plane_strain", 33 : "The name of the out_of_plane_strain variable used in the " 34 : "WeakPlaneStress kernel."); 35 6792 : params.set<bool>("use_displaced_mesh") = false; 36 13584 : params.addParam<bool>("volumetric_locking_correction", 37 13584 : false, 38 : "Set to false to turn off volumetric locking correction"); 39 6792 : return params; 40 0 : } 41 : 42 : template <typename R2> 43 3396 : ADStressDivergenceTensorsTempl<R2>::ADStressDivergenceTensorsTempl( 44 : const InputParameters & parameters) 45 : : ADKernel(parameters), 46 3492 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 47 6792 : _stress(getADMaterialProperty<R2>(_base_name + "stress")), 48 6792 : _component(getParam<unsigned int>("component")), 49 3396 : _ndisp(coupledComponents("displacements")), 50 3396 : _disp_var(_ndisp), 51 : _avg_grad_test(), 52 3396 : _out_of_plane_strain_coupled(isCoupled("out_of_plane_strain")), 53 3396 : _out_of_plane_strain(_out_of_plane_strain_coupled ? &adCoupledValue("out_of_plane_strain") 54 : : nullptr), 55 10188 : _volumetric_locking_correction(getParam<bool>("volumetric_locking_correction")) 56 : { 57 12348 : for (unsigned int i = 0; i < _ndisp; ++i) 58 : // the next line should be _disp_var[i] = coupled("displacements", i); 59 : // but the Coupleable:: is required to avoid triggering an internal Intel compiler bug 60 8952 : _disp_var[i] = Coupleable::coupled("displacements", i); 61 : 62 : // Error if volumetric locking correction is turned on for 1D problems 63 3396 : if (_ndisp == 1 && _volumetric_locking_correction) 64 0 : mooseError("Volumetric locking correction should be set to false for 1-D problems."); 65 3396 : } 66 : 67 : template <typename R2> 68 : void 69 3018 : ADStressDivergenceTensorsTempl<R2>::initialSetup() 70 : { 71 3018 : if (getBlockCoordSystem() != Moose::COORD_XYZ) 72 0 : mooseError( 73 : "The coordinate system in the Problem block must be set to XYZ for cartesian geometries."); 74 3018 : } 75 : 76 : template <typename R2> 77 : ADReal 78 388532080 : ADStressDivergenceTensorsTempl<R2>::computeQpResidual() 79 : { 80 388532080 : ADReal residual = _stress[_qp].row(_component) * _grad_test[_i][_qp]; 81 : 82 : // volumetric locking correction 83 388532080 : if (_volumetric_locking_correction) 84 157349376 : residual += (_avg_grad_test[_i] - _grad_test[_i][_qp](_component)) / 3.0 * _stress[_qp].trace(); 85 : 86 388532080 : if (_ndisp != 3 && _out_of_plane_strain_coupled && _use_displaced_mesh) 87 : { 88 12800 : const ADReal out_of_plane_thickness = std::exp((*_out_of_plane_strain)[_qp]); 89 12800 : residual *= out_of_plane_thickness; 90 : } 91 : 92 388532080 : return residual; 93 : } 94 : 95 : template <typename R2> 96 : void 97 7485752 : ADStressDivergenceTensorsTempl<R2>::precalculateResidual() 98 : { 99 7485752 : if (!_volumetric_locking_correction) 100 6256388 : return; 101 : 102 1229364 : ADReal ad_current_elem_volume = 0.0; 103 11063892 : for (unsigned int qp = 0; qp < _qrule->n_points(); qp++) 104 19669056 : ad_current_elem_volume += _ad_JxW[qp] * _ad_coord[qp]; 105 : 106 : // Calculate volume averaged value of shape function derivative 107 1229364 : _avg_grad_test.resize(_test.size()); 108 11063892 : for (_i = 0; _i < _test.size(); ++_i) 109 : { 110 9834528 : _avg_grad_test[_i] = 0.0; 111 88509216 : for (_qp = 0; _qp < _qrule->n_points(); ++_qp) 112 157349376 : _avg_grad_test[_i] += _grad_test[_i][_qp](_component) * _ad_JxW[_qp] * _ad_coord[_qp]; 113 : 114 9834528 : _avg_grad_test[_i] /= ad_current_elem_volume; 115 : } 116 : } 117 : 118 : template class ADStressDivergenceTensorsTempl<RankTwoTensor>; 119 : template class ADStressDivergenceTensorsTempl<SymmetricRankTwoTensor>;