1076 auto &m_field = getPtrFE()->mField;
1077 auto fe_ent = getNumeredEntFiniteElementPtr()->getEnt();
1086 const auto nb_gauss_pts = getGaussPts().size2();
1088 auto t_disp_h1 = getFTensor1FromMat<3>(*
uH1Ptr);
1089 auto t_coords = getFTensor1CoordsAtGaussPts();
1090 auto t_traction = getFTensor1FromMat<3>(
commonDataPtr->contactTraction);
1098 auto get_ele_centre = [
i](
auto t_ele_coords) {
1100 t_ele_center(
i) = 0;
1101 for (
int nn = 0; nn != 3; nn++) {
1102 t_ele_center(
i) += t_ele_coords(
i);
1105 t_ele_center(
i) /= 3;
1106 return t_ele_center;
1109 auto get_ele_radius = [
i](
auto t_ele_center,
auto t_ele_coords) {
1111 t_n0(
i) = t_ele_center(
i) - t_ele_coords(
i);
1115 auto get_face_conn = [
this](
auto face) {
1119 face, conn, num_nodes,
true),
1121 if (num_nodes != 3) {
1127 auto get_face_coords = [
this](
auto conn) {
1128 std::array<double, 9> coords;
1133 auto get_closet_face = [
this](
auto *point_ptr,
auto r) {
1135 std::vector<EntityHandle> faces_out;
1139 "get closest faces");
1143 auto get_faces_out = [
this](
auto *point_ptr,
auto *unit_ray_ptr,
auto radius,
1145 std::vector<double> distances_out;
1146 std::vector<EntityHandle> faces_out;
1151 point_ptr, unit_ray_ptr, &radius),
1153 "get closest faces");
1154 return std::make_pair(faces_out, distances_out);
1157 auto get_normal = [](
auto &ele_coords) {
1159 Tools::getTriNormal(ele_coords.data(), &t_normal(0));
1163 auto make_map = [&](
auto &face_out,
auto &face_dist,
auto &t_ray_point,
1164 auto &t_unit_ray,
auto &t_master_coord) {
1167 std::map<double, EntityHandle>
m;
1168 for (
auto ii = 0; ii != face_out.size(); ++ii) {
1169 auto face_conn = get_face_conn(face_out[ii]);
1172 t_face_normal.normalize();
1174 t_x(
i) = t_ray_point(
i) + t_unit_ray(
i) * face_dist[ii];
1177 t_x(
i) * t_face_normal(
j) - t_master_coord(
i) * t_unit_ray(
j);
1178 if (t_unit_ray(
i) * t_face_normal(
i) > std::cos(M_PI / 3)) {
1179 auto dot = std::sqrt(t_chi(
i,
j) * t_chi(
i,
j));
1180 m[dot] = face_out[ii];
1186 auto get_tag_data = [
this](
auto tag,
auto face,
auto &vec) {
1190 vec.resize(tag_length);
1196 auto create_tag = [
this](
const std::string tag_name,
const int size) {
1197 double def_VAL[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1201 tag_name.c_str(), size, MB_TYPE_DOUBLE,
th,
1202 MB_TAG_CREAT | MB_TAG_SPARSE, def_VAL);
1209 auto set_float_precision = [](
const double x) {
1210 if (std::abs(x) < std::numeric_limits<float>::epsilon())
1217 auto save_scal_tag = [&](
auto &
th,
auto v,
const int gg) {
1220 v = set_float_precision(
v);
1227 auto get_fe_adjacencies = [
this](
auto fe_ent) {
1230 &fe_ent, 1, 2,
false, adj_faces, moab::Interface::UNION),
1232 std::set<int> adj_ids;
1233 for (
auto f : adj_faces) {
1239 auto get_face_id = [
this](
auto face) {
1248 auto get_body_id = [
this](
auto face) {
1257 auto get_face_part = [
this](
auto face) {
1258 ParallelComm *pcomm_post_proc_mesh = ParallelComm::get_pcomm(
1262 pcomm_post_proc_mesh->part_tag(), &face, 1, &part) == MB_SUCCESS) {
1268 auto check_face = [&](
auto face,
auto fe_id,
auto part) {
1269 auto face_id = get_face_id(face);
1270 auto face_part = get_face_part(face);
1271 if (face_id == fe_id && face_part == part)
1279 auto save_vec_tag = [&](
auto &
th,
auto &t_d,
const int gg) {
1283 for (
auto &
a :
v.data())
1284 a = set_float_precision(
a);
1286 &*
v.data().begin());
1291 Tag th_mark = create_tag(
"contact_mark", 1);
1292 Tag th_mark_slave = create_tag(
"contact_mark_slave", 1);
1293 Tag th_body_id = create_tag(
"contact_body_id", 1);
1294 Tag th_gap = create_tag(
"contact_gap", 1);
1295 Tag th_tn_master = create_tag(
"contact_tn_master", 1);
1296 Tag th_tn_slave = create_tag(
"contact_tn_slave", 1);
1297 Tag th_contact_traction = create_tag(
"contact_traction", 3);
1298 Tag th_contact_traction_master = create_tag(
"contact_traction_master", 3);
1299 Tag th_contact_traction_slave = create_tag(
"contact_traction_slave", 3);
1300 Tag th_c = create_tag(
"contact_c", 1);
1301 Tag th_normal = create_tag(
"contact_normal", 3);
1302 Tag th_dist = create_tag(
"contact_dip", 3);
1304 auto t_ele_centre = get_ele_centre(getFTensor1Coords());
1305 auto ele_radius = get_ele_radius(t_ele_centre, getFTensor1Coords());
1311 auto adj_fe_ids = get_fe_adjacencies(fe_ent);
1313 for (
auto gg = 0; gg != nb_gauss_pts; ++gg) {
1316 t_spatial_coords(
i) = t_coords(
i) + t_disp_h1(
i);
1319 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1322 auto faces_close = get_closet_face(&t_spatial_coords(0), ele_radius);
1323 for (
auto face_close : faces_close) {
1324 if (check_face(face_close, fe_id, m_field.get_comm_rank())) {
1326 auto body_id = get_body_id(face_close);
1328 auto master_face_conn = get_face_conn(face_close);
1329 std::array<double, 9> master_coords;
1332 master_coords.data());
1333 std::array<double, 9> master_traction;
1336 master_traction.data());
1337 auto t_normal_face_close = get_normal(master_coords);
1338 t_normal_face_close.normalize();
1342 CHKERR save_scal_tag(th_mark,
m, gg);
1343 CHKERR save_scal_tag(th_body_id,
static_cast<double>(body_id), gg);
1344 CHKERR save_vec_tag(th_normal, t_normal_face_close, gg);
1345 CHKERR save_vec_tag(th_contact_traction, t_traction, gg);
1349 t_unit_ray(
i) = -t_normal_face_close(
i);
1351 t_ray_point(
i) = t_spatial_coords(
i) - t_unit_ray(
i) * ele_radius;
1353 constexpr
double eps = 1e-3;
1354 auto [faces_out, faces_dist] = get_faces_out(
1355 &t_ray_point(0), &t_unit_ray(0), 2 * ele_radius,
eps * ele_radius);
1357 auto m = make_map(faces_out, faces_dist, t_ray_point, t_unit_ray,
1359 for (
auto m_it =
m.begin(); m_it !=
m.end(); ++m_it) {
1360 auto face = m_it->second;
1361 if (face != face_close) {
1365 body_id != get_body_id(face) &&
1366 (adj_fe_ids.find(get_face_id(face)) == adj_fe_ids.end() ||
1367 get_face_part(face) != m_field.get_comm_rank())
1371 shadow_vec.push_back(ContactTree::FaceData());
1372 shadow_vec.back().gaussPtNb = gg;
1374 auto slave_face_conn = get_face_conn(face);
1375 std::array<double, 9> slave_coords;
1378 slave_coords.data());
1379 auto t_normal_face = get_normal(slave_coords);
1380 std::array<double, 9> slave_tractions;
1383 slave_tractions.data());
1385 auto t_master_point =
1386 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data());
1387 auto t_slave_point =
1388 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data());
1389 auto t_ray_point_data =
1390 getFTensor1FromPtr<3>(shadow_vec.back().rayPoint.data());
1391 auto t_unit_ray_data =
1392 getFTensor1FromPtr<3>(shadow_vec.back().unitRay.data());
1394 t_slave_point(
i) = t_ray_point(
i) + m_it->first * t_unit_ray(
i);
1396 auto eval_position = [&](
auto &&t_elem_coords,
auto &&t_point) {
1397 std::array<double, 2> loc_coords;
1399 Tools::getLocalCoordinatesOnReferenceThreeNodeTri(
1400 &t_elem_coords(0, 0), &t_point(0), 1,
1402 "get local coords");
1411 t_point_out(
i) = t_shape_fun(
j) * t_elem_coords(
j,
i);
1415 auto t_master_point_updated = eval_position(
1416 getFTensor2FromPtr<3, 3>(master_coords.data()),
1417 getFTensor1FromPtr<3>(shadow_vec.back().masterPoint.data()));
1418 t_master_point(
i) = t_master_point_updated(
i);
1420 auto t_slave_point_updated = eval_position(
1421 getFTensor2FromPtr<3, 3>(slave_coords.data()),
1422 getFTensor1FromPtr<3>(shadow_vec.back().slavePoint.data()));
1423 t_slave_point(
i) = t_slave_point_updated(
i);
1425 t_ray_point_data(
i) = t_ray_point(
i);
1426 t_unit_ray_data(
i) = t_unit_ray(
i);
1428 std::copy(master_coords.begin(), master_coords.end(),
1429 shadow_vec.back().masterPointNodes.begin());
1430 std::copy(master_traction.begin(), master_traction.end(),
1431 shadow_vec.back().masterTractionNodes.begin());
1432 std::copy(slave_coords.begin(), slave_coords.end(),
1433 shadow_vec.back().slavePointNodes.begin());
1434 std::copy(slave_tractions.begin(), slave_tractions.end(),
1435 shadow_vec.back().slaveTractionNodes.begin());
1437 shadow_vec.back().eleRadius = ele_radius;
1447 auto [gap, tn_master, tn_slave,
c, t_master_traction,
1449 multiGetGap(&(shadow_vec.back()), t_spatial_coords);
1451 t_gap_vec(
i) = t_slave_point(
i) - t_spatial_coords(
i);
1452 CHKERR save_scal_tag(th_gap, gap, gg);
1453 CHKERR save_scal_tag(th_tn_master, tn_master, gg);
1454 CHKERR save_scal_tag(th_tn_slave, tn_slave, gg);
1455 CHKERR save_scal_tag(th_c,
c, gg);
1457 CHKERR save_scal_tag(th_mark_slave,
m, gg);
1458 CHKERR save_vec_tag(th_dist, t_gap_vec, gg);
1459 CHKERR save_vec_tag(th_contact_traction_master,
1460 t_master_traction, gg);
1461 CHKERR save_vec_tag(th_contact_traction_slave, t_slave_traction,