Salome HOME
Update copyrights
[modules/paravis.git] / src / Plugins / MEDReader / IO / Testing / Cxx / TestMedWriteOcta12.cxx
1 // Copyright (C) 2010-2019  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  * TestMedWriteOcta12.cxx
22  *
23  *  Created on: 17 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 = 20;
42   const med_float coordinates[3 * 20] =
43           { 0.,   0.,   1.,
44             1.,   0.,   1.,
45             1.5,  1.,   1.,
46             1.,   2.,   1.,
47             0.,   2.,   1.,
48            -0.5,  1.,   1.,
49             0.,   0.,   0.,
50             1.,   0.,   0.,
51             1.5,  1.,   0.,
52             1.,   2.,   0.,
53             0.,   2.,   0.,
54            -0.5,  1.,   0.,
55             2.5,  1.,   1.,
56             3.,   2.,   1.,
57             2.5,  2.5,  1.,
58             1.5,  2.5,  1.,
59             2.5,  1.,   0.,
60             3.,   2.,   0.,
61             2.5,  2.5,  0.,
62             1.5,  2.5,  0.  };
63
64   const med_int nOcta = 2;
65   const med_int octa12Connectivity[12*2] =
66      { 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12,
67       13, 14, 15, 16,  4,  3, 17, 18, 19, 20, 10,  9 };
68
69   /* open MED file */
70   fid = MEDfileOpen("UsesCase_MEDmesh_19.med",
71         MED_ACC_CREAT);
72   if (fid < 0) {
73     MESSAGE("ERROR : file creation ...");
74     return -1;
75   }
76
77   /* write a comment in the file */
78   if (MEDfileCommentWr(fid,
79            "A 3D unstructured mesh : 2 Hexagonal Prisms") < 0) {
80     MESSAGE("ERROR : write file description ...");
81     return -1;
82   }
83
84   /* mesh creation : a 3D unstructured mesh */
85   if (MEDmeshCr(fid,
86     meshname,
87     spacedim,
88     meshdim,
89     MED_UNSTRUCTURED_MESH,
90     "A 3D mesh with 1 hexagonal in NODAL connectivity",
91     "",
92     MED_SORT_DTIT,
93     MED_CARTESIAN,
94     axisname,
95     unitname) < 0) {
96     MESSAGE("ERROR : mesh creation ...");
97     return -1;
98   }
99
100   /* nodes coordinates in a cartesian axis in full interlace mode
101      (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
102   */
103   if (MEDmeshNodeCoordinateWr(fid,
104             meshname,
105             MED_NO_DT,
106             MED_NO_IT,
107             MED_UNDEF_DT,
108             MED_FULL_INTERLACE,
109             nnodes,
110             coordinates) < 0) {
111     MESSAGE("ERROR : nodes coordinates ...");
112     return -1;
113   }
114
115   // cells connectiviy is defined in nodal mode
116   if (MEDmeshElementConnectivityWr(fid,
117            meshname,
118            MED_NO_DT,
119            MED_NO_IT,
120            0.0,
121            MED_CELL,
122            MED_OCTA12,
123            MED_NODAL,
124            MED_FULL_INTERLACE,
125            nOcta,
126            octa12Connectivity) < 0) {
127     MESSAGE("ERROR : triangular cells connectivity ...");
128     return -1;
129   }
130
131   /* create family 0 : by default, all mesh entities family number is 0 */
132   if (MEDfamilyCr(fid,
133       meshname,
134       "",
135       0,
136       0,
137       "") < 0) {
138     MESSAGE("ERROR : quadrangular cells connectivity ...");
139     return -1;
140   }
141
142   /* close MED file */
143   if (MEDfileClose(fid)  < 0) {
144     MESSAGE("ERROR : close file ...");
145     return -1;
146   }
147
148   return 0;
149 }