00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #if defined(_WIN32) && !defined(__NUTC__)
00004 # include <io.h>
00005 #else
00006 # include <unistd.h>
00007 #endif
00008 #include "cgnslib.h"
00009
00010 static float xc[27], yc[27], zc[27];
00011
00012 static int node[1] = {1};
00013 static int bar[3] = {1, 3, 2};
00014 static int tri[6] = {1, 3, 7, 2, 5, 4};
00015 static int quad[9] = {1, 3, 9, 7, 2, 6, 8, 4, 5};
00016 static int tetra[10] = {1, 3, 7, 19, 2, 5, 4, 10, 11, 13};
00017 static int pyra[14] = {1, 3, 9, 7, 19, 2, 6, 8, 4, 10, 11, 14, 13, 5};
00018 static int penta[18] = {1, 3, 7, 19, 21, 25, 2, 5, 4, 10, 12, 16, 20, 23, 22, 11, 14, 13};
00019 static int hexa[27] = {1, 3, 9, 7, 19, 21, 27, 25, 2, 6, 8, 4, 10, 12, 18, 16,
00020 20, 24, 26, 22, 5, 11, 15, 17, 13, 23, 14};
00021
00022 static int npoly = 16;
00023 static int poly[80] = {6, 1, 2, 12, 21, 20, 10,
00024 3, 2, 3, 12,
00025 3, 10, 20, 19,
00026 6, 4, 13, 23, 24, 15, 5,
00027 3, 5, 15, 6,
00028 3, 13, 23, 12,
00029 4, 1, 4, 5, 2,
00030 4, 2, 5, 15, 12,
00031 4, 12, 15, 24, 21,
00032 4, 21, 24, 23, 20,
00033 4, 20, 23, 13, 10,
00034 4, 10, 13, 4, 1,
00035 4, 2, 5, 6, 3,
00036 4, 3, 6, 15, 12,
00037 4, 13, 10, 19, 22,
00038 4, 22, 19, 20, 24};
00039 static int nface = 3;
00040 static int face[21] = {8, 1, 4, 7, 8, 9, 10, 11, 12,
00041 5, 2, 5, 8, 13, 14,
00042 5, 3, 6, 11, 15, 16};
00043
00044 static int elems[256];
00045
00046 int main (int argc, char *argv[])
00047 {
00048 int i, j, k, n, ne;
00049 int fnum, bnum, znum, snum, cnum;
00050 int size[3];
00051 ElementType_t type;
00052 char *outfile = "elemtest.cgns";
00053
00054 for (i = 0, n = 0; n < NofValidElementTypes; n++) {
00055 type = (ElementType_t)n;
00056 if (type >= TETRA_4 && type <= HEXA_27)
00057 i++;
00058 }
00059 size[0] = 27;
00060 size[1] = i << 1;
00061 size[2] = 0;
00062 #if CGNS_VERSION >= 3000
00063 size[1] += nface;
00064 #endif
00065
00066 for (n = 0, k = 0; k < 3; k++) {
00067 for (j = 0; j < 3; j++) {
00068 for (i = 0; i < 3; i++) {
00069 xc[n] = (float)i;
00070 yc[n] = (float)j;
00071 zc[n] = (float)k;
00072 n++;
00073 }
00074 }
00075 }
00076
00077 unlink (outfile);
00078
00079
00080 if (cg_open (outfile, CG_MODE_WRITE, &fnum) ||
00081 cg_base_write (fnum, "Base", 3, 3, &bnum) ||
00082 cg_zone_write (fnum, bnum, "Zone", size, Unstructured, &znum) ||
00083 cg_coord_write (fnum, bnum, znum, RealSingle, "CoordinateX", xc, &cnum) ||
00084 cg_coord_write (fnum, bnum, znum, RealSingle, "CoordinateY", yc, &cnum) ||
00085 cg_coord_write (fnum, bnum, znum, RealSingle, "CoordinateZ", zc, &cnum))
00086 cg_error_exit ();
00087
00088 ne = j = 0;
00089
00090
00091
00092 if (cg_section_write (fnum, bnum, znum, "NODE", NODE,
00093 ne+1, ne+1, 0, node, &snum))
00094 cg_error_exit ();
00095 ne++;
00096
00097 elems[j++] = (int)NODE;
00098 elems[j++] = node[0];
00099
00100
00101
00102 if (cg_section_write (fnum, bnum, znum, "BAR_2", BAR_2,
00103 ne+1, ne+1, 0, bar, &snum) ||
00104 cg_section_write (fnum, bnum, znum, "BAR_3", BAR_3,
00105 ne+2, ne+2, 0, bar, &snum))
00106 cg_error_exit ();
00107 ne += 2;
00108
00109 elems[j++] = (int)BAR_2;
00110 for (n = 0; n < 2; n++)
00111 elems[j++] = bar[n];
00112 elems[j++] = (int)BAR_3;
00113 for (n = 0; n < 3; n++)
00114 elems[j++] = bar[n];
00115
00116
00117
00118 if (cg_section_write (fnum, bnum, znum, "TRI_3", TRI_3,
00119 ne+1, ne+1, 0, tri, &snum) ||
00120 cg_section_write (fnum, bnum, znum, "TRI_6", TRI_6,
00121 ne+2, ne+2, 0, tri, &snum))
00122 cg_error_exit ();
00123 ne += 2;
00124
00125 elems[j++] = (int)TRI_3;
00126 for (n = 0; n < 3; n++)
00127 elems[j++] = tri[n];
00128 elems[j++] = (int)TRI_6;
00129 for (n = 0; n < 6; n++)
00130 elems[j++] = tri[n];
00131
00132
00133
00134 if (cg_section_write (fnum, bnum, znum, "QUAD_4", QUAD_4,
00135 ne+1, ne+1, 0, quad, &snum) ||
00136 cg_section_write (fnum, bnum, znum, "QUAD_8", QUAD_8,
00137 ne+2, ne+2, 0, quad, &snum) ||
00138 cg_section_write (fnum, bnum, znum, "QUAD_9", QUAD_9,
00139 ne+3, ne+3, 0, quad, &snum))
00140 cg_error_exit ();
00141 ne += 3;
00142
00143 elems[j++] = (int)QUAD_4;
00144 for (n = 0; n < 4; n++)
00145 elems[j++] = quad[n];
00146 elems[j++] = (int)QUAD_8;
00147 for (n = 0; n < 8; n++)
00148 elems[j++] = quad[n];
00149 elems[j++] = (int)QUAD_9;
00150 for (n = 0; n < 9; n++)
00151 elems[j++] = quad[n];
00152
00153
00154
00155 if (cg_section_write (fnum, bnum, znum, "TETRA_4", TETRA_4,
00156 ne+1, ne+1, 0, tetra, &snum) ||
00157 cg_section_write (fnum, bnum, znum, "TETRA_10", TETRA_10,
00158 ne+2, ne+2, 0, tetra, &snum))
00159 cg_error_exit ();
00160 ne += 2;
00161
00162 elems[j++] = (int)TETRA_4;
00163 for (n = 0; n < 4; n++)
00164 elems[j++] = tetra[n];
00165 elems[j++] = (int)TETRA_10;
00166 for (n = 0; n < 10; n++)
00167 elems[j++] = tetra[n];
00168
00169
00170
00171 if (cg_section_write (fnum, bnum, znum, "PYRA_5", PYRA_5,
00172 ne+1, ne+1, 0, pyra, &snum) ||
00173 cg_section_write (fnum, bnum, znum, "PYRA_14", PYRA_14,
00174 ne+2, ne+2, 0, pyra, &snum))
00175 cg_error_exit ();
00176 ne += 2;
00177
00178 elems[j++] = (int)PYRA_5;
00179 for (n = 0; n < 5; n++)
00180 elems[j++] = pyra[n];
00181 elems[j++] = (int)PYRA_14;
00182 for (n = 0; n < 14; n++)
00183 elems[j++] = pyra[n];
00184
00185 #if CGNS_VERSION >= 3000
00186 if (cg_section_write (fnum, bnum, znum, "PYRA_13", PYRA_13,
00187 ne+1, ne+1, 0, pyra, &snum))
00188 cg_error_exit ();
00189 ne++;
00190
00191 elems[j++] = (int)PYRA_13;
00192 for (n = 0; n < 13; n++)
00193 elems[j++] = pyra[n];
00194 #endif
00195
00196
00197
00198 if (cg_section_write (fnum, bnum, znum, "PENTA_6", PENTA_6,
00199 ne+1, ne+1, 0, penta, &snum) ||
00200 cg_section_write (fnum, bnum, znum, "PENTA_15", PENTA_15,
00201 ne+2, ne+2, 0, penta, &snum) ||
00202 cg_section_write (fnum, bnum, znum, "PENTA_18", PENTA_18,
00203 ne+3, ne+3, 0, penta, &snum))
00204 cg_error_exit ();
00205 ne += 3;
00206
00207 elems[j++] = (int)PENTA_6;
00208 for (n = 0; n < 6; n++)
00209 elems[j++] = penta[n];
00210 elems[j++] = (int)PENTA_15;
00211 for (n = 0; n < 15; n++)
00212 elems[j++] = penta[n];
00213 elems[j++] = (int)PENTA_18;
00214 for (n = 0; n < 18; n++)
00215 elems[j++] = penta[n];
00216
00217
00218
00219 if (cg_section_write (fnum, bnum, znum, "HEXA_8", HEXA_8,
00220 ne+1, ne+1, 0, hexa, &snum) ||
00221 cg_section_write (fnum, bnum, znum, "HEXA_20", HEXA_20,
00222 ne+2, ne+2, 0, hexa, &snum) ||
00223 cg_section_write (fnum, bnum, znum, "HEXA_27", HEXA_27,
00224 ne+3, ne+3, 0, hexa, &snum))
00225 cg_error_exit ();
00226 ne += 3;
00227
00228 elems[j++] = (int)HEXA_8;
00229 for (n = 0; n < 8; n++)
00230 elems[j++] = hexa[n];
00231 elems[j++] = (int)HEXA_20;
00232 for (n = 0; n < 20; n++)
00233 elems[j++] = hexa[n];
00234 elems[j++] = (int)HEXA_27;
00235 for (n = 0; n < 27; n++)
00236 elems[j++] = hexa[n];
00237
00238
00239
00240 i = ne;
00241 elems[j++] = (int)(NGON_n + 3);
00242 for (n = 0; n < 3; n++)
00243 elems[j++] = tri[n];
00244 elems[j++] = (int)(NGON_n + 4);
00245 for (n = 0; n < 4; n++)
00246 elems[j++] = quad[n];
00247 i += 2;
00248
00249 if (cg_section_write (fnum, bnum, znum, "MIXED", MIXED,
00250 ne+1, ne+i, 0, elems, &snum))
00251 cg_error_exit ();
00252 ne += i;
00253
00254 #if CGNS_VERSION >= 3000
00255 for (k = 0, i = 0; i < nface; i++) {
00256 n = face[k++];
00257 for (j = 0; j < n; j++) {
00258 face[k++] += ne;
00259 }
00260 }
00261
00262 if (cg_section_write (fnum, bnum, znum, "NGON_n", NGON_n,
00263 ne+1, ne+npoly, 0, poly, &snum) ||
00264 cg_section_write (fnum, bnum, znum, "NFACE_n", NFACE_n,
00265 ne+npoly+1, ne+npoly+nface, 0, face, &snum))
00266 cg_error_exit ();
00267 #endif
00268
00269 if (cg_close (fnum)) cg_error_exit ();
00270 return 0;
00271 }