4 /*****************************************************************************************************/
6 void affiche_noeuds(med_float * nodes,int nnpl)
8 int nbr_nodes=nnpl*nnpl*nnpl;
11 for (i=0;i<nbr_nodes;i++)
12 printf("Noeud %d : ( %4.5f ; %4.5f ; %4.5f )\n",i,nodes[3*i],nodes[3*i+1],
16 void cree_nodes(med_float * coord_nodes,int nnpl, int flag)
19 int nbr_nodes=nnpl*nnpl*nnpl;
21 int diviseur=nnpl-1+flag;
23 /*coord_nodes=(med_float *) malloc(3*nbr_nodes*sizeof(med_float));*/
25 for (i=0;i<nnpl;i++) for (j=0;j<nnpl;j++) for (k=0;k<nnpl;k++)
27 num_noeud=i+nnpl*j+nnpl*nnpl*k;
29 if (3*num_noeud >=3*nbr_nodes)
30 {printf("%d : OUT OF RANGE REQUEST\n",num_noeud);exit(-1);}
31 if (3*num_noeud+1>=3*nbr_nodes)
32 {printf("%d : OUT OF RANGE REQUEST\n",num_noeud);exit(-1);}
33 if (3*num_noeud+2>=3*nbr_nodes)
34 {printf("%d : OUT OF RANGE REQUEST\n",num_noeud);exit(-1);}
36 coord_nodes[3*num_noeud ]= (double) (i+flag)/diviseur;
37 coord_nodes[3*num_noeud+1]= (double) (j+flag)/diviseur;
38 coord_nodes[3*num_noeud+2]= (double) (k+flag)/diviseur;
41 affiche_noeuds(coord_nodes,nnpl);
45 void cree_num_nodes(med_int * num_nodes,int nnpl)
47 int nbr_nodes=nnpl*nnpl*nnpl;
49 /*num_nodes=(med_int *) malloc(nbr_nodes*sizeof(med_int));*/
50 for (i=0;i<nbr_nodes;i++) num_nodes[i]=i+1;//nbr_nodes+i;
53 void cree_Hexa8(med_int * conn_hexa8, int nnpl,med_int * num_nodes)
56 int i0,j0,k0,i1,j1,k1;
57 int nbr_nodes=nnpl*nnpl*nnpl;
58 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
61 /*conn_hexa8=(med_int *) malloc(8*nbr_hexa8*sizeof(med_int));*/
63 for (i=0;i<nnpl-1;i++) for (j=0;j<nnpl-1;j++) for (k=0;k<nnpl-1;k++)
68 num_hexa8=i+(nnpl-1)*j+(nnpl-1)*(nnpl-1)*k;
70 if (8*num_hexa8 >=8*nbr_hexa8)
71 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
72 if (8*num_hexa8+1>=8*nbr_hexa8)
73 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
74 if (8*num_hexa8+2>=8*nbr_hexa8)
75 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
76 if (8*num_hexa8+3>=8*nbr_hexa8)
77 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
78 if (8*num_hexa8+4>=8*nbr_hexa8)
79 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
80 if (8*num_hexa8+5>=8*nbr_hexa8)
81 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
82 if (8*num_hexa8+6>=8*nbr_hexa8)
83 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
84 if (8*num_hexa8+7>=8*nbr_hexa8)
85 {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
87 conn_hexa8[8*num_hexa8 ] = num_nodes[ i0+nnpl*j1+nnpl*nnpl*k1 ];
88 conn_hexa8[8*num_hexa8+1] = num_nodes[ i0+nnpl*j0+nnpl*nnpl*k1 ];
89 conn_hexa8[8*num_hexa8+2] = num_nodes[ i1+nnpl*j0+nnpl*nnpl*k1 ];
90 conn_hexa8[8*num_hexa8+3] = num_nodes[ i1+nnpl*j1+nnpl*nnpl*k1 ];
91 conn_hexa8[8*num_hexa8+4] = num_nodes[ i0+nnpl*j1+nnpl*nnpl*k0 ];
92 conn_hexa8[8*num_hexa8+5] = num_nodes[ i0+nnpl*j0+nnpl*nnpl*k0 ];
93 conn_hexa8[8*num_hexa8+6] = num_nodes[ i1+nnpl*j0+nnpl*nnpl*k0 ];
94 conn_hexa8[8*num_hexa8+7] = num_nodes[ i1+nnpl*j1+nnpl*nnpl*k0 ];
99 for (num_hexa8=0;num_hexa8<nbr_hexa8;num_hexa8++)
101 printf("Maille numéro %4d :",num_hexa8);
102 printf("%4d ",conn_hexa8[8*num_hexa8 ]);
103 printf("%4d ",conn_hexa8[8*num_hexa8+1]);
104 printf("%4d ",conn_hexa8[8*num_hexa8+2]);
105 printf("%4d ",conn_hexa8[8*num_hexa8+3]);
106 printf("%4d ",conn_hexa8[8*num_hexa8+4]);
107 printf("%4d ",conn_hexa8[8*num_hexa8+5]);
108 printf("%4d ",conn_hexa8[8*num_hexa8+6]);
109 printf("%4d ",conn_hexa8[8*num_hexa8+7]);
114 void cree_noms_mailles(char * noms, int nnpl)
116 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
118 char pnom[MED_TAILLE_PNOM+1]="hexa ";
120 /*noms=(char *) malloc((nbr_hexa8*MED_TAILLE_PNOM+1)*sizeof(char));*/
122 for (i=0;i<nbr_hexa8;i++) strncpy(&noms[i*MED_TAILLE_PNOM],pnom,MED_TAILLE_PNOM);
124 noms[nbr_hexa8*MED_TAILLE_PNOM]='\n';
127 void cree_num_mailles(med_int * num_mailles,int nnpl)
129 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
132 /*num_mailles=(med_int *) malloc(nbr_hexa8*sizeof(med_int));*/
134 for (i=0;i<nbr_hexa8;i++) num_mailles[i]=i+1;
137 void cree_fam_nodes(med_int * fam,int nnpl)
139 int nbr_nodes=nnpl*nnpl*nnpl;
142 /*fam=(med_int *) malloc(nbr_nodes*sizeof(med_int));*/
144 for (i=0;i<nbr_nodes;i++) fam[i]=0;
147 void cree_fam_mailles(med_int * fam,int nnpl)
149 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
152 /*fam=(med_int *) malloc(nbr_hexa8*sizeof(med_int));*/
154 for (i=0;i<nbr_hexa8;i++) fam[i]=0;
157 void cree_valeurs_champ_node(med_float * val,int nnpl)
160 int nbr_nodes=nnpl*nnpl*nnpl;
162 int diviseur=3*(nnpl-1);
164 /*val=(med_float *) malloc(nbr_nodes*sizeof(med_float));*/
166 for (i=0;i<nnpl;i++) for (j=0;j<nnpl;j++) for (k=0;k<nnpl;k++)
168 num_noeud=i+nnpl*j+nnpl*nnpl*k;
169 val[num_noeud] = (med_float) (i+j+k)/diviseur;
171 for (num_noeud=0;num_noeud<nbr_nodes;num_noeud++)
172 printf("Valeur Scalaire noeud %5d : %4.5f\n",num_noeud,val[num_noeud]);
175 void cree_valeurs_champ_vector_node(med_float * val,int nnpl)
178 int nbr_nodes=nnpl*nnpl*nnpl;
181 /*val=(med_float *) malloc(nbr_nodes*sizeof(med_float));*/
183 for (i=0;i<nnpl;i++) for (j=0;j<nnpl;j++) for (k=0;k<nnpl;k++)
185 num_noeud=i+nnpl*j+nnpl*nnpl*k;
186 val[3*num_noeud ] = (med_float) 0;
187 val[3*num_noeud+1] = (med_float) 1;
188 val[3*num_noeud+2] = (med_float) 2;
190 for (num_noeud=0;num_noeud<nbr_nodes;num_noeud++)
191 printf("Valeur Vectorielle noeud %5d : %4.5f %4.5f %4.5f \n ",num_noeud,
192 val[3*num_noeud],val[3*num_noeud+1],val[3*num_noeud+2]);
195 void cree_valeurs_champ_cell(med_float * val,int nnpl)
198 int nbr_cells=(nnpl-1)*(nnpl-1)*(nnpl-1);
201 med_float diviseur=3*(nnpl-2);
203 /*val=(med_float *) malloc(3*nbr_cells*sizeof(med_float));*/
205 for (i=0;i<nnpl-1;i++) for (j=0;j<nnpl-1;j++) for (k=0;k<nnpl-1;k++)
207 num_cell=i+(nnpl-1)*j+(nnpl-1)*(nnpl-1)*k;
208 val[num_cell ] = (med_float) (i+j+k)/diviseur;
210 for (num_cell=0;num_cell<nbr_cells;num_cell++)
211 printf("Valeur scalaire maille %5d : %4.5f\n ",num_cell,val[num_cell]);
214 void cree_valeurs_champ_vector_cell(med_float * val,int nnpl)
217 int nbr_cells=(nnpl-1)*(nnpl-1)*(nnpl-1);
220 /*val=(med_float *) malloc(3*nbr_cells*sizeof(med_float));*/
222 for (i=0;i<nnpl-1;i++) for (j=0;j<nnpl-1;j++) for (k=0;k<nnpl-1;k++)
224 num_cell=i+(nnpl-1)*j+(nnpl-1)*(nnpl-1)*k;
225 val[3*num_cell ] = (med_float) 0;
226 val[3*num_cell+1] = (med_float) 1;
227 val[3*num_cell+2] = (med_float) 2;
229 for (num_cell=0;num_cell<nbr_cells;num_cell++)
230 printf("Valeur Vectorielle maille %5d : %4.5f %4.5f %4.5f \n ",num_cell,
231 val[3*num_cell],val[3*num_cell+1],val[3*num_cell+2]);
235 /*****************************************************************************************************/
237 int main (int argc, char **argv)
244 int nbr_nodes, nbr_hexa8;
249 char frommaa[MED_TAILLE_NOM+1] = "fromMesh";
250 char frommaadesc[MED_TAILLE_DESC+1] = "First 3D non-structured mesh example for the Interpolation module in Med Memory";
251 char tomaa[MED_TAILLE_NOM+1] = "toMesh";
252 char tomaadesc[MED_TAILLE_DESC+1] = "Second 3D non-structured mesh example for the Interpolation module in Med Memory";
253 const med_int mdim = 3;
260 char nomcoo[3*MED_TAILLE_PNOM+1] = "x y z ";
261 char unicoo[3*MED_TAILLE_PNOM+1] = "cm cm cm ";
263 char * nomnoe = NULL ;
265 med_int * fromnumnoe;
266 med_int * fromnufano;
279 med_int * fromnumhexa8;
280 med_int * fromnufahexa8;
283 med_int * tonumhexa8;
284 med_int * tonufahexa8;
286 /*****************************************************************************************************/
288 char nomfam[MED_TAILLE_NOM+1];
290 char attdes[MED_TAILLE_DESC+1];
295 char gro[MED_TAILLE_LNOM+1];
296 char gro2[MED_TAILLE_LNOM*2+1];
297 char gro3[MED_TAILLE_LNOM*3+1];
301 /*****************************************************************************************************/
303 /* Some fields : one on nodes : double , one on cells : double */
305 char champnode[MED_TAILLE_NOM+1]="fieldnodedouble" ;
306 char champnode_comp[MED_TAILLE_PNOM+1]="X+Y+Z " ;
307 char champnode_unit[MED_TAILLE_PNOM+1]="X+Y+Z " ;
308 med_float * fieldnodedouble;
310 char champnodevector[MED_TAILLE_NOM+1]="fieldnodedoublevector" ;
311 char champnodevector_comp[MED_TAILLE_PNOM*3+1]="0 1 2 " ;
312 char champnodevector_unit[MED_TAILLE_PNOM*3+1]="O 1 2 " ;
313 med_float * fieldnodedoublevector;
315 char champcellscalar[MED_TAILLE_NOM+1]="fieldcelldouble" ;
316 char champcellscalar_comp[MED_TAILLE_PNOM+1]="X+Y+Z " ;
317 char champcellscalar_unit[MED_TAILLE_PNOM+1]="X+Y+Z " ;
318 med_float * fieldcelldouble;
320 char champcell[MED_TAILLE_NOM+1]="fieldcelldoublevector" ;
321 char champcell_comp[MED_TAILLE_PNOM*3+1]="0 1 2 " ;
322 char champcell_unit[MED_TAILLE_PNOM*3+1]="0 1 2 " ;
323 med_float * fieldcelldoublevector;
325 /*****************************************************************************************************/
329 printf("Il manque un paramètre : le nombre de point par ligne\n");
333 sscanf(argv[1],"%d",&nnpl);
335 printf("VERSION 2.0\n");
336 printf("Traitement avec %d noeuds par ligne\n",nnpl);
338 fromnnoe = nnpl*nnpl*nnpl ;
339 fromnhexa8 = (nnpl-1)*(nnpl-1)*(nnpl-1) ;
340 tonnoe = (nnpl-1)*(nnpl-1)*(nnpl-1) ;
341 tonhexa8 = (nnpl-2)*(nnpl-2)*(nnpl-2) ;
343 nbr_nodes=nnpl*nnpl*nnpl;
344 nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
346 fromcoo = (med_float *) malloc(3*nbr_nodes*sizeof(med_float));
347 cree_nodes ( fromcoo , nnpl, 0 );
349 fromnumnoe = (med_int *) malloc(nbr_nodes*sizeof(med_int));
350 cree_num_nodes ( fromnumnoe , nnpl );
352 fromnufano = (med_int *) malloc(nbr_nodes*sizeof(med_int));
353 cree_fam_nodes ( fromnufano , nnpl );
355 fromhexa8 = (med_int *) malloc(8*nbr_hexa8*sizeof(med_int));
356 cree_Hexa8 ( fromhexa8 , nnpl ,fromnumnoe);
358 fromnomhexa8 = (char *) malloc((nbr_hexa8*MED_TAILLE_PNOM+1)*sizeof(char));
359 cree_noms_mailles ( fromnomhexa8 , nnpl );
361 fromnumhexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int));
362 cree_num_mailles ( fromnumhexa8 , nnpl );
364 fromnufahexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int));
365 cree_fam_mailles ( fromnufahexa8 , nnpl );
367 fieldnodedouble = (med_float *) malloc(nbr_nodes*sizeof(med_float));
368 cree_valeurs_champ_node ( fieldnodedouble , nnpl );
370 fieldnodedoublevector = (med_float *) malloc(3*nbr_nodes*sizeof(med_float));
371 cree_valeurs_champ_vector_node ( fieldnodedoublevector , nnpl );
373 fieldcelldouble = (med_float *) malloc(nbr_hexa8*sizeof(med_float));
374 cree_valeurs_champ_cell ( fieldcelldouble , nnpl );
376 fieldcelldoublevector = (med_float *) malloc(3*nbr_hexa8*sizeof(med_float));
377 cree_valeurs_champ_vector_cell ( fieldcelldoublevector , nnpl );
379 nbr_nodes=(nnpl-1)*(nnpl-1)*(nnpl-1);
380 nbr_hexa8=(nnpl-2)*(nnpl-2)*(nnpl-2);
382 tocoo = (med_float *) malloc(3*nbr_nodes*sizeof(med_float));
383 cree_nodes ( tocoo , nnpl-1, 1 );
385 tonumnoe = (med_int *) malloc(nbr_nodes*sizeof(med_int));
386 cree_num_nodes ( tonumnoe , nnpl-1 );
388 tonufano = (med_int *) malloc(nbr_nodes*sizeof(med_int));
389 cree_fam_nodes ( tonufano , nnpl-1 );
391 tohexa8 = (med_int *) malloc(8*nbr_hexa8*sizeof(med_int));
392 cree_Hexa8 ( tohexa8 , nnpl-1 ,tonumnoe);
394 tonomhexa8 = (char *) malloc((nbr_hexa8*MED_TAILLE_PNOM+1)*sizeof(char));
395 cree_noms_mailles ( tonomhexa8 , nnpl-1 );
397 tonumhexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int));
398 cree_num_mailles ( tonumhexa8 , nnpl-1 );
400 tonufahexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int));
401 cree_fam_mailles ( tonufahexa8 , nnpl-1 );
404 /*****************************************************************************************************/
405 fromfid = MEDouvrir("fromMesh.med",MED_LECTURE_ECRITURE);
412 printf("MEDouvrir : %d\n",ret);
413 /*****************************************************************************************************/
414 tofid = MEDouvrir("toMesh.med",MED_LECTURE_ECRITURE);
421 printf("MEDouvrir : %d\n",ret);
422 /*****************************************************************************************************/
424 ret = MEDmaaCr(fromfid,frommaa,mdim,MED_NON_STRUCTURE,frommaadesc);
426 printf("MEDmaaCr : %d\n",ret);
427 /*****************************************************************************************************/
429 ret = MEDmaaCr(tofid,tomaa,mdim,MED_NON_STRUCTURE,tomaadesc);
431 printf("MEDmaaCr : %d\n",ret);
432 /*****************************************************************************************************/
434 ret = MEDnoeudsEcr(fromfid,frommaa,mdim,fromcoo,MED_FULL_INTERLACE,
435 MED_CART,nomcoo,unicoo,nomnoe,MED_FAUX,fromnumnoe,
436 MED_FAUX,fromnufano,fromnnoe);
438 printf("MEDnoeudsEcr : %d\n",ret);
439 /*****************************************************************************************************/
441 ret = MEDnoeudsEcr(tofid,tomaa,mdim,tocoo,MED_FULL_INTERLACE,MED_CART,
442 nomcoo,unicoo,nomnoe,MED_FAUX,tonumnoe,MED_FAUX,
445 printf("MEDnoeudsEcr : %d\n",ret);
447 /*****************************************************************************************************/
448 /* ecriture des mailles MED_HEXA8 :
451 - numeros (optionnel)
452 - numeros des familles */
455 ret = MEDelementsEcr(fromfid,frommaa,mdim,fromhexa8,MED_FULL_INTERLACE,
456 fromnomhexa8,MED_FAUX,fromnumhexa8,MED_VRAI,
457 fromnufahexa8,fromnhexa8,MED_MAILLE,
460 printf("MEDelementsEcr : %d \n",ret);
461 /*****************************************************************************************************/
462 /* ecriture des mailles MED_HEXA8 :
465 - numeros (optionnel)
466 - numeros des familles */
469 ret = MEDelementsEcr(tofid,tomaa,mdim,tohexa8,MED_FULL_INTERLACE,
470 tonomhexa8,MED_FAUX,tonumhexa8,MED_VRAI,tonufahexa8,
471 tonhexa8,MED_MAILLE,MED_HEXA8,MED_NOD);
473 printf("MEDelementsEcr : %d \n",ret);
474 /*****************************************************************************************************/
475 /* ecriture des familles */
477 - toujours creer une famille de numero 0 ne comportant aucun attribut
478 ni groupe (famille de reference pour les noeuds ou les elements
479 qui ne sont rattaches a aucun groupe ni attribut)
480 - les numeros de familles de noeuds sont > 0
481 - les numeros de familles des elements sont < 0
482 - rien d'imposer sur les noms de familles
489 strcpy(nomfam,"FAMILLE_0");
491 ret = MEDfamCr(fromfid,frommaa,nomfam,numfam,&attide,&attval,attdes,0,
495 printf("MEDfamCr : %d \n",ret);
496 /*****************************************************************************************************/
499 strcpy(nomfam,"FAMILLE_0");
501 ret = MEDfamCr(tofid,tomaa,nomfam,numfam,&attide,&attval,attdes,0,gro,0);
504 printf("MEDfamCr : %d \n",ret);
505 /*****************************************************************************************************/
510 ret = MEDchampCr(fromfid,champnode,MED_FLOAT64,champnode_comp,
513 printf("MEDchampCr : %d \n",ret);
517 ret = MEDchampEcr(fromfid, frommaa, champnode,
518 (unsigned char *)fieldnodedouble,
519 MED_FULL_INTERLACE, fromnnoe, MED_NOGAUSS,
520 MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
521 MED_NOPDT," ", 0. , MED_NONOR);
523 printf("MEDchampEcr : %d \n",ret);
529 ret = MEDchampCr(fromfid,champcell,MED_FLOAT64,champcell_comp,
532 printf("MEDchampCr : %d \n",ret);
536 ret = MEDchampEcr(fromfid, frommaa, champcell,
537 (unsigned char *)fieldcelldoublevector,
538 MED_FULL_INTERLACE, fromnhexa8, MED_NOGAUSS,
539 MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE,
540 MED_HEXA8, MED_NOPDT," ", 0., MED_NONOR);
542 printf("MEDchampEcr : %d \n",ret);
548 ret = MEDchampCr(fromfid,champcellscalar,MED_FLOAT64,
549 champcellscalar_comp,champcellscalar_unit,1);
551 printf("MEDchampCr : %d \n",ret);
555 ret = MEDchampEcr(fromfid, frommaa, champcellscalar,
556 (unsigned char *)fieldcelldouble,
557 MED_FULL_INTERLACE, fromnhexa8, MED_NOGAUSS,
558 MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE,
559 MED_HEXA8, MED_NOPDT," ", 0., MED_NONOR);
561 printf("MEDchampEcr : %d \n",ret);
567 ret = MEDchampCr(fromfid,champnodevector,MED_FLOAT64,
568 champnodevector_comp,champnodevector_unit,3);
569 printf("MEDchampCr : %d \n",ret);
573 ret = MEDchampEcr(fromfid, frommaa, champnodevector,
574 (unsigned char *)fieldnodedoublevector,
575 MED_FULL_INTERLACE, fromnnoe, MED_NOGAUSS,
576 MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD,
577 0, MED_NOPDT," ", 0. , MED_NONOR);
579 printf("MEDchampEcr : %d \n",ret);
584 /***************************************************************************/
585 ret = MEDfermer(fromfid);
587 printf("MEDfermer : %d\n",ret);
588 /***************************************************************************/
589 ret = MEDfermer(tofid);
591 printf("MEDfermer : %d\n",ret);