]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/create_mesh_c3h8q4_wrong.c
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/med.git] / src / MEDMEM / create_mesh_c3h8q4_wrong.c
1 /*----------------------------------------------------------------------------
2 MED MEDMEM : MED files in memory
3
4  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
6
7  This library is free software; you can redistribute it and/or 
8  modify it under the terms of the GNU Lesser General Public 
9  License as published by the Free Software Foundation; either 
10  version 2.1 of the License. 
11
12  This library is distributed in the hope that it will be useful, 
13  but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
15  Lesser General Public License for more details. 
16
17  You should have received a copy of the GNU Lesser General Public 
18  License along with this library; if not, write to the Free Software 
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
20
21  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
22
23
24
25   File   : create_mesh_c3h8q4_wrong.c
26 Module : MED
27 ----------------------------------------------------------------------------*/
28
29 /*
30   creation d'une geometrie 3d : un cube [0,1]^3
31   maillé uniformement en hexahedres reguliers;
32   avec en plus une partie des faces (une partie
33   des faces de la frontiere) du maillage.
34   ATTENTION : 3 noeuds dans chaque direction
35 */
36
37 #include <med.h>
38 #include <string.h>
39
40 int main (int argc, char **argv)
41 {
42   med_err ret;
43   med_idt fid;
44   char maa[MED_TAILLE_NOM+1] = "CUBE_EN_HEXA8_QUAD4_WRONG";
45   med_int mdim = 3;
46   med_int nnoe = 27;
47   /*
48     les noeuds:
49   */
50   med_float coo[81] = {
51     0.0, 0.0, 0.0, 
52     0.5, 0.0, 0.0, 
53     1.0, 0.0, 0.0, 
54     0.0, 0.5, 0.0, 
55     0.5, 0.5, 0.0, 
56     1.0, 0.5, 0.0, 
57     0.0, 1.0, 0.0, 
58     0.5, 1.0, 0.0, 
59     1.0, 1.0, 0.0, 
60     0.0, 0.0, 0.5, 
61     0.5, 0.0, 0.5, 
62     1.0, 0.0, 0.5, 
63     0.0, 0.5, 0.5, 
64     0.5, 0.5, 0.5, 
65     1.0, 0.5, 0.5, 
66     0.0, 1.0, 0.5, 
67     0.5, 1.0, 0.5, 
68     1.0, 1.0, 0.5, 
69     0.0, 0.0, 1.0, 
70     0.5, 0.0, 1.0, 
71     1.0, 0.0, 1.0, 
72     0.0, 0.5, 1.0, 
73     0.5, 0.5, 1.0, 
74     1.0, 0.5, 1.0, 
75     0.0, 1.0, 1.0, 
76     0.5, 1.0, 1.0, 
77     1.0, 1.0, 1.0
78   };
79   char nomcoo[3*MED_TAILLE_PNOM+1] = "x       y       z       ";
80   char unicoo[3*MED_TAILLE_PNOM+1] = "cm      cm      cm      ";
81   /*  char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
82   char *nomnoe ;
83   med_int numnoe[27] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27};
84   med_int nufano[27] = {1,1,1,1,1,1,1,1,1,3,3,3,3,0,3,3,3,3,2,2,2,2,2,2,2,2,2};
85   /*
86     les elements:
87   */
88   med_int nhexa8 = 8;
89   med_int hexa8[64] = {
90     4, 13, 14, 5, 1, 10, 11, 2,
91     5, 14, 15, 6, 2, 11, 12, 3,
92     7, 16, 17, 8, 4, 13, 14, 5,
93     8, 17, 18, 9, 5, 14, 15, 6,
94     13, 22, 23, 14, 10, 19, 20, 11,
95     14, 23, 24, 15, 11, 20, 21, 12,
96     16, 25, 26, 17, 13, 22, 23, 14,
97     17, 26, 27, 18, 14, 23, 24, 15
98   };
99   char nomhexa8[MED_TAILLE_PNOM*8+1] = "hexa1   hexa2   hexa3   hexa4   hexa5   hexa6   hexa7   hexa8   ";
100   med_int numhexa8[8] = {1,2,3,4,5,6,7,8};
101   med_int nufahexa8[8] = {-1,-1,-1,-1,-2,-2,-2,-2};
102
103   /*
104     Les Faces qui dans ce cas (2D) sont des arretes
105
106     a face is wrongly oriented, it is just to test the applidation
107     duplicateMEDMESH
108   */
109
110   med_int nquad4 = 8;
111   med_int quad4[32] = {
112     20, 21, 24, 23,
113     22, 23, 26, 25,
114     19, 20, 23, 22,
115     23, 24, 27, 26,
116     /*1 , 4, 5, 2,*/
117     1 , 2, 5, 4,
118     5, 8, 9, 6, 
119     2, 5, 6, 3, 
120     7, 8, 5, 4
121   };
122
123   char nomquad4[MED_TAILLE_PNOM*8+1] = "quad1   quad2   quad3   quad4   quad5   quad6   quad7   quad8  ";
124   med_int numquad4[8] = {1,2,3,4,5,6,7,8};
125   med_int nufaquad4[8] = {-3,-3,-3,-3,-4, -4, -4 , -4};
126
127   char nomfam[MED_TAILLE_NOM+1];
128   med_int numfam;
129   char attdes[MED_TAILLE_DESC+1];
130   med_int natt;
131   med_int attide;
132   med_int attval;
133   med_int ngro;
134   char gro[MED_TAILLE_LNOM+1];
135   int i;
136   int nfame = 1; 
137   int nfamn = 1;
138   int nfamf = 1;
139
140   /*
141     Some fields : 2 on nodes : one int and one double , one on cells : double
142   */
143
144   char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ;
145   char champ1_comp[MED_TAILLE_PNOM+1]="comp1   " ;
146   char champ1_unit[MED_TAILLE_PNOM+1]="M       " ;
147   med_int fieldnodeint[27] = {1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5};
148
149   char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ;
150   char champ2_comp[MED_TAILLE_PNOM+1]="comp1   " ;
151   char champ2_unit[MED_TAILLE_PNOM+1]="J       " ;
152   med_float fieldnodedouble1[27] = {1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.};
153   med_float fieldnodedouble2[27] = {1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.};
154
155   char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ;
156   char champ3_comp[MED_TAILLE_PNOM*3+1]="comp1   comp2   comp3   " ;
157   char champ3_unit[MED_TAILLE_PNOM*3+1]="M/S     m/s     m/s     " ;
158   med_float fieldcelldouble[8*3] = {0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.};
159
160   /***************************************************************************/
161   fid = MEDouvrir("cube_hexa8_quad4_wrong.med",MED_REMP);
162   if (fid < 0)
163     ret = -1;
164   else
165     ret = 0;
166   printf("%d\n",ret);
167
168   /***************************************************************************/
169   if (ret == 0)
170     ret = MEDmaaCr(fid,maa,mdim);
171   printf("%d\n",ret);
172   if (ret == 0)
173     ret = MEDunvCr(fid,maa);
174   printf("%d\n",ret);
175
176   /***************************************************************************/
177   if (ret == 0)
178     ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
179                        nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
180                        nufano,nnoe,MED_ECRI);
181   printf("%d\n",ret);
182
183   /* ecriture des mailles MED_HEXA8 :
184      - connectivite
185      - noms (optionnel) 
186      - numeros (optionnel)
187      - numeros des familles */
188   if (ret == 0) 
189     ret = MEDelementsEcr(fid,maa,mdim,hexa8,MED_FULL_INTERLACE,
190                          nomhexa8,MED_FAUX,numhexa8,MED_VRAI,nufahexa8,nhexa8,
191                          MED_MAILLE,MED_HEXA8,MED_NOD,MED_ECRI);
192   printf("%d \n",ret);
193
194   /* ecriture des mailles MED_QUAD4 :
195      - connectivite
196      - noms (optionnel) 
197      - numeros (optionnel)
198      - numeros des familles */
199   if (ret == 0) 
200     ret = MEDelementsEcr(fid,maa,mdim,quad4,MED_FULL_INTERLACE,
201                          nomquad4,MED_FAUX,numquad4,MED_VRAI,nufaquad4,nquad4,
202                          MED_FACE,MED_QUAD4,MED_NOD,MED_ECRI);
203   printf("%d \n",ret);
204
205   /***************************************************************************/
206   /* ecriture des familles */
207   /* Conventions :
208      - toujours creer une famille de numero 0 ne comportant aucun attribut
209        ni groupe (famille de reference pour les noeuds ou les elements
210        qui ne sont rattaches a aucun groupe ni attribut)
211      - les numeros de familles de noeuds sont > 0
212      - les numeros de familles des elements sont < 0
213      - rien d'imposer sur les noms de familles
214    */ 
215
216   /* la famille 0 */
217   if (ret == 0)
218     {
219       strcpy(nomfam,"FAMILLE_0");
220       numfam = 0;
221       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
222                      gro,0);
223     }
224   printf("%d \n",ret);
225
226   /* on cree :
227       - 2 familles d'elements (-1,-2) et 
228       - 3 familles de noeuds (1,2,3) 
229       - 1 famille(s) d'elements de dimension (d-1)
230         en fait de face (-3)
231   */
232
233   if (ret == 0)
234     {
235       nfame = 2;
236       for (i=0;i<nfame;i++)
237         {
238           if (ret == 0)
239             {
240               strcpy(nomfam,"FAMILLE_ELEMENT_");
241               numfam = -(i+1);
242               sprintf(nomfam,"%s%d",nomfam,-numfam);
243               attide = 1;
244               attval = numfam*100;
245               natt = 1;
246               strcpy(attdes,"description attribut");
247               strcpy(gro,"groupe1");
248               ngro = 1;
249
250               /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
251
252               ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
253                              natt,gro,ngro);
254               printf("MEDfamCr : %d\n",ret);
255             }
256         }
257     }
258   
259   if (ret == 0)
260     {
261       nfamn = 3;
262       for (i=0;i<nfamn;i++)
263         {
264           if(ret == 0)
265             {
266               strcpy(nomfam,"FAMILLE_NOEUD_");
267               numfam = i+1;
268               sprintf(nomfam,"%s%d",nomfam,numfam);
269               attide = 1;
270               attval = numfam*100;
271               natt = 1;
272               strcpy(attdes,"description attribut");
273               strcpy(gro,"groupe2");
274               ngro = 1;
275               ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
276                              natt,gro,ngro);
277               printf("MEDfamCr : %d\n",ret);
278             }
279         }
280     }
281
282   if (ret == 0)
283     {
284       nfamf = 2;
285       for (i=0;i<nfamf;i++)
286         {
287           if (ret == 0)
288             {
289               strcpy(nomfam,"FAMILLE_FACE_");
290               numfam = -(i+3);
291               sprintf(nomfam,"%s%d",nomfam,-numfam);
292               attide = 1;
293               attval = numfam*100;
294               natt = 1;
295               strcpy(attdes,"description attribut");
296               strcpy(gro,"groupe3");
297               ngro = 1;
298               /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
299               ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
300                              natt,gro,ngro);
301               printf("MEDfamCr : %d\n",ret);
302             }
303         }
304     }
305
306   /***************************************************************************/
307   /*
308     Les champs
309   */
310   if (ret == 0)
311     {
312       ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
313       printf("MEDchampCr : %d \n",ret);
314       if (ret == 0) {
315         ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
316                           MED_FULL_INTERLACE, nnoe,
317                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
318                           0, MED_NOPDT,"        ", 0., MED_NONOR);
319         
320         printf("MEDchampEcr : %d \n",ret);
321       }
322     }
323   
324   if (ret == 0)
325     {
326       ret = MEDchampCr(fid,champ2,MED_REEL64,champ2_comp,champ2_unit,1);
327       printf("MEDchampCr : %d \n",ret);
328       if (ret == 0) {
329         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
330                           MED_FULL_INTERLACE, nnoe,
331                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
332                           0, 1,"S       ", 1.1 , MED_NONOR);
333         printf("MEDchampEcr1 : %d \n",ret);
334         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
335                           MED_FULL_INTERLACE, nnoe,
336                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
337                           0, 2,"S       ", 1.2 , MED_NONOR);
338         printf("MEDchampEcr2 : %d \n",ret);
339       }
340     }
341   
342   // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !
343   if (ret == 0)
344     {
345       ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
346                         MED_FULL_INTERLACE, nnoe,
347                         MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
348                         0, MED_NOPDT,"        ", 0. , MED_NONOR);
349       printf("MEDchampEcr : %d \n",ret); 
350     }
351
352   if (ret == 0)
353     {
354       ret = MEDchampCr(fid,champ3,MED_REEL64,champ3_comp,champ3_unit,3);
355       printf("MEDchampCr : %d \n",ret);
356       if (ret == 0) {
357         ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble,
358                           MED_FULL_INTERLACE, nhexa8,
359                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE, 
360                           MED_HEXA8, MED_NOPDT,"        ", 0., MED_NONOR);
361         printf("MEDchampEcr : %d \n",ret);
362       }
363     }
364
365   /***************************************************************************/
366
367   ret = MEDfermer(fid);
368   printf("%d\n",ret);
369   
370   return 0;
371 }
372