UsesCase_MEDmesh_13.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2016  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 /*
00019  *  Use case 13 : a 2D unstructured mesh with 10 nodes and 2 polygons
00020  * poly1 : 1,4,7,9,6,3
00021  * poly2 : 2,5,8,10,7,4
00022  *      9   10
00023  *
00024  *   6    7    8
00025  *
00026  *   3    4    5
00027  *
00028  *      1     2
00029  *
00030 */
00031 
00032 #include <med.h>
00033 #define MESGERR 1
00034 #include <med_utils.h>
00035 
00036 #include <string.h>
00037 
00038 int main (int argc, char **argv) {
00039   med_idt fid;
00040   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00041   const med_int spacedim = 2;
00042   const med_int meshdim = 2;
00043   /*                                         12345678901234561234567890123456 */
00044   const char axisname[2*MED_SNAME_SIZE+1] = "x               y               ";
00045   const char unitname[2*MED_SNAME_SIZE+1] = "cm              cm              ";
00046   /* Dix noeuds dont deux communs aux deux polygones */
00047   const med_float coordinates[2*10] = { 0.5,   0.,
00048                                         1.5,   0.,
00049                                         0.,    0.5,
00050                                         1.,    0.5,
00051                                         2.,    0.5,
00052                                         0.,    1.,
00053                                         1.,    1.,
00054                                         2.,    1.,
00055                                         0.5,   2.,
00056                                         1.5,   2. };
00057   const med_int nnodes    = 10;
00058   const med_int indexsize = 3;
00059   const med_int index[3]  = {1,7,13};
00060   /* connectivity : 2 hexagons */
00061   const med_int connectivity[12] = {1,4,7,9,6,3,
00062                                     2,5,8,10,7,4};
00063   int ret=-1;
00064 
00065   /* open MED file */
00066   fid = MEDfileOpen("UsesCase_MEDmesh_13.med", MED_ACC_CREAT);
00067   if (fid < 0) {
00068     MESSAGE("ERROR : file creation ...");
00069     goto ERROR;
00070   }
00071 
00072   /* write a comment in the file */
00073   if (MEDfileCommentWr(fid, "A 2D unstructured mesh : 12, 12 polygons") < 0) 
00074     { MESSAGE("ERROR : write file description ...");
00075       goto ERROR;
00076     }
00077   
00078   /* mesh creation : a 2D unstructured mesh */
00079   if (MEDmeshCr(fid, meshname, spacedim, meshdim, 
00080                 MED_UNSTRUCTURED_MESH, "A 2D mesh with 2 polygons",
00081                 "", MED_SORT_DTIT, MED_CARTESIAN, axisname, unitname) < 0) 
00082     { MESSAGE("ERROR : mesh creation ...");
00083       goto ERROR;
00084     }
00085 
00086   /* nodes coordinates in a cartesian axis in full interlace mode 
00087      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step 
00088   */
00089   if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00090                               MED_FULL_INTERLACE, nnodes, coordinates) < 0) 
00091     { MESSAGE("ERROR : nodes coordinates ...");
00092       goto ERROR;
00093     }
00094 
00095   /* cells connectiviy is defined in nodal mode */
00096   /* 2 polygons */
00097   if (MEDmeshPolygonWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00098                        MED_CELL, MED_NODAL, indexsize, index, connectivity) < 0)
00099     { MESSAGE("ERROR : polygon connectivity ...");
00100       goto ERROR;
00101     }
00102 
00103 
00104   /* create family 0 : by default, all mesh entities family number is 0 */
00105   if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) 
00106     { MESSAGE("ERROR : family 0 creation ...");
00107       goto ERROR;
00108     }
00109 
00110   ret=0;
00111  ERROR:
00112   
00113   /* close MED file */
00114   if (MEDfileClose(fid)  < 0) {
00115     MESSAGE("ERROR : close file ...");
00116     ret=-1;
00117   }
00118 
00119   return ret;
00120 }

Généré le Thu Jan 21 18:06:09 2016 pour MED fichier par  doxygen 1.6.1