8 #ifndef __HENKY_OPS_HPP__
9 #define __HENKY_OPS_HPP__
13 constexpr
double eps = std::numeric_limits<float>::epsilon();
15 auto f = [](
double v) {
return 0.5 * std::log(
v); };
16 auto d_f = [](
double v) {
return 0.5 /
v; };
17 auto dd_f = [](
double v) {
return -0.5 / (
v *
v); };
20 static inline auto check(
const double &
a,
const double &b) {
28 inline auto is_eq(
const double &
a,
const double &b) {
33 std::array<double, DIM> tmp;
34 std::copy(ptr, &ptr[DIM], tmp.begin());
35 std::sort(tmp.begin(), tmp.end());
36 isEq::absMax = std::max(std::abs(tmp[0]), std::abs(tmp[DIM - 1]));
37 return std::distance(tmp.begin(), std::unique(tmp.begin(), tmp.end(),
is_eq));
45 std::max(std::max(std::abs(eig(0)), std::abs(eig(1))), std::abs(eig(2)));
47 int i = 0,
j = 1,
k = 2;
49 if (
is_eq(eig(0), eig(1))) {
53 }
else if (
is_eq(eig(0), eig(2))) {
57 }
else if (
is_eq(eig(1), eig(2))) {
64 eigen_vec(
i, 0), eigen_vec(
i, 1), eigen_vec(
i, 2),
66 eigen_vec(
j, 0), eigen_vec(
j, 1), eigen_vec(
j, 2),
68 eigen_vec(
k, 0), eigen_vec(
k, 1), eigen_vec(
k, 2)};
76 eigen_vec(
i,
j) = eigen_vec_c(
i,
j);
80 struct CommonData :
public boost::enable_shared_from_this<CommonData> {
95 return boost::shared_ptr<MatrixDouble>(shared_from_this(),
100 return boost::shared_ptr<MatrixDouble>(shared_from_this(),
105 return boost::shared_ptr<MatrixDouble>(shared_from_this(), &
matLogC);
109 return boost::shared_ptr<MatrixDouble>(shared_from_this(), &
matTangent);
113 template <
int DIM, IntegrationType I,
typename DomainEleOp>
116 template <
int DIM, IntegrationType I,
typename DomainEleOp>
119 template <
int DIM, IntegrationType I,
typename DomainEleOp>
122 template <
int DIM, IntegrationType I,
typename DomainEleOp,
int S>
125 template <
int DIM, IntegrationType I,
typename DomainEleOp,
int S>
128 template <
int DIM, IntegrationType I,
typename DomainEleOp,
int S>
131 template <
int DIM, IntegrationType I,
typename DomainEleOp,
int S>
134 template <
int DIM,
typename DomainEleOp>
138 boost::shared_ptr<CommonData> common_data)
140 commonDataPtr(common_data) {
141 std::fill(&DomainEleOp::doEntities[MBEDGE],
142 &DomainEleOp::doEntities[MBMAXTYPE],
false);
154 const size_t nb_gauss_pts = DomainEleOp::getGaussPts().size2();
156 auto t_grad = getFTensor2FromMat<DIM, DIM>(*(commonDataPtr->matGradPtr));
158 commonDataPtr->matEigVal.resize(DIM, nb_gauss_pts,
false);
159 commonDataPtr->matEigVec.resize(DIM * DIM, nb_gauss_pts,
false);
160 auto t_eig_val = getFTensor1FromMat<DIM>(commonDataPtr->matEigVal);
161 auto t_eig_vec = getFTensor2FromMat<DIM, DIM>(commonDataPtr->matEigVec);
163 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
173 for (
int ii = 0; ii != DIM; ii++)
174 for (
int jj = 0; jj != DIM; jj++)
175 eigen_vec(ii, jj) = C(ii, jj);
178 for (
auto ii = 0; ii != DIM; ++ii)
179 eig(ii) = std::max(std::numeric_limits<double>::epsilon(), eig(ii));
182 auto nb_uniq = get_uniq_nb<DIM>(&eig(0));
183 if constexpr (DIM == 3) {
185 sort_eigen_vals<DIM>(eig, eigen_vec);
189 t_eig_val(
i) = eig(
i);
190 t_eig_vec(
i,
j) = eigen_vec(
i,
j);
204 template <
int DIM,
typename DomainEleOp>
208 boost::shared_ptr<CommonData> common_data)
210 commonDataPtr(common_data) {
211 std::fill(&DomainEleOp::doEntities[MBEDGE],
212 &DomainEleOp::doEntities[MBMAXTYPE],
false);
223 const size_t nb_gauss_pts = DomainEleOp::getGaussPts().size2();
224 constexpr
auto size_symm = (DIM * (DIM + 1)) / 2;
225 commonDataPtr->matLogC.resize(
size_symm, nb_gauss_pts,
false);
227 auto t_eig_val = getFTensor1FromMat<DIM>(commonDataPtr->matEigVal);
228 auto t_eig_vec = getFTensor2FromMat<DIM, DIM>(commonDataPtr->matEigVec);
230 auto t_logC = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matLogC);
232 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
235 auto nb_uniq = get_uniq_nb<DIM>(&(t_eig_val(0)));
239 eig(
i) = t_eig_val(
i);
240 eigen_vec(
i,
j) = t_eig_vec(
i,
j);
242 t_logC(
i,
j) = logC(
i,
j);
256 template <
int DIM,
typename DomainEleOp>
260 boost::shared_ptr<CommonData> common_data)
262 commonDataPtr(common_data) {
263 std::fill(&DomainEleOp::doEntities[MBEDGE],
264 &DomainEleOp::doEntities[MBMAXTYPE],
false);
275 const size_t nb_gauss_pts = DomainEleOp::getGaussPts().size2();
276 constexpr
auto size_symm = (DIM * (DIM + 1)) / 2;
278 auto t_logC_dC = getFTensor4DdgFromMat<DIM, DIM>(commonDataPtr->matLogCdC);
279 auto t_eig_val = getFTensor1FromMat<DIM>(commonDataPtr->matEigVal);
280 auto t_eig_vec = getFTensor2FromMat<DIM, DIM>(commonDataPtr->matEigVec);
282 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
286 eig(
i) = t_eig_val(
i);
287 eigen_vec(
i,
j) = t_eig_vec(
i,
j);
290 auto nb_uniq = get_uniq_nb<DIM>(&eig(0));
292 dlogC_dC(
i,
j,
k,
l) *= 2;
294 t_logC_dC(
i,
j,
k,
l) = dlogC_dC(
i,
j,
k,
l);
308 template <
int DIM,
typename DomainEleOp,
int S>
313 boost::shared_ptr<CommonData> common_data)
315 commonDataPtr(common_data) {
316 std::fill(&DomainEleOp::doEntities[MBEDGE],
317 &DomainEleOp::doEntities[MBMAXTYPE],
false);
331 const size_t nb_gauss_pts = DomainEleOp::getGaussPts().size2();
332 auto t_D = getFTensor4DdgFromMat<DIM, DIM, S>(*commonDataPtr->matDPtr);
333 auto t_logC = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matLogC);
334 constexpr
auto size_symm = (DIM * (DIM + 1)) / 2;
335 commonDataPtr->matHenckyStress.resize(
size_symm, nb_gauss_pts,
false);
336 auto t_T = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matHenckyStress);
338 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
339 t_T(
i,
j) = t_D(
i,
j,
k,
l) * t_logC(
k,
l);
352 template <
int DIM,
typename DomainEleOp,
int S>
357 boost::shared_ptr<CommonData> common_data,
358 boost::shared_ptr<MatrixDouble> mat_D_ptr,
359 const double scale = 1)
361 scaleStress(
scale), matDPtr(mat_D_ptr) {
362 std::fill(&DomainEleOp::doEntities[MBEDGE],
363 &DomainEleOp::doEntities[MBMAXTYPE],
false);
365 matLogCPlastic = commonDataPtr->matLogCPlastic;
379 const size_t nb_gauss_pts = DomainEleOp::getGaussPts().size2();
380 auto t_D = getFTensor4DdgFromMat<DIM, DIM, S>(*matDPtr);
381 auto t_logC = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matLogC);
382 auto t_logCPlastic = getFTensor2SymmetricFromMat<DIM>(*matLogCPlastic);
383 constexpr
auto size_symm = (DIM * (DIM + 1)) / 2;
384 commonDataPtr->matHenckyStress.resize(
size_symm, nb_gauss_pts,
false);
385 auto t_T = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matHenckyStress);
387 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
388 t_T(
i,
j) = t_D(
i,
j,
k,
l) * (t_logC(
k,
l) - t_logCPlastic(
k,
l));
389 t_T(
i,
j) /= scaleStress;
406 template <
int DIM,
typename DomainEleOp,
int S>
411 boost::shared_ptr<CommonData> common_data)
413 commonDataPtr(common_data) {
414 std::fill(&DomainEleOp::doEntities[MBEDGE],
415 &DomainEleOp::doEntities[MBMAXTYPE],
false);
429 const size_t nb_gauss_pts = DomainEleOp::getGaussPts().size2();
430 #ifdef HENCKY_SMALL_STRAIN
431 auto t_D = getFTensor4DdgFromMat<DIM, DIM, S>(*commonDataPtr->matDPtr);
433 auto t_logC = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matLogC);
434 auto t_logC_dC = getFTensor4DdgFromMat<DIM, DIM>(commonDataPtr->matLogCdC);
435 constexpr
auto size_symm = (DIM * (DIM + 1)) / 2;
436 commonDataPtr->matFirstPiolaStress.resize(DIM * DIM, nb_gauss_pts,
false);
437 commonDataPtr->matSecondPiolaStress.resize(
size_symm, nb_gauss_pts,
false);
438 auto t_P = getFTensor2FromMat<DIM, DIM>(commonDataPtr->matFirstPiolaStress);
439 auto t_T = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matHenckyStress);
441 getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matSecondPiolaStress);
442 auto t_grad = getFTensor2FromMat<DIM, DIM>(*(commonDataPtr->matGradPtr));
444 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
446 #ifdef HENCKY_SMALL_STRAIN
447 t_P(
i,
j) = t_D(
i,
j,
k,
l) * t_grad(
k,
l);
451 t_S(
k,
l) = t_T(
i,
j) * t_logC_dC(
i,
j,
k,
l);
452 t_P(
i,
l) = t_F(
i,
k) * t_S(
k,
l);
461 #ifdef HENCKY_SMALL_STRAIN
473 template <
int DIM,
typename DomainEleOp,
int S>
476 boost::shared_ptr<CommonData> common_data,
477 boost::shared_ptr<MatrixDouble> mat_D_ptr =
nullptr)
479 commonDataPtr(common_data) {
480 std::fill(&DomainEleOp::doEntities[MBEDGE],
481 &DomainEleOp::doEntities[MBMAXTYPE],
false);
485 matDPtr = commonDataPtr->matDPtr;
502 const size_t nb_gauss_pts = DomainEleOp::getGaussPts().size2();
503 constexpr
auto size_symm = (DIM * (DIM + 1)) / 2;
504 commonDataPtr->matTangent.resize(DIM * DIM * DIM * DIM, nb_gauss_pts);
506 getFTensor4FromMat<DIM, DIM, DIM, DIM, 1>(commonDataPtr->matTangent);
508 auto t_D = getFTensor4DdgFromMat<DIM, DIM, S>(*matDPtr);
509 auto t_eig_val = getFTensor1FromMat<DIM>(commonDataPtr->matEigVal);
510 auto t_eig_vec = getFTensor2FromMat<DIM, DIM>(commonDataPtr->matEigVec);
511 auto t_T = getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matHenckyStress);
513 getFTensor2SymmetricFromMat<DIM>(commonDataPtr->matSecondPiolaStress);
514 auto t_grad = getFTensor2FromMat<DIM, DIM>(*(commonDataPtr->matGradPtr));
515 auto t_logC_dC = getFTensor4DdgFromMat<DIM, DIM>(commonDataPtr->matLogCdC);
517 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
519 #ifdef HENCKY_SMALL_STRAIN
520 dP_dF(
i,
j,
k,
l) = t_D(
i,
j,
k,
l);
529 eig(
i) = t_eig_val(
i);
530 eigen_vec(
i,
j) = t_eig_vec(
i,
j);
534 auto nb_uniq = get_uniq_nb<DIM>(&eig(0));
544 P_D_P_plus_TL(
i,
j,
k,
l) =
546 (t_logC_dC(
i,
j, o, p) * t_D(o, p,
m,
n)) * t_logC_dC(
m,
n,
k,
l);
547 P_D_P_plus_TL(
i,
j,
k,
l) *= 0.5;
550 t_F(
i,
k) * (P_D_P_plus_TL(
k,
j, o, p) * dC_dF(o, p,
m,
n));
574 template <
int DIM, IntegrationType I>
577 template <
int DIM, IntegrationType I>
580 template <
int DIM, IntegrationType I>
583 template <
int DIM, IntegrationType I,
int S>
587 template <
int DIM, IntegrationType I,
int S = 0>
591 template <
int DIM, IntegrationType I,
int S>
595 template <
int DIM, IntegrationType I,
int S>
602 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
603 std::string block_name,
604 boost::shared_ptr<MatrixDouble> mat_D_Ptr,
Sev sev,
611 std::vector<const CubitMeshSets *> meshset_vec_ptr,
617 "Can not get data from block");
624 for (
auto &b : blockData) {
626 if (b.blockEnts.find(getFEEntityHandle()) != b.blockEnts.end()) {
627 CHKERR getMatDPtr(matDPtr, b.bulkModulusK * scaleYoungModulus,
628 b.shearModulusG * scaleYoungModulus);
633 CHKERR getMatDPtr(matDPtr, bulkModulusKDefault * scaleYoungModulus,
634 shearModulusGDefault * scaleYoungModulus);
639 boost::shared_ptr<MatrixDouble> matDPtr;
640 const double scaleYoungModulus;
644 double shearModulusG;
648 double bulkModulusKDefault;
649 double shearModulusGDefault;
650 std::vector<BlockData> blockData;
654 std::vector<const CubitMeshSets *> meshset_vec_ptr,
658 for (
auto m : meshset_vec_ptr) {
660 std::vector<double> block_data;
661 CHKERR m->getAttributes(block_data);
662 if (block_data.size() != 2) {
664 "Expected that block has two attribute");
666 auto get_block_ents = [&]() {
669 m_field.
get_moab().get_entities_by_handle(
m->meshset, ents,
true);
688 MoFEMErrorCode getMatDPtr(boost::shared_ptr<MatrixDouble> mat_D_ptr,
692 auto set_material_stiffness = [&]() {
698 double A = (DIM == 2)
702 auto t_D = getFTensor4DdgFromMat<DIM, DIM, 0>(*mat_D_ptr);
709 constexpr
auto size_symm = (DIM * (DIM + 1)) / 2;
711 set_material_stiffness();
719 CHKERR PetscOptionsBegin(PETSC_COMM_WORLD,
"hencky_",
"",
"none");
720 CHKERR PetscOptionsScalar(
"-young_modulus",
"Young modulus",
"",
E, &
E,
722 CHKERR PetscOptionsScalar(
"-poisson_ratio",
"poisson ratio",
"", nu, &nu,
724 ierr = PetscOptionsEnd();
728 pip.push_back(
new OpMatBlocks(
732 m_field.
getInterface<MeshsetsManager>()->getCubitMeshsetPtr(std::regex(
734 (boost::format(
"%s(.*)") % block_name).str()
744 template <
int DIM, IntegrationType I,
typename DomainEleOp>
747 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
750 auto common_ptr = boost::make_shared<HenckyOps::CommonData>();
751 common_ptr->matDPtr = boost::make_shared<MatrixDouble>();
752 common_ptr->matGradPtr = boost::make_shared<MatrixDouble>();
755 common_ptr->matDPtr, sev,
scale),
762 pip.push_back(
new typename H::template OpCalculateEigenVals<DIM, I>(
765 new typename H::template OpCalculateLogC<DIM, I>(
field_name, common_ptr));
766 pip.push_back(
new typename H::template OpCalculateLogC_dC<DIM, I>(
769 pip.push_back(
new typename H::template OpCalculateHenckyStress<DIM, I, 0>(
771 pip.push_back(
new typename H::template OpCalculatePiolaStress<DIM, I, 0>(
777 template <
int DIM, AssemblyType A, IntegrationType I,
typename DomainEleOp>
780 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
781 std::string
field_name, boost::shared_ptr<HenckyOps::CommonData> common_ptr,
785 using B =
typename FormsIntegrators<DomainEleOp>::template Assembly<
786 A>::template LinearForm<I>;
795 template <
int DIM, AssemblyType A, IntegrationType I,
typename DomainEleOp>
798 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
802 auto common_ptr = commonDataFactory<DIM, I, DomainEleOp>(
810 template <
int DIM, AssemblyType A, IntegrationType I,
typename DomainEleOp>
813 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
814 std::string
field_name, boost::shared_ptr<HenckyOps::CommonData> common_ptr,
818 using B =
typename FormsIntegrators<DomainEleOp>::template Assembly<
820 using OpKPiola =
typename B::template OpGradTensorGrad<1, DIM, DIM, 1>;
825 new typename H::template OpHenckyTangent<DIM, I, 0>(
field_name, common_ptr));
832 template <
int DIM, AssemblyType A, IntegrationType I,
typename DomainEleOp>
835 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
839 auto common_ptr = commonDataFactory<DIM, I, DomainEleOp>(
848 #endif // __HENKY_OPS_HPP__