v0.15.5
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
EshelbianPlasticity::OpTreeSearch Struct Reference
Inheritance diagram for EshelbianPlasticity::OpTreeSearch:
[legend]
Collaboration diagram for EshelbianPlasticity::OpTreeSearch:
[legend]

Public Types

using UOP = FaceElementForcesAndSourcesCore::UserDataOperator
 

Public Member Functions

 OpTreeSearch (boost::shared_ptr< ContactTree > contact_tree_ptr, boost::shared_ptr< MatrixDouble > u_h1_ptr, boost::shared_ptr< MatrixDouble > traction_ptr, Range r, moab::Interface *post_proc_mesh_ptr, std::vector< EntityHandle > *map_gauss_pts_ptr)
 
MoFEMErrorCode doWork (int side, EntityType type, EntitiesFieldData::EntData &data)
 

Protected Attributes

boost::shared_ptr< ContactTreecontactTreePtr
 
boost::shared_ptr< MatrixDouble > uH1Ptr
 
boost::shared_ptr< MatrixDouble > tractionPtr
 
moab::Interface * postProcMeshPtr = nullptr
 
std::vector< EntityHandle > * mapGaussPtsPtr = nullptr
 
Range contactRange
 

Detailed Description

Definition at line 1441 of file EshelbianContact.cpp.

Member Typedef Documentation

◆ UOP

using EshelbianPlasticity::OpTreeSearch::UOP = FaceElementForcesAndSourcesCore::UserDataOperator

Definition at line 1443 of file EshelbianContact.cpp.

Constructor & Destructor Documentation

◆ OpTreeSearch()

EshelbianPlasticity::OpTreeSearch::OpTreeSearch ( boost::shared_ptr< ContactTree contact_tree_ptr,
boost::shared_ptr< MatrixDouble >  u_h1_ptr,
boost::shared_ptr< MatrixDouble >  traction_ptr,
Range  r,
moab::Interface *  post_proc_mesh_ptr,
std::vector< EntityHandle > *  map_gauss_pts_ptr 
)

Definition at line 1466 of file EshelbianContact.cpp.

1475 : UOP(NOSPACE, UOP::OPSPACE), contactTreePtr(contact_tree_ptr),
1476 uH1Ptr(u_h1_ptr), tractionPtr(traction_ptr),
1477 postProcMeshPtr(post_proc_mesh_ptr), mapGaussPtsPtr(map_gauss_pts_ptr),
1478 contactRange(r) {}
@ NOSPACE
Definition definitions.h:83
boost::shared_ptr< ContactTree > contactTreePtr
std::vector< EntityHandle > * mapGaussPtsPtr
boost::shared_ptr< MatrixDouble > uH1Ptr
boost::shared_ptr< MatrixDouble > tractionPtr
FaceElementForcesAndSourcesCore::UserDataOperator UOP

Member Function Documentation

◆ doWork()

MoFEMErrorCode EshelbianPlasticity::OpTreeSearch::doWork ( int  side,
EntityType  type,
EntitiesFieldData::EntData data 
)

Definition at line 1480 of file EshelbianContact.cpp.

