1 /*   Program read_bcpnts_unst   */
2 /*
3 Opens an existing CGNS file that contains a simple 3-D
4 unstructured grid + BCs (in PointList+GridLocation=FaceCenter
5 format), and reads the BCs
6 
7 The CGNS grid file 'grid_c.cgns' must already exist
8 (created using write_grid_unst.c), and the BCs must also
9 already have been written (using write_bcpnts_unst.c).  Note: whether the
10 existing CGNS file has a flow solution in it already or
11 not is irrelevant.
12 
13 Example compilation for this program is (change paths if needed!):
14 
15 cc -I ../.. -c read_bcpnts_unst.c
16 cc -o read_bcpnts_unst_c read_bcpnts_unst.o -L ../../lib -lcgns
17 
18 (../../lib is the location where the compiled
19 library libcgns.a is located)
20 */
21 
22 #include <stdio.h>
23 /* cgnslib.h file must be located in directory specified by -I during compile: */
24 #include "cgnslib.h"
25 
26 #if CGNS_VERSION < 3100
27 # define cgsize_t int
28 #endif
29 
30 #define maxpnts 960
31 
main()32 int main()
33 {
34     int index_file,index_base,index_zone,nbocos,ib;
35     int normalindex[3],ndataset;
36     int i,normallist;
37     char boconame[33];
38     CGNS_ENUMT(BCType_t) ibocotype;
39     CGNS_ENUMT(PointSetType_t) iptset;
40     CGNS_ENUMT(DataType_t) normaldatatype;
41     CGNS_ENUMT(GridLocation_t) igr;
42     cgsize_t npts,normallistflag;
43     cgsize_t ipnts[maxpnts];
44 
45 /* READ BOUNDARY CONDITIONS FROM EXISTING CGNS FILE */
46 /* open CGNS file for read-only */
47     if (cg_open("grid_c.cgns",CG_MODE_READ,&index_file)) cg_error_exit();
48 /* we know there is only one base (real working code would check!) */
49     index_base=1;
50 /* we know there is only one zone (real working code would check!) */
51     index_zone=1;
52 /* find out number of BCs that exist under this zone */
53     cg_nbocos(index_file,index_base,index_zone,&nbocos);
54 /* do loop over the total number of BCs */
55     for (ib=1; ib <= nbocos; ib++)
56     {
57 /* find out what BC grid location is (expecting FaceCenter) */
58       cg_goto(index_file,index_base,"Zone_t",1,"ZoneBC_t",1,"BC_t",ib,"end");
59       cg_gridlocation_read(&igr);
60       if (igr == CGNS_ENUMV(FaceCenter))
61       {
62         printf("\nGridLocation=FaceCenter means BC data refers to elements, not nodes\n");
63       }
64 /* get BC info */
65       cg_boco_info(index_file,index_base,index_zone,ib,boconame,&ibocotype,
66                    &iptset,&npts,normalindex,&normallistflag,&normaldatatype,&ndataset);
67       if (iptset != CGNS_ENUMV(PointList))
68       {
69         printf("\nError.  For this program, BCs must be set up as PointList type %s\n",
70             PointSetTypeName[iptset]);
71         return 1;
72       }
73       printf("\nBC number: %i\n",ib);
74       printf("   name= %s\n",boconame);
75       printf("   type= %s\n",BCTypeName[ibocotype]);
76       printf("   no of elements= %i\n",(int)npts);
77       if (npts > maxpnts)
78       {
79         printf("\nError.  Must increase maxpnts to at least %i\n",(int)npts);
80         return 1;
81       }
82 /* read point list in here (nothing done with them in this program) */
83       cg_boco_read(index_file,index_base,index_zone,ib,ipnts,&normallist);
84       printf("      (these elements read here, but only some printed out:)\n");
85       for (i=0; i < 10; i++)
86       {
87         printf("    ipnts[%i]=%i\n",i,(int)ipnts[i]);
88       }
89     }
90 /* close CGNS file */
91     cg_close(index_file);
92     printf("\nSuccessfully read BCs (PointList format) from file grid_c.cgns\n");
93     return 0;
94 }
95