76 if (data.
x_prev.size() != data.
x.size())
78 Eigen::MatrixXd local_disp;
80 Eigen::MatrixXd local_prev_disp = local_disp;
84 for (
size_t ii = 0; ii < bs.global.size(); ++ii)
86 for (
int d = 0; d <
size(); ++d)
88 local_disp(i, d) += bs.global[ii].val * data.
x(bs.global[ii].index *
size() + d);
89 local_prev_disp(i, d) += bs.global[ii].val * data.
x_prev(bs.global[ii].index *
size() + d);
97 const int n_pts = data.
da.size();
100 for (
long p = 0; p < n_pts; ++p)
103 prev_def_grad.setZero();
114 def_grad = local_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
115 prev_def_grad = local_prev_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
117 Eigen::MatrixXd delF_delU = grad * jac_it;
119 Eigen::MatrixXd dRdF, dRdFdot;
122 G += delF_delU * (dRdFdot / (-data.
dt)) * data.
da(p);
125 Eigen::MatrixXd G_T = G.transpose();
127 Eigen::VectorXd temp(Eigen::Map<Eigen::VectorXd>(G_T.data(), G_T.size()));
136 if (data.
x_prev.size() != data.
x.size())
138 Eigen::MatrixXd local_disp;
140 Eigen::MatrixXd local_prev_disp = local_disp;
144 for (
size_t ii = 0; ii < bs.global.size(); ++ii)
146 for (
int d = 0; d <
size(); ++d)
148 local_disp(i, d) += bs.global[ii].val * data.
x(bs.global[ii].index *
size() + d);
149 local_prev_disp(i, d) += bs.global[ii].val * data.
x_prev(bs.global[ii].index *
size() + d);
157 const int n_pts = data.
da.size();
160 for (
long p = 0; p < n_pts; ++p)
163 prev_def_grad.setZero();
174 def_grad = local_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
175 prev_def_grad = local_prev_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
177 Eigen::MatrixXd delF_delU = grad * jac_it;
178 auto dFdt = (def_grad - prev_def_grad) / data.
dt;
180 Eigen::MatrixXd dRdF, dRdFdot;
181 Eigen::MatrixXd dEdt = 0.5 * (dFdt.transpose() * def_grad + def_grad.transpose() * dFdt);
184 G += delF_delU * ((dFdt + def_grad / data.
dt) * tmp).transpose() * data.
da(p);
187 Eigen::MatrixXd G_T = G.transpose();
189 Eigen::VectorXd temp(Eigen::Map<Eigen::VectorXd>(G_T.data(), G_T.size()));
198 Eigen::MatrixXd hessian;
200 if (data.
x_prev.size() != data.
x.size())
202 Eigen::MatrixXd local_disp;
204 Eigen::MatrixXd local_prev_disp = local_disp;
208 for (
size_t ii = 0; ii < bs.global.size(); ++ii)
210 for (
int d = 0; d <
size(); ++d)
212 local_disp(i, d) += bs.global[ii].val * data.
x(bs.global[ii].index *
size() + d);
213 local_prev_disp(i, d) += bs.global[ii].val * data.
x_prev(bs.global[ii].index *
size() + d);
218 const int n_pts = data.
da.size();
221 Eigen::MatrixXd d2RdF2, d2RdFdFdot, d2RdFdot2;
222 Eigen::MatrixXd hessian_temp, hessian_temp2;
223 for (
long p = 0; p < n_pts; ++p)
234 def_grad = local_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
235 prev_def_grad = local_prev_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
237 Eigen::MatrixXd dFdt = (def_grad - prev_def_grad) / data.
dt;
240 hessian_temp = d2RdF2 + (1. / data.
dt) * (d2RdFdFdot + d2RdFdFdot.transpose()) + (1. / data.
dt / data.
dt) * d2RdFdot2;
241 hessian_temp2 = hessian_temp;
242 for (
int i = 0; i <
size(); i++)
243 for (
int j = 0; j <
size(); j++)
244 for (
int k = 0; k <
size(); k++)
245 for (
int l = 0; l <
size(); l++)
246 hessian_temp(i + j *
size(), k + l *
size()) = hessian_temp2(i *
size() + j, k *
size() + l);
248 Eigen::MatrixXd delF_delU_tensor(jac_it.size(), grad.size());
250 for (
size_t i = 0; i < local_disp.rows(); ++i)
252 for (
size_t j = 0; j < local_disp.cols(); ++j)
254 Eigen::MatrixXd temp;
256 temp.row(j) = grad.row(i);
257 temp = temp * jac_it;
258 Eigen::VectorXd temp_flattened(Eigen::Map<Eigen::VectorXd>(temp.data(), temp.size()));
259 delF_delU_tensor.col(i *
size() + j) = temp_flattened;
263 hessian += delF_delU_tensor.transpose() * hessian_temp * delF_delU_tensor * data.
da(p);
273 Eigen::MatrixXd stress_grad_Ut;
275 if (data.
x_prev.size() != data.
x.size())
276 return stress_grad_Ut;
277 Eigen::MatrixXd local_disp;
279 Eigen::MatrixXd local_prev_disp = local_disp;
283 for (
size_t ii = 0; ii < bs.global.size(); ++ii)
285 for (
int d = 0; d <
size(); ++d)
287 local_disp(i, d) += bs.global[ii].val * data.
x(bs.global[ii].index *
size() + d);
288 local_prev_disp(i, d) += bs.global[ii].val * data.
x_prev(bs.global[ii].index *
size() + d);
293 const int n_pts = data.
da.size();
296 for (
long p = 0; p < n_pts; ++p)
299 prev_def_grad.setZero();
310 def_grad = local_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
311 prev_def_grad = local_prev_disp.transpose() * grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
313 Eigen::MatrixXd d2RdF2, d2RdFdFdot, d2RdFdot2;
314 Eigen::MatrixXd dFdt = (def_grad - prev_def_grad) / data.
dt;
317 Eigen::MatrixXd stress_grad_Ut_temp = -(1. / data.
dt) * d2RdFdFdot - (1. / data.
dt / data.
dt) * d2RdFdot2;
318 Eigen::MatrixXd stress_grad_Ut_temp2 = stress_grad_Ut_temp;
319 for (
int i = 0; i <
size(); i++)
320 for (
int j = 0; j <
size(); j++)
321 for (
int k = 0; k <
size(); k++)
322 for (
int l = 0; l <
size(); l++)
323 stress_grad_Ut_temp(i + j *
size(), k + l *
size()) = stress_grad_Ut_temp2(i *
size() + j, k *
size() + l);
325 Eigen::MatrixXd delF_delU_tensor(jac_it.size(), grad.size());
327 for (
size_t i = 0; i < local_disp.rows(); ++i)
329 for (
size_t j = 0; j < local_disp.cols(); ++j)
331 Eigen::MatrixXd temp;
333 temp.row(j) = grad.row(i);
334 temp = temp * jac_it;
335 Eigen::VectorXd temp_flattened(Eigen::Map<Eigen::VectorXd>(temp.data(), temp.size()));
336 delF_delU_tensor.col(i *
size() + j) = temp_flattened;
340 stress_grad_Ut += delF_delU_tensor.transpose() * stress_grad_Ut_temp * delF_delU_tensor * data.
da(p);
343 return stress_grad_Ut;
349 Eigen::MatrixXd local_disp;
351 if (data.
x_prev.size() != data.
x.size())
353 Eigen::MatrixXd local_prev_disp = local_disp;
357 for (
size_t ii = 0; ii < bs.global.size(); ++ii)
359 for (
int d = 0; d <
size(); ++d)
361 local_disp(i, d) += bs.global[ii].val * data.
x(bs.global[ii].index *
size() + d);
362 local_prev_disp(i, d) += bs.global[ii].val * data.
x_prev(bs.global[ii].index *
size() + d);
368 const int n_pts = data.
da.size();
371 for (
long p = 0; p < n_pts; ++p)
374 prev_def_grad.setZero();
380 for (
int d = 0; d <
size(); ++d)
382 for (
int c = 0; c <
size(); ++c)
384 def_grad(d, c) += bs.grad(p, c) * local_disp(i, d);
385 prev_def_grad(d, c) += bs.grad(p, c) * local_prev_disp(i, d);
390 Eigen::MatrixXd jac_it(
size(),
size());
391 for (
long k = 0; k < jac_it.size(); ++k)
394 def_grad = def_grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
395 prev_def_grad = prev_def_grad * jac_it + Eigen::MatrixXd::Identity(
size(),
size());
397 Eigen::MatrixXd dFdt = (def_grad - prev_def_grad) / data.
dt;
398 Eigen::MatrixXd dEdt = 0.5 * (dFdt.transpose() * def_grad + def_grad.transpose() * dFdt);
402 energy +=
val * data.
da(p);