# UsesCase_MEDmesh_13.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2011  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 12 nodes and 2 polygons
    00020  */
    00021
    00022 #include <med.h>
    00023 #define MESGERR 1
    00024 #include <med_utils.h>
    00025
    00026 #include <string.h>
    00027
    00028 int main (int argc, char **argv) {
    00029   med_idt fid;
    00030   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
    00031   const med_int spacedim = 2;
    00032   const med_int meshdim = 2;
    00033   /*                                         12345678901234561234567890123456 */
    00034   const char axisname[2*MED_SNAME_SIZE+1] = "x               y               ";
    00035   const char unitname[2*MED_SNAME_SIZE+1] = "cm              cm              ";
    00036   const med_float coordinates[2*12] = { 0.5,   0.,
    00037                                         1.5,   0.,
    00038                                         0.,    0.5,
    00039                                         1.,    0.5,
    00040                                         2.,    0.5,
    00041                                         0.,    1.,
    00042                                         1.,    1.,
    00043                                         2.,    1.,
    00044                                         0.5,   2.,
    00045                                         1.5,   2. };
    00046   const med_int nnodes = 12;
    00047   const med_int indexsize = 3;
    00048   const med_int index[3] = {1,7,13};
    00049   /* connectivity : 2 hexagons */
    00050   const med_int connectivity[12] = {1,4,7,9,6,3,
    00051                                     2,5,8,10,7,4};
    00052   int ret=-1;
    00053
    00054   /* open MED file */
    00055   fid = MEDfileOpen("UsesCase_MEDmesh_13.med",
    00056                     MED_ACC_CREAT);
    00057   if (fid < 0) {
    00058     MESSAGE("ERROR : file creation ...");
    00059     goto ERROR;
    00060   }
    00061
    00062   /* write a comment in the file */
    00063   if (MEDfileCommentWr(fid,
    00064                        "A 2D unstructured mesh : 12, 12 polygons") < 0) {
    00065     MESSAGE("ERROR : write file description ...");
    00066     goto ERROR;
    00067   }
    00068
    00069   /* mesh creation : a 2D unstructured mesh */
    00070   if (MEDmeshCr(fid,
    00071                 meshname,
    00072                 spacedim,
    00073                 meshdim,
    00074                 MED_UNSTRUCTURED_MESH,
    00075                 "A 2D mesh with 2 polygons",
    00076                 "",
    00077                 MED_SORT_DTIT,
    00078                 MED_CARTESIAN,
    00079                 axisname,
    00080                 unitname) < 0) {
    00081     MESSAGE("ERROR : mesh creation ...");
    00082     goto ERROR;
    00083   }
    00084
    00085   /* nodes coordinates in a cartesian axis in full interlace mode
    00086      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
    00087   */
    00088   if (MEDmeshNodeCoordinateWr(fid,
    00089                               meshname,
    00090                               MED_NO_DT,
    00091                               MED_NO_IT,
    00092                               MED_UNDEF_DT,
    00093                               MED_FULL_INTERLACE,
    00094                               nnodes,
    00095                               coordinates) < 0) {
    00096     MESSAGE("ERROR : nodes coordinates ...");
    00097     goto ERROR;
    00098   }
    00099
    00100   /* cells connectiviy is defined in nodal mode */
    00101   /* 2 polygons */
    00102   if (MEDmeshPolygonWr(fid,
    00103                        meshname,
    00104                        MED_NO_DT,
    00105                        MED_NO_IT,
    00106                        MED_UNDEF_DT,
    00107                        MED_CELL,
    00108                        MED_NODAL,
    00109                        indexsize,
    00110                        index,
    00111                        connectivity) < 0) {
    00112     MESSAGE("ERROR : polygon connectivity ...");
    00113     goto ERROR;
    00114   }
    00115
    00116
    00117   /* create family 0 : by default, all mesh entities family number is 0 */
    00118   if (MEDfamilyCr(fid,
    00119                   meshname,
    00120                   MED_NO_NAME,
    00121                   0,
    00122                   0,
    00123                   MED_NO_GROUP) < 0) {
    00124     MESSAGE("ERROR : family 0 creation ...");
    00125     goto ERROR;
    00126   }
    00127
    00128   ret=0;
    00129  ERROR:
    00130
    00131   /* close MED file */
    00132   if (MEDfileClose(fid)  < 0) {
    00133     MESSAGE("ERROR : close file ...");
    00134     ret=-1;
    00135   }
    00136
    00137   return ret;
    00138 }