Line data Source code
1 : //
2 : // Class Vector
3 : // Vector class used for vector fields and particle attributes like the coordinate.
4 : //
5 : #ifndef IPPL_Vector_H
6 : #define IPPL_Vector_H
7 :
8 : #include <initializer_list>
9 :
10 : #include "Expression/IpplExpressions.h"
11 :
12 : namespace ippl {
13 : /*!
14 : * @file Vector.h
15 : */
16 :
17 : /*!
18 : * @class Vector
19 : * @tparam T intrinsic vector data type
20 : * @tparam Dim vector dimension
21 : */
22 : template <typename T, unsigned Dim>
23 : class Vector : public detail::Expression<Vector<T, Dim>, sizeof(T) * Dim> {
24 : public:
25 : typedef T value_type;
26 : static constexpr unsigned dim = Dim;
27 :
28 : KOKKOS_FUNCTION
29 30743154 : Vector()
30 30743154 : : Vector(value_type(0)) {}
31 :
32 : template <typename... Args,
33 : typename std::enable_if<sizeof...(Args) == Dim, bool>::type = true>
34 : explicit KOKKOS_FUNCTION Vector(const Args&... args);
35 :
36 : template <typename E, size_t N>
37 : KOKKOS_FUNCTION Vector(const detail::Expression<E, N>& expr);
38 :
39 : KOKKOS_DEFAULTED_FUNCTION
40 : Vector(const Vector<T, Dim>& v) = default;
41 :
42 : KOKKOS_FUNCTION
43 : Vector(const T& val);
44 :
45 : Vector(const std::array<T, Dim>& a);
46 :
47 : Vector(const std::array<std::vector<T>, Dim>& a);
48 :
49 : /*!
50 : * @param list of values
51 : */
52 : KOKKOS_FUNCTION
53 : Vector(const std::initializer_list<T>& list);
54 :
55 : KOKKOS_FUNCTION
56 190006675 : ~Vector() {}
57 :
58 : // Get and Set Operations
59 : KOKKOS_INLINE_FUNCTION value_type& operator[](unsigned int i);
60 :
61 : KOKKOS_INLINE_FUNCTION value_type operator[](unsigned int i) const;
62 :
63 : KOKKOS_INLINE_FUNCTION value_type& operator()(unsigned int i);
64 :
65 : KOKKOS_INLINE_FUNCTION value_type operator()(unsigned int i) const;
66 :
67 : // Assignment Operators
68 : template <typename E, size_t N>
69 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator=(const detail::Expression<E, N>& expr);
70 :
71 : template <typename E, size_t N>
72 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator+=(const detail::Expression<E, N>& expr);
73 :
74 : template <typename E, size_t N>
75 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator-=(const detail::Expression<E, N>& expr);
76 :
77 : template <typename E, size_t N>
78 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator*=(const detail::Expression<E, N>& expr);
79 :
80 : template <typename E, size_t N>
81 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator/=(const detail::Expression<E, N>& expr);
82 :
83 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator+=(const T& val);
84 :
85 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator-=(const T& val);
86 :
87 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator*=(const T& val);
88 :
89 : KOKKOS_INLINE_FUNCTION Vector<T, Dim>& operator/=(const T& val);
90 :
91 : using iterator = T*;
92 : using const_iterator = const T*;
93 : KOKKOS_INLINE_FUNCTION constexpr iterator begin();
94 : KOKKOS_INLINE_FUNCTION constexpr iterator end();
95 : KOKKOS_INLINE_FUNCTION constexpr const_iterator begin() const;
96 : KOKKOS_INLINE_FUNCTION constexpr const_iterator end() const;
97 :
98 : KOKKOS_INLINE_FUNCTION T dot(const Vector<T, Dim>& rhs) const;
99 :
100 : KOKKOS_INLINE_FUNCTION T Pnorm(const int p = 2) const;
101 :
102 : // Needs to be public to be a standard-layout type
103 : // private:
104 : T data_m[Dim];
105 : };
106 :
107 : template <typename T, unsigned Dim>
108 : KOKKOS_INLINE_FUNCTION Vector<T, Dim> min(const Vector<T, Dim>& a, const Vector<T, Dim>& b);
109 : template <typename T, unsigned Dim>
110 : KOKKOS_INLINE_FUNCTION Vector<T, Dim> max(const Vector<T, Dim>& a, const Vector<T, Dim>& b);
111 : } // namespace ippl
112 :
113 : #include "Vector.hpp"
114 :
115 : #endif
|