1485 {
1487
1488 auto &m_field = getPtrFE()->mField;
1489 auto fe_ent = getNumeredEntFiniteElementPtr()->getEnt();
1491
1494
1497
1498 const auto nb_gauss_pts = getGaussPts().size2();
1499
1500 auto t_disp_h1 = getFTensor1FromMat<3>(*
uH1Ptr);
1501 auto t_coords = getFTensor1CoordsAtGaussPts();
1502 auto t_traction = getFTensor1FromMat<3>(*
tractionPtr);
1503
1504 auto next = [&]() {
1505 ++t_disp_h1;
1506 ++t_traction;
1507 ++t_coords;
1508 };
1509
1510 auto get_ele_centre = [
i](
auto t_ele_coords) {
1512 t_ele_center(
i) = 0;
1513 for (int nn = 0; nn != 3; nn++) {
1514 t_ele_center(
i) += t_ele_coords(
i);
1515 ++t_ele_coords;
1516 }
1517 t_ele_center(
i) /= 3;
1518 return t_ele_center;
1519 };
1520
1521 auto get_ele_radius = [
i](
auto t_ele_center,
auto t_ele_coords) {
1523 t_n0(
i) = t_ele_center(
i) - t_ele_coords(
i);
1525 };
1526
1527 auto get_face_conn = [this](auto face) {
1529 int num_nodes;
1531 face, conn, num_nodes, true),
1532 "get conn");
1533 if (num_nodes != 3) {
1535 }
1536 return conn;
1537 };
1538
1539 auto get_face_coords = [this](auto conn) {
1540 std::array<double, 9> coords;
1542 return coords;
1543 };
1544
1545 auto get_closet_face = [
this](
auto *point_ptr,
auto r) {
1547 std::vector<EntityHandle> faces_out;
1551 "get closest faces");
1552 return faces_out;
1553 };
1554
1555 auto get_faces_out = [this](auto *point_ptr, auto *unit_ray_ptr, auto radius,
1557 std::vector<double> distances_out;
1558 std::vector<EntityHandle> faces_out;
1560
1563 point_ptr, unit_ray_ptr, &radius),
1564
1565 "get closest faces");
1566 return std::make_pair(faces_out, distances_out);
1567 };
1568
1569 auto get_normal = [](auto &ele_coords) {
1572 return t_normal;
1573 };
1574
1575 auto make_map = [&](auto &face_out, auto &face_dist, auto &t_ray_point,
1576 auto &t_unit_ray, auto &t_master_coord) {
1579 std::map<double, EntityHandle>
m;
1580 for (auto ii = 0; ii != face_out.size(); ++ii) {
1581 auto face_conn = get_face_conn(face_out[ii]);
1584 t_face_normal.normalize();
1586 t_x(
i) = t_ray_point(
i) + t_unit_ray(
i) * face_dist[ii];
1589 t_x(
i) * t_face_normal(
j) - t_master_coord(
i) * t_unit_ray(
j);
1590 if (t_unit_ray(
i) * t_face_normal(
i) > std::cos(M_PI / 3)) {
1591 auto dot = std::sqrt(t_chi(
i,
j) * t_chi(
i,
j));
1592 m[dot] = face_out[ii];
1593 }
1594 }
1596 };
1597
1598 auto get_tag_data = [this](auto tag, auto face, auto &vec) {
1600 int tag_length;
1602 vec.resize(tag_length);
1604 &*vec.begin());
1606 };
1607
1608 auto create_tag = [this](const std::string tag_name, const int size) {
1609 double def_VAL[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1613 tag_name.c_str(), size, MB_TYPE_DOUBLE,
th,
1614 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
1617 }
1619 };
1620
1621 auto set_float_precision = [](const double x) {
1622 if (std::abs(x) < std::numeric_limits<float>::epsilon())
1623 return 0.;
1624 else
1625 return x;
1626 };
1627
1628
1629 auto save_scal_tag = [&](
auto &
th,
auto v,
const int gg) {
1632 v = set_float_precision(
v);
1634 }
1636 };
1637
1638
1639 auto get_fe_adjacencies = [this](auto fe_ent) {
1642 &fe_ent, 1, 2, false, adj_faces, moab::Interface::UNION),
1643 "get adj");
1644 std::set<int> adj_ids;
1645 for (auto f : adj_faces) {
1647 }
1648 return adj_ids;
1649 };
1650
1651 auto get_face_id = [this](auto face) {
1652 int id;
1655 return id;
1656 }
1657 return -1;
1658 };
1659
1660 auto get_body_id = [this](auto face) {
1661 int id;
1664 return id;
1665 }
1666 return -1;
1667 };
1668
1669 auto get_face_part = [this](auto face) {
1670 const moab::Core *core_mesh_ptr =
1671 dynamic_cast<const moab::Core *
>(&
contactTreePtr->getPostProcMesh());
1672 auto pcomm_post_proc_mesh =
1674 int part;
1676 pcomm_post_proc_mesh->part_tag(), &face, 1, &part) == MB_SUCCESS) {
1677 return part;
1678 }
1679 return -1;
1680 };
1681
1682 auto check_face = [&](auto face, auto fe_id, auto part) {
1683 auto face_id = get_face_id(face);
1684 auto face_part = get_face_part(face);
1685 if (face_id == fe_id && face_part == part)
1686 return true;
1687 return false;
1688 };
1689
1690
1693 auto save_vec_tag = [&](
auto &
th,
auto &t_d,
const int gg) {
1697 for (
auto &
a :
v.data())
1698 a = set_float_precision(
a);
1700 &*
v.data().begin());
1701 }
1703 };
1704
1705 Tag th_mark = create_tag(
"contact_mark", 1);
1706 Tag th_mark_slave = create_tag(
"contact_mark_slave", 1);
1707 Tag th_body_id = create_tag(
"contact_body_id", 1);
1708 Tag th_gap = create_tag(
"contact_gap", 1);
1709 Tag th_tn_master = create_tag(
"contact_tn_master", 1);
1710 Tag th_tn_slave = create_tag(
"contact_tn_slave", 1);
1711 Tag th_contact_traction = create_tag(
"contact_traction", 3);
1712 Tag th_contact_traction_master = create_tag(
"contact_traction_master", 3);
1713 Tag th_contact_traction_slave = create_tag(
"contact_traction_slave", 3);
1714 Tag th_c = create_tag(
"contact_c", 1);
1715 Tag th_normal = create_tag(
"contact_normal", 3);
1716 Tag th_dist = create_tag(
"contact_dip", 3);
1717
1718 auto t_ele_centre = get_ele_centre(getFTensor1Coords());
1719 auto ele_radius = get_ele_radius(t_ele_centre, getFTensor1Coords());
1720
1723 shadow_vec.clear();
1724
1725 auto adj_fe_ids = get_fe_adjacencies(fe_ent);
1726
1727 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
1728
1730 t_spatial_coords(
i) = t_coords(
i) + t_disp_h1(
i);
1731
1733 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1734 }
1735
1736 auto faces_close = get_closet_face(&t_spatial_coords(0), ele_radius);
1737 for (auto face_close : faces_close) {
1738 if (check_face(face_close, fe_id, m_field.get_comm_rank())) {
1739
1740 auto body_id = get_body_id(face_close);
1741
1742 auto master_face_conn = get_face_conn(face_close);
1743 std::array<double, 9> master_coords;
1746 master_coords.data());
1747 std::array<double, 9> master_traction;
1750 master_traction.data());
1751 auto t_normal_face_close = get_normal(master_coords);
1752 t_normal_face_close.normalize();
1753
1756 CHKERR save_scal_tag(th_mark,
m, gg);
1757 CHKERR save_scal_tag(th_body_id,
static_cast<double>(body_id), gg);
1758 CHKERR save_vec_tag(th_normal, t_normal_face_close, gg);
1759 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1760 }
1761
1763 t_unit_ray(
i) = -t_normal_face_close(
i);
1766 t_spatial_coords(
i) -
1768
1769 constexpr double eps = 1e-3;
1770 auto [faces_out, faces_dist] =
1771 get_faces_out(&t_ray_point(0), &t_unit_ray(0),
1774
1775 auto m = make_map(faces_out, faces_dist, t_ray_point, t_unit_ray,
1776 t_spatial_coords);
1777 for (
auto m_it =
m.begin(); m_it !=
m.end(); ++m_it) {
1778 auto face = m_it->second;
1779 if (face != face_close) {
1780
1781 if (
1782
1783 (adj_fe_ids.find(get_face_id(face)) == adj_fe_ids.end() ||
1784 get_face_part(face) != m_field.get_comm_rank())
1785
1786 ) {
1787
1788 shadow_vec.push_back(ContactTree::FaceData());
1789 shadow_vec.back().gaussPtNb = gg;
1790
1791 auto slave_face_conn = get_face_conn(face);
1792 std::array<double, 9> slave_coords;
1795 slave_coords.data());
1796 auto t_normal_face = get_normal(slave_coords);
1797 std::array<double, 9> slave_tractions;
1800 slave_tractions.data());
1801
1802 auto t_master_point =
1803 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data());
1804 auto t_slave_point =
1805 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data());
1806 auto t_ray_point_data =
1807 getFTensor1FromPtr<3>(shadow_vec.back().rayPoint.data());
1808 auto t_unit_ray_data =
1809 getFTensor1FromPtr<3>(shadow_vec.back().unitRay.data());
1810
1811 t_slave_point(
i) = t_ray_point(
i) + m_it->first * t_unit_ray(
i);
1812
1813 auto eval_position = [&](auto &&t_elem_coords, auto &&t_point) {
1814 std::array<double, 2> loc_coords;
1817 &t_elem_coords(0, 0), &t_point(0), 1,
1818 loc_coords.data()),
1819 "get local coords");
1822 &loc_coords[0],
1823 &loc_coords[1], 1),
1824 "calc shape fun");
1828 t_point_out(
i) = t_shape_fun(
j) * t_elem_coords(
j,
i);
1829 return t_point_out;
1830 };
1831
1832 auto t_master_point_updated = eval_position(
1833 getFTensor2FromPtr<3, 3>(master_coords.data()),
1834 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data()));
1835 t_master_point(
i) = t_master_point_updated(
i);
1836
1837 auto t_slave_point_updated = eval_position(
1838 getFTensor2FromPtr<3, 3>(slave_coords.data()),
1839 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data()));
1840 t_slave_point(
i) = t_slave_point_updated(
i);
1841
1842 t_ray_point_data(
i) = t_ray_point(
i);
1843 t_unit_ray_data(
i) = t_unit_ray(
i);
1844
1845 std::copy(master_coords.begin(), master_coords.end(),
1846 shadow_vec.back().masterPointNodes.begin());
1847 std::copy(master_traction.begin(), master_traction.end(),
1848 shadow_vec.back().masterTractionNodes.begin());
1849 std::copy(slave_coords.begin(), slave_coords.end(),
1850 shadow_vec.back().slavePointNodes.begin());
1851 std::copy(slave_tractions.begin(), slave_tractions.end(),
1852 shadow_vec.back().slaveTractionNodes.begin());
1853
1854 shadow_vec.back().eleRadius = ele_radius;
1855
1856
1857
1858
1859
1860
1861
1862
1864 auto [gap, tn_master, tn_slave,
c, t_master_traction,
1865 t_slave_traction] =
1866 multiGetGap(&(shadow_vec.back()), t_spatial_coords);
1868 t_gap_vec(
i) = t_slave_point(
i) - t_spatial_coords(
i);
1869 CHKERR save_scal_tag(th_gap, gap, gg);
1870 CHKERR save_scal_tag(th_tn_master, tn_master, gg);
1871 CHKERR save_scal_tag(th_tn_slave, tn_slave, gg);
1872 CHKERR save_scal_tag(th_c,
c, gg);
1874 CHKERR save_scal_tag(th_mark_slave,
m, gg);
1875 CHKERR save_vec_tag(th_dist, t_gap_vec, gg);
1876 CHKERR save_vec_tag(th_contact_traction_master,
1877 t_master_traction, gg);
1878 CHKERR save_vec_tag(th_contact_traction_slave, t_slave_traction,
1879 gg);
1880 }
1881
1882 break;
1883 }
1884 }
1885 }
1886 break;
1887 }
1888 }
1889 next();
1890 }
1891
1893}
#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)