UsesCase_MEDmesh_4.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 /*
00020  *  How to create a structured mesh 
00021  *
00022  *  Use case 4 :  write a 2D structured mesh (5x3 cartesian grid)
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 structured 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   med_int         axis, size ;
00039   const med_float cooXaxis[5] = {1.,2.,3.,4.,5.};
00040   const med_float cooYaxis[3] = {1.,2.,3.};
00041   const med_int   nquad4 = 8;
00042   /*                                           12345678901234561234567890123456123456789012345612345678901234561234567890123456123456789012345612345678901234561234567890123456 */
00043   const char cellsnames[8*MED_SNAME_SIZE+1] = "CELL_1          CELL_2          CELL_3          CELL_4          CELL_5          CELL_6          CELL_7          CELL_8          ";
00044   const char     familyname   [MED_NAME_SIZE+1]  = "CART_GRID_QUAD_FAMILY";
00045   const char     groupname    [MED_LNAME_SIZE+1] = "CART_GRID_GROUP";
00046   const med_int  familynumbers[8]           = { -1, -1, -1, -1, -1, -1, -1, -1 };
00047   int ret=-1;
00048 
00049   /* MED file creation */
00050   fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_CREAT);
00051   if (fid < 0) {
00052     MESSAGE("ERROR : file creation ...");
00053     goto ERROR;
00054   }
00055 
00056   /* create the structured mesh in the MED file */
00057   if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_STRUCTURED_MESH,  
00058                 "A 2D structured mesh","",MED_SORT_DTIT,
00059                 MED_CARTESIAN, axisname, unitname) < 0) {
00060     MESSAGE("ERROR : mesh creation ...");
00061     goto ERROR;
00062   }
00063   
00064   /* specify the grid type : MED_CARTESIAN_GRID */
00065    if (MEDmeshGridTypeWr(fid,meshname, MED_CARTESIAN_GRID) < 0) {
00066     MESSAGE("ERROR : write grid type ...");
00067     goto ERROR;
00068   }
00069   
00070    /* write axis "X" and "Y" coordinates */ 
00071    axis = 1;
00072    size = 5;
00073    if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0, 
00074                                     axis, size, cooXaxis) < 0) {
00075      MESSAGE("ERROR : write of axis X coordinates ...");
00076      goto ERROR;
00077    }
00078   axis++;
00079   size = 3;
00080   if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0, 
00081                                    axis, size, cooYaxis) < 0) {
00082     MESSAGE("ERROR : write of axis Y coordinates ...");
00083     goto ERROR;
00084   }
00085 
00086   /* optionnal : names for nodes or elements */
00087   /* In this case, a name is given to the cells of the mesh */
00088   if (MEDmeshEntityNameWr(fid, meshname, MED_NO_DT, MED_NO_IT,
00089                           MED_CELL, MED_QUAD4, nquad4, cellsnames) < 0) {
00090     MESSAGE("ERROR : cells names  ...");
00091     goto ERROR;
00092   }
00093   
00094   /* We have to create family 0 : by default, all mesh entities family number is 0 */
00095   if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
00096     MESSAGE("ERROR : quadrangular cells connectivity ...");
00097     goto ERROR;
00098   }
00099 
00100   /* We decide to create a family for boundary quad4 : 
00101      by convention a nodes family number is > 0 and an element family number is < 0 */
00102   if (MEDfamilyCr(fid, meshname,familyname, 1, -1, groupname) < 0) {
00103     MESSAGE("ERROR : family creation ...");
00104     goto ERROR;
00105   }
00106 
00107   /* Then we write family number for quad4 */
00108   if (MEDmeshEntityFamilyNumberWr(fid, meshname, MED_NO_DT, MED_NO_IT,
00109                                   MED_CELL, MED_QUAD4, nquad4, familynumbers) < 0) {
00110     MESSAGE("ERROR : nodes family numbers ...");
00111     goto ERROR;
00112   }    
00113 
00114   ret = 0;
00115  ERROR:
00116 
00117   /* close MED file  */
00118   if (MEDfileClose(fid) < 0) {
00119     MESSAGE("ERROR : close file ...");             
00120     ret = -1; 
00121   } 
00122 
00123   return ret;
00124 }
00125 

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