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 "GlobalStrainUserObject.h"
11 :
12 : #include "libmesh/quadrature.h"
13 :
14 : registerMooseObject("SolidMechanicsApp", GlobalStrainUserObject);
15 :
16 : InputParameters
17 96 : GlobalStrainUserObject::validParams()
18 : {
19 96 : InputParameters params = ElementUserObject::validParams();
20 96 : params.addClassDescription(
21 : "Global Strain UserObject to provide Residual and diagonal Jacobian entry");
22 192 : params.addParam<std::vector<Real>>("applied_stress_tensor",
23 : "Vector of values defining the constant applied stress "
24 : "to add, in order 11, 22, 33, 23, 13, 12");
25 192 : params.addParam<std::string>("base_name", "Material properties base name");
26 192 : params.addCoupledVar("displacements", "The name of the displacement variables");
27 96 : params.set<ExecFlagEnum>("execute_on") = EXEC_LINEAR;
28 :
29 96 : return params;
30 0 : }
31 :
32 48 : GlobalStrainUserObject::GlobalStrainUserObject(const InputParameters & parameters)
33 : : ElementUserObject(parameters),
34 : GlobalStrainUserObjectInterface(),
35 48 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
36 96 : _dstress_dstrain(getMaterialProperty<RankFourTensor>(_base_name + "Jacobian_mult")),
37 96 : _stress(getMaterialProperty<RankTwoTensor>(_base_name + "stress")),
38 48 : _dim(_mesh.dimension()),
39 48 : _ndisp(coupledComponents("displacements")),
40 48 : _disp_var(_ndisp),
41 96 : _periodic_dir()
42 : {
43 180 : for (unsigned int i = 0; i < _ndisp; ++i)
44 132 : _disp_var[i] = coupled("displacements", i);
45 :
46 180 : for (unsigned int dir = 0; dir < _dim; ++dir)
47 : {
48 132 : _periodic_dir(dir) = _mesh.isTranslatedPeriodic(_disp_var[0], dir);
49 :
50 372 : for (unsigned int i = 1; i < _ndisp; ++i)
51 240 : if (_mesh.isTranslatedPeriodic(_disp_var[i], dir) != _periodic_dir(dir))
52 0 : mooseError("All the displacement components in a particular direction should have same "
53 : "periodicity.");
54 : }
55 :
56 96 : if (isParamValid("applied_stress_tensor"))
57 72 : _applied_stress_tensor.fillFromInputVector(
58 : getParam<std::vector<Real>>("applied_stress_tensor"));
59 : else
60 : _applied_stress_tensor.zero();
61 48 : }
62 :
63 : void
64 532 : GlobalStrainUserObject::initialize()
65 : {
66 : _residual.zero();
67 532 : _jacobian.zero();
68 532 : }
69 :
70 : void
71 6232 : GlobalStrainUserObject::execute()
72 : {
73 6232 : computeAdditionalStress();
74 :
75 37912 : for (unsigned int _qp = 0; _qp < _qrule->n_points(); _qp++)
76 : {
77 : // residual, integral of stress components
78 31680 : _residual += _JxW[_qp] * _coord[_qp] * (_stress[_qp] - _applied_stress_tensor);
79 :
80 : // diagonal jacobian, integral of elasticity tensor components
81 63360 : _jacobian += _JxW[_qp] * _coord[_qp] * _dstress_dstrain[_qp];
82 : }
83 6232 : }
84 :
85 : void
86 0 : GlobalStrainUserObject::threadJoin(const UserObject & uo)
87 : {
88 : const auto & pstuo = static_cast<const GlobalStrainUserObject &>(uo);
89 0 : _residual += pstuo._residual;
90 0 : _jacobian += pstuo._jacobian;
91 0 : }
92 :
93 : void
94 532 : GlobalStrainUserObject::finalize()
95 : {
96 532 : std::vector<Real> residual(9);
97 532 : std::vector<Real> jacobian(81);
98 :
99 532 : std::copy(&_residual(0, 0), &_residual(0, 0) + 9, residual.begin());
100 532 : std::copy(&_jacobian(0, 0, 0, 0), &_jacobian(0, 0, 0, 0) + 81, jacobian.begin());
101 :
102 : gatherSum(residual);
103 : gatherSum(jacobian);
104 :
105 532 : std::copy(residual.begin(), residual.end(), &_residual(0, 0));
106 532 : std::copy(jacobian.begin(), jacobian.end(), &_jacobian(0, 0, 0, 0));
107 532 : }
108 :
109 : const RankTwoTensor &
110 48 : GlobalStrainUserObject::getResidual() const
111 : {
112 48 : return _residual;
113 : }
114 :
115 : const RankFourTensor &
116 48 : GlobalStrainUserObject::getJacobian() const
117 : {
118 48 : return _jacobian;
119 : }
120 :
121 : const VectorValue<bool> &
122 342 : GlobalStrainUserObject::getPeriodicDirections() const
123 : {
124 342 : return _periodic_dir;
125 : }
|