5 /*****************************************************************************************************/
7 void affiche_noeuds(med_float * nodes,int nnpl)
9 int nbr_nodes=nnpl*nnpl*nnpl;
12 for (i=0;i<nbr_nodes;i++) printf("Noeud %d : ( %4.5f ; %4.5f ; %4.5f )\n",i,nodes[3*i],nodes[3*i+1],nodes[3*i+2]);
17 void cree_nodes(med_float * coord_nodes,int nnpl, int flag)
20 int nbr_nodes=nnpl*nnpl*nnpl;
22 int diviseur=nnpl-1+flag;
24 /*coord_nodes=(med_float *) malloc(3*nbr_nodes*sizeof(med_float));*/
26 for (i=0;i<nnpl;i++) for (j=0;j<nnpl;j++) for (k=0;k<nnpl;k++)
28 num_noeud=i+nnpl*j+nnpl*nnpl*k;
30 if (3*num_noeud >=3*nbr_nodes) {printf("%d : OUT OF RANGE REQUEST\n",num_noeud);exit(-1);}
31 if (3*num_noeud+1>=3*nbr_nodes) {printf("%d : OUT OF RANGE REQUEST\n",num_noeud);exit(-1);}
32 if (3*num_noeud+2>=3*nbr_nodes) {printf("%d : OUT OF RANGE REQUEST\n",num_noeud);exit(-1);}
34 coord_nodes[3*num_noeud ]= (double) (i+flag)/diviseur;
35 coord_nodes[3*num_noeud+1]= (double) (j+flag)/diviseur;
36 coord_nodes[3*num_noeud+2]= (double) (k+flag)/diviseur;
39 affiche_noeuds(coord_nodes,nnpl);
42 void cree_num_nodes(med_int * num_nodes,int nnpl)
44 int nbr_nodes=nnpl*nnpl*nnpl;
46 /*num_nodes=(med_int *) malloc(nbr_nodes*sizeof(med_int));*/
47 for (i=0;i<nbr_nodes;i++) num_nodes[i]=i+1;//nbr_nodes+i;
49 void cree_Hexa8(med_int * conn_hexa8, int nnpl,med_int * num_nodes)
52 int i0,j0,k0,i1,j1,k1;
53 int nbr_nodes=nnpl*nnpl*nnpl;
54 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
57 /*conn_hexa8=(med_int *) malloc(8*nbr_hexa8*sizeof(med_int));*/
59 for (i=0;i<nnpl-1;i++) for (j=0;j<nnpl-1;j++) for (k=0;k<nnpl-1;k++)
64 num_hexa8=i+(nnpl-1)*j+(nnpl-1)*(nnpl-1)*k;
66 if (8*num_hexa8 >=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
67 if (8*num_hexa8+1>=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
68 if (8*num_hexa8+2>=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
69 if (8*num_hexa8+3>=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
70 if (8*num_hexa8+4>=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
71 if (8*num_hexa8+5>=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
72 if (8*num_hexa8+6>=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
73 if (8*num_hexa8+7>=8*nbr_hexa8) {printf("%d : OUT OF RANGE REQUEST\n",num_hexa8);exit(-1);}
75 conn_hexa8[8*num_hexa8 ] = num_nodes[ i0+nnpl*j1+nnpl*nnpl*k1 ];
76 conn_hexa8[8*num_hexa8+1] = num_nodes[ i0+nnpl*j0+nnpl*nnpl*k1 ];
77 conn_hexa8[8*num_hexa8+2] = num_nodes[ i1+nnpl*j0+nnpl*nnpl*k1 ];
78 conn_hexa8[8*num_hexa8+3] = num_nodes[ i1+nnpl*j1+nnpl*nnpl*k1 ];
79 conn_hexa8[8*num_hexa8+4] = num_nodes[ i0+nnpl*j1+nnpl*nnpl*k0 ];
80 conn_hexa8[8*num_hexa8+5] = num_nodes[ i0+nnpl*j0+nnpl*nnpl*k0 ];
81 conn_hexa8[8*num_hexa8+6] = num_nodes[ i1+nnpl*j0+nnpl*nnpl*k0 ];
82 conn_hexa8[8*num_hexa8+7] = num_nodes[ i1+nnpl*j1+nnpl*nnpl*k0 ];
87 for (num_hexa8=0;num_hexa8<nbr_hexa8;num_hexa8++)
89 printf("Maille numéro %4d :",num_hexa8);
90 printf("%4d ",conn_hexa8[8*num_hexa8 ]);
91 printf("%4d ",conn_hexa8[8*num_hexa8+1]);
92 printf("%4d ",conn_hexa8[8*num_hexa8+2]);
93 printf("%4d ",conn_hexa8[8*num_hexa8+3]);
94 printf("%4d ",conn_hexa8[8*num_hexa8+4]);
95 printf("%4d ",conn_hexa8[8*num_hexa8+5]);
96 printf("%4d ",conn_hexa8[8*num_hexa8+6]);
97 printf("%4d ",conn_hexa8[8*num_hexa8+7]);
101 void cree_noms_mailles(char * noms, int nnpl)
103 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
105 char pnom[MED_TAILLE_PNOM+1]="hexa ";
107 /*noms=(char *) malloc((nbr_hexa8*MED_TAILLE_PNOM+1)*sizeof(char));*/
109 for (i=0;i<nbr_hexa8;i++) strncpy(&noms[i*MED_TAILLE_PNOM],pnom,MED_TAILLE_PNOM);
111 noms[nbr_hexa8*MED_TAILLE_PNOM]='\n';
114 void cree_num_mailles(med_int * num_mailles,int nnpl)
116 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
119 /*num_mailles=(med_int *) malloc(nbr_hexa8*sizeof(med_int));*/
121 for (i=0;i<nbr_hexa8;i++) num_mailles[i]=i+1;
123 void cree_fam_nodes(med_int * fam,int nnpl)
125 int nbr_nodes=nnpl*nnpl*nnpl;
128 /*fam=(med_int *) malloc(nbr_nodes*sizeof(med_int));*/
130 for (i=0;i<nbr_nodes;i++) fam[i]=0;
132 void cree_fam_mailles(med_int * fam,int nnpl)
134 int nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
137 /*fam=(med_int *) malloc(nbr_hexa8*sizeof(med_int));*/
139 for (i=0;i<nbr_hexa8;i++) fam[i]=0;
141 void cree_valeurs_champ_node(med_float * val,int nnpl)
144 int nbr_nodes=nnpl*nnpl*nnpl;
146 int diviseur=3*(nnpl-1);
148 /*val=(med_float *) malloc(nbr_nodes*sizeof(med_float));*/
150 for (i=0;i<nnpl;i++) for (j=0;j<nnpl;j++) for (k=0;k<nnpl;k++)
152 num_noeud=i+nnpl*j+nnpl*nnpl*k;
153 val[num_noeud] = (med_float) (i+j+k)/diviseur;
155 for (num_noeud=0;num_noeud<nbr_nodes;num_noeud++) printf("Valeur Scalaire noeud %5d : %4.5f\n",num_noeud,val[num_noeud]);
157 void cree_valeurs_champ_vector_node(med_float * val,int nnpl)
160 int nbr_nodes=nnpl*nnpl*nnpl;
163 /*val=(med_float *) malloc(nbr_nodes*sizeof(med_float));*/
165 for (i=0;i<nnpl;i++) for (j=0;j<nnpl;j++) for (k=0;k<nnpl;k++)
167 num_noeud=i+nnpl*j+nnpl*nnpl*k;
168 val[3*num_noeud ] = (med_float) 0;
169 val[3*num_noeud+1] = (med_float) 1;
170 val[3*num_noeud+2] = (med_float) 2;
172 for (num_noeud=0;num_noeud<nbr_nodes;num_noeud++) printf("Valeur Vectorielle noeud %5d : %4.5f %4.5f %4.5f \n ",num_noeud,val[3*num_noeud],val[3*num_noeud+1],val[3*num_noeud+2]);
174 void cree_valeurs_champ_cell(med_float * val,int nnpl)
177 int nbr_cells=(nnpl-1)*(nnpl-1)*(nnpl-1);
180 med_float diviseur=3*(nnpl-2);
182 /*val=(med_float *) malloc(3*nbr_cells*sizeof(med_float));*/
184 for (i=0;i<nnpl-1;i++) for (j=0;j<nnpl-1;j++) for (k=0;k<nnpl-1;k++)
186 num_cell=i+(nnpl-1)*j+(nnpl-1)*(nnpl-1)*k;
187 val[num_cell ] = (med_float) (i+j+k)/diviseur;
189 for (num_cell=0;num_cell<nbr_cells;num_cell++) printf("Valeur scalaire maille %5d : %4.5f\n ",num_cell,val[num_cell]);
191 void cree_valeurs_champ_vector_cell(med_float * val,int nnpl)
194 int nbr_cells=(nnpl-1)*(nnpl-1)*(nnpl-1);
197 /*val=(med_float *) malloc(3*nbr_cells*sizeof(med_float));*/
199 for (i=0;i<nnpl-1;i++) for (j=0;j<nnpl-1;j++) for (k=0;k<nnpl-1;k++)
201 num_cell=i+(nnpl-1)*j+(nnpl-1)*(nnpl-1)*k;
202 val[3*num_cell ] = (med_float) 0;
203 val[3*num_cell+1] = (med_float) 1;
204 val[3*num_cell+2] = (med_float) 2;
206 for (num_cell=0;num_cell<nbr_cells;num_cell++) printf("Valeur Vectorielle maille %5d : %4.5f %4.5f %4.5f \n ",num_cell,val[3*num_cell],val[3*num_cell+1],val[3*num_cell+2]);
210 /*****************************************************************************************************/
212 int main (int argc, char **argv)
219 int nbr_nodes, nbr_hexa8;
224 char frommaa[MED_TAILLE_NOM+1] = "fromMesh";
225 char tomaa[MED_TAILLE_NOM+1] = "toMesh";
226 char frommaadesc[MED_TAILLE_DESC+1] = "Initial Mesh description";
227 char tomaadesc[MED_TAILLE_DESC+1] = "Target Mesh description";
228 med_maillage type = MED_NON_STRUCTURE;
229 const med_int mdim = 3;
236 char nomcoo[3*MED_TAILLE_PNOM+1] = "x y z ";
237 char unicoo[3*MED_TAILLE_PNOM+1] = "cm cm cm ";
239 char * nomnoe = NULL ;
241 med_int * fromnumnoe;
242 med_int * fromnufano;
255 med_int * fromnumhexa8;
256 med_int * fromnufahexa8;
259 med_int * tonumhexa8;
260 med_int * tonufahexa8;
262 /*****************************************************************************************************/
264 char nomfam[MED_TAILLE_NOM+1];
266 char attdes[MED_TAILLE_DESC+1];
271 char gro[MED_TAILLE_LNOM+1];
272 char gro2[MED_TAILLE_LNOM*2+1];
273 char gro3[MED_TAILLE_LNOM*3+1];
277 /*****************************************************************************************************/
279 /* Some fields : one on nodes : double , one on cells : double */
281 char champnode[MED_TAILLE_NOM+1]="fieldnodedouble" ;
282 char champnode_comp[MED_TAILLE_PNOM+1]="X+Y+Z " ;
283 char champnode_unit[MED_TAILLE_PNOM+1]="X+Y+Z " ;
284 med_float * fieldnodedouble;
286 char champnodevector[MED_TAILLE_NOM+1]="fieldnodedoublevector" ;
287 char champnodevector_comp[MED_TAILLE_PNOM*3+1]="0 1 2 " ;
288 char champnodevector_unit[MED_TAILLE_PNOM*3+1]="O 1 2 " ;
289 med_float * fieldnodedoublevector;
291 char champcellscalar[MED_TAILLE_NOM+1]="fieldcelldouble" ;
292 char champcellscalar_comp[MED_TAILLE_PNOM+1]="X+Y+Z " ;
293 char champcellscalar_unit[MED_TAILLE_PNOM+1]="X+Y+Z " ;
294 med_float * fieldcelldouble;
296 char champcell[MED_TAILLE_NOM+1]="fieldcelldoublevector" ;
297 char champcell_comp[MED_TAILLE_PNOM*3+1]="0 1 2 " ;
298 char champcell_unit[MED_TAILLE_PNOM*3+1]="0 1 2 " ;
299 med_float * fieldcelldoublevector;
301 /*****************************************************************************************************/
306 printf("Il manque un paramètre : le nombre de point par ligne\n");
310 sscanf(argv[1],"%d",&nnpl);
312 printf("VERSION 2.0\n");
313 printf("Traitement avec %d noeuds par ligne\n",nnpl);
315 fromnnoe = nnpl*nnpl*nnpl ;
316 fromnhexa8 = (nnpl-1)*(nnpl-1)*(nnpl-1) ;
317 tonnoe = (nnpl-1)*(nnpl-1)*(nnpl-1) ;
318 tonhexa8 = (nnpl-2)*(nnpl-2)*(nnpl-2) ;
322 nbr_nodes=nnpl*nnpl*nnpl;
323 nbr_hexa8=(nnpl-1)*(nnpl-1)*(nnpl-1);
325 fromcoo = (med_float *) malloc(3*nbr_nodes*sizeof(med_float)); cree_nodes ( fromcoo , nnpl, 0 );
326 fromnumnoe = (med_int *) malloc(nbr_nodes*sizeof(med_int)); cree_num_nodes ( fromnumnoe , nnpl );
327 fromnufano = (med_int *) malloc(nbr_nodes*sizeof(med_int)); cree_fam_nodes ( fromnufano , nnpl );
328 fromhexa8 = (med_int *) malloc(8*nbr_hexa8*sizeof(med_int)); cree_Hexa8 ( fromhexa8 , nnpl ,fromnumnoe);
329 fromnomhexa8 = (char *) malloc((nbr_hexa8*MED_TAILLE_PNOM+1)*sizeof(char)); cree_noms_mailles ( fromnomhexa8 , nnpl );
330 fromnumhexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int)); cree_num_mailles ( fromnumhexa8 , nnpl );
331 fromnufahexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int)); cree_fam_mailles ( fromnufahexa8 , nnpl );
333 fieldnodedouble = (med_float *) malloc(nbr_nodes*sizeof(med_float)); cree_valeurs_champ_node ( fieldnodedouble , nnpl );
334 fieldnodedoublevector = (med_float *) malloc(3*nbr_nodes*sizeof(med_float)); cree_valeurs_champ_vector_node ( fieldnodedoublevector , nnpl );
335 fieldcelldouble = (med_float *) malloc(nbr_hexa8*sizeof(med_float)); cree_valeurs_champ_cell ( fieldcelldouble , nnpl );
336 fieldcelldoublevector = (med_float *) malloc(3*nbr_hexa8*sizeof(med_float)); cree_valeurs_champ_vector_cell ( fieldcelldoublevector , nnpl );
339 nbr_nodes=(nnpl-1)*(nnpl-1)*(nnpl-1);
340 nbr_hexa8=(nnpl-2)*(nnpl-2)*(nnpl-2);
342 tocoo = (med_float *) malloc(3*nbr_nodes*sizeof(med_float)); cree_nodes ( tocoo , nnpl-1, 1 );
343 tonumnoe = (med_int *) malloc(nbr_nodes*sizeof(med_int)); cree_num_nodes ( tonumnoe , nnpl-1 );
344 tonufano = (med_int *) malloc(nbr_nodes*sizeof(med_int)); cree_fam_nodes ( tonufano , nnpl-1 );
345 tohexa8 = (med_int *) malloc(8*nbr_hexa8*sizeof(med_int)); cree_Hexa8 ( tohexa8 , nnpl-1 ,tonumnoe);
346 tonomhexa8 = (char *) malloc((nbr_hexa8*MED_TAILLE_PNOM+1)*sizeof(char)); cree_noms_mailles ( tonomhexa8 , nnpl-1 );
347 tonumhexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int)); cree_num_mailles ( tonumhexa8 , nnpl-1 );
348 tonufahexa8 = (med_int *) malloc(nbr_hexa8*sizeof(med_int)); cree_fam_mailles ( tonufahexa8 , nnpl-1 );
351 /*****************************************************************************************************/
352 fromfid = MEDouvrir("fromMesh.med",MED_LECTURE_AJOUT);
357 printf("MEDouvrir : %d\n",ret);
359 /*****************************************************************************************************/
360 tofid = MEDouvrir("toMesh.med",MED_LECTURE_AJOUT);
365 printf("MEDouvrir : %d\n",ret);
366 /*****************************************************************************************************/
368 ret = MEDmaaCr(fromfid,frommaa,mdim,type,frommaadesc);
369 printf("MEDmaaCr : %d\n",ret);
371 /*****************************************************************************************************/
374 ret = MEDmaaCr(tofid,tomaa,mdim,type,tomaadesc);
375 printf("MEDmaaCr : %d\n",ret);
377 /*****************************************************************************************************/
379 ret = MEDnoeudsEcr(fromfid,frommaa,mdim,fromcoo,MED_FULL_INTERLACE,MED_CART,
380 // nomcoo,unicoo,nomnoe,MED_FAUX,fromnumnoe,MED_VRAI,
381 nomcoo,unicoo,nomnoe,MED_FAUX,fromnumnoe,MED_FAUX,
382 fromnufano,fromnnoe);
383 printf("MEDnoeudsEcr : %d\n",ret);
384 /*****************************************************************************************************/
387 ret = MEDnoeudsEcr(tofid,tomaa,mdim,tocoo,MED_FULL_INTERLACE,MED_CART,
388 //nomcoo,unicoo,nomnoe,MED_FAUX,tonumnoe,MED_VRAI,
389 nomcoo,unicoo,nomnoe,MED_FAUX,tonumnoe,MED_FAUX,
391 printf("MEDnoeudsEcr : %d\n",ret);
394 /*****************************************************************************************************/
395 /* ecriture des mailles MED_HEXA8 :
398 - numeros (optionnel)
399 - numeros des familles */
401 ret = MEDelementsEcr(fromfid,frommaa,mdim,fromhexa8,MED_FULL_INTERLACE,
402 fromnomhexa8,MED_FAUX,fromnumhexa8,MED_VRAI,fromnufahexa8,fromnhexa8,
403 MED_MAILLE,MED_HEXA8,MED_NOD);
404 printf("MEDelementsEcr : %d \n",ret);
406 /*****************************************************************************************************/
407 /* ecriture des mailles MED_HEXA8 :
410 - numeros (optionnel)
411 - numeros des familles */
414 ret = MEDelementsEcr(tofid,tomaa,mdim,tohexa8,MED_FULL_INTERLACE,
415 tonomhexa8,MED_FAUX,tonumhexa8,MED_VRAI,tonufahexa8,tonhexa8,
416 MED_MAILLE,MED_HEXA8,MED_NOD);
417 printf("MEDelementsEcr : %d \n",ret);
419 /*****************************************************************************************************/
420 /* ecriture des familles */
422 - toujours creer une famille de numero 0 ne comportant aucun attribut
423 ni groupe (famille de reference pour les noeuds ou les elements
424 qui ne sont rattaches a aucun groupe ni attribut)
425 - les numeros de familles de noeuds sont > 0
426 - les numeros de familles des elements sont < 0
427 - rien d'imposer sur les noms de familles
433 strcpy(nomfam,"FAMILLE_0");
435 ret = MEDfamCr(fromfid,frommaa,nomfam,numfam,&attide,&attval,attdes,0,gro,0);
437 printf("MEDfamCr : %d \n",ret);
438 /*****************************************************************************************************/
442 strcpy(nomfam,"FAMILLE_0");
444 ret = MEDfamCr(tofid,tomaa,nomfam,numfam,&attide,&attval,attdes,0,gro,0);
446 printf("MEDfamCr : %d \n",ret);
448 /*****************************************************************************************************/
453 ret = MEDchampCr(fromfid,champnode,MED_FLOAT64,champnode_comp,champnode_unit,1);
454 printf("MEDchampCr : %d \n",ret);
457 ret = MEDchampEcr(fromfid, frommaa, champnode, (unsigned char *)fieldnodedouble,
458 MED_FULL_INTERLACE, fromnnoe,
459 MED_NOGAUSS, MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD,
460 0, MED_NOPDT," ", 0. , MED_NONOR);
461 printf("MEDchampEcr : %d \n",ret);
467 ret = MEDchampCr(fromfid,champcell,MED_FLOAT64,champcell_comp,champcell_unit,3);
468 printf("MEDchampCr : %d \n",ret);
471 ret = MEDchampEcr(fromfid, frommaa, champcell, (unsigned char *)fieldcelldoublevector,
472 MED_FULL_INTERLACE, fromnhexa8,
473 MED_NOGAUSS, MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE,
474 MED_HEXA8, MED_NOPDT," ", 0., MED_NONOR);
475 printf("MEDchampEcr : %d \n",ret);
481 ret = MEDchampCr(fromfid,champcellscalar,MED_FLOAT64,champcellscalar_comp,champcellscalar_unit,1);
482 printf("MEDchampCr : %d \n",ret);
485 ret = MEDchampEcr(fromfid, frommaa, champcellscalar, (unsigned char *)fieldcelldouble,
486 MED_FULL_INTERLACE, fromnhexa8,
487 MED_NOGAUSS, MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE,
488 MED_HEXA8, MED_NOPDT," ", 0., MED_NONOR);
489 printf("MEDchampEcr : %d \n",ret);
495 ret = MEDchampCr(fromfid,champnodevector,MED_FLOAT64,champnodevector_comp,champnodevector_unit,3);
496 printf("MEDchampCr : %d \n",ret);
499 ret = MEDchampEcr(fromfid, frommaa, champnodevector, (unsigned char *)fieldnodedoublevector,
500 MED_FULL_INTERLACE, fromnnoe,
501 MED_NOGAUSS, MED_ALL, MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD,
502 0, MED_NOPDT," ", 0. , MED_NONOR);
503 printf("MEDchampEcr : %d \n",ret);
508 /***************************************************************************/
509 ret = MEDfermer(fromfid);
510 printf("MEDfermer : %d\n",ret);
511 /***************************************************************************/
512 ret = MEDfermer(tofid);
513 printf("MEDfermer : %d\n",ret);