Back to index

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