Alsvinn  0.5.3
The fast FVM simulator with UQ support
ConservedVariables.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 
18 #include "alsfvm/types.hpp"
19 #include <cassert>
20 
21 namespace alsfvm {
22 namespace equation {
23 namespace euler {
24 
29 template<int nsd>
31 public:
32  typedef typename Types<nsd>::rvec rvec;
34 
36  : rho(0), m(0), E(0) {
37  // empty
38  }
39 
40 
41 
42  template<class ValueType>
44 
45  const typename Types<nsd>::template vec<ValueType>& m_, real E_)
46  : rho(rho_), m(m_.template convert<real>()), E(E_) {
47  // empty
48  }
49 
50 
51  template<class T>
52  inline __device__ __host__ ConservedVariables(T rho_, T mx, T my, T mz, T E)
53  : rho(rho_), m(rvec3{mx, my, mz}), E(E) {
54  static_assert(nsd == 3 || sizeof(T) == 0, "Only for 3 dimensions!");
55  }
56 
57  template<class T>
58  inline __device__ __host__ ConservedVariables(T rho_, T mx, T my, T E)
59  : rho(rho_), m(rvec2{mx, my}), E(E) {
60  static_assert(nsd == 2 || sizeof(T) == 0, "Only for 3 dimensions!");
61  }
62 
63  template<class T>
64  inline __device__ __host__ ConservedVariables(T rho_, T mx, T E)
65  : rho(rho_), m(rvec1{mx}), E(E) {
66  static_assert(nsd == 1 || sizeof(T) == 0, "Only for 3 dimensions!");
67  }
68 
69 
70 
71  __device__ __host__ ConservedVariables(const state_vector& in);
72 
73 
74  inline __device__ __host__ real operator[](size_t index) const {
75  assert(index < nsd + 2);
76  return ((real*)this)[index];
77  }
78 
79  inline __device__ __host__ real& operator[](size_t index) {
80  assert(index < nsd + 2);
81  return ((real*)this)[index];
82  }
83 
84  inline __device__ __host__ static constexpr size_t size() {
85  return nsd + 2;
86  }
87 
88  inline __device__ __host__ bool operator==(const ConservedVariables& other)
89  const {
90  return rho == other.rho && m == other.m && E == other.E;
91  }
93  rvec m;
95 
96 };
97 
102 template<int nsd>
105  return ConservedVariables<nsd>(a.rho - b.rho, a.m - b.m, a.E - b.E);
106 }
107 
112 template<int nsd>
115  return ConservedVariables<nsd>(a.rho + b.rho, a.m + b.m, a.E + b.E);
116 }
117 
122 template<int nsd>
124  const ConservedVariables<nsd>& b) {
125  return ConservedVariables<nsd>(a * b.rho, a * b.m, a * b.E);
126 }
127 
132 template<int nsd>
135  return ConservedVariables<nsd>(a.rho / b, a.m / b, a.E / b);
136 }
137 
138 template<>
140  const rvec5& in)
141  : rho(in[0]), m(in[1], in[2], in[3]), E(in[4]) {
142  // empty
143 }
144 
145 template<>
147  const rvec4& in)
148  : rho(in[0]), m(in[1], in[2]), E(in[3]) {
149  // e
150 }
151 
152 template<>
154  const rvec3& in)
155  : rho(in[0]), m(in[1]), E(in[2]) {
156  // e
157 }
158 
159 } // namespace alsfvm
160 
161 } // namespace numflux
162 
163 } // namespace euler
164 
Definition: vec4.hpp:25
__device__ __host__ real & operator[](size_t index)
Definition: ConservedVariables.hpp:79
Definition: types.hpp:104
__device__ __host__ ConservedVariables(T rho_, T mx, T E)
Definition: ConservedVariables.hpp:64
#define __host__
Definition: types.hpp:46
Definition: ConservedVariables.hpp:30
Definition: vec2.hpp:24
double real
Definition: types.hpp:65
__device__ __host__ ConservedVariables(T rho_, T mx, T my, T E)
Definition: ConservedVariables.hpp:58
__device__ __host__ ConservedVariables(real rho_, const typename Types< nsd >::template vec< ValueType > &m_, real E_)
Definition: ConservedVariables.hpp:43
Types< nsd+2 >::rvec state_vector
Definition: ConservedVariables.hpp:33
__device__ __host__ ConservedVariables()
Definition: ConservedVariables.hpp:35
__device__ __host__ real operator[](size_t index) const
Definition: ConservedVariables.hpp:74
rvec m
Definition: ConservedVariables.hpp:93
Definition: vec1.hpp:24
#define static_assert(x, y)
Definition: types.hpp:52
Types< nsd >::rvec rvec
Definition: ConservedVariables.hpp:32
__device__ __host__ ConservedVariables< nsd > operator*(real a, const ConservedVariables< nsd > &b)
Definition: ConservedVariables.hpp:123
#define __device__
Definition: types.hpp:45
Definition: vec5.hpp:25
real rho
Definition: ConservedVariables.hpp:92
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
__device__ static __host__ constexpr size_t size()
Definition: ConservedVariables.hpp:84
__device__ __host__ ConservedVariables(T rho_, T mx, T my, T mz, T E)
Definition: ConservedVariables.hpp:52
real E
Definition: ConservedVariables.hpp:94
__device__ __host__ bool operator==(const ConservedVariables &other) const
Definition: ConservedVariables.hpp:88