-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterp.c
94 lines (77 loc) · 1.61 KB
/
interp.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Modified by Alexander Tchekhovskoy: MPI+3D
/* M1: no changes needed */
/***
includes all interpolation routines
linear (MC or other limiter)
parabolic (from collela and woodward)
weno
***/
#include "decs.h"
/* performs the slope-limiting for the numerical flux calculation */
double slope_lim(double y1, double y2, double y3)
{
double Dqm, Dqp, Dqc, s;
/* woodward, or monotonized central, slope limiter */
if (lim == MC) {
Dqm = 2. * (y2 - y1);
Dqp = 2. * (y3 - y2);
Dqc = 0.5 * (y3 - y1);
s = Dqm * Dqp;
if (s <= 0.)
return 0.;
else {
if (fabs(Dqm) < fabs(Dqp) && fabs(Dqm) < fabs(Dqc))
return (Dqm);
else if (fabs(Dqp) < fabs(Dqc))
return (Dqp);
else
return (Dqc);
}
}
/* van leer slope limiter */
else if (lim == VANL) {
Dqm = (y2 - y1);
Dqp = (y3 - y2);
s = Dqm * Dqp;
if (s <= 0.)
return 0.;
else
return (2. * s / (Dqm + Dqp));
}
/* minmod slope limiter (crude but robust) */
else if (lim == MINM) {
Dqm = (y2 - y1);
Dqp = (y3 - y2);
s = Dqm * Dqp;
if (s <= 0.)
return 0.;
else if (fabs(Dqm) < fabs(Dqp))
return Dqm;
else
return Dqp;
}
fprintf(stderr, "unknown slope limiter\n");
exit(10);
return (0.);
}
void linear_mc(double x1, double x2, double x3, double *lout, double *rout)
{
double Dqm,Dqp,Dqc,s;
Dqm = 2. * (x2 - x1);
Dqp = 2. * (x3 - x2);
Dqc = 0.5 * (x3 - x1);
s = Dqm * Dqp;
if (s <= 0.)
s = 0.;
else {
if (fabs(Dqm) < fabs(Dqp) && fabs(Dqm) < fabs(Dqc))
s = Dqm;
else if (fabs(Dqp) < fabs(Dqc))
s = Dqp;
else
s = Dqc;
}
/* reconstruct left, right */
*lout = x2 - 0.5*s;
*rout = x2 + 0.5*s;
}