UsesCase_MEDmesh_13.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  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",
00067                     MED_ACC_CREAT);
00068   if (fid < 0) {
00069     MESSAGE("ERROR : file creation ...");
00070     goto ERROR;
00071   }
00072 
00073   /* write a comment in the file */
00074   if (MEDfileCommentWr(fid,
00075                        "A 2D unstructured mesh : 12, 12 polygons") < 0) {
00076     MESSAGE("ERROR : write file description ...");
00077     goto ERROR;
00078   }
00079   
00080   /* mesh creation : a 2D unstructured mesh */
00081   if (MEDmeshCr(fid, 
00082                 meshname, 
00083                 spacedim, 
00084                 meshdim, 
00085                 MED_UNSTRUCTURED_MESH, 
00086                 "A 2D mesh with 2 polygons",
00087                 "",
00088                 MED_SORT_DTIT,
00089                 MED_CARTESIAN, 
00090                 axisname, 
00091                 unitname) < 0) {
00092     MESSAGE("ERROR : mesh creation ...");
00093     goto ERROR;
00094   }
00095 
00096   /* nodes coordinates in a cartesian axis in full interlace mode 
00097      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step 
00098   */
00099   if (MEDmeshNodeCoordinateWr(fid, 
00100                               meshname, 
00101                               MED_NO_DT, 
00102                               MED_NO_IT, 
00103                               MED_UNDEF_DT,
00104                               MED_FULL_INTERLACE, 
00105                               nnodes, 
00106                               coordinates) < 0) {
00107     MESSAGE("ERROR : nodes coordinates ...");
00108     goto ERROR;
00109   }
00110 
00111   /* cells connectiviy is defined in nodal mode */
00112   /* 2 polygons */
00113   if (MEDmeshPolygonWr(fid,
00114                        meshname,
00115                        MED_NO_DT,
00116                        MED_NO_IT,
00117                        MED_UNDEF_DT,
00118                        MED_CELL,
00119                        MED_NODAL,
00120                        indexsize,
00121                        index,
00122                        connectivity) < 0) {
00123     MESSAGE("ERROR : polygon connectivity ...");
00124     goto ERROR;
00125   }
00126 
00127 
00128   /* create family 0 : by default, all mesh entities family number is 0 */
00129   if (MEDfamilyCr(fid, 
00130                   meshname,
00131                   MED_NO_NAME, 
00132                   0, 
00133                   0, 
00134                   MED_NO_GROUP) < 0) {
00135     MESSAGE("ERROR : family 0 creation ...");
00136     goto ERROR;
00137   }
00138 
00139   ret=0;
00140  ERROR:
00141   
00142   /* close MED file */
00143   if (MEDfileClose(fid)  < 0) {
00144     MESSAGE("ERROR : close file ...");
00145     ret=-1;
00146   }
00147 
00148   return ret;
00149 }

Généré le Thu Oct 8 14:26:17 2015 pour MED fichier par  doxygen 1.6.1