]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/create_mesh_c2q4s2.c
Salome HOME
sources v1.2
[modules/med.git] / src / MEDMEM / create_mesh_c2q4s2.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.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";
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
85   med_int nseg2 = 6;
86   med_int seg2[12] = {
87     6, 3,
88     8, 9,
89     3, 2,
90     9, 6,
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_TAILLE_NOM+1];
99   med_int numfam;
100   char attdes[MED_TAILLE_DESC+1];
101   med_int natt;
102   med_int attide;
103   med_int attval;
104   med_int ngro;
105   char gro[MED_TAILLE_LNOM+1];
106   int i;
107   int nfame = 1; 
108   int nfamn = 1;
109
110   /*
111     Some fields : 2 on nodes : one int and one double , one on cells : double
112    */
113   char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ;
114   char champ1_comp[MED_TAILLE_PNOM+1]="comp1   " ;
115   char champ1_unit[MED_TAILLE_PNOM+1]="M       " ;
116   med_int     fieldnodeint[9]    = {1,1,3,2,2,3,4,4,5};
117
118   char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ;
119   char champ2_comp[MED_TAILLE_PNOM+1]="comp1   " ;
120   char champ2_unit[MED_TAILLE_PNOM+1]="J       " ;
121   med_float   fieldnodedouble1[9] = {1.,3.,4.,1.,3.,4.,3.,2.,5.};
122   med_float   fieldnodedouble2[9] = {1.,2.,2.,3.,3.,3.,4.,4.,5.};
123
124   char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ;
125   char champ3_comp[MED_TAILLE_PNOM*2+1]="comp1   comp2   " ;
126   char champ3_unit[MED_TAILLE_PNOM*2+1]="M/S     m/s     " ;
127   med_float   fieldcelldouble[4*2] = {0.,1.,1.,1.,1.,2.,2.,3.};
128
129   /***************************************************************************/
130   fid = MEDouvrir("carre_en_quad4_seg2.med",MED_REMP);
131   if (fid < 0)
132     ret = -1;
133   else
134     ret = 0;
135   printf("%d\n",ret);
136
137   /***************************************************************************/
138   if (ret == 0)
139     ret = MEDmaaCr(fid,maa,mdim);
140   printf("%d\n",ret);
141   if (ret == 0)
142     ret = MEDunvCr(fid,maa);
143   printf("%d\n",ret);
144
145   /***************************************************************************/
146   if (ret == 0)
147     ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
148                        nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
149                        nufano,nnoe,MED_ECRI);
150   printf("%d\n",ret);
151
152   /* ecriture des mailles MED_QUAD4 :
153      - connectivite
154      - noms (optionnel) 
155      - numeros (optionnel)
156      - numeros des familles */
157   if (ret == 0) 
158     ret = MEDelementsEcr(fid,maa,mdim,quad4,MED_FULL_INTERLACE,
159                          nomquad4,MED_FAUX,numquad4,MED_VRAI,nufaquad4,nquad4,
160                          MED_MAILLE,MED_QUAD4,MED_NOD,MED_ECRI);
161   printf("%d \n",ret);
162
163   /* ecriture des mailles MED_SEG2 :
164      - connectivite
165      - noms (optionnel) 
166      - numeros (optionnel)
167      - numeros des familles */
168   if (ret == 0) 
169     ret = MEDelementsEcr(fid,maa,mdim,seg2,MED_FULL_INTERLACE,
170                          nomseg2,MED_FAUX,numseg2,MED_VRAI,nufaseg2,nseg2,
171                          MED_ARETE,MED_SEG2,MED_NOD,MED_ECRI);
172   printf("%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 = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
191                      gro,0);
192     }
193   printf("%d \n",ret);
194
195   /* on cree :
196       - 1 familles d'elements de dimension (d-1)
197         en fait de edge (-1)
198       - 1 familles d'elements de dimension (d-1)
199         en fait de edge (-2)
200       - 1 familles d'elements de dimension (d)
201         en fait de face (-10)
202   */
203
204   if (ret == 0)
205     {
206       numfam = -1;
207       strcpy(nomfam,"FAMILLE_EDGE_");
208       sprintf(nomfam,"%s%d",nomfam,-numfam);
209       attide = 1;
210       attval = numfam*100;
211       natt = 1;
212       strcpy(attdes,"description attribut");
213       strcpy(gro,"groupe1");
214       ngro = 1;
215
216       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
217                      natt,gro,ngro);
218       printf("MEDfamCr : %d\n",ret);
219     }
220   if (ret == 0)
221     {
222       numfam = -2;
223       strcpy(nomfam,"FAMILLE_EDGE_");
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,"groupe1");
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   if (ret == 0)
237     {
238       numfam = -10;
239       strcpy(nomfam,"FAMILLE_CELL_");
240       sprintf(nomfam,"%s%d",nomfam,-numfam);
241       attide = 1;
242       attval = numfam*100;
243       natt = 1;
244       strcpy(attdes,"description attribut");
245       strcpy(gro,"groupe0");
246       ngro = 1;
247
248       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
249                      natt,gro,ngro);
250       printf("MEDfamCr : %d\n",ret);
251     }
252   /***************************************************************************/
253   /*
254     Les champs
255   */
256   if (ret == 0)
257     {
258       ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
259       printf("MEDchampCr : %d \n",ret);
260       if (ret == 0) {
261         ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
262                           MED_NO_INTERLACE, nnoe,
263                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
264                           0, MED_NOPDT,"        ", 0., MED_NONOR);
265         
266         printf("MEDchampEcr : %d \n",ret);
267       }
268     }
269   
270   if (ret == 0)
271     {
272       ret = MEDchampCr(fid,champ2,MED_REEL64,champ2_comp,champ2_unit,1);
273       printf("MEDchampCr : %d \n",ret);
274       if (ret == 0) {
275         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
276                           MED_NO_INTERLACE, nnoe,
277                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
278                           0, 1,"S       ", 1.1 , MED_NONOR);
279         printf("MEDchampEcr1 : %d \n",ret);
280         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
281                           MED_NO_INTERLACE, nnoe,
282                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
283                           0, 2,"S       ", 1.2 , MED_NONOR);
284         printf("MEDchampEcr2 : %d \n",ret);
285       }
286     }
287   
288   // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !
289   if (ret == 0)
290     {
291       ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
292                         MED_NO_INTERLACE, nnoe,
293                         MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD, 
294                         0, MED_NOPDT,"        ", 0. , MED_NONOR);
295       printf("MEDchampEcr : %d \n",ret); 
296     }
297
298   if (ret == 0)
299     {
300       ret = MEDchampCr(fid,champ3,MED_REEL64,champ3_comp,champ3_unit,2);
301       printf("MEDchampCr : %d \n",ret);
302       if (ret == 0) {
303         ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble,
304                           MED_NO_INTERLACE, nquad4,
305                           MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE, 
306                           MED_QUAD4, MED_NOPDT,"        ", 0., MED_NONOR);
307         printf("MEDchampEcr : %d \n",ret);
308       }
309     }
310   
311   /***************************************************************************/
312
313   ret = MEDfermer(fid);
314   printf("%d\n",ret);
315   
316   return 0;
317 }
318