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 4156 : ADStressDivergenceTensorsTempl<R2>::validParams() 21 : { 22 4156 : InputParameters params = ADKernel::validParams(); 23 4156 : params.addClassDescription("Stress divergence kernel with automatic differentiation for the " 24 : "Cartesian coordinate system"); 25 8312 : 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 8312 : params.addRequiredCoupledVar("displacements", 30 : "The string of displacements suitable for the problem statement"); 31 8312 : params.addParam<std::string>("base_name", "Material property base name"); 32 8312 : params.addCoupledVar("out_of_plane_strain", 33 : "The name of the out_of_plane_strain variable used in the " 34 : "WeakPlaneStress kernel."); 35 4156 : params.set<bool>("use_displaced_mesh") = false; 36 8312 : params.addParam<bool>("volumetric_locking_correction", 37 8312 : false, 38 : "Set to false to turn off volumetric locking correction"); 39 4156 : return params; 40 0 : } 41 : 42 : template <typename R2> 43 2078 : ADStressDivergenceTensorsTempl<R2>::ADStressDivergenceTensorsTempl( 44 : const InputParameters & parameters) 45 : : ADKernel(parameters), 46 2134 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 47 4156 : _stress(getADMaterialProperty<R2>(_base_name + "stress")), 48 4156 : _component(getParam<unsigned int>("component")), 49 2078 : _ndisp(coupledComponents("displacements")), 50 2078 : _disp_var(_ndisp), 51 : _avg_grad_test(), 52 2078 : _out_of_plane_strain_coupled(isCoupled("out_of_plane_strain")), 53 2078 : _out_of_plane_strain(_out_of_plane_strain_coupled ? &adCoupledValue("out_of_plane_strain") 54 : : nullptr), 55 6234 : _volumetric_locking_correction(getParam<bool>("volumetric_locking_correction")) 56 : { 57 7584 : 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 5506 : _disp_var[i] = Coupleable::coupled("displacements", i); 61 : 62 : // Error if volumetric locking correction is turned on for 1D problems 63 2078 : if (_ndisp == 1 && _volumetric_locking_correction) 64 0 : mooseError("Volumetric locking correction should be set to false for 1-D problems."); 65 2078 : } 66 : 67 : template <typename R2> 68 : void 69 1853 : ADStressDivergenceTensorsTempl<R2>::initialSetup() 70 : { 71 1853 : 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 1853 : } 75 : 76 : template <typename R2> 77 : ADReal 78 205483752 : ADStressDivergenceTensorsTempl<R2>::computeQpResidual() 79 : { 80 : using std::exp; 81 : 82 205483752 : ADReal residual = _stress[_qp].row(_component) * _grad_test[_i][_qp]; 83 : 84 : // volumetric locking correction 85 205483752 : if (_volumetric_locking_correction) 86 94915584 : residual += (_avg_grad_test[_i] - _grad_test[_i][_qp](_component)) / 3.0 * _stress[_qp].trace(); 87 : 88 205483752 : if (_ndisp != 3 && _out_of_plane_strain_coupled && _use_displaced_mesh) 89 : { 90 11392 : const ADReal out_of_plane_thickness = exp((*_out_of_plane_strain)[_qp]); 91 11392 : residual *= out_of_plane_thickness; 92 : } 93 : 94 205483752 : return residual; 95 : } 96 : 97 : template <typename R2> 98 : void 99 3757956 : ADStressDivergenceTensorsTempl<R2>::precalculateResidual() 100 : { 101 3757956 : if (!_volumetric_locking_correction) 102 3016356 : return; 103 : 104 741600 : ADReal ad_current_elem_volume = 0.0; 105 6674016 : for (unsigned int qp = 0; qp < _qrule->n_points(); qp++) 106 11864832 : ad_current_elem_volume += _ad_JxW[qp] * _ad_coord[qp]; 107 : 108 : // Calculate volume averaged value of shape function derivative 109 741600 : _avg_grad_test.resize(_test.size()); 110 6674016 : for (_i = 0; _i < _test.size(); ++_i) 111 : { 112 5932416 : _avg_grad_test[_i] = 0.0; 113 53390208 : for (_qp = 0; _qp < _qrule->n_points(); ++_qp) 114 94915584 : _avg_grad_test[_i] += _grad_test[_i][_qp](_component) * _ad_JxW[_qp] * _ad_coord[_qp]; 115 : 116 5932416 : _avg_grad_test[_i] /= ad_current_elem_volume; 117 : } 118 : } 119 : 120 : template class ADStressDivergenceTensorsTempl<RankTwoTensor>; 121 : template class ADStressDivergenceTensorsTempl<SymmetricRankTwoTensor>;