OGS
Lubby2.cpp
Go to the documentation of this file.
1 
10 #include "Lubby2.h"
11 
13 
14 namespace MPL = MaterialPropertyLib;
15 
16 namespace MaterialLib
17 {
18 namespace Solids
19 {
20 namespace Lubby2
21 {
24 template <int DisplacementDim>
25 Eigen::Matrix<double, Lubby2<DisplacementDim>::JacobianResidualSize,
28 {
29  Eigen::Matrix<double, Lubby2<DisplacementDim>::JacobianResidualSize,
31  dGdE =
32  Eigen::Matrix<double, Lubby2<DisplacementDim>::JacobianResidualSize,
34  dGdE.template topLeftCorner<Lubby2<DisplacementDim>::KelvinVectorSize,
36  .diagonal()
37  .setConstant(-2.);
38  return dGdE;
39 }
40 
41 template <int DisplacementDim, typename LinearSolver>
43  double const GM0, double const KM0, LinearSolver const& linear_solver)
44 {
45  // Calculate dGdE for time step
46  auto const dGdE = calculatedGdEBurgers<DisplacementDim>();
47 
48  // Consistent tangent from local Newton iteration of material
49  // functionals.
50  // Only the upper left block is relevant for the global tangent.
51  static int const KelvinVectorSize =
53  using KelvinMatrix =
55 
56  KelvinMatrix const dzdE =
57  linear_solver.solve(-dGdE)
58  .template topLeftCorner<KelvinVectorSize, KelvinVectorSize>();
59 
61  auto const& P_sph = Invariants::spherical_projection;
62  auto const& P_dev = Invariants::deviatoric_projection;
63 
64  KelvinMatrix C = GM0 * dzdE * P_dev + 3. * KM0 * P_sph;
65  return C;
66 };
67 
68 template <int DisplacementDim>
69 std::optional<std::tuple<typename Lubby2<DisplacementDim>::KelvinVector,
70  std::unique_ptr<typename MechanicsBase<
71  DisplacementDim>::MaterialStateVariables>,
74  MaterialPropertyLib::VariableArray const& variable_array_prev,
75  MaterialPropertyLib::VariableArray const& variable_array, double const t,
76  ParameterLib::SpatialPosition const& x, double const dt,
78  material_state_variables) const
79 {
80  auto const& eps_m = std::get<MPL::SymmetricTensor<DisplacementDim>>(
81  variable_array[static_cast<int>(MPL::Variable::mechanical_strain)]);
82  auto const& eps_m_prev = std::get<MPL::SymmetricTensor<DisplacementDim>>(
83  variable_array_prev[static_cast<int>(
84  MPL::Variable::mechanical_strain)]);
85  auto const& sigma_prev = std::get<MPL::SymmetricTensor<DisplacementDim>>(
86  variable_array_prev[static_cast<int>(MPL::Variable::stress)]);
87 
89 
90  assert(dynamic_cast<MaterialStateVariables const*>(
91  &material_state_variables) != nullptr);
93  static_cast<MaterialStateVariables const&>(material_state_variables));
94  state.setInitialConditions();
95 
96  auto local_lubby2_properties =
98 
99  // calculation of deviatoric parts
100  auto const& P_dev = Invariants::deviatoric_projection;
101  KelvinVector const eps_m_d_i = P_dev * eps_m;
102  KelvinVector const eps_m_d_t = P_dev * eps_m_prev;
103 
104  // initial guess as elastic predictor.
105  KelvinVector sigd_j = 2.0 * (eps_m_d_i - state.eps_M_t - state.eps_K_t);
106  // Note: sigd_t contains dimensionless stresses!
107  KelvinVector sigd_t = P_dev * sigma_prev / local_lubby2_properties.GM0;
108 
109  // Calculate effective stress and update material properties
110  double sig_eff = Invariants::equivalentStress(sigd_j);
111  local_lubby2_properties.update(sig_eff);
112 
113  using LocalJacobianMatrix =
114  Eigen::Matrix<double, KelvinVectorSize * 3, KelvinVectorSize * 3,
115  Eigen::RowMajor>;
116 
117  // Linear solver for the newton loop is required after the loop with the
118  // same matrix. This saves one decomposition.
119  Eigen::FullPivLU<LocalJacobianMatrix> linear_solver;
120 
121  // Different solvers are available for the solution of the local system.
122  // TODO Make the following choice of linear solvers available from the
123  // input file configuration:
124  // K_loc.partialPivLu().solve(-res_loc);
125  // K_loc.fullPivLu().solve(-res_loc);
126  // K_loc.householderQr().solve(-res_loc);
127  // K_loc.colPivHouseholderQr().solve(res_loc);
128  // K_loc.fullPivHouseholderQr().solve(-res_loc);
129  // K_loc.llt().solve(-res_loc);
130  // K_loc.ldlt().solve(-res_loc);
131 
132  LocalJacobianMatrix K_loc;
133  { // Local Newton solver
134  using LocalResidualVector =
135  Eigen::Matrix<double, KelvinVectorSize * 3, 1>;
136 
137  auto const update_residual = [&](LocalResidualVector& residual)
138  {
139  calculateResidualBurgers(dt, eps_m_d_i, eps_m_d_t, sigd_j, sigd_t,
140  state.eps_K_j, state.eps_K_t,
141  state.eps_M_j, state.eps_M_t, residual,
142  local_lubby2_properties);
143  };
144 
145  auto const update_jacobian = [&](LocalJacobianMatrix& jacobian)
146  {
147  calculateJacobianBurgers(
148  t, x, dt, jacobian, sig_eff, sigd_j, state.eps_K_j,
149  local_lubby2_properties); // for solution dependent Jacobians
150  };
151 
152  auto const update_solution = [&](LocalResidualVector const& increment)
153  {
154  // increment solution vectors
155  sigd_j.noalias() += increment.template segment<KelvinVectorSize>(
156  KelvinVectorSize * 0);
157  state.eps_K_j.noalias() +=
158  increment.template segment<KelvinVectorSize>(KelvinVectorSize *
159  1);
160  state.eps_M_j.noalias() +=
161  increment.template segment<KelvinVectorSize>(KelvinVectorSize *
162  2);
163 
164  // Calculate effective stress and update material properties
166  KelvinVectorSize>::equivalentStress(sigd_j);
167  local_lubby2_properties.update(sig_eff);
168  };
169 
170  auto newton_solver = NumLib::NewtonRaphson<
171  decltype(linear_solver), LocalJacobianMatrix,
172  decltype(update_jacobian), LocalResidualVector,
173  decltype(update_residual), decltype(update_solution)>(
174  linear_solver, update_jacobian, update_residual, update_solution,
175  _nonlinear_solver_parameters);
176 
177  auto const success_iterations = newton_solver.solve(K_loc);
178 
179  if (!success_iterations)
180  {
181  return {};
182  }
183 
184  // If the Newton loop didn't run, the linear solver will not be
185  // initialized.
186  // This happens usually for the first iteration of the first timestep.
187  if (*success_iterations == 0)
188  {
189  linear_solver.compute(K_loc);
190  }
191  }
192 
193  KelvinMatrix C =
194  tangentStiffnessA<DisplacementDim>(local_lubby2_properties.GM0,
195  local_lubby2_properties.KM0,
196  linear_solver);
197 
198  // Hydrostatic part for the stress and the tangent.
199  double const delta_eps_m_trace = Invariants::trace(eps_m - eps_m_prev);
200  double const sigma_trace_prev = Invariants::trace(sigma_prev);
201  KelvinVector const sigma =
202  local_lubby2_properties.GM0 * sigd_j +
203  (local_lubby2_properties.KM0 * delta_eps_m_trace +
204  sigma_trace_prev / 3.) *
205  Invariants::identity2;
206  return {std::make_tuple(
207  sigma,
208  std::unique_ptr<
210  new MaterialStateVariables{state}},
211  C)};
212 }
213 
214 template <int DisplacementDim>
216  const double dt,
217  const KelvinVector& strain_curr,
218  const KelvinVector& strain_t,
219  const KelvinVector& stress_curr,
220  const KelvinVector& stress_t,
221  const KelvinVector& strain_Kel_curr,
222  const KelvinVector& strain_Kel_t,
223  const KelvinVector& strain_Max_curr,
224  const KelvinVector& strain_Max_t,
225  ResidualVector& res,
226  detail::LocalLubby2Properties<DisplacementDim> const& properties) const
227 {
228  // calculate stress residual
229  res.template segment<KelvinVectorSize>(0).noalias() =
230  (stress_curr - stress_t) -
231  2. * ((strain_curr - strain_t) - (strain_Kel_curr - strain_Kel_t) -
232  (strain_Max_curr - strain_Max_t));
233 
234  // calculate Kelvin strain residual
235  res.template segment<KelvinVectorSize>(KelvinVectorSize).noalias() =
236  (strain_Kel_curr - strain_Kel_t) -
237  dt / (2. * properties.etaK) *
238  (properties.GM0 * stress_curr -
239  2. * properties.GK * strain_Kel_curr);
240 
241  // calculate Maxwell strain residual
242  res.template segment<KelvinVectorSize>(2 * KelvinVectorSize).noalias() =
243  (strain_Max_curr - strain_Max_t) -
244  dt * 0.5 * properties.GM0 / properties.etaM * stress_curr;
245 }
246 
247 template <int DisplacementDim>
249  double const t,
251  const double dt,
252  JacobianMatrix& Jac,
253  double s_eff,
254  const KelvinVector& sig_i,
255  const KelvinVector& eps_K_i,
256  detail::LocalLubby2Properties<DisplacementDim> const& properties) const
257 {
258  Jac.setZero();
259 
260  // build G_11
261  Jac.template block<KelvinVectorSize, KelvinVectorSize>(0, 0)
262  .diagonal()
263  .setConstant(1.);
264 
265  // build G_12
266  Jac.template block<KelvinVectorSize, KelvinVectorSize>(0, KelvinVectorSize)
267  .diagonal()
268  .setConstant(2.);
269 
270  // build G_13
271  Jac.template block<KelvinVectorSize, KelvinVectorSize>(0,
272  2 * KelvinVectorSize)
273  .diagonal()
274  .setConstant(2.);
275 
276  // build G_21
277  Jac.template block<KelvinVectorSize, KelvinVectorSize>(KelvinVectorSize, 0)
278  .noalias() =
279  -0.5 * dt * properties.GM0 / properties.etaK * KelvinMatrix::Identity();
280  if (s_eff > 0.)
281  {
282  KelvinVector const eps_K_aid =
283  1. / (properties.etaK * properties.etaK) *
284  (properties.GM0 * sig_i - 2. * properties.GK * eps_K_i);
285 
286  KelvinVector const dG_K = 1.5 * _mp.mK(t, x)[0] * properties.GK *
287  properties.GM0 / s_eff * sig_i;
288  KelvinVector const dmu_vK = 1.5 * _mp.mvK(t, x)[0] * properties.GM0 *
289  properties.etaK / s_eff * sig_i;
290  Jac.template block<KelvinVectorSize, KelvinVectorSize>(KelvinVectorSize,
291  0)
292  .noalias() += 0.5 * dt * eps_K_aid * dmu_vK.transpose() +
293  dt / properties.etaK * eps_K_i * dG_K.transpose();
294  }
295 
296  // build G_22
297  Jac.template block<KelvinVectorSize, KelvinVectorSize>(KelvinVectorSize,
298  KelvinVectorSize)
299  .diagonal()
300  .setConstant(1. + dt * properties.GK / properties.etaK);
301 
302  // nothing to do for G_23
303 
304  // build G_31
305  Jac.template block<KelvinVectorSize, KelvinVectorSize>(2 * KelvinVectorSize,
306  0)
307  .noalias() =
308  -0.5 * dt * properties.GM0 / properties.etaM * KelvinMatrix::Identity();
309  if (s_eff > 0.)
310  {
311  KelvinVector const dmu_vM = 1.5 * _mp.mvM(t, x)[0] * properties.GM0 *
312  properties.etaM / s_eff * sig_i;
313  Jac.template block<KelvinVectorSize, KelvinVectorSize>(
314  2 * KelvinVectorSize, 0)
315  .noalias() += 0.5 * dt * properties.GM0 /
316  (properties.etaM * properties.etaM) * sig_i *
317  dmu_vM.transpose();
318  }
319 
320  // nothing to do for G_32
321 
322  // build G_33
323  Jac.template block<KelvinVectorSize, KelvinVectorSize>(2 * KelvinVectorSize,
324  2 * KelvinVectorSize)
325  .diagonal()
326  .setConstant(1.);
327 }
328 
329 template class Lubby2<2>;
330 template class Lubby2<3>;
331 
332 } // namespace Lubby2
333 } // namespace Solids
334 } // namespace MaterialLib
Eigen::Matrix< double, JacobianResidualSize, 1 > ResidualVector
Definition: Lubby2.h:169
MathLib::KelvinVector::KelvinVectorType< DisplacementDim > KelvinVector
Definition: Lubby2.h:162
static int const KelvinVectorSize
Definition: Lubby2.h:159
Eigen::Matrix< double, JacobianResidualSize, JacobianResidualSize, Eigen::RowMajor > JacobianMatrix
Definition: Lubby2.h:173
MathLib::KelvinVector::KelvinMatrixType< DisplacementDim > KelvinMatrix
Definition: Lubby2.h:164
std::optional< int > solve(JacobianMatrix &jacobian) const
Definition: NewtonRaphson.h:56
MathLib::KelvinVector::KelvinMatrixType< DisplacementDim > tangentStiffnessA(double const GM0, double const KM0, LinearSolver const &linear_solver)
Definition: Lubby2.cpp:42
Eigen::Matrix< double, Lubby2< DisplacementDim >::JacobianResidualSize, Lubby2< DisplacementDim >::KelvinVectorSize > calculatedGdEBurgers()
Definition: Lubby2.cpp:27
std::array< VariableType, static_cast< int >(Variable::number_of_variables)> VariableArray
Definition: VariableType.h:108
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
Definition: KelvinVector.h:23
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), kelvin_vector_dimensions(DisplacementDim), Eigen::RowMajor > KelvinMatrixType
Definition: KelvinVector.h:56