Alsvinn  0.5.3
The fast FVM simulator with UQ support
WENO2.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 "alsfvm/types.hpp"
19 
20 namespace alsfvm {
21 namespace reconstruction {
22 
27 template<class Equation>
28 class WENO2 {
29 public:
30 
31  __device__ __host__ static void reconstruct(Equation eq,
32  typename Equation::ConstViews& in,
33  size_t x, size_t y, size_t z,
34  typename Equation::Views& leftView,
35  typename Equation::Views& rightView,
36  bool xDir, bool yDir, bool zDir) {
37  const size_t indexOut = leftView.index(x, y, z);
38  const size_t indexRight = leftView.index(x + xDir, y + yDir, z + zDir);
39  const size_t indexLeft = leftView.index(x - xDir, y - yDir, z - zDir);
40  const real i0 = eq.getWeight(in, indexOut);
41  const real b0 = square(eq.getWeight(in, indexRight) - i0);
42  const real b1 = square(i0 - eq.getWeight(in, indexLeft));
43 
44  const real a0Left = 1 / (3 * (ALSFVM_WENO_EPSILON + b0) *
45  (ALSFVM_WENO_EPSILON + b0));
46  const real a1Left = 2 / (3 * (ALSFVM_WENO_EPSILON + b1) *
47  (ALSFVM_WENO_EPSILON + b1));
48  const real w0Left = a0Left / (a0Left + a1Left);
49  const real w1Left = a1Left / (a0Left + a1Left);
50 
51  const real a0Right = 2 / (3 * (ALSFVM_WENO_EPSILON + b0) *
52  (ALSFVM_WENO_EPSILON + b0));
53  const real a1Right = 1 / (3 * (ALSFVM_WENO_EPSILON + b1) *
54  (ALSFVM_WENO_EPSILON + b1));
55  const real w0Right = a0Right / (a0Right + a1Right);
56  const real w1Right = a1Right / (a0Right + a1Right);
57 #if 1
58 #ifdef __CUDA_ARCH__
59 #pragma unroll
60 #endif
61 
62  for (size_t var = 0; var < Equation::getNumberOfConservedVariables(); ++var) {
63  leftView.get(var).at(indexOut) = 0.5 * (w1Left * in.get(var).at(indexLeft) +
64  (3 * w0Left + w1Left) * in.get(var).at(indexOut) -
65  w0Left * in.get(var).at(indexRight));
66 
67  rightView.get(var).at(indexOut) = 0.5 * (w0Right * in.get(var).at(indexRight) +
68  (3 * w1Right + w0Right) * in.get(var).at(indexOut) -
69  w1Right * in.get(var).at(indexLeft));
70 
71  }
72 
73 #else
74  typename Equation::ConservedVariables inLeft = eq.fetchConservedVariables(in,
75  indexLeft);
76  typename Equation::ConservedVariables inMiddle = eq.fetchConservedVariables(in,
77  indexOut);
78  typename Equation::ConservedVariables inRight = eq.fetchConservedVariables(in,
79  indexRight);
80 
81  typename Equation::ConservedVariables left = 0.5 * (w1Left * inLeft +
82  (3 * w0Left + w1Left) * inMiddle -
83  w0Left * inRight);
84 
85  typename Equation::ConservedVariables right = 0.5 * (w0Right * inRight +
86  (3 * w1Right + w0Right) * inMiddle -
87  w1Right * inLeft);
88  eq.setViewAt(leftView, indexOut, left);
89  eq.setViewAt(rightView, indexOut, right);
90 #endif
91  }
92 
94  return 2;
95  }
96 };
97 } // namespace alsfvm
98 } // namespace reconstruction
alsfvm::shared_ptr< reconstruction::Reconstruction > & reconstruction
Definition: NumericalFluxFactory.cpp:101
#define ALSFVM_WENO_EPSILON
Definition: WENOCoefficients.hpp:21
__device__ static __host__ void reconstruct(Equation eq, typename Equation::ConstViews &in, size_t x, size_t y, size_t z, typename Equation::Views &leftView, typename Equation::Views &rightView, bool xDir, bool yDir, bool zDir)
Definition: WENO2.hpp:31
#define __host__
Definition: types.hpp:46
double real
Definition: types.hpp:65
#define __device__
Definition: types.hpp:45
__device__ static __host__ int getNumberOfGhostCells()
Definition: WENO2.hpp:93
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
Definition: WENO2.hpp:28
__host__ __device__ real square(const real &x)
Definition: types.hpp:159