Alsvinn  0.5.3
The fast FVM simulator with UQ support
types.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 <iostream>
18 #include <iomanip>
19 #include <complex>
20 #include <cmath>
21 #include <cstdlib>
22 #include <cctype>
23 #include <cstdlib>
24 #include <cfloat>
25 #include <memory>
26 #include <complex>
27 
28 #include <memory>
29 #include "alsutils/config.hpp"
30 namespace alsfvm {
31 using std::shared_ptr;
32 using std::make_shared;
33 using std::dynamic_pointer_cast;
34 }
35 
36 // For CUDA we need special flags for the functions,
37 // for normal build, we just need to define these flags as empty.
38 #ifdef ALSVINN_HAVE_CUDA
39  #include <cuda_runtime.h>
40  #include <cuda.h>
41  #include <cmath>
42 
43 #else
44 
45  #define __device__
46  #define __host__
47 #endif
48 
49 #if __cplusplus <= 199711L
50  #ifndef _WIN32
51  #include <cassert>
52  #define static_assert(x, y) assert(x)
53  #endif
54 #endif
55 
56 #include "alsutils/vec.hpp"
57 #include "alsutils/mat.hpp"
58 #ifdef ALSVINN_USE_QUADMATH
59  #include <quadmath.h>
60 #endif
61 
62 
63 namespace alsutils {
64 #ifndef ALSVINN_USE_FLOAT
65  typedef double real;
66 #else
67  typedef float real;
68 #endif
69 
70 typedef vec1<real> rvec1;
71 typedef vec1<int> ivec1;
72 
73 typedef vec2<real> rvec2;
74 typedef vec2<int> ivec2;
75 
76 typedef vec3<real> rvec3;
77 typedef vec3<int> ivec3;
78 
79 typedef vec4<real> rvec4;
80 typedef vec4<int> ivec4;
81 
82 typedef vec5<real> rvec5;
83 typedef vec5<int> ivec5;
84 
85 typedef vec6<real> rvec6;
86 typedef vec6<int> ivec6;
87 
88 inline __device__ __host__ ivec3 make_direction_vector(size_t direction) {
89  return ivec3( direction == 0, direction == 1, direction == 2 );
90 }
91 
93  int nz) {
94  return ivec3(nx > 1, ny > 1, nz > 1);
95 }
97 
102 
103 template<int nsd>
104 struct Types {
105  // empty
106 };
107 
108 template<>
109 struct Types<1> {
110  typedef rvec1 rvec;
111  typedef ivec1 ivec;
112  template<class T>
113  using vec = vec1<T>;
114  typedef matrix1 matrix;
115 };
116 
117 template<>
118 struct Types<2> {
119  typedef rvec2 rvec;
120  typedef ivec2 ivec;
121  template<class T>
122  using vec = vec2<T>;
123  typedef matrix2 matrix;
124 };
125 
126 template<>
127 struct Types<3> {
128  typedef rvec3 rvec;
129  typedef ivec3 ivec;
130  template<class T>
131  using vec = vec3<T>;
132  typedef matrix3 matrix;
133 };
134 
135 template<>
136 struct Types<4> {
137  typedef rvec4 rvec;
138  typedef ivec4 ivec;
139  template<class T>
140  using vec = vec4<T>;
141  typedef matrix4 matrix;
142 };
143 
144 template<>
145 struct Types<5> {
146  typedef rvec5 rvec;
147  typedef ivec5 ivec;
148  template<class T>
149  using vec = vec5<T>;
150  typedef matrix5 matrix;
151 };
152 
153 
154 
159 inline __host__ __device__ real square(const real& x) {
160  return x * x;
161 }
162 
163 
164 }
165 
166 #ifdef ALSVINN_USE_QUADMATH
167 namespace std {
168 
169 inline __float128 fabs(const __float128& x) {
170  return fabsq(x);
171 }
172 
173 inline __float128 abs(const __float128& x) {
174  return fabsq(x);
175 }
176 
177 inline bool isnan(const __float128& x) {
178  return isnanq(x);
179 }
180 
181 inline bool pow(__float128 x, int b) {
182  return powq(x, b);
183 }
184 
185 inline bool pow(__float128 x, double b) {
186  return powq(x, b);
187 }
188 
189 inline bool isfinite(const __float128& x) {
190  return !isinfq(x);
191 }
192 
193 inline bool isinf(const __float128& x) {
194  return isinfq(x);
195 }
196 
197 inline std::basic_ostream<char>& operator<<(std::basic_ostream<char>& os,
198  const __float128& x) {
199  return (os << (double)x);
200 }
201 
202 
203 
204 
205 }
206 #endif
matrix3 matrix
Definition: types.hpp:132
vec5< int > ivec5
Definition: types.hpp:83
matrix< real, 4, 4 > matrix4
Definition: types.hpp:100
Definition: vec4.hpp:25
Definition: types.hpp:104
rvec3 rvec
Definition: types.hpp:128
matrix< real, 5, 5 > matrix5
Definition: types.hpp:101
matrix5 matrix
Definition: types.hpp:150
ivec1 ivec
Definition: types.hpp:111
matrix4 matrix
Definition: types.hpp:141
rvec5 rvec
Definition: types.hpp:146
#define __host__
Definition: types.hpp:46
Definition: vec2.hpp:24
vec4< int > ivec4
Definition: types.hpp:80
ivec2 ivec
Definition: types.hpp:120
size_t nx
Definition: VolumeFactory.cpp:87
double real
Definition: types.hpp:65
vec3< int > ivec3
Definition: types.hpp:77
ivec5 ivec
Definition: types.hpp:147
Definition: vec6.hpp:24
matrix< real, 1, 1 > matrix1
Definition: types.hpp:96
Definition: mat.hpp:23
rvec1 rvec
Definition: types.hpp:110
size_t ny
Definition: VolumeFactory.cpp:88
Various utilities for mpi and cuda.
Definition: Factory.hpp:3
Definition: vec1.hpp:24
ivec3 ivec
Definition: types.hpp:129
vec4< real > rvec4
Definition: types.hpp:79
rvec2 rvec
Definition: types.hpp:119
rvec4 rvec
Definition: types.hpp:137
matrix< real, 3, 3 > matrix3
Definition: types.hpp:99
vec5< real > rvec5
Definition: types.hpp:82
vec6< real > rvec6
Definition: types.hpp:85
vec6< int > ivec6
Definition: types.hpp:86
matrix< real, 2, 2 > matrix2
Definition: types.hpp:98
#define __device__
Definition: types.hpp:45
Definition: vec5.hpp:25
vec2< real > rvec2
Definition: types.hpp:73
__device__ __host__ ivec3 make_space_filling_vector(int nx, int ny, int nz)
Definition: types.hpp:92
matrix1 matrix
Definition: types.hpp:114
size_t nz
Definition: VolumeFactory.cpp:89
vec3< real > rvec3
Definition: types.hpp:76
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
vec1< real > rvec1
Definition: types.hpp:70
matrix2 matrix
Definition: types.hpp:123
vec1< int > ivec1
Definition: types.hpp:71
ivec4 ivec
Definition: types.hpp:138
__device__ __host__ ivec3 make_direction_vector(size_t direction)
Definition: types.hpp:88
vec2< int > ivec2
Definition: types.hpp:74
__host__ __device__ real square(const real &x)
Definition: types.hpp:159