# UsesCase_MEDmesh_10.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  *  How to create an unstructured mesh
    00020  *
    00021  *  Use case 10 : a 2D unstructured mesh with 15 nodes, 8 triangular cells, 4 triangular cells
    00022  *                and families
    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   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
    00034   const med_int spacedim = 2;
    00035   const med_int meshdim = 2;
    00036   const char axisname[2*MED_SNAME_SIZE+1] = "x               y               ";
    00037   const char unitname[2*MED_SNAME_SIZE+1] = "cm              cm              ";
    00038   const med_float coordinates[30] = { 2.,1.,  7.,1.,  12.,1.,  17.,1.,  22.,1.,
    00039                                       2.,6.,  7.,6.,  12.,6.,  17.,6.,  22.,6.,
    00040                                       2.,11., 7.,11., 12.,11., 17.,11., 22.,11.};
    00041   const med_int nnodes = 15;
    00042   const med_int triaconnectivity[24] = { 1,7,6,   2,7,1,  3,7,2,   8,7,3,
    00043                                          13,7,8, 12,7,13, 11,7,12, 6,7,11 };
    00044   const med_int ntria3 = 8;
    00045   const med_int quadconnectivity[16] = {3,4,9,8,    4,5,10,9,
    00046                                         15,14,9,10, 13,8,9,14};
    00047   const med_int nquad4 = 4;
    00048   const char familyname[MED_NAME_SIZE+1] = "BOUNDARY_VERTICES";
    00049   const char groupname[MED_LNAME_SIZE+1] =  "MESH_BOUNDARY_VERTICES";
    00050   const med_int familynumbers[15] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1 };
    00051   int ret=-1;
    00052
    00053   /* open MED file */
    00054   fid = MEDfileOpen("UsesCase_MEDmesh_10.med",MED_ACC_CREAT);
    00055   if (fid < 0) {
    00056     MESSAGE("ERROR : file creation ...");
    00057     goto ERROR;
    00058   }
    00059
    00060   /* write a comment in the file */
    00061   if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) {
    00062     MESSAGE("ERROR : write file description ...");
    00063     goto ERROR;
    00064   }
    00065
    00066   /* mesh creation : a 2D unstructured mesh */
    00067   if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH,
    00068                 "A 2D unstructured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) {
    00069     MESSAGE("ERROR : mesh creation ...");
    00070     goto ERROR;
    00071   }
    00072
    00073   /* nodes coordinates in a cartesian axis in full interlace mode
    00074      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
    00075   */
    00076   if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
    00077                               MED_FULL_INTERLACE, nnodes, coordinates) < 0) {
    00078     MESSAGE("ERROR : nodes coordinates ...");
    00079     goto ERROR;
    00080   }
    00081
    00082   /* cells connectiviy is defined in nodal mode */
    00083   if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_TRIA3,
    00084                                    MED_NODAL, MED_FULL_INTERLACE, ntria3, triaconnectivity) < 0) {
    00085     MESSAGE("ERROR : triangular cells connectivity ...");
    00086     goto ERROR;
    00087   }
    00088
    00089   if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4,
    00090                                    MED_NODAL, MED_FULL_INTERLACE, nquad4, quadconnectivity) < 0) {
    00091     MESSAGE("ERROR : quadrangular cells connectivity ...");
    00092     goto ERROR;
    00093   }
    00094
    00095   /* create family 0 : by default, all mesh entities family number is 0 */
    00096   if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
    00097     MESSAGE("ERROR : family creation ...");
    00098     goto ERROR;
    00099   }
    00100
    00101   /* create a family for boundary vertices : by convention a nodes family number is > 0,
    00102      and an element family number is < 0 */
    00103   if (MEDfamilyCr(fid, meshname,familyname, 1, 1, groupname) < 0) {
    00104     MESSAGE("ERROR : family creation ...");
    00105     goto ERROR;
    00106   }
    00107
    00108   /* write family number for nodes */
    00109   if (MEDmeshEntityFamilyNumberWr(fid, meshname, MED_NO_DT, MED_NO_IT,
    00110                                   MED_NODE, MED_NONE, nnodes, familynumbers) < 0) {
    00111     MESSAGE("ERROR : nodes family numbers ...");
    00112     goto ERROR;
    00113   }
    00114
    00115   ret=0;
    00116  ERROR:
    00117
    00118   /* close MED file */
    00119   if (MEDfileClose(fid)  < 0) {
    00120     MESSAGE("ERROR : close file ...");
    00121     ret=-1;
    00122   }
    00123
    00124   return ret;
    00125 }