Alsvinn  0.5.3
The fast FVM simulator with UQ support
vec6.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #pragma once
17 #include <vector>
18 namespace alsutils {
19 
23 template<class T>
24 struct vec6 {
25  T x;
26  T y;
27  T z;
28  T v;
29  T w;
30  T u;
31 
33  : x(0), y(0), z(0), v(0), w(0), u(0) {
34 
35  }
36  __device__ __host__ vec6(T x, T y, T z, T v, T w, T u)
37  : x(x), y(y), z(z), v(v), w(w), u(0) {
38  // Empty
39  }
40 
41  __device__ __host__ bool operator==(const vec6& other) const {
42  return other.x == x && other.y == y && other.z == z && other.v == v
43  && other.w == w && other.u == u;
44  }
45 #if __cplusplus > 199711L || WIN32
46  std::vector<T> toStdVector() {
51  return std::vector<T>({ x, y, z, v, w, u });
52  }
53 #endif
54  template<class S>
59  return vec6<S>(S(x), S(y), S(z), S(v), S(w), S(u));
60  }
61 
65  __device__ __host__ const T& operator[](size_t i) const {
66  // Note: We only store five numbers in this struct, hence this is safe
67  return ((T*)this)[i];
68  }
69 
74  // Note: We only store five numbers in this struct, hence this is safe
75  return ((T*)this)[i];
76  }
77 
81  __device__ __host__ T dot(const vec6<T>& other) const {
82  return x * other.x + y * other.y + z * other.z + v * other.v + w * other.w + u *
83  other.u;
84  }
85 
89  __device__ __host__ static constexpr size_t size() {
90  return 6;
91  }
92 
93  __host__ std::string str() const;
94 };
95 
101 template<class T>
103  const vec6<T>& b) {
104  return vec6<T>(a.x / b.x, a.y / b.y, a.z / b.z, a.v / b.v, a.w / b.w,
105  a.u / b.u);
106 }
107 
112 template<class T>
113 __device__ __host__ inline vec6<T> operator*(T scalar, const vec6<T>& a) {
114  return vec6<T>(a.x * scalar, a.y * scalar, a.z * scalar, a.v * scalar,
115  a.w * scalar, a.u * scalar);
116 }
117 
122 template<class T>
124  const vec6<T>& b) {
125  return vec6<T>(a.x - b.x, a.y - b.y, a.z - b.z, a.v - b.v, a.w - b.w,
126  a.u - b.u);
127 }
128 
133 template<class T>
134 __device__ __host__ inline vec6<T> operator/(const vec6<T>& a, T scalar) {
135  return vec6<T>(a.x / scalar, a.y / scalar, a.z / scalar, a.v / scalar,
136  a.w / scalar, a.u / scalar);
137 }
138 
143 template<class T>
145  const vec6<T>& b) {
146  return vec6<T>(a.x + b.x, a.y + b.y, a.z + b.z.a.v + b.v, a.w + b.w, a.u + b.u);
147 }
148 
149 
150 }
151 
152 
153 template<typename T>
154 std::ostream& operator <<(std::ostream& os,
155  const alsutils::vec6<T>& vec) {
156  os << "[";
157 
158  for (int i = 0; i < 6; ++i) {
159  os << vec[i];
160 
161  if (i < 5) {
162  os << ", ";
163  }
164  }
165 
166  os << "]";
167  return os;
168 }
169 template<class T>
170 inline __host__ std::string alsutils::vec6<T>::str() const {
171  std::stringstream ss;
172  ss << *this;
173  return ss.str();
174 }
T y
Definition: vec6.hpp:26
__device__ __host__ vec1< T > operator-(const vec1< T > &a, const vec1< T > &b)
Definition: vec1.hpp:140
__device__ static __host__ constexpr size_t size()
Definition: vec6.hpp:89
T x
Definition: vec6.hpp:25
__host__ std::string str() const
Definition: vec6.hpp:170
__device__ __host__ const T & operator[](size_t i) const
Definition: vec6.hpp:65
__device__ __host__ vec1< T > operator*(T scalar, const vec1< T > &a)
Definition: vec1.hpp:131
T u
Definition: vec6.hpp:30
__device__ __host__ vec6()
Definition: vec6.hpp:32
__device__ __host__ vec6(T x, T y, T z, T v, T w, T u)
Definition: vec6.hpp:36
#define __host__
Definition: types.hpp:46
__device__ __host__ T dot(const vec6< T > &other) const
Definition: vec6.hpp:81
__device__ __host__ bool operator==(const vec6 &other) const
Definition: vec6.hpp:41
Definition: vec6.hpp:24
__device__ __host__ vec1< T > operator+(const vec1< T > &a, const vec1< S > &b)
Definition: vec1.hpp:159
T v
Definition: vec6.hpp:28
__device__ __host__ vec6< S > convert()
Definition: vec6.hpp:58
Various utilities for mpi and cuda.
Definition: Factory.hpp:3
#define __device__
Definition: types.hpp:45
__device__ __host__ T & operator[](size_t i)
Definition: vec6.hpp:73
__device__ __host__ vec1< T > operator/(const vec1< T > &a, const vec1< T > &b)
Definition: vec1.hpp:121
T z
Definition: vec6.hpp:27
std::ostream & operator<<(std::ostream &os, const alsutils::vec6< T > &vec)
Definition: vec6.hpp:154
T w
Definition: vec6.hpp:29