limiter.m 1.13 KB
Newer Older
Gidon Lucian Bauer's avatar
Limiter    
Gidon Lucian Bauer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
close all; clear; clc;

theta = linspace(-4, 4, 1000);

fig = figure(1);
fig.WindowState = 'maximized';
hold on;
plot(theta, superbee(theta), 'DisplayName', 'superbee');
plot(theta, minmod(theta), 'DisplayName', 'minmod');
plot(theta, vanLeer(theta), 'DisplayName', 'van Leer');
plot(theta, cslimiter(theta), 'DisplayName', 'Čada-Schmidtmann');
title('Limiter functions');
xlabel('\theta');
ylabel('\phi');
legend;
hold off;

function phi = t3(theta)
    phi = (2 + theta) / 3;
end

function phi = cslimiter(theta)
    phi = zeros(size(theta));
    for i = 1:length(theta)
        phi(i) = max(0, min(t3(theta(i)), max(-theta(i), min(2*theta(i), min(t3(theta(i)), 1.5)))));
    end
end

function phi = superbee(theta)
    phi = zeros(size(theta));
    for i = 1:length(theta)
        phi(i) = max(0, max(min(1, 2*theta(i)), min(2, theta(i))));
    end
end

function phi = minmod(theta)
    phi = zeros(size(theta));
    for i = 1:length(theta)
        phi(i) = max(0, min(1, theta(i)));
    end
end

function phi = vanLeer(theta)
    phi = zeros(size(theta));
    for i = 1:length(theta)
        phi(i) = (theta(i) + abs(theta(i))) / (1 + theta(i));
    end
end