1474 {
1476
1477 auto &m_field = getPtrFE()->mField;
1478 auto fe_ent = getNumeredEntFiniteElementPtr()->getEnt();
1480
1483
1486
1487 const auto nb_gauss_pts = getGaussPts().size2();
1488
1489 auto t_disp_h1 = getFTensor1FromMat<3>(*
uH1Ptr);
1490 auto t_coords = getFTensor1CoordsAtGaussPts();
1491 auto t_traction = getFTensor1FromMat<3>(*
tractionPtr);
1492
1493 auto next = [&]() {
1494 ++t_disp_h1;
1495 ++t_traction;
1496 ++t_coords;
1497 };
1498
1499 auto get_ele_centre = [
i](
auto t_ele_coords) {
1501 t_ele_center(
i) = 0;
1502 for (int nn = 0; nn != 3; nn++) {
1503 t_ele_center(
i) += t_ele_coords(
i);
1504 ++t_ele_coords;
1505 }
1506 t_ele_center(
i) /= 3;
1507 return t_ele_center;
1508 };
1509
1510 auto get_ele_radius = [
i](
auto t_ele_center,
auto t_ele_coords) {
1512 t_n0(
i) = t_ele_center(
i) - t_ele_coords(
i);
1514 };
1515
1516 auto get_face_conn = [this](auto face) {
1518 int num_nodes;
1520 face, conn, num_nodes, true),
1521 "get conn");
1522 if (num_nodes != 3) {
1524 }
1525 return conn;
1526 };
1527
1528 auto get_face_coords = [this](auto conn) {
1529 std::array<double, 9> coords;
1531 return coords;
1532 };
1533
1534 auto get_closet_face = [
this](
auto *point_ptr,
auto r) {
1536 std::vector<EntityHandle> faces_out;
1540 "get closest faces");
1541 return faces_out;
1542 };
1543
1544 auto get_faces_out = [this](auto *point_ptr, auto *unit_ray_ptr, auto radius,
1546 std::vector<double> distances_out;
1547 std::vector<EntityHandle> faces_out;
1549
1552 point_ptr, unit_ray_ptr, &radius),
1553
1554 "get closest faces");
1555 return std::make_pair(faces_out, distances_out);
1556 };
1557
1558 auto get_normal = [](auto &ele_coords) {
1561 return t_normal;
1562 };
1563
1564 auto make_map = [&](auto &face_out, auto &face_dist, auto &t_ray_point,
1565 auto &t_unit_ray, auto &t_master_coord) {
1568 std::map<double, EntityHandle>
m;
1569 for (auto ii = 0; ii != face_out.size(); ++ii) {
1570 auto face_conn = get_face_conn(face_out[ii]);
1573 t_face_normal.normalize();
1575 t_x(
i) = t_ray_point(
i) + t_unit_ray(
i) * face_dist[ii];
1578 t_x(
i) * t_face_normal(
j) - t_master_coord(
i) * t_unit_ray(
j);
1579 if (t_unit_ray(
i) * t_face_normal(
i) > std::cos(M_PI / 3)) {
1580 auto dot = std::sqrt(t_chi(
i,
j) * t_chi(
i,
j));
1581 m[dot] = face_out[ii];
1582 }
1583 }
1585 };
1586
1587 auto get_tag_data = [this](auto tag, auto face, auto &vec) {
1589 int tag_length;
1591 vec.resize(tag_length);
1593 &*vec.begin());
1595 };
1596
1597 auto create_tag = [this](const std::string tag_name, const int size) {
1598 double def_VAL[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1602 tag_name.c_str(), size, MB_TYPE_DOUBLE,
th,
1603 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
1606 }
1608 };
1609
1610 auto set_float_precision = [](const double x) {
1611 if (std::abs(x) < std::numeric_limits<float>::epsilon())
1612 return 0.;
1613 else
1614 return x;
1615 };
1616
1617
1618 auto save_scal_tag = [&](
auto &
th,
auto v,
const int gg) {
1621 v = set_float_precision(
v);
1623 }
1625 };
1626
1627
1628 auto get_fe_adjacencies = [this](auto fe_ent) {
1631 &fe_ent, 1, 2, false, adj_faces, moab::Interface::UNION),
1632 "get adj");
1633 std::set<int> adj_ids;
1634 for (auto f : adj_faces) {
1636 }
1637 return adj_ids;
1638 };
1639
1640 auto get_face_id = [this](auto face) {
1641 int id;
1644 return id;
1645 }
1646 return -1;
1647 };
1648
1649 auto get_body_id = [this](auto face) {
1650 int id;
1653 return id;
1654 }
1655 return -1;
1656 };
1657
1658 auto get_face_part = [this](auto face) {
1659 ParallelComm *pcomm_post_proc_mesh = ParallelComm::get_pcomm(
1661 int part;
1663 pcomm_post_proc_mesh->part_tag(), &face, 1, &part) == MB_SUCCESS) {
1664 return part;
1665 }
1666 return -1;
1667 };
1668
1669 auto check_face = [&](auto face, auto fe_id, auto part) {
1670 auto face_id = get_face_id(face);
1671 auto face_part = get_face_part(face);
1672 if (face_id == fe_id && face_part == part)
1673 return true;
1674 return false;
1675 };
1676
1677
1680 auto save_vec_tag = [&](
auto &
th,
auto &t_d,
const int gg) {
1684 for (
auto &
a :
v.data())
1685 a = set_float_precision(
a);
1687 &*
v.data().begin());
1688 }
1690 };
1691
1692 Tag th_mark = create_tag(
"contact_mark", 1);
1693 Tag th_mark_slave = create_tag(
"contact_mark_slave", 1);
1694 Tag th_body_id = create_tag(
"contact_body_id", 1);
1695 Tag th_gap = create_tag(
"contact_gap", 1);
1696 Tag th_tn_master = create_tag(
"contact_tn_master", 1);
1697 Tag th_tn_slave = create_tag(
"contact_tn_slave", 1);
1698 Tag th_contact_traction = create_tag(
"contact_traction", 3);
1699 Tag th_contact_traction_master = create_tag(
"contact_traction_master", 3);
1700 Tag th_contact_traction_slave = create_tag(
"contact_traction_slave", 3);
1701 Tag th_c = create_tag(
"contact_c", 1);
1702 Tag th_normal = create_tag(
"contact_normal", 3);
1703 Tag th_dist = create_tag(
"contact_dip", 3);
1704
1705 auto t_ele_centre = get_ele_centre(getFTensor1Coords());
1706 auto ele_radius = get_ele_radius(t_ele_centre, getFTensor1Coords());
1707
1710 shadow_vec.clear();
1711
1712 auto adj_fe_ids = get_fe_adjacencies(fe_ent);
1713
1714 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
1715
1717 t_spatial_coords(
i) = t_coords(
i) + t_disp_h1(
i);
1718
1720 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1721 }
1722
1723 auto faces_close = get_closet_face(&t_spatial_coords(0), ele_radius);
1724 for (auto face_close : faces_close) {
1725 if (check_face(face_close, fe_id, m_field.get_comm_rank())) {
1726
1727 auto body_id = get_body_id(face_close);
1728
1729 auto master_face_conn = get_face_conn(face_close);
1730 std::array<double, 9> master_coords;
1733 master_coords.data());
1734 std::array<double, 9> master_traction;
1737 master_traction.data());
1738 auto t_normal_face_close = get_normal(master_coords);
1739 t_normal_face_close.normalize();
1740
1743 CHKERR save_scal_tag(th_mark,
m, gg);
1744 CHKERR save_scal_tag(th_body_id,
static_cast<double>(body_id), gg);
1745 CHKERR save_vec_tag(th_normal, t_normal_face_close, gg);
1746 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1747 }
1748
1750 t_unit_ray(
i) = -t_normal_face_close(
i);
1753 t_spatial_coords(
i) -
1755
1756 constexpr double eps = 1e-3;
1757 auto [faces_out, faces_dist] =
1758 get_faces_out(&t_ray_point(0), &t_unit_ray(0),
1761
1762 auto m = make_map(faces_out, faces_dist, t_ray_point, t_unit_ray,
1763 t_spatial_coords);
1764 for (
auto m_it =
m.begin(); m_it !=
m.end(); ++m_it) {
1765 auto face = m_it->second;
1766 if (face != face_close) {
1767
1768 if (
1769
1770 (adj_fe_ids.find(get_face_id(face)) == adj_fe_ids.end() ||
1771 get_face_part(face) != m_field.get_comm_rank())
1772
1773 ) {
1774
1775 shadow_vec.push_back(ContactTree::FaceData());
1776 shadow_vec.back().gaussPtNb = gg;
1777
1778 auto slave_face_conn = get_face_conn(face);
1779 std::array<double, 9> slave_coords;
1782 slave_coords.data());
1783 auto t_normal_face = get_normal(slave_coords);
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 MYPCOMM_INDEX
default communicator number PCOMM
#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