forked from zuowangda/Fast-Fluid-Dynamics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsci_reader.c
704 lines (610 loc) · 21.6 KB
/
sci_reader.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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
///////////////////////////////////////////////////////////////////////////////
//
// Filename: sci_reader.c
//
// Written by: Mingang Jin
//
// Last Modified by: Wangda Zuo on 7/7/2013
//
//Task: read mesh and simulation data defined by SCI with a file extension
// name ".cfd".
//
///////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "data_structure.h"
#include "ffd_data_reader.h"
#include "utility.h"
FILE *file_params;
/******************************************************************************
| Read the information for dimension and number of meshes
******************************************************************************/
int read_sci_max(PARA_DATA *para, REAL **var)
{
char string[400];
// Open the file
if((file_params=fopen(para->inpu->parameter_file_name,"r")) == NULL)
{
fprintf(stderr,"Error:can not open the file \"%s\".\n", para->inpu->parameter_file_name);
return 1;
}
// Get the first line for the length in X, Y and Z directions
fgets(string, 400, file_params);
sscanf(string,"%f %f %f", ¶->geom->Lx, ¶->geom->Ly, ¶->geom->Lz);
// Get the second line for the number of cells in X, Y and Z directions
fgets(string, 400, file_params);
sscanf(string,"%d %d %d", ¶->geom->imax, ¶->geom->jmax, ¶->geom->kmax);
fclose(file_params);
return 0;
} // End of read_sci_max()
/******************************************************************************
| Read the parameters from a file generated by SCI
******************************************************************************/
int read_sci_input(PARA_DATA *para, REAL **var, int **BINDEX)
{
int i, j, k;
int ii,ij,ik;
REAL tempx, tempy, tempz;
REAL Lx = para->geom->Lx;
REAL Ly = para->geom->Ly;
REAL Lz = para->geom->Lz;
REAL *gx = var[GX], *gy = var[GY], *gz = var[GZ];
REAL *x = var[X], *y = var[Y], *z = var[Z];
int IWWALL,IEWALL,ISWALL,INWALL,IBWALL,ITWALL;
int SI,SJ,SK,EI,EJ,EK,FLTMP;
REAL TMP,MASS,U,V,W;
REAL trefmax;
char name[100];
int imax = para->geom->imax;
int jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int index=0;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
char *temp, string[400];
REAL *delx,*dely,*delz;
REAL *flagp = var[FLAGP],*flagu = var[FLAGU],*flagv = var[FLAGV],*flagw = var[FLAGW];
char msg[200], tmp[50];
int bcnameid = -1;
// Open the parameter file
if((file_params=fopen(para->inpu->parameter_file_name,"r")) == NULL )
{
fprintf(stderr,"Error:can not open the file \"%s\"\n.", para->inpu->parameter_file_name);
return 1;
}
sprintf(msg, "sci_reader.c: Start to read sci input file %s", para->inpu->parameter_file_name);
ffd_log(msg, FFD_NORMAL);
// Ingore the first and second lines
temp = fgets(string, 400, file_params);
temp = fgets(string, 400, file_params);
/*---------------------------------------------------------------------------
| Convert the cell dimensions defined by SCI to coordinates in FFD
----------------------------------------------------------------------------*/
// Allocate temporary memory for diemension of each cell
delx = (REAL *) malloc ((imax+2)*sizeof(REAL));
dely = (REAL *) malloc ((jmax+2)*sizeof(REAL));
delz = (REAL *) malloc ((kmax+2)*sizeof(REAL));
if( !delx || !dely ||!delz )
{
fprintf ( stderr, "Cannot allocate memory for delx, dely or delz in read_sci_input()\n");
return 1;
}
delx[0]=0;
dely[0]=0;
delz[0]=0;
// Read cell dimensions in X, Y, Z directions
for(i=1; i<=imax; i++) fscanf(file_params, "%f", &delx[i]);
fscanf(file_params,"\n");
for(j=1; j<=jmax; j++) fscanf(file_params, "%f", &dely[j]);
fscanf(file_params,"\n");
for(k=1; k<=kmax; k++) fscanf(file_params, "%f", &delz[k]);
fscanf(file_params,"\n");
// Store the locations of grid cell surfaces
// Fixme: use one "temp", not tempx tempy and tempz
tempx = 0.0; tempy = 0.0; tempz = 0.0;
for(i=0; i<=imax+1; i++)
{
tempx += delx[i];
if(i>=imax) tempx = Lx;
for(j=0; j<=jmax+1; j++)
for(k=0; k<=kmax+1; k++) var[GX][IX(i,j,k)]=tempx;
}
for(j=0; j<=jmax+1; j++)
{
tempy += dely[j];
if(j>=jmax) tempy = Ly;
for(i=0; i<=imax+1; i++)
for(k=0; k<=kmax+1; k++) var[GY][IX(i,j,k)] = tempy;
}
for(k=0; k<=kmax+1; k++)
{
tempz += delz[k];
if(k>=kmax) tempz = Lz;
for(i=0; i<=imax+1; i++)
for(j=0; j<=jmax+1; j++) var[GZ][IX(i,j,k)] = tempz;
}
// Convert the coordinates for cell furfaces to the coordinates for the cell center
FOR_ALL_CELL
if(i<1)
x[IX(i,j,k)] = 0;
else if(i>imax)
x[IX(i,j,k)] = Lx;
else
x[IX(i,j,k)] = 0.5 * (gx[IX(i,j,k)]+gx[IX(i-1,j,k)]);
if(j<1)
y[IX(i,j,k)] = 0;
else if(j>jmax)
y[IX(i,j,k)] = Ly;
else
y[IX(i,j,k)] = 0.5 * (gy[IX(i,j,k)]+gy[IX(i,j-1,k)]);
if(k<1)
z[IX(i,j,k)] = 0;
else if(k>kmax)
z[IX(i,j,k)] = Lz;
else
z[IX(i,j,k)] = 0.5 * (gz[IX(i,j,k)]+gz[IX(i,j,k-1)]);
END_FOR
// Get the wall property
fgets(string, 400, file_params);
sscanf(string,"%d%d%d%d%d%d",&IWWALL,&IEWALL,&ISWALL,&INWALL,&IBWALL,&ITWALL);
/*---------------------------------------------------------------------------
| Read total number of boundary conditions
----------------------------------------------------------------------------*/
fgets(string, 400, file_params);
sscanf(string,"%d", ¶->bc->nb_bc);
sprintf(msg, "sci_reader.c: para->bc->nb_bc=%d", para->bc->nb_bc);
ffd_log(msg, FFD_NORMAL);
// Allocate the memory for bC name array
para->bc->bcname = (char**)malloc(para->bc->nb_bc * sizeof(char*));
/*---------------------------------------------------------------------------
| Read the inlet boundary conditions
----------------------------------------------------------------------------*/
// Get number of inlet boundaries
fgets(string, 400, file_params);
sscanf(string,"%d",¶->bc->nb_inlet);
sprintf(msg, "sci_reader.c: para->bc->nb_inlet=%d", para->bc->nb_inlet);
ffd_log(msg, FFD_NORMAL);
index=0;
// Setting inlet boundary
if(para->bc->nb_inlet != 0)
{
// Loop for each inlet boundary
for(i=1;i<=para->bc->nb_inlet;i++)
{
fgets(string, 400, file_params);
sscanf(string,"%s%d%d%d%d%d%d%f%f%f%f%f", name, &SI, &SJ, &SK, &EI, &EJ, &EK,
&TMP, &MASS, &U, &V, &W);
bcnameid ++; // starts from -1, thus the first id will be 0
para->bc->bcname[bcnameid] = (char*)malloc(sizeof(name));
strcpy(para->bc->bcname[bcnameid], name);
sprintf(msg, "sci_reader.c: para->bc->bcname[%d]=%s", bcnameid, para->bc->bcname[bcnameid]);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: VX=%f, VY=%f, VX=%f, T=%f, Xi=%f",
U, V, W, TMP, MASS);
ffd_log(msg, FFD_NORMAL);
if(EI==0)
{
if(SI==1) SI = 0;
EI = SI + EI;
EJ = SJ + EJ - 1;
EK = SK + EK - 1;
}
if(EJ==0)
{
if(SJ==1) SJ = 0;
EI = SI + EI - 1;
EJ = SJ + EJ;
EK = SK + EK - 1;
}
if(EK==0)
{
if(SK==1) SK = 0;
EI = SI + EI - 1;
EJ = SJ + EJ - 1;
EK = SK + EK;
}
// Assign the inlet boundary condition for each cell
for(ii=SI; ii<=EI; ii++)
for(ij=SJ; ij<=EJ; ij++)
for(ik=SK; ik<=EK; ik++)
{
BINDEX[0][index] = ii;
BINDEX[1][index] = ij;
BINDEX[2][index] = ik;
BINDEX[4][index] = bcnameid;
index++;
var[TEMPBC][IX(ii,ij,ik)] = TMP;
var[VXBC][IX(ii,ij,ik)] = U;
var[VYBC][IX(ii,ij,ik)] = V;
var[VZBC][IX(ii,ij,ik)] = W;
flagp[IX(ii,ij,ik)] = 0; // Cell flag to be inlet
} // End of assigning the inlet B.C. for each cell
} // End of loop for each inlet boundary
} // End of setting inlet boundary
if(para->outp->version == DEBUG)
printf("Last index of inlet B.C. cell: %d\n", index);
/*---------------------------------------------------------------------------
| Read the outlet boundary conditions
----------------------------------------------------------------------------*/
fgets(string, 400, file_params);
sscanf(string,"%d",¶->bc->nb_outlet);
sprintf(msg, "sci_reader.c: para->bc->nb_outlet=%d", para->bc->nb_outlet);
ffd_log(msg, FFD_NORMAL);
if(para->bc->nb_outlet!=0)
{
for(i=1;i<=para->bc->nb_outlet;i++)
{
fgets(string, 400, file_params);
sscanf(string,"%s%d%d%d%d%d%d%f%f%f%f%f", &name, &SI, &SJ, &SK, &EI,
&EJ, &EK, &TMP, &MASS, &U, &V, &W);
bcnameid++;
para->bc->bcname[bcnameid] = (char*)malloc(sizeof(name));
strcpy(para->bc->bcname[bcnameid], name);
sprintf(msg, "sci_reader.c: para->bc->bcname[%d]=%s", bcnameid, para->bc->bcname[bcnameid]);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: VX=%f, VY=%f, VX=%f, T=%f, Xi=%f",
U, V, W, TMP, MASS);
ffd_log(msg, FFD_NORMAL);
if(EI==0)
{
if(SI==1) SI=0;
EI = SI + EI;
EJ = SJ + EJ - 1;
EK = SK + EK - 1;
}
if(EJ==0)
{
if(SJ==1) SJ=0;
EI = SI+EI-1;
EJ = SJ+EJ;
EK = SK+EK-1;
}
if(EK==0)
{
if(SK==1) SK = 0;
EI = SI+EI-1;
EJ = SJ+EJ-1;
EK = SK+EK;
}
// Assign the outlet boundary condition for each cell
for(ii=SI; ii<=EI ;ii++)
for(ij=SJ; ij<=EJ ;ij++)
for(ik=SK; ik<=EK; ik++)
{
BINDEX[0][index] = ii;
BINDEX[1][index] = ij;
BINDEX[2][index] = ik;
BINDEX[4][index] = bcnameid;
index++;
// Fixme: Why assign TMP, U, V, W for oulet B.C?
var[TEMPBC][IX(ii,ij,ik)] = TMP;
var[VXBC][IX(ii,ij,ik)] = U;
var[VYBC][IX(ii,ij,ik)] = V;
var[VZBC][IX(ii,ij,ik)] = W;
flagp[IX(ii,ij,ik)] = 2;
} // End of assigning the outlet B.C. for each cell
} // End of loop for each outlet boundary
} // End of setting outlet boundary
/*---------------------------------------------------------------------------
| Read the internal solid block boundary conditions
----------------------------------------------------------------------------*/
fgets(string, 400, file_params);
sscanf(string, "%d", ¶->bc->nb_block);
sprintf(msg, "sci_reader.c: para->bc->nb_block=%d", para->bc->nb_block);
ffd_log(msg, FFD_NORMAL);
if(para->bc->nb_block!=0)
{
for(i=1; i<=para->bc->nb_block; i++)
{
fgets(string, 400, file_params);
// X_index_start, Y_index_Start, Z_index_Start,
// X_index_End, Y_index_End, Z_index_End,
// Thermal Codition (0: Flux; 1:Temperature), Value of thermal conditon
sscanf(string,"%s%d%d%d%d%d%d%d%f", &name, &SI, &SJ, &SK, &EI, &EJ, &EK,
&FLTMP, &TMP);
bcnameid++;
para->bc->bcname[bcnameid] = (char*)malloc(sizeof(name));
strcpy(para->bc->bcname[bcnameid], name);
sprintf(msg, "sci_reader.c: para->bc->bcname[%d]=%s", bcnameid, para->bc->bcname[bcnameid]);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: VX=%f, VY=%f, VX=%f, ThermalBC=%d, T/q_dot=%f, Xi=%f",
U, V, W, FLTMP, TMP, MASS);
ffd_log(msg, FFD_NORMAL);
if(SI==1)
{
SI=0;
if(EI>=imax) EI=EI+SI+1;
else EI=EI+SI;
}
else
EI=EI+SI-1;
if(SJ==1)
{
SJ=0;
if(EJ>=jmax) EJ=EJ+SJ+1;
else EJ=EJ+SJ;
}
else
EJ=EJ+SJ-1;
if(SK==1)
{
SK=0;
if(EK>=kmax) EK=EK+SK+1;
else EK=EK+SK;
}
else
EK=EK+SK-1;
for(ii=SI ;ii<=EI ;ii++)
for(ij=SJ ;ij<=EJ ;ij++)
for(ik=SK ;ik<=EK ;ik++)
{
BINDEX[0][index] = ii;
BINDEX[1][index] = ij;
BINDEX[2][index] = ik;
BINDEX[3][index] = FLTMP;
BINDEX[4][index] = bcnameid;
index++;
if(FLTMP==1) var[TEMPBC][IX(ii,ij,ik)] = TMP;
if(FLTMP==0) var[QFLUXBC][IX(ii,ij,ik)] = TMP;
flagp[IX(ii,ij,ik)] = 1; // Flag for solid
} // End of assigning value for internal solid block
}
}
/*---------------------------------------------------------------------------
| Read the wall boundary conditions
----------------------------------------------------------------------------*/
fgets(string, 400, file_params);
sscanf(string,"%d", ¶->bc->nb_wall);
sprintf(msg, "sci_reader.c: para->bc->nb_wall=%d", para->bc->nb_wall);
ffd_log(msg, FFD_NORMAL);
if(para->bc->nb_wall!=0)
{
// Read wall conditions for each wall
for(i=1;i<=para->bc->nb_wall;i++)
{
fgets(string, 400, file_params);
// X_index_start, Y_index_Start, Z_index_Start,
// X_index_End, Y_index_End, Z_index_End,
// Thermal Codition (0: Flux; 1:Temperature), Value of thermal conditon
sscanf(string,"%s%d%d%d%d%d%d%d%f", &name, &SI, &SJ, &SK, &EI, &EJ, &EK,
&FLTMP, &TMP);
bcnameid++;
para->bc->bcname[bcnameid] = (char*)malloc(sizeof(name));
strcpy(para->bc->bcname[bcnameid], name);
sprintf(msg, "sci_reader.c: para->bc->bcname[%d]=%s", bcnameid, para->bc->bcname[bcnameid]);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: VX=%f, VY=%f, VX=%f, ThermalBC=%d, T/q_dot=%f, Xi=%f",
U, V, W, FLTMP, TMP, MASS);
ffd_log(msg, FFD_NORMAL);
// Reset X index
if(SI==1)
{
SI = 0;
if(EI>=imax) EI = EI + 1;
}
else //
EI = EI + SI;
// Reset Y index
if(SJ==1)
{
SJ = 0;
if(EJ>=jmax) EJ = EJ + 1;
}
else
EJ = EJ + SJ;
// Reset Z index
if(SK==1)
{
SK = 0;
if(EK>=kmax) EK = EK + 1;
}
else
EK = EK + SK;
// Assign value for each wall cell
for(ii=SI; ii<=EI; ii++)
for(ij=SJ; ij<=EJ; ij++)
for(ik=SK; ik<=EK; ik++)
{
// If cell hasn't been updated (default value -1)
if(flagp[IX(ii,ij,ik)]<0)
{
BINDEX[0][index] = ii;
BINDEX[1][index] = ij;
BINDEX[2][index] = ik;
// Define the thermal boundary property
BINDEX[3][index] = FLTMP;
BINDEX[4][index] = bcnameid;
index++;
// Set the cell to solid
flagp[IX(ii,ij,ik)] = 1;
if(FLTMP==1) var[TEMPBC][IX(ii,ij,ik)] = TMP;
if(FLTMP==0) var[QFLUXBC][IX(ii,ij,ik)] = TMP;
}
} // End of assigning value for each wall cell
} // End of assigning value for each wall surface
} // End of assigning value for wall boundary
/*---------------------------------------------------------------------------
| Read the boundary conditions for contanmiant source
| Fixme: The data is ignored in current version
----------------------------------------------------------------------------*/
fgets(string, 400, file_params);
sscanf(string,"%d", ¶->bc->nb_source);
sprintf(msg, "sci_reader.c: para->bc->nb_source=%d", para->bc->nb_source);
ffd_log(msg, FFD_NORMAL);
if(para->bc->nb_source!=0)
{
sscanf(string,"%s%d%d%d%d%d%d%f", &name, &SI, &SJ, &SK, &EI, &EJ, &EK,
&MASS);
bcnameid++;
para->bc->bcname[bcnameid] = (char*)malloc(sizeof(name));
strcpy(para->bc->bcname[bcnameid], name);
sprintf(msg, "sci_reader.c: para->bc->bcname[%d]=%s", bcnameid, para->bc->bcname[bcnameid]);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: Xi_dot=%f", MASS);
ffd_log(msg, FFD_NORMAL);
// Fixme:Need to add code to assign the BC value as other part does
}
para->geom->index=index;
// Discard the unused data
temp = fgets(string, 400, file_params); //maximum iteration
temp = fgets(string, 400, file_params); //convergence rate
temp = fgets(string, 400, file_params); //Turbulence model
temp = fgets(string, 400, file_params); //initial value
temp = fgets(string, 400, file_params); //minimum value
temp = fgets(string, 400, file_params); //maximum value
temp = fgets(string, 400, file_params); //fts value
temp = fgets(string, 400, file_params); //under relaxation
temp = fgets(string, 400, file_params); //reference point
temp = fgets(string, 400, file_params); //monitering point
// Read setting for restarting the old FFD simulation
fgets(string, 400, file_params);
sscanf(string,"%d",¶->inpu->read_old_ffd_file);
sprintf(msg, "sci_reader.c: para->inpu->read_old_ffd_file=%d", para->inpu->read_old_ffd_file);
ffd_log(msg, FFD_NORMAL);
// Discard the unused data
temp = fgets(string, 400, file_params); //print frequency
temp = fgets(string, 400, file_params); //Pressure variable Y/N
temp = fgets(string, 400, file_params); //Steady state, buoyancy.
// Read pysical properties
fgets(string, 400, file_params);
sscanf(string,"%f %f %f %f %f %f %f %f %f", ¶->prob->rho,
¶->prob->nu, ¶->prob->cond,
¶->prob->gravx, ¶->prob->gravy, ¶->prob->gravz,
¶->prob->beta, &trefmax, ¶->prob->Cp);
sprintf(msg, "sci_reader.c: para->prob->rho=%f", para->prob->rho);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->prob->nu=%f", para->prob->nu);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->prob->cond=%f", para->prob->cond);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->prob->gravx=%f", para->prob->gravx);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->prob->gravy=%f", para->prob->gravy);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->prob->gravz=%f", para->prob->gravz);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->prob->beta=%f", para->prob->beta);
ffd_log(msg, FFD_NORMAL);
//para->prob->trefmax=trefmax;
sprintf(msg, "sci_reader.c: para->prob->Cp=%f", para->prob->Cp);
ffd_log(msg, FFD_NORMAL);
// Read simulation time settings
fgets(string, 400, file_params);
sscanf(string,"%f %f %d", ¶->mytime->t_start, ¶->mytime->dt,
¶->mytime->step_total);
sprintf(msg, "sci_reader.c: para->mytime->t_start=%f",
para->mytime->t_start);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->mytime->dt=%f", para->mytime->dt);
ffd_log(msg, FFD_NORMAL);
sprintf(msg, "sci_reader.c: para->mytime->step_total=%d",
para->mytime->step_total);
ffd_log(msg, FFD_NORMAL);
temp = fgets(string, 400, file_params); //prandtl
fclose(file_params);
free(delx);
free(dely);
free(delz);
sprintf(msg, "sci_reader.c: End of reading sci input file %s", para->inpu->parameter_file_name);
ffd_log(msg, FFD_NORMAL);
return 0;
} // End of read_sci_input()
int read_sci_zeroone(PARA_DATA *para, REAL **var, int **BINDEX)
{
int i,j, k;
int delcount=0;
int mark;
int imax = para->geom->imax;
int jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int index = para->geom->index;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *flagp = var[FLAGP],*flagu = var[FLAGU],*flagv = var[FLAGV],*flagw = var[FLAGW];
char msg[100];
if( (file_params=fopen("zeroone.dat","r")) == NULL )
{
ffd_log("sci_reader.c:can not open file zeroone.dat!\n", FFD_ERROR);
return 1;
}
sprintf(msg, "sci_reader.c: start to read zeroone.dat.");
ffd_log(msg, FFD_NORMAL);
for(k=1;k<=kmax;k++)
for(j=1;j<=jmax;j++)
for(i=1;i<=imax;i++)
{
fscanf(file_params,"%d" ,&mark);
if(mark==1)
{
flagp[IX(i,j,k)]=1;
BINDEX[0][index]=i;
BINDEX[1][index]=j;
BINDEX[2][index]=k;
index++;
}
delcount++;
if(delcount==25)
{
fscanf(file_params,"\n");
delcount=0;
}
}
fclose(file_params);
para->geom->index=index;
sprintf(msg, "sci_reader.c: end of reading zeroone.dat.");
ffd_log(msg, FFD_NORMAL);
return 0;
} // End of read_sci_zeroone()
void mark_cell(PARA_DATA *para, REAL **var)
{
int i,j, k;
int imax = para->geom->imax;
int jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int index = para->geom->index;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
REAL *flagp = var[FLAGP],*flagu = var[FLAGU],*flagv = var[FLAGV],*flagw = var[FLAGW];
flagp[IX(0,0,0)]=1;
flagp[IX(0,0,kmax+1)]=1;
flagp[IX(0,jmax+1,0)]=1;
flagp[IX(0,jmax+1,kmax+1)]=1;
flagp[IX(imax+1,0,0)]=1;
flagp[IX(imax+1,0,kmax+1)]=1;
flagp[IX(imax+1,jmax+1,0)]=1;
flagp[IX(imax+1,jmax+1,kmax+1)]=1;
FOR_EACH_CELL
if(flagp[IX(i,j,k)]>=0) continue;
if ( flagp[IX(i-1,j,k)]>=0 && flagp[IX(i+1,j,k)]>=0 &&
flagp[IX(i,j-1,k)]>=0 && flagp[IX(i,j+1,k)]>=0 &&
flagp[IX(i,j,k-1)]>=0 && flagp[IX(i,j,k+1)]>=0 )
flagp[IX(i,j,k)]=1;
END_FOR
FOR_ALL_CELL
if(flagp[IX(i,j,k)]==1)
{
flagu[IX(i,j,k)]=1;
flagv[IX(i,j,k)]=1;
flagw[IX(i,j,k)]=1;
if(i!=0) flagu[IX(i-1,j,k)]=1;
if(j!=0) flagv[IX(i,j-1,k)]=1;
if(k!=0) flagw[IX(i,j,k-1)]=1;
}
if(flagp[IX(i,j,k)]==0)
{
flagu[IX(i,j,k)]=0;
flagv[IX(i,j,k)]=0;
flagw[IX(i,j,k)]=0;
if(i!=0) flagu[IX(i-1,j,k)]=0;
if(j!=0) flagv[IX(i,j-1,k)]=0;
if(k!=0) flagw[IX(i,j,k-1)]=0;
}
if(flagp[IX(i,j,k)]==2)
{
flagu[IX(i,j,k)]=2;
flagv[IX(i,j,k)]=2;
flagw[IX(i,j,k)]=2;
if(i!=0) flagu[IX(i-1,j,k)]=2;
if(j!=0) flagv[IX(i,j-1,k)]=2;
if(k!=0) flagw[IX(i,j,k-1)]=2;
}
END_FOR
}