https://mooseframework.inl.gov
ADCompute2DSmallStrain.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 
10 #include "ADCompute2DSmallStrain.h"
11 
12 #include "libmesh/quadrature.h"
13 
16 {
18  params.addClassDescription("Compute a small strain in a plane strain configuration.");
19  MooseEnum outOfPlaneDirection("x y z", "z");
20  params.addParam<MooseEnum>(
21  "out_of_plane_direction", outOfPlaneDirection, "The direction of the out-of-plane strain.");
22  return params;
23 }
24 
26  : ADComputeSmallStrain(parameters),
27  _out_of_plane_direction(getParam<MooseEnum>("out_of_plane_direction"))
28 {
29 }
30 
31 void
33 {
35  for (unsigned int i = 0; i < 3; ++i)
36  {
37  if (_out_of_plane_direction == i)
38  {
39  _disp[i] = &_ad_zero;
41  }
42  else
43  {
44  _disp[i] = &adCoupledValue("displacements", i);
45  _grad_disp[i] = &adCoupledGradient("displacements", i);
46  }
47  }
48 }
49 
50 void
52 {
53  const auto o0 = _out_of_plane_direction;
54  const auto o1 = (_out_of_plane_direction + 1) % 3;
55  const auto o2 = (_out_of_plane_direction + 2) % 3;
56 
57  ADReal volumetric_strain = 0.0;
58  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
59  {
61  _total_strain[_qp](o1, o1) = (*_grad_disp[o1])[_qp](o1);
62  _total_strain[_qp](o2, o2) = (*_grad_disp[o2])[_qp](o2);
63  _total_strain[_qp](o1, o2) = ((*_grad_disp[o1])[_qp](o2) + (*_grad_disp[o2])[_qp](o1)) / 2.0;
64  _total_strain[_qp](o2, o1) = _total_strain[_qp](o1, o2); // force the symmetrical strain tensor
65 
67  volumetric_strain += _total_strain[_qp].trace() * _JxW[_qp] * _coord[_qp];
68  }
69 
71  volumetric_strain /= _current_elem_volume;
72 
73  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
74  {
76  {
77  const ADReal correction = (volumetric_strain - _total_strain[_qp].trace()) / 3.0;
78  _total_strain[_qp](0, 0) += correction;
79  _total_strain[_qp](1, 1) += correction;
80  _total_strain[_qp](2, 2) += correction;
81  }
82 
84 
85  // Remove the eigenstrains
86  for (const auto es : _eigenstrains)
87  _mechanical_strain[_qp] -= (*es)[_qp];
88  }
89 }
90 
91 void
93 {
94  if (_out_of_plane_direction != 2 && _ndisp != 3)
95  mooseError("For 2D simulations where the out-of-plane direction is x or y the number of "
96  "supplied displacements must be three.");
97  else if (_out_of_plane_direction == 2 && _ndisp != 2)
98  mooseError("For 2D simulations where the out-of-plane direction is z the number of supplied "
99  "displacements must be two.");
100 }
const QBase *const & _qrule
const unsigned int _ndisp
Coupled displacement variables.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const MooseArray< ADRealVectorValue > & _ad_grad_zero
const ADVariableGradient & adCoupledGradient(const std::string &var_name, unsigned int comp=0) const
static InputParameters validParams()
const ADVariableValue & adCoupledValue(const std::string &var_name, unsigned int comp=0) const
const MooseArray< Real > & _JxW
unsigned int _qp
std::vector< const ADVariableGradient * > _grad_disp
Gradient of displacements.
static InputParameters validParams()
std::vector< const ADMaterialProperty< R2 > * > _eigenstrains
ADMaterialProperty< R2 > & _mechanical_strain
ADComputeSmallStrain defines a strain tensor, assuming small strains.
virtual void computeProperties() override
virtual void displacementIntegrityCheck() override
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const unsigned int _out_of_plane_direction
const MooseArray< ADReal > & _ad_zero
std::vector< const ADVariableValue * > _disp
Displacement variables.
const MooseArray< Real > & _coord
ADCompute2DSmallStrain(const InputParameters &parameters)
virtual ADReal computeOutOfPlaneStrain()=0
ADMaterialProperty< R2 > & _total_strain