15 #ifndef __CONSTANT_AREA_HPP__
16 #define __CONSTANT_AREA_HPP__
19 #error "MoFEM need to be compiled with ADOL-C"
62 std::string
field_name =
"LAMBDA_CRACKFRONT_AREA")
70 CHKERR FaceElementForcesAndSourcesCore::preProcess();
72 if (
petscB != PETSC_NULL) {
76 if (
petscF != PETSC_NULL) {
81 case CTX_TSSETIFUNCTION: {
83 snes_ctx = CTX_SNESSETFUNCTION;
88 case CTX_TSSETIJACOBIAN: {
90 snes_ctx = CTX_SNESSETJACOBIAN;
104 if (
petscQ != PETSC_NULL) {
105 if (
petscB == PETSC_NULL) {
107 "Matrix B should be set");
113 problemPtr->getName(),
COL,
117 CHKERR VecGhostUpdateBegin(
119 INSERT_VALUES, SCATTER_FORWARD);
122 INSERT_VALUES, SCATTER_FORWARD);
134 CHKERR FaceElementForcesAndSourcesCore::postProcess();
135 if (
petscQ != PETSC_NULL) {
136 if (
petscB == PETSC_NULL) {
138 "Matrix B should be set");
148 problemPtr->getName(),
COL, &Qv);
151 auto project_vectors_and_assemble = [
this, Qv](
auto dit) {
156 "Vector on row not found");
162 CHKERR VecGhostUpdateBegin(
168 CHKERR VecGhostUpdateBegin(
170 INSERT_VALUES, SCATTER_FORWARD);
173 INSERT_VALUES, SCATTER_FORWARD);
177 CHKERR VecGhostUpdateBegin(Qv, INSERT_VALUES, SCATTER_FORWARD);
178 CHKERR VecGhostUpdateEnd(Qv, INSERT_VALUES, SCATTER_FORWARD);
181 auto save_vec = [](std::string name,
Vec v) {
183 PetscViewerASCIIOpen(PETSC_COMM_WORLD, name.c_str(), &viewer);
184 PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);
186 PetscViewerPopFormat(viewer);
187 PetscViewerDestroy(&viewer);
190 "V_" + boost::lexical_cast<std::string>(dit->get()->getEnt()) +
194 "Qv_" + boost::lexical_cast<std::string>(dit->get()->getEnt()) +
201 CHKERR VecGetArray(Qv, &array);
202 vector<int> glob_idx;
204 int row = dit->get()->getPetscGlobalDofIdx();
209 int idx = diit->get()->getPetscGlobalDofIdx();
210 double val = array[diit->get()->getPetscGlobalDofIdx()];
211 glob_idx.push_back(idx);
215 &*glob_idx.begin(), &*vals.begin(), ADD_VALUES);
216 CHKERR VecRestoreArray(Qv, &array);
224 CHKERR project_vectors_and_assemble(dit);
290 ublas::matrix<TYPE>
A;
294 PetscErrorCode
sPin(ublas::matrix<TYPE> &spin, ublas::vector<TYPE> &vec) {
296 spin.resize(3, 3,
false);
297 std::fill(spin.data().begin(), spin.data().end(), 0);
298 spin(0, 1) = -vec[2];
299 spin(0, 2) = +vec[1];
300 spin(1, 0) = +vec[2];
301 spin(1, 2) = -vec[0];
302 spin(2, 0) = -vec[1];
303 spin(2, 1) = +vec[0];
309 Bksi.resize(3, 9,
false);
311 for (
int ii = 0; ii < 3; ++ii) {
312 for (
int jj = 0; jj < 3; ++jj) {
313 Bksi(jj, ii * 3 + jj) = data.getDiffN(gg)(ii, 0);
316 Beta.resize(3, 9,
false);
318 for (
int ii = 0; ii < 3; ++ii) {
319 for (
int jj = 0; jj < 3; ++jj) {
320 Beta(jj, ii * 3 + jj) = data.getDiffN(gg)(ii, 1);
332 for (
auto ii = 0; ii !=
Bksi.size1(); ++ii)
333 for (
auto jj = 0; jj !=
Bksi.size2(); ++jj)
335 for (
auto ii = 0; ii !=
Beta.size1(); ++ii)
336 for (
auto jj = 0; jj !=
Beta.size2(); ++jj)
356 for (
int dd = 0;
dd != 3; ++
dd) {
365 A.resize(3, 9,
false);
367 for (
auto ii = 0; ii !=
A.size1(); ++ii)
368 for (
auto jj = 0; jj !=
A.size2(); ++jj)
379 for (
int dd = 0;
dd != 9;
dd++) {
380 for (
int ii = 0; ii != 3; ii++) {
412 for (
int ii = 0; ii != 3; ++ii) {
413 t_crack_front_tangent(
i) =
tSpin(
i,
j) * t_area_increment(
j);
415 ++t_crack_front_tangent;
430 if (
type != MBVERTEX) {
434 int nb_dofs = data.getFieldData().size();
435 int nb_gauss_pts = data.getN().size1();
442 for (
int dd = 0;
dd != nb_dofs;
dd++) {
445 for (
int dd = 0;
dd != nb_dofs;
dd++) {
453 for (
int gg = 0; gg != nb_gauss_pts; ++gg) {
455 double val = getGaussPts()(2, gg) * 0.5;
467 for (
int dd = 0;
dd != nb_dofs;
dd++) {
491 int side, EntityType
type,
494 int nb_dofs = data.getIndices().size();
496 for (
int dd = 0;
dd != nb_dofs;
dd++) {
499 for (
int dd = 0;
dd != nb_dofs;
dd++) {
511 "LAMBDA_CRACKFRONT_AREA",
"MESH_NODE_POSITIONS",
513 AuxOp(tag, common_data) {
519 PetscErrorCode
doWork(
int row_side,
int col_side, EntityType row_type,
525 if (row_type != MBVERTEX) {
528 VectorInt &row_indices = row_data.getIndices();
529 const int nb_rows = row_indices.size();
532 VectorInt &col_indices = col_data.getIndices();
533 const int nb_cols = col_indices.size();
538 for (
int nn = 0; nn != 3; ++nn) {
539 if (row_indices[nn] != -1) {
540 if (row_data.getFieldDofs()[nn]->getEnt() != conn[nn]) {
542 "Data inconsistency");
545 for (
int dd = 0;
dd != 3; ++
dd) {
546 if (col_indices[3 * nn +
dd] != -1) {
547 if (col_data.getFieldDofs()[3 * nn +
dd]->getEnt() != conn[nn]) {
549 "Data inconsistency");
555 auto row_dofs = getFEMethod()->getRowDofsPtr();
556 for (
auto it = row_dofs->begin(); it != row_dofs->end(); ++it) {
557 int side = it->get()->getSideNumber();
558 if (conn[side] != it->get()->getEnt()) {
560 "Data inconsistency");
564 auto col_dofs = getFEMethod()->getColDofsPtr();
565 for (
auto it = col_dofs->begin(); it != col_dofs->end(); ++it) {
566 int side = it->get()->getSideNumber();
567 if (conn[side] != it->get()->getEnt()) {
569 "Data inconsistency");
573 cMat.resize(3, 9,
false);
578 int nb_dofs = col_data.getFieldData().size();
586 "ADOL-C function evaluation with error r = %d",
r);
589 auto check_isnormal = [](
double v) {
591 if (
v != 0 && !std::isnormal(
v)) {
593 "Not a number %3.4e",
v);
598 for (
int rr = 0; rr != nb_rows; rr++) {
599 if (row_indices[rr] != -1) {
611 nb_cols, &col_indices[0], &
cMat(0, 0), ADD_VALUES);
613 for (
int rr = 0; rr != nb_rows; ++rr) {
614 if (row_indices[rr] != -1) {
618 "Vector for given DOF in map not found");
620 for (
int cc = 0; cc != nb_cols; ++cc) {
621 if (col_indices[cc] != -1) {
626 &col_indices[0], &
cMat(rr, 0), ADD_VALUES);
649 if (
type != MBVERTEX) {
653 int nb_dofs = data.getFieldData().size();
654 int nb_gauss_pts = data.getN().size1();
661 for (
int dd = 0;
dd != nb_dofs;
dd++) {
664 for (
int dd = 0;
dd != nb_dofs;
dd++) {
675 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
677 double val = getGaussPts()(2, gg) * 0.5;
688 for (
int dd = 0;
dd != nb_dofs;
dd++) {
705 "LAMBDA_CRACKFRONT_AREA_TANGENT",
"MESH_NODE_POSITIONS",
707 AuxOp(tag, common_data) {
713 PetscErrorCode
doWork(
int row_side,
int col_side, EntityType row_type,
719 if (row_type != MBVERTEX) {
723 VectorInt &row_indices = row_data.getIndices();
724 const int nb_rows = row_indices.size();
727 VectorInt &col_indices = col_data.getIndices();
728 const int nb_cols = col_indices.size();
731 cMat.resize(3, 9,
false);
736 int nb_dofs = col_data.getFieldData().size();
744 "ADOL-C function evaluation with error r = %d",
r);
751 const BitRefLevel bit = getFEMethod()->problemPtr->getBitRefLevel();
752 Range adj_side_elems;
754 bit, &face, 1, 3, adj_side_elems);
755 adj_side_elems = adj_side_elems.subset_by_type(MBTET);
756 if (adj_side_elems.size() != 1) {
758 "expect 1 tet but is %u", adj_side_elems.size());
761 int side_number, sense, offset;
763 side_elem, face, side_number, sense, offset);
776 auto check_isnormal = [](
double v) {
778 if (
v != 0 && !std::isnormal(
v)) {
784 for (
int rr = 0; rr != nb_rows; ++rr) {
785 if (row_indices[rr] != -1) {
800 nb_cols, &col_indices[0], &
cMat(0, 0), ADD_VALUES);
802 for (
int rr = 0; rr != nb_rows; ++rr) {
803 if (row_indices[rr] != -1) {
807 "Vector for given DOF in map not found");
809 for (
int cc = 0; cc != nb_cols; ++cc) {
810 if (col_indices[cc] != -1) {
815 &col_indices[0], &
cMat(rr, 0), ADD_VALUES);
826 #endif //__CONSTANT_AREA_HPP__