1481 {
1483
1484 auto &m_field = getPtrFE()->mField;
1485 auto fe_ent = getNumeredEntFiniteElementPtr()->getEnt();
1487
1490
1493
1494 const auto nb_gauss_pts = getGaussPts().size2();
1495
1496 auto t_disp_h1 = getFTensor1FromMat<3>(*
uH1Ptr);
1497 auto t_coords = getFTensor1CoordsAtGaussPts();
1498 auto t_traction = getFTensor1FromMat<3>(*
tractionPtr);
1499
1500 auto next = [&]() {
1501 ++t_disp_h1;
1502 ++t_traction;
1503 ++t_coords;
1504 };
1505
1506 auto get_ele_centre = [
i](
auto t_ele_coords) {
1508 t_ele_center(
i) = 0;
1509 for (int nn = 0; nn != 3; nn++) {
1510 t_ele_center(
i) += t_ele_coords(
i);
1511 ++t_ele_coords;
1512 }
1513 t_ele_center(
i) /= 3;
1514 return t_ele_center;
1515 };
1516
1517 auto get_ele_radius = [
i](
auto t_ele_center,
auto t_ele_coords) {
1519 t_n0(
i) = t_ele_center(
i) - t_ele_coords(
i);
1521 };
1522
1523 auto get_face_conn = [this](auto face) {
1525 int num_nodes;
1527 face, conn, num_nodes, true),
1528 "get conn");
1529 if (num_nodes != 3) {
1531 }
1532 return conn;
1533 };
1534
1535 auto get_face_coords = [this](auto conn) {
1536 std::array<double, 9> coords;
1538 return coords;
1539 };
1540
1541 auto get_closet_face = [
this](
auto *point_ptr,
auto r) {
1543 std::vector<EntityHandle> faces_out;
1547 "get closest faces");
1548 return faces_out;
1549 };
1550
1551 auto get_faces_out = [this](auto *point_ptr, auto *unit_ray_ptr, auto radius,
1553 std::vector<double> distances_out;
1554 std::vector<EntityHandle> faces_out;
1556
1559 point_ptr, unit_ray_ptr, &radius),
1560
1561 "get closest faces");
1562 return std::make_pair(faces_out, distances_out);
1563 };
1564
1565 auto get_normal = [](auto &ele_coords) {
1568 return t_normal;
1569 };
1570
1571 auto make_map = [&](auto &face_out, auto &face_dist, auto &t_ray_point,
1572 auto &t_unit_ray, auto &t_master_coord) {
1575 std::map<double, EntityHandle>
m;
1576 for (auto ii = 0; ii != face_out.size(); ++ii) {
1577 auto face_conn = get_face_conn(face_out[ii]);
1580 t_face_normal.normalize();
1582 t_x(
i) = t_ray_point(
i) + t_unit_ray(
i) * face_dist[ii];
1585 t_x(
i) * t_face_normal(
j) - t_master_coord(
i) * t_unit_ray(
j);
1586 if (t_unit_ray(
i) * t_face_normal(
i) > std::cos(M_PI / 3)) {
1587 auto dot = std::sqrt(t_chi(
i,
j) * t_chi(
i,
j));
1588 m[dot] = face_out[ii];
1589 }
1590 }
1592 };
1593
1594 auto get_tag_data = [this](auto tag, auto face, auto &vec) {
1596 int tag_length;
1598 vec.resize(tag_length);
1600 &*vec.begin());
1602 };
1603
1604 auto create_tag = [this](const std::string tag_name, const int size) {
1605 double def_VAL[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1609 tag_name.c_str(), size, MB_TYPE_DOUBLE,
th,
1610 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
1613 }
1615 };
1616
1617 auto set_float_precision = [](const double x) {
1618 if (std::abs(x) < std::numeric_limits<float>::epsilon())
1619 return 0.;
1620 else
1621 return x;
1622 };
1623
1624
1625 auto save_scal_tag = [&](
auto &
th,
auto v,
const int gg) {
1628 v = set_float_precision(
v);
1630 }
1632 };
1633
1634
1635 auto get_fe_adjacencies = [this](auto fe_ent) {
1638 &fe_ent, 1, 2, false, adj_faces, moab::Interface::UNION),
1639 "get adj");
1640 std::set<int> adj_ids;
1641 for (auto f : adj_faces) {
1643 }
1644 return adj_ids;
1645 };
1646
1647 auto get_face_id = [this](auto face) {
1648 int id;
1651 return id;
1652 }
1653 return -1;
1654 };
1655
1656 auto get_body_id = [this](auto face) {
1657 int id;
1660 return id;
1661 }
1662 return -1;
1663 };
1664
1665 auto get_face_part = [this](auto face) {
1666 auto pcomm_post_proc_mesh =
contactTreePtr->getPostProcMeshPcommPtr();
1667 if (pcomm_post_proc_mesh == nullptr)
1669 int part;
1671 pcomm_post_proc_mesh->part_tag(), &face, 1, &part) == MB_SUCCESS) {
1672 return part;
1673 }
1674 return -1;
1675 };
1676
1677 auto check_face = [&](auto face, auto fe_id, auto part) {
1678 auto face_id = get_face_id(face);
1679 auto face_part = get_face_part(face);
1680 if (face_id == fe_id && face_part == part)
1681 return true;
1682 return false;
1683 };
1684
1685
1688 auto save_vec_tag = [&](
auto &
th,
auto &t_d,
const int gg) {
1692 for (
auto &
a :
v.data())
1693 a = set_float_precision(
a);
1695 &*
v.data().begin());
1696 }
1698 };
1699
1700 Tag th_mark = create_tag(
"contact_mark", 1);
1701 Tag th_mark_slave = create_tag(
"contact_mark_slave", 1);
1702 Tag th_body_id = create_tag(
"contact_body_id", 1);
1703 Tag th_gap = create_tag(
"contact_gap", 1);
1704 Tag th_tn_master = create_tag(
"contact_tn_master", 1);
1705 Tag th_tn_slave = create_tag(
"contact_tn_slave", 1);
1706 Tag th_contact_traction = create_tag(
"contact_traction", 3);
1707 Tag th_contact_traction_master = create_tag(
"contact_traction_master", 3);
1708 Tag th_contact_traction_slave = create_tag(
"contact_traction_slave", 3);
1709 Tag th_c = create_tag(
"contact_c", 1);
1710 Tag th_normal = create_tag(
"contact_normal", 3);
1711 Tag th_dist = create_tag(
"contact_dip", 3);
1712
1713 auto t_ele_centre = get_ele_centre(getFTensor1Coords());
1714 auto ele_radius = get_ele_radius(t_ele_centre, getFTensor1Coords());
1715
1718 shadow_vec.clear();
1719
1720 auto adj_fe_ids = get_fe_adjacencies(fe_ent);
1721
1722 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
1723
1725 t_spatial_coords(
i) = t_coords(
i) + t_disp_h1(
i);
1726
1728 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1729 }
1730
1731 auto faces_close = get_closet_face(&t_spatial_coords(0), ele_radius);
1732 for (auto face_close : faces_close) {
1733 if (check_face(face_close, fe_id, m_field.get_comm_rank())) {
1734
1735 auto body_id = get_body_id(face_close);
1736
1737 auto master_face_conn = get_face_conn(face_close);
1738 std::array<double, 9> master_coords;
1741 master_coords.data());
1742 std::array<double, 9> master_traction;
1745 master_traction.data());
1746 auto t_normal_face_close = get_normal(master_coords);
1747 t_normal_face_close.normalize();
1748
1751 CHKERR save_scal_tag(th_mark,
m, gg);
1752 CHKERR save_scal_tag(th_body_id,
static_cast<double>(body_id), gg);
1753 CHKERR save_vec_tag(th_normal, t_normal_face_close, gg);
1754 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1755 }
1756
1758 t_unit_ray(
i) = -t_normal_face_close(
i);
1761 t_spatial_coords(
i) -
1763
1764 constexpr double eps = 1e-3;
1765 auto [faces_out, faces_dist] =
1766 get_faces_out(&t_ray_point(0), &t_unit_ray(0),
1769
1770 auto m = make_map(faces_out, faces_dist, t_ray_point, t_unit_ray,
1771 t_spatial_coords);
1772 for (
auto m_it =
m.begin(); m_it !=
m.end(); ++m_it) {
1773 auto face = m_it->second;
1774 if (face != face_close) {
1775
1776 if (
1777
1778 (adj_fe_ids.find(get_face_id(face)) == adj_fe_ids.end() ||
1779 get_face_part(face) != m_field.get_comm_rank())
1780
1781 ) {
1782
1783 shadow_vec.push_back(ContactTree::FaceData());
1784 shadow_vec.back().gaussPtNb = gg;
1785
1786 auto slave_face_conn = get_face_conn(face);
1787 std::array<double, 9> slave_coords;
1790 slave_coords.data());
1791 auto t_normal_face = get_normal(slave_coords);
1792 std::array<double, 9> slave_tractions;
1795 slave_tractions.data());
1796
1797 auto t_master_point =
1798 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data());
1799 auto t_slave_point =
1800 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data());
1801 auto t_ray_point_data =
1802 getFTensor1FromPtr<3>(shadow_vec.back().rayPoint.data());
1803 auto t_unit_ray_data =
1804 getFTensor1FromPtr<3>(shadow_vec.back().unitRay.data());
1805
1806 t_slave_point(
i) = t_ray_point(
i) + m_it->first * t_unit_ray(
i);
1807
1808 auto eval_position = [&](auto &&t_elem_coords, auto &&t_point) {
1809 std::array<double, 2> loc_coords;
1812 &t_elem_coords(0, 0), &t_point(0), 1,
1813 loc_coords.data()),
1814 "get local coords");
1817 &loc_coords[0],
1818 &loc_coords[1], 1),
1819 "calc shape fun");
1823 t_point_out(
i) = t_shape_fun(
j) * t_elem_coords(
j,
i);
1824 return t_point_out;
1825 };
1826
1827 auto t_master_point_updated = eval_position(
1828 getFTensor2FromPtr<3, 3>(master_coords.data()),
1829 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data()));
1830 t_master_point(
i) = t_master_point_updated(
i);
1831
1832 auto t_slave_point_updated = eval_position(
1833 getFTensor2FromPtr<3, 3>(slave_coords.data()),
1834 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data()));
1835 t_slave_point(
i) = t_slave_point_updated(
i);
1836
1837 t_ray_point_data(
i) = t_ray_point(
i);
1838 t_unit_ray_data(
i) = t_unit_ray(
i);
1839
1840 std::copy(master_coords.begin(), master_coords.end(),
1841 shadow_vec.back().masterPointNodes.begin());
1842 std::copy(master_traction.begin(), master_traction.end(),
1843 shadow_vec.back().masterTractionNodes.begin());
1844 std::copy(slave_coords.begin(), slave_coords.end(),
1845 shadow_vec.back().slavePointNodes.begin());
1846 std::copy(slave_tractions.begin(), slave_tractions.end(),
1847 shadow_vec.back().slaveTractionNodes.begin());
1848
1849 shadow_vec.back().eleRadius = ele_radius;
1850
1851
1852
1853
1854
1855
1856
1857
1859 auto [gap, tn_master, tn_slave,
c, t_master_traction,
1860 t_slave_traction] =
1861 multiGetGap(&(shadow_vec.back()), t_spatial_coords);
1863 t_gap_vec(
i) = t_slave_point(
i) - t_spatial_coords(
i);
1864 CHKERR save_scal_tag(th_gap, gap, gg);
1865 CHKERR save_scal_tag(th_tn_master, tn_master, gg);
1866 CHKERR save_scal_tag(th_tn_slave, tn_slave, gg);
1867 CHKERR save_scal_tag(th_c,
c, gg);
1869 CHKERR save_scal_tag(th_mark_slave,
m, gg);
1870 CHKERR save_vec_tag(th_dist, t_gap_vec, gg);
1871 CHKERR save_vec_tag(th_contact_traction_master,
1872 t_master_traction, gg);
1873 CHKERR save_vec_tag(th_contact_traction_slave, t_slave_traction,
1874 gg);
1875 }
1876
1877 break;
1878 }
1879 }
1880 }
1881 break;
1882 }
1883 }
1884 next();
1885 }
1886
1888}
#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