IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
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
11
12namespace ippl {
16
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
30 : 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
52 KOKKOS_FUNCTION
53 Vector(const std::initializer_list<T>& list);
54
55 KOKKOS_FUNCTION
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:
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
constexpr unsigned Dim
Definition Archive.h:20
KOKKOS_INLINE_FUNCTION Vector< T, Dim > min(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
Definition Vector.hpp:217
KOKKOS_INLINE_FUNCTION constexpr iterator begin()
Definition Vector.hpp:160
KOKKOS_FUNCTION ~Vector()
Definition Vector.h:56
KOKKOS_INLINE_FUNCTION T Pnorm(const int p=2) const
Definition Vector.hpp:191
KOKKOS_INLINE_FUNCTION constexpr const_iterator begin() const
Definition Vector.hpp:170
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator/=(const detail::Expression< E, N > &expr)
Definition Vector.hpp:125
Vector(const std::array< std::vector< T >, Dim > &a)
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator/=(const T &val)
Definition Vector.hpp:155
KOKKOS_INLINE_FUNCTION value_type operator[](unsigned int i) const
Definition Vector.hpp:58
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator*=(const T &val)
Definition Vector.hpp:147
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator-=(const detail::Expression< E, N > &expr)
Definition Vector.hpp:105
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator-=(const T &val)
Definition Vector.hpp:142
KOKKOS_DEFAULTED_FUNCTION Vector(const Vector< T, Dim > &v)=default
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator+=(const detail::Expression< E, N > &expr)
Definition Vector.hpp:95
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator*=(const detail::Expression< E, N > &expr)
Definition Vector.hpp:115
KOKKOS_INLINE_FUNCTION constexpr const_iterator end() const
Definition Vector.hpp:176
KOKKOS_INLINE_FUNCTION value_type & operator[](unsigned int i)
Definition Vector.hpp:51
KOKKOS_FUNCTION Vector(const std::initializer_list< T > &list)
Definition Vector.hpp:36
KOKKOS_INLINE_FUNCTION value_type operator()(unsigned int i) const
Definition Vector.hpp:72
KOKKOS_FUNCTION Vector(const T &val)
Definition Vector.hpp:30
KOKKOS_INLINE_FUNCTION value_type & operator()(unsigned int i)
Definition Vector.hpp:65
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator=(const detail::Expression< E, N > &expr)
Definition Vector.hpp:85
static constexpr unsigned dim
Definition Vector.h:26
KOKKOS_FUNCTION Vector(const Args &... args)
Definition Vector.hpp:18
KOKKOS_INLINE_FUNCTION T dot(const Vector< T, Dim > &rhs) const
Definition Vector.hpp:182
KOKKOS_INLINE_FUNCTION constexpr iterator end()
Definition Vector.hpp:165
KOKKOS_FUNCTION Vector()
Definition Vector.h:29
KOKKOS_FUNCTION Vector(const detail::Expression< E, N > &expr)
Definition Vector.hpp:23
Vector(const std::array< T, Dim > &a)
KOKKOS_INLINE_FUNCTION Vector< T, Dim > & operator+=(const T &val)
Definition Vector.hpp:134