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