14#include <adolc/adolc.h>
21 auto create_vec = [&]() {
33 return 2 * (
order - 1) + addToRule;
39 CHKERR VolumeElementForcesAndSourcesCore::preProcess();
41 if (
A != PETSC_NULLPTR) {
45 if (
F != PETSC_NULLPTR) {
65 CHKERR VecAssemblyBegin(V);
73 CHKERR VolumeElementForcesAndSourcesCore::postProcess();
85 std::vector<VectorDouble> &values_at_gauss_pts,
86 std::vector<MatrixDouble> &gardient_at_gauss_pts)
89 valuesAtGaussPts(values_at_gauss_pts),
90 gradientAtGaussPts(gardient_at_gauss_pts), zeroAtType(MBVERTEX) {}
97 const int nb_base_functions = data.
getN().size2();
101 const int nb_gauss_pts = data.
getN().size1();
102 const int rank = data.
getFieldDofs()[0]->getNbOfCoeffs();
105 if (
type == zeroAtType) {
106 valuesAtGaussPts.resize(nb_gauss_pts);
107 gradientAtGaussPts.resize(nb_gauss_pts);
108 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
109 valuesAtGaussPts[gg].resize(rank,
false);
110 gradientAtGaussPts[gg].resize(rank, 3,
false);
112 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
113 valuesAtGaussPts[gg].clear();
114 gradientAtGaussPts[gg].clear();
125 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
127 double &val = valuesAtGaussPts[gg][0];
129 &gradientAtGaussPts[gg](0, 1),
130 &gradientAtGaussPts[gg](0, 2));
132 for (; bb != nb_dofs; bb++) {
133 val += base_function * field_data;
134 grad(
i) += diff_base_functions(
i) * field_data;
135 ++diff_base_functions;
139 for (; bb != nb_base_functions; bb++) {
140 ++diff_base_functions;
145 }
else if (rank == 3) {
147 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
150 &valuesAtGaussPts[gg][1],
151 &valuesAtGaussPts[gg][2]);
153 &gradientAtGaussPts[gg](0, 0), &gradientAtGaussPts[gg](0, 1),
154 &gradientAtGaussPts[gg](0, 2), &gradientAtGaussPts[gg](1, 0),
155 &gradientAtGaussPts[gg](1, 1), &gradientAtGaussPts[gg](1, 2),
156 &gradientAtGaussPts[gg](2, 0), &gradientAtGaussPts[gg](2, 1),
157 &gradientAtGaussPts[gg](2, 2));
159 for (; bb != nb_dofs / 3; bb++) {
160 values(
i) += base_function * field_data(
i);
161 gradient(
i,
j) += field_data(
i) * diff_base_functions(
j);
162 ++diff_base_functions;
166 for (; bb != nb_base_functions; bb++) {
167 ++diff_base_functions;
175 for (
int gg = 0; gg < nb_gauss_pts; gg++) {
178 for (
int dd = 0; dd < nb_dofs / rank; dd++) {
179 for (
int rr1 = 0; rr1 < rank; rr1++) {
180 valuesAtGaussPts[gg][rr1] +=
N[dd] * values[rank * dd + rr1];
181 for (
int rr2 = 0; rr2 < 3; rr2++) {
182 gradientAtGaussPts[gg](rr1, rr2) +=
183 diffN(dd, rr2) * values[rank * dd + rr1];
201 int tag,
bool jacobian,
bool ale,
205 dAta(data),
commonData(common_data),
tAg(tag), adlocReturnValue(0),
206 jAcobian(jacobian), fUnction(!jacobian), aLe(ale), fieldDisp(field_disp) {
215 CHKERR dAta.materialAdoublePtr->calculateP_PiolaKirchhoffI(
216 dAta, getNumeredEntFiniteElementPtr());
219 auto &t_P = dAta.materialAdoublePtr->t_P;
220 auto &t_invH = dAta.materialAdoublePtr->t_invH;
221 t_P(
i,
j) = t_P(
i,
k) * t_invH(
j,
k);
222 t_P(
i,
j) *= dAta.materialAdoublePtr->detH;
226 for (
int dd1 = 0; dd1 < 3; dd1++) {
227 for (
int dd2 = 0; dd2 < 3; dd2++) {
228 dAta.materialAdoublePtr->P(dd1, dd2) >>=
243 dAta.materialAdoublePtr->F.resize(3, 3,
false);
247 nbActiveVariables = 0;
248 for (
int dd1 = 0; dd1 < 3; dd1++) {
249 for (
int dd2 = 0; dd2 < 3; dd2++) {
250 dAta.materialAdoublePtr->F(dd1, dd2) <<= (*ptrh)[gg](dd1, dd2);
253 dAta.materialAdoublePtr->F(dd1, dd2) += 1;
262 nbActiveVariables = 0;
264 dAta.materialAdoublePtr->h.resize(3, 3,
false);
265 for (
int dd1 = 0; dd1 < 3; dd1++) {
266 for (
int dd2 = 0; dd2 < 3; dd2++) {
267 dAta.materialAdoublePtr->h(dd1, dd2) <<= (*ptrh)[gg](dd1, dd2);
272 dAta.materialAdoublePtr->H.resize(3, 3,
false);
273 for (
int dd1 = 0; dd1 < 3; dd1++) {
274 for (
int dd2 = 0; dd2 < 3; dd2++) {
275 dAta.materialAdoublePtr->H(dd1, dd2) <<= (*ptrH)[gg](dd1, dd2);
281 dAta.materialAdoublePtr->invH.resize(3, 3,
false);
283 dAta.materialAdoublePtr->detH,
284 dAta.materialAdoublePtr->invH);
286 auto &t_F = dAta.materialAdoublePtr->t_F;
287 auto &t_h = dAta.materialAdoublePtr->t_h;
288 auto &t_invH = dAta.materialAdoublePtr->t_invH;
290 t_F(
i,
j) = t_h(
i,
k) * t_invH(
k,
j);
294 CHKERR dAta.materialAdoublePtr->setUserActiveVariables(nbActiveVariables);
295 CHKERR calculateStress(gg);
311 r = ::function(
tAg, 9, nbActiveVariables, &activeVariables[0],
313 if (r < adlocReturnValue) {
315 "ADOL-C function evaluation with error r = %d", r);
321 double *jac_ptr[] = {
328 r = jacobian(
tAg, 9, nbActiveVariables, &activeVariables[0], jac_ptr);
329 if (r < adlocReturnValue) {
331 "ADOL-C function evaluation with error");
339 int row_side, EntityType row_type,
344 if (row_type != MBVERTEX)
347 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
355 dAta.materialAdoublePtr->commonDataPtr = &
commonData;
356 dAta.materialAdoublePtr->opPtr =
this;
358 int nb_gauss_pts = row_data.
getN().size1();
367 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
369 dAta.materialAdoublePtr->gG = gg;
372 if (recordTagForIntegrationPoint(gg)) {
377 if (jAcobian || (!recordTagForIntegrationPoint(gg))) {
378 activeVariables.resize(nbActiveVariables,
false);
380 for (
int dd1 = 0; dd1 < 3; dd1++) {
381 for (
int dd2 = 0; dd2 < 3; dd2++) {
382 activeVariables(dd1 * 3 + dd2) = (*ptrh)[gg](dd1, dd2);
386 for (
int dd1 = 0; dd1 < 3; dd1++) {
387 for (
int dd2 = 0; dd2 < 3; dd2++) {
388 activeVariables(dd1 * 3 + dd2) = (*ptrh)[gg](dd1, dd2);
391 for (
int dd1 = 0; dd1 < 3; dd1++) {
392 for (
int dd2 = 0; dd2 < 3; dd2++) {
393 activeVariables(9 + dd1 * 3 + dd2) = (*ptrH)[gg](dd1, dd2);
397 CHKERR dAta.materialAdoublePtr->setUserActiveVariables(activeVariables);
400 if (jAcobian || (!recordTagForIntegrationPoint(gg))) {
413 bool hessian,
bool ale,
bool field_disp)
416 dAta(data),
commonData(common_data),
tAg(tag), gRadient(gradient),
417 hEssian(hessian), aLe(ale), fieldDisp(field_disp) {}
422 CHKERR dAta.materialAdoublePtr->calculateElasticEnergy(
423 dAta, getNumeredEntFiniteElementPtr());
436 nbActiveVariables = 0;
437 for (
int dd1 = 0; dd1 < 3; dd1++) {
438 for (
int dd2 = 0; dd2 < 3; dd2++) {
439 dAta.materialAdoublePtr->F(dd1, dd2) <<= (*ptrh)[gg](dd1, dd2);
442 dAta.materialAdoublePtr->F(dd1, dd2) += 1;
451 nbActiveVariables = 0;
453 dAta.materialAdoublePtr->h.resize(3, 3,
false);
454 for (
int dd1 = 0; dd1 < 3; dd1++) {
455 for (
int dd2 = 0; dd2 < 3; dd2++) {
456 dAta.materialAdoublePtr->h(dd1, dd2) <<= (*ptrh)[gg](dd1, dd2);
461 dAta.materialAdoublePtr->H.resize(3, 3,
false);
462 for (
int dd1 = 0; dd1 < 3; dd1++) {
463 for (
int dd2 = 0; dd2 < 3; dd2++) {
464 dAta.materialAdoublePtr->H(dd1, dd2) <<= (*ptrH)[gg](dd1, dd2);
470 dAta.materialAdoublePtr->invH.resize(3, 3,
false);
472 dAta.materialAdoublePtr->detH,
473 dAta.materialAdoublePtr->invH);
475 auto &t_F = dAta.materialAdoublePtr->t_F;
476 auto &t_h = dAta.materialAdoublePtr->t_h;
477 auto &t_invH = dAta.materialAdoublePtr->t_invH;
479 t_F(
i,
j) = t_h(
i,
k) * t_invH(
k,
j);
483 CHKERR dAta.materialAdoublePtr->setUserActiveVariables(nbActiveVariables);
497 int r = ::gradient(
tAg, nbActiveVariables, &activeVariables[0],
503 "ADOL-C function evaluation with error");
510 double *
H[nbActiveVariables];
511 for (
int n = 0;
n != nbActiveVariables;
n++) {
514 int r = ::hessian(
tAg, nbActiveVariables, &*activeVariables.begin(),
H);
519 "ADOL-C function evaluation with error");
527 int row_side, EntityType row_type,
532 if (row_type != MBVERTEX)
535 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
543 dAta.materialAdoublePtr->commonDataPtr = &
commonData;
544 dAta.materialAdoublePtr->opPtr =
this;
546 int nb_gauss_pts = row_data.
getN().size1();
555 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
557 dAta.materialAdoublePtr->gG = gg;
560 if (recordTagForIntegrationPoint(gg)) {
564 activeVariables.resize(nbActiveVariables,
false);
566 for (
int dd1 = 0; dd1 < 3; dd1++) {
567 for (
int dd2 = 0; dd2 < 3; dd2++) {
568 activeVariables(dd1 * 3 + dd2) = (*ptrh)[gg](dd1, dd2);
572 for (
int dd1 = 0; dd1 < 3; dd1++) {
573 for (
int dd2 = 0; dd2 < 3; dd2++) {
574 activeVariables(dd1 * 3 + dd2) = (*ptrh)[gg](dd1, dd2);
577 for (
int dd1 = 0; dd1 < 3; dd1++) {
578 for (
int dd2 = 0; dd2 < 3; dd2++) {
579 activeVariables(9 + dd1 * 3 + dd2) = (*ptrH)[gg](dd1, dd2);
583 CHKERR dAta.materialAdoublePtr->setUserActiveVariables(activeVariables);
596 dAta(data),
commonData(common_data), aLe(false) {}
599 int row_side, EntityType row_type,
605 if (!dAta.forcesOnlyOnEntitiesRow.empty()) {
606 iNdices.resize(nb_dofs,
false);
608 indices_ptr = &iNdices[0];
610 VectorDofs::iterator dit = dofs.begin();
611 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
612 if (dAta.forcesOnlyOnEntitiesRow.find((*dit)->getEnt()) ==
613 dAta.forcesOnlyOnEntitiesRow.end()) {
624 int row_side, EntityType row_type,
628 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
633 const int nb_dofs = row_data.
getIndices().size();
636 if ((
unsigned int)nb_dofs > 3 * row_data.
getN().size2()) {
637 SETERRQ(PETSC_COMM_SELF, 1,
"data inconsistency");
639 const int nb_base_functions = row_data.
getN().size2();
640 const int nb_gauss_pts = row_data.
getN().size1();
642 nf.resize(nb_dofs,
false);
649 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
650 double val = getVolume() * getGaussPts()(3, gg);
653 &stress(0, 0), &stress(0, 1), &stress(0, 2), &stress(1, 0),
654 &stress(1, 1), &stress(1, 2), &stress(2, 0), &stress(2, 1),
658 for (; bb != nb_dofs / 3; bb++) {
659 rhs(
i) += val * t3(
i,
j) * diff_base_functions(
j);
661 ++diff_base_functions;
663 for (; bb != nb_base_functions; bb++) {
664 ++diff_base_functions;
668 CHKERR aSemble(row_side, row_type, row_data);
680 dAta(data),
commonData(common_data), ghostVec(ghost_vec, true),
681 fieldDisp(field_disp) {}
684 int row_side, EntityType row_type,
688 if (row_type != MBVERTEX)
690 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
695 std::vector<MatrixDouble> &
F =
697 dAta.materialDoublePtr->F.resize(3, 3,
false);
701 for (
unsigned int gg = 0; gg != row_data.
getN().size1(); ++gg) {
702 double val = getVolume() * getGaussPts()(3, gg);
703 noalias(dAta.materialDoublePtr->F) =
F[gg];
705 for (
int dd = 0; dd < 3; dd++) {
706 dAta.materialDoublePtr->F(dd, dd) += 1;
709 int nb_active_variables = 0;
710 CHKERR dAta.materialDoublePtr->setUserActiveVariables(nb_active_variables);
711 CHKERR dAta.materialDoublePtr->calculateElasticEnergy(
712 dAta, getNumeredEntFiniteElementPtr());
713 energy += val * dAta.materialDoublePtr->eNergy;
716 CHKERR VecSetValue(ghostVec, 0, energy, ADD_VALUES);
725 dAta(data),
commonData(common_data), aLe(false) {}
738 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
742 &jac_stress(3 * 0 + 0, S + 0), &jac_stress(3 * 0 + 0, S + 1),
743 &jac_stress(3 * 0 + 0, S + 2), &jac_stress(3 * 0 + 1, S + 0),
744 &jac_stress(3 * 0 + 1, S + 1), &jac_stress(3 * 0 + 1, S + 2),
745 &jac_stress(3 * 0 + 2, S + 0), &jac_stress(3 * 0 + 2, S + 1),
746 &jac_stress(3 * 0 + 2, S + 2), &jac_stress(3 * 1 + 0, S + 0),
747 &jac_stress(3 * 1 + 0, S + 1), &jac_stress(3 * 1 + 0, S + 2),
748 &jac_stress(3 * 1 + 1, S + 0), &jac_stress(3 * 1 + 1, S + 1),
749 &jac_stress(3 * 1 + 1, S + 2), &jac_stress(3 * 1 + 2, S + 0),
750 &jac_stress(3 * 1 + 2, S + 1), &jac_stress(3 * 1 + 2, S + 2),
751 &jac_stress(3 * 2 + 0, S + 0), &jac_stress(3 * 2 + 0, S + 1),
752 &jac_stress(3 * 2 + 0, S + 2), &jac_stress(3 * 2 + 1, S + 0),
753 &jac_stress(3 * 2 + 1, S + 1), &jac_stress(3 * 2 + 1, S + 2),
754 &jac_stress(3 * 2 + 2, S + 0), &jac_stress(3 * 2 + 2, S + 1),
755 &jac_stress(3 * 2 + 2, S + 2));
757 &jac_stress(3 * 0 + 0, S + 3), &jac_stress(3 * 0 + 0, S + 4),
758 &jac_stress(3 * 0 + 0, S + 5), &jac_stress(3 * 0 + 1, S + 3),
759 &jac_stress(3 * 0 + 1, S + 4), &jac_stress(3 * 0 + 1, S + 5),
760 &jac_stress(3 * 0 + 2, S + 3), &jac_stress(3 * 0 + 2, S + 4),
761 &jac_stress(3 * 0 + 2, S + 5), &jac_stress(3 * 1 + 0, S + 3),
762 &jac_stress(3 * 1 + 0, S + 4), &jac_stress(3 * 1 + 0, S + 5),
763 &jac_stress(3 * 1 + 1, S + 3), &jac_stress(3 * 1 + 1, S + 4),
764 &jac_stress(3 * 1 + 1, S + 5), &jac_stress(3 * 1 + 2, S + 3),
765 &jac_stress(3 * 1 + 2, S + 4), &jac_stress(3 * 1 + 2, S + 5),
766 &jac_stress(3 * 2 + 0, S + 3), &jac_stress(3 * 2 + 0, S + 4),
767 &jac_stress(3 * 2 + 0, S + 5), &jac_stress(3 * 2 + 1, S + 3),
768 &jac_stress(3 * 2 + 1, S + 4), &jac_stress(3 * 2 + 1, S + 5),
769 &jac_stress(3 * 2 + 2, S + 3), &jac_stress(3 * 2 + 2, S + 4),
770 &jac_stress(3 * 2 + 2, S + 5));
772 &jac_stress(3 * 0 + 0, S + 6), &jac_stress(3 * 0 + 0, S + 7),
773 &jac_stress(3 * 0 + 0, S + 8), &jac_stress(3 * 0 + 1, S + 6),
774 &jac_stress(3 * 0 + 1, S + 7), &jac_stress(3 * 0 + 1, S + 8),
775 &jac_stress(3 * 0 + 2, S + 6), &jac_stress(3 * 0 + 2, S + 7),
776 &jac_stress(3 * 0 + 2, S + 8), &jac_stress(3 * 1 + 0, S + 6),
777 &jac_stress(3 * 1 + 0, S + 7), &jac_stress(3 * 1 + 0, S + 8),
778 &jac_stress(3 * 1 + 1, S + 6), &jac_stress(3 * 1 + 1, S + 7),
779 &jac_stress(3 * 1 + 1, S + 8), &jac_stress(3 * 1 + 2, S + 6),
780 &jac_stress(3 * 1 + 2, S + 7), &jac_stress(3 * 1 + 2, S + 8),
781 &jac_stress(3 * 2 + 0, S + 6), &jac_stress(3 * 2 + 0, S + 7),
782 &jac_stress(3 * 2 + 0, S + 8), &jac_stress(3 * 2 + 1, S + 6),
783 &jac_stress(3 * 2 + 1, S + 7), &jac_stress(3 * 2 + 1, S + 8),
784 &jac_stress(3 * 2 + 2, S + 6), &jac_stress(3 * 2 + 2, S + 7),
785 &jac_stress(3 * 2 + 2, S + 8));
789 &jac(0, 0), &jac(1, 0), &jac(2, 0), &jac(3, 0), &jac(4, 0), &jac(5, 0),
790 &jac(6, 0), &jac(7, 0), &jac(8, 0));
792 &jac(0, 1), &jac(1, 1), &jac(2, 1), &jac(3, 1), &jac(4, 1), &jac(5, 1),
793 &jac(6, 1), &jac(7, 1), &jac(8, 1));
795 &jac(0, 2), &jac(1, 2), &jac(2, 2), &jac(3, 2), &jac(4, 2), &jac(5, 2),
796 &jac(6, 2), &jac(7, 2), &jac(8, 2));
798 diff_ptr, &diff_ptr[1], &diff_ptr[2]);
799 for (
int dd = 0; dd != nb_col / 3; ++dd) {
800 t2_1_0(
i,
j) += t3_1_0(
i,
j,
k) * diff(
k);
801 t2_1_1(
i,
j) += t3_1_1(
i,
j,
k) * diff(
k);
802 t2_1_2(
i,
j) += t3_1_2(
i,
j,
k) * diff(
k);
817 int row_side,
int col_side, EntityType row_type, EntityType col_type,
825 int *row_indices_ptr = &row_data.
getIndices()[0];
826 int *col_indices_ptr = &col_data.
getIndices()[0];
828 if (!dAta.forcesOnlyOnEntitiesRow.empty()) {
829 rowIndices.resize(nb_row,
false);
831 row_indices_ptr = &rowIndices[0];
833 VectorDofs::iterator dit = dofs.begin();
834 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
835 if (dAta.forcesOnlyOnEntitiesRow.find((*dit)->getEnt()) ==
836 dAta.forcesOnlyOnEntitiesRow.end()) {
842 if (!dAta.forcesOnlyOnEntitiesCol.empty()) {
843 colIndices.resize(nb_col,
false);
845 col_indices_ptr = &colIndices[0];
847 VectorDofs::iterator dit = dofs.begin();
848 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
849 if (dAta.forcesOnlyOnEntitiesCol.find((*dit)->getEnt()) ==
850 dAta.forcesOnlyOnEntitiesCol.end()) {
857 col_indices_ptr, &
k(0, 0), ADD_VALUES);
860 if (row_side != col_side || row_type != col_type) {
865 if (!dAta.forcesOnlyOnEntitiesCol.empty()) {
866 rowIndices.resize(nb_row,
false);
868 row_indices_ptr = &rowIndices[0];
870 VectorDofs::iterator dit = dofs.begin();
871 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
872 if (dAta.forcesOnlyOnEntitiesCol.find((*dit)->getEnt()) ==
873 dAta.forcesOnlyOnEntitiesCol.end()) {
879 if (!dAta.forcesOnlyOnEntitiesRow.empty()) {
880 colIndices.resize(nb_col,
false);
882 col_indices_ptr = &colIndices[0];
884 VectorDofs::iterator dit = dofs.begin();
885 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
886 if (dAta.forcesOnlyOnEntitiesRow.find((*dit)->getEnt()) ==
887 dAta.forcesOnlyOnEntitiesRow.end()) {
893 trans_k.resize(nb_col, nb_row,
false);
894 noalias(trans_k) = trans(
k);
896 row_indices_ptr, &trans_k(0, 0), ADD_VALUES);
903 int row_side,
int col_side, EntityType row_type, EntityType col_type,
915 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
921 const int nb_gauss_pts = row_data.
getN().size1();
927 k.resize(nb_row, nb_col,
false);
929 jac.resize(9, nb_col,
false);
931 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
932 CHKERR getJac(col_data, gg);
933 double val = getVolume() * getGaussPts()(3, gg);
935 &jac(3 * 0 + 0, 0), &jac(3 * 0 + 0, 1), &jac(3 * 0 + 0, 2),
936 &jac(3 * 0 + 1, 0), &jac(3 * 0 + 1, 1), &jac(3 * 0 + 1, 2),
937 &jac(3 * 0 + 2, 0), &jac(3 * 0 + 2, 1), &jac(3 * 0 + 2, 2),
938 &jac(3 * 1 + 0, 0), &jac(3 * 1 + 0, 1), &jac(3 * 1 + 0, 2),
939 &jac(3 * 1 + 1, 0), &jac(3 * 1 + 1, 1), &jac(3 * 1 + 1, 2),
940 &jac(3 * 1 + 2, 0), &jac(3 * 1 + 2, 1), &jac(3 * 1 + 2, 2),
941 &jac(3 * 2 + 0, 0), &jac(3 * 2 + 0, 1), &jac(3 * 2 + 0, 2),
942 &jac(3 * 2 + 1, 0), &jac(3 * 2 + 1, 1), &jac(3 * 2 + 1, 2),
943 &jac(3 * 2 + 2, 0), &jac(3 * 2 + 2, 1), &jac(3 * 2 + 2, 2));
944 for (
int cc = 0; cc != nb_col / 3; cc++) {
947 &
k(0, 3 * cc + 0), &
k(0, 3 * cc + 1), &
k(0, 3 * cc + 2),
948 &
k(1, 3 * cc + 0), &
k(1, 3 * cc + 1), &
k(1, 3 * cc + 2),
949 &
k(2, 3 * cc + 0), &
k(2, 3 * cc + 1), &
k(2, 3 * cc + 2), 3 * nb_col);
950 for (
int rr = 0; rr != nb_row / 3; rr++) {
951 lhs(
i,
j) += val * t3_1(
i,
m,
j) * diff_base_functions(
m);
952 ++diff_base_functions;
959 CHKERR aSemble(row_side, col_side, row_type, col_type, row_data, col_data);
977 int row_side,
int col_side, EntityType row_type, EntityType col_type,
985 int *row_indices_ptr = &row_data.
getIndices()[0];
986 if (!dAta.forcesOnlyOnEntitiesRow.empty()) {
987 rowIndices.resize(nb_row,
false);
989 row_indices_ptr = &rowIndices[0];
991 VectorDofs::iterator dit = dofs.begin();
992 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
993 if (dAta.forcesOnlyOnEntitiesRow.find((*dit)->getEnt()) ==
994 dAta.forcesOnlyOnEntitiesRow.end()) {
1000 int *col_indices_ptr = &col_data.
getIndices()[0];
1001 if (!dAta.forcesOnlyOnEntitiesCol.empty()) {
1002 colIndices.resize(nb_col,
false);
1004 col_indices_ptr = &colIndices[0];
1006 VectorDofs::iterator dit = dofs.begin();
1007 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
1008 if (dAta.forcesOnlyOnEntitiesCol.find((*dit)->getEnt()) ==
1009 dAta.forcesOnlyOnEntitiesCol.end()) {
1010 colIndices[ii] = -1;
1024 col_indices_ptr, &
k(0, 0), ADD_VALUES);
1031 int tag,
bool jacobian,
bool ale)
1033 jacobian, ale, false) {}
1040 CHKERR dAta.materialAdoublePtr->calculatesIGma_EshelbyStress(
1041 dAta, getNumeredEntFiniteElementPtr());
1043 auto &t_sIGma = dAta.materialAdoublePtr->t_sIGma;
1044 auto &t_invH = dAta.materialAdoublePtr->t_invH;
1045 t_sIGma(
i,
j) = t_sIGma(
i,
k) * t_invH(
j,
k);
1046 t_sIGma(
i,
j) *= dAta.materialAdoublePtr->detH;
1050 for (
int dd1 = 0; dd1 < 3; dd1++) {
1051 for (
int dd2 = 0; dd2 < 3; dd2++) {
1052 dAta.materialAdoublePtr->sIGma(dd1, dd2) >>=
1088 materialAdoublePtr) {
1091 if (!materialDoublePtr) {
1093 "Pointer for materialDoublePtr not allocated");
1095 if (!materialAdoublePtr) {
1097 "Pointer for materialAdoublePtr not allocated");
1103 CHKERR it->getAttributeDataStructure(mydata);
1104 int id = it->getMeshsetId();
1111 setOfBlocks[id].materialDoublePtr = materialDoublePtr;
1112 setOfBlocks[id].materialAdoublePtr = materialAdoublePtr;
1119 const std::string element_name,
1120 const std::string spatial_position_field_name,
1121 const std::string material_position_field_name,
const bool ale) {
1126 element_name, spatial_position_field_name);
1128 element_name, spatial_position_field_name);
1130 element_name, spatial_position_field_name);
1134 element_name, material_position_field_name);
1136 element_name, material_position_field_name);
1139 element_name, material_position_field_name);
1142 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
1152 const std::string spatial_position_field_name,
1153 const std::string material_position_field_name,
const bool ale,
1154 const bool field_disp) {
1167 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
1170 spatial_position_field_name, sit->second,
commonData,
tAg,
false, ale,
1173 spatial_position_field_name, sit->second,
commonData));
1200 spatial_position_field_name, sit->second,
commonData,
tAg,
true, ale,
1203 spatial_position_field_name, spatial_position_field_name, sit->second,
static MoFEMErrorCode calculateEnergy(DM dm, boost::shared_ptr< map< int, BlockData > > block_sets_ptr, const std::string x_field, const std::string X_field, const bool ale, const bool field_disp, SmartPetscObj< Vec > &v_energy_ptr)
static MoFEMErrorCode get_jac(EntitiesFieldData::EntData &col_data, int gg, MatrixDouble &jac_stress, MatrixDouble &jac)
Operators and data structures for non-linear elastic analysis.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MAT_ELASTICSET
block name is "MAT_ELASTIC"
@ MOFEM_OPERATION_UNSUCCESSFUL
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual bool check_field(const std::string &name) const =0
check if field is in database
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
const double n
refractive index of diffusive medium
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
MatrixShallowArrayAdaptor< double > MatrixAdaptor
Matrix adaptor.
VectorShallowArrayAdaptor< double > VectorAdaptor
implementation of Data Operators for Forces and Sources
MoFEMErrorCode invertTensor3by3(ublas::matrix< T, L, A > &jac_data, ublas::vector< T, A > &det_data, ublas::matrix< T, L, A > &inv_jac_data)
Calculate inverse of tensor rank 2 at integration points.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
static auto determinantTensor3by3(T &t)
Calculate the determinant of a 3x3 matrix or a tensor of rank 2.
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.
ublas::vector< FEDofEntity *, DofsAllocator > VectorDofs
constexpr auto field_name
FTensor::Index< 'm', 3 > m
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
bool sYmm
If true assume that matrix is symmetric structure.
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
MatrixDouble & getDiffN(const FieldApproximationBase base)
get derivatives of base functions
auto getFTensor1FieldData()
Return FTensor of rank 1, i.e. vector from field data coefficients.
auto getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
MatrixDouble & getN(const FieldApproximationBase base)
get base functions this return matrix (nb. of rows is equal to nb. of Gauss pts, nb....
const VectorDouble & getFieldData() const
Get DOF values on entity.
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0FieldData()
Return scalar files as a FTensor of rank 0.
const VectorDofs & getFieldDofs() const
Get DOF data structures (const version)
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
boost::ptr_deque< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
Elastic material data structure.
intrusive_ptr for managing petsc objects
FTensor::Tensor2< double *, 3, 3 > & getJac()
get element Jacobian
Volume finite element base.
data for calculation heat conductivity and heat capacity elements
common data used by volume elements
std::vector< VectorDouble > jacEnergy
std::vector< MatrixDouble > jacStress
this is simply material tangent operator
std::vector< double > eNergy
std::vector< VectorDouble > hessianEnergy
std::vector< MatrixDouble3by3 > sTress
std::map< std::string, std::vector< MatrixDouble > > gradAtGaussPts
Implementation of elastic (non-linear) St. Kirchhoff equation.
MoFEMErrorCode preProcess()
Pre-processing function executed at loop initialization.
MoFEMErrorCode postProcess()
Post-processing function executed at loop completion.
MyVolumeFE(MoFEM::Interface &m_field)
int getRule(int order)
it is used to calculate nb. of Gauss integration points
OpEnergy(const std::string field_name, BlockData &data, CommonData &common_data, SmartPetscObj< Vec > ghost_vec, bool field_disp)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
OpGetCommonDataAtGaussPts(const std::string field_name, CommonData &common_data)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
operator calculating deformation gradient
OpGetDataAtGaussPts(const std::string field_name, std::vector< VectorDouble > &values_at_gauss_pts, std::vector< MatrixDouble > &gradient_at_gauss_pts)
virtual MoFEMErrorCode playTag(const int gg)
Play ADOL-C tape.
OpJacobianEnergy(const std::string field_name, BlockData &data, CommonData &common_data, int tag, bool gradient, bool hessian, bool ale, bool field_disp)
virtual MoFEMErrorCode recordTag(const int gg)
Record ADOL-C tape.
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
virtual MoFEMErrorCode calculateEnergy(const int gg)
Calculate Paola-Kirchhoff I stress.
MoFEMErrorCode calculateStress(const int gg)
Calculate Paola-Kirchhoff I stress.
OpJacobianEshelbyStress(const std::string field_name, BlockData &data, CommonData &common_data, int tag, bool jacobian, bool ale)
Operator performs automatic differentiation.
virtual MoFEMErrorCode recordTag(const int gg)
Record ADOL-C tape.
virtual MoFEMErrorCode playTag(const int gg)
Play ADOL-C tape.
OpJacobianPiolaKirchhoffStress(const std::string field_name, BlockData &data, CommonData &common_data, int tag, bool jacobian, bool ale, bool field_disp)
Construct operator to calculate Piola-Kirchhoff stress or its derivatives over gradient deformation.
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
Calculate stress or jacobian at gauss points.
virtual MoFEMErrorCode calculateStress(const int gg)
Calculate Paola-Kirchhoff I stress.
OpLhsEshelby_dX(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data)
OpLhsEshelby_dx(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data)
OpLhsPiolaKirchhoff_dX(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data)
MoFEMErrorCode aSemble(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
virtual MoFEMErrorCode aSemble(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
OpLhsPiolaKirchhoff_dx(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data)
OpRhsEshelbyStress(const std::string field_name, BlockData &data, CommonData &common_data)
virtual MoFEMErrorCode aSemble(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
OpRhsPiolaKirchhoff(const std::string field_name, BlockData &data, CommonData &common_data)
MyVolumeFE feRhs
calculate right hand side for tetrahedral elements
NonlinearElasticElement(MoFEM::Interface &m_field, short int tag)
MoFEMErrorCode addElement(const std::string element_name, const std::string spatial_position_field_name, const std::string material_position_field_name="MESH_NODE_POSITIONS", const bool ale=false)
std::map< int, BlockData > setOfBlocks
maps block set id with appropriate BlockData
FTensor::Index< 'k', 3 > k
FTensor::Index< 'j', 3 > j
MoFEM::Interface & mField
MoFEMErrorCode setBlocks(boost::shared_ptr< FunctionsToCalculatePiolaKirchhoffI< double > > materialDoublePtr, boost::shared_ptr< FunctionsToCalculatePiolaKirchhoffI< adouble > > materialAdoublePtr)
MyVolumeFE feEnergy
calculate elastic energy
FTensor::Index< 'i', 3 > i
MoFEMErrorCode setOperators(const std::string spatial_position_field_name, const std::string material_position_field_name="MESH_NODE_POSITIONS", const bool ale=false, const bool field_disp=false)
Set operators to calculate left hand tangent matrix and right hand residual.