Back to index

salome-paravis  6.5.0
TestMedDescendingPolyhedron.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  * TestMedDescendingPolyhedron.cxx
00022  *
00023  *  Created on: 3 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 = 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.,  1.618,    -1.,
00054             0., -1.618,    -1.  };
00055   const med_int nodeIndexSize = 20;
00056   const med_int nodeindex[20] = {
00057           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3,
00058           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3,
00059           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3,
00060           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3 };
00061   const med_int faceIndexSize = 2;
00062   /* connectivity : 1 icosahedron */
00063   const med_int faceindex[2] = { 1, 21 };
00064 
00065   const med_int connectivity[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,
00066                                     11,12,13,14,15,16,17,18,19,20 };
00067 
00068   const med_int ntria3 = 20;
00069   const med_int triaConnectivity[60] = { 1,  9,  5,
00070                                      1,  6, 11,
00071                                      3,  5, 10,
00072                                      3, 12,  6,
00073                                      2,  7,  9,
00074                                      2, 11,  8,
00075                                      4, 10,  7,
00076                                      4,  8, 12,
00077                                      1, 11,  9,
00078                                      2,  9, 11,
00079                                      3, 10, 12,
00080                                      4, 10, 12,
00081                                      5,  3,  1,
00082                                      6,  1,  3,
00083                                      7,  2,  4,
00084                                      8,  4,  2,
00085                                      9,  7,  5,
00086                                     10,  5,  7,
00087                                     11,  6,  8,
00088                                     12,  8,  6  };
00089 
00090   /* open MED file */
00091   fid = MEDfileOpen("UsesCase_MEDmesh_17.med",
00092         MED_ACC_CREAT);
00093   if (fid < 0) {
00094     MESSAGE("ERROR : file creation ...");
00095     return -1;
00096   }
00097 
00098   /* write a comment in the file */
00099   if (MEDfileCommentWr(fid,
00100            "A 3D unstructured mesh : 1 icosahedron") < 0) {
00101     MESSAGE("ERROR : write file description ...");
00102     return -1;
00103   }
00104 
00105   /* mesh creation : a 3D unstructured mesh */
00106   if (MEDmeshCr(fid,
00107     meshname,
00108     spacedim,
00109     meshdim,
00110     MED_UNSTRUCTURED_MESH,
00111     "A 3D mesh with 1 icosahedron in DESCENDING connectivity",
00112     "",
00113     MED_SORT_DTIT,
00114     MED_CARTESIAN,
00115     axisname,
00116     unitname) < 0) {
00117     MESSAGE("ERROR : mesh creation ...");
00118     return -1;
00119   }
00120 
00121   /* nodes coordinates in a cartesian axis in full interlace mode
00122      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
00123   */
00124   if (MEDmeshNodeCoordinateWr(fid,
00125             meshname,
00126             MED_NO_DT,
00127             MED_NO_IT,
00128             MED_UNDEF_DT,
00129             MED_FULL_INTERLACE,
00130             nnodes,
00131             coordinates) < 0) {
00132     MESSAGE("ERROR : nodes coordinates ...");
00133     return -1;
00134   }
00135 
00136   // cells connectiviy is defined in nodal mode
00137   // it is later in the polyhedron thet the connectivity is descending
00138   if (MEDmeshElementConnectivityWr(fid,
00139            meshname,
00140            MED_NO_DT,
00141            MED_NO_IT,
00142            0.0,
00143            MED_DESCENDING_FACE,
00144            MED_TRIA3,
00145            MED_NODAL,
00146            MED_FULL_INTERLACE,
00147            ntria3,
00148            triaConnectivity) < 0) {
00149     MESSAGE("ERROR : triangular cells connectivity ...");
00150     return -1;
00151   }
00152 
00153   // cells connectiviy is defined in descending mode
00154   // 1 icosahedron
00155   if (MEDmeshPolyhedronWr(fid,
00156               meshname,
00157               MED_NO_DT,
00158               MED_NO_IT,
00159               MED_UNDEF_DT,
00160               MED_CELL,
00161               MED_DESCENDING,
00162               faceIndexSize,
00163               faceindex,
00164               nodeIndexSize,
00165               nodeindex,
00166               connectivity) < 0) {
00167     MESSAGE("ERROR : polyhedron connectivity ...");
00168     return -1;
00169   }
00170 
00171   /* create family 0 : by default, all mesh entities family number is 0 */
00172   if (MEDfamilyCr(fid,
00173       meshname,
00174       "",
00175       0,
00176       0,
00177       "") < 0) {
00178     MESSAGE("ERROR : quadrangular cells connectivity ...");
00179     return -1;
00180   }
00181 
00182   /* close MED file */
00183   if (MEDfileClose(fid)  < 0) {
00184     MESSAGE("ERROR : close file ...");
00185     return -1;
00186   }
00187 
00188   return 0;
00189 }