Alsvinn  0.5.3
The fast FVM simulator with UQ support
HLL.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
20 #include <algorithm>
21 
22 namespace alsfvm {
23 namespace numflux {
24 namespace euler {
25 
34 template<int nsd>
35 class HLL {
36 public:
37 
41  static const std::string name;
42 
43  typedef typename Types<nsd>::rvec rvec;
44 
51  template<int direction>
52  __device__ __host__ inline static real computeFlux(const
56 
57  static_assert(direction < 3, "We only support three dimensions.");
58  real speedLeft;
59  real speedRight;
60 
61  computeHLLSpeeds<direction>(eq, left, right, speedLeft, speedRight);
62 
63  if (speedLeft == 0) {
65  } else if (speedLeft > 0) {
66  eq.template computePointFlux<direction>(left, F);
67  } else if (speedRight < 0) {
68  eq.template computePointFlux<direction>(right, F);
69  } else {
70  equation::euler::ConservedVariables<nsd> leftFlux, rightFlux;
71  eq.template computePointFlux<direction>(left, leftFlux);
72  eq.template computePointFlux<direction>(right, rightFlux);
73  F = (speedRight * leftFlux - speedLeft * rightFlux + speedRight * speedLeft *
74  (right.conserved() - left.conserved())) / (speedRight - speedLeft);
75  }
76 
77  return fmax(fabs(speedLeft), fabs(speedRight));
78  }
79 
89  template<int direction>
90  __device__ __host__ inline static void computeHLLSpeeds(
93  const equation::euler::AllVariables<nsd>& right, real& speedLeft,
94  real& speedRight) {
95 
96  static_assert(direction < 3, "We only support up to three dimensions.");
97 
98  const real waveLeft = sqrt(left.rho);
99  const real waveRight = sqrt(right.rho);
100 
101  const real rho = (left.rho + right.rho) / 2;
102  const rvec u = (waveLeft * left.u + waveRight * right.u) /
103  (waveLeft + waveRight);
104 
105  const real p = (left.p * waveLeft + right.p * waveRight) /
106  (waveLeft + waveRight);
107 
108  const real cs = sqrt(eq.getGamma() * p / rho);
109 
110  speedLeft = fmin(left.u[direction] - sqrt(eq.getGamma() * left.p / left.rho),
111  u[direction] - cs);
112  speedRight = fmax(right.u[direction] + sqrt(eq.getGamma() * right.p /
113  right.rho), u[direction] + cs);
114 
115  }
116 };
117 } // namespace alsfvm
118 } // namespace numflux
119 } // namespace euler
120 
Definition: types.hpp:104
__device__ __host__ real getGamma() const
Definition: Euler.hpp:299
#define __host__
Definition: types.hpp:46
__device__ static __host__ void computeHLLSpeeds(const equation::euler::Euler< nsd > eq, const equation::euler::AllVariables< nsd > &left, const equation::euler::AllVariables< nsd > &right, real &speedLeft, real &speedRight)
Definition: HLL.hpp:90
Definition: ConservedVariables.hpp:30
double real
Definition: types.hpp:65
int rho
Definition: sodshocktube.py:3
Definition: HLL.hpp:35
rvec u
Definition: ExtraVariables.hpp:59
#define static_assert(x, y)
Definition: types.hpp:52
__device__ static __host__ real computeFlux(const equation::euler::Euler< nsd > eq, const equation::euler::AllVariables< nsd > &left, const equation::euler::AllVariables< nsd > &right, equation::euler::ConservedVariables< nsd > &F)
Definition: HLL.hpp:52
#define __device__
Definition: types.hpp:45
Definition: Euler.hpp:36
static const std::string name
name is "hll"
Definition: HLL.hpp:41
real p
Definition: ExtraVariables.hpp:58
real rho
Definition: ConservedVariables.hpp:92
Definition: AllVariables.hpp:27
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
float p
Definition: sodshocktube.py:5
Types< nsd >::rvec rvec
Definition: HLL.hpp:43