https://mooseframework.inl.gov
HomogenizationConstraint.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 //* This file is part of the MOOSE framework
11 //* https://mooseframework.inl.gov
12 //*
13 //* All rights reserved, see COPYRIGHT for full restrictions
14 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
15 //*
16 //* Licensed under LGPL 2.1, please see LICENSE for details
17 //* https://www.gnu.org/licenses/lgpl-2.1.html
18 
20 
21 #include "Function.h"
22 
23 registerMooseObject("SolidMechanicsApp", HomogenizationConstraint);
24 
27 {
29  params.addClassDescription("Calculate element contribution to the homogenization constraint "
30  "depending on the homogenization constraint type.");
32  "constraint_types",
34  "Type of each constraint: strain, stress, or none. The types are specified in the "
35  "column-major order, and there must be 9 entries in total.");
36  params.addRequiredParam<std::vector<FunctionName>>(
37  "targets", "Functions giving the targets to hit for constraint types that are not none.");
38  params.addParam<bool>("large_kinematics", false, "Using large displacements?");
39  params.addParam<std::string>("base_name", "Material property base name");
40  return params;
41 }
42 
44  : ElementUserObject(parameters),
45  _large_kinematics(getParam<bool>("large_kinematics")),
46  _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
47  _F(getMaterialPropertyByName<RankTwoTensor>(_base_name + "deformation_gradient")),
48  _pk1_stress(getMaterialPropertyByName<RankTwoTensor>(_base_name + "pk1_stress")),
49  _pk1_jacobian(getMaterialPropertyByName<RankFourTensor>(_base_name + "pk1_jacobian"))
50 {
51  // Constraint types
52  auto types = getParam<MultiMooseEnum>("constraint_types");
53  if (types.size() != Moose::dim * Moose::dim)
54  mooseError("Number of constraint types must equal dim * dim. ", types.size(), " are provided.");
55 
56  // Targets to hit
57  const std::vector<FunctionName> & fnames = getParam<std::vector<FunctionName>>("targets");
58 
59  // Prepare the constraint map
60  unsigned int fcount = 0;
61  for (const auto j : make_range(Moose::dim))
62  for (const auto i : make_range(Moose::dim))
63  {
64  const auto idx = i + Moose::dim * j;
65  const auto ctype = static_cast<Homogenization::ConstraintType>(types.get(idx));
67  {
68  const Function * const f = &getFunctionByName(fnames[fcount++]);
69  _cmap[{i, j}] = {ctype, f};
70  }
71  }
72 }
73 
74 void
76 {
77  _residual.zero();
78  _jacobian.zero();
79 }
80 
81 void
83 {
84  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
85  {
86  Real dV = _JxW[_qp] * _coord[_qp];
87  _residual += computeResidual() * dV;
88  _jacobian += computeJacobian() * dV;
89  }
90 }
91 
92 void
94 {
95  const HomogenizationConstraint & other = static_cast<const HomogenizationConstraint &>(y);
96  _residual += other._residual;
97  _jacobian += other._jacobian;
98 }
99 
100 void
102 {
103  std::vector<Real> residual(&_residual(0, 0), &_residual(0, 0) + RankTwoTensor::N2);
104  std::vector<Real> jacobian(&_jacobian(0, 0, 0, 0), &_jacobian(0, 0, 0, 0) + RankFourTensor::N4);
105 
106  gatherSum(residual);
107  gatherSum(jacobian);
108 
109  std::copy(residual.begin(), residual.end(), &_residual(0, 0));
110  std::copy(jacobian.begin(), jacobian.end(), &_jacobian(0, 0, 0, 0));
111 }
112 
115 {
116  RankTwoTensor res;
117 
118  for (auto && [indices, constraint] : _cmap)
119  {
120  auto && [i, j] = indices;
121  auto && [ctype, ctarget] = constraint;
122 
123  if (_large_kinematics)
124  {
126  res(i, j) = _pk1_stress[_qp](i, j) - ctarget->value(_t, _q_point[_qp]);
127  else if (ctype == Homogenization::ConstraintType::Strain)
128  res(i, j) = _F[_qp](i, j) - (Real(i == j) + ctarget->value(_t, _q_point[_qp]));
129  else
130  mooseError("Unknown constraint type in the integral!");
131  }
132  else
133  {
135  res(i, j) = _pk1_stress[_qp](i, j) - ctarget->value(_t, _q_point[_qp]);
136  else if (ctype == Homogenization::ConstraintType::Strain)
137  res(i, j) = 0.5 * (_F[_qp](i, j) + _F[_qp](j, i)) -
138  (Real(i == j) + ctarget->value(_t, _q_point[_qp]));
139  else
140  mooseError("Unknown constraint type in the integral!");
141  }
142  }
143 
144  return res;
145 }
146 
149 {
150  RankFourTensor res;
151 
152  for (auto && [indices1, constraint1] : _cmap)
153  {
154  auto && [i, j] = indices1;
155  auto && ctype = constraint1.first;
156  for (auto && indices2 : _cmap)
157  {
158  auto && [a, b] = indices2.first;
160  res(i, j, a, b) = _pk1_jacobian[_qp](i, j, a, b);
161  else if (ctype == Homogenization::ConstraintType::Strain)
162  {
163  if (_large_kinematics)
164  res(i, j, a, b) = Real(i == a && j == b);
165  else
166  res(i, j, a, b) = 0.5 * Real(i == a && j == b) + 0.5 * Real(i == b && j == a);
167  }
168  else
169  mooseError("Unknown constraint type in Jacobian calculator!");
170  }
171  }
172 
173  return res;
174 }
virtual RankTwoTensor computeResidual()
Total residual assembled as a rank two tensor.
virtual void initialize() override
const MooseArray< Point > & _q_point
const MooseArray< Real > & _coord
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
RankTwoTensor _residual
The assembled tensor residual.
static InputParameters validParams()
virtual void threadJoin(const UserObject &y) override
static constexpr std::size_t dim
const std::vector< double > y
const MaterialProperty< RankTwoTensor > & _F
Deformation gradient.
RankFourTensor _jacobian
The assembled tensor jacobian.
static constexpr unsigned int N4
void addRequiredParam(const std::string &name, const std::string &doc_string)
Computes ${V}(X_{ij}-{X}_{ij})dV$.
static constexpr unsigned int N2
void gatherSum(T &value)
static InputParameters validParams()
Real f(Real x)
Test function for Brents method.
unsigned int _qp
Used to loop through quadrature points.
virtual void finalize() override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
ConstraintType
Constraint type: stress/PK stress or strain/deformation gradient.
const Function & getFunctionByName(const FunctionName &name) const
const MooseArray< Real > & _JxW
virtual void execute() override
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
const MultiMooseEnum constraintType("strain stress none")
Moose constraint type, for input.
Homogenization::ConstraintMap _cmap
Type of each constraint (stress or strain) for each component.
virtual RankFourTensor computeJacobian()
Total Jacobian assembled as a rank two tensor.
const MaterialProperty< RankFourTensor > & _pk1_jacobian
PK derivative.
const MaterialProperty< RankTwoTensor > & _pk1_stress
1st PK (or small) stress
const bool _large_kinematics
If true use large displacement kinematics.
registerMooseObject("SolidMechanicsApp", HomogenizationConstraint)
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
HomogenizationConstraint(const InputParameters &parameters)