44#ifndef NIMBLE_CONTACTENTITY_H
45#define NIMBLE_CONTACTENTITY_H
59#include <bvh/kdop.hpp>
60#include <bvh/types.hpp>
78 double a[3], b[3], cross[3], area;
79 a[0] = pt_2_x - pt_1_x;
80 a[1] = pt_2_y - pt_1_y;
81 a[2] = pt_2_z - pt_1_z;
82 b[0] = pt_3_x - pt_1_x;
83 b[1] = pt_3_y - pt_1_y;
84 b[2] = pt_3_z - pt_1_z;
86 area = 0.5 * std::sqrt(cross[0] * cross[0] + cross[1] * cross[1] + cross[2] * cross[2]);
94 return ((p[0] - p1[0]) * (p2[0] - p1[0]) + (p[1] - p1[1]) * (p2[1] - p1[1]) + (p[2] - p1[2]) * (p2[2] - p1[2])) /
95 ((p2[0] - p1[0]) * (p2[0] - p1[0]) + (p2[1] - p1[1]) * (p2[1] - p1[1]) + (p2[2] - p1[2]) * (p2[2] - p1[2]));
102 double temp1 = p1[0] + (p2[0] - p1[0]) * t - p[0];
103 double temp2 = p1[1] + (p2[1] - p1[1]) * t - p[1];
104 double temp3 = p1[2] + (p2[2] - p1[2]) * t - p[2];
105 return (temp1 * temp1 + temp2 * temp2 + temp3 * temp3);
110 std::string
const& command,
111 std::vector<std::string>& primary_block_names,
112 std::vector<std::string>& secondary_block_names,
113 double& penalty_parameter);
169 double const coord[],
170 double characteristic_length,
171 int node_id_for_node_1,
172 int node_id_for_node_2 = 0,
173 const int node_ids_for_fictitious_node[4] = 0)
179 characteristic_length,
182 node_ids_for_fictitious_node)
190 int contact_entity_local_id,
191 double const coord[],
192 double characteristic_length,
193 int node_id_for_node_1,
194 int node_id_for_node_2 = 0,
195 const int node_ids_for_fictitious_node[4] = 0)
215 printf(
"\n**** Error in ContactEntity constructor, invalid entity type.\n");
235 template <
typename ArgT>
252 coord_3_x_ = (coord[n0] + coord[n1] + coord[n2] + coord[n3]) / 4.0;
253 coord_3_y_ = (coord[n0 + 1] + coord[n1 + 1] + coord[n2 + 1] + coord[n3 + 1]) / 4.0;
254 coord_3_z_ = (coord[n0 + 2] + coord[n1 + 2] + coord[n2 + 2] + coord[n3 + 2]) / 4.0;
259 template <
typename ArgT>
264#ifdef NIMBLE_HAVE_KOKKOS
266 Kokkos::atomic_add(&force[n + 1],
force_1_y_);
267 Kokkos::atomic_add(&force[n + 2],
force_1_z_);
275#ifdef NIMBLE_HAVE_KOKKOS
277 Kokkos::atomic_add(&force[n + 1],
force_2_y_);
278 Kokkos::atomic_add(&force[n + 2],
force_2_z_);
284 std::vector<int> list{
289 for (
const auto n : list) {
290#ifdef NIMBLE_HAVE_KOKKOS
291 Kokkos::atomic_add(&force[n],
force_3_x_ / 4.0);
292 Kokkos::atomic_add(&force[n + 1],
force_3_y_ / 4.0);
293 Kokkos::atomic_add(&force[n + 2],
force_3_z_ / 4.0);
377#ifdef NIMBLE_HAVE_KOKKOS
384#ifdef NIMBLE_HAVE_BVH
385 bvh::bphase_kdop kdop_;
396 kdop_ = bvh::bphase_kdop::from_vertices(&v, &v + 1, inflation_length);
409 kdop_ = bvh::bphase_kdop::from_vertices(v, v + 3, inflation_length);
440 throw std::invalid_argument(
"\n Null pointer provided.\n\n");
460 double N[3] = {0.0, 0.0, 0.0};
467 closest_point_projection[0],
468 closest_point_projection[1],
469 closest_point_projection[2],
480 closest_point_projection[0],
481 closest_point_projection[1],
482 closest_point_projection[2],
488 N[0] = area_1 / full_area;
489 N[1] = area_2 / full_area;
490 N[2] = 1.0 - N[0] - N[1];
521 template <
typename ArgT>
525 template <
typename ArgT>
598template <
typename ArgT>
602 constexpr size_t size_int =
sizeof(int);
603 constexpr size_t size_double =
sizeof(double);
604 size_t entity_size = 10 *
sizeof(double) + 8 *
sizeof(
int);
605 buffer.resize(entity_size * num_entities);
606 char* scan = &buffer[0];
607 for (
int i = 0; i < num_entities; i++) {
608 memcpy(scan, &contact_entities[i].
coord_1_x_, size_double);
610 memcpy(scan, &contact_entities[i].
coord_1_y_, size_double);
612 memcpy(scan, &contact_entities[i].
coord_1_z_, size_double);
614 memcpy(scan, &contact_entities[i].
coord_2_x_, size_double);
616 memcpy(scan, &contact_entities[i].
coord_2_y_, size_double);
618 memcpy(scan, &contact_entities[i].
coord_2_z_, size_double);
620 memcpy(scan, &contact_entities[i].
coord_3_x_, size_double);
622 memcpy(scan, &contact_entities[i].
coord_3_y_, size_double);
624 memcpy(scan, &contact_entities[i].
coord_3_z_, size_double);
626 memcpy(scan, &contact_entities[i].
char_len_, size_double);
645template <
typename ArgT>
649 constexpr size_t size_int =
sizeof(int);
650 constexpr size_t size_double =
sizeof(double);
663 char* scan = &buffer[0];
664 for (
int i = 0; i < num_entities; i++) {
665 memcpy(&entity.
coord_1_x_, scan, size_double);
667 memcpy(&entity.
coord_1_y_, scan, size_double);
669 memcpy(&entity.
coord_1_z_, scan, size_double);
671 memcpy(&entity.
coord_2_x_, scan, size_double);
673 memcpy(&entity.
coord_2_y_, scan, size_double);
675 memcpy(&entity.
coord_2_z_, scan, size_double);
677 memcpy(&entity.
coord_3_x_, scan, size_double);
679 memcpy(&entity.
coord_3_y_, scan, size_double);
681 memcpy(&entity.
coord_3_z_, scan, size_double);
683 memcpy(&entity.
char_len_, scan, size_double);
700 contact_entities[i] = entity;
704#ifdef NIMBLE_HAVE_BVH
Definition kokkos_contact_manager.h:49
void SerializeContactFaces(int num_entities, ArgT contact_entities, std::vector< char > &buffer)
Definition nimble_contact_entity.h:600
void ParseContactCommand(std::string const &command, std::vector< std::string > &primary_block_names, std::vector< std::string > &secondary_block_names, double &penalty_parameter)
Definition nimble_contact_manager.cc:96
void UnserializeContactFaces(int num_entities, ArgT contact_entities, std::vector< char > &buffer)
Definition nimble_contact_entity.h:647
NIMBLE_INLINE_FUNCTION double PointEdgeClosestPointFindDistanceSquared(double const p1[], double const p2[], double const p[], double t)
Definition nimble_contact_entity.h:100
NIMBLE_INLINE_FUNCTION double PointEdgeClosestPointFindT(double const p1[], double const p2[], double const p[])
Definition nimble_contact_entity.h:92
NIMBLE_INLINE_FUNCTION double TriangleArea(double pt_1_x, double pt_1_y, double pt_1_z, double pt_2_x, double pt_2_y, double pt_2_z, double pt_3_x, double pt_3_y, double pt_3_z)
Definition nimble_contact_entity.h:67
@ NODE
Definition nimble_data_utils.h:60
#define NIMBLE_INLINE_FUNCTION
Definition nimble_defs.h:50
NIMBLE_INLINE_FUNCTION void CrossProduct(const ScalarT *const u, const ScalarT *const v, ScalarT *const result)
Definition nimble_utils.h:395