Salome HOME
Merge branch V7_3_1_BR
[modules/paravis.git] / src / Plugins / MEDReader / IO / Testing / Cxx / TestMedPolyhedron.cxx
1 // Copyright (C) 2010-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 /*
21  * TestMedPolyhedron.cxx
22  *
23  *  Created on: 15 févr. 2011
24  *      Author: alejandro
25  */
26
27 #include <med.h>
28 #define MESGERR 1
29 #include <med_utils.h>
30
31 #include <string.h>
32
33 int main (int argc, char **argv) {
34   med_idt fid;
35   const char meshname[MED_NAME_SIZE+1] = "3D unstructured mesh";
36   const med_int spacedim = 3;
37   const med_int meshdim = 3;
38   /*                                         12345678901234561234567890123456 */
39   const char axisname[3*MED_SNAME_SIZE+1] = "x               y               z               ";
40   const char unitname[3*MED_SNAME_SIZE+1] = "cm              cm              cm              ";
41   const med_int nnodes = 12;
42   const med_float coordinates[3 * 12] =
43           { 1.618,  1.,     0.,
44            -1.618,  1.,     0.,
45             1.618, -1.,     0.,
46            -1.618, -1.,     0.,
47             1.,     0.,     1.618,
48             1.,     0.,    -1.618,
49            -1.,     0.,     1.618,
50            -1.,     0.,    -1.618,
51             0.,  1.618,     1.,
52             0., -1.618,     1.,
53             0.,  0,    0.,
54 //            0.,  1.618,    -1.,
55             0., -1.618,    -1.  };
56   const med_int faceIndexSize = 2;
57   const med_int faceindex[2] = {1,22};
58   const med_int nodeIndexSize = 21;
59   /* connectivity : 1 icosahedron */
60   const med_int nodeindex[21] = { 1, 4, 7,10,13,16,19,22,25,28,
61                                  31,34,37,40,43,46,49,52,55,58,61 };
62   const med_int connectivity[60] = { 1,  9,  5,
63                                      1,  6, 11,
64                                      3,  5, 10,
65                                      3, 12,  6,
66                                      2,  7,  9,
67                                      2, 11,  8,
68                                      4, 10,  7,
69                                      4,  8, 12,
70                                      1, 11,  9,
71                                      2,  9, 11,
72                                      3, 10, 12,
73                                      4, 10, 12,
74                                      5,  3,  1,
75                                      6,  1,  3,
76                                      7,  2,  4,
77                                      8,  4,  2,
78                                      9,  7,  5,
79                                     10,  5,  7,
80                                     11,  6,  8,
81                                     12,  8,  6  };
82
83   /* open MED file */
84   fid = MEDfileOpen("UsesCase_MEDmesh_15.med",
85         MED_ACC_CREAT);
86   if (fid < 0) {
87     MESSAGE("ERROR : file creation ...");
88     return -1;
89   }
90
91   /* write a comment in the file */
92   if (MEDfileCommentWr(fid,
93            "A 3D unstructured mesh : 1 icosahedron") < 0) {
94     MESSAGE("ERROR : write file description ...");
95     return -1;
96   }
97
98   /* mesh creation : a 3D unstructured mesh */
99   if (MEDmeshCr(fid,
100     meshname,
101     spacedim,
102     meshdim,
103     MED_UNSTRUCTURED_MESH,
104     "A 3D mesh with 1 icosahedron",
105     "",
106     MED_SORT_DTIT,
107     MED_CARTESIAN,
108     axisname,
109     unitname) < 0) {
110     MESSAGE("ERROR : mesh creation ...");
111     return -1;
112   }
113
114   /* nodes coordinates in a cartesian axis in full interlace mode
115      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
116   */
117   if (MEDmeshNodeCoordinateWr(fid,
118             meshname,
119             MED_NO_DT,
120             MED_NO_IT,
121             MED_UNDEF_DT,
122             MED_FULL_INTERLACE,
123             nnodes,
124             coordinates) < 0) {
125     MESSAGE("ERROR : nodes coordinates ...");
126     return -1;
127   }
128
129   /* cells connectiviy is defined in nodal mode */
130   /* 1 icosahedron */
131   if (MEDmeshPolyhedronWr(fid,
132               meshname,
133               MED_NO_DT,
134               MED_NO_IT,
135               MED_UNDEF_DT,
136               MED_CELL,
137               MED_NODAL,
138               faceIndexSize,
139               faceindex,
140               nodeIndexSize,
141               nodeindex,
142               connectivity) < 0) {
143     MESSAGE("ERROR : polyhedron connectivity ...");
144     return -1;
145   }
146
147   /* create family 0 : by default, all mesh entities family number is 0 */
148   if (MEDfamilyCr(fid,
149       meshname,
150       "",
151       0,
152       0,
153       "") < 0) {
154     MESSAGE("ERROR : quadrangular cells connectivity ...");
155     return -1;
156   }
157
158   /* close MED file */
159   if (MEDfileClose(fid)  < 0) {
160     MESSAGE("ERROR : close file ...");
161     return -1;
162   }
163
164   return 0;
165 }