forked from mdelorme/fv2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStates.h
109 lines (90 loc) · 2.14 KB
/
States.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
namespace fv2d {
KOKKOS_INLINE_FUNCTION
State getStateFromArray(Array arr, int i, int j) {
return {arr(j, i, IR),
arr(j, i, IU),
arr(j, i, IV),
arr(j, i, IP)};
}
KOKKOS_INLINE_FUNCTION
void setStateInArray(Array arr, int i, int j, State st) {
for (int ivar=0; ivar < Nfields; ++ivar)
arr(j, i, ivar) = st[ivar];
}
KOKKOS_INLINE_FUNCTION
State primToCons(State &q, const Params ¶ms) {
State res;
res[IR] = q[IR];
res[IU] = q[IR]*q[IU];
res[IV] = q[IR]*q[IV];
real_t Ek = 0.5 * (res[IU]*res[IU] + res[IV]*res[IV]) / q[IR];
res[IE] = (Ek + q[IP] / (params.gamma0-1.0));
return res;
}
KOKKOS_INLINE_FUNCTION
State consToPrim(State &u, const Params ¶ms) {
State res;
res[IR] = u[IR];
res[IU] = u[IU] / u[IR];
res[IV] = u[IV] / u[IR];
real_t Ek = 0.5 * res[IR] * (res[IU]*res[IU] + res[IV]*res[IV]);
res[IP] = (u[IE] - Ek) * (params.gamma0-1.0);
return res;
}
KOKKOS_INLINE_FUNCTION
real_t speedOfSound(State &q, const Params ¶ms) {
return sqrt(q[IP] * params.gamma0 / q[IR]);
}
KOKKOS_INLINE_FUNCTION
State& operator+=(State &a, State b) {
for (int i=0; i < Nfields; ++i)
a[i] += b[i];
return a;
}
KOKKOS_INLINE_FUNCTION
State& operator-=(State &a, State b) {
for (int i=0; i < Nfields; ++i)
a[i] -= b[i];
return a;
}
KOKKOS_INLINE_FUNCTION
State operator*(const State &a, real_t q) {
State res;
for (int i=0; i < Nfields; ++i)
res[i] = a[i]*q;
return res;
}
KOKKOS_INLINE_FUNCTION
State operator/(const State &a, real_t q) {
State res;
for (int i=0; i < Nfields; ++i)
res[i] = a[i]/q;
return res;
}
KOKKOS_INLINE_FUNCTION
State operator*(real_t q, const State &a) {
return a*q;
}
KOKKOS_INLINE_FUNCTION
State operator+(const State &a, const State &b) {
State res;
for (int i=0; i < Nfields; ++i)
res[i] = a[i]+b[i];
return res;
}
KOKKOS_INLINE_FUNCTION
State operator-(const State &a, const State &b) {
State res;
for (int i=0; i < Nfields; ++i)
res[i] = a[i]-b[i];
return res;
}
KOKKOS_INLINE_FUNCTION
State swap_component(State &q, IDir dir) {
if (dir == IX)
return q;
else
return {q[IR], q[IV], q[IU], q[IP]};
}
}