1483 {
1485
1486 auto &m_field = getPtrFE()->mField;
1487 auto fe_ent = getNumeredEntFiniteElementPtr()->getEnt();
1489
1492
1495
1496 const auto nb_gauss_pts = getGaussPts().size2();
1497
1498 auto t_disp_h1 = getFTensor1FromMat<3>(*
uH1Ptr);
1499 auto t_coords = getFTensor1CoordsAtGaussPts();
1500 auto t_traction = getFTensor1FromMat<3>(*
tractionPtr);
1501
1502 auto next = [&]() {
1503 ++t_disp_h1;
1504 ++t_traction;
1505 ++t_coords;
1506 };
1507
1508 auto get_ele_centre = [
i](
auto t_ele_coords) {
1510 t_ele_center(
i) = 0;
1511 for (int nn = 0; nn != 3; nn++) {
1512 t_ele_center(
i) += t_ele_coords(
i);
1513 ++t_ele_coords;
1514 }
1515 t_ele_center(
i) /= 3;
1516 return t_ele_center;
1517 };
1518
1519 auto get_ele_radius = [
i](
auto t_ele_center,
auto t_ele_coords) {
1521 t_n0(
i) = t_ele_center(
i) - t_ele_coords(
i);
1523 };
1524
1525 auto get_face_conn = [this](auto face) {
1526 const EntityHandle *conn;
1527 int num_nodes;
1529 face, conn, num_nodes, true),
1530 "get conn");
1531 if (num_nodes != 3) {
1533 }
1534 return conn;
1535 };
1536
1537 auto get_face_coords = [this](auto conn) {
1538 std::array<double, 9> coords;
1540 return coords;
1541 };
1542
1543 auto get_closet_face = [
this](
auto *point_ptr,
auto r) {
1545 std::vector<EntityHandle> faces_out;
1549 "get closest faces");
1550 return faces_out;
1551 };
1552
1553 auto get_faces_out = [this](auto *point_ptr, auto *unit_ray_ptr, auto radius,
1555 std::vector<double> distances_out;
1556 std::vector<EntityHandle> faces_out;
1558
1561 point_ptr, unit_ray_ptr, &radius),
1562
1563 "get closest faces");
1564 return std::make_pair(faces_out, distances_out);
1565 };
1566
1567 auto get_normal = [](auto &ele_coords) {
1570 return t_normal;
1571 };
1572
1573 auto make_map = [&](auto &face_out, auto &face_dist, auto &t_ray_point,
1574 auto &t_unit_ray, auto &t_master_coord) {
1577 std::map<double, EntityHandle>
m;
1578 for (auto ii = 0; ii != face_out.size(); ++ii) {
1579 auto face_conn = get_face_conn(face_out[ii]);
1582 t_face_normal.normalize();
1584 t_x(
i) = t_ray_point(
i) + t_unit_ray(
i) * face_dist[ii];
1587 t_x(
i) * t_face_normal(
j) - t_master_coord(
i) * t_unit_ray(
j);
1588 if (t_unit_ray(
i) * t_face_normal(
i) > std::cos(M_PI / 3)) {
1589 auto dot = std::sqrt(t_chi(
i,
j) * t_chi(
i,
j));
1590 m[dot] = face_out[ii];
1591 }
1592 }
1594 };
1595
1596 auto create_tag = [this](const std::string tag_name, const int size) {
1597 double def_VAL[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1601 tag_name.c_str(), size, MB_TYPE_DOUBLE,
th,
1602 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
1605 }
1607 };
1608
1609 auto set_float_precision = [](const double x) {
1610 if (std::abs(x) < std::numeric_limits<float>::epsilon())
1611 return 0.;
1612 else
1613 return x;
1614 };
1615
1616
1617 auto save_scal_tag = [&](
auto &
th,
auto v,
const int gg) {
1620 v = set_float_precision(
v);
1622 }
1624 };
1625
1626
1627 auto get_fe_adjacencies = [this](auto fe_ent) {
1630 &fe_ent, 1, 2, false, adj_faces, moab::Interface::UNION),
1631 "get adj");
1632 std::set<int> adj_ids;
1633 for (auto f : adj_faces) {
1635 }
1636 return adj_ids;
1637 };
1638
1639 auto get_face_id = [this](auto face) {
1640 int id;
1643 return id;
1644 }
1645 return -1;
1646 };
1647
1648 auto get_body_id = [this](auto face) {
1649 int id;
1652 return id;
1653 }
1654 return -1;
1655 };
1656
1657 auto get_face_part = [this](auto face) {
1658 const moab::Core *core_mesh_ptr =
1659 dynamic_cast<const moab::Core *
>(&
contactTreePtr->getPostProcMesh());
1660 auto pcomm_post_proc_mesh =
1662 int part;
1664 pcomm_post_proc_mesh->part_tag(), &face, 1, &part) == MB_SUCCESS) {
1665 return part;
1666 }
1667 return -1;
1668 };
1669
1670 auto check_face = [&](auto face, auto fe_id, auto part) {
1671 auto face_id = get_face_id(face);
1672 auto face_part = get_face_part(face);
1673 if (face_id == fe_id && face_part == part)
1674 return true;
1675 return false;
1676 };
1677
1678
1681 auto save_vec_tag = [&](
auto &
th,
auto &t_d,
const int gg) {
1685 for (
auto &
a :
v.data())
1686 a = set_float_precision(
a);
1688 &*
v.data().begin());
1689 }
1691 };
1692
1693 Tag th_mark = create_tag(
"contact_mark", 1);
1694 Tag th_mark_slave = create_tag(
"contact_mark_slave", 1);
1695 Tag th_body_id = create_tag(
"contact_body_id", 1);
1696 Tag th_gap = create_tag(
"contact_gap", 1);
1697 Tag th_tn_master = create_tag(
"contact_tn_master", 1);
1698 Tag th_tn_slave = create_tag(
"contact_tn_slave", 1);
1699 Tag th_contact_traction = create_tag(
"contact_traction", 3);
1700 Tag th_contact_traction_master = create_tag(
"contact_traction_master", 3);
1701 Tag th_contact_traction_slave = create_tag(
"contact_traction_slave", 3);
1702 Tag th_c = create_tag(
"contact_c", 1);
1703 Tag th_normal = create_tag(
"contact_normal", 3);
1704 Tag th_dist = create_tag(
"contact_dip", 3);
1705
1706 auto t_ele_centre = get_ele_centre(getFTensor1Coords());
1707 auto ele_radius = get_ele_radius(t_ele_centre, getFTensor1Coords());
1708
1711 shadow_vec.clear();
1712
1713 auto adj_fe_ids = get_fe_adjacencies(fe_ent);
1714
1715 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
1716
1718 t_spatial_coords(
i) = t_coords(
i) + t_disp_h1(
i);
1719
1721 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1722 }
1723
1724 auto faces_close = get_closet_face(&t_spatial_coords(0), ele_radius);
1725 for (auto face_close : faces_close) {
1726 if (check_face(face_close, fe_id, m_field.get_comm_rank())) {
1727
1728 auto body_id = get_body_id(face_close);
1729
1730 auto master_face_conn = get_face_conn(face_close);
1731 std::array<double, 9> master_coords;
1734 master_coords.data());
1735 std::array<double, 9> master_traction;
1738 master_traction.data());
1739 auto t_normal_face_close = get_normal(master_coords);
1740 t_normal_face_close.normalize();
1741
1744 CHKERR save_scal_tag(th_mark,
m, gg);
1745 CHKERR save_scal_tag(th_body_id,
static_cast<double>(body_id), gg);
1746 CHKERR save_vec_tag(th_normal, t_normal_face_close, gg);
1747 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1748 }
1749
1751 t_unit_ray(
i) = -t_normal_face_close(
i);
1754 t_spatial_coords(
i) -
1756
1757 constexpr double eps = 1e-3;
1758 auto [faces_out, faces_dist] =
1759 get_faces_out(&t_ray_point(0), &t_unit_ray(0),
1762
1763 auto m = make_map(faces_out, faces_dist, t_ray_point, t_unit_ray,
1764 t_spatial_coords);
1765 for (
auto m_it =
m.begin(); m_it !=
m.end(); ++m_it) {
1766 auto face = m_it->second;
1767 if (face != face_close) {
1768
1769 if (
1770
1771 (adj_fe_ids.find(get_face_id(face)) == adj_fe_ids.end() ||
1772 get_face_part(face) != m_field.get_comm_rank())
1773
1774 ) {
1775
1776 shadow_vec.push_back(ContactTree::FaceData());
1777 shadow_vec.back().gaussPtNb = gg;
1778
1779 auto slave_face_conn = get_face_conn(face);
1780 std::array<double, 9> slave_coords;
1783 slave_coords.data());
1784 std::array<double, 9> slave_tractions;
1787 slave_tractions.data());
1788
1789 auto t_master_point =
1790 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data());
1791 auto t_slave_point =
1792 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data());
1793 auto t_ray_point_data =
1794 getFTensor1FromPtr<3>(shadow_vec.back().rayPoint.data());
1795 auto t_unit_ray_data =
1796 getFTensor1FromPtr<3>(shadow_vec.back().unitRay.data());
1797
1798 t_slave_point(
i) = t_ray_point(
i) + m_it->first * t_unit_ray(
i);
1799
1800 auto eval_position = [&](auto &&t_elem_coords, auto &&t_point) {
1801 std::array<double, 2> loc_coords;
1804 &t_elem_coords(0, 0), &t_point(0), 1,
1805 loc_coords.data()),
1806 "get local coords");
1809 &loc_coords[0],
1810 &loc_coords[1], 1),
1811 "calc shape fun");
1815 t_point_out(
i) = t_shape_fun(
j) * t_elem_coords(
j,
i);
1816 return t_point_out;
1817 };
1818
1819 auto t_master_point_updated = eval_position(
1820 getFTensor2FromPtr<3, 3>(master_coords.data()),
1821 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data()));
1822 t_master_point(
i) = t_master_point_updated(
i);
1823
1824 auto t_slave_point_updated = eval_position(
1825 getFTensor2FromPtr<3, 3>(slave_coords.data()),
1826 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data()));
1827 t_slave_point(
i) = t_slave_point_updated(
i);
1828
1829 t_ray_point_data(
i) = t_ray_point(
i);
1830 t_unit_ray_data(
i) = t_unit_ray(
i);
1831
1832 std::copy(master_coords.begin(), master_coords.end(),
1833 shadow_vec.back().masterPointNodes.begin());
1834 std::copy(master_traction.begin(), master_traction.end(),
1835 shadow_vec.back().masterTractionNodes.begin());
1836 std::copy(slave_coords.begin(), slave_coords.end(),
1837 shadow_vec.back().slavePointNodes.begin());
1838 std::copy(slave_tractions.begin(), slave_tractions.end(),
1839 shadow_vec.back().slaveTractionNodes.begin());
1840
1841 shadow_vec.back().eleRadius = ele_radius;
1842
1843
1844
1845
1846
1847
1848
1849
1851 auto [gap, tn_master, tn_slave,
c, t_master_traction,
1852 t_slave_traction] =
1853 multiGetGap(&(shadow_vec.back()), t_spatial_coords);
1855 t_gap_vec(
i) = t_slave_point(
i) - t_spatial_coords(
i);
1856 CHKERR save_scal_tag(th_gap, gap, gg);
1857 CHKERR save_scal_tag(th_tn_master, tn_master, gg);
1858 CHKERR save_scal_tag(th_tn_slave, tn_slave, gg);
1859 CHKERR save_scal_tag(th_c,
c, gg);
1861 CHKERR save_scal_tag(th_mark_slave,
m, gg);
1862 CHKERR save_vec_tag(th_dist, t_gap_vec, gg);
1863 CHKERR save_vec_tag(th_contact_traction_master,
1864 t_master_traction, gg);
1865 CHKERR save_vec_tag(th_contact_traction_slave, t_slave_traction,
1866 gg);
1867 }
1868
1869 break;
1870 }
1871 }
1872 }
1873 break;
1874 }
1875 }
1876 next();
1877 }
1878
1880}
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#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 ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
static const double face_coords[4][9]
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'j', 3 > j
auto multiGetGap(ContactTree::FaceData *face_data_ptr, FTensor::Tensor1< T1, 3 > &t_spatial_coords)
VectorBoundedArray< double, 3 > VectorDouble3
auto id_from_handle(const EntityHandle h)
FTensor::Index< 'm', 3 > m
static auto getOrCreate(moab::Core *core_mesh_ptr)