Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
cpu_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 CPU_SLOPE_LIMITERS_H
24#define CPU_SLOPE_LIMITERS_H
25
26#include "vec.h"
27
28using namespace std;
29
30static inline Vec minmod(const Vec &slope1, const Vec &slope2)
31{
32 const Vec veczero(0.0);
33 const Vec slope = select(abs(slope1) < abs(slope2), slope1, slope2);
34 return select(slope1 * slope2 <= 0, veczero, slope);
35}
36static inline Vec maxmod(const Vec &slope1, const Vec &slope2)
37{
38 const Vec veczero(0.0);
39 const Vec slope = select(abs(slope1) > abs(slope2), slope1, slope2);
40 return select(slope1 * slope2 <= 0, veczero, slope);
41}
42
46
47static inline Vec slope_limiter_sb(const Vec &l, const Vec &m, const Vec &r)
48{
49 const Vec a = r-m;
50 const Vec b = m-l;
51 const Vec slope1 = minmod(a, 2*b);
52 const Vec slope2 = minmod(2*a, b);
53 return maxmod(slope1, slope2);
54}
55
59
60static inline Vec slope_limiter_minmod(const Vec& l,const Vec& m, const Vec& r)
61{
62 //Vec sign;
63 const Vec a=r-m;
64 const Vec b=m-l;
65 return minmod(a,b);
66}
67
71
72static inline Vec slope_limiter_mc(const Vec& l,const Vec& m, const Vec& r)
73{
74 const Vec veczero(0.0);
75 const Vec vectwo(2.0);
76 const Vec vechalf(0.5);
77 //Vec sign;
78 const Vec a=r-m;
79 const Vec b=m-l;
80 Vec minval=min(vectwo*abs(a),vectwo*abs(b));
81 minval=min(minval,vechalf*abs(a+b));
82
83 //check for extrema
84 const Vec output = select(a*b < 0,veczero,minval);
85 //set sign
86 return select(a + b < 0,-output,output);
87}
88
89static inline Vec slope_limiter_minmod_amr(const Vec& l,const Vec& m, const Vec& r,const Vec& a,const Vec& b)
90{
91 const Vec J = r-l;
92 Vec f = (m-l)/J;
93 f = min(Vec(1.0),f);
94 return min(f/(1+a),(Vec(1.)-f)/(1+b))*2*J;
95}
96
97static inline Vec slope_limiter(const Vec &l, const Vec &m, const Vec &r)
98{
99 return slope_limiter_sb(l,m,r);
100 //return slope_limiter_minmod(l,m,r);
101}
102
103/*
104 * @param a Cell size fraction dx[i-1]/dx[i] = 1/2, 1, or 2.
105 * @param b Cell size fraction dx[i+1]/dx[i] = 1/2, 1, or 2.
106 * @return Limited value of slope.*/
107static inline Vec slope_limiter_amr(const Vec& l,const Vec& m, const Vec& r,const Vec& dx_left,const Vec& dx_rght)
108{
109 return slope_limiter_minmod_amr(l,m,r,dx_left,dx_rght);
110}
111
112/* Slope limiter with abs and sign separatelym, uses the currently active slope limiter*/
113static inline void slope_limiter(const Vec& l,const Vec& m, const Vec& r, Vec& slope_abs, Vec& slope_sign)
114{
115 const Vec slope = slope_limiter(l,m,r);
116 slope_abs = abs(slope);
117 slope_sign = select(slope > 0, Vec(1.0), Vec(-1.0));
118}
119
120#endif
An interface to a type with floating point values.
static ARCH_HOSTDEV VecSimple< T > min(VecSimple< T > const &l, VecSimple< T > const &r)
static ARCH_HOSTDEV VecSimple< T > select(VecSimple< bool > const &a, VecSimple< T > const &b, VecSimple< T > const &c)
static ARCH_HOSTDEV VecSimple< T > abs(const VecSimple< T > &l)
static Vec minmod(const Vec &slope1, const Vec &slope2)
static Vec slope_limiter_minmod(const Vec &l, const Vec &m, const Vec &r)
static Vec slope_limiter_mc(const Vec &l, const Vec &m, const Vec &r)
static Vec slope_limiter_amr(const Vec &l, const Vec &m, const Vec &r, const Vec &dx_left, const Vec &dx_rght)
static Vec slope_limiter(const Vec &l, const Vec &m, const Vec &r)
static Vec maxmod(const Vec &slope1, const Vec &slope2)
static Vec slope_limiter_minmod_amr(const Vec &l, const Vec &m, const Vec &r, const Vec &a, const Vec &b)
static Vec slope_limiter_sb(const Vec &l, const Vec &m, const Vec &r)