6#define _USE_MATH_DEFINES
22template <
typename T>
class Utils
26 void dot(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, T &out);
27 void dot(
const std::array<std::complex<T>, 3> &cv1,
const std::array<std::complex<T>, 3> &cv2, std::complex<T> &out);
28 void dot(
const std::array<std::complex<T>, 3> &cv1,
const std::array<T, 3> &v2, std::complex<T> &out);
29 void dot(
const std::array<T, 3> &v1,
const std::array<std::complex<T>, 3> &cv2, std::complex<T> &out);
32 void ext(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<T, 3> &out);
33 void ext(
const std::array<std::complex<T>, 3> &cv1,
const std::array<std::complex<T>, 3> &cv2, std::array<std::complex<T>, 3> &out);
34 void ext(
const std::array<std::complex<T>, 3> &cv1,
const std::array<T, 3> &v2, std::array<std::complex<T>, 3> &out);
35 void ext(
const std::array<T, 3> &v1,
const std::array<std::complex<T>, 3> &cv2, std::array<std::complex<T>, 3> &out);
38 void abs(
const std::array<T, 3> &v, T &out);
41 void diff(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<T, 3> &out);
42 void diff(
const std::array<std::complex<T>, 3> &cv1,
const std::array<std::complex<T>, 3> &cv2, std::array<std::complex<T>, 3> &out);
45 void normalize(
const std::array<T, 3> &v, std::array<T, 3> &out);
48 void add(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<T, 3> &out);
51 void s_mult(
const std::array<T, 3> &v,
const T &s, std::array<T, 3> &out);
52 void s_mult(
const std::array<std::complex<T>, 3> &cv,
const std::complex<T> &cs, std::array<std::complex<T>, 3> &out);
53 void s_mult(
const std::array<T, 3> &v,
const std::complex<T> &cs, std::array<std::complex<T>, 3> &out);
54 void s_mult(
const std::array<std::complex<T>, 3> &cv,
const T &s, std::array<std::complex<T>, 3> &out);
57 void conj(
const std::array<std::complex<T>, 3> &cv, std::array<std::complex<T>, 3> &out);
60 void snell(
const std::array<T, 3> &vin,
const std::array<T, 3> &normal, std::array<T, 3> &out);
61 void snell_t(
const std::array<T, 3> &vin,
const std::array<T, 3> &normal, T mu, std::array<T, 3> &out);
64 void dyad(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<std::array<T, 3>, 3> &out);
67 void matDiff(
const std::array<std::array<T, 3>, 3> &m1,
const std::array<std::array<T, 3>, 3> &m2, std::array<std::array<T, 3>, 3> &out);
70 void matVec(
const std::array<std::array<T, 3>, 3> &m1,
const std::array<T, 3> &v1, std::array<T, 3> &out);
71 void matVec(
const std::array<std::array<T, 3>, 3> &m1,
const std::array<std::complex<T>, 3> &cv1, std::array<std::complex<T>, 3> &out);
74 void matVec4(
const T *m1,
const std::array<T, 3> &v1, std::array<T, 3> &out,
bool vec=
false);
76 void invmatVec4(
const T *m1,
const std::array<T, 3> &v1, std::array<T, 3> &out,
bool vec=
false);
77 void matRot(
const std::array<T, 3> &rot,
const std::array<T, 3> &v1,
const std::array<T, 3> &cRot, std::array<T, 3> &out);
89template <
typename T>
inline
90void Utils<T>::dot(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, T &out)
94 for(
int n=0; n<3; n++)
109template <
typename T>
inline
110void Utils<T>::dot(
const std::array<std::complex<T>, 3> &cv1,
const std::array<std::complex<T>, 3> &cv2, std::complex<T> &out)
114 for(
int n=0; n<3; n++)
116 out += std::conj(cv1[n]) * cv2[n];
129template <
typename T>
inline
130void Utils<T>::dot(
const std::array<std::complex<T>, 3> &cv1,
const std::array<T, 3> &v2, std::complex<T> &out)
134 for(
int n=0; n<3; n++)
136 out += std::conj(cv1[n]) * v2[n];
149template <
typename T>
inline
150void Utils<T>::dot(
const std::array<T, 3> &v1,
const std::array<std::complex<T>, 3> &cv2, std::complex<T> &out)
154 for(
int n=0; n<3; n++)
156 out += v1[n] * cv2[n];
169template <
typename T>
inline
170void Utils<T>::ext(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<T, 3> &out)
172 out[0] = v1[1]*v2[2] - v1[2]*v2[1];
173 out[1] = v1[2]*v2[0] - v1[0]*v2[2];
174 out[2] = v1[0]*v2[1] - v1[1]*v2[0];
186template <
typename T>
inline
187void Utils<T>::ext(
const std::array<std::complex<T>, 3> &cv1,
const std::array<std::complex<T>, 3> &cv2, std::array<std::complex<T>, 3> &out)
189 out[0] = cv1[1]*cv2[2] - cv1[2]*cv2[1];
190 out[1] = cv1[2]*cv2[0] - cv1[0]*cv2[2];
191 out[2] = cv1[0]*cv2[1] - cv1[1]*cv2[0];
203template <
typename T>
inline
204void Utils<T>::ext(
const std::array<std::complex<T>, 3> &cv1,
const std::array<T, 3> &v2, std::array<std::complex<T>, 3> &out)
206 out[0] = cv1[1]*v2[2] - cv1[2]*v2[1];
207 out[1] = cv1[2]*v2[0] - cv1[0]*v2[2];
208 out[2] = cv1[0]*v2[1] - cv1[1]*v2[0];
220template <
typename T>
inline
221void Utils<T>::ext(
const std::array<T, 3> &v1,
const std::array<std::complex<T>, 3> &cv2, std::array<std::complex<T>, 3> &out)
223 out[0] = v1[1]*cv2[2] - v1[2]*cv2[1];
224 out[1] = v1[2]*cv2[0] - v1[0]*cv2[2];
225 out[2] = v1[0]*cv2[1] - v1[1]*cv2[0];
237template <
typename T>
inline
238void Utils<T>::diff(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<T, 3> &out)
240 for(
int n=0; n<3; n++)
242 out[n] = v1[n] - v2[n];
255template <
typename T>
inline
256void Utils<T>::diff(
const std::array<std::complex<T>, 3> &cv1,
const std::array<std::complex<T>, 3> &cv2, std::array<std::complex<T>, 3> &out)
258 for(
int n=0; n<3; n++)
260 out[n] = cv1[n] - cv2[n];
272template <
typename T>
inline
276 out = std::sqrt(out);
287template <
typename T>
inline
293 if (norm <= std::numeric_limits<T>::denorm_min())
295 norm = std::numeric_limits<T>::denorm_min();
298 for(
int n=0; n<3; n++)
300 out[n] = v[n] / norm;
313template <
typename T>
inline
314void Utils<T>::add(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<T, 3> &out)
316 for(
int n=0; n<3; n++)
318 out[n] = v1[n] + v2[n];
331template <
typename T>
inline
334 for(
int n=0; n<3; n++)
349template <
typename T>
inline
350void Utils<T>::s_mult(
const std::array<std::complex<T>, 3> &cv,
const std::complex<T> &cs, std::array<std::complex<T>, 3> &out)
352 for(
int n=0; n<3; n++)
367template <
typename T>
inline
368void Utils<T>::s_mult(
const std::array<T, 3> &v,
const std::complex<T> &cs, std::array<std::complex<T>, 3> &out)
370 for(
int n=0; n<3; n++)
385template <
typename T>
inline
386void Utils<T>::s_mult(
const std::array<std::complex<T>, 3> &cv,
const T &s, std::array<std::complex<T>, 3> &out)
388 for(
int n=0; n<3; n++)
402template <
typename T>
inline
403void Utils<T>::conj(
const std::array<std::complex<T>, 3> &cv, std::array<std::complex<T>, 3> &out)
405 for(
int n=0; n<3; n++)
407 out[n] = std::conj(cv[n]);
420template <
typename T>
inline
421void Utils<T>::snell(
const std::array<T, 3> &vin,
const std::array<T, 3> &normal, std::array<T, 3> &out)
424 dot(vin, normal, factor);
426 factor = 2. * factor;
428 std::array<T, 3> rhs;
429 s_mult(normal, factor, rhs);
444template <
typename T>
inline
445void Utils<T>::snell_t(
const std::array<T, 3> &vin,
const std::array<T, 3> &normal, T mu, std::array<T, 3> &out)
448 std::array<T, 3> term1, term2, temp1, temp2;
450 dot(normal, vin, in_dot_n);
452 factor1 = sqrt(1 - mu*mu * (1 - in_dot_n*in_dot_n));
453 s_mult(normal, factor1, term1);
455 s_mult(normal, in_dot_n, temp1);
456 diff(vin, temp1, temp2);
459 add(term1, term2, out);
471template <
typename T>
inline
472void Utils<T>::dyad(
const std::array<T, 3> &v1,
const std::array<T, 3> &v2, std::array<std::array<T, 3>, 3> &out)
474 for(
int n=0; n<3; n++)
476 out[n][0] = v1[n] * v2[0];
477 out[n][1] = v1[n] * v2[1];
478 out[n][2] = v1[n] * v2[2];
491template <
typename T>
inline
492void Utils<T>::matDiff(
const std::array<std::array<T, 3>, 3> &m1,
const std::array<std::array<T, 3>, 3> &m2, std::array<std::array<T, 3>, 3> &out)
494 for(
int n=0; n<3; n++)
496 out[n][0] = m1[n][0] - m2[n][0];
497 out[n][1] = m1[n][1] - m2[n][1];
498 out[n][2] = m1[n][2] - m2[n][2];
511template <
typename T>
inline
512void Utils<T>::matVec(
const std::array<std::array<T, 3>, 3> &m1,
const std::array<T, 3> &v1, std::array<T, 3> &out)
514 for(
int n=0; n<3; n++)
516 out[n] = m1[n][0] * v1[0] + m1[n][1] * v1[1] + m1[n][2] * v1[2];
529template <
typename T>
inline
530void Utils<T>::matVec(
const std::array<std::array<T, 3>, 3> &m1,
const std::array<std::complex<T>, 3> &cv1, std::array<std::complex<T>, 3> &out)
532 for(
int n=0; n<3; n++)
534 out[n] = m1[n][0] * cv1[0] + m1[n][1] * cv1[1] + m1[n][2] * cv1[2];
549template <
typename T>
inline
554 for(
int n=0; n<3; n++)
556 out[n] = m1[n*4] * v1[0] + m1[1+n*4] * v1[1] + m1[2+n*4] * v1[2];
562 for(
int n=0; n<3; n++)
564 out[n] = m1[n*4] * v1[0] + m1[1+n*4] * v1[1] + m1[2+n*4] * v1[2] + m1[3+n*4];
580template <
typename T>
inline
585 for(
int n=0; n<3; n++)
587 out[n] = m1[n] * v1[0] + m1[n+4] * v1[1] + m1[n+8] * v1[2];
594 for(
int n=0; n<3; n++)
596 temp = -m1[n]*m1[3] - m1[n+4]*m1[7] - m1[n+8]*m1[11];
597 out[n] = m1[n] * v1[0] + m1[n+4] * v1[1] + m1[n+8] * v1[2] + temp;
612template <
typename T>
inline
613void Utils<T>::matRot(
const std::array<T, 3> &rot,
const std::array<T, 3> &v1,
const std::array<T, 3> &cRot, std::array<T, 3> &out)
615 T cosx = cos(rot[0]);
616 T cosy = cos(rot[1]);
617 T cosz = cos(rot[2]);
619 T sinx = sin(rot[0]);
620 T siny = sin(rot[1]);
621 T sinz = sin(rot[2]);
626 std::array<T, 3> to_rot;
628 for(
int n=0; n<3; n++) {to_rot[n] = v1[n] - cRot[n];}
630 out[0] = cosz*cosy * to_rot[0] + (mu*sinx - sinz*cosx) * to_rot[1] + (mu*cosx + sinz*sinx) * to_rot[2];
631 out[1] = sinz*cosy * to_rot[0] + (rho*sinx + cosz*cosx) * to_rot[1] + (rho*cosx - cosz*sinx) * to_rot[2];
632 out[2] = -siny * to_rot[0] + cosy*sinx * to_rot[1] + cosy*cosx * to_rot[2];
634 for(
int n=0; n<3; n++) {out[n] = out[n] + cRot[n];}
__device__ __inline__ void diff(float(&v1)[3], float(&v2)[3], float(&out)[3])
Definition GUtils.h:162
__device__ __inline__ void abs(float(&v)[3], float &out)
Definition GUtils.h:195
__device__ __inline__ void s_mult(float(&v)[3], float &s, float(&out)[3])
Definition GUtils.h:268
__device__ __inline__ void add(float(&v1)[3], float(&v2)[3], float(&out)[3])
Definition GUtils.h:251
__device__ __inline__ void dot(float(&v1)[3], float(&v2)[3], float &out)
Definition GUtils.h:21
void ext(const std::array< T, 3 > &v1, const std::array< std::complex< T >, 3 > &cv2, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:221
void abs(const std::array< T, 3 > &v, T &out)
Definition Utils.h:273
void dyad(const std::array< T, 3 > &v1, const std::array< T, 3 > &v2, std::array< std::array< T, 3 >, 3 > &out)
Definition Utils.h:472
void s_mult(const std::array< std::complex< T >, 3 > &cv, const std::complex< T > &cs, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:350
void diff(const std::array< std::complex< T >, 3 > &cv1, const std::array< std::complex< T >, 3 > &cv2, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:256
void invmatVec4(const T *m1, const std::array< T, 3 > &v1, std::array< T, 3 > &out, bool vec=false)
Definition Utils.h:581
void normalize(const std::array< T, 3 > &v, std::array< T, 3 > &out)
Definition Utils.h:288
void ext(const std::array< T, 3 > &v1, const std::array< T, 3 > &v2, std::array< T, 3 > &out)
Definition Utils.h:170
void dot(const std::array< std::complex< T >, 3 > &cv1, const std::array< std::complex< T >, 3 > &cv2, std::complex< T > &out)
Definition Utils.h:110
void matVec(const std::array< std::array< T, 3 >, 3 > &m1, const std::array< T, 3 > &v1, std::array< T, 3 > &out)
Definition Utils.h:512
void dot(const std::array< T, 3 > &v1, const std::array< std::complex< T >, 3 > &cv2, std::complex< T > &out)
Definition Utils.h:150
void dot(const std::array< std::complex< T >, 3 > &cv1, const std::array< T, 3 > &v2, std::complex< T > &out)
Definition Utils.h:130
void snell_t(const std::array< T, 3 > &vin, const std::array< T, 3 > &normal, T mu, std::array< T, 3 > &out)
Definition Utils.h:445
void s_mult(const std::array< std::complex< T >, 3 > &cv, const T &s, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:386
void matVec(const std::array< std::array< T, 3 >, 3 > &m1, const std::array< std::complex< T >, 3 > &cv1, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:530
void add(const std::array< T, 3 > &v1, const std::array< T, 3 > &v2, std::array< T, 3 > &out)
Definition Utils.h:314
void diff(const std::array< T, 3 > &v1, const std::array< T, 3 > &v2, std::array< T, 3 > &out)
Definition Utils.h:238
void ext(const std::array< std::complex< T >, 3 > &cv1, const std::array< std::complex< T >, 3 > &cv2, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:187
void matDiff(const std::array< std::array< T, 3 >, 3 > &m1, const std::array< std::array< T, 3 >, 3 > &m2, std::array< std::array< T, 3 >, 3 > &out)
Definition Utils.h:492
void s_mult(const std::array< T, 3 > &v, const std::complex< T > &cs, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:368
void matVec4(const T *m1, const std::array< T, 3 > &v1, std::array< T, 3 > &out, bool vec=false)
Definition Utils.h:550
void s_mult(const std::array< T, 3 > &v, const T &s, std::array< T, 3 > &out)
Definition Utils.h:332
void ext(const std::array< std::complex< T >, 3 > &cv1, const std::array< T, 3 > &v2, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:204
void dot(const std::array< T, 3 > &v1, const std::array< T, 3 > &v2, T &out)
Definition Utils.h:90
void snell(const std::array< T, 3 > &vin, const std::array< T, 3 > &normal, std::array< T, 3 > &out)
Definition Utils.h:421
void matRot(const std::array< T, 3 > &rot, const std::array< T, 3 > &v1, const std::array< T, 3 > &cRot, std::array< T, 3 > &out)
Definition Utils.h:613
void conj(const std::array< std::complex< T >, 3 > &cv, std::array< std::complex< T >, 3 > &out)
Definition Utils.h:403