https://mooseframework.inl.gov
HomogenizedTotalLagrangianStressDivergence.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 
12 // MOOSE includes
13 #include "Function.h"
14 #include "MooseVariableScalar.h"
15 
17 
20 {
22  params.addClassDescription("Total Lagrangian stress equilibrium kernel with "
23  "homogenization constraint Jacobian terms");
24  params.renameCoupledVar(
25  "scalar_variable", "macro_var", "Optional scalar field with the macro gradient");
26 
27  return params;
28 }
29 
31  const InputParameters & parameters)
33 {
34 }
35 
36 std::set<std::string>
38 {
39  // Add the scalar variable to the list of variables that this kernel contributes to
40  std::set<std::string> vars = TotalLagrangianStressDivergence::additionalROVariables();
41  vars.insert(_kappa_var_ptr->name());
42  return vars;
43 }
44 
45 void
47 {
48  if (_alpha != 0)
49  return;
50 
51  std::vector<Real> scalar_residuals(_k_order);
52 
53  // only assemble scalar residual once; i.e. when handling the first displacement component
54  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
55  {
56  initScalarQpResidual();
57  const auto dV = _JxW[_qp] * _coord[_qp];
58 
59  // index for residual vector
60  unsigned int h = 0;
61 
62  for (const auto & [indices, constraint] : cmap())
63  {
64  const auto [i, j] = indices;
65  const auto [ctype, ctarget] = constraint;
66  const auto cval = ctarget->value(_t, _q_point[_qp]);
67 
68  // value to be constrained
69  Real val;
71  {
73  val = _pk1[_qp](i, j);
75  val = _F[_qp](i, j) - (Real(i == j));
76  else
77  mooseError("Unknown constraint type in the integral!");
78  }
79  else
80  {
82  val = _pk1[_qp](i, j);
84  val = 0.5 * (_F[_qp](i, j) + _F[_qp](j, i)) - (Real(i == j));
85  else
86  mooseError("Unknown constraint type in the integral!");
87  }
88 
89  scalar_residuals[h++] += (val - cval) * dV;
90  }
91  }
92 
93  addResiduals(
94  _assembly, scalar_residuals, _kappa_var_ptr->dofIndices(), _kappa_var_ptr->scalingFactor());
95 }
96 
97 void
99 {
100  if (_alpha != 0)
101  return;
102 
103  _local_ke.resize(_k_order, _k_order);
104 
105  // only assemble scalar residual once; i.e. when handling the first displacement component
106  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
107  {
108  initScalarQpJacobian(_kappa_var);
109  const auto dV = _JxW[_qp] * _coord[_qp];
110 
111  // index for Jacobian row
112  unsigned int h = 0;
113 
114  for (const auto & [indices1, constraint1] : cmap())
115  {
116  const auto [i, j] = indices1;
117  const auto ctype = constraint1.first;
118 
119  // index for Jacobian col
120  unsigned int m = 0;
121 
122  for (const auto & [indices2, constraint2] : cmap())
123  {
124  const auto [k, l] = indices2;
126  _local_ke(h, m++) += dV * (_dpk1[_qp](i, j, k, l));
127  else if (ctype == Homogenization::ConstraintType::Strain)
128  {
129  if (_large_kinematics)
130  _local_ke(h, m++) += dV * (Real(i == k && j == l));
131  else
132  _local_ke(h, m++) += dV * (0.5 * Real(i == k && j == l) + 0.5 * Real(i == l && j == k));
133  }
134  else
135  mooseError("Unknown constraint type in Jacobian calculator!");
136  }
137  h++;
138  }
139  }
140 
141  addJacobian(_assembly,
142  _local_ke,
143  _kappa_var_ptr->dofIndices(),
144  _kappa_var_ptr->dofIndices(),
145  _kappa_var_ptr->scalingFactor());
146 }
147 
148 void
150  const unsigned int jvar_num)
151 {
152  // ONLY assemble the contribution from _alpha component, which is connected with _var
153  // The other components are handled by other kernel instances with other _alpha
154  if (jvar_num != _var.number())
155  return;
156 
157  const auto & jvar = getVariable(jvar_num);
158  const auto jvar_size = jvar.phiSize();
159  _local_ke.resize(_k_order, jvar_size);
160 
161  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
162  {
163  const auto dV = _JxW[_qp] * _coord[_qp];
164 
165  // index for Jacobian row
166  unsigned int h = 0;
167 
168  for (const auto & [indices, constraint] : cmap())
169  {
170  std::tie(_m, _n) = indices;
171  _ctype = constraint.first;
172  initScalarQpOffDiagJacobian(jvar);
173  for (_j = 0; _j < jvar_size; _j++)
174  _local_ke(h, _j) += dV * computeScalarQpOffDiagJacobian(jvar_num);
175  h++;
176  }
177  }
178 
179  addJacobian(_assembly,
180  _local_ke,
181  _kappa_var_ptr->dofIndices(),
182  jvar.dofIndices(),
183  _kappa_var_ptr->scalingFactor());
184 }
185 
186 void
188  const unsigned int svar_num)
189 {
190  // Just in case, skip any other scalar variables
191  if (svar_num != _kappa_var)
192  return;
193 
194  _local_ke.resize(_test.size(), _k_order);
195 
196  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
197  {
198  unsigned int l = 0;
199  const auto dV = _JxW[_qp] * _coord[_qp];
200  for (const auto & [indices, constraint] : cmap())
201  {
202  // copy constraint indices to protected variables to pass to Qp routine
203  std::tie(_m, _n) = indices;
204  _ctype = constraint.first;
205  initScalarQpJacobian(svar_num);
206  for (_i = 0; _i < _test.size(); _i++)
207  _local_ke(_i, l) += dV * computeQpOffDiagJacobianScalar(svar_num);
208  l++;
209  }
210  }
211 
212  addJacobian(
213  _assembly, _local_ke, _var.dofIndices(), _kappa_var_ptr->dofIndices(), _var.scalingFactor());
214 }
215 
216 Real
218  unsigned int /*svar_num*/)
219 {
220  return _dpk1[_qp].contractionKl(_m, _n, gradTest(_alpha));
221 }
222 
223 Real
225  unsigned int /*jvar_num*/)
226 {
228  return _dpk1[_qp].contractionIj(_m, _n, gradTrial(_alpha));
230  if (_large_kinematics)
231  return Real(_m == _alpha) * gradTrial(_alpha)(_m, _n);
232  else
233  return 0.5 * (Real(_m == _alpha) * gradTrial(_alpha)(_m, _n) +
234  Real(_n == _alpha) * gradTrial(_alpha)(_n, _m));
235  else
236  mooseError("Unknown constraint type in kernel calculation!");
237 }
const unsigned int _alpha
Which component of the vector residual this kernel is responsible for.
const MaterialProperty< RankTwoTensor > & _pk1
The 1st Piola-Kirchhoff stress.
void mooseError(Args &&... args)
char ** vars
registerMooseObject("SolidMechanicsApp", HomogenizedTotalLagrangianStressDivergence)
void renameCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &new_docstring)
virtual void computeScalarOffDiagJacobian(const unsigned int jvar_num) override
Method for computing an off-diagonal jacobian component d-_kappa-residual / d-jvar.
const MaterialProperty< RankTwoTensor > & _F
The actual (stabilized) deformation gradient.
virtual RankTwoTensor gradTest(unsigned int component) override
const bool _large_kinematics
If true use large deformation kinematics.
Interface for objects that use the homogenization constraint.
virtual Real computeQpOffDiagJacobianScalar(const unsigned int svar_num) override
Method for computing d-_var-residual / d-svar at quadrature points.
virtual void computeOffDiagJacobianScalarLocal(const unsigned int svar_num) override
Method for computing an off-diagonal jacobian component d-_var-residual / d-svar. ...
static InputParameters validParams()
virtual Real computeScalarQpOffDiagJacobian(const unsigned int jvar_num) override
Method for computing an off-diagonal jacobian component at quadrature points.
Total Lagrangian formulation with all homogenization terms (one disp_xyz field and macro_gradient sca...
const MaterialProperty< RankFourTensor > & _dpk1
The derivative of the PK1 stress with respect to the deformation gradient.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _m
Indices for off-diagonal Jacobian components.
Enforce equilibrium with a total Lagrangian formulation.
Homogenization::ConstraintType _ctype
Type of current homogenization constraint.
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
HomogenizedTotalLagrangianStressDivergence(const InputParameters &parameters)
virtual void computeScalarResidual() override
Method for computing the scalar part of residual for _kappa.
virtual void computeScalarJacobian() override
Method for computing the scalar variable part of Jacobian for d-_kappa-residual / d-_kappa...
virtual RankTwoTensor gradTrial(unsigned int component) override
virtual std::set< std::string > additionalROVariables() override
Inform moose that this kernel covers the constraint scalar variable.
static const std::string k
Definition: NS.h:130
const Homogenization::ConstraintMap & cmap() const
Get the constraint map.