Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / create_mesh_c3h8.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 3d : un cube [0,1]^3
21   maillĂ© uniformement en hexahedres reguliers;
22   avec en plus une partie des faces (une partie
23   des faces 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] = "CUBE_EN_HEXA8";
35   char maadesc[MED_TAILLE_DESC+1] = "Example de maillage non structure 3D";
36   med_int mdim = 3;
37   med_int nnoe = 27;
38   /*
39     les noeuds:
40   */
41   med_float coo[81] = {
42     0.0, 0.0, 0.0, 
43     0.5, 0.0, 0.0, 
44     1.0, 0.0, 0.0, 
45     0.0, 0.5, 0.0, 
46     0.5, 0.5, 0.0, 
47     1.0, 0.5, 0.0, 
48     0.0, 1.0, 0.0, 
49     0.5, 1.0, 0.0, 
50     1.0, 1.0, 0.0, 
51     0.0, 0.0, 0.5, 
52     0.5, 0.0, 0.5, 
53     1.0, 0.0, 0.5, 
54     0.0, 0.5, 0.5, 
55     0.5, 0.5, 0.5, 
56     1.0, 0.5, 0.5, 
57     0.0, 1.0, 0.5, 
58     0.5, 1.0, 0.5, 
59     1.0, 1.0, 0.5, 
60     0.0, 0.0, 1.0, 
61     0.5, 0.0, 1.0, 
62     1.0, 0.0, 1.0, 
63     0.0, 0.5, 1.0, 
64     0.5, 0.5, 1.0, 
65     1.0, 0.5, 1.0, 
66     0.0, 1.0, 1.0, 
67     0.5, 1.0, 1.0, 
68     1.0, 1.0, 1.0
69   };
70   char nomcoo[3*MED_TAILLE_PNOM+1] = "x               y               z               ";
71   char unicoo[3*MED_TAILLE_PNOM+1] = "cm              cm              cm              ";
72   /*  char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
73   char *nomnoe ;
74   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};
75   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};
76   /*
77     les elements:
78   */
79   med_int nhexa8 = 8;
80   med_int hexa8[64] = {
81     4, 13, 14, 5, 1, 10, 11, 2,
82     5, 14, 15, 6, 2, 11, 12, 3,
83     7, 16, 17, 8, 4, 13, 14, 5,
84     8, 17, 18, 9, 5, 14, 15, 6,
85     13, 22, 23, 14, 10, 19, 20, 11,
86     14, 23, 24, 15, 11, 20, 21, 12,
87     16, 25, 26, 17, 13, 22, 23, 14,
88     17, 26, 27, 18, 14, 23, 24, 15
89   };
90   char nomhexa8[MED_TAILLE_PNOM*8+1] = "hexa1           hexa2           hexa3           hexa4           hexa5           hexa6           hexa7           hexa8           ";
91   med_int numhexa8[8] = {1,2,3,4,5,6,7,8};
92   med_int nufahexa8[8] = {-1,-1,-1,-1,-2,-2,-2,-2};
93
94   char nomfam[MED_TAILLE_NOM+1];
95   med_int numfam;
96   char attdes[MED_TAILLE_DESC+1];
97   med_int natt;
98   med_int attide;
99   med_int attval;
100   med_int ngro;
101   char gro[MED_TAILLE_LNOM+1];
102   int i;
103   int nfame = 1; 
104   int nfamn = 1;
105   int nfamf = 1;
106
107   /*
108     Some fields : 2 on nodes : one int and one double , one on cells : double
109   */
110
111   char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ;
112   char champ1_comp[MED_TAILLE_PNOM+1]="comp1           " ;
113   char champ1_unit[MED_TAILLE_PNOM+1]="M               " ;
114   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};
115
116   char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ;
117   char champ2_comp[MED_TAILLE_PNOM+1]="comp1           " ;
118   char champ2_unit[MED_TAILLE_PNOM+1]="J               " ;
119   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.};
120   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.};
121
122   char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ;
123   char champ3_comp[MED_TAILLE_PNOM*3+1]="comp1           comp2           comp3           " ;
124   char champ3_unit[MED_TAILLE_PNOM*3+1]="M/S             m/s             m/s             " ;
125   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.};
126
127   /***************************************************************************/
128   fid = MEDouvrir("cube_hexa8.med",MED_LECTURE_ECRITURE);
129   if (fid < 0)
130     ret = -1;
131   else
132     ret = 0;
133   printf("MEDouvrir : %d\n",ret);
134
135   /***************************************************************************/
136   if (ret == 0)
137     ret = MEDmaaCr(fid,maa,mdim,MED_NON_STRUCTURE,maadesc);
138   printf("MEDmaaCr : %d\n",ret);
139   if (ret == 0)
140     ret = MEDunvCr(fid,maa);
141   printf("MEDunvCr : %d\n",ret);
142
143   /***************************************************************************/
144   if (ret == 0)
145     ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
146                        nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
147                        nufano,nnoe);
148   printf("MEDnoeudsEcr : %d\n",ret);
149
150   /* ecriture des mailles MED_HEXA8 :
151      - connectivite
152      - noms (optionnel) 
153      - numeros (optionnel)
154      - numeros des familles */
155   if (ret == 0) 
156     ret = MEDelementsEcr(fid,maa,mdim,hexa8,MED_FULL_INTERLACE,
157                          nomhexa8,MED_FAUX,numhexa8,MED_VRAI,nufahexa8,nhexa8,
158                          MED_MAILLE,MED_HEXA8,MED_NOD);
159   printf("MEDelementsEcr : %d \n",ret);
160
161   /***************************************************************************/
162   /* ecriture des familles */
163   /* Conventions :
164      - toujours creer une famille de numero 0 ne comportant aucun attribut
165        ni groupe (famille de reference pour les noeuds ou les elements
166        qui ne sont rattaches a aucun groupe ni attribut)
167      - les numeros de familles de noeuds sont > 0
168      - les numeros de familles des elements sont < 0
169      - rien d'imposer sur les noms de familles
170    */ 
171
172   /* la famille 0 */
173   if (ret == 0)
174     {
175       strcpy(nomfam,"FAMILLE_0");
176       numfam = 0;
177       ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
178                      gro,0);
179     }
180   printf("%d \n",ret);
181
182   /* on cree :
183       - 2 familles d'elements (-1,-2) et 
184       - 3 familles de noeuds (1,2,3) 
185   */
186
187   if (ret == 0)
188     {
189       nfame = 2;
190       for (i=0;i<nfame;i++)
191         {
192           if (ret == 0)
193             {
194               strcpy(nomfam,"FAMILLE_ELEMENT_");
195               numfam = -(i+1);
196               sprintf(nomfam,"%s%d",nomfam,-numfam);
197               attide = 1;
198               attval = numfam*100;
199               natt = 1;
200               strcpy(attdes,"description attribut");
201               strcpy(gro,"groupe1");
202               ngro = 1;
203
204               /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
205
206               ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
207                              natt,gro,ngro);
208               printf("MEDfamCr : %d\n",ret);
209             }
210         }
211     }
212   
213   if (ret == 0)
214     {
215       nfamn = 3;
216       for (i=0;i<nfamn;i++)
217         {
218           if(ret == 0)
219             {
220               strcpy(nomfam,"FAMILLE_NOEUD_");
221               numfam = i+1;
222               sprintf(nomfam,"%s%d",nomfam,numfam);
223               attide = 1;
224               attval = numfam*100;
225               natt = 1;
226               strcpy(attdes,"description attribut");
227               strcpy(gro,"groupe2");
228               ngro = 1;
229               ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
230                              natt,gro,ngro);
231               printf("MEDfamCr : %d\n",ret);
232             }
233         }
234     }
235
236   /***************************************************************************/
237   /*
238     Les champs
239   */
240   if (ret == 0)
241     {
242       ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
243       printf("MEDchampCr : %d \n",ret);
244       if (ret == 0) {
245         ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
246                           MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
247                           MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
248                           MED_NOPDT,"        ", 0., MED_NONOR);
249         
250         printf("MEDchampEcr : %d \n",ret);
251       }
252     }
253   
254   if (ret == 0)
255     {
256       ret = MEDchampCr(fid,champ2,MED_FLOAT64,champ2_comp,champ2_unit,1);
257       printf("MEDchampCr : %d \n",ret);
258       if (ret == 0) {
259         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
260                           MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
261                           MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
262                           1,"S       ", 1.1 , MED_NONOR);
263         printf("MEDchampEcr1 : %d \n",ret);
264         ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
265                           MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
266                           MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
267                           2,"S       ", 1.2 , MED_NONOR);
268         printf("MEDchampEcr2 : %d \n",ret);
269       }
270     }
271   
272   /* on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !*/
273   if (ret == 0)
274     {
275       ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
276                         MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
277                         MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
278                         MED_NOPDT,"        ", 0. , MED_NONOR);
279       printf("MEDchampEcr : %d \n",ret); 
280     }
281
282   if (ret == 0)
283     {
284       ret = MEDchampCr(fid,champ3,MED_FLOAT64,champ3_comp,champ3_unit,3);
285       printf("MEDchampCr : %d \n",ret);
286       if (ret == 0) {
287         ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble,
288                           MED_FULL_INTERLACE, nhexa8, MED_NOGAUSS, MED_ALL,
289                           MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE, MED_HEXA8,
290                           MED_NOPDT,"        ", 0., MED_NONOR);
291         printf("MEDchampEcr : %d \n",ret);
292       }
293     }
294
295   /***************************************************************************/
296
297   ret = MEDfermer(fid);
298   printf("%d\n",ret);
299   
300   return 0;
301 }