v0.16.3
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< ContactTree > contactTreePtr
 
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 1443 of file EshelbianContact.cpp.

Member Typedef Documentation

◆ UOP

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

Definition at line 1445 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 1468 of file EshelbianContact.cpp.

1477 : UOP(NOSPACE, UOP::OPSPACE), contactTreePtr(contact_tree_ptr),
1478 uH1Ptr(u_h1_ptr), tractionPtr(traction_ptr),
1479 postProcMeshPtr(post_proc_mesh_ptr), mapGaussPtsPtr(map_gauss_pts_ptr),
1480 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 1482 of file EshelbianContact.cpp.

1483 {
1485
1486 auto &m_field = getPtrFE()->mField;
1487 auto fe_ent = getNumeredEntFiniteElementPtr()->getEnt();
1488 auto fe_id = id_from_handle(fe_ent);
1489
1490 if (contactRange.find(fe_ent) == contactRange.end())
1492
1493 FTensor::Index<'i', 3> i;
1494 FTensor::Index<'j', 3> j;
1495
1496 const auto nb_gauss_pts = getGaussPts().size2();
1497
1498 auto t_disp_h1 = getFTensor1FromMat<3>(*uH1Ptr);
1499 auto t_coords = getFTensor1CoordsAtGaussPts();
1500 auto t_traction = getFTensor1FromMat<3>(*tractionPtr);
1501
1502 auto next = [&]() {
1503 ++t_disp_h1;
1504 ++t_traction;
1505 ++t_coords;
1506 };
1507
1508 auto get_ele_centre = [i](auto t_ele_coords) {
1509 FTensor::Tensor1<double, 3> t_ele_center;
1510 t_ele_center(i) = 0;
1511 for (int nn = 0; nn != 3; nn++) {
1512 t_ele_center(i) += t_ele_coords(i);
1513 ++t_ele_coords;
1514 }
1515 t_ele_center(i) /= 3;
1516 return t_ele_center;
1517 };
1518
1519 auto get_ele_radius = [i](auto t_ele_center, auto t_ele_coords) {
1521 t_n0(i) = t_ele_center(i) - t_ele_coords(i);
1522 return t_n0.l2();
1523 };
1524
1525 auto get_face_conn = [this](auto face) {
1526 const EntityHandle *conn;
1527 int num_nodes;
1528 CHK_MOAB_THROW(contactTreePtr->getPostProcMesh().get_connectivity(
1529 face, conn, num_nodes, true),
1530 "get conn");
1531 if (num_nodes != 3) {
1532 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "face is not a triangle");
1533 }
1534 return conn;
1535 };
1536
1537 auto get_face_coords = [this](auto conn) {
1538 std::array<double, 9> coords;
1539 CHKERR contactTreePtr->getPostProcMesh().get_coords(conn, 3, coords.data());
1540 return coords;
1541 };
1542
1543 auto get_closet_face = [this](auto *point_ptr, auto r) {
1544 FTensor::Tensor1<double, 3> t_point_out;
1545 std::vector<EntityHandle> faces_out;
1547 contactTreePtr->getTreeSurfPtr()->sphere_intersect_triangles(
1548 point_ptr, r / 8, contactTreePtr->getRootSetSurf(), faces_out),
1549 "get closest faces");
1550 return faces_out;
1551 };
1552
1553 auto get_faces_out = [this](auto *point_ptr, auto *unit_ray_ptr, auto radius,
1554 auto eps) {
1555 std::vector<double> distances_out;
1556 std::vector<EntityHandle> faces_out;
1558
1559 contactTreePtr->getTreeSurfPtr()->ray_intersect_triangles(
1560 distances_out, faces_out, contactTreePtr->getRootSetSurf(), eps,
1561 point_ptr, unit_ray_ptr, &radius),
1562
1563 "get closest faces");
1564 return std::make_pair(faces_out, distances_out);
1565 };
1566
1567 auto get_normal = [](auto &ele_coords) {
1569 Tools::getTriNormal(ele_coords.data(), &t_normal(0));
1570 return t_normal;
1571 };
1572
1573 auto make_map = [&](auto &face_out, auto &face_dist, auto &t_ray_point,
1574 auto &t_unit_ray, auto &t_master_coord) {
1575 FTensor::Index<'i', 3> i;
1576 FTensor::Index<'j', 3> j;
1577 std::map<double, EntityHandle> m;
1578 for (auto ii = 0; ii != face_out.size(); ++ii) {
1579 auto face_conn = get_face_conn(face_out[ii]);
1580 auto face_coords = get_face_coords(face_conn);
1581 auto t_face_normal = get_normal(face_coords);
1582 t_face_normal.normalize();
1584 t_x(i) = t_ray_point(i) + t_unit_ray(i) * face_dist[ii];
1586 t_chi(i, j) =
1587 t_x(i) * t_face_normal(j) - t_master_coord(i) * t_unit_ray(j);
1588 if (t_unit_ray(i) * t_face_normal(i) > std::cos(M_PI / 3)) {
1589 auto dot = std::sqrt(t_chi(i, j) * t_chi(i, j));
1590 m[dot] = face_out[ii];
1591 }
1592 }
1593 return m;
1594 };
1595
1596 auto create_tag = [this](const std::string tag_name, const int size) {
1597 double def_VAL[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1598 Tag th;
1599 if (postProcMeshPtr) {
1600 CHKERR postProcMeshPtr->tag_get_handle(
1601 tag_name.c_str(), size, MB_TYPE_DOUBLE, th,
1602 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
1603 CHKERR postProcMeshPtr->tag_clear_data(th, &*mapGaussPtsPtr->begin(),
1604 mapGaussPtsPtr->size(), def_VAL);
1605 }
1606 return th;
1607 };
1608
1609 auto set_float_precision = [](const double x) {
1610 if (std::abs(x) < std::numeric_limits<float>::epsilon())
1611 return 0.;
1612 else
1613 return x;
1614 };
1615
1616 // scalars
1617 auto save_scal_tag = [&](auto &th, auto v, const int gg) {
1619 if (postProcMeshPtr) {
1620 v = set_float_precision(v);
1621 CHKERR postProcMeshPtr->tag_set_data(th, &(*mapGaussPtsPtr)[gg], 1, &v);
1622 }
1624 };
1625
1626 // adjacencies
1627 auto get_fe_adjacencies = [this](auto fe_ent) {
1628 Range adj_faces;
1629 CHK_MOAB_THROW(getFaceFE()->mField.get_moab().get_adjacencies(
1630 &fe_ent, 1, 2, false, adj_faces, moab::Interface::UNION),
1631 "get adj");
1632 std::set<int> adj_ids;
1633 for (auto f : adj_faces) {
1634 adj_ids.insert(id_from_handle(f));
1635 }
1636 return adj_ids;
1637 };
1638
1639 auto get_face_id = [this](auto face) {
1640 int id;
1641 if (contactTreePtr->getPostProcMesh().tag_get_data(
1642 contactTreePtr->thEleId, &face, 1, &id) == MB_SUCCESS) {
1643 return id;
1644 }
1645 return -1;
1646 };
1647
1648 auto get_body_id = [this](auto face) {
1649 int id;
1650 if (contactTreePtr->getPostProcMesh().tag_get_data(
1651 contactTreePtr->thBodyId, &face, 1, &id) == MB_SUCCESS) {
1652 return id;
1653 }
1654 return -1;
1655 };
1656
1657 auto get_face_part = [this](auto face) {
1658 const moab::Core *core_mesh_ptr =
1659 dynamic_cast<const moab::Core *>(&contactTreePtr->getPostProcMesh());
1660 auto pcomm_post_proc_mesh =
1661 MeshPCommRegistry::getOrCreate(const_cast<moab::Core *>(core_mesh_ptr));
1662 int part;
1663 if (contactTreePtr->getPostProcMesh().tag_get_data(
1664 pcomm_post_proc_mesh->part_tag(), &face, 1, &part) == MB_SUCCESS) {
1665 return part;
1666 }
1667 return -1;
1668 };
1669
1670 auto check_face = [&](auto face, auto fe_id, auto part) {
1671 auto face_id = get_face_id(face);
1672 auto face_part = get_face_part(face);
1673 if (face_id == fe_id && face_part == part)
1674 return true;
1675 return false;
1676 };
1677
1678 // vectors
1679 VectorDouble3 v(3);
1680 FTensor::Tensor1<FTensor::PackPtr<double *, 0>, 3> t_v(&v[0], &v[1], &v[2]);
1681 auto save_vec_tag = [&](auto &th, auto &t_d, const int gg) {
1683 if (postProcMeshPtr) {
1684 t_v(i) = t_d(i);
1685 for (auto &a : v.data())
1686 a = set_float_precision(a);
1687 CHKERR postProcMeshPtr->tag_set_data(th, &(*mapGaussPtsPtr)[gg], 1,
1688 &*v.data().begin());
1689 }
1691 };
1692
1693 Tag th_mark = create_tag("contact_mark", 1);
1694 Tag th_mark_slave = create_tag("contact_mark_slave", 1);
1695 Tag th_body_id = create_tag("contact_body_id", 1);
1696 Tag th_gap = create_tag("contact_gap", 1);
1697 Tag th_tn_master = create_tag("contact_tn_master", 1);
1698 Tag th_tn_slave = create_tag("contact_tn_slave", 1);
1699 Tag th_contact_traction = create_tag("contact_traction", 3);
1700 Tag th_contact_traction_master = create_tag("contact_traction_master", 3);
1701 Tag th_contact_traction_slave = create_tag("contact_traction_slave", 3);
1702 Tag th_c = create_tag("contact_c", 1);
1703 Tag th_normal = create_tag("contact_normal", 3);
1704 Tag th_dist = create_tag("contact_dip", 3);
1705
1706 auto t_ele_centre = get_ele_centre(getFTensor1Coords());
1707 auto ele_radius = get_ele_radius(t_ele_centre, getFTensor1Coords());
1708
1709 contactTreePtr->shadowDataMap.clear();
1710 auto &shadow_vec = contactTreePtr->shadowDataMap[fe_ent];
1711 shadow_vec.clear();
1712
1713 auto adj_fe_ids = get_fe_adjacencies(fe_ent);
1714
1715 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
1716
1717 FTensor::Tensor1<double, 3> t_spatial_coords;
1718 t_spatial_coords(i) = t_coords(i) + t_disp_h1(i);
1719
1720 if (postProcMeshPtr) {
1721 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1722 }
1723
1724 auto faces_close = get_closet_face(&t_spatial_coords(0), ele_radius);
1725 for (auto face_close : faces_close) {
1726 if (check_face(face_close, fe_id, m_field.get_comm_rank())) {
1727
1728 auto body_id = get_body_id(face_close);
1729
1730 auto master_face_conn = get_face_conn(face_close);
1731 std::array<double, 9> master_coords;
1732 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1733 contactTreePtr->thSmallX, master_face_conn, 3,
1734 master_coords.data());
1735 std::array<double, 9> master_traction;
1736 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1737 contactTreePtr->thTraction, master_face_conn, 3,
1738 master_traction.data());
1739 auto t_normal_face_close = get_normal(master_coords);
1740 t_normal_face_close.normalize();
1741
1742 if (postProcMeshPtr) {
1743 double m = 1;
1744 CHKERR save_scal_tag(th_mark, m, gg);
1745 CHKERR save_scal_tag(th_body_id, static_cast<double>(body_id), gg);
1746 CHKERR save_vec_tag(th_normal, t_normal_face_close, gg);
1747 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1748 }
1749
1750 FTensor::Tensor1<double, 3> t_unit_ray;
1751 t_unit_ray(i) = -t_normal_face_close(i);
1752 FTensor::Tensor1<double, 3> t_ray_point;
1753 t_ray_point(i) =
1754 t_spatial_coords(i) -
1755 t_unit_ray(i) * ContactOps::airplane_ray_distance * ele_radius;
1756
1757 constexpr double eps = 1e-3;
1758 auto [faces_out, faces_dist] =
1759 get_faces_out(&t_ray_point(0), &t_unit_ray(0),
1760 2 * ContactOps::airplane_ray_distance * ele_radius,
1761 eps * ele_radius);
1762
1763 auto m = make_map(faces_out, faces_dist, t_ray_point, t_unit_ray,
1764 t_spatial_coords);
1765 for (auto m_it = m.begin(); m_it != m.end(); ++m_it) {
1766 auto face = m_it->second;
1767 if (face != face_close) {
1768
1769 if (
1770
1771 (adj_fe_ids.find(get_face_id(face)) == adj_fe_ids.end() ||
1772 get_face_part(face) != m_field.get_comm_rank())
1773
1774 ) {
1775
1776 shadow_vec.push_back(ContactTree::FaceData());
1777 shadow_vec.back().gaussPtNb = gg;
1778
1779 auto slave_face_conn = get_face_conn(face);
1780 std::array<double, 9> slave_coords;
1781 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1782 contactTreePtr->thSmallX, slave_face_conn, 3,
1783 slave_coords.data());
1784 std::array<double, 9> slave_tractions;
1785 CHKERR contactTreePtr->getPostProcMesh().tag_get_data(
1786 contactTreePtr->thTraction, slave_face_conn, 3,
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");
1807 FTensor::Tensor1<double, 3> t_shape_fun;
1808 CHK_THROW_MESSAGE(Tools::shapeFunMBTRI<0>(&t_shape_fun(0),
1809 &loc_coords[0],
1810 &loc_coords[1], 1),
1811 "calc shape fun");
1812 FTensor::Index<'i', 3> i;
1813 FTensor::Index<'j', 3> j;
1814 FTensor::Tensor1<double, 3> t_point_out;
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 // CHKERR get_tag_data(contactTreePtr->thIds, face,
1844 // shadow_vec.back().dofsSlaveIds);
1845 // CHKERR get_tag_data(contactTreePtr->thCoeff, face,
1846 // shadow_vec.back().dofsSlaveCoeff);
1847 // CHKERR get_tag_data(contactTreePtr->thBases, face,
1848 // shadow_vec.back().baseSlaveFuncs);
1849
1850 if (postProcMeshPtr) {
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);
1860 double m = 1;
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}
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 auto getOrCreate(moab::Core *core_mesh_ptr)
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 1465 of file EshelbianContact.cpp.

◆ contactTreePtr

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

Definition at line 1459 of file EshelbianContact.cpp.

◆ mapGaussPtsPtr

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

Definition at line 1463 of file EshelbianContact.cpp.

◆ postProcMeshPtr

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

Definition at line 1462 of file EshelbianContact.cpp.

◆ tractionPtr

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

Definition at line 1461 of file EshelbianContact.cpp.

◆ uH1Ptr

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

Definition at line 1460 of file EshelbianContact.cpp.


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