forked from AFD-Illinois/igrmonty2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interp.c
50 lines (36 loc) · 952 Bytes
/
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
#include "decs.h"
double interp_scalar(double X[NDIM], double ***var)
{
double interp, del[NDIM], b1, b2;
int i, j, k, ip1, jp1, kp1;
Xtoijk(X, &i, &j, &k, del);
ip1 = i + 1;
jp1 = j + 1;
kp1 = k + 1;
// Hard-coded periodicity in X[3]
if (k == N3 - 1) kp1 = 0;
b1 = 1. - del[1];
b2 = 1. - del[2];
// Interpolate in x1, x2
interp = var[i][j][k]*b1*b2 +
var[i][jp1][k]*b1*del[2] +
var[ip1][j][k]*del[1]*b2 +
var[ip1][jp1][k]*del[1]*del[2];
// Interpolate in x3
interp = (1.-del[3])*interp +
del[3]*(var[i ][j ][kp1]*b1*b2 +
var[i ][jp1][kp1]*del[2]*b1 +
var[ip1][j ][kp1]*del[1]*b2 +
var[ip1][jp1][kp1]*del[1]*del[2]);
return interp;
}
double linear_interp_weight(double nu)
{
int i;
double di, lnu;
lnu = log(nu);
di = (lnu - LNUMIN)/DLNU;
i = (int)di;
di = di - i;
return exp((1. - di)*wgt[i] + di*wgt[i + 1]);
}