Salome HOME
Merge from V6_main 01/04/2013
[modules/paravis.git] / src / Plugins / MedReader / IO / Testing / Cxx / TestMedDescendingPolyhedron.cxx
1 // Copyright (C) 2010-2013  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.
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  * TestMedDescendingPolyhedron.cxx
22  *
23  *  Created on: 3 mars 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.,  1.618,    -1.,
54             0., -1.618,    -1.  };
55   const med_int nodeIndexSize = 20;
56   const med_int nodeindex[20] = {
57           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3,
58           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3,
59           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3,
60           MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3, MED_TRIA3 };
61   const med_int faceIndexSize = 2;
62   /* connectivity : 1 icosahedron */
63   const med_int faceindex[2] = { 1, 21 };
64
65   const med_int connectivity[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,
66                                     11,12,13,14,15,16,17,18,19,20 };
67
68   const med_int ntria3 = 20;
69   const med_int triaConnectivity[60] = { 1,  9,  5,
70                                      1,  6, 11,
71                                      3,  5, 10,
72                                      3, 12,  6,
73                                      2,  7,  9,
74                                      2, 11,  8,
75                                      4, 10,  7,
76                                      4,  8, 12,
77                                      1, 11,  9,
78                                      2,  9, 11,
79                                      3, 10, 12,
80                                      4, 10, 12,
81                                      5,  3,  1,
82                                      6,  1,  3,
83                                      7,  2,  4,
84                                      8,  4,  2,
85                                      9,  7,  5,
86                                     10,  5,  7,
87                                     11,  6,  8,
88                                     12,  8,  6  };
89
90   /* open MED file */
91   fid = MEDfileOpen("UsesCase_MEDmesh_17.med",
92         MED_ACC_CREAT);
93   if (fid < 0) {
94     MESSAGE("ERROR : file creation ...");
95     return -1;
96   }
97
98   /* write a comment in the file */
99   if (MEDfileCommentWr(fid,
100            "A 3D unstructured mesh : 1 icosahedron") < 0) {
101     MESSAGE("ERROR : write file description ...");
102     return -1;
103   }
104
105   /* mesh creation : a 3D unstructured mesh */
106   if (MEDmeshCr(fid,
107     meshname,
108     spacedim,
109     meshdim,
110     MED_UNSTRUCTURED_MESH,
111     "A 3D mesh with 1 icosahedron in DESCENDING connectivity",
112     "",
113     MED_SORT_DTIT,
114     MED_CARTESIAN,
115     axisname,
116     unitname) < 0) {
117     MESSAGE("ERROR : mesh creation ...");
118     return -1;
119   }
120
121   /* nodes coordinates in a cartesian axis in full interlace mode
122      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
123   */
124   if (MEDmeshNodeCoordinateWr(fid,
125             meshname,
126             MED_NO_DT,
127             MED_NO_IT,
128             MED_UNDEF_DT,
129             MED_FULL_INTERLACE,
130             nnodes,
131             coordinates) < 0) {
132     MESSAGE("ERROR : nodes coordinates ...");
133     return -1;
134   }
135
136   // cells connectiviy is defined in nodal mode
137   // it is later in the polyhedron thet the connectivity is descending
138   if (MEDmeshElementConnectivityWr(fid,
139            meshname,
140            MED_NO_DT,
141            MED_NO_IT,
142            0.0,
143            MED_DESCENDING_FACE,
144            MED_TRIA3,
145            MED_NODAL,
146            MED_FULL_INTERLACE,
147            ntria3,
148            triaConnectivity) < 0) {
149     MESSAGE("ERROR : triangular cells connectivity ...");
150     return -1;
151   }
152
153   // cells connectiviy is defined in descending mode
154   // 1 icosahedron
155   if (MEDmeshPolyhedronWr(fid,
156               meshname,
157               MED_NO_DT,
158               MED_NO_IT,
159               MED_UNDEF_DT,
160               MED_CELL,
161               MED_DESCENDING,
162               faceIndexSize,
163               faceindex,
164               nodeIndexSize,
165               nodeindex,
166               connectivity) < 0) {
167     MESSAGE("ERROR : polyhedron connectivity ...");
168     return -1;
169   }
170
171   /* create family 0 : by default, all mesh entities family number is 0 */
172   if (MEDfamilyCr(fid,
173       meshname,
174       "",
175       0,
176       0,
177       "") < 0) {
178     MESSAGE("ERROR : quadrangular cells connectivity ...");
179     return -1;
180   }
181
182   /* close MED file */
183   if (MEDfileClose(fid)  < 0) {
184     MESSAGE("ERROR : close file ...");
185     return -1;
186   }
187
188   return 0;
189 }