forked from zuowangda/Fast-Fluid-Dynamics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpolation.c
89 lines (81 loc) · 3.13 KB
/
interpolation.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
///////////////////////////////////////////////////////////////////////////////
///
/// \file interpolation.c
///
/// \brief Interpolate the data for advection step
///
/// \author Wangda Zuo
/// University of Miami
/// Mingang Jin, Qingyan Chen
/// Purdue University
///
/// \date 8/3/2013
///
///////////////////////////////////////////////////////////////////////////////
#include "interpolation.h"
///////////////////////////////////////////////////////////////////////////////
/// Entrance of interpolation
///
///\param para Pointer to FFD parameters
///\param d0 Pointer to the variable for interpolation
///\param p I-index of the control volume
///\param q J-index of the control volume
///\param r K-index of the control volume
///\param x_1 Reciprocal of X-length
///\param y_1 Reciprocal of Y-length
///\param z_1 Reciprocal of Z-length
///
///\return Interpolated value
///////////////////////////////////////////////////////////////////////////////
REAL interpolation(PARA_DATA *para, REAL *d0, REAL x_1, REAL y_1, REAL z_1,
int p, int q, int r) {
int imax = para->geom->imax, jmax = para->geom->jmax;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
switch(para->solv->interpolation) {
case BILINEAR:
return interpolation_bilinear(x_1, y_1, z_1,
d0[IX(p,q,r)], d0[IX(p,q+1,r)], d0[IX(p+1,q,r)], d0[IX(p+1,q+1,r)],
d0[IX(p,q,r+1)],d0[IX(p,q+1,r+1)],d0[IX(p+1,q,r+1)],d0[IX(p+1,q+1,r+1)]);
break;
default:
sprintf(msg,
"interpolation(): the requried interpolation method %d is not available.",
para->solv->interpolation);
ffd_log(msg, FFD_ERROR);
return -1;
}
} // End of interpolation()
///////////////////////////////////////////////////////////////////////////////
/// Bilinear interpolation
///
///\param x_1 Reciprocal of X-length
///\param y_1 Reciprocal of Y-length
///\param z_1 Reciprocal of Z-length
///\param d000 parameter for interpolation
///\param d010 parameter for interpolation
///\param d100 parameter for interpolation
///\param d110 parameter for interpolation
///\param d001 parameter for interpolation
///\param d011 parameter for interpolation
///\param d101 parameter for interpolation
///\param d111 parameter for interpolation
//
///\return Interpolated value
///////////////////////////////////////////////////////////////////////////////
REAL interpolation_bilinear(REAL x_1, REAL y_1, REAL z_1,
REAL d000, REAL d010, REAL d100, REAL d110,
REAL d001, REAL d011, REAL d101, REAL d111) {
REAL x_0, y_0, z_0;
REAL tmp0, tmp1;
/*-------------------------------------------------------------------------
| Interpolating for all variables
-------------------------------------------------------------------------*/
x_0 = (REAL) 1.0 - x_1;
y_0 = (REAL) 1.0 - y_1;
z_0 = (REAL) 1.0 - z_1;
tmp0 = x_0*(y_0*d000+y_1*d010) + x_1*(y_0*d100+y_1*d110);
tmp1 = x_0*(y_0*d001+y_1*d011) + x_1*(y_0*d101+y_1*d111);
return z_0*tmp0+z_1*tmp1;
} // End of interpolation_bilinear()