https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADStressDivergenceTensors.C
Go to the documentation of this file.
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
11#include "RankTwoTensor.h"
13#include "libmesh/quadrature.h"
14
17
18template <typename R2>
21{
23 params.addClassDescription("Stress divergence kernel with automatic differentiation for the "
24 "Cartesian coordinate system");
25 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 params.addRequiredCoupledVar("displacements",
30 "The string of displacements suitable for the problem statement");
31 params.addParam<std::string>("base_name", "Material property base name");
32 params.addCoupledVar("out_of_plane_strain",
33 "The name of the out_of_plane_strain variable used in the "
34 "WeakPlaneStress kernel.");
35 params.set<bool>("use_displaced_mesh") = false;
36 params.addParam<bool>("volumetric_locking_correction",
37 false,
38 "Set to false to turn off volumetric locking correction");
39 return params;
40}
41
42template <typename R2>
44 const InputParameters & parameters)
45 : ADKernel(parameters),
46 _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
47 _stress(getADMaterialProperty<R2>(_base_name + "stress")),
48 _component(getParam<unsigned int>("component")),
49 _ndisp(coupledComponents("displacements")),
50 _disp_var(_ndisp),
51 _avg_grad_test(),
52 _out_of_plane_strain_coupled(isCoupled("out_of_plane_strain")),
53 _out_of_plane_strain(_out_of_plane_strain_coupled ? &adCoupledValue("out_of_plane_strain")
54 : nullptr),
55 _volumetric_locking_correction(getParam<bool>("volumetric_locking_correction"))
56{
57 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 _disp_var[i] = Coupleable::coupled("displacements", i);
61
62 // Error if volumetric locking correction is turned on for 1D problems
64 mooseError("Volumetric locking correction should be set to false for 1-D problems.");
65}
66
67template <typename R2>
68void
70{
71 if (getBlockCoordSystem() != Moose::COORD_XYZ)
73 "The coordinate system in the Problem block must be set to XYZ for cartesian geometries.");
74}
75
76template <typename R2>
79{
80 using std::exp;
81
82 ADReal residual = _stress[_qp].row(_component) * _grad_test[_i][_qp];
83
84 // volumetric locking correction
85 if (_volumetric_locking_correction)
86 residual += (_avg_grad_test[_i] - _grad_test[_i][_qp](_component)) / 3.0 * _stress[_qp].trace();
87
88 if (_ndisp != 3 && _out_of_plane_strain_coupled && _use_displaced_mesh)
89 {
90 const ADReal out_of_plane_thickness = exp((*_out_of_plane_strain)[_qp]);
91 residual *= out_of_plane_thickness;
92 }
93
94 return residual;
95}
96
97template <typename R2>
98void
100{
101 if (!_volumetric_locking_correction)
102 return;
103
104 ADReal ad_current_elem_volume = 0.0;
105 for (unsigned int qp = 0; qp < _qrule->n_points(); qp++)
106 ad_current_elem_volume += _ad_JxW[qp] * _ad_coord[qp];
107
108 // Calculate volume averaged value of shape function derivative
109 _avg_grad_test.resize(_test.size());
110 for (_i = 0; _i < _test.size(); ++_i)
111 {
112 _avg_grad_test[_i] = 0.0;
113 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
114 _avg_grad_test[_i] += _grad_test[_i][_qp](_component) * _ad_JxW[_qp] * _ad_coord[_qp];
115
116 _avg_grad_test[_i] /= ad_current_elem_volume;
117 }
118}
119
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("SolidMechanicsApp", ADStressDivergenceTensors)
void mooseError(Args &&... args)
void ErrorVector unsigned int
static InputParameters validParams()
ADStressDivergenceTensors is the automatic differentiation version of StressDivergenceTensors.
const unsigned int _ndisp
Number of coupled displacement variables.
std::vector< unsigned int > _disp_var
Coupled displacement variable IDs.
ADStressDivergenceTensorsTempl(const InputParameters &parameters)
const bool _volumetric_locking_correction
Flag for volumetric locking correction.
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void addCoupledVar(const std::string &name, const std::string &doc_string)
void mooseError(Args &&... args) const