Salome HOME
MEDMEM suppression
[modules/med.git] / src / MEDMEMBinTest / create_mesh_c2q4s2_wrong.c
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 /*
24   creation d'une geometrie 2d : un cube [0,1]^2
25   maillĂ© uniformement en quadrangle reguliers;
26   avec en plus une partie des aretes (une partie
27   des arretes de la frontiere) du maillage.
28   ATTENTION : 3 noeuds dans chaque direction
29 */
30
31 #include <med.h>
32 #include <string.h>
33 #include <stdlib.h>
34
35 int main (int argc, char **argv)
36 {
37   med_err ret;
38   med_idt fid;
39   char maa[MED_NAME_SIZE+1] = "carre_en_quad4_seg2_wrong";
40   char maadesc[MED_COMMENT_SIZE+1] = "Example de maillage non structure 2D";
41   med_int mdim = 2;
42   med_int nnoe = 9;
43   /*
44     les noeuds:
45   */
46   med_float coo[18] = {
47     0.0, 0.0,
48     0.5, 0.0,
49     1.0, 0.0,
50     0.0, 0.5,
51     0.5, 0.5,
52     1.0, 0.5,
53     0.0, 1.0,
54     0.5, 1.0,
55     1.0, 1.0
56   };
57   char nomcoo[2*MED_SNAME_SIZE+1] = "x               y               ";
58   char unicoo[2*MED_SNAME_SIZE+1] = "cm              cm              ";
59   /*  char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
60   //char *nomnoe ;
61 //  med_int numnoe[9] = {1,2,3,4,5,6,7,8,9};
62   med_int nufano[9] = {0,0,0,0,0,0,0,0,0};
63   /*
64     les elements:
65   */
66   med_int nquad4 = 4;
67   med_int quad4[16] = {
68     4, 5, 2, 1,
69     5, 6, 3, 2,
70     7, 8, 5, 4,
71     8, 9, 6, 5
72   };
73  // char nomquad4[MED_TAILLE_PNOM*4+1] = "quad1           quad2           quad3           quad4           ";
74  // med_int numquad4[4] = {1,2,3,4};
75   med_int nufaquad4[4] = {-10,-10,0,0};
76
77   /*
78     Les Faces qui dans ce cas (2D) sont des arretes
79
80     a face is wrongly oriented, it is just to test the applidation
81     duplicateMEDMESH
82   */
83
84   med_int nseg2 = 6;
85   med_int seg2[12] = {
86     6, 3,
87     8, 9,
88     3, 2,
89     /*9, 6,*/
90     6, 9,
91     2, 5,
92     5, 8
93   };
94  // char nomseg2[MED_TAILLE_PNOM*6+1] = "seg1            seg2            seg3            seg4            seg5            seg6            ";
95  // med_int numseg2[6] = {1,2,3,4,5,6};
96   med_int nufaseg2[6] = {-1,-2,-1,-1,-2,-2};
97
98   char nomfam[MED_NAME_SIZE+1];
99   med_int numfam;
100   //char attdesMED_TAILLE_DESC+1];
101   med_int natt;
102   med_int attide;
103   med_int attval;
104   med_int ngro;
105   char gro[MED_LNAME_SIZE+1];
106   char dtunitp3[MED_LNAME_SIZE+1]="";
107
108   /*
109     Some fields : 2 on nodes : one int and one double , one on cells : double
110    */
111   char champ1[MED_NAME_SIZE+1]="fieldnodeint" ;
112   char champ1_comp[MED_SNAME_SIZE+1]="comp1           " ;
113   char champ1_unit[MED_SNAME_SIZE+1]="M               " ;
114   med_int     fieldnodeint[9]    = {1,1,3,2,2,3,4,4,5};
115
116   char champ2[MED_NAME_SIZE+1]="fieldnodedouble" ;
117   char champ2_comp[MED_SNAME_SIZE+1]="comp1           " ;
118   char champ2_unit[MED_SNAME_SIZE+1]="J               " ;
119   med_float   fieldnodedouble1[9] = {1.,3.,4.,1.,3.,4.,3.,2.,5.};
120   med_float   fieldnodedouble2[9] = {1.,2.,2.,3.,3.,3.,4.,4.,5.};
121
122   char champ3[MED_NAME_SIZE+1]="fieldcelldouble" ;
123   char champ3_comp[MED_SNAME_SIZE*2+1]="comp1           comp2           " ;
124   char champ3_unit[MED_SNAME_SIZE*2+1]="M/S             m/s             " ;
125   med_float   fieldcelldouble[4*2] = {0.,1.,1.,1.,1.,2.,2.,3.};
126
127   /***************************************************************************/
128   fid = MEDfileOpen("carre_en_quad4_seg2_wrong.med",MED_ACC_RDWR);
129   if (fid < 0)
130     ret = -1;
131   else
132     ret = 0;
133   printf("MEDouvrir : %d\n",ret);
134
135   /***************************************************************************/
136   if (ret == 0)
137     ret = MEDmeshCr(fid,maa,mdim,mdim,MED_UNSTRUCTURED_MESH,maadesc,dtunitp3,
138                     MED_SORT_DTIT,MED_CARTESIAN,nomcoo,unicoo);
139   printf("MEDmaaCr : %d\n",ret);
140   if (ret == 0)
141     ret = MEDunvCr(fid,maa);
142   printf("MEDunvCr : %d\n",ret);
143
144   /***************************************************************************/
145   if (ret == 0)
146     ret = MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,MED_FULL_INTERLACE,nnoe,coo);
147   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,0,nnoe,nufano);
148   printf("MEDnoeudsEcr : %d\n",ret);
149
150   /* ecriture des mailles MED_QUAD4 :
151      - connectivite
152      - noms (optionnel) 
153      - numeros (optionnel)
154      - numeros des familles */
155   if (ret == 0) 
156     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
157                                        MED_CELL,MED_QUAD4,MED_NODAL,MED_FULL_INTERLACE,
158                                        nquad4,quad4);
159   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_QUAD4,nquad4,nufaquad4);
160   printf("MEDelementsEcr : %d \n",ret);
161
162   /* ecriture des mailles MED_SEG2 :
163      - connectivite
164      - noms (optionnel) 
165      - numeros (optionnel)
166      - numeros des familles */
167   if (ret == 0) 
168     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
169                                        MED_CELL,MED_SEG2,MED_NODAL,MED_FULL_INTERLACE,
170                                        nseg2,seg2);
171   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_SEG2,nseg2,nufaseg2);
172   printf("MEDelementsEcr : %d \n",ret);
173
174   /***************************************************************************/
175   /* ecriture des familles */
176   /* Conventions :
177      - toujours creer une famille de numero 0 ne comportant aucun attribut
178        ni groupe (famille de reference pour les noeuds ou les elements
179        qui ne sont rattaches a aucun groupe ni attribut)
180      - les numeros de familles de noeuds sont > 0
181      - les numeros de familles des elements sont < 0
182      - rien d'imposer sur les noms de familles
183    */ 
184
185   /* la famille 0 */
186   if (ret == 0)
187     {
188       strcpy(nomfam,"FAMILLE_0");
189       numfam = 0;
190       ret = MEDfamilyCr(fid,maa,nomfam,numfam,0,gro);
191     }
192   printf("%d \n",ret);
193
194   /* on cree :
195       - 1 familles d'elements de dimension (d-1)
196         en fait de edge (-1)
197       - 1 familles d'elements de dimension (d-1)
198         en fait de edge (-2)
199       - 1 familles d'elements de dimension (d)
200         en fait de face (-10)
201   */
202
203   if (ret == 0)
204     {
205       numfam = -1;
206       strcpy(nomfam,"FAMILLE_EDGE_");
207       sprintf(nomfam,"%s%d",nomfam,-numfam);
208       attide = 1;
209       attval = numfam*100;
210       natt = 1;
211       //strcpy(attdes,"description attribut");
212       strcpy(gro,"groupe1");
213       ngro = 1;
214
215       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
216       printf("MEDfamCr : %d\n",ret);
217     }
218   if (ret == 0)
219     {
220       numfam = -2;
221       strcpy(nomfam,"FAMILLE_EDGE_");
222       sprintf(nomfam,"%s%d",nomfam,-numfam);
223       attide = 1;
224       attval = numfam*100;
225       natt = 1;
226       //strcpy(attdes,"description attribut");
227       strcpy(gro,"groupe1");
228       ngro = 1;
229
230       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
231       printf("MEDfamCr : %d\n",ret);
232     }
233   if (ret == 0)
234     {
235       numfam = -10;
236       strcpy(nomfam,"FAMILLE_CELL_");
237       sprintf(nomfam,"%s%d",nomfam,-numfam);
238       attide = 1;
239       attval = numfam*100;
240       natt = 1;
241       //strcpy(attdes,"description attribut");
242       strcpy(gro,"groupe0");
243       ngro = 1;
244
245       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
246       printf("MEDfamCr : %d\n",ret);
247     }
248   /***************************************************************************/
249   /*
250     Les champs
251   */
252   if (ret == 0)
253     {
254       ret = MEDfieldCr(fid,champ1,MED_INT32,1,champ1_comp,champ1_unit,dtunitp3,maa);
255       printf("MEDchampCr : %d \n",ret);
256       if (ret == 0) {
257         ret = MEDfieldValueWr(fid, champ1,MED_NO_DT,MED_NO_IT,0.,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodeint);
258         
259         printf("MEDchampEcr : %d \n",ret);
260       }
261     }
262   
263   if (ret == 0)
264     {
265       ret = MEDfieldCr(fid,champ2,MED_FLOAT64,1,champ2_comp,champ2_unit,dtunitp3,maa);
266       printf("MEDchampCr : %d \n",ret);
267       if (ret == 0) {
268         ret = MEDfieldValueWr(fid, champ2,1,MED_NO_IT,1.1 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
269         printf("MEDchampEcr1 : %d \n",ret);
270         ret = MEDfieldValueWr(fid, champ2,2,MED_NO_IT,1.2 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble2);
271         printf("MEDchampEcr2 : %d \n",ret);
272       }
273     }
274   
275   /* on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !*/
276   if (ret == 0)
277     {
278       ret = MEDfieldValueWr(fid, champ2,MED_NO_DT,MED_NO_IT,0. ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
279       printf("MEDchampEcr : %d \n",ret); 
280     }
281
282   if (ret == 0)
283     {
284       ret = MEDfieldCr(fid,champ3,MED_FLOAT64,2,champ3_comp,champ3_unit,dtunitp3,maa);
285       printf("MEDchampCr : %d \n",ret);
286       if (ret == 0) {
287         ret = MEDfieldValueWr(fid, champ3,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_QUAD4,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nquad4, (unsigned char *)fieldcelldouble);
288         printf("MEDchampEcr : %d \n",ret);
289       }
290     }
291   
292   /***************************************************************************/
293
294   ret = MEDfermer(fid);
295   printf("%d\n",ret);
296   
297   if ( getenv("srcdir") ) 
298     /* we are in 'make check' */
299     remove( "carre_en_quad4_seg2_wrong.med" );
300
301   return 0;
302 }