PeTar
N-body code for collisional gravitational systems
|
Go to the documentation of this file. 1 #ifndef HPP_PIKG_VECTOR
2 #define HPP_PIKG_VECTOR
4 #ifdef PIKG_USE_FDPS_VECTOR
5 #include <particle_simulator.hpp>
6 namespace PIKG = ParticleSimulator;
8 namespace ParticleSimulator{
32 Vector3(
const T _x,
const T _y,
const T _z) : x(_x), y(_y), z(_z) {}
37 static const int DIM = 3;
52 return Vector3(x + rhs.
x, y + rhs.
y, z + rhs.
z);
55 (*this) = (*this) + rhs;
59 return Vector3(x - rhs.
x, y - rhs.
y, z - rhs.
z);
63 (*this) = (*this) - rhs;
68 return Vector3(x * s, y * s, z * s);
71 (*this) = (*this) * s;
78 return Vector3(x / s, y / s, z / s);
81 (*this) = (*this) / s;
94 return (x * rhs.
x) + (y * rhs.
y) + (z * rhs.
z);
99 (z * rhs.
x - x * rhs.
z),
100 (x * rhs.
y - y * rhs.
x) );
103 template <
typename U>
111 c<<u.
x<<
" "<<u.
y<<
" "<<u.
z;
115 friend std::istream & operator >>(std::istream & c,
Vector3 & u){
116 c>>u.
x; c>>u.
y; c>>u.
z;
135 return ( (x==u.
x) && (y==u.
y) && (z==u.
z) );
138 return ( (x!=u.
x) || (y!=u.
y) || (z!=u.
z) );
144 T max_val = (v.
x > v.
y) ? v.
x : v.
y;
145 max_val = (max_val > v.
z ) ? max_val : v.
z;
151 T min_val = (v.
x < v.
y) ? v.
x : v.
y;
152 min_val = (min_val < v.
z ) ? min_val : v.
z;
158 const float inv_s = 1.0f/s;
159 return Vector3(x * inv_s, y * inv_s, z * inv_s);
163 const double inv_s = 1.0/s;
164 return Vector3(x * inv_s, y * inv_s, z * inv_s);
173 template <
typename T>
178 Vector2(
const T _x,
const T _y) : x(_x), y(_y) {}
182 static const int DIM = 2;
199 (*this) = (*this) + rhs;
206 (*this) = (*this) - rhs;
215 (*this) = (*this) * s;
225 (*this) = (*this) / s;
239 return (x * rhs.
x) + (y * rhs.
y);
244 const T z = (x * rhs.
y) - (y * rhs.
x);
249 template <
typename U>
256 return x > y ? x : y;
260 return x < y ? x : y;
269 return Vector2( f(arg1.
x, arg2.
x), f(arg1.
y, arg2.
y) );
277 friend std::istream & operator >>(std::istream & c,
Vector2 & u){
295 return ( (x==u.
x) && (y==u.
y) );
298 return ( (x!=u.
x) || (y!=u.
y) );
305 const float inv_s = 1.0f/s;
306 return Vector2(x * inv_s, y * inv_s);
310 const double inv_s = 1.0/s;
311 return Vector2(x * inv_s, y * inv_s);
324 Vector4() : x(T(0)), y(T(0)), z(T(0)), w(T(0)) {}
325 Vector4(
const T _x,
const T _y,
const T _z,
const T _w) : x(_x), y(_y), z(_z), w(_w) {}
326 Vector4(
const T s) : x(s), y(s), z(s), w(s) {}
330 static const int DIM = 4;
346 return Vector4(x + rhs.
x, y + rhs.
y, z + rhs.
z, w + rhs.
z);
349 (*this) = (*this) + rhs;
353 return Vector4(x - rhs.
x, y - rhs.
y, z - rhs.
z, w - rhs.
w);
357 (*this) = (*this) - rhs;
362 return Vector4(x * s, y * s, z * s, w * s);
365 (*this) = (*this) * s;
372 return Vector4(x / s, y / s, z / s, w / s);
375 (*this) = (*this) / s;
384 return Vector4(-x, -y, -z, -w);
388 return (x * rhs.
x) + (y * rhs.
y) + (z * rhs.
z) + (w * rhs.
w);
392 template <
typename U>
401 c<<u.
x<<
" "<<u.
y<<
" "<<u.
z<<
" "<<u.
w;
405 friend std::istream & operator >>(std::istream & c,
Vector4 & u){
406 c>>u.
x; c>>u.
y; c>>u.
z; c>>u.
w;
427 return ( (x==u.
x) && (y==u.
y) && (z==u.
z) && (w==u.
w));
430 return ( (x!=u.
x) || (y!=u.
y) || (z!=u.
z) || (w!=u.
w));
436 T max_val = (v.
x > v.
y) ? v.
x : v.
y;
437 max_val = (max_val > v.
z ) ? max_val : v.
z;
438 max_val = (max_val > v.
w ) ? max_val : v.
w;
444 T min_val = (v.
x < v.
y) ? v.
x : v.
y;
445 min_val = (min_val < v.
z ) ? min_val : v.
z;
446 min_val = (min_val < v.
w ) ? min_val : v.
w;
452 const float inv_s = 1.0f/s;
453 return Vector4(x * inv_s, y * inv_s, z * inv_s, w * inv_s);
457 const double inv_s = 1.0/s;
458 return Vector4(x * inv_s, y * inv_s, z * inv_s, w * inv_s);
Definition: pikg_vector.hpp:321
T & operator[](const int i)
Definition: pikg_vector.hpp:418
T w
Definition: pikg_vector.hpp:323
T y
Definition: pikg_vector.hpp:323
const T & operator[](const int i) const
Definition: pikg_vector.hpp:410
T z
Definition: pikg_vector.hpp:30
uint32_t U32
Definition: pikg_vector.hpp:21
T x
Definition: pikg_vector.hpp:323
Vector3(const T s)
Definition: pikg_vector.hpp:33
int32_t S32
Definition: pikg_vector.hpp:24
T & operator[](const int i)
Definition: pikg_vector.hpp:127
T DataType
Definition: pikg_vector.hpp:36
Vector4(const Vector4 &src)
Definition: pikg_vector.hpp:327
std::ostream & operator<<(std::ostream &os, const IOParams< Type > &par)
Definition: io.hpp:75
T y
Definition: pikg_vector.hpp:30
double F64
Definition: pikg_vector.hpp:17
Vector2(const T s)
Definition: pikg_vector.hpp:179
T getMax() const
Definition: pikg_vector.hpp:255
T x
Definition: pikg_vector.hpp:176
Vector4(const T s)
Definition: pikg_vector.hpp:326
T & operator[](const int i)
Definition: pikg_vector.hpp:282
int64_t S64
Definition: pikg_vector.hpp:23
const T & operator[](const int i) const
Definition: pikg_vector.hpp:287
Definition: pikg_vector.hpp:174
Vector2 applyEach(F f) const
Definition: pikg_vector.hpp:264
Vector3(const T _x, const T _y, const T _z)
Definition: pikg_vector.hpp:32
const T & operator[](const int i) const
Definition: pikg_vector.hpp:120
Vector3(const Vector3 &src)
Definition: pikg_vector.hpp:34
Vector4()
Definition: pikg_vector.hpp:324
Vector3()
Definition: pikg_vector.hpp:31
Vector4(const T _x, const T _y, const T _z, const T _w)
Definition: pikg_vector.hpp:325
T getMin() const
Definition: pikg_vector.hpp:259
T DataType
Definition: pikg_vector.hpp:329
Definition: pikg_vector.hpp:28
T min(const Vector4< T > &v)
Definition: pikg_vector.hpp:443
T x
Definition: pikg_vector.hpp:30
Vector2(const T _x, const T _y)
Definition: pikg_vector.hpp:178
Definition: pikg_vector.hpp:16
T max(const Vector4< T > &v)
Definition: pikg_vector.hpp:435
T z
Definition: pikg_vector.hpp:323
T y
Definition: pikg_vector.hpp:176
Vector2()
Definition: pikg_vector.hpp:177
Vector2(const Vector2 &src)
Definition: pikg_vector.hpp:180
friend Vector2 ApplyEach(F f, const Vector2 &arg1, const Vector2 &arg2)
Definition: pikg_vector.hpp:268
uint64_t U64
Definition: pikg_vector.hpp:20
float F32
Definition: pikg_vector.hpp:18