324 assert(data.
x.cols() == 1);
326 const int n_pts = data.
da.size();
329 local_disp.setZero();
333 for (
size_t ii = 0; ii < bs.global.size(); ++ii)
335 for (
int d = 0; d <
size(); ++d)
337 local_disp(i, d) += bs.global[ii].val * data.
x(bs.global[ii].index *
size() + d);
342 Eigen::Matrix<double, dim, dim> def_grad(
size(),
size());
347 for (
long p = 0; p < n_pts; ++p)
356 const Eigen::Matrix<double, dim, dim> jac_it = data.
vals.
jac_it[p];
358 const Eigen::Matrix<double, n_basis, dim> delF_delU = grad * jac_it;
361 def_grad = local_disp.transpose() * delF_delU + Eigen::Matrix<double, dim, dim>::Identity(
size(),
size());
368 Eigen::Matrix<double, n_basis, dim> gradient = delF_delU * gradient_temp.transpose();
370 G.noalias() += gradient * data.
da(p);
373 Eigen::Matrix<double, dim, n_basis> G_T = G.transpose();
375 constexpr int N = (n_basis == Eigen::Dynamic) ? Eigen::Dynamic : n_basis * dim;
376 Eigen::Matrix<double, N, 1> temp(Eigen::Map<Eigen::Matrix<double, N, 1>>(G_T.data(), G_T.size()));
383 assert(data.
x.cols() == 1);
385 constexpr int N = (n_basis == Eigen::Dynamic) ? Eigen::Dynamic : n_basis * dim;
386 const int n_pts = data.
da.size();
389 local_disp.setZero();
393 for (
size_t ii = 0; ii < bs.global.size(); ++ii)
395 for (
int d = 0; d <
size(); ++d)
397 local_disp(i, d) += bs.global[ii].val * data.
x(bs.global[ii].index *
size() + d);
402 Eigen::Matrix<double, dim, dim> def_grad(
size(),
size());
404 for (
long p = 0; p < n_pts; ++p)
413 Eigen::Matrix<double, dim, dim> jac_it = data.
vals.
jac_it[p];
416 def_grad = local_disp.transpose() * grad * jac_it + Eigen::Matrix<double, dim, dim>::Identity(
size(),
size());
423 Eigen::Matrix<double, dim * dim, N> delF_delU_tensor(jac_it.size(), grad.size());
425 for (
size_t i = 0; i < local_disp.rows(); ++i)
427 for (
size_t j = 0; j < local_disp.cols(); ++j)
429 Eigen::Matrix<double, dim, dim> temp(
size(),
size());
431 temp.row(j) = grad.row(i);
432 temp = temp * jac_it;
433 Eigen::Matrix<double, dim * dim, 1> temp_flattened(Eigen::Map<Eigen::Matrix<double, dim * dim, 1>>(temp.data(), temp.size()));
434 delF_delU_tensor.col(i *
size() + j) = temp_flattened;
438 Eigen::Matrix<double, N, N> hessian = delF_delU_tensor.transpose() * hessian_temp * delF_delU_tensor;
440 H += hessian * data.
da(p);
501 Eigen::MatrixXd &dstress_dmu,
502 Eigen::MatrixXd &dstress_dlambda)
const
504 const double t = data.
t;
505 const int el_id = data.
el_id;
506 const Eigen::MatrixXd &local_pts = data.
local_pts;
507 const Eigen::MatrixXd &global_pts = data.
global_pts;
508 const Eigen::MatrixXd &grad_u_i = data.
grad_u_i;
510 const Eigen::MatrixXd def_grad = Eigen::MatrixXd::Identity(
size(),
size()) + grad_u_i;
513 Eigen::VectorXd sigmas;
529 Eigen::MatrixXd delJ_delF(
size(),
size());
534 delJ_delF(0, 0) = def_grad(1, 1);
535 delJ_delF(0, 1) = -def_grad(1, 0);
536 delJ_delF(1, 0) = -def_grad(0, 1);
537 delJ_delF(1, 1) = def_grad(0, 0);
539 else if (
size() == 3)
541 const Eigen::Matrix<double, 3, 1> u = def_grad.col(0);
542 const Eigen::Matrix<double, 3, 1> v = def_grad.col(1);
543 const Eigen::Matrix<double, 3, 1> w = def_grad.col(2);
545 delJ_delF.col(0) = cross<3>(v, w);
546 delJ_delF.col(1) = cross<3>(w, u);
547 delJ_delF.col(2) = cross<3>(u, v);
550 dstress_dmu = 2 * (def_grad - UVT);
551 dstress_dlambda = (sigmas.prod() - 1) * delJ_delF;
636 const double sigmaProd = sigmas.prod();
637 Eigen::Matrix<double, dim, 1> sigmaProd_noI;
638 if constexpr (dim == 2) {
639 sigmaProd_noI[0] = sigmas[1];
640 sigmaProd_noI[1] = sigmas[0];
643 sigmaProd_noI[0] = sigmas[1] * sigmas[2];
644 sigmaProd_noI[1] = sigmas[2] * sigmas[0];
645 sigmaProd_noI[2] = sigmas[0] * sigmas[1];
648 double _2mu = mu * 2;
649 Eigen::Matrix<double, dim, dim> d2E_div_dsigma2;
650 d2E_div_dsigma2.setZero();
651 d2E_div_dsigma2(0, 0) = _2mu + lambda * sigmaProd_noI[0] * sigmaProd_noI[0];
652 d2E_div_dsigma2(1, 1) = _2mu + lambda * sigmaProd_noI[1] * sigmaProd_noI[1];
653 if constexpr (dim == 3) {
654 d2E_div_dsigma2(2, 2) = _2mu + lambda * sigmaProd_noI[2] * sigmaProd_noI[2];
657 if constexpr (dim == 2) {
658 d2E_div_dsigma2(0, 1) = d2E_div_dsigma2(1, 0) = lambda * ((sigmaProd - 1.0) + sigmaProd_noI[0] * sigmaProd_noI[1]);
661 d2E_div_dsigma2(0, 1) = d2E_div_dsigma2(1, 0) = lambda * (sigmas[2] * (sigmaProd - 1.0) + sigmaProd_noI[0] * sigmaProd_noI[1]);
662 d2E_div_dsigma2(0, 2) = d2E_div_dsigma2(2, 0) = lambda * (sigmas[1] * (sigmaProd - 1.0) + sigmaProd_noI[0] * sigmaProd_noI[2]);
663 d2E_div_dsigma2(2, 1) = d2E_div_dsigma2(1, 2) = lambda * (sigmas[0] * (sigmaProd - 1.0) + sigmaProd_noI[2] * sigmaProd_noI[1]);
666 return d2E_div_dsigma2;
714 constexpr int Cdim2 = dim * (dim - 1) / 2;
715 Eigen::Matrix<double, Cdim2, 1> BLeftCoef;
718 const double tmp = lambda / 2.0 * (sigmas.prod() - 1);
719 if constexpr (dim == 2) {
720 BLeftCoef[0] = mu - tmp;
723 BLeftCoef[0] = mu - tmp * sigmas[2];
724 BLeftCoef[1] = mu - tmp * sigmas[0];
725 BLeftCoef[2] = mu - tmp * sigmas[1];
728 Eigen::Matrix2d B[Cdim2];
729 for (
int cI = 0; cI < Cdim2; cI++) {
731 int cI_post = (cI + 1) % dim;
733 double rightCoef = dE_div_dsigma[cI] + dE_div_dsigma[cI_post];
734 double sum_sigma = sigmas[cI] + sigmas[cI_post];
735 rightCoef /= 2.0 * std::max(sum_sigma, 1.0e-12);
737 const double& leftCoef = BLeftCoef[cI];
738 B[cI](0, 0) = B[cI](1, 1) = leftCoef + rightCoef;
739 B[cI](0, 1) = B[cI](1, 0) = leftCoef - rightCoef;
743 Eigen::Matrix<double, dim * dim, dim * dim> M;
745 if constexpr (dim == 2) {
746 M(0, 0) = d2E_div_dsigma2(0, 0);
747 M(0, 3) = d2E_div_dsigma2(0, 1);
748 M.block(1, 1, 2, 2) = B[0];
749 M(3, 0) = d2E_div_dsigma2(1, 0);
750 M(3, 3) = d2E_div_dsigma2(1, 1);
754 M(0, 0) = d2E_div_dsigma2(0, 0);
755 M(0, 4) = d2E_div_dsigma2(0, 1);
756 M(0, 8) = d2E_div_dsigma2(0, 2);
757 M(4, 0) = d2E_div_dsigma2(1, 0);
758 M(4, 4) = d2E_div_dsigma2(1, 1);
759 M(4, 8) = d2E_div_dsigma2(1, 2);
760 M(8, 0) = d2E_div_dsigma2(2, 0);
761 M(8, 4) = d2E_div_dsigma2(2, 1);
762 M(8, 8) = d2E_div_dsigma2(2, 2);
764 M(1, 1) = B[0](0, 0);
765 M(1, 3) = B[0](0, 1);
766 M(3, 1) = B[0](1, 0);
767 M(3, 3) = B[0](1, 1);
769 M(5, 5) = B[1](0, 0);
770 M(5, 7) = B[1](0, 1);
771 M(7, 5) = B[1](1, 0);
772 M(7, 7) = B[1](1, 1);
774 M(2, 2) = B[2](1, 1);
775 M(2, 6) = B[2](1, 0);
776 M(6, 2) = B[2](0, 1);
777 M(6, 6) = B[2](0, 0);
781 Eigen::Matrix<double, dim*dim, dim*dim> hessian;
783 const Eigen::Matrix<double, dim, dim>& U = svd.
matrixU();
784 const Eigen::Matrix<double, dim, dim>&
V = svd.
matrixV();
785 for (
int i = 0; i < dim; i++) {
787 for (
int j = 0; j < dim; j++) {
788 int ij = i + j * dim;
789 for (
int r = 0; r < dim; r++) {
791 for (
int s = 0; s < dim; s++) {
792 int rs = r + s * dim;
798 if constexpr (dim == 2) {
799 hessian(ij, rs) = M(0, 0) * U(i, 0) *
V(j, 0) * U(r, 0) *
V(s, 0) + M(0, 3) * U(i, 0) *
V(j, 0) * U(r, 1) *
V(s, 1) + M(1, 1) * U(i, 0) *
V(j, 1) * U(r, 0) *
V(s, 1) + M(1, 2) * U(i, 0) *
V(j, 1) * U(r, 1) *
V(s, 0) + M(2, 1) * U(i, 1) *
V(j, 0) * U(r, 0) *
V(s, 1) + M(2, 2) * U(i, 1) *
V(j, 0) * U(r, 1) *
V(s, 0) + M(3, 0) * U(i, 1) *
V(j, 1) * U(r, 0) *
V(s, 0) + M(3, 3) * U(i, 1) *
V(j, 1) * U(r, 1) *
V(s, 1);
802 hessian(ij, rs) = M(0, 0) * U(i, 0) *
V(j, 0) * U(r, 0) *
V(s, 0) + M(0, 4) * U(i, 0) *
V(j, 0) * U(r, 1) *
V(s, 1) + M(0, 8) * U(i, 0) *
V(j, 0) * U(r, 2) *
V(s, 2) + M(4, 0) * U(i, 1) *
V(j, 1) * U(r, 0) *
V(s, 0) + M(4, 4) * U(i, 1) *
V(j, 1) * U(r, 1) *
V(s, 1) + M(4, 8) * U(i, 1) *
V(j, 1) * U(r, 2) *
V(s, 2) + M(8, 0) * U(i, 2) *
V(j, 2) * U(r, 0) *
V(s, 0) + M(8, 4) * U(i, 2) *
V(j, 2) * U(r, 1) *
V(s, 1) + M(8, 8) * U(i, 2) *
V(j, 2) * U(r, 2) *
V(s, 2) + M(1, 1) * U(i, 0) *
V(j, 1) * U(r, 0) *
V(s, 1) + M(1, 3) * U(i, 0) *
V(j, 1) * U(r, 1) *
V(s, 0) + M(3, 1) * U(i, 1) *
V(j, 0) * U(r, 0) *
V(s, 1) + M(3, 3) * U(i, 1) *
V(j, 0) * U(r, 1) *
V(s, 0) + M(5, 5) * U(i, 1) *
V(j, 2) * U(r, 1) *
V(s, 2) + M(5, 7) * U(i, 1) *
V(j, 2) * U(r, 2) *
V(s, 1) + M(7, 5) * U(i, 2) *
V(j, 1) * U(r, 1) *
V(s, 2) + M(7, 7) * U(i, 2) *
V(j, 1) * U(r, 2) *
V(s, 1) + M(2, 2) * U(i, 0) *
V(j, 2) * U(r, 0) *
V(s, 2) + M(2, 6) * U(i, 0) *
V(j, 2) * U(r, 2) *
V(s, 0) + M(6, 2) * U(i, 2) *
V(j, 0) * U(r, 0) *
V(s, 2) + M(6, 6) * U(i, 2) *
V(j, 0) * U(r, 2) *
V(s, 0);
806 hessian(rs, ij) = hessian(ij, rs);