Back to index

salome-paravis  6.5.0
TestMedWriteOcta12.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 /*
00021  * TestMedWriteOcta12.cxx
00022  *
00023  *  Created on: 17 mars 2011
00024  *      Author: alejandro
00025  */
00026 
00027 #include <med.h>
00028 #define MESGERR 1
00029 #include <med_utils.h>
00030 
00031 #include <string.h>
00032 
00033 int main (int argc, char **argv) {
00034   med_idt fid;
00035   const char meshname[MED_NAME_SIZE+1] = "3D unstructured mesh";
00036   const med_int spacedim = 3;
00037   const med_int meshdim = 3;
00038   /*                                         12345678901234561234567890123456 */
00039   const char axisname[3*MED_SNAME_SIZE+1] = "x               y               z               ";
00040   const char unitname[3*MED_SNAME_SIZE+1] = "cm              cm              cm              ";
00041   const med_int nnodes = 20;
00042   const med_float coordinates[3 * 20] =
00043           { 0.,   0.,   1.,
00044             1.,   0.,   1.,
00045             1.5,  1.,   1.,
00046             1.,   2.,   1.,
00047             0.,   2.,   1.,
00048            -0.5,  1.,   1.,
00049             0.,   0.,   0.,
00050             1.,   0.,   0.,
00051             1.5,  1.,   0.,
00052             1.,   2.,   0.,
00053             0.,   2.,   0.,
00054            -0.5,  1.,   0.,
00055             2.5,  1.,   1.,
00056             3.,   2.,   1.,
00057             2.5,  2.5,  1.,
00058             1.5,  2.5,  1.,
00059             2.5,  1.,   0.,
00060             3.,   2.,   0.,
00061             2.5,  2.5,  0.,
00062             1.5,  2.5,  0.  };
00063 
00064   const med_int nOcta = 2;
00065   const med_int octa12Connectivity[12*2] =
00066      { 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12,
00067       13, 14, 15, 16,  4,  3, 17, 18, 19, 20, 10,  9 };
00068 
00069   /* open MED file */
00070   fid = MEDfileOpen("UsesCase_MEDmesh_19.med",
00071         MED_ACC_CREAT);
00072   if (fid < 0) {
00073     MESSAGE("ERROR : file creation ...");
00074     return -1;
00075   }
00076 
00077   /* write a comment in the file */
00078   if (MEDfileCommentWr(fid,
00079            "A 3D unstructured mesh : 2 Hexagonal Prisms") < 0) {
00080     MESSAGE("ERROR : write file description ...");
00081     return -1;
00082   }
00083 
00084   /* mesh creation : a 3D unstructured mesh */
00085   if (MEDmeshCr(fid,
00086     meshname,
00087     spacedim,
00088     meshdim,
00089     MED_UNSTRUCTURED_MESH,
00090     "A 3D mesh with 1 hexagonal in NODAL connectivity",
00091     "",
00092     MED_SORT_DTIT,
00093     MED_CARTESIAN,
00094     axisname,
00095     unitname) < 0) {
00096     MESSAGE("ERROR : mesh creation ...");
00097     return -1;
00098   }
00099 
00100   /* nodes coordinates in a cartesian axis in full interlace mode
00101      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
00102   */
00103   if (MEDmeshNodeCoordinateWr(fid,
00104             meshname,
00105             MED_NO_DT,
00106             MED_NO_IT,
00107             MED_UNDEF_DT,
00108             MED_FULL_INTERLACE,
00109             nnodes,
00110             coordinates) < 0) {
00111     MESSAGE("ERROR : nodes coordinates ...");
00112     return -1;
00113   }
00114 
00115   // cells connectiviy is defined in nodal mode
00116   if (MEDmeshElementConnectivityWr(fid,
00117            meshname,
00118            MED_NO_DT,
00119            MED_NO_IT,
00120            0.0,
00121            MED_CELL,
00122            MED_OCTA12,
00123            MED_NODAL,
00124            MED_FULL_INTERLACE,
00125            nOcta,
00126            octa12Connectivity) < 0) {
00127     MESSAGE("ERROR : triangular cells connectivity ...");
00128     return -1;
00129   }
00130 
00131   /* create family 0 : by default, all mesh entities family number is 0 */
00132   if (MEDfamilyCr(fid,
00133       meshname,
00134       "",
00135       0,
00136       0,
00137       "") < 0) {
00138     MESSAGE("ERROR : quadrangular cells connectivity ...");
00139     return -1;
00140   }
00141 
00142   /* close MED file */
00143   if (MEDfileClose(fid)  < 0) {
00144     MESSAGE("ERROR : close file ...");
00145     return -1;
00146   }
00147 
00148   return 0;
00149 }