-
Notifications
You must be signed in to change notification settings - Fork 7
/
diffusion.c
342 lines (312 loc) · 12 KB
/
diffusion.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
///////////////////////////////////////////////////////////////////////////////
///
/// \file diffusion.c
///
/// \brief Calculate the diffusion equation
///
/// \author Mingang Jin, Qingyan Chen
/// Purdue University
/// Wangda Zuo
/// University of Miami
///
/// \date 8/3/2013
///
/// This file provides functions that are used for calculating the diffusion
/// equations.
///
///////////////////////////////////////////////////////////////////////////////
#include "diffusion.h"
///////////////////////////////////////////////////////////////////////////////
/// Entrance of calculating diffusion equation
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param var_type Type of variable
///\param index Index of trace substance or species
///\param psi Pointer to the variable at current time step
///\param psi0 Pointer to the variable at previous time step
///\param BINDEX Pointer to boundary index
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int diffusion(PARA_DATA *para, REAL **var, int var_type, int index,
REAL *psi, REAL *psi0, int **BINDEX) {
int flag = 0;
/****************************************************************************
| Define the coeffcients for diffusion euqation
****************************************************************************/
flag = coef_diff(para, var, psi, psi0, var_type, index, BINDEX);
if(flag!=0) {
ffd_log("diffsuion(): Could not calculate coefficents for "
"diffusion equation.", FFD_ERROR);
return flag;
}
// Solve the equations
equ_solver(para, var, var_type, psi);
// Define B.C.
set_bnd(para, var, var_type, index, psi, BINDEX);
// Check residual
if(para->solv->check_residual==1) {
switch(var_type) {
case VX:
sprintf(msg, "diffusion(): Residual of VX is %f",
check_residual(para, var, psi));
ffd_log(msg, FFD_NORMAL);
break;
case VY:
sprintf(msg, "diffusion(): Residual of VY is %f",
check_residual(para, var, psi));
ffd_log(msg, FFD_NORMAL);
break;
case VZ:
sprintf(msg, "diffusion(): Residual of VZ is %f",
check_residual(para, var, psi));
ffd_log(msg, FFD_NORMAL);
break;
case TEMP:
sprintf(msg, "diffusion(): Residual of T is %f",
check_residual(para, var, psi));
ffd_log(msg, FFD_NORMAL);
break;
case TRACE:
sprintf(msg, "diffusion(): Residual of Trace %d is %f",
index, check_residual(para, var, psi));
ffd_log(msg, FFD_NORMAL);
break;
default:
sprintf(msg, "diffusion(): No sovler for varibale type %d",
var_type);
ffd_log(msg, FFD_ERROR);
flag = 1;
}
}
return flag;
} // End of diffusion( )
///////////////////////////////////////////////////////////////////////////////
/// Calcuate coefficients for difussion equation solver
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param psi Pointer to the variable at current time step
///\param psi0 Pointer to the variable at previous time step
///\param var_type Type of variable
///\param index Index of trace substance or species
///\param BINDEX Pointer to boundary index
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int coef_diff(PARA_DATA *para, REAL **var, REAL *psi, REAL *psi0,
int var_type, int index, int **BINDEX) {
int i, j, k;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *aw = var[AW], *ae = var[AE], *as = var[AS], *an = var[AN];
REAL *af = var[AF], *ab = var[AB], *ap = var[AP], *ap0 = var[AP0], *b = var[B];
REAL *x = var[X], *y = var[Y], *z = var[Z];
REAL *gx = var[GX], *gy = var[GY], *gz = var[GZ];
REAL *pp = var[PP];
REAL *Temp = var[TEMP];
REAL dxe, dxw, dyn, dys, dzf, dzb, Dx, Dy, Dz;
REAL dt = para->mytime->dt, beta = para->prob->beta;
REAL Temp_Buoyancy = para->prob->Temp_Buoyancy;
REAL gravx = para->prob->gravx, gravy = para->prob->gravy,
gravz = para->prob->gravz;
REAL kapa;
// define kapa
switch(var_type) {
/*-------------------------------------------------------------------------
| X-velocity
-------------------------------------------------------------------------*/
case VX:
if(para->prob->tur_model==LAM)
kapa = para->prob->nu;
else if(para->prob->tur_model==CONSTANT)
kapa = 101.0f * para->prob->nu;
FOR_U_CELL
dxe = gx[IX(i+1,j ,k)] - gx[IX(i ,j,k)];
dxw = gx[IX(i ,j ,k)] - gx[IX(i-1,j,k)];
dyn = y[IX(i ,j+1,k)] - y[IX(i ,j,k)];
dys = y[IX(i,j,k)] - y[IX(i,j-1,k)];
dzf = z[IX(i,j,k+1)] - z[IX(i,j,k)];
dzb = z[IX(i,j,k)] - z[IX(i,j,k-1)];
Dx = x[IX(i+1,j,k)] - x[IX(i,j,k)];
Dy = gy[IX(i,j,k)] - gy[IX(i,j-1,k)];
Dz = gz[IX(i,j,k)] - gz[IX(i,j,k-1)];
if(para->prob->tur_model==CHEN)
kapa = nu_t_chen_zero_equ(para, var, i, j, k);
aw[IX(i,j,k)] = kapa*Dy*Dz/dxw;
ae[IX(i,j,k)] = kapa*Dy*Dz/dxe;
an[IX(i,j,k)] = kapa*Dx*Dz/dyn;
as[IX(i,j,k)] = kapa*Dx*Dz/dys;
af[IX(i,j,k)] = kapa*Dx*Dy/dzf;
ab[IX(i,j,k)] = kapa*Dx*Dy/dzb;
ap0[IX(i,j,k)] = Dx*Dy*Dz/dt;
b[IX(i,j,k)] = psi0[IX(i,j,k)]*ap0[IX(i,j,k)]
- beta*gravx*(Temp[IX(i,j,k)]-Temp_Buoyancy)*Dx*Dy*Dz
+ (pp[IX(i,j,k)]-pp[IX(i+1,j,k)])*Dy*Dz;
END_FOR
//set_bnd(para, var, var_type, psi, BINDEX);
FOR_U_CELL
ap[IX(i,j,k)] = ap0[IX(i,j,k)] + ae[IX(i,j,k)] + aw[IX(i,j,k)]
+ an[IX(i,j,k)] + as[IX(i,j,k)] + af[IX(i,j,k)]
+ ab[IX(i,j,k)];
END_FOR
break;
/*-------------------------------------------------------------------------
| Y-velocity
-------------------------------------------------------------------------*/
case VY:
if(para->prob->tur_model==LAM)
kapa = para->prob->nu;
else if(para->prob->tur_model==CONSTANT)
kapa = (REAL) 101.0 * para->prob->nu;
FOR_V_CELL
dxe = x[IX(i+1,j,k)] - x[IX(i,j,k)];
dxw = x[IX(i,j,k)] - x[IX(i-1,j,k)];
dyn = gy[IX(i,j+1,k)] - gy[IX(i,j,k)];
dys = gy[IX(i,j,k)] - gy[IX(i,j-1,k)];
dzf = z[IX(i,j,k+1)] - z[IX(i,j,k)];
dzb = z[IX(i,j,k)] - z[IX(i,j,k-1)];
Dx = gx[IX(i,j,k)] - gx[IX(i-1,j,k)];
Dy = y[IX(i,j+1,k)] - y[IX(i,j,k)];
Dz = gz[IX(i,j,k)] - gz[IX(i,j,k-1)];
if(para->prob->tur_model==CHEN)
kapa = nu_t_chen_zero_equ(para, var, i, j, k);
aw[IX(i,j,k)] = kapa*Dy*Dz/dxw;
ae[IX(i,j,k)] = kapa*Dy*Dz/dxe;
an[IX(i,j,k)] = kapa*Dx*Dz/dyn;
as[IX(i,j,k)] = kapa*Dx*Dz/dys;
af[IX(i,j,k)] = kapa*Dx*Dy/dzf;
ab[IX(i,j,k)] = kapa*Dx*Dy/dzb;
ap0[IX(i,j,k)] = Dx*Dy*Dz/dt;
b[IX(i,j,k)] = psi0[IX(i,j,k)]*ap0[IX(i,j,k)]
- beta*gravy*(Temp[IX(i,j,k)]-Temp_Buoyancy)*Dx*Dy*Dz
+ (pp[IX(i,j,k)]-pp[IX(i ,j+1,k)])*Dx*Dz;
END_FOR
//set_bnd(para, var, var_type, psi,BINDEX);
FOR_V_CELL
ap[IX(i,j,k)] = ap0[IX(i,j,k)] + ae[IX(i,j,k)] + aw[IX(i,j,k)]
+ an[IX(i,j,k)] + as[IX(i,j,k)] + af[IX(i,j,k)]
+ ab[IX(i,j,k)];
END_FOR
break;
/*-------------------------------------------------------------------------
| Z-velocity
-------------------------------------------------------------------------*/
case VZ:
if(para->prob->tur_model==LAM)
kapa = para->prob->nu;
else if(para->prob->tur_model==CONSTANT)
kapa = (REAL) 101.0 * para->prob->nu;
FOR_W_CELL
dxe = x[IX(i+1,j,k)] - x[IX(i,j,k)];
dxw = x[IX(i,j,k)] - x[IX(i-1,j,k)];
dyn = y[IX(i,j+1,k)] - y[IX(i,j,k)];
dys = y[IX(i,j,k)] - y[IX(i,j-1,k)];
dzf = gz[IX(i,j,k+1)] - gz[IX(i,j,k)];
dzb = gz[IX(i,j,k)] - gz[IX(i,j,k-1)];
Dx = gx[IX(i,j,k)] - gx[IX(i-1,j,k)];
Dy = gy[IX(i,j,k)] - gy[IX(i,j-1,k)];
Dz = z[IX(i,j,k+1)] - z[IX(i,j,k)];
if(para->prob->tur_model==CHEN)
kapa = nu_t_chen_zero_equ(para, var, i, j, k);
aw[IX(i,j,k)] = kapa*Dy*Dz/dxw;
ae[IX(i,j,k)] = kapa*Dy*Dz/dxe;
an[IX(i,j,k)] = kapa*Dx*Dz/dyn;
as[IX(i,j,k)] = kapa*Dx*Dz/dys;
af[IX(i,j,k)] = kapa*Dx*Dy/dzf;
ab[IX(i,j,k)] = kapa*Dx*Dy/dzb;
ap0[IX(i,j,k)] = Dx*Dy*Dz/dt;
b[IX(i,j,k)] = psi0[IX(i,j,k)]*ap0[IX(i,j,k)]
- beta*gravz*(Temp[IX(i,j,k)]-Temp_Buoyancy)*Dx*Dy*Dz
+ (pp[IX(i,j,k)]-pp[IX(i ,j,k+1)])*Dy*Dx;
END_FOR
//set_bnd(para, var, var_type, psi, BINDEX);
FOR_W_CELL
ap[IX(i,j,k)] = ap0[IX(i,j,k)] + ae[IX(i,j,k)] + aw[IX(i,j,k)]
+ an[IX(i,j,k)] + as[IX(i,j,k)] + af[IX(i,j,k)]
+ ab[IX(i,j,k)];
END_FOR
break;
/*-------------------------------------------------------------------------
| Scalar Variable
-------------------------------------------------------------------------*/
case TEMP:
case TRACE:
if(para->prob->tur_model == LAM)
kapa = para->prob->alpha;
else if(para->prob->tur_model == CONSTANT)
kapa = (REAL) 101.0 * para->prob->alpha;
FOR_EACH_CELL
dxe = x[IX(i+1,j,k)] - x[IX(i,j,k)];
dxw = x[IX(i,j,k)] - x[IX(i-1,j,k)];
dyn = y[IX(i,j+1,k)] - y[IX(i,j,k)];
dys = y[IX(i,j,k)] - y[IX(i,j-1,k)];
dzf = z[IX(i,j,k+1)] - z[IX(i,j,k)];
dzb = z[IX(i,j,k)] - z[IX(i,j,k-1)];
Dx = gx[IX(i,j,k)] - gx[IX(i-1,j,k)];
Dy = gy[IX(i,j,k)] - gy[IX(i,j-1,k)];
Dz = gz[IX(i,j,k)] - gz[IX(i,j,k-1)];
aw[IX(i,j,k)] = kapa*Dy*Dz/dxw;
ae[IX(i,j,k)] = kapa*Dy*Dz/dxe;
an[IX(i,j,k)] = kapa*Dx*Dz/dyn;
as[IX(i,j,k)] = kapa*Dx*Dz/dys;
af[IX(i,j,k)] = kapa*Dx*Dy/dzf;
ab[IX(i,j,k)] = kapa*Dx*Dy/dzb;
ap0[IX(i,j,k)] = Dx*Dy*Dz/dt;
b[IX(i,j,k)] = psi0[IX(i,j,k)]*ap0[IX(i,j,k)];
END_FOR
set_bnd(para, var, var_type, index, psi, BINDEX);
FOR_EACH_CELL
ap[IX(i,j,k)] = ap0[IX(i,j,k)] + ae[IX(i,j,k)] + aw[IX(i,j,k)]
+ an[IX(i,j,k)] + as[IX(i,j,k)] + af[IX(i,j,k)] + ab[IX(i,j,k)];
END_FOR
break;
default:
sprintf(msg, "coe_diff(): No function for variable type %d", var_type);
ffd_log(msg, FFD_ERROR);
return 1;
break;
}
return 0;
}// End of coef_diff( )
///////////////////////////////////////////////////////////////////////////////
/// Calcuate source term in the difussion equation
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param var_type Type of variable
///\param index Index of trace substances or species
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int source_diff(PARA_DATA *para, REAL **var, int var_type, int index) {
int i, j, k;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *b = var[B];
FOR_EACH_CELL
switch(var_type) {
case VX:
b[IX(i,j,k)] += var[VXS][IX(i,j,k)];
break;
case VY:
b[IX(i,j,k)] += var[VYS][IX(i,j,k)];
break;
case VZ:
b[IX(i,j,k)] += var[VZS][IX(i,j,k)];
break;
case TEMP:
b[IX(i,j,k)] += var[TEMPS][IX(i,j,k)];
break;
case TRACE:
b[IX(i,j,k)] += var[TRACE+para->bc->nb_Xi+index][IX(i,j,k)];
break;
}
END_FOR
return 0;
} // End of source_diff()