Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
gpu_slope_limiters.hpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#ifndef GPU_SLOPE_LIMITERS_H
24#define GPU_SLOPE_LIMITERS_H
25
27
28/****
29 Define functions for Realf instead of Vec
30 These functions take direct arguments instead of references for non-const input
31 so that registers and other optimizations are available.
32***/
33
34static ARCH_DEV inline Realf minmod(const Realf slope1, const Realf slope2)
35{
36 const Realf slope = (abs(slope1) < abs(slope2)) ? slope1 : slope2;
37 return (slope1 * slope2 <= (Realf)(0.0)) ? (Realf)(0.0) : slope;
38}
39static ARCH_DEV inline Realf maxmod(const Realf slope1, const Realf slope2)
40{
41 const Realf slope = (abs(slope1) > abs(slope2)) ? slope1 : slope2;
42 return (slope1 * slope2 <= (Realf)(0.0)) ? (Realf)(0.0) : slope;
43}
44
48
49static ARCH_DEV inline Realf slope_limiter_sb(const Realf l, const Realf m, const Realf r)
50{
51 const Realf a = r-m;
52 const Realf b = m-l;
53 const Realf slope1 = minmod(a, (Realf)(2.0)*b);
54 const Realf slope2 = minmod((Realf)(2.0)*a, b);
55 return maxmod(slope1, slope2);
56}
57
61
62static ARCH_DEV inline Realf slope_limiter_minmod(const Realf l, const Realf m, const Realf r)
63{
64 const Realf a=r-m;
65 const Realf b=m-l;
66 return minmod(a,b);
67}
68
72
73static ARCH_DEV inline Realf slope_limiter_mc(const Realf l, const Realf m, const Realf r)
74{
75 const Realf a=r-m;
76 const Realf b=m-l;
77 Realf minval=min((Realf)(2.0)*abs(a),(Realf)(2.0)*abs(b));
78 minval=min(minval,(Realf)(0.5)*abs(a+b));
79
80 //check for extrema
81 const Realf output = (a*b < (Realf)(0.0)) ? (Realf)(0.0) : minval;
82 //set sign
83 return (a + b < (Realf)(0.0)) ? -output : output;
84}
85
86static ARCH_DEV inline Realf slope_limiter_minmod_amr(const Realf l,const Realf m, const Realf r,const Realf a,const Realf b)
87{
88 const Realf J = r-l;
89 Realf f = (m-l)/J;
90 f = min((Realf)(1.0),f);
91 return min((Realf)(f)/(1+a),(Realf)(1.-f)/((Realf)(1.0)+b))*(Realf)(2.0)*J;
92}
93
94static ARCH_DEV inline Realf slope_limiter(const Realf l, const Realf m, const Realf r)
95{
96 return slope_limiter_sb(l,m,r);
97 //return slope_limiter_minmod(l,m,r);
98}
99
100/*
101 * @param a Cell size fraction dx[i-1]/dx[i] = 1/2, 1, or 2.
102 * @param b Cell size fraction dx[i+1]/dx[i] = 1/2, 1, or 2.
103 * @return Limited value of slope.*/
104static ARCH_DEV inline Realf slope_limiter_amr(const Realf l,const Realf m, const Realf r,const Realf dx_left,const Realf dx_rght)
105{
106 return slope_limiter_minmod_amr(l,m,r,dx_left,dx_rght);
107}
108
109/* Slope limiter with abs and sign separately, uses the currently active slope limiter*/
110static ARCH_DEV inline void slope_limiter(const Realf l,const Realf m, const Realf r, Realf& slope_abs, Realf& slope_sign)
111{
112 const Realf slope = slope_limiter(l,m,r);
113 slope_abs = abs(slope);
114 slope_sign = (slope > (Realf)(0.0)) ? (Realf)(1.0) : (Realf)(-1.0);
115}
116
117
118
119#endif
#define ARCH_DEV
float Realf
Definition definitions.h:33
static ARCH_DEV Realf maxmod(const Realf slope1, const Realf slope2)
static ARCH_DEV Realf slope_limiter(const Realf l, const Realf m, const Realf r)
static ARCH_DEV Realf slope_limiter_minmod_amr(const Realf l, const Realf m, const Realf r, const Realf a, const Realf b)
static ARCH_DEV Realf slope_limiter_sb(const Realf l, const Realf m, const Realf r)
static ARCH_DEV Realf minmod(const Realf slope1, const Realf slope2)
static ARCH_DEV Realf slope_limiter_amr(const Realf l, const Realf m, const Realf r, const Realf dx_left, const Realf dx_rght)
static ARCH_DEV Realf slope_limiter_mc(const Realf l, const Realf m, const Realf r)
static ARCH_DEV Realf slope_limiter_minmod(const Realf l, const Realf m, const Realf r)
static ARCH_HOSTDEV VecSimple< T > min(VecSimple< T > const &l, VecSimple< T > const &r)
static ARCH_HOSTDEV VecSimple< T > abs(const VecSimple< T > &l)