| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include <med.h> |
| 25 |
#define MESGERR 1 |
| 26 |
#include <med_utils.h> |
| 27 |
|
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
int main (int argc, char **argv) { |
| 31 |
med_idt fid; |
| 32 |
const char meshname[MED_NAME_SIZE+1] = "3D Unstructured Mesh With 2 polyhedrons"; |
| 33 |
const med_int spacedim = 3; |
| 34 |
const med_int meshdim = 3; |
| 35 |
|
| 36 |
const char axisname[3*MED_SNAME_SIZE+1] = "x y z "; |
| 37 |
const char unitname[3*MED_SNAME_SIZE+1] = "cm cm cm "; |
| 38 |
|
| 39 |
const med_int nnodes = 16; |
| 40 |
const med_float coordinates[3 * 16] = { |
| 41 |
-10.0, -10.0, +0.0, |
| 42 |
-10.0, -10.0, +10., |
| 43 |
-10.0, +10.0, +10., |
| 44 |
-10.0, +10.0, +0.0, |
| 45 |
+10.0, -10.0, +0.0, |
| 46 |
+10.0, -10.0, +10., |
| 47 |
+10.0, +10.0, +10., |
| 48 |
+10.0, +10.0, +0.0, |
| 49 |
-10.0, +0.0 , +10.0, |
| 50 |
-10.0, +0.0 , +0.0 , |
| 51 |
+0.0 , -10.0 , +10.0, |
| 52 |
+0.0 , -10.0 , +0.0 , |
| 53 |
+0.0 , +10.0 , +10.0, |
| 54 |
+10.0, +0.0 , +10.0, |
| 55 |
+0.0 , +10.0 , +0.0 , |
| 56 |
+10.0, +0.0 , +0.0 |
| 57 |
}; |
| 58 |
|
| 59 |
*/ |
| 60 |
const med_int connectivity[26+32] = { |
| 61 |
|
| 62 |
1, 2 , 9 , 3 , 10, |
| 63 |
1, 12 , 5 , 6 , 11, 2, |
| 64 |
2, 11 , 6 , 3 , 9 , |
| 65 |
3, 6 , 5 , |
| 66 |
3, 5 , 10 , |
| 67 |
1, 10 , 5 , 12, |
| 68 |
|
| 69 |
3, 13 , 7 , 8 , 15, 4, |
| 70 |
3, 4 , 10 , |
| 71 |
4, 15 , 8 , 16 , 5, 10, |
| 72 |
3, 6 , 14 , 7 , 13, |
| 73 |
5, 16 , 8 , 7 , 14, 6, |
| 74 |
3, 10 , 5 , |
| 75 |
3, 5 , 6 |
| 76 |
}; |
| 77 |
|
| 78 |
/ |
| 79 |
|
| 80 |
const med_int nodeindex[6+7+1] = { 1, 6, 12, 17, 20, 23, |
| 81 |
27, 33, 36, 42, 47, 53, 56, 59}; |
| 82 |
|
| 83 |
|
| 84 |
const med_int nodeindexSize = 6+7+1; |
| 85 |
|
| 86 |
/ |
| 87 |
|
| 88 |
const med_int faceindex[3] = {1,7,14}; |
| 89 |
const med_int faceindexSize = 3; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
fid = MEDfileOpen("UsesCase_MEDmesh_15.med", |
| 94 |
MED_ACC_CREAT); |
| 95 |
if (fid < 0) { |
| 96 |
MESSAGE("ERROR : file creation ..."); |
| 97 |
return -1; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
if (MEDfileCommentWr(fid, |
| 102 |
"A 3D unstructured mesh : 2 polyhedrons") < 0) { |
| 103 |
MESSAGE("ERROR : write file description ..."); |
| 104 |
return -1; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
if (MEDmeshCr(fid, meshname, spacedim, meshdim, |
| 109 |
MED_UNSTRUCTURED_MESH, "A 3D mesh with 2 polyhedron", |
| 110 |
"", MED_SORT_DTIT, |
| 111 |
MED_CARTESIAN, axisname, unitname) < 0) { |
| 112 |
MESSAGE("ERROR : mesh creation ..."); |
| 113 |
return -1; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
if (MEDmeshNodeCoordinateWr(fid, meshname, |
| 120 |
MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, |
| 121 |
MED_FULL_INTERLACE, nnodes, coordinates) < 0) { |
| 122 |
MESSAGE("ERROR : nodes coordinates ..."); |
| 123 |
return -1; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
if (MEDmeshPolyhedronWr(fid, meshname, |
| 128 |
MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, |
| 129 |
MED_CELL, MED_NODAL, |
| 130 |
faceindexSize, faceindex, |
| 131 |
nodeindexSize, nodeindex, |
| 132 |
connectivity) < 0) { |
| 133 |
MESSAGE("ERROR : polyhedron connectivity ..."); |
| 134 |
return -1; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
if (MEDfamilyCr(fid, meshname, "", 0, 0, "") < 0) { |
| 139 |
MESSAGE("ERROR : family 0 creation ..."); |
| 140 |
return -1; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
if (MEDfileClose(fid) < 0) { |
| 145 |
MESSAGE("ERROR : close file ..."); |
| 146 |
return -1; |
| 147 |
} |
| 148 |
|
| 149 |
return 0; |
| 150 |
} |