Compute objective function contributions at element level.
Evaluates Python objective function with current displacement and stress state, and accumulates global objective value and gradients.
1613 {
1615
1616
1621
1624
1626 2;
1627
1631
1632 auto nb_gauss_pts =
1633 getGaussPts().size2();
1634 auto objective_ptr = boost::make_shared<MatrixDouble>(
1635 1, nb_gauss_pts);
1636 auto objective_dstress = boost::make_shared<MatrixDouble>(
1637 nb_gauss_pts,
1638 symm_size);
1639 auto objective_dstrain = boost::make_shared<MatrixDouble>(
1640 nb_gauss_pts,
1641 symm_size);
1642 auto objective_du =
1643 boost::make_shared<MatrixDouble>(nb_gauss_pts,
SPACE_DIM);
1644
1645
1646 auto evaluate_python = [&]() {
1648 auto &coords = OP::getCoordsAtGaussPts();
1651 objective_ptr);
1654 objective_dstress);
1657 objective_dstrain);
1660 objective_du);
1661
1662 auto t_grad_u =
1663 getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*(
commPtr->matGradPtr));
1664 auto t_D =
1665 getFTensor4DdgFromMat<SPACE_DIM, SPACE_DIM, 0>(*(
commPtr->matDPtr));
1666 auto t_jac = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*(
jacPtr));
1667 auto t_diff_jac = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*(
diffJacPtr));
1669 auto t_d_grad = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*(
dGradPtr));
1670
1672 auto t_obj_dstress =
1673 getFTensor2SymmetricFromMat<SPACE_DIM>(*objective_dstress);
1674 auto t_obj_dstrain =
1675 getFTensor2SymmetricFromMat<SPACE_DIM>(*objective_dstrain);
1676 auto t_obj_du = getFTensor1FromMat<SPACE_DIM>(*objective_du);
1677 auto t_d_u = getFTensor1FromMat<SPACE_DIM>(*
dUPtr);
1678
1679 auto vol = OP::getMeasure();
1680 auto t_w = getFTensor0IntegrationWeight();
1681 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
1682
1686
1688 t_diff_inv_jac(
i,
j) =
1689 -(t_inv_jac(
i,
I) * t_diff_jac(
I,
J)) * t_inv_jac(
J,
j);
1691 t_diff_grad(
i,
j) = t_grad_u(
i,
k) * t_diff_inv_jac(
k,
j);
1692
1694 t_d_strain(
i,
j) = t_diff_symm(
i,
j,
k,
l) * (
1695
1697
1698 +
1699
1701
1702 );
1703
1704 auto alpha = t_w * vol;
1705
1706 (*globObjectivePtr) += alpha * t_obj;
1707 (*globObjectiveGradPtr) +=
1708 alpha *
1709 (
1710
1711 t_obj_dstress(
i,
j) * (t_D(
i,
j,
k,
l) * t_d_strain(
k,
l))
1712
1713 +
1714
1715 t_obj_dstrain(
i,
j) * t_d_strain(
i,
j)
1716
1717 +
1718
1719 t_obj_du(
i) * t_d_u(
i)
1720
1721 +
1722
1723 t_obj * t_cof
1724
1725 );
1726
1727 ++t_w;
1728 ++t_jac;
1729 ++t_diff_jac;
1730 ++t_cof;
1731
1732 ++t_obj;
1733 ++t_obj_dstress;
1734 ++t_obj_dstrain;
1735 ++t_obj_du;
1736
1737 ++t_grad_u;
1738 ++t_d_grad;
1739 ++t_d_u;
1740 }
1742 };
1743
1744 CHKERR evaluate_python();
1745
1747 }
#define FTENSOR_INDEX(DIM, I)
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
auto diff_symmetrize(FTensor::Number< DIM >)
constexpr int SPACE_DIM
[Define dimension]
constexpr IntegrationType I
Use Gauss quadrature for integration.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'J', DIM1 > J
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
static MoFEMErrorCode invertTensor(FTensor::Tensor2< T1, DIM, DIM > &t, T2 &det, FTensor::Tensor2< T3, DIM, DIM > &inv_t)
static auto determinantTensor(FTensor::Tensor2< T, DIM, DIM > &t)
Calculate the determinant of a tensor of rank DIM.
auto getFTensor0FromMat(M &data)
Get tensor rank 0 (scalar) form data vector.
static auto getFTensor0FromVec(V &data)
Get tensor rank 0 (scalar) form data vector.