1 /*   Program read_floweqn_str   */
2 /*
3 Opens an existing CGNS file and reads flow equation info
4 
5 The CGNS grid file 'grid_c.cgns' must already exist
6 (created using write_grid_str.c followed by write_floweqn_str.c)
7 
8 Example compilation for this program is (change paths if needed!):
9 
10 cc -I ../.. -c read_floweqn_str.c
11 cc -o read_floweqn_str_c read_floweqn_str.o -L ../../lib -lcgns
12 
13 (../../lib is the location where the compiled
14 library libcgns.a is located)
15 */
16 
17 #include <stdio.h>
18 /* cgnslib.h file must be located in directory specified by -I during compile: */
19 #include "cgnslib.h"
20 
21 #if CGNS_VERSION < 3100
22 # define cgsize_t int
23 #endif
24 
main()25 int main()
26 {
27     int idata[6];
28     int index_file,index_base,index_zone;
29     int id,ige,igm,ivm,itcm,itc,itm;
30     float gamma,prandtl;
31     CGNS_ENUMT(GoverningEquationsType_t) itype;
32     CGNS_ENUMT(ModelType_t) mtype;
33 
34 /* READ FLOW EQUATION SET INFO */
35 /* open CGNS file for read-only */
36     if (cg_open("grid_c.cgns",CG_MODE_READ,&index_file)) cg_error_exit();
37 /* we know there is only one base (real working code would check!) */
38     index_base=1;
39 /* we know there is only one zone (real working code would check!) */
40     index_zone=1;
41 /* existing file must be 3D structured (real working code would check!) */
42 /* Read info from 'FlowEquationSet' node under 'Zone_t' */
43     cg_goto(index_file,index_base,"Zone_t",index_zone,"end");
44     if (cg_equationset_read(&id,&ige,&igm,&ivm,&itcm,&itc,&itm))
45     {
46       printf("\nError!  FlowEquationSet node does not exist.\n");
47       return 1;
48     }
49     printf("\nEqn dimension = %i\n",id);
50 /* Read 'GoverningEquations' node */
51     if (ige == 1)
52     {
53       cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowEquationSet_t",1,"end");
54       cg_governing_read(&itype);
55       printf(" Gov eqn = %s\n",GoverningEquationsTypeName[itype]);
56 /* Read 'DiffusionModel' node */
57       cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowEquationSet_t",1, \
58               "GoverningEquations_t",1,"end");
59       cg_diffusion_read(idata);
60       printf("     diffusion= %i, %i, %i, %i, %i, %i\n",idata[0],idata[1], \
61              idata[2],idata[3],idata[4],idata[5]);
62     }
63 /* Read gas model */
64     if (igm == 1)
65     {
66       cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowEquationSet_t",1,"end");
67       cg_model_read("GasModel_t",&mtype);
68       printf(" Gas model type = %s\n",ModelTypeName[mtype]);
69       cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowEquationSet_t",1, \
70               "GasModel_t",1,"end");
71       cg_array_read_as(1,CGNS_ENUMV(RealSingle),&gamma);
72       printf("     gamma = %f\n",gamma);
73     }
74 /* Read turbulence closure */
75     if (itc == 1)
76     {
77       cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowEquationSet_t",1,"end");
78       cg_model_read("TurbulenceClosure_t",&mtype);
79       printf(" Turbulence closure type = %s\n",ModelTypeName[mtype]);
80       cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowEquationSet_t",1, \
81               "TurbulenceClosure_t",1,"end");
82       cg_array_read_as(1,CGNS_ENUMV(RealSingle),&prandtl);
83       printf("     turb prandtl number = %f\n",prandtl);
84     }
85     if (itm == 1)
86     {
87       cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowEquationSet_t",1,"end");
88       cg_model_read("TurbulenceModel_t",&mtype);
89       printf(" Turbulence model type = %s\n",ModelTypeName[mtype]);
90     }
91 /* close CGNS file */
92     cg_close(index_file);
93     printf("\nSuccessfully read equation set info from file grid_c.cgns\n");
94     return 0;
95 }
96