UsesCase_MEDmesh_15.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  *  How to create an unstructured mesh with polyhedrons
00020  *
00021  *  Use case 15 : a 3D unstructured mesh with 2 polyhedrons
00022  */
00023 
00024 #include <med.h>
00025 #define MESGERR 1
00026 #include <med_utils.h>
00027 
00028 #include <string.h>
00029 
00030 int main (int argc, char **argv) {
00031   med_idt fid;
00032   const char meshname[MED_NAME_SIZE+1] = "3D Unstructured Mesh With 2 polyhedrons";
00033   const med_int spacedim = 3;
00034   const med_int meshdim  = 3;
00035   /*                                         12345678901234561234567890123456 */
00036   const char axisname[3*MED_SNAME_SIZE+1] = "x               y               z               ";
00037   const char unitname[3*MED_SNAME_SIZE+1] = "cm              cm              cm              ";
00038  
00039   const med_int nnodes = 16;
00040   const med_float coordinates[3 * 16] = {
00041 /* [     1 ] */  -10.0,  -10.0,  +0.0,
00042 /* [     2 ] */  -10.0,  -10.0,  +10., 
00043 /* [     3 ] */  -10.0,  +10.0,  +10., 
00044 /* [     4 ] */  -10.0,  +10.0,  +0.0,
00045 /* [     5 ] */  +10.0,  -10.0,  +0.0,
00046 /* [     6 ] */  +10.0,  -10.0,  +10., 
00047 /* [     7 ] */  +10.0,  +10.0,  +10., 
00048 /* [     8 ] */  +10.0,  +10.0,  +0.0,
00049 /* [     9 ] */  -10.0,  +0.0 , +10.0,
00050 /* [    10 ] */  -10.0,  +0.0 , +0.0 ,
00051 /* [    11 ] */  +0.0 , -10.0 , +10.0,
00052 /* [    12 ] */  +0.0 , -10.0 , +0.0 ,
00053 /* [    13 ] */  +0.0 , +10.0 , +10.0,
00054 /* [    14 ] */  +10.0,  +0.0 , +10.0,
00055 /* [    15 ] */  +0.0 , +10.0 , +0.0 ,
00056 /* [    16 ] */  +10.0,  +0.0 , +0.0
00057   };
00058 
00059   /*Il y a 58 numéros de noeuds dans le tableau de connextivité*/
00060   const med_int connectivity[26+32] = {
00061 /*  - Poly 1 : */  
00062 /*  - Face 1 : */  1,  2  ,  9 , 3  , 10, 
00063 /*  - Face 2 : */  1,  12 ,  5 , 6  , 11,  2, 
00064 /*  - Face 3 : */  2,  11 ,  6 , 3  , 9 ,
00065 /*  - Face 4 : */  3,  6  ,  5 ,      
00066 /*  - Face 5 : */  3,  5  , 10 ,      
00067 /*  - Face 6 : */  1,  10 ,  5 , 12,  
00068 /*  - Poly 2 : */                     
00069 /*  - Face 1 : */  3,  13 ,  7 , 8  , 15,  4, 
00070 /*  - Face 2 : */  3,  4  , 10 ,      
00071 /*  - Face 3 : */  4,  15 ,  8 , 16 ,  5,  10, 
00072 /*  - Face 4 : */  3,  6  , 14 , 7  , 13, 
00073 /*  - Face 5 : */  5,  16 ,  8 , 7  , 14,  6, 
00074 /*  - Face 6 : */  3,  10 ,  5 , 
00075 /*  - Face 7 : */  3,  5  ,  6
00076   };
00077 
00078   /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */
00079   /* La face 7 du Poly 2 utilise 59-56=3 noeuds */
00080   const med_int nodeindex[6+7+1] = { 1, 6, 12, 17, 20, 23,
00081                                      27, 33, 36, 42, 47, 53, 56, 59};
00082   /* Il y a un total de 13 faces */
00083   /* NodeIndexSize == Nbre De Faces +1 */
00084   const med_int nodeindexSize = 6+7+1;
00085 
00086   /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */
00087   /* Pn+1 == FaceIndex[n+1]== NodeIndexSize== Nbre De Faces +1 */
00088   const med_int faceindex[3] = {1,7,14};
00089   const med_int faceindexSize = 3;
00090 
00091 
00092   /* open MED file */
00093   fid = MEDfileOpen("UsesCase_MEDmesh_15.med",
00094         MED_ACC_CREAT);
00095   if (fid < 0) {
00096     MESSAGE("ERROR : file creation ...");
00097     return -1;
00098   }
00099 
00100   /* write a comment in the file */
00101   if (MEDfileCommentWr(fid,
00102            "A 3D unstructured mesh : 2 polyhedrons") < 0) {
00103     MESSAGE("ERROR : write file description ...");
00104     return -1;
00105   }
00106 
00107   /* mesh creation : a 3D unstructured mesh */
00108   if (MEDmeshCr(fid, meshname, spacedim, meshdim,
00109                 MED_UNSTRUCTURED_MESH, "A 3D mesh with 2 polyhedron",
00110                 "", MED_SORT_DTIT,
00111                 MED_CARTESIAN, axisname, unitname) < 0) {
00112     MESSAGE("ERROR : mesh creation ...");
00113     return -1;
00114   }
00115 
00116   /* nodes coordinates in a cartesian axis in full interlace mode
00117      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
00118   */
00119   if (MEDmeshNodeCoordinateWr(fid, meshname,
00120             MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00121             MED_FULL_INTERLACE, nnodes, coordinates) < 0) {
00122     MESSAGE("ERROR : nodes coordinates ...");
00123     return -1;
00124   }
00125 
00126   /* cells connectiviy is defined in nodal mode */
00127   if (MEDmeshPolyhedronWr(fid, meshname,
00128                           MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00129                           MED_CELL, MED_NODAL,
00130                           faceindexSize, faceindex,
00131                           nodeindexSize, nodeindex,
00132                           connectivity) < 0) {
00133     MESSAGE("ERROR : polyhedron connectivity ...");
00134     return -1;
00135   }
00136 
00137   /* create family 0 : by default, all mesh entities family number is 0 */
00138   if (MEDfamilyCr(fid, meshname, "", 0, 0, "") < 0) {
00139     MESSAGE("ERROR : quadrangular cells connectivity ...");
00140     return -1;
00141   }
00142 
00143   /* close MED file */
00144   if (MEDfileClose(fid)  < 0) {
00145     MESSAGE("ERROR : close file ...");
00146     return -1;
00147   }
00148 
00149   return 0;
00150 }

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