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 ParallelComm *pcomm_post_proc_mesh = ParallelComm::get_pcomm(
1668 int part;
1670 pcomm_post_proc_mesh->part_tag(), &face, 1, &part) == MB_SUCCESS) {
1671 return part;
1672 }
1673 return -1;
1674 };
1675
1676 auto check_face = [&](auto face, auto fe_id, auto part) {
1677 auto face_id = get_face_id(face);
1678 auto face_part = get_face_part(face);
1679 if (face_id == fe_id && face_part == part)
1680 return true;
1681 return false;
1682 };
1683
1684
1687 auto save_vec_tag = [&](
auto &
th,
auto &t_d,
const int gg) {
1691 for (
auto &
a :
v.data())
1692 a = set_float_precision(
a);
1694 &*
v.data().begin());
1695 }
1697 };
1698
1699 Tag th_mark = create_tag(
"contact_mark", 1);
1700 Tag th_mark_slave = create_tag(
"contact_mark_slave", 1);
1701 Tag th_body_id = create_tag(
"contact_body_id", 1);
1702 Tag th_gap = create_tag(
"contact_gap", 1);
1703 Tag th_tn_master = create_tag(
"contact_tn_master", 1);
1704 Tag th_tn_slave = create_tag(
"contact_tn_slave", 1);
1705 Tag th_contact_traction = create_tag(
"contact_traction", 3);
1706 Tag th_contact_traction_master = create_tag(
"contact_traction_master", 3);
1707 Tag th_contact_traction_slave = create_tag(
"contact_traction_slave", 3);
1708 Tag th_c = create_tag(
"contact_c", 1);
1709 Tag th_normal = create_tag(
"contact_normal", 3);
1710 Tag th_dist = create_tag(
"contact_dip", 3);
1711
1712 auto t_ele_centre = get_ele_centre(getFTensor1Coords());
1713 auto ele_radius = get_ele_radius(t_ele_centre, getFTensor1Coords());
1714
1717 shadow_vec.clear();
1718
1719 auto adj_fe_ids = get_fe_adjacencies(fe_ent);
1720
1721 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
1722
1724 t_spatial_coords(
i) = t_coords(
i) + t_disp_h1(
i);
1725
1727 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1728 }
1729
1730 auto faces_close = get_closet_face(&t_spatial_coords(0), ele_radius);
1731 for (auto face_close : faces_close) {
1732 if (check_face(face_close, fe_id, m_field.get_comm_rank())) {
1733
1734 auto body_id = get_body_id(face_close);
1735
1736 auto master_face_conn = get_face_conn(face_close);
1737 std::array<double, 9> master_coords;
1740 master_coords.data());
1741 std::array<double, 9> master_traction;
1744 master_traction.data());
1745 auto t_normal_face_close = get_normal(master_coords);
1746 t_normal_face_close.normalize();
1747
1750 CHKERR save_scal_tag(th_mark,
m, gg);
1751 CHKERR save_scal_tag(th_body_id,
static_cast<double>(body_id), gg);
1752 CHKERR save_vec_tag(th_normal, t_normal_face_close, gg);
1753 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1754 }
1755
1757 t_unit_ray(
i) = -t_normal_face_close(
i);
1760 t_spatial_coords(
i) -
1762
1763 constexpr double eps = 1e-3;
1764 auto [faces_out, faces_dist] =
1765 get_faces_out(&t_ray_point(0), &t_unit_ray(0),
1768
1769 auto m = make_map(faces_out, faces_dist, t_ray_point, t_unit_ray,
1770 t_spatial_coords);
1771 for (
auto m_it =
m.begin(); m_it !=
m.end(); ++m_it) {
1772 auto face = m_it->second;
1773 if (face != face_close) {
1774
1775 if (
1776
1777 (adj_fe_ids.find(get_face_id(face)) == adj_fe_ids.end() ||
1778 get_face_part(face) != m_field.get_comm_rank())
1779
1780 ) {
1781
1782 shadow_vec.push_back(ContactTree::FaceData());
1783 shadow_vec.back().gaussPtNb = gg;
1784
1785 auto slave_face_conn = get_face_conn(face);
1786 std::array<double, 9> slave_coords;
1789 slave_coords.data());
1790 auto t_normal_face = get_normal(slave_coords);
1791 std::array<double, 9> slave_tractions;
1794 slave_tractions.data());
1795
1796 auto t_master_point =
1797 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data());
1798 auto t_slave_point =
1799 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data());
1800 auto t_ray_point_data =
1801 getFTensor1FromPtr<3>(shadow_vec.back().rayPoint.data());
1802 auto t_unit_ray_data =
1803 getFTensor1FromPtr<3>(shadow_vec.back().unitRay.data());
1804
1805 t_slave_point(
i) = t_ray_point(
i) + m_it->first * t_unit_ray(
i);
1806
1807 auto eval_position = [&](auto &&t_elem_coords, auto &&t_point) {
1808 std::array<double, 2> loc_coords;
1811 &t_elem_coords(0, 0), &t_point(0), 1,
1812 loc_coords.data()),
1813 "get local coords");
1816 &loc_coords[0],
1817 &loc_coords[1], 1),
1818 "calc shape fun");
1822 t_point_out(
i) = t_shape_fun(
j) * t_elem_coords(
j,
i);
1823 return t_point_out;
1824 };
1825
1826 auto t_master_point_updated = eval_position(
1827 getFTensor2FromPtr<3, 3>(master_coords.data()),
1828 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data()));
1829 t_master_point(
i) = t_master_point_updated(
i);
1830
1831 auto t_slave_point_updated = eval_position(
1832 getFTensor2FromPtr<3, 3>(slave_coords.data()),
1833 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data()));
1834 t_slave_point(
i) = t_slave_point_updated(
i);
1835
1836 t_ray_point_data(
i) = t_ray_point(
i);
1837 t_unit_ray_data(
i) = t_unit_ray(
i);
1838
1839 std::copy(master_coords.begin(), master_coords.end(),
1840 shadow_vec.back().masterPointNodes.begin());
1841 std::copy(master_traction.begin(), master_traction.end(),
1842 shadow_vec.back().masterTractionNodes.begin());
1843 std::copy(slave_coords.begin(), slave_coords.end(),
1844 shadow_vec.back().slavePointNodes.begin());
1845 std::copy(slave_tractions.begin(), slave_tractions.end(),
1846 shadow_vec.back().slaveTractionNodes.begin());
1847
1848 shadow_vec.back().eleRadius = ele_radius;
1849
1850
1851
1852
1853
1854
1855
1856
1858 auto [gap, tn_master, tn_slave,
c, t_master_traction,
1859 t_slave_traction] =
1860 multiGetGap(&(shadow_vec.back()), t_spatial_coords);
1862 t_gap_vec(
i) = t_slave_point(
i) - t_spatial_coords(
i);
1863 CHKERR save_scal_tag(th_gap, gap, gg);
1864 CHKERR save_scal_tag(th_tn_master, tn_master, gg);
1865 CHKERR save_scal_tag(th_tn_slave, tn_slave, gg);
1866 CHKERR save_scal_tag(th_c,
c, gg);
1868 CHKERR save_scal_tag(th_mark_slave,
m, gg);
1869 CHKERR save_vec_tag(th_dist, t_gap_vec, gg);
1870 CHKERR save_vec_tag(th_contact_traction_master,
1871 t_master_traction, gg);
1872 CHKERR save_vec_tag(th_contact_traction_slave, t_slave_traction,
1873 gg);
1874 }
1875
1876 break;
1877 }
1878 }
1879 }
1880 break;
1881 }
1882 }
1883 next();
1884 }
1885
1887}
#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