Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/med.git] / src / MEDMEM / create_mesh_c2q4s2_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_c2q4s2_wrong.c
26 Module : MED
27 ----------------------------------------------------------------------------*/
28
29 /*
30   creation d'une geometrie 2d : un cube [0,1]^2
31   maillĂ© uniformement en quadrangle reguliers;
32   avec en plus une partie des aretes (une partie
33   des arretes 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] = "carre_en_quad4_seg2_wrong";
45   med_int mdim = 2;
46   med_int nnoe = 9;
47   /*
48     les noeuds:
49   */
50   med_float coo[18] = {
51     0.0, 0.0,
52     0.5, 0.0,
53     1.0, 0.0,
54     0.0, 0.5,
55     0.5, 0.5,
56     1.0, 0.5,
57     0.0, 1.0,
58     0.5, 1.0,
59     1.0, 1.0
60   };
61   char nomcoo[2*MED_TAILLE_PNOM+1] = "x       y       ";
62   char unicoo[2*MED_TAILLE_PNOM+1] = "cm      cm      ";
63   /*  char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
64   char *nomnoe ;
65   med_int numnoe[9] = {1,2,3,4,5,6,7,8,9};
66   med_int nufano[9] = {0,0,0,0,0,0,0,0,0};
67   /*
68     les elements:
69   */
70   med_int nquad4 = 4;
71   med_int quad4[16] = {
72     4, 5, 2, 1,
73     5, 6, 3, 2,
74     7, 8, 5, 4,
75     8, 9, 6, 5
76   };
77   char nomquad4[MED_TAILLE_PNOM*4+1] = "quad1   quad2   quad3   quad4   ";
78   med_int numquad4[4] = {1,2,3,4};
79   med_int nufaquad4[4] = {-10,-10,0,0};
80
81   /*
82     Les Faces qui dans ce cas (2D) sont des arretes
83
84     a face is wrongly oriented, it is just to test the applidation
85     duplicateMEDMESH
86   */
87
88   med_int nseg2 = 6;
89   med_int seg2[12] = {
90     6, 3,
91     8, 9,
92     3, 2,
93     /*9, 6,*/
94     6, 9,
95     2, 5,
96     5, 8
97   };
98   char nomseg2[MED_TAILLE_PNOM*6+1] = "seg1    seg2    seg3    seg4    seg5    seg6    ";
99   med_int numseg2[6] = {1,2,3,4,5,6};
100   med_int nufaseg2[6] = {-1,-2,-1,-1,-2,-2};
101
102   char nomfam[MED_TAILLE_NOM+1];
103   med_int numfam;
104   char attdes[MED_TAILLE_DESC+1];
105   med_int natt;
106   med_int attide;
107   med_int attval;
108   med_int ngro;
109   char gro[MED_TAILLE_LNOM+1];
110   int i;
111   int nfame = 1; 
112   int nfamn = 1;
113
114   /*
115     Some fields : 2 on nodes : one int and one double , one on cells : double
116    */
117   char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ;
118   char champ1_comp[MED_TAILLE_PNOM+1]="comp1   " ;
119   char champ1_unit[MED_TAILLE_PNOM+1]="M       " ;
120   med_int     fieldnodeint[9]    = {1,1,3,2,2,3,4,4,5};
121
122   char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ;
123   char champ2_comp[MED_TAILLE_PNOM+1]="comp1   " ;
124   char champ2_unit[MED_TAILLE_PNOM+1]="J       " ;
125   med_float   fieldnodedouble1[9] = {1.,3.,4.,1.,3.,4.,3.,2.,5.};
126   med_float   fieldnodedouble2[9] = {1.,2.,2.,3.,3.,3.,4.,4.,5.};
127
128   char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ;
129   char champ3_comp[MED_TAILLE_PNOM*2+1]="comp1   comp2   " ;
130   char champ3_unit[MED_TAILLE_PNOM*2+1]="M/S     m/s     " ;
131   med_float   fieldcelldouble[4*2] = {0.,1.,1.,1.,1.,2.,2.,3.};
132
133   /***************************************************************************/
134   fid = MEDouvrir("carre_en_quad4_seg2_wrong.med",MED_REMP);
135   if (fid < 0)
136     ret = -1;
137   else
138     ret = 0;
139   printf("%d\n",ret);
140
141   /***************************************************************************/
142   if (ret == 0)
143     ret = MEDmaaCr(fid,maa,mdim);
144   printf("%d\n",ret);
145   if (ret == 0)
146     ret = MEDunvCr(fid,maa);
147   printf("%d\n",ret);
148
149   /***************************************************************************/
150   if (ret == 0)
151     ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
152                        nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
153                        nufano,nnoe,MED_ECRI);
154   printf("%d\n",ret);
155
156   /* ecriture des mailles MED_QUAD4 :
157      - connectivite
158      - noms (optionnel) 
159      - numeros (optionnel)
160      - numeros des familles */
161   if (ret == 0) 
162     ret = MEDelementsEcr(fid,maa,mdim,quad4,MED_FULL_INTERLACE,
163                          nomquad4,MED_FAUX,numquad4,MED_VRAI,nufaquad4,nquad4,
164                          MED_MAILLE,MED_QUAD4,MED_NOD,MED_ECRI);
165   printf("%d \n",ret);
166
167   /* ecriture des mailles MED_SEG2 :
168      - connectivite
169      - noms (optionnel) 
170      - numeros (optionnel)
171      - numeros des familles */
172   if (ret == 0) 
173     ret = MEDelementsEcr(fid,maa,mdim,seg2,MED_FULL_INTERLACE,
174                          nomseg2,MED_FAUX,numseg2,MED_VRAI,nufaseg2,nseg2,
175                          MED_ARETE,MED_SEG2,MED_NOD,MED_ECRI);
176   printf("%d \n",ret);
177
178   /***************************************************************************/
179   /* ecriture des familles */
180   /* Conventions :
181      - toujours creer une famille de numero 0 ne comportant aucun attribut
182        ni groupe (famille de reference pour les noeuds ou les elements
183        qui ne sont rattaches a aucun groupe ni attribut)
184      - les numeros de familles de noeuds sont > 0
185      - les numeros de familles des elements sont < 0
186      - rien d'imposer sur les noms de familles
187    */ 
188
189   /* la famille 0 */
190   if (ret == 0)
191     {
192       strcpy(nomfam,"FAMILLE_0");
193       numfam = 0;
194       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
195                      gro,0);
196     }
197   printf("%d \n",ret);
198
199   /* on cree :
200       - 1 familles d'elements de dimension (d-1)
201         en fait de edge (-1)
202       - 1 familles d'elements de dimension (d-1)
203         en fait de edge (-2)
204       - 1 familles d'elements de dimension (d)
205         en fait de face (-10)
206   */
207
208   if (ret == 0)
209     {
210       numfam = -1;
211       strcpy(nomfam,"FAMILLE_EDGE_");
212       sprintf(nomfam,"%s%d",nomfam,-numfam);
213       attide = 1;
214       attval = numfam*100;
215       natt = 1;
216       strcpy(attdes,"description attribut");
217       strcpy(gro,"groupe1");
218       ngro = 1;
219
220       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
221                      natt,gro,ngro);
222       printf("MEDfamCr : %d\n",ret);
223     }
224   if (ret == 0)
225     {
226       numfam = -2;
227       strcpy(nomfam,"FAMILLE_EDGE_");
228       sprintf(nomfam,"%s%d",nomfam,-numfam);
229       attide = 1;
230       attval = numfam*100;
231       natt = 1;
232       strcpy(attdes,"description attribut");
233       strcpy(gro,"groupe1");
234       ngro = 1;
235
236       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
237                      natt,gro,ngro);
238       printf("MEDfamCr : %d\n",ret);
239     }
240   if (ret == 0)
241     {
242       numfam = -10;
243       strcpy(nomfam,"FAMILLE_CELL_");
244       sprintf(nomfam,"%s%d",nomfam,-numfam);
245       attide = 1;
246       attval = numfam*100;
247       natt = 1;
248       strcpy(attdes,"description attribut");
249       strcpy(gro,"groupe0");
250       ngro = 1;
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     Les champs
259   */
260   if (ret == 0)
261     {
262       ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
263       printf("MEDchampCr : %d \n",ret);
264       if (ret == 0) {
265         ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
266                           MED_NO_INTERLACE, nnoe,
267                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
268                           0, MED_NOPDT,"        ", 0., MED_NONOR);
269         
270         printf("MEDchampEcr : %d \n",ret);
271       }
272     }
273   
274   if (ret == 0)
275     {
276       ret = MEDchampCr(fid,champ2,MED_REEL64,champ2_comp,champ2_unit,1);
277       printf("MEDchampCr : %d \n",ret);
278       if (ret == 0) {
279         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
280                           MED_NO_INTERLACE, nnoe,
281                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
282                           0, 1,"S       ", 1.1 , MED_NONOR);
283         printf("MEDchampEcr1 : %d \n",ret);
284         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
285                           MED_NO_INTERLACE, nnoe,
286                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
287                           0, 2,"S       ", 1.2 , MED_NONOR);
288         printf("MEDchampEcr2 : %d \n",ret);
289       }
290     }
291   
292   // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !
293   if (ret == 0)
294     {
295       ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
296                         MED_NO_INTERLACE, nnoe,
297                         MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
298                         0, MED_NOPDT,"        ", 0. , MED_NONOR);
299       printf("MEDchampEcr : %d \n",ret); 
300     }
301
302   if (ret == 0)
303     {
304       ret = MEDchampCr(fid,champ3,MED_REEL64,champ3_comp,champ3_unit,2);
305       printf("MEDchampCr : %d \n",ret);
306       if (ret == 0) {
307         ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble,
308                           MED_NO_INTERLACE, nquad4,
309                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE, 
310                           MED_QUAD4, MED_NOPDT,"        ", 0., MED_NONOR);
311         printf("MEDchampEcr : %d \n",ret);
312       }
313     }
314   
315   /***************************************************************************/
316
317   ret = MEDfermer(fid);
318   printf("%d\n",ret);
319   
320   return 0;
321 }
322