00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <med.h>
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028
00029 #include <string.h>
00030
00031 int main (int argc, char **argv) {
00032 med_idt fid;
00033 char elementname[MED_NAME_SIZE+1]="";
00034 const char ballsupportname[MED_NAME_SIZE+1]="BALL_SUPPORT_MESH";
00035 const char beamsupportname[MED_NAME_SIZE+1]="BEAM_SUPPORT_MESH";
00036 const char computmeshname[MED_NAME_SIZE+1]="COMPUT_MESH";
00037 const char beamsectionname[MED_NAME_SIZE+1]="BEAM_SECTION_MESH";
00038 const med_int elementdim = 3;
00039 med_int nnode;
00040 med_geometry_type geotype=MED_NONE;
00041 med_int ncomp;
00042 const med_float ballmeshnodescoo[3] = {0.0, 0.0, 0.0 };
00043 const med_float beammeshnodescoo[3*7] = {0.0,0.0,0.0,
00044 0.0,0.0,2.0,
00045 0.0,0.0,4.0,
00046 0.0,0.0,5.0,
00047 0.0,0.0,7.0,
00048 0.0,0.0,10.0,
00049 0.0,0.0,11.0 };
00050 const med_float beamsectioncoo[9*3] = {-0.2,-0.2,0.0,
00051 0.0,-0.2,0.0,
00052 0.2,-0.2,0.0,
00053 -0.2, 0.0,0.0,
00054 0.0, 0.0,0.0,
00055 0.2, 0.0,0.0,
00056 -0.2, 0.2,0.0,
00057 0.0, 0.2,0.0,
00058 0.2, 0.2,0.0 };
00059 const med_int seg2connectivity[2*6] = {1,2, 2,3, 3,4, 4,5, 5,6, 6,7};
00060 med_int spacedim, meshdim,nseg2;
00061
00062 const char axisname[3*MED_SNAME_SIZE+1] = "x y z ";
00063 const char unitname[3*MED_SNAME_SIZE+1] = "cm cm cm ";
00064 const med_float attvalue[6] = {0.2,0.3,0.4,0.4,0.3,0.2};
00065
00066 const char attprovalue[2*MED_NAME_SIZE+1] = {"EXTREMITY_1_____________________________________________________" \
00067 "EXTREMITY_2_____________________________________________________" };
00068 const char profilename[MED_NAME_SIZE+1] = "EXTREMITY_PROFILE_NAME";
00069 const med_int profilesize = 2;
00070 const med_int profile[2] = {1,6};
00071 const med_float meshcoo[3*12] = { 0.0, 0.0, 0.0,
00072 1.1, 1.1, 1.1,
00073 2.2, 2.2, 2.2,
00074 10., 10., 10.,
00075 12., 12., 12.,
00076 60., 20., 20.,
00077 70., 20., 20.,
00078 80., 20., 20.,
00079 90., 20., 20.,
00080 100., 20., 20.,
00081 110., 20., 20.,
00082 120., 20., 20.
00083 };
00084 const med_int meshseg2connectivity[12] = { 6,7,
00085 7,8,
00086 8,9,
00087 9,10,
00088 10,11,
00089 11,12 };
00090 med_int nentity;
00091 const med_int labels[3] = { 1, 2, 3 };
00092 const med_int ballconnectivity[2] = { 4, 5 };
00093 const med_int beamconnectivity[6] = { 1, 2, 3, 4, 5, 6};
00094 const med_float balldiameter[2] = { 2.0, 5.8 };
00095 const med_int nquad4=4;
00096 const med_int beamsectionconnectivity[4*4] = { 4,5,2,1,
00097 5,6,3,2,
00098 7,8,5,4,
00099 8,9,6,5};
00100 int ret=-1;
00101
00102
00103 fid = MEDfileOpen("UsesCase_MEDstructElement_1.med",MED_ACC_CREAT);
00104 if (fid < 0) {
00105 MESSAGE("ERROR : file creation");
00106 goto ERROR;
00107 }
00108
00109
00110 spacedim = 3;
00111 meshdim = 3;
00112
00113
00114 if (MEDsupportMeshCr(fid, ballsupportname, spacedim, meshdim, "Support mesh for a ball model",
00115 MED_CARTESIAN, axisname, unitname) < 0) {
00116 MESSAGE("ERROR : creating a support mesh ...");
00117 goto ERROR;
00118 }
00119
00120 nnode = 1;
00121 if (MEDmeshNodeCoordinateWr(fid, ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
00122 MED_FULL_INTERLACE, nnode, ballmeshnodescoo) < 0) {
00123 MESSAGE("ERROR : write nodes coordinates ...");
00124 goto ERROR;
00125 }
00126
00127
00128 if (MEDsupportMeshCr(fid, beamsupportname, spacedim, meshdim, "Support mesh for a beam model",
00129 MED_CARTESIAN, axisname, unitname) < 0) {
00130 MESSAGE("ERROR : creating a support mesh ...");
00131 goto ERROR;
00132 }
00133
00134 nnode = 7;
00135 if (MEDmeshNodeCoordinateWr(fid, beamsupportname, MED_NO_DT, MED_NO_IT, 0.0,
00136 MED_FULL_INTERLACE, nnode, beammeshnodescoo) < 0) {
00137 MESSAGE("ERROR : write nodes coordinates ...");
00138 goto ERROR;
00139 }
00140 nseg2 = 6;
00141 if (MEDmeshElementConnectivityWr(fid, beamsupportname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_SEG2,
00142 MED_NODAL, MED_FULL_INTERLACE, nseg2, seg2connectivity) < 0) {
00143 MESSAGE("ERROR : write cells connectivity ...");
00144 goto ERROR;
00145 }
00146
00147
00148
00149 if (MEDsupportMeshCr(fid, beamsectionname, spacedim, meshdim, "Support mesh for a section of the beam model",
00150 MED_CARTESIAN, axisname, unitname) < 0) {
00151 MESSAGE("ERROR : creating a support mesh ...");
00152 goto ERROR;
00153 }
00154
00155 nnode = 9;
00156 if (MEDmeshNodeCoordinateWr(fid, beamsectionname, MED_NO_DT, MED_NO_IT, 0.0,
00157 MED_FULL_INTERLACE, nnode, beamsectioncoo) < 0) {
00158 MESSAGE("ERROR : write nodes coordinates ...");
00159 goto ERROR;
00160 }
00161
00162 if (MEDmeshElementConnectivityWr(fid, beamsectionname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4,
00163 MED_NODAL, MED_FULL_INTERLACE, nquad4, beamsectionconnectivity) < 0) {
00164 MESSAGE("ERROR : write cells connectivity ...");
00165 goto ERROR;
00166 }
00167
00168
00169
00170 strcpy(elementname,MED_PARTICLE_NAME);
00171 if ((geotype = MEDstructElementCr(fid, elementname, elementdim, MED_NO_MESHNAME,
00172 MED_NONE,MED_NONE)) < 0) {
00173 MESSAGE("ERROR : creating struct element");
00174 goto ERROR;
00175 }
00176 ncomp=1;
00177 if (MEDstructElementVarAttCr(fid, elementname,
00178 MED_PARTICLE_LABEL, MED_ATT_INT, ncomp) < 0) {
00179 MESSAGE("ERROR : creating struct element");
00180 goto ERROR;
00181 }
00182
00183
00184 strcpy(elementname,MED_BALL_NAME);
00185 if ((geotype = MEDstructElementCr(fid, elementname, elementdim, ballsupportname,
00186 MED_NODE,MED_NONE)) < 0) {
00187 MESSAGE("ERROR : creating struct element");
00188 goto ERROR;
00189 }
00190 ncomp=1;
00191 if (MEDstructElementVarAttCr(fid, elementname,
00192 MED_BALL_DIAMETER, MED_ATT_FLOAT64, ncomp) < 0) {
00193 MESSAGE("ERROR : creating struct element");
00194 goto ERROR;
00195 }
00196
00197
00198
00199 strcpy(elementname,MED_BEAM_NAME);
00200 if ((geotype = MEDstructElementCr(fid, elementname, elementdim, beamsupportname,
00201 MED_CELL,MED_SEG2)) < 0) {
00202 MESSAGE("ERROR : creating struct element");
00203 goto ERROR;
00204 }
00205 ncomp=1;
00206
00207 if (MEDstructElementConstAttWr(fid, elementname,
00208 MED_BEAM_THICKNESS, MED_ATT_FLOAT64, ncomp,
00209 MED_CELL,(void*) attvalue) < 0) {
00210 MESSAGE("ERROR : creating struct element");
00211 goto ERROR;
00212 }
00213
00214
00215
00216 if (MEDprofileWr(fid, profilename, profilesize, profile ) < 0) {
00217 MESSAGE("ERROR : create profile ...");
00218 goto ERROR;
00219 }
00220
00221 if (MEDstructElementConstAttWithProfileWr(fid,
00222 elementname,
00223 "BEAM_EXTREMITIES_LABELS",
00224 MED_ATT_NAME,
00225 ncomp,
00226 MED_CELL,
00227 profilename,
00228 (void*) attprovalue) < 0) {
00229 MESSAGE("ERROR : creating struct element");
00230 goto ERROR;
00231 }
00232
00233
00234
00235
00236 if (MEDmeshCr(fid, computmeshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH,
00237 "Computation mesh", "s", MED_SORT_DTIT,
00238 MED_CARTESIAN, axisname, unitname) < 0) {
00239 MESSAGE("ERROR : creating computation mesh ...");
00240 goto ERROR;
00241 }
00242
00243
00244 nnode = 12;
00245 if (MEDmeshNodeCoordinateWr(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00246 MED_FULL_INTERLACE, nnode, meshcoo) < 0) {
00247 MESSAGE("ERROR : writing nodes coordinates ...");
00248 goto ERROR;
00249 }
00250
00251
00252 nentity = 1;
00253 SSCRUTE(elementname);
00254 geotype = MEDstructElementGeotype(fid,elementname);
00255 ISCRUTE(geotype);
00256 if (MEDmeshElementConnectivityWr(fid, computmeshname, MED_NO_DT, MED_NO_IT, 0.0,
00257 MED_STRUCT_ELEMENT, geotype , MED_NODAL, MED_FULL_INTERLACE,
00258 nentity, meshseg2connectivity) < 0) {
00259 MESSAGE("ERROR : writing beams model mesh support connectivity ...");
00260 goto ERROR;
00261 }
00262
00263
00264
00265
00266
00267 strcpy(elementname,MED_PARTICLE_NAME);
00268 geotype = MEDstructElementGeotype(fid,elementname);
00269 nentity = 3;
00270 ISCRUTE(geotype);
00271 if (MEDmeshElementConnectivityWr(fid, computmeshname, MED_NO_DT, MED_NO_IT, 0.0,
00272 MED_STRUCT_ELEMENT, geotype , MED_NODAL, MED_FULL_INTERLACE,
00273 nentity, 0) < 0) {
00274 MESSAGE("ERROR : writing particles connectivity ...");
00275 goto ERROR;
00276 }
00277
00278
00279
00280 if (MEDmeshStructElementVarAttWr(fid, computmeshname, MED_NO_DT, MED_NO_IT,
00281 geotype, MED_PARTICLE_LABEL,
00282 nentity, labels) < 0 ) {
00283 MESSAGE("ERROR : writing variable attributes ...");
00284 goto ERROR;
00285 }
00286
00287
00288
00289 strcpy(elementname,MED_BALL_NAME);
00290 nentity = 2;
00291 geotype = MEDstructElementGeotype(fid,elementname);
00292 if (MEDmeshElementConnectivityWr(fid,computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00293 MED_STRUCT_ELEMENT, geotype, MED_NODAL,
00294 MED_FULL_INTERLACE, nentity, ballconnectivity) < 0 ) {
00295 MESSAGE("ERROR : writing balls connectivity");
00296 goto ERROR;
00297 }
00298
00299
00300 if (MEDmeshStructElementVarAttWr(fid, computmeshname, MED_NO_DT, MED_NO_IT,
00301 geotype, MED_BALL_DIAMETER,
00302 nentity, balldiameter) < 0 ) {
00303 MESSAGE("ERROR : writing variable attributes ...");
00304 goto ERROR;
00305 }
00306
00307
00308 strcpy(elementname,MED_BEAM_NAME);
00309 nentity = 1;
00310 geotype = MEDstructElementGeotype(fid,elementname);
00311
00312 if (MEDmeshElementConnectivityWr(fid,computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00313 MED_STRUCT_ELEMENT, geotype, MED_NODAL,
00314 MED_FULL_INTERLACE, nentity, beamconnectivity) < 0 ) {
00315 MESSAGE("ERROR : beam connectivity ...");
00316 goto ERROR;
00317 }
00318
00319 ret=0;
00320 ERROR:
00321
00322
00323 if (MEDfileClose(fid) < 0) {
00324 MESSAGE("ERROR : file closing");
00325 ret=-1;
00326 }
00327
00328 return ret;
00329 }
00330