Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
fs_limiters.h
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
30
31#ifndef FS_LIMITERS_H
32#define FS_LIMITERS_H
33
34#include <cstdlib>
35#include <algorithm>
36#include <limits>
37
38template<typename T> inline T minmod(const T& a,const T& b) {
39 const T ZERO = 0.0;
40
41 if (a*b < ZERO) return ZERO;
42 else if (fabs(a) < fabs(b)) return a;
43 else return b;
44}
45
46template<typename T> inline T minmod(const T& left,const T& cent,const T& rght) {
47 const T HALF = 0.5;
48 const T val1 = cent-left;
49 const T val2 = rght-cent;
50 return HALF*(sign(val1)+sign(val2))*std::min(fabs(val1),fabs(val2));
51}
52
53template<typename T> inline T MClimiter(const T& left,const T& cent,const T& right) {
54 const T HALF = 0.5;
55 const T TWO = 2.0;
56
57 const T forw = right-cent;
58 const T back = cent-left;
59 const T cntr = HALF*(right-left);
60 const T slope1 = minmod(TWO*forw,cntr);
61 const T slope2 = minmod(TWO*back,cntr);
62 return minmod(slope1,slope2);
63}
64
65template<typename T> inline T superbee(const T& left,const T& cent,const T& right) {
66 const T HALF = 0.5;
67
68 const T back = cent-left;
69 const T forw = right-cent;
70 T tmp = std::min(fabs(back),fabs(forw));
71 tmp = std::min(tmp,HALF*std::max(fabs(back),fabs(forw)));
72 return (sign(back)+sign(forw))*tmp;
73}
74
75template<typename T> inline T vanLeer(const T& left,const T& cent,const T& right) {
76 static constexpr T EPSILON = std::numeric_limits<T>::min();
77 static constexpr T ZERO = 0.0;
78 static constexpr T TWO = 2.0;
79
80 const T numerator = std::max((right - cent) * (cent - left), ZERO);
81 const T denumerator = right - left;
82 return fabs(denumerator) < EPSILON ? ZERO : TWO * numerator / denumerator;
83}
84
85template<typename T> inline T limiter(const T& left,const T& cent,const T& rght) {
86 return vanLeer(left, cent, rght);
87}
88
90//Real limiter(creal& left,creal& cent,creal& rght);
91
92#endif
int sign(const T &value)
Definition common.h:528
const Real HALF
Definition fs_common.h:49
const Real ZERO
Definition fs_common.h:59
const Real TWO
Definition fs_common.h:58
T vanLeer(const T &left, const T &cent, const T &right)
Definition fs_limiters.h:75
T limiter(const T &left, const T &cent, const T &rght)
Definition fs_limiters.h:85
T MClimiter(const T &left, const T &cent, const T &right)
Definition fs_limiters.h:53
T superbee(const T &left, const T &cent, const T &right)
Definition fs_limiters.h:65
T minmod(const T &a, const T &b)
Definition fs_limiters.h:38