1481 {
1483
1484 auto &m_field = getPtrFE()->mField;
1485 auto fe_ent = getNumeredEntFiniteElementPtr()->getEnt();
1486 auto fe_id = id_from_handle(fe_ent);
1487
1488 if (contactRange.find(fe_ent) == contactRange.end())
1490
1491 FTensor::Index<'i', 3> i;
1492 FTensor::Index<'j', 3> j;
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) {
1507 FTensor::Tensor1<double, 3> t_ele_center;
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);
1520 return t_n0.l2();
1521 };
1522
1523 auto get_face_conn = [this](auto face) {
1524 const EntityHandle *conn;
1525 int num_nodes;
1526 CHK_MOAB_THROW(contactTreePtr->getPostProcMesh().get_connectivity(
1527 face, conn, num_nodes, true),
1528 "get conn");
1529 if (num_nodes != 3) {
1530 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "face is not a triangle");
1531 }
1532 return conn;
1533 };
1534
1535 auto get_face_coords = [this](auto conn) {
1536 std::array<double, 9> coords;
1537 CHKERR contactTreePtr->getPostProcMesh().get_coords(conn, 3, coords.data());
1538 return coords;
1539 };
1540
1541 auto get_closet_face = [this](auto *point_ptr, auto r) {
1542 FTensor::Tensor1<double, 3> t_point_out;
1543 std::vector<EntityHandle> faces_out;
1545 contactTreePtr->getTreeSurfPtr()->sphere_intersect_triangles(
1546 point_ptr, r / 8, contactTreePtr->getRootSetSurf(), 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,
1552 auto eps) {
1553 std::vector<double> distances_out;
1554 std::vector<EntityHandle> faces_out;
1556
1557 contactTreePtr->getTreeSurfPtr()->ray_intersect_triangles(
1558 distances_out, faces_out, contactTreePtr->getRootSetSurf(), eps,
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) {
1567 Tools::getTriNormal(ele_coords.data(), &t_normal(0));
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) {
1573 FTensor::Index<'i', 3> i;
1574 FTensor::Index<'j', 3> j;
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]);
1578 auto face_coords = get_face_coords(face_conn);
1579 auto t_face_normal = get_normal(face_coords);
1580 t_face_normal.normalize();
1582 t_x(i) = t_ray_point(i) + t_unit_ray(i) * face_dist[ii];
1584 t_chi(i, j) =
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 }
1591 return m;
1592 };
1593
1594 auto get_tag_data = [this](auto tag, auto face, auto &vec) {
1596 int tag_length;
1597 CHKERR contactTreePtr->getPostProcMesh().tag_get_length(tag, tag_length);
1598 vec.resize(tag_length);
1599 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(tag, &face, 1,
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};
1606 Tag th;
1607 if (postProcMeshPtr) {
1608 CHKERR postProcMeshPtr->tag_get_handle(
1609 tag_name.c_str(), size, MB_TYPE_DOUBLE, th,
1610 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
1611 CHKERR postProcMeshPtr->tag_clear_data(th, &*mapGaussPtsPtr->begin(),
1612 mapGaussPtsPtr->size(), def_VAL);
1613 }
1614 return th;
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 // scalars
1625 auto save_scal_tag = [&](auto &th, auto v, const int gg) {
1627 if (postProcMeshPtr) {
1628 v = set_float_precision(v);
1629 CHKERR postProcMeshPtr->tag_set_data(th, &(*mapGaussPtsPtr)[gg], 1, &v);
1630 }
1632 };
1633
1634 // adjacencies
1635 auto get_fe_adjacencies = [this](auto fe_ent) {
1636 Range adj_faces;
1637 CHK_MOAB_THROW(getFaceFE()->mField.get_moab().get_adjacencies(
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) {
1642 adj_ids.insert(id_from_handle(f));
1643 }
1644 return adj_ids;
1645 };
1646
1647 auto get_face_id = [this](auto face) {
1648 int id;
1649 if (contactTreePtr->getPostProcMesh().tag_get_data(
1650 contactTreePtr->thEleId, &face, 1, &id) == MB_SUCCESS) {
1651 return id;
1652 }
1653 return -1;
1654 };
1655
1656 auto get_body_id = [this](auto face) {
1657 int id;
1658 if (contactTreePtr->getPostProcMesh().tag_get_data(
1659 contactTreePtr->thBodyId, &face, 1, &id) == MB_SUCCESS) {
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)
1668 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "PComm not allocated");
1669 int part;
1670 if (contactTreePtr->getPostProcMesh().tag_get_data(
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 // vectors
1686 VectorDouble3 v(3);
1687 FTensor::Tensor1<FTensor::PackPtr<double *, 0>, 3> t_v(&v[0], &v[1], &v[2]);
1688 auto save_vec_tag = [&](auto &th, auto &t_d, const int gg) {
1690 if (postProcMeshPtr) {
1691 t_v(i) = t_d(i);
1692 for (auto &a : v.data())
1693 a = set_float_precision(a);
1694 CHKERR postProcMeshPtr->tag_set_data(th, &(*mapGaussPtsPtr)[gg], 1,
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
1716 contactTreePtr->shadowDataMap.clear();
1717 auto &shadow_vec = contactTreePtr->shadowDataMap[fe_ent];
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
1724 FTensor::Tensor1<double, 3> t_spatial_coords;
1725 t_spatial_coords(i) = t_coords(i) + t_disp_h1(i);
1726
1727 if (postProcMeshPtr) {
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;
1739 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1740 contactTreePtr->thSmallX, master_face_conn, 3,
1741 master_coords.data());
1742 std::array<double, 9> master_traction;
1743 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1744 contactTreePtr->thTraction, master_face_conn, 3,
1745 master_traction.data());
1746 auto t_normal_face_close = get_normal(master_coords);
1747 t_normal_face_close.normalize();
1748
1749 if (postProcMeshPtr) {
1750 double m = 1;
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
1757 FTensor::Tensor1<double, 3> t_unit_ray;
1758 t_unit_ray(i) = -t_normal_face_close(i);
1759 FTensor::Tensor1<double, 3> t_ray_point;
1760 t_ray_point(i) =
1761 t_spatial_coords(i) -
1762 t_unit_ray(i) * ContactOps::airplane_ray_distance * ele_radius;
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),
1767 2 * ContactOps::airplane_ray_distance * ele_radius,
1768 eps * ele_radius);
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;
1788 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1789 contactTreePtr->thSmallX, slave_face_conn, 3,
1790 slave_coords.data());
1791 auto t_normal_face = get_normal(slave_coords);
1792 std::array<double, 9> slave_tractions;
1793 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1794 contactTreePtr->thTraction, slave_face_conn, 3,
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");
1815 FTensor::Tensor1<double, 3> t_shape_fun;
1816 CHK_THROW_MESSAGE(Tools::shapeFunMBTRI<0>(&t_shape_fun(0),
1817 &loc_coords[0],
1818 &loc_coords[1], 1),
1819 "calc shape fun");
1820 FTensor::Index<'i', 3> i;
1821 FTensor::Index<'j', 3> j;
1822 FTensor::Tensor1<double, 3> t_point_out;
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 // CHKERR get_tag_data(contactTreePtr->thIds, face,
1852 // shadow_vec.back().dofsSlaveIds);
1853 // CHKERR get_tag_data(contactTreePtr->thCoeff, face,
1854 // shadow_vec.back().dofsSlaveCoeff);
1855 // CHKERR get_tag_data(contactTreePtr->thBases, face,
1856 // shadow_vec.back().baseSlaveFuncs);
1857
1858 if (postProcMeshPtr) {
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);
1868 double m = 1;
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}
constexpr double a
static const double eps
#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
Definition definitions.h:31
#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
double airplane_ray_distance
auto multiGetGap(ContactTree::FaceData *face_data_ptr, FTensor::Tensor1< T1, 3 > &t_spatial_coords)
VectorBoundedArray< double, 3 > VectorDouble3
Definition Types.hpp:92
auto id_from_handle(const EntityHandle h)
int r
Definition sdf.py:205
FTensor::Index< 'm', 3 > m
static MoFEMErrorCode getLocalCoordinatesOnReferenceThreeNodeTri(const double *elem_coords, const double *glob_coords, const int nb_nodes, double *local_coords)
Get the local coordinates on reference three node tri object.
Definition Tools.cpp:188
static MoFEMErrorCode getTriNormal(const double *coords, double *normal, double *d_normal=nullptr)
Get the Tri Normal objectGet triangle normal.
Definition Tools.cpp:353

Member Data Documentation

◆ contactRange

Range EshelbianPlasticity::OpTreeSearch::contactRange
protected

Definition at line 1463 of file EshelbianContact.cpp.

◆ contactTreePtr

boost::shared_ptr<ContactTree> EshelbianPlasticity::OpTreeSearch::contactTreePtr
protected

Definition at line 1457 of file EshelbianContact.cpp.

◆ mapGaussPtsPtr

std::vector<EntityHandle>* EshelbianPlasticity::OpTreeSearch::mapGaussPtsPtr = nullptr
protected

Definition at line 1461 of file EshelbianContact.cpp.

◆ postProcMeshPtr

moab::Interface* EshelbianPlasticity::OpTreeSearch::postProcMeshPtr = nullptr
protected

Definition at line 1460 of file EshelbianContact.cpp.

◆ tractionPtr

boost::shared_ptr<MatrixDouble> EshelbianPlasticity::OpTreeSearch::tractionPtr
protected

Definition at line 1459 of file EshelbianContact.cpp.

◆ uH1Ptr

boost::shared_ptr<MatrixDouble> EshelbianPlasticity::OpTreeSearch::uH1Ptr
protected

Definition at line 1458 of file EshelbianContact.cpp.


The documentation for this struct was generated from the following file: