18 #include <moab/SpatialLocator.hpp>
19 #include <moab/ElemEvaluator.hpp>
22 using namespace MoFEM;
49 namespace po = boost::program_options;
75 auto set_gauss_pts = [
this]() {
77 gaussPts.swap(refGaussCoords);
78 const size_t nb_gauss_pts = gaussPts.size2();
79 dataH1.dataOnEntities[MBVERTEX][0].getN(
NOBASE).resize(nb_gauss_pts, 4);
81 &*dataH1.dataOnEntities[MBVERTEX][0].getN(
NOBASE).data().begin();
83 &gaussPts(2, 0), nb_gauss_pts);
87 std::bitset<4> singular_nodes_ids;
88 if (refineIntegration == PETSC_TRUE && singularElement) {
90 for (
int nn = 0; nn != 4; nn++) {
91 if (singularNodes[nn])
92 singular_nodes_ids.set(nn);
95 auto it_map_ref_coords =
mapRefCoords.find(singular_nodes_ids.to_ulong());
98 refGaussCoords = it_map_ref_coords->second;
106 int rule = (singularElement) ? 2 * (std::max(
order, 3) - 1) : 2 * (
order - 1);
117 gaussPts.resize(4, nb_gauss_pts,
false);
118 cblas_dcopy(nb_gauss_pts, &
QUAD_3D_TABLE[rule]->points[1], 4, &gaussPts(0, 0),
120 cblas_dcopy(nb_gauss_pts, &
QUAD_3D_TABLE[rule]->points[2], 4, &gaussPts(1, 0),
122 cblas_dcopy(nb_gauss_pts, &
QUAD_3D_TABLE[rule]->points[3], 4, &gaussPts(2, 0),
124 cblas_dcopy(nb_gauss_pts,
QUAD_3D_TABLE[rule]->weights, 1, &gaussPts(3, 0),
126 dataH1.dataOnEntities[MBVERTEX][0].getN(
NOBASE).resize(nb_gauss_pts, 4,
129 &*dataH1.dataOnEntities[MBVERTEX][0].getN(
NOBASE).data().begin();
130 cblas_dcopy(4 * nb_gauss_pts,
QUAD_3D_TABLE[rule]->points, 1, shape_ptr, 1);
138 if (!singularElement)
142 if (refineIntegration == PETSC_TRUE) {
144 const int max_level = refinementLevels;
148 double base_coords[] = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1};
150 for (
int nn = 0; nn != 4; nn++)
151 CHKERR moab_ref.create_vertex(&base_coords[3 * nn], nodes[nn]);
152 CHKERR moab_ref.create_element(MBTET, nodes, 4, tet);
158 Range singular_nodes;
159 for (
int nn = 0; nn != 4; nn++) {
160 if (singularNodes[nn]) {
162 CHKERR moab_ref.side_element(tet, 0, nn, ent);
163 singular_nodes.insert(ent);
168 if (singular_nodes.size() > 1) {
169 CHKERR moab_ref.create_meshset(MESHSET_SET, meshset);
170 for (
int ee = 0; ee != 6; ee++) {
171 if (singularEdges[ee]) {
173 CHKERR moab_ref.side_element(tet, 1, ee, ent);
174 CHKERR moab_ref.add_entities(meshset, &ent, 1);
181 for (
int ll = 0; ll != max_level; ll++) {
185 ->getEntitiesByTypeAndRefLevel(
BitRefLevel().set(ll),
188 CHKERR moab_ref.get_adjacencies(singular_nodes, 1,
true, ref_edges,
189 moab::Interface::UNION);
190 ref_edges = intersect(ref_edges, edges);
191 if (singular_nodes.size() > 1) {
193 CHKERR moab_ref.get_entities_by_type(meshset, MBEDGE, ents,
true);
194 ref_edges = intersect(ref_edges, ents);
198 ->getEntitiesByTypeAndRefLevel(
BitRefLevel().set(ll),
204 if (singular_nodes.size() > 1) {
206 ->updateMeshsetByEntitiesChildren(
207 meshset,
BitRefLevel().set(ll + 1), meshset, MBEDGE,
true);
213 ->getEntitiesByTypeAndRefLevel(
BitRefLevel().set(max_level),
215 refCoords.resize(tets.size(), 12,
false);
217 for (Range::iterator tit = tets.begin(); tit != tets.end(); tit++, tt++) {
220 CHKERR moab_ref.get_connectivity(*tit, conn, num_nodes,
false);
221 CHKERR moab_ref.get_coords(conn, num_nodes, &refCoords(tt, 0));
226 CHKERR moab_ref.create_meshset(MESHSET_SET, out_meshset);
227 CHKERR moab_ref.add_entities(out_meshset, tets);
228 std::string file_name =
229 "ref_tet_" + boost::lexical_cast<std::string>(nInTheLoop) +
".vtk";
230 CHKERR moab_ref.write_file(file_name.c_str(),
"VTK",
"", &out_meshset, 1);
231 CHKERR moab_ref.delete_entities(&out_meshset, 1);
237 const size_t nb_gauss_pts = gaussPts.size2();
238 refGaussCoords.resize(4, nb_gauss_pts * refCoords.size1());
241 for (
size_t tt = 0; tt != refCoords.size1(); tt++) {
242 double *tet_coords = &refCoords(tt, 0);
245 for (
size_t ggg = 0; ggg != nb_gauss_pts; ++ggg, ++gg) {
246 for (
int dd = 0;
dd != 3;
dd++) {
247 refGaussCoords(
dd, gg) = shape_n(ggg, 0) * tet_coords[3 * 0 +
dd] +
248 shape_n(ggg, 1) * tet_coords[3 * 1 +
dd] +
249 shape_n(ggg, 2) * tet_coords[3 * 2 +
dd] +
250 shape_n(ggg, 3) * tet_coords[3 * 3 +
dd];
252 refGaussCoords(3, gg) = gaussPts(3, ggg) * det;
256 mapRefCoords[singular_nodes_ids.to_ulong()] = refGaussCoords;
267 if (!singularElement) {
271 const int nb_dofs = data.getFieldData().size();
272 if (!nb_dofs &&
type == this->zeroType) {
273 this->dataPtr->resize(9, 0,
false);
279 const int nb_gauss_pts = data.getN().size1();
280 const int nb_base_functions = data.getN().size2();
281 ublas::matrix<double, ublas::row_major, DoubleAllocator> &mat =
283 if (
type == this->zeroType) {
284 mat.resize(9, nb_gauss_pts,
false);
287 auto diff_base_function = data.getFTensor1DiffN<3>();
288 auto gradients_at_gauss_pts = getFTensor2FromMat<3, 3>(mat);
292 int size = nb_dofs / 3;
296 double *inv_jac_ptr = &*invSJac.data().begin();
298 inv_jac_ptr, &inv_jac_ptr[1], &inv_jac_ptr[2], &inv_jac_ptr[3],
299 &inv_jac_ptr[4], &inv_jac_ptr[5], &inv_jac_ptr[6], &inv_jac_ptr[7],
302 for (
int gg = 0; gg < nb_gauss_pts; ++gg) {
303 auto field_data = data.getFTensor1FieldData<3>();
305 for (; bb < size; ++bb) {
306 gradients_at_gauss_pts(
I,
J) +=
308 (t_inv_singular_jacobian(
K,
J) * diff_base_function(
K));
310 ++diff_base_function;
313 for (; bb != nb_base_functions; ++bb)
314 ++diff_base_function;
315 ++gradients_at_gauss_pts;
316 ++t_inv_singular_jacobian;
323 OpGetCrackFrontDataAtGaussPts::doWork(
int side, EntityType
type,
327 if (!singularElement) {
332 const int nb_dofs = data.getFieldData().size();
333 const int nb_base_functions = data.getN().size2();
337 const int nb_gauss_pts = data.getN().size1();
338 const int rank = data.getFieldDofs()[0]->getNbOfCoeffs();
341 if (
type == zeroAtType) {
342 valuesAtGaussPts.resize(nb_gauss_pts);
343 gradientAtGaussPts.resize(nb_gauss_pts);
344 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
345 valuesAtGaussPts[gg].resize(rank,
false);
346 gradientAtGaussPts[gg].resize(rank, 3,
false);
348 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
349 valuesAtGaussPts[gg].clear();
350 gradientAtGaussPts[gg].clear();
354 auto base_function = data.getFTensor0N();
355 auto diff_base_functions = data.getFTensor1DiffN<3>();
360 double *inv_jac_ptr = &*invSJac.data().begin();
362 inv_jac_ptr, &inv_jac_ptr[1], &inv_jac_ptr[2], &inv_jac_ptr[3],
363 &inv_jac_ptr[4], &inv_jac_ptr[5], &inv_jac_ptr[6], &inv_jac_ptr[7],
368 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
369 auto field_data = data.getFTensor1FieldData<3>();
371 &valuesAtGaussPts[gg][1],
372 &valuesAtGaussPts[gg][2]);
374 &gradientAtGaussPts[gg](0, 0), &gradientAtGaussPts[gg](0, 1),
375 &gradientAtGaussPts[gg](0, 2), &gradientAtGaussPts[gg](1, 0),
376 &gradientAtGaussPts[gg](1, 1), &gradientAtGaussPts[gg](1, 2),
377 &gradientAtGaussPts[gg](2, 0), &gradientAtGaussPts[gg](2, 1),
378 &gradientAtGaussPts[gg](2, 2));
380 for (; bb != nb_dofs / 3; bb++) {
381 values(
i) += base_function * field_data(
i);
382 gradient(
i,
j) += field_data(
i) * (t_inv_singular_jacobian(
k,
j) *
383 diff_base_functions(
k));
384 ++diff_base_functions;
388 for (; bb != nb_base_functions; bb++) {
389 ++diff_base_functions;
392 ++t_inv_singular_jacobian;
398 "Not implemented for rank = %d", rank);
405 OpPostProcDisplacements::doWork(
int side, EntityType
type,
408 if (!singularElement ||
type != MBVERTEX) {
411 double def_VAL[3] = {0, 0, 0};
412 Tag th_singular_disp;
413 CHKERR postProcMesh.tag_get_handle(
"SINGULAR_DISP", 3, MB_TYPE_DOUBLE,
415 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
419 auto t_H = getFTensor2FromMat<3, 3>(*
H);
421 &singularDisp(0, 0), &singularDisp(0, 1), &singularDisp(0, 2));
423 for (
unsigned int gg = 0; gg != singularDisp.size1(); gg++) {
424 t_singular_current_disp(
i) = t_H(
i,
j) * t_singular_disp(
j);
425 CHKERR postProcMesh.tag_set_data(th_singular_disp, &mapGaussPts[gg], 1,
426 &t_singular_current_disp(0));
439 if (!singularElement)
442 if (invSJac.size2() != 9) {
444 "It looks that ho inverse of Jacobian is not calculated %d != 9",
447 double *t_inv_jac_ptr = &*invSJac.data().begin();
449 t_inv_jac_ptr, &t_inv_jac_ptr[1], &t_inv_jac_ptr[2], &t_inv_jac_ptr[3],
450 &t_inv_jac_ptr[4], &t_inv_jac_ptr[5], &t_inv_jac_ptr[6],
451 &t_inv_jac_ptr[7], &t_inv_jac_ptr[8], 9);
456 for (
unsigned int gg = 0; gg != getGaussPts().size2(); ++gg) {
457 getGaussPts()(3, gg) *= detS[gg];
463 unsigned int nb_gauss_pts = data.getN(bAse).size1();
464 if (nb_gauss_pts == 0)
466 if (invSJac.size1() != nb_gauss_pts) {
469 "It looks that ho inverse of Jacobian is not calculated %d != %d",
470 invSJac.size1(), nb_gauss_pts);
472 unsigned int nb_base_functions = data.getN(bAse).size2();
473 if (nb_base_functions == 0)
475 diffNinvJac.resize(nb_gauss_pts, 3 * nb_base_functions,
false);
476 double *t_inv_n_ptr = &*diffNinvJac.data().begin();
481 &data.getDiffN(bAse)(0, 0), &data.getDiffN(bAse)(0, 1),
482 &data.getDiffN(bAse)(0, 2), 3);
483 for (
unsigned int gg = 0; gg != nb_gauss_pts; ++gg) {
484 for (
unsigned int bb = 0; bb != nb_base_functions; ++bb) {
485 t_inv_diff_n(
i) = t_diff_n(
j) * t_inv_jac(
j,
i);
491 if (
type == MBVERTEX) {
492 data.getDiffN(bAse).resize(diffNinvJac.size1(), diffNinvJac.size2(),
495 data.getDiffN(bAse).
data().swap(diffNinvJac.data());
504 OpRhsBoneExplicitDerivariveWithHooke::OpRhsBoneExplicitDerivariveWithHooke(
505 HookeElement::DataAtIntegrationPts &common_data,
506 boost::shared_ptr<VectorDouble> rho_at_gauss_pts,
507 boost::shared_ptr<MatrixDouble> rho_grad_at_gauss_pts,
Range tets_in_block,
508 const double rho_0,
const double bone_n,
Range *forces_only_on_entities_row)
511 commonData(common_data), rhoAtGaussPts(rho_at_gauss_pts),
512 rhoGradAtGaussPts(rho_grad_at_gauss_pts), tetsInBlock(tets_in_block),
513 rHo0(rho_0), boneN(bone_n) {
514 if (forces_only_on_entities_row)
519 int row_side, EntityType row_type,
523 const int nb_dofs = row_data.getIndices().size();
530 const int nb_gauss_pts = row_data.getN().size1();
531 nF.resize(nb_dofs,
false);
538 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
541 const double denergy_drho =
543 auto t_base = row_data.getFTensor0N(gg, 0);
546 for (
int bb = 0; bb != nb_dofs / 3; bb++) {
547 t_nf(
i) += t_base * (
w * denergy_drho * t_rho_gradient(
i));
556 int *indices_ptr = &row_data.getIndices()[0];
558 iNdices.resize(nb_dofs,
false);
559 noalias(
iNdices) = row_data.getIndices();
561 auto &dofs = row_data.getFieldDofs();
562 auto dit = dofs.begin();
563 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
564 if (
auto dof = (*dit)) {
582 HookeElement::DataAtIntegrationPts &common_data,
583 boost::shared_ptr<VectorDouble> rho_at_gauss_pts,
584 boost::shared_ptr<MatrixDouble> diff_rho_at_gauss_pts,
585 boost::shared_ptr<MatrixDouble> diff_diff_rho_at_gauss_pts,
587 const double bone_n,
Range *forces_only_on_entities_row)
589 "MESH_NODE_POSITIONS",
"MESH_NODE_POSITIONS",
591 commonData(common_data), rhoAtGaussPts(rho_at_gauss_pts),
592 diffRhoAtGaussPts(diff_rho_at_gauss_pts),
593 diffDiffRhoAtGaussPts(diff_diff_rho_at_gauss_pts),
594 singularDispl(singular_displ), tetsInBlock(tets_in_block), rHo0(rho_0),
596 if (forces_only_on_entities_row)
601 int row_side,
int col_side, EntityType row_type, EntityType col_type,
609 const int row_nb_dofs = row_data.getIndices().size();
613 const int col_nb_dofs = col_data.getIndices().size();
617 nA.resize(row_nb_dofs, col_nb_dofs,
false);
620 const int nb_gauss_pts = row_data.getN().size1();
621 auto t_invH = getFTensor2FromMat<3, 3>(*
commonData.invHMat);
622 auto t_h = getFTensor2FromMat<3, 3>(*
commonData.hMat);
623 auto t_H = getFTensor2FromMat<3, 3>(*
commonData.HMat);
628 auto t_cauchy_stress =
629 getFTensor2SymmetricFromMat<3>(*
commonData.cauchyStressMat);
634 auto t_initial_singular_displacement = getFTensor1FromMat<3>(
singularDispl);
635 auto t_row_diff_n = row_data.getFTensor1DiffN<3>();
637 const int nb_row_base = row_data.getN().size2();
646 for (
int gg = 0; gg != nb_gauss_pts; ++gg) {
649 const double drho_coeff = (
boneN /
rho);
650 const double denergy_drho = energy * drho_coeff;
651 const double denergy_drho_drho =
654 t_F_dX(
i,
j,
k,
l) = -(t_h(
i,
m) * t_invH(
m,
k)) * t_H(
l,
j);
657 t_energy_dX(
k,
l) = t_F_dX(
i,
j,
k,
l) * t_cauchy_stress(
i,
j);
665 t_rho_dX_pulled(
i) = t_diff_rho(
j) * t_invH(
j,
i);
667 t_energy_dX(
i,
j) * t_rho_dX_pulled(
j) * val * drho_coeff;
668 t_psi_dX_rho_dX_pulled(
j) = t_psi_dX_rho_dX(
i) * t_invH(
i,
j);
670 auto t_row_base = row_data.getFTensor0N(gg, 0);
672 for (; rr != row_nb_dofs / 3; rr++) {
674 &
nA(3 * rr + 0, 0), &
nA(3 * rr + 0, 1), &
nA(3 * rr + 0, 2),
675 &
nA(3 * rr + 1, 0), &
nA(3 * rr + 1, 1), &
nA(3 * rr + 1, 2),
676 &
nA(3 * rr + 2, 0), &
nA(3 * rr + 2, 1), &
nA(3 * rr + 2, 2), 3);
679 t_a(
i,
j) = val * denergy_drho_drho * t_diff_rho(
i) * t_diff_rho(
j);
680 t_a(
i,
j) += val * denergy_drho * t_diff_diff_rho(
i,
j);
681 t_b(
i) = t_row_base * val * denergy_drho * t_diff_rho(
i);
683 auto t_col_base = col_data.getFTensor0N(gg, 0);
684 auto t_col_diff_base = col_data.getFTensor1DiffN<3>(gg, 0);
686 for (
int cc = 0; cc != col_nb_dofs / 3; cc++) {
688 t_mat(
i,
j) += t_row_base * t_a(
i,
j) * t_col_base;
689 t_mat(
i,
j) += t_row_base * t_a(
i,
j) * t_col_diff_base(
k) *
690 t_initial_singular_displacement(
k);
692 t_mat(
i,
j) += t_b(
i) * (t_invH(
l,
j) * t_col_diff_base(
l));
694 t_row_base * t_psi_dX_rho_dX_pulled(
i) * t_col_diff_base(
j);
702 for (; rr != nb_row_base; ++rr) {
718 ++t_initial_singular_displacement;
722 int *indices_ptr = &row_data.getIndices()[0];
725 noalias(
iNdices) = row_data.getIndices();
727 auto &dofs = row_data.getFieldDofs();
728 auto dit = dofs.begin();
729 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
730 if (
auto dof = (*dit)) {
740 col_nb_dofs, &*col_data.getIndices().begin(),
741 &*
nA.data().begin(), ADD_VALUES);
747 HookeElement::DataAtIntegrationPts &common_data,
748 boost::shared_ptr<VectorDouble> rho_at_gauss_pts,
749 boost::shared_ptr<MatrixDouble> diff_rho_at_gauss_pts,
750 boost::shared_ptr<MatrixDouble> diff_diff_rho_at_gauss_pts,
752 const double bone_n,
Range *forces_only_on_entities_row)
756 commonData(common_data), rhoAtGaussPts(rho_at_gauss_pts),
757 diffRhoAtGaussPts(diff_rho_at_gauss_pts),
758 diffDiffRhoAtGaussPts(diff_diff_rho_at_gauss_pts),
759 singularDispl(singular_displ), tetsInBlock(tets_in_block), rHo0(rho_0),
761 if (forces_only_on_entities_row)
766 int row_side,
int col_side, EntityType row_type, EntityType col_type,
773 const int row_nb_dofs = row_data.getIndices().size();
777 const int col_nb_dofs = col_data.getIndices().size();
781 nA.resize(row_nb_dofs, col_nb_dofs,
false);
784 const int nb_row_base = row_data.getN().size2();
785 const int nb_gauss_pts = row_data.getN().size1();
787 auto t_initial_singular_displacement = getFTensor1FromMat<3>(
singularDispl);
788 auto t_row_diff_n = row_data.getFTensor1DiffN<3>();
790 auto t_H = getFTensor2FromMat<3, 3>(*(
commonData.HMat));
791 auto t_h = getFTensor2FromMat<3, 3>(*(
commonData.hMat));
793 auto t_invH = getFTensor2FromMat<3, 3>(*
commonData.invHMat);
796 auto t_cauchy_stress =
797 getFTensor2SymmetricFromMat<3>(*(
commonData.cauchyStressMat));
809 for (
int gg = 0; gg != nb_gauss_pts; ++gg) {
812 auto t_row_base = row_data.getFTensor0N(gg, 0);
813 const double drho_coef = (
boneN /
rho);
816 for (; rr != row_nb_dofs / 3; ++rr) {
818 auto t_col_n = col_data.getFTensor0N(gg, 0);
819 auto t_col_diff_base = col_data.getFTensor1DiffN<3>(gg, 0);
822 &
nA(3 * rr + 0, 0), &
nA(3 * rr + 0, 1), &
nA(3 * rr + 0, 2),
823 &
nA(3 * rr + 1, 0), &
nA(3 * rr + 1, 1), &
nA(3 * rr + 1, 2),
824 &
nA(3 * rr + 2, 0), &
nA(3 * rr + 2, 1), &
nA(3 * rr + 2, 2), 3);
828 t_row_base * t_cauchy_stress(
i,
j) * t_diff_rho(
j) * val * drho_coef;
830 for (
int cc = 0; cc != col_nb_dofs / 3; cc++) {
832 t_mat(
i,
j) += t_a(
i) * (t_invH(
l,
j) * t_col_diff_base(
l));
842 for (; rr != nb_row_base; ++rr) {
854 ++t_initial_singular_displacement;
857 int *indices_ptr = &row_data.getIndices()[0];
860 noalias(
iNdices) = row_data.getIndices();
862 auto &dofs = row_data.getFieldDofs();
863 auto dit = dofs.begin();
864 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
865 if(
auto dof = (*dit)) {
875 col_nb_dofs, &*col_data.getIndices().begin(),
876 &*
nA.data().begin(), ADD_VALUES);
883 const Range &crack_front_nodes,
const Range &crack_front_nodes_edges,
884 const Range &crack_front_elements, PetscBool add_singularity,
886 boost::ptr_vector<MethodForForceScaling> &methods_op,
887 boost::ptr_vector<NeumannForcesSurface::MethodForAnalyticalForce>
888 &analytical_force_op)
891 tRis(tris), methodsOp(methods_op), analyticalForceOp(analytical_force_op),
892 volSideFe(m_field, set_singular_coordinates, crack_front_nodes,
893 crack_front_nodes_edges, crack_front_elements, add_singularity),
894 setSingularCoordinates(set_singular_coordinates) {}
901 if (data.getIndices().size() == 0)
903 EntityHandle ent = getNumeredEntFiniteElementPtr()->getEnt();
907 if (
type == MBVERTEX) {
911 int rank = data.getFieldDofs()[0]->getNbOfCoeffs();
912 int nb_row_dofs = data.getIndices().size() / rank;
914 Nf.resize(data.getIndices().size(),
false);
930 inv_jac_ptr, &inv_jac_ptr[1], &inv_jac_ptr[2], &inv_jac_ptr[3],
931 &inv_jac_ptr[4], &inv_jac_ptr[5], &inv_jac_ptr[6], &inv_jac_ptr[7],
934 double nrm = 2 * getArea();
936 sNrm.resize(data.getN().size1(),
false);
937 for (
unsigned int gg = 0; gg != data.getN().size1(); gg++) {
940 t_s_normal(
i) = det * t_inv_s_jac(
j,
i) * t_normal(
j) / nrm;
941 sNrm[gg] = sqrt(t_s_normal(
i) * t_s_normal(
i));
948 const auto &coords_at_gauss_pts = getCoordsAtGaussPts();
949 const auto &normals_at_gauss_pts = getNormalsAtGaussPts();
951 for (
unsigned int gg = 0; gg < data.getN().size1(); gg++) {
954 double val = getGaussPts()(2, gg);
955 val *= 0.5 * cblas_dnrm2(3, &getNormalsAtGaussPts()(gg, 0), 1);
956 for (
int dd = 0;
dd != 3;
dd++) {
957 coords[
dd] = coords_at_gauss_pts(gg,
dd);
958 normal[
dd] = normals_at_gauss_pts(gg,
dd);
961 for (
int dd = 0;
dd != 3;
dd++) {
967 for (boost::ptr_vector<
973 CHKERR vit->getForce(ent, coords, normal, force);
975 for (
int rr = 0; rr != 3; rr++) {
976 cblas_daxpy(nb_row_dofs, val * force[rr], &data.getN()(gg, 0), 1,
987 &data.getIndices()[0], &
Nf[0], ADD_VALUES);
994 const Range &crack_front_nodes,
const Range &crack_front_nodes_edges,
995 const Range &crack_front_elements, PetscBool add_singularity,
997 boost::ptr_vector<MethodForForceScaling> &methods_op,
998 boost::ptr_vector<NeumannForcesSurface::MethodForAnalyticalForce>
999 &analytical_force_op,
1000 Range *forces_only_on_entities_row)
1003 tRis(tris), methodsOp(methods_op), analyticalForceOp(analytical_force_op),
1004 volSideFe(m_field, set_singular_coordinates, crack_front_nodes,
1005 crack_front_nodes_edges, crack_front_elements, add_singularity),
1006 setSingularCoordinates(set_singular_coordinates) {
1013 volSideFe.meshPositionsFieldName =
"NONE";
1014 if (forces_only_on_entities_row) {
1024 if (data.getIndices().size() == 0)
1026 EntityHandle ent = getNumeredEntFiniteElementPtr()->getEnt();
1030 if (
type == MBVERTEX) {
1033 if (
type != MBVERTEX) {
1035 const EntityHandle ent = data.getFieldDofs()[0]->getEnt();
1036 int side_number, sense, offset;
1038 volSideFe.numeredEntFiniteElementPtr->getEnt(), ent, side_number,
1047 for (
unsigned int gg = 0; gg !=
volSideFe.gaussPts.size2(); gg++) {
1048 for (
int dd = 0;
dd != 3;
dd++) {
1056 CHKERR volSideFe.calHierarchicalBaseFunctionsOnElement(data.getBase());
1057 map<int, int> map_face_nodes;
1058 for (
unsigned int gg = 0; gg != data.getN().size1(); gg++) {
1059 for (
int nn = 0; nn != 3; nn++) {
1060 data.getN()(gg, nn) =
1062 .getN(data.getBase())(gg,
volSideFe.getFaceConnMap()[nn]);
1067 int rank = data.getFieldDofs()[0]->getNbOfCoeffs();
1068 int nb_row_base = data.getIndices().size() / rank;
1070 Nf.resize(data.getIndices().size(),
false);
1086 double *inv_jac_ptr = &*
volSideFe.invSJac.data().begin();
1088 inv_jac_ptr, &inv_jac_ptr[1], &inv_jac_ptr[2], &inv_jac_ptr[3],
1089 &inv_jac_ptr[4], &inv_jac_ptr[5], &inv_jac_ptr[6], &inv_jac_ptr[7],
1090 &inv_jac_ptr[8], 9);
1091 auto t_hg = getFTensor2FromMat<3, 3>(*
hG);
1092 auto t_normal = getFTensor1Normal();
1093 double nrm = 2 * getArea();
1095 sNrm.resize(data.getN().size1(),
false);
1096 for (
unsigned int gg = 0; gg != data.getN().size1(); gg++) {
1099 t_s_normal(
i) = det * t_inv_s_jac(
j,
i) * t_normal(
j) / nrm;
1100 sNrm[gg] = sqrt(t_s_normal(
i) * t_s_normal(
i));
1102 t_tmp(
i,
j) = t_hg(
i,
k) * t_inv_s_jac(
k,
j);
1103 t_hg(
i,
j) = t_tmp(
i,
j);
1112 auto t_hg = getFTensor2FromMat<3, 3>(*
hG);
1113 auto t_Hg = getFTensor2FromMat<3, 3>(*
HG);
1118 for (
unsigned int gg = 0; gg < data.getN().size1(); gg++) {
1121 double val = getGaussPts()(2, gg);
1122 val *= 0.5 * cblas_dnrm2(3, &getNormalsAtGaussPts()(gg, 0), 1);
1123 for (
int dd = 0;
dd != 3;
dd++) {
1124 coords[
dd] = getCoordsAtGaussPts()(gg,
dd);
1125 normal[
dd] = getNormalsAtGaussPts()(gg,
dd);
1128 for (
int dd = 0;
dd != 3;
dd++) {
1134 for (boost::ptr_vector<
1140 CHKERR vit->getForce(ent, coords, normal, force);
1147 t_F(
i,
k) = t_hg(
i,
j) * t_inv_Hg(
j,
k);
1148 t_ft_force(
i) = -t_F(
j,
i) * t_force(
j);
1150 for (
int rr = 0; rr != 3; rr++) {
1151 cblas_daxpy(nb_row_base, val * FTforce[rr], &data.getN()(gg, 0), 1,
1164 int nb_dofs = data.getIndices().size();
1165 int *indices_ptr = &data.getIndices()[0];
1167 iNdices.resize(nb_dofs,
false);
1168 noalias(
iNdices) = data.getIndices();
1170 auto &dofs = data.getFieldDofs();
1171 auto dit = dofs.begin();
1172 for (
int ii = 0; dit != dofs.end(); dit++, ii++) {
1173 if (
auto dof = (*dit)) {
1188 const std::string row_field,
const std::string col_field,
1189 boost::shared_ptr<HookeElement::DataAtIntegrationPts> &data_at_pts,
1190 boost::shared_ptr<VectorDouble> rho_at_gauss_pts,
1191 boost::shared_ptr<MatrixDouble> rho_grad_at_gauss_pts,
1192 const double rho_n,
const double rho_0,
1193 boost::shared_ptr<MatrixDouble> singular_displacement)
1195 dataAtPts(data_at_pts), rhoAtGaussPtsPtr(rho_at_gauss_pts),
1196 rhoGradAtGaussPtsPtr(rho_grad_at_gauss_pts),
1197 singularDisplacement(singular_displacement), rhoN(rho_n), rHo0(rho_0) {}
1200 int row_side,
int col_side, EntityType row_type, EntityType col_type,
1205 nbRows = row_data.getIndices().size();
1209 nbCols = col_data.getIndices().size();
1217 if (row_side == col_side && row_type == col_type) {
1235 &
m(
r + 0,
c + 0), &
m(
r + 0,
c + 1), &
m(
r + 0,
c + 2), &
m(
r + 1,
c + 0),
1236 &
m(
r + 1,
c + 1), &
m(
r + 1,
c + 2), &
m(
r + 2,
c + 0), &
m(
r + 2,
c + 1),
1245 double vol = getVolume();
1247 auto t_w = getFTensor0IntegrationWeight();
1249 auto t_row_diff_base = row_data.getFTensor1DiffN<3>();
1250 const int row_nb_base_fun = row_data.getN().size2();
1255 auto t_eshelby_stress =
1256 getFTensor2FromMat<3, 3>(*
dataAtPts->eshelbyStressMat);
1257 auto t_invH = getFTensor2FromMat<3, 3>(*
dataAtPts->invHMat);
1260 auto t_initial_singular_displacement =
1265 double a = t_w * vol * det_H[gg];
1266 const double stress_dho_coef = (
rhoN /
rho);
1269 for (; rr !=
nbRows / 3; ++rr) {
1271 auto t_m = get_tensor2(
K, 3 * rr, 0);
1274 t_row_diff_base_pulled(
i) = t_row_diff_base(
j) * t_invH(
j,
i);
1277 t_row_stress(
i) =
a * t_row_diff_base_pulled(
j) * t_eshelby_stress(
i,
j);
1279 t_a(
i,
k) = t_row_stress(
i) * stress_dho_coef * t_grad_rho(
k);
1281 auto t_col_diff_base = col_data.getFTensor1DiffN<3>(gg, 0);
1282 auto t_col_base = col_data.getFTensor0N(gg, 0);
1283 for (
int cc = 0; cc !=
nbCols / 3; ++cc) {
1286 t_a(
i,
k) * t_col_diff_base(
l) * t_initial_singular_displacement(
l);
1295 for (; rr != row_nb_base_fun; ++rr)
1298 ++t_initial_singular_displacement;
1314 const int *row_indices = &*row_data.getIndices().data().begin();
1315 const int *col_indices = &*col_data.getIndices().data().begin();
1318 Mat B = getFEMethod()->ksp_B != PETSC_NULL ? getFEMethod()->ksp_B
1319 : getFEMethod()->snes_B;
1322 &*
K.data().begin(), ADD_VALUES);
1327 transK.resize(
K.size2(),
K.size1(),
false);
1330 &*
transK.data().begin(), ADD_VALUES);
1337 const std::string row_field,
const std::string col_field,
1338 boost::shared_ptr<HookeElement::DataAtIntegrationPts> &data_at_pts,
1339 boost::shared_ptr<VectorDouble> rho_at_gauss_pts,
1340 boost::shared_ptr<MatrixDouble> rho_grad_at_gauss_pts,
1341 const double rho_n,
const double rho_0,
1342 boost::shared_ptr<MatrixDouble> singular_displacement)
1344 dataAtPts(data_at_pts), rhoAtGaussPtsPtr(rho_at_gauss_pts),
1345 rhoGradAtGaussPtsPtr(rho_grad_at_gauss_pts),
1346 singularDisplacement(singular_displacement), rhoN(rho_n), rHo0(rho_0) {}
1349 int row_side,
int col_side, EntityType row_type, EntityType col_type,
1354 nbRows = row_data.getIndices().size();
1358 nbCols = col_data.getIndices().size();
1366 if (row_side == col_side && row_type == col_type) {
1384 &
m(
r + 0,
c + 0), &
m(
r + 0,
c + 1), &
m(
r + 0,
c + 2), &
m(
r + 1,
c + 0),
1385 &
m(
r + 1,
c + 1), &
m(
r + 1,
c + 2), &
m(
r + 2,
c + 0), &
m(
r + 2,
c + 1),
1394 double vol = getVolume();
1396 auto t_w = getFTensor0IntegrationWeight();
1398 auto t_row_diff_base = row_data.getFTensor1DiffN<3>();
1399 const int row_nb_base_fun = row_data.getN().size2();
1404 auto t_cauchy_stress =
1405 getFTensor2SymmetricFromMat<3>(*(
dataAtPts->cauchyStressMat));
1406 auto t_invH = getFTensor2FromMat<3, 3>(*
dataAtPts->invHMat);
1409 auto t_initial_singular_displacement =
1414 double a = t_w * vol * det_H[gg];
1415 const double stress_dho_coef = (
rhoN /
rho);
1418 for (; rr !=
nbRows / 3; ++rr) {
1420 auto t_m = get_tensor2(
K, 3 * rr, 0);
1423 t_row_diff_base_pulled(
i) = t_row_diff_base(
j) * t_invH(
j,
i);
1426 t_row_stress(
i) =
a * t_row_diff_base_pulled(
j) * t_cauchy_stress(
i,
j);
1428 t_a(
i,
k) = t_row_stress(
i) * stress_dho_coef * t_grad_rho(
k);
1430 auto t_col_diff_base = col_data.getFTensor1DiffN<3>(gg, 0);
1431 auto t_col_base = col_data.getFTensor0N(gg, 0);
1432 for (
int cc = 0; cc !=
nbCols / 3; ++cc) {
1435 t_a(
i,
k) * t_col_diff_base(
l) * t_initial_singular_displacement(
l);
1444 for (; rr != row_nb_base_fun; ++rr)
1447 ++t_initial_singular_displacement;
1463 const int *row_indices = &*row_data.getIndices().data().begin();
1464 const int *col_indices = &*col_data.getIndices().data().begin();
1467 Mat B = getFEMethod()->ksp_B != PETSC_NULL ? getFEMethod()->ksp_B
1468 : getFEMethod()->snes_B;
1471 &*
K.data().begin(), ADD_VALUES);
1476 transK.resize(
K.size2(),
K.size1(),
false);
1479 &*
transK.data().begin(), ADD_VALUES);
1488 if (row_type != MBVERTEX)
1491 const int nb_integration_pts = getGaussPts().size2();
1511 auto t_material_positions = getFTensor1FromMat<3>(coords);
1512 auto t_mwls_material_positions = getFTensor1FromMat<3>(coords);
1516 singular_current_displacement.resize(3, nb_integration_pts,
false);
1517 singular_current_displacement.clear();
1522 auto t_inital_singular_displacement = getFTensor1FromMat<3>(
singularDisp);
1523 auto t_current_singular_displacement =
1524 getFTensor1FromMat<3>(singular_current_displacement);
1527 "Matrix for gradient of positions not allocated");
1529 for (
int gg = 0; gg != nb_integration_pts; gg++) {
1531 t_inital_singular_displacement(
i) = t_singular_displacement(
i);
1532 t_current_singular_displacement(
i) =
1533 t_H(
i,
j) * t_singular_displacement(
j);
1535 t_material_positions(
i) += t_current_singular_displacement(
i);
1537 ++t_material_positions;
1539 ++t_singular_displacement;
1540 ++t_inital_singular_displacement;
1541 ++t_current_singular_displacement;
1544 for (
int gg = 0; gg != nb_integration_pts; ++gg) {
1546 1 + t_mwls_material_positions(
i) *
1547 t_mwls_material_positions(
i);
1549 t_grad_rho(
i) = 2 * t_mwls_material_positions(
i);
1550 t_grad_grad_rho(0, 0) = 2.;
1551 t_grad_grad_rho(1, 1) = 2.;
1552 t_grad_grad_rho(2, 2) = 2.;
1555 ++t_mwls_material_positions;
1568 if (data.getFieldData().size() == 0)
1579 MB_TAG_CREAT | MB_TAG_SPARSE, &def_VAL);
1582 for (
int gg = 0; gg != nb_gauss_pts; ++gg) {
1588 if (check_data == 0)