Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / create_poly2D.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 : 
21   maillĂ© en 4 quadrangles reguliers
22             1 triangle et 1 polygone.
23
24 */
25
26 #include <med.h>
27 #include <string.h>
28
29 int main (int argc, char **argv)
30 {
31   med_err ret;
32   med_idt fid;
33   char maa[MED_TAILLE_NOM+1] = "poly2D";
34   char maadesc[MED_TAILLE_DESC+1] = "Example de maillage non structure 2D avec 1 polygone";
35   med_int mdim = 2;
36   med_int nnoe = 11;
37   /*
38     les noeuds:
39   */
40   med_float coo[22] = {
41     0.0, 0.0,
42     0.5, 0.0,
43     1.0, 0.0,
44     0.25, 0.5,
45     0.5, 0.5,
46     0.75, 0.5,
47     0.0, 1.0,
48     0.5, 1.0,
49     1.0, 1.0,
50     1.5, 0.0,
51     1.5, 1.0
52   };
53   char nomcoo[2*MED_TAILLE_PNOM+1] = "x               y               ";
54   char unicoo[2*MED_TAILLE_PNOM+1] = "cm              cm              ";
55   /*  char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
56   char *nomnoe ;
57   med_int numnoe[11] = {1,2,3,4,5,6,7,8,9,10,11};
58   med_int nufano[11] = {0,0,0,0,0,0,0,0,0,0,0};
59   /*
60     les elements:
61   */
62   med_int nquad4 = 4;
63   med_int quad4[16] = {
64     4, 5, 2, 1,
65     5, 6, 3, 2,
66     7, 8, 5, 4,
67     8, 9, 6, 5
68   };
69   char nomquad4[MED_TAILLE_PNOM*4+1] = "quad1           quad2           quad3           quad4           ";
70   med_int numquad4[4] = {1,2,3,4};
71   med_int nufaquad4[4] = {-1,-1,0,0};
72
73   med_int ntria3 = 1;
74   med_int tria3[3] = {
75     7, 4, 1
76   };
77   char nomtria3[MED_TAILLE_PNOM+1] = "tria1           ";
78   med_int numtria3[1] = {1};
79   med_int nufatria3[1] = {-2};
80
81   med_int npoly = 1;
82   med_int nindexpoly = 2;
83   med_int indexpoly [2] = {
84     1,6
85   };
86   med_int poly[5] = {
87     9,11,10,3,6
88   };
89   char nompoly[MED_TAILLE_PNOM+1] = "poly            ";
90   med_int numpoly[1] = {1};
91   med_int nufapoly[1] = {-3};
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 = 2; 
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("poly2D.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 for quad : %d \n",ret);
157
158   /* ecriture des mailles MED_TRIA3 :
159      - connectivite
160      - noms (optionnel) 
161      - numeros (optionnel)
162      - numeros des familles */
163   if (ret == 0) 
164     ret = MEDelementsEcr(fid,maa,mdim,tria3,MED_FULL_INTERLACE,
165                          nomtria3,MED_FAUX,numtria3,MED_VRAI,nufatria3,ntria3,
166                          MED_MAILLE,MED_TRIA3,MED_NOD);
167   printf("MEDelementsEcr for tria : %d \n",ret);
168
169   /* ecriture des mailles MED_POLYGONE:
170      - connectivite
171      - noms (optionnel) 
172      - numeros (optionnel)
173      - numeros des familles
174      Dans ce cas il n existe pas de routine globale (Warning !!)
175    */
176
177   if (ret == 0)
178     ret = MEDpolygoneConnEcr(fid,maa,indexpoly,nindexpoly,poly,
179                              MED_MAILLE,MED_NOD);
180   printf("MEDpolygoneConnEcr: %d \n",ret);
181
182   if (ret == 0)
183     MEDnomEcr(fid,maa,nompoly,npoly,MED_MAILLE,MED_POLYGONE);
184   printf("MEDnomEcr for poly : %d \n",ret);
185
186   if (ret == 0)
187     MEDnumEcr(fid,maa,numpoly,npoly,MED_MAILLE,MED_POLYGONE);
188   printf("MEDnumEcr for poly : %d \n",ret);
189
190   if (ret == 0)
191     MEDfamEcr(fid,maa,nufapoly,npoly,MED_MAILLE,MED_POLYGONE);
192   printf("MEDfamEcr for poly : %d \n",ret);
193
194
195   /***************************************************************************/
196   /* ecriture des familles */
197   /* Conventions :
198      - toujours creer une famille de numero 0 ne comportant aucun attribut
199        ni groupe (famille de reference pour les noeuds ou les elements
200        qui ne sont rattaches a aucun groupe ni attribut)
201      - les numeros de familles de noeuds sont > 0
202      - les numeros de familles des elements sont < 0
203      - rien d'imposer sur les noms de familles
204    */ 
205
206   /* la famille 0 */
207   if (ret == 0)
208     {
209       strcpy(nomfam,"FAMILLE_0");
210       numfam = 0;
211       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
212                      gro,0);
213     }
214   printf("MEDfamCr : %d \n",ret);
215
216   /* on cree :
217       - 2 familles d'elements de dimension (d)
218         en fait de face (-10)
219   */
220   if (ret == 0)
221     {
222       numfam = -1;
223       strcpy(nomfam,"FAMILLE_CELL_");
224       sprintf(nomfam,"%s%d",nomfam,-numfam);
225       attide = 1;
226       attval = numfam*100;
227       natt = 1;
228       strcpy(attdes,"description attribut");
229       strcpy(gro,"groupe0");
230       ngro = 1;
231
232       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
233                      natt,gro,ngro);
234       printf("MEDfamCr : %d\n",ret);
235
236       numfam = -2;
237       strcpy(nomfam,"FAMILLE_CELL_");
238       sprintf(nomfam,"%s%d",nomfam,-numfam);
239       attide = 1;
240       attval = numfam*100;
241       natt = 1;
242       strcpy(attdes,"description attribut");
243       strcpy(gro,"groupe0");
244       ngro = 1;
245
246       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
247                      natt,gro,ngro);
248       printf("MEDfamCr : %d\n",ret);
249
250       numfam = -3;
251       strcpy(nomfam,"FAMILLE_CELL_");
252       sprintf(nomfam,"%s%d",nomfam,-numfam);
253       attide = 1;
254       attval = numfam*100;
255       natt = 1;
256       strcpy(attdes,"description attribut");
257       strcpy(gro,"groupe0");
258       ngro = 1;
259
260       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
261                      natt,gro,ngro);
262       printf("MEDfamCr : %d\n",ret);
263     }
264
265   /***************************************************************************/
266   /*
267     Les champs
268   */
269   if (ret == 0)
270     {
271       ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
272       printf("MEDchampCr : %d \n",ret);
273       if (ret == 0) {
274         ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
275                           MED_NO_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
276                           MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
277                           MED_NOPDT,"        ", 0., MED_NONOR);
278         
279         printf("MEDchampEcr : %d \n",ret);
280       }
281     }
282   
283   if (ret == 0)
284     {
285       ret = MEDchampCr(fid,champ2,MED_FLOAT64,champ2_comp,champ2_unit,1);
286       printf("MEDchampCr : %d \n",ret);
287       if (ret == 0) {
288         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
289                           MED_NO_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
290                           MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
291                           1,"S       ", 1.1 , MED_NONOR);
292         printf("MEDchampEcr1 : %d \n",ret);
293         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
294                           MED_NO_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
295                           MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
296                           2,"S       ", 1.2 , MED_NONOR);
297         printf("MEDchampEcr2 : %d \n",ret);
298       }
299     }
300   
301   // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !
302   if (ret == 0)
303     {
304       ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
305                         MED_NO_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
306                         MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
307                         MED_NOPDT,"        ", 0. , MED_NONOR);
308       printf("MEDchampEcr : %d \n",ret); 
309     }
310
311   if (ret == 0)
312     {
313       ret = MEDchampCr(fid,champ3,MED_FLOAT64,champ3_comp,champ3_unit,2);
314       printf("MEDchampCr : %d \n",ret);
315       if (ret == 0) {
316         ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble,
317                           MED_NO_INTERLACE, nquad4, MED_NOGAUSS, MED_ALL,
318                           MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE, MED_QUAD4,
319                           MED_NOPDT,"        ", 0., MED_NONOR);
320         printf("MEDchampEcr : %d \n",ret);
321       }
322     }
323
324   /***************************************************************************/
325
326   ret = MEDfermer(fid);
327   printf("MEDfermer : %d\n",ret);
328   
329   return 0;
330 }
331