1 #ifndef AMREX_EB_TRIGEOMOPS_K_H_
2 #define AMREX_EB_TRIGEOMOPS_K_H_
3 #include <AMReX_Config.H>
12 return( (P1[0]-P2[0])*(P1[0]-P2[0]) +
13 (P1[1]-P2[1])*(P1[1]-P2[1]) +
14 (P1[2]-P2[2])*(P1[2]-P2[2]) );
19 return(v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]);
43 vmag=
std::sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
51 v[0]=v1[1]*v2[2]-v1[2]*v2[1];
52 v[1]=v1[2]*v2[0]-v1[0]*v2[2];
53 v[2]=v1[0]*v2[1]-v1[1]*v2[0];
58 L[0] = v1[0]*v2[1] - v1[1]*v2[0];
59 L[1] = v1[0]*v2[2] - v1[2]*v2[0];
61 L[3] = v1[1]*v2[2] - v1[2]*v2[1];
67 const Real t1[3],
const Real t2[3],
const Real t3[3],
68 Real &S1, Real &S2, Real &S3)
71 Real L[6],e1[6],e2[6],e3[6];
85 const Real testp[3], Real n[3])
87 Real v1[3],v2[3],magn;
88 Real centr[3],c_tp_vec[3];
95 centr[0]=Real(1./3.)*(P1[0]+P2[0]+P3[0]);
96 centr[1]=Real(1./3.)*(P1[1]+P2[1]+P3[1]);
97 centr[2]=Real(1./3.)*(P1[2]+P2[2]+P3[2]);
99 getvec(centr,testp,c_tp_vec);
100 magn=
std::sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
102 if(
DotProd(c_tp_vec,n) < Real(0.0))
114 Real v1[3],v2[3],area[3];
124 const Real t1[3],
const Real t2[3],
const Real t3[3], Real ip[3],
int bisect_iters=20,Real tol=1e-6)
126 Real plane_eq_mid,plane_eq1,plane_eq2;
128 Real ab[3],ac[3],n[3],magn;
129 Real midp[3],p1[3],p2[3];
135 magn=
std::sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
152 for(
int i=0;i<bisect_iters;i++)
154 midp[0]=Real(0.5)*(p1[0]+p2[0]);
155 midp[1]=Real(0.5)*(p1[1]+p2[1]);
156 midp[2]=Real(0.5)*(p1[2]+p2[2]);
158 plane_eq_mid= (midp[0]-t1[0])*n[0] + (midp[1]-t1[1])*n[1] + (midp[2]-t1[2])*n[2];
159 plane_eq1 = (p1[0] -t1[0])*n[0] + (p1[1] -t1[1])*n[1] + (p1[2] -t1[2])*n[2];
160 plane_eq2 = (p2[0] -t1[0])*n[0] + (p2[1] -t1[1])*n[1] + (p2[2] -t1[2])*n[2];
169 if(plane_eq_mid*plane_eq1 < Real(0.0))
175 else if(plane_eq_mid*plane_eq2 < Real(0.0))
185 if(plane_eq_mid*plane_eq1 > Real(0.0) && plane_eq_mid*plane_eq2 > Real(0.0))
201 const Real t1[3],
const Real t2[3],
const Real t3[3])
207 Real tri_area,area1,area2;
208 Real L2[6],L3[6],L4[6],ls_s1,ls_s2;
213 int no_intersections=1;
215 Real
eps = std::numeric_limits<Real>::epsilon();
232 no_intersections = 0;
236 else if( (S1 < Real(0.0) && S2 < Real(0.0) && S3 < Real(0.0)) ||
237 (S1 > Real(0.0) && S2 > Real(0.0) && S3 > Real(0.0)) ||
256 if(ls_s1*ls_s2 > Real(0.0))
258 no_intersections = 0;
277 no_intersections = 0;
298 return(no_intersections);
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
constexpr double eps
Definition: AMReX_MLNodeLap_K.H:19
Definition: AMReX_EB_triGeomOps_K.H:8
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real side_op(const Real L1[6], const Real L2[6])
Definition: AMReX_EB_triGeomOps_K.H:23
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real DotProd(const Real v1[3], const Real v2[3])
Definition: AMReX_EB_triGeomOps_K.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int lineseg_tri_intersect(const Real v1[3], const Real v2[3], const Real t1[3], const Real t2[3], const Real t3[3])
Definition: AMReX_EB_triGeomOps_K.H:200
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void CrossProd(const Real v1[3], const Real v2[3], Real v[3])
Definition: AMReX_EB_triGeomOps_K.H:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void get_plucker_coords(const Real v1[3], const Real v2[3], Real L[6])
Definition: AMReX_EB_triGeomOps_K.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getvec(const Real P1[3], const Real P2[3], Real v[3])
Definition: AMReX_EB_triGeomOps_K.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void side_op3(const Real v1[3], const Real v2[3], const Real t1[3], const Real t2[3], const Real t3[3], Real &S1, Real &S2, Real &S3)
Definition: AMReX_EB_triGeomOps_K.H:66
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real Distance2(const Real P1[3], const Real P2[3])
Definition: AMReX_EB_triGeomOps_K.H:10
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getunitvec(const Real v[3], Real vu[3])
Definition: AMReX_EB_triGeomOps_K.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void tri_n(const Real P1[3], const Real P2[3], const Real P3[3], const Real testp[3], Real n[3])
Definition: AMReX_EB_triGeomOps_K.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real triangle_area(const Real P1[3], const Real P2[3], const Real P3[3])
Definition: AMReX_EB_triGeomOps_K.H:112
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool find_intersection_point(const Real v1[3], const Real v2[3], const Real t1[3], const Real t2[3], const Real t3[3], Real ip[3], int bisect_iters=20, Real tol=1e-6)
Definition: AMReX_EB_triGeomOps_K.H:123
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition: AMReX_GpuComplex.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373