1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 creation d'une geometrie 3d : un cube [0,1]^3
25 maillé uniformement en hexahedres reguliers;
26 avec n (=argv[1]) noeuds dans chaque direction.
28 - DbleVectNode champ vectoriel reel sur les noeuds
29 - DbleVectCell champ vectoriel reel sur les cellules
31 En sortie, il y aura production d'un fichier MED
32 cube_hexa8_n.med qui contiendra un seul maillage et 2 champs
33 avec une seule famille la FAMILLE_0
42 int main (int argc, char **argv)
46 char maa[MED_TAILLE_NOM+1] = "cube_hexa8";
62 med_float * DbleVectNode;
63 med_float * DbleVectCell;
71 char nomcoo[3*MED_TAILLE_PNOM+1] = "x y z ";
72 char unicoo[3*MED_TAILLE_PNOM+1] = "cm cm cm ";
73 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
82 int indexN1, indexN2, indexN3, indexN4, indexN5, indexN6, indexN7, indexN8;
84 char nomfam[MED_TAILLE_NOM+1];
86 char attdes[MED_TAILLE_DESC+1];
91 char gro[MED_TAILLE_LNOM+1];
95 char MedFile[100] = "cube_hexa8_";
102 char champDbleVectNode[MED_TAILLE_NOM+1] = "DbleVectNode";
103 char compDbleVectNode[MED_TAILLE_PNOM*3+1] = "comp1 comp2 comp3 " ;
104 char unitDbleVectNode[MED_TAILLE_PNOM*3+1] = "unit1 unit2 unit3 " ;
106 char champDbleVectCell[MED_TAILLE_NOM+1] = "DbleVectCell";
107 char compDbleVectCell[MED_TAILLE_PNOM*3+1] = "comp1 comp2 comp3 " ;
108 char unitDbleVectCell[MED_TAILLE_PNOM*3+1] = "unit1 unit2 unit3 " ;
112 printf("Usage: %s <n> \n",argv[0]);
114 printf(" - n is the number of nodes in each direction.\n");
116 printf("This program will produce a MED file cube_hexa8_n.med\n");
120 nnoe_dir = atoi(argv[1]);
121 nelt_dir = nnoe_dir-1;
122 nnoe = nnoe_dir*nnoe_dir*nnoe_dir;
124 coo = malloc(mdim*nnoe*sizeof(med_float));
125 numnoe = malloc(nnoe*sizeof(med_int));
126 nufano = malloc(nnoe*sizeof(med_int));
127 nomnoe = malloc((MED_TAILLE_PNOM*nnoe+1)*sizeof(char));
129 hxsize = 1./((med_float) (nnoe_dir - 1));
133 nhexa8 = nelt_dir*nelt_dir*nelt_dir;
134 hexa8 = malloc(8*nhexa8*sizeof(med_int));
135 numhexa8 = malloc(nhexa8*sizeof(med_int));
136 nufahexa8 = malloc(nhexa8*sizeof(med_int));
137 nomhexa8 = malloc((MED_TAILLE_PNOM*nhexa8+1)*sizeof(char));
139 DbleVectNode = malloc(mdim*nnoe*sizeof(med_float));
140 DbleVectCell = malloc(mdim*nhexa8*sizeof(med_float));
146 for(k=0;k<nnoe_dir;k++)
148 for(j=0;j<nnoe_dir;j++)
150 for (i=0;i<nnoe_dir;i++)
152 int ijk = k*nnoe_dir*nnoe_dir+j*nnoe_dir+i;
157 coo[mdim*ijk] = ((med_float) i)*hxsize;
158 coo[mdim*ijk+1] = ((med_float) j)*hysize;
159 coo[mdim*ijk+2] = ((med_float) k)*hzsize;
162 printf("Coordonnées %d X = %lf Y = %lf Z = %lf\n",(ijk+1),coo[mdim*ijk],coo[mdim*ijk+1],coo[mdim*ijk+2]);
172 for(k=0;k<nelt_dir;k++)
174 for(j=0;j<nelt_dir;j++)
176 for (i=0;i<nelt_dir;i++)
178 int ijk = k*nelt_dir*nelt_dir+j*nelt_dir+i;
180 numhexa8[ijk] = ijk+1;
183 indexN5 = k*nnoe_dir*nnoe_dir+j*nnoe_dir+i+1;
185 indexN1 = indexN5+nnoe_dir;
186 indexN4 = indexN8+nnoe_dir;
188 indexN6 = indexN5+nnoe_dir*nnoe_dir;
189 indexN7 = indexN8+nnoe_dir*nnoe_dir;
190 indexN2 = indexN1+nnoe_dir*nnoe_dir;
191 indexN3 = indexN4+nnoe_dir*nnoe_dir;
193 hexa8[8*ijk] = indexN1;
194 hexa8[8*ijk+1] = indexN2;
195 hexa8[8*ijk+2] = indexN3;
196 hexa8[8*ijk+3] = indexN4;
197 hexa8[8*ijk+4] = indexN5;
198 hexa8[8*ijk+5] = indexN6;
199 hexa8[8*ijk+6] = indexN7;
200 hexa8[8*ijk+7] = indexN8;
203 printf("Connectivitée %d i1 = %d i2 = %d i3 = %d i4 = %d i5 = %d i6 = %d i7 = %d i8 = %d\n",(ijk+1),hexa8[8*ijk],hexa8[8*ijk+1],hexa8[8*ijk+2],hexa8[8*ijk+3],hexa8[8*ijk+4],hexa8[8*ijk+5],hexa8[8*ijk+6],hexa8[8*ijk+7]);
215 srand((int) t1); /* use time in seconds to set seed */
219 DbleVectNode[mdim*i] = (med_float)
220 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
222 DbleVectNode[mdim*i+1] = (med_float)
223 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
225 DbleVectNode[mdim*i+2] = (med_float)
226 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
229 printf("i %d DbleVectNode %lf %lf\n",i,DbleVectNode[mdim*i],
230 DbleVectNode[mdim*i+1],DbleVectNode[mdim*i+2]);
234 for(i=0;i<nhexa8;i++)
236 DbleVectCell[mdim*i] = (med_float)
237 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
239 DbleVectCell[mdim*i+1] = (med_float)
240 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
242 DbleVectCell[mdim*i+2] = (med_float)
243 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
246 printf("i %d DbleVectCell %lf %lf\n",i,DbleVectCell[mdim*i],
247 DbleVectCell[mdim*i+1],DbleVectCell[mdim*i+2]);
251 /***************************************************************************/
253 sprintf(buff,"%d",nnoe_dir);
254 strcat(MedFile,buff);
255 strcat(MedFile,".med");
257 fid = MEDouvrir(MedFile,RDWR);
265 /***************************************************************************/
268 ret = MEDmaaCr(fid,maa,mdim);
272 ret = MEDunvCr(fid,maa);
275 /***************************************************************************/
278 ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
279 nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
284 ecriture des mailles MED_HEXA8 :
287 - numeros (optionnel)
288 - numeros des familles
292 ret = MEDelementsEcr(fid,maa,mdim,hexa8,MED_FULL_INTERLACE,
293 nomhexa8,MED_FAUX,numhexa8,MED_VRAI,nufahexa8,nhexa8,
294 MED_MAILLE,MED_HEXA8,MED_NOD,WRONLY);
297 /***************************************************************************/
298 /* ecriture des familles */
300 - toujours creer une famille de numero 0 ne comportant aucun attribut
301 ni groupe (famille de reference pour les noeuds ou les elements
302 qui ne sont rattaches a aucun groupe ni attribut)
303 - les numeros de familles de noeuds sont > 0
304 - les numeros de familles des elements sont < 0
305 - rien d'imposer sur les noms de familles
311 strcpy(nomfam,"FAMILLE_0");
313 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
318 /***************************************************************************/
325 ret = MEDchampCr(fid,champDbleVectNode,MED_REEL64,compDbleVectNode,
326 unitDbleVectNode,mdim);
328 printf("MEDchampCr DbleVectNode : %d \n",ret);
332 ret = MEDchampEcr(fid, maa, champDbleVectNode,
333 (unsigned char *)DbleVectNode,
334 MED_NO_INTERLACE, nnoe,
335 MED_NOPG, MED_ALL, MED_NOPFL, WRONLY, MED_NOEUD,
336 0, MED_NOPDT," ", 0., MED_NONOR);
338 printf("MEDchampEcr DbleVectNode : %d \n",ret);
344 ret = MEDchampCr(fid,champDbleVectCell,MED_REEL64,compDbleVectCell,
345 unitDbleVectCell,mdim);
347 printf("MEDchampCr DbleVectCell : %d \n",ret);
351 ret = MEDchampEcr(fid, maa, champDbleVectCell,
352 (unsigned char *)DbleVectCell,
353 MED_NO_INTERLACE, nhexa8,
354 MED_NOPG, MED_ALL, MED_NOPFL, WRONLY, MED_MAILLE,
355 MED_HEXA8, MED_NOPDT," ", 0., MED_NONOR);
357 printf("MEDchampEcr DbleVectCell : %d \n",ret);
361 /***************************************************************************/
363 ret = MEDfermer(fid);