-
Notifications
You must be signed in to change notification settings - Fork 7
/
utility.c
625 lines (554 loc) · 19.8 KB
/
utility.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
///////////////////////////////////////////////////////////////////////////////
///
/// \file utility.c
///
/// \brief Some frequently used functions for FFD
///
/// \author Mingang Jin, Qingyan Chen
/// Purdue University
/// Jin55@purdue.edu, YanChen@purdue.edu
/// Wangda Zuo
/// University of Miami
/// W.Zuo@miami.edu
///
/// \date 8/3/2013
///
///////////////////////////////////////////////////////////////////////////////
#include "utility.h"
///////////////////////////////////////////////////////////////////////////////
/// Check the residual of equation
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param psi Pointer to the variable
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
REAL check_residual(PARA_DATA *para, REAL **var, REAL *x) {
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int i, j, k;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *aw = var[AW], *ae = var[AE], *as = var[AS], *an = var[AN];
REAL *ap = var[AP], *ab = var[AB], *af = var[AF], *b = var[B];
REAL tmp, residual = 0.0;
FOR_EACH_CELL
tmp = ap[IX(i,j,k)]*x[IX(i,j,k)]
- ae[IX(i,j,k)]*x[IX(i+1,j,k)] - aw[IX(i,j,k)]*x[IX(i-1,j,k)]
- an[IX(i,j,k)]*x[IX(i,j+1,k)] - as[IX(i,j,k)]*x[IX(i,j-1,k)]
- af[IX(i,j,k)]*x[IX(i,j,k+1)] - ab[IX(i,j,k)]*x[IX(i,j,k-1)]
- b[IX(i,j,k)];
residual += tmp * tmp;
END_FOR
return residual / (imax*jmax*kmax);
}// End of check_residual( )
///////////////////////////////////////////////////////////////////////////////
/// Write the log file
///
///\param message Pointer the message
///\param msg_type Type ogf message
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
void ffd_log(char *message, FFD_MSG_TYPE msg_type) {
if(msg_type==FFD_NEW) {
if((file_log=fopen("log.ffd","w"))==NULL) {
fprintf(stderr, "Error:can not open error file!\n");
exit(1);
}
}
else if((file_log=fopen("log.ffd","a+"))==NULL) {
fprintf(stderr,"Error:can not open error file!\n");
exit(1);
}
switch(msg_type) {
case FFD_WARNING:
fprintf(file_log, "WARNING in %s\n", message);
break;
case FFD_ERROR:
fprintf(file_log, "ERROR in %s\n", message);
break;
// Normal log
default:
fprintf(file_log, "%s\n", message);
}
fclose(file_log);
} // End of ffd_log()
///////////////////////////////////////////////////////////////////////////////
/// Check the outflow rate of the scalar psi
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param psi Pointer to the variable
///\param BINDEX Pointer to the boudnary index
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
REAL outflow(PARA_DATA *para, REAL **var, REAL *psi, int **BINDEX) {
int i, j, k;
int it;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int index= para->geom->index;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *gx = var[GX], *gy = var[GY], *gz = var[GZ];
REAL *u = var[VX], *v = var[VY], *w = var[VZ];
REAL mass_out=0;
REAL *flagp = var[FLAGP];
/*---------------------------------------------------------------------------
| Compute the total outflow
---------------------------------------------------------------------------*/
for(it=0;it<index;it++) {
i=BINDEX[0][it];
j=BINDEX[1][it];
k=BINDEX[2][it];
if(flagp[IX(i,j,k)]==2) {
if(i==0)
mass_out += psi[IX(i,j,k)] * (-u[IX(i,j,k)])
* (gy[IX(i,j,k)]-gy[IX(i,j-1,k)])
* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(i==imax+1)
mass_out += psi[IX(i-1,j,k)] * u[IX(i-1,j,k)]
* (gy[IX(i,j,k)]-gy[IX(i,j-1,k)])
* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(j==0) mass_out += psi[IX(i,j,k)]*(-v[IX(i,j,k)])*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(j==jmax+1) mass_out += psi[IX(i,j,k)]*v[IX(i,j-1,k)]*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(k==0) mass_out += psi[IX(i,j,k)]*(-w[IX(i,j,k)])*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gy[IX(i,j,k)]-gy[IX(i,j-1,k)]);
if(k==kmax+1) mass_out += psi[IX(i,j,k)]*w[IX(i,j,k-1)]*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gy[IX(i,j,k)]-gy[IX(i,j-1,k)]);
}
}
return mass_out;
} // End of outflow()
///////////////////////////////////////////////////////////////////////////////
/// Check the inflow rate of the scalar psi
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param psi Pointer to the variable
///\param BINDEX Pointer to the boudnary index
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
REAL inflow(PARA_DATA *para, REAL **var, REAL *psi, int **BINDEX) {
int i, j, k;
int it;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int index= para->geom->index;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *gx = var[GX], *gy = var[GY], *gz = var[GZ];
REAL *u = var[VX], *v = var[VY], *w = var[VZ];
REAL mass_in=0;
REAL *flagp = var[FLAGP];
/*---------------------------------------------------------------------------
| Compute the total inflow
---------------------------------------------------------------------------*/
for(it=0;it<index;it++) {
i=BINDEX[0][it];
j=BINDEX[1][it];
k=BINDEX[2][it];
if(flagp[IX(i,j,k)]==0) {
if(i==0) mass_in += psi[IX(i,j,k)]*u[IX(i,j,k)]*(gy[IX(i,j,k)]
-gy[IX(i,j-1,k)])* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(i==imax+1) mass_in += psi[IX(i,j,k)]*(-u[IX(i,j,k)])*(gy[IX(i,j,k)]
-gy[IX(i,j-1,k)])* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(j==0) mass_in += psi[IX(i,j,k)]*v[IX(i,j,k)]*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(j==jmax+1) mass_in += psi[IX(i,j,k)]*(-v[IX(i,j,k)])*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
if(k==0) mass_in += psi[IX(i,j,k)]*w[IX(i,j,k)]*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gy[IX(i,j,k)]-gy[IX(i,j-1,k)]);
if(k==kmax+1) mass_in += psi[IX(i,j,k)]*(-w[IX(i,j,k)])*(gx[IX(i,j,k)]
-gx[IX(i-1,j,k)])* (gy[IX(i,j,k)]-gy[IX(i,j-1,k)]);
}
}
return mass_in;
} // End of inflow()
///////////////////////////////////////////////////////////////////////////////
/// Check the minimum value of the scalar psi at (ci,cj,ck) and its surrounding
/// cells
///
///\param para Pointer to FFD parameters
///\param psi Pointer to the variable
///\param ci Index in x direction
///\param cj Index in y direction
///\param ck Index in z direction
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
REAL check_min(PARA_DATA *para, REAL *psi, int ci, int cj, int ck) {
int imax = para->geom->imax, jmax = para->geom->jmax;
int i, j, k;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL tmp = psi[IX(ci,cj,ck)];
for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
for(k=0;k<=1;k++) {
if(tmp>psi[IX(ci+i,cj+j,ck+k)]) tmp=psi[IX(ci+i,cj+j,ck+k)];
}
return tmp;
}// End of check_min( )
///////////////////////////////////////////////////////////////////////////////
/// Check the maximum value of the scalar psi at (ci,cj,ck) and its surrounding
/// cells
///
///\param para Pointer to FFD parameters
///\param psi Pointer to the variable
///\param ci Index in x direction
///\param cj Index in y direction
///\param ck Index in z direction
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
REAL check_max(PARA_DATA *para, REAL *psi, int ci, int cj, int ck) {
int imax = para->geom->imax, jmax = para->geom->jmax;
int i, j, k;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL tmp = psi[IX(ci,cj,ck)];
for(i=0;i<=1;i++)
for(j=0;j<=1;j++)
for(k=0;k<=1;k++) {
if(tmp<psi[IX(ci+i,cj+j,ck+k)]) tmp=psi[IX(ci+i,cj+j,ck+k)];
}
return tmp;
}// End of check_max( )
///////////////////////////////////////////////////////////////////////////////
/// Calculate averaged value of psi
///
///\param para Pointer to FFD parameters
///\param psi Pointer to the variable
///
///\return Non-weighted average
///////////////////////////////////////////////////////////////////////////////
REAL average(PARA_DATA *para, REAL *psi) {
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int i, j, k;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL tmp=0;
FOR_EACH_CELL
tmp +=psi[IX(i,j,k)];
END_FOR
return tmp / (imax*jmax*kmax);
}// End of average( )
///////////////////////////////////////////////////////////////////////////////
/// Calculate volume weighted averaged value of psi in a space
///
/// The average is weighted by volume of each cell
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param psi Pointer to the variable
///
///\return Volume weighted average
///////////////////////////////////////////////////////////////////////////////
REAL average_volume(PARA_DATA *para, REAL **var, REAL *psi) {
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int i, j, k;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL tmp1 = 0, tmp2 = 0, tmp3 = 0;
FOR_EACH_CELL
if(var[FLAGP][IX(i,j,k)]==FLUID) {
tmp1 = vol(para, var, i, j, k);
tmp2 += psi[IX(i,j,k)]*tmp1;
tmp3 += tmp1;
}
else
continue;
END_FOR
if(tmp3==0)
return 0;
else
return tmp2 / tmp3;
}// End of average_volume( )
///////////////////////////////////////////////////////////////////////////////
/// Calcuate time averaged value
///
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int average_time(PARA_DATA *para, REAL **var) {
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);
int step = para->mytime->step_mean;
FOR_ALL_CELL
var[VXM][IX(i,j,k)] = var[VXM][IX(i,j,k)] / step;
var[VYM][IX(i,j,k)] = var[VYM][IX(i,j,k)] / step;
var[VZM][IX(i,j,k)] = var[VZM][IX(i,j,k)] / step;
var[TEMPM][IX(i,j,k)] = var[TEMPM][IX(i,j,k)] / step;
END_FOR
// Wall surfaces
for(i=0; i<para->bc->nb_wall; i++)
para->bc->temHeaMean[i] = para->bc->temHeaMean[i] / step;
// Fluid ports
for(i=0; i<para->bc->nb_port; i++) {
para->bc->TPortMean[i] = para->bc->TPortMean[i] / step;
para->bc->velPortMean[i] = para->bc->velPortMean[i] / step;
for(j=0; j<para->bc->nb_Xi; j++)
para->bc->XiPortMean[i][j] = para->bc->XiPortMean[i][j] / step;
for(j=0; j<para->bc->nb_C; j++)
para->bc->CPortMean[i][j] = para->bc->CPortMean[i][j] / step;
}
// Sensor data
para->sens->TRooMean = para->sens->TRooMean / step;
for(i=0; i<para->sens->nb_sensor; i++)
para->sens->senValMean[i] = para->sens->senValMean[i] / step;
return 0;
} // End of average_time()
///////////////////////////////////////////////////////////////////////////////
/// Reset time averaged value to 0
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int reset_time_averaged_data (PARA_DATA *para, REAL **var) {
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);
FOR_ALL_CELL
var[VXM][IX(i,j,k)] = 0;
var[VYM][IX(i,j,k)] = 0;
var[VZM][IX(i,j,k)] = 0;
var[TEMPM][IX(i,j,k)] = 0;
END_FOR
// Wall surfaces
for(i=0; i<para->bc->nb_wall; i++)
para->bc->temHeaMean[i] = 0;
// Fluid ports
for(i=0; i<para->bc->nb_port; i++) {
para->bc->TPortMean[i] = 0;
para->bc->velPortMean[i] = 0;
for(j=0; j<para->bc->nb_Xi; j++)
para->bc->XiPortMean[i][j] = 0;
for(j=0; j<para->bc->nb_C; j++)
para->bc->CPortMean[i][j] = 0;
}
// Sensor data
para->sens->TRooMean = 0;
for(i=0; i<para->sens->nb_sensor; i++)
para->sens->senValMean[i] = 0;
//Reset the time step to 0
para->mytime->step_mean = 0;
return 0;
} // End of reset_time_averaged_data()
///////////////////////////////////////////////////////////////////////////////
/// Add time averaged value for the time average later on
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int add_time_averaged_data(PARA_DATA *para, REAL **var) {
int i, j;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
int size = (imax+2) * (jmax+2) * (kmax+2);
// All the cells
for(i=0; i<size; i++) {
var[VXM][i] += var[VX][i];
var[VYM][i] += var[VY][i];
var[VZM][i] += var[VZ][i];
var[TEMPM][i] += var[TEMP][i];
}
// Wall surfaces
for(i=0; i<para->bc->nb_wall; i++)
para->bc->temHeaMean[i] += para->bc->temHeaAve[i];
// Fluid ports
for(i=0; i<para->bc->nb_port; i++) {
para->bc->TPortMean[i] += para->bc->TPortAve[i];
para->bc->velPortMean[i] += para->bc->velPortAve[i];
for(j=0; j<para->bc->nb_Xi; j++)
para->bc->XiPortMean[i][j] += para->bc->XiPortAve[i][j];
for(j=0; j<para->bc->nb_C; j++)
para->bc->CPortMean[i][j] += para->bc->CPortAve[i][j];
}
// Sensor data
para->sens->TRooMean += para->sens->TRoo;
for(j=0; j<para->sens->nb_sensor; j++)
para->sens->senValMean[j] += para->sens->senVal[j];
// Update the step
para->mytime->step_mean++;
return 0;
} // End of add_time_averaged_data()
///////////////////////////////////////////////////////////////////////////////
/// Check the energy transfer rate through the wall to the air
///
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param BINDEX Pointer to the boudnary index
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
REAL qwall(PARA_DATA *para, REAL **var,int **BINDEX) {
int i, j, k;
int it;
int index=para->geom->index;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *psi=var[TEMP];
REAL *gx = var[GX], *gy = var[GY], *gz = var[GZ];
REAL coeff_h=para->prob->coeff_h;
REAL qwall=0;
REAL *flagp = var[FLAGP];
for(it=0;it<index;it++) {
i=BINDEX[0][it];
j=BINDEX[1][it];
k=BINDEX[2][it];
if(flagp[IX(i,j,k)]==1) {
if(i==0) {
if(flagp[IX(i+1,j,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i+1,j,k)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
}
else if(i==imax+1) {
if(flagp[IX(i-1,j,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i-1,j,k)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
}
else {
if(flagp[IX(i+1,j,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i+1,j,k)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
if(flagp[IX(i-1,j,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i-1,j,k)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
}
if(j==0) {
if(flagp[IX(i,j+1,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j+1,k)])*coeff_h
*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
}
else if(j==jmax+1) {
if(flagp[IX(i,j-1,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j-1,k)])*coeff_h
*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
}
else {
if(flagp[IX(i,j-1,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j-1,k)])*coeff_h
*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
if(flagp[IX(i,j+1,k)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j+1,k)])*coeff_h
*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)])*(gz[IX(i,j,k)]-gz[IX(i,j,k-1)]);
}
}
if(k==0) {
if(flagp[IX(i,j,k+1)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j,k+1)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)]);
}
}
else if(k==kmax+1) {
if(flagp[IX(i,j,k-1)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j,k-1)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)]);
}
}
else {
if(flagp[IX(i,j,k+1)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j,k+1)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)]);
}
if(flagp[IX(i,j,k-1)]<0) {
qwall += (psi[IX(i,j,k)]-psi[IX(i,j,k-1)])*coeff_h
*(gy[IX(i,j,k)]-gy[IX(i,j-1,k)])*(gx[IX(i,j,k)]-gx[IX(i-1,j,k)]);
}
}
}
}
return qwall;
} // End of qwall()
///////////////////////////////////////////////////////////////////////////////
/// Free memory for BINDEX
///
///\param BINDEX Pointer to the boudnary index
///
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
void free_index(int **BINDEX) {
if(BINDEX[0]) free(BINDEX[0]);
if(BINDEX[1]) free(BINDEX[1]);
if(BINDEX[2]) free(BINDEX[2]);
} // End of free_index ()
///////////////////////////////////////////////////////////////////////////////
/// Free memory for FFD simulation variables
///
///\param var Pointer to FFD simulation variables
///
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
void free_data(REAL **var) {
if(var[X]) free(var[X]);
if(var[Y]) free(var[Y]);
if(var[Z]) free(var[Z]);
if(var[VX]) free(var[VX]);
if(var[VY]) free(var[VY]);
if(var[VZ]) free(var[VZ]);
if(var[VXS]) free(var[VXS]);
if(var[VYS]) free(var[VYS]);
if(var[VZS]) free(var[VZS]);
if(var[VXM]) free(var[VXM]);
if(var[VYM]) free(var[VYM]);
if(var[VZM]) free(var[VZM]);
if(var[TEMP]) free(var[TEMP]);
if(var[TEMPM]) free(var[TEMPM]);
if(var[TEMPS]) free(var[TEMPS]);
if(var[IP]) free(var[IP]);
if(var[TMP1]) free(var[TMP1]);
if(var[TMP2]) free(var[TMP2]);
if(var[TMP3]) free(var[TMP3]);
if(var[AP]) free(var[AP]);
if(var[AN]) free(var[AN]);
if(var[AS]) free(var[AS]);
if(var[AE]) free(var[AE]);
if(var[AW]) free(var[AW]);
if(var[AF]) free(var[AF]);
if(var[AB]) free(var[AB]);
if(var[B]) free(var[B]);
if(var[GX]) free(var[GX]);
if(var[GY]) free(var[GY]);
if(var[GZ]) free(var[GZ]);
if(var[AP0]) free(var[AP0]);
if(var[PP]) free(var[PP]);
if(var[FLAGP]) free(var[FLAGP]);
if(var[FLAGU]) free(var[FLAGU]);
if(var[FLAGV]) free(var[FLAGV]);
if(var[FLAGW]) free(var[FLAGW]);
if(var[LOCMIN]) free(var[LOCMIN]);
if(var[LOCMAX]) free(var[LOCMAX]);
if(var[VXBC]) free(var[VXBC]);
if(var[VYBC]) free(var[VYBC]);
if(var[VZBC]) free(var[VZBC]);
if(var[TEMPBC]) free(var[TEMPBC]);
if(var[QFLUXBC]) free(var[QFLUXBC]);
if(var[QFLUX]) free(var[QFLUX]);
} // End of free_data()