# UsesCase_MEDmesh_15.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2012  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 polygons
    00020  *
    00021  *  Use case 15 : a 2D 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";
    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   const med_int nnodes = 12;
    00039   const med_float coordinates[3 * 12] =
    00040           { 1.618,  1.,     0.,
    00041            -1.618,  1.,     0.,
    00042             1.618, -1.,     0.,
    00043            -1.618, -1.,     0.,
    00044             1.,     0.,     1.618,
    00045             1.,     0.,    -1.618,
    00046            -1.,     0.,     1.618,
    00047            -1.,     0.,    -1.618,
    00048             0.,  1.618,     1.,
    00049             0., -1.618,     1.,
    00050             0.,  1.618,     1.,
    00051             0., -1.618,     1.  };
    00052   const med_int nodeindex[2] = {1,21};
    00053   const med_int nodeIndexSize = 2;
    00054   const med_int faceindex[21] = { 1, 4, 7,10,13,16,19,22,25,28,
    00055                                  31,34,37,40,43,46,49,52,55,58,61 };
    00056   const med_int faceIndexSize = 21;
    00057   /* connectivity : 1 icosahedron */
    00058   const med_int connectivity[60] = { 1,  9,  5,
    00059                                      1,  6, 11,
    00060                                      3,  5, 10,
    00061                                      3, 12,  6,
    00062                                      2,  7,  9,
    00063                                      2, 11,  8,
    00064                                      4, 10,  7,
    00065                                      4,  8, 12,
    00066                                      1, 11,  9,
    00067                                      2,  9, 11,
    00068                                      3, 10, 12,
    00069                                      4, 10, 12,
    00070                                      5,  3,  1,
    00071                                      6,  1,  3,
    00072                                      7,  2,  4,
    00073                                      8,  4,  2,
    00074                                      9,  7,  5,
    00075                                     10,  5,  7,
    00076                                     11,  6,  8,
    00077                                     12,  8,  6  };
    00078
    00079   /* open MED file */
    00080   fid = MEDfileOpen("UsesCase_MEDmesh_15.med",
    00081         MED_ACC_CREAT);
    00082   if (fid < 0) {
    00083     MESSAGE("ERROR : file creation ...");
    00084     return -1;
    00085   }
    00086
    00087   /* write a comment in the file */
    00088   if (MEDfileCommentWr(fid,
    00089            "A 3D unstructured mesh : 1 icosahedron") < 0) {
    00090     MESSAGE("ERROR : write file description ...");
    00091     return -1;
    00092   }
    00093
    00094   /* mesh creation : a 3D unstructured mesh */
    00095   if (MEDmeshCr(fid,
    00096                 meshname,
    00097                 spacedim,
    00098                 meshdim,
    00099                 MED_UNSTRUCTURED_MESH,
    00100                 "A 3D mesh with 1 icosahedron",
    00101                 "",
    00102                 MED_SORT_DTIT,
    00103                 MED_CARTESIAN,
    00104                 axisname,
    00105                 unitname) < 0) {
    00106     MESSAGE("ERROR : mesh creation ...");
    00107     return -1;
    00108   }
    00109
    00110   /* nodes coordinates in a cartesian axis in full interlace mode
    00111      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
    00112   */
    00113   if (MEDmeshNodeCoordinateWr(fid,
    00114             meshname,
    00115             MED_NO_DT,
    00116             MED_NO_IT,
    00117             MED_UNDEF_DT,
    00118             MED_FULL_INTERLACE,
    00119             nnodes,
    00120             coordinates) < 0) {
    00121     MESSAGE("ERROR : nodes coordinates ...");
    00122     return -1;
    00123   }
    00124
    00125   /* cells connectiviy is defined in nodal mode */
    00126   /* 1 icosahedron */
    00127   if (MEDmeshPolyhedronWr(fid,
    00128                           meshname,
    00129                           MED_NO_DT,
    00130                           MED_NO_IT,
    00131                           MED_UNDEF_DT,
    00132                           MED_CELL,
    00133                           MED_NODAL,
    00134                           nodeIndexSize,
    00135                           nodeindex,
    00136                           faceIndexSize,
    00137                           faceindex,
    00138                           connectivity) < 0) {
    00139     MESSAGE("ERROR : polyhedron connectivity ...");
    00140     return -1;
    00141   }
    00142
    00143   /* create family 0 : by default, all mesh entities family number is 0 */
    00144   if (MEDfamilyCr(fid,
    00145       meshname,
    00146       "",
    00147       0,
    00148       0,
    00149       "") < 0) {
    00150     MESSAGE("ERROR : quadrangular cells connectivity ...");
    00151     return -1;
    00152   }
    00153
    00154   /* close MED file */
    00155   if (MEDfileClose(fid)  < 0) {
    00156     MESSAGE("ERROR : close file ...");
    00157     return -1;
    00158   }
    00159
    00160   return 0;
    00161 }