27 #ifdef PROJECT_POLYCRISTAUX
89 std::vector<OT_VECTEUR_3D>
cdm;
112 FILE *out=fopen(fichierout,
"wt");
113 LISTE_MG_POINT::iterator it;
115 if (pt->get_type()==MG_ELEMENT_GEOMETRIQUE::TYPE_ELEMENT_GEOMETRIQUE::LC_POINT)
119 fprintf(out,
"%e %e %e\n",xyz[0],xyz[1],xyz[2]);
167 std::vector<double> lstphase;
168 lstphase.push_back(0.68);
169 lstphase.push_back(0.32);
171 std::vector<double> lstdens;
172 lstdens.push_back(5.);
173 lstdens.push_back(12.);
175 std::vector<double> lst1,lst2,lst3;
176 lst1.push_back(66.69e9);
177 lst1.push_back(120.1e9);
178 lst2.push_back(0.4189);
180 lst3.push_back(75.4e9);
181 lst3.push_back(85.2e9);
206 affiche((
char*)
"\nCreation du fichier de parametre");
214 FILE *paraout2=fopen(nom2,
"wt");
215 fprintf(paraout2,
"-> %s\n",nom);
216 fprintf(paraout2,
"operationaeffectuer = 3.000000\n");
217 fprintf(paraout2,
"reprise_geo = 1.000000\n");
218 fprintf(paraout2,
"reprise_ori = 1.000000\n");
219 fprintf(paraout2,
"reprise_mai = 1.000000\n");
220 fprintf(paraout2,
"enregistrerres = 1.000000\n");
228 FILE *out = fopen(
"vasy",
"wt");
229 fprintf(out,
"#!/bin/bash\n");
230 fprintf(out,
"for ((c=1;c<=$1;c++))\n");
231 fprintf(out,
"do\n");
232 fprintf(out,
"timeout 900s %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom);
233 fprintf(out,
"VAR=$?\n");
234 fprintf(out,
"if (( $VAR )) ; then\n");
235 fprintf(out,
" echo \"Timeout\"\n");
236 fprintf(out,
"else\n");
237 fprintf(out,
" %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom2);
238 fprintf(out,
"fi\n");
239 fprintf(out,
"done\n");
243 out = fopen(
"vasy_par",
"wt");
244 fprintf(out,
"#!/bin/bash\n");
245 fprintf(out,
"VAR=1\n");
246 fprintf(out,
"while (($VAR))\n");
247 fprintf(out,
"do\n");
248 bool chemindanspath=
false;
249 if ((nomexe[0]>=
'a') && (nomexe[0]<=
'z')) chemindanspath=
true;
250 if ((nomexe[0]>=
'A') && (nomexe[0]<=
'Z')) chemindanspath=
true;
252 fprintf(out,
"timeout 1800s %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom);
254 fprintf(out,
"timeout 1800s ../%s -polycristaux -out cristal.magic -param %s\n", nomexe,nom);
255 fprintf(out,
"VAR=$?\n");
256 fprintf(out,
"if (( $VAR )) ; then\n");
257 fprintf(out,
" echo \"Timeout\"\n");
258 fprintf(out,
"else\n");
260 fprintf(out,
" %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom2);
262 fprintf(out,
" ../%s -polycristaux -out cristal.magic -param %s\n", nomexe,nom2);
263 fprintf(out,
"fi\n");
264 fprintf(out,
"done\n");
268 chmod (
"vasy",strtol(
"0777", NULL,8));
269 chmod (
"vasy_par",strtol(
"0777", NULL,8));
286 #ifdef PROJECT_POLYCRISTAUX
295 std::string nomfichierbrep=nomfichier+
".brep";
296 std::string nomfichierocaf=nomfichier+
".ocaf";
297 std::string nomfichiercarte=nomfichier+
".sol";
304 BOITE_3D boite(xmin,ymin,zmin,xmax,ymax,zmax);
309 std::random_device seed;
310 std::mt19937_64 generateur(seed());
311 affiche((
char*)
"\nInitialisation");
329 affiche((
char*)
"Generation de cristaux aléatoires");
330 double rayon=
param.
get_valeur(
"rayon")*0.3333333333333333333*(dx+dy+dz);
331 std::uniform_real_distribution<double> distribution_position_x(boite.
get_xmin(),boite.
get_xmax());
332 std::uniform_real_distribution<double> distribution_position_y(boite.
get_ymin(),boite.
get_ymax());
333 std::uniform_real_distribution<double> distribution_position_z(boite.
get_zmin(),boite.
get_zmax());
336 std::vector<POLYCRISTAUX::POINT_TIRE*> listepointainserer;
337 std::vector<double> listedepointvoro;
338 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmin());
339 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmin());
340 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmin());
341 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmin());
342 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmax());
343 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmax());
344 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmax());
345 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmax());
347 while (nbinsere<nbainsere)
349 double x=distribution_position_x(generateur);
350 double y=distribution_position_y(generateur);
351 double z=distribution_position_z(generateur);
363 listedepointvoro.push_back(x);
364 listedepointvoro.push_back(y);
365 listedepointvoro.push_back(z);
368 listepointainserer.push_back(pt);
373 for (
int i=0;i<listepointainserer.size();i++)
374 delete listepointainserer[i];
377 sprintf(message,
" Construction des Voronoi avec borne de fusion de %lf",epsfusion);
379 Polycristal poly(listedepointvoro,(
char*)nomfichierbrep.c_str(),epsfusion);
383 if (valeur==0) avecstep=
false;
384 if (valeur==1) avecstep=
true;
390 int nb=listedepointvoro.size()/3;
391 for (
int i=8;i<nb;i++)
393 double x=listedepointvoro[3*i];
394 double y=listedepointvoro[3*i+1];
395 double z=listedepointvoro[3*i+2];
403 affiche((
char*)
"Reprise de calcul d'un ancien polycristal");
411 sprintf(mess,
" Nombre de cristaux MAGiC assemblés = %d ", mggeo->
get_nb_mg_volume());;
413 double tens1[9],tens2[9],tens3[9];
414 for (
int i=0;i<9;i++)
422 std::uniform_real_distribution<double> distribution_angle1(0.,360.);
423 std::uniform_real_distribution<double> distribution_angle2(-1.,1.);
424 std::uniform_real_distribution<double> distribution_angle3(0.,360.);
425 affiche((
char*)
"Conditions aux limites");
426 LISTE_MG_VOLUME::iterator it;
435 std::vector<double> volume(nbphase);
436 std::vector<double> tirage(nbphase);
437 std::vector<OT_VECTEUR_3D> cdm(nbphase);
438 std::vector<double> cible(nbphase);
439 std::vector<int> ordrecible(nbphase);
440 std::vector<double> densite(nbphase);
441 std::vector<int> nbcristaux(nbphase);
444 for (
int i=0;i<nbphase;i++)
464 OT_TENSEUR rig(6,6),rigphase(6,6),souphase(6,6);
467 rigphase=cible[i]*rigphase;
468 souphase=cible[i]*souphase;
469 rigtot=rigtot+rigphase;
470 soutot=soutot+souphase;
483 std::shuffle(ordrecible.begin(),ordrecible.end(),generateur);
484 std::vector<MG_VOLUME*> listevolume;
486 listevolume.push_back(vol);
487 std::shuffle(listevolume.begin(),listevolume.end(),generateur);
490 std::vector<double> deno(nbphase);
491 for (
int i=0;i<nbphase;i++)
493 for (
int i=0;i<nbphase;i++)
495 nume=nume*densite[i];
496 for (
int j=0;j<nbphase;j++)
497 if (i!=j) deno[j]=deno[j]*densite[i];
498 else deno[j]=deno[j]*cible[i];
501 for (
int i=0;i<nbphase;i++)
502 massetot=massetot+deno[i];
503 massetot=nume/massetot;
506 for (
int i=0;i<listevolume.size();i++)
512 if (tirage[ordrecible[j]]/massetot<cible[ordrecible[j]]) tir=ordrecible[j];
519 double dens=densite[tir];
521 volume[tir]=volume[tir]+volu;
522 tirage[tir]=tirage[tir]+masse;
523 cdm[tir]=cdm[tir]+masse*cdm2;
524 nbcristaux[tir]=nbcristaux[tir]+1;
549 double a1=distribution_angle1(generateur);
550 double a3=distribution_angle3(generateur);
551 double a2=distribution_angle2(generateur);
552 a2=
acos(a2)/M_PI*180.;
556 double x1[3],x2[3],x3[3];
557 double psi=a1/180.*M_PI;
558 double teta=a2/180.*M_PI;
559 double phi=a3/180.*M_PI;
567 x3[1]=-
sin(teta)*
cos(psi);
569 for (
int i=0;i<3;i++)
570 for (
int j=0;j<3;j++)
572 tens1[i*3+j]+=x1[i]*x1[j];
573 tens2[i*3+j]+=x2[i]*x2[j];
574 tens3[i*3+j]+=x3[i]*x3[j];
578 double massetotale=0.;
579 double volumetotal=0.;
580 for (
int i=0;i<nbphase;i++)
582 volumetotal=volumetotal+volume[i];
583 massetotale=massetotale+tirage[i];
586 sprintf(mess,
" Masse estimée %lf calculée %lf",massetot,massetotale);
588 statres.
masse[nbphase]=massetotale;
589 statres.
volume[nbphase]=volumetotal;
590 for (
int i=0;i<nbphase;i++)
593 sprintf(mess,
" Phase %d (%d cristaux) = tirage %d \n masse %lf ou %lf%% \n volume %lf ou %lf%%", i+1,nbcristaux[i],ordrecible[i]+1,tirage[i],tirage[i]/massetotale*100.,volume[i],volume[i]/volumetotal*100.);
595 sprintf(mess,
" Centre de masse x = %lf ",cdm[i].get_x()/tirage[i]);
597 sprintf(mess,
" y = %lf ",cdm[i].get_y()/tirage[i]);
599 sprintf(mess,
" z = %lf ",cdm[i].get_z()/tirage[i]);
601 statres.
masse[i]=tirage[i];
602 statres.
volume[i]=volume[i];
603 statres.
cdm[i]=cdm[i]/tirage[i];
604 statres.
cdm[nbphase]=statres.
cdm[nbphase]+cdm[i];
608 sprintf(mess,
" Centre de masse global x = %lf ",statres.
cdm[statres.
nbphase].get_x());
610 sprintf(mess,
" y = %lf ",statres.
cdm[statres.
nbphase].get_y());
612 sprintf(mess,
" z = %lf ",statres.
cdm[statres.
nbphase].get_z());
617 affiche((
char*)
"Reprise conditions aux limites");
618 LISTE_MG_VOLUME::iterator it;
624 for (
int i=0;i<statres.
nbphase;i++)
629 statres.
cdm[i].change_x(0.);
630 statres.
cdm[i].change_y(0.);
631 statres.
cdm[i].change_z(0.);
636 vol->get_valeur_ccf((
char*)
"a1",a1);
637 vol->get_valeur_ccf((
char*)
"a2",a2);
638 vol->get_valeur_ccf((
char*)
"a3",a3);
639 double x1[3],x2[3],x3[3];
640 double psi=a1/180.*M_PI;
641 double teta=a2/180.*M_PI;
642 double phi=a3/180.*M_PI;
650 x3[1]=-
sin(teta)*
cos(psi);
652 for (
int i=0;i<3;i++)
653 for (
int j=0;j<3;j++)
655 tens1[i*3+j]+=x1[i]*x1[j];
656 tens2[i*3+j]+=x2[i]*x2[j];
657 tens3[i*3+j]+=x3[i]*x3[j];
660 vol->get_valeur_ccf((
char*)
"Ph",val);
661 int numphase=(int)val;
662 vol->get_valeur_ccf((
char*)
"Ro",val);
667 vol->get_propriete_massique(gest->
get_mg_maillage(0),volu,mass,cdm2,m1,m2,dens,-1);
669 statres.
masse[numphase]=statres.
masse[numphase]+mass;
671 statres.
cdm[numphase]=statres.
cdm[numphase]+mass*cdm2;
678 for (
int i=0;i<statres.
nbphase;i++)
682 statres.
cdm[i]=(1./statres.
masse[i])*statres.
cdm[i];
686 for (
int i=0;i<statres.
nbphase;i++)
693 sprintf(mess,
" Centre de masse x = %lf ",statres.
cdm[i].get_x());
695 sprintf(mess,
" y = %lf ",statres.
cdm[i].get_y());
697 sprintf(mess,
" z = %lf ",statres.
cdm[i].get_z());
701 sprintf(mess,
" Centre de masse global x = %lf ",statres.
cdm[statres.
nbphase].get_x());
703 sprintf(mess,
" y = %lf ",statres.
cdm[statres.
nbphase].get_y());
705 sprintf(mess,
" z = %lf ",statres.
cdm[statres.
nbphase].get_z());
710 for (
int i=0;i<9;i++)
730 affiche((
char*)
"Carte de taille");
732 std::vector<double> lstpoint;
736 if (typeborne==1) bornerafmin=bornerafmin*dg;
737 for (
int i=0;i<nbarete;i++)
741 if (val<epsfusion) std::cout<<
" pb" << std::endl;
746 lstpoint.push_back(xyz[0]);
747 lstpoint.push_back(xyz[1]);
748 lstpoint.push_back(xyz[2]);
749 lstpoint.push_back(std::max(val,bornerafmin));
754 sprintf(message,
" Écart nodal demande : %lf Écart nodal minimal : %lf",dg,bornerafmin);
756 sprintf(message,
" %d points de raffinement",(
int)(lstpoint.size())/4);
792 sprintf(mess,
"Maillage FEM degre %d",degre);
799 affiche((
char*)
"Reprise de calcul d'un ancien maillage");
805 LISTE_FEM_ELEMENT3::iterator it;
817 double vol=fabs(pvec*vec3);
822 sprintf(message,
" Volume des mailles = %lf",volume);
832 double epsx,epsy,epsz,epsxy,epsxz,epsyz;
833 double sigx,sigy,sigz,sigxy,sigxz,sigyz;
834 affiche((
char*)
"\n---> 1. CLDHS\n");
836 int erreur=
calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
839 statres.
KDH=1./3.*(sigx+sigy+sigz)/(epsx+epsy+epsz);
842 sprintf(message,
" KDH=%lf",statres.
KDH);
845 else exit(EXIT_FAILURE);
850 affiche((
char*)
"\n---> 2. CLDHD\n");
852 erreur=
calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
855 statres.
GDH=1./6.*(sigxy/epsxy+sigyz/epsyz+sigxz/epsxz);
859 sprintf(message,
" GDH=%lf\n EDH=%lf\n",statres.
GDH,statres.
EDH);
862 else exit(EXIT_FAILURE);
867 affiche((
char*)
"\n---> 3. CLCHS\n");
869 erreur=
calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
872 statres.
KCH=1./3.*(sigx+sigy+sigz)/(epsx+epsy+epsz);
875 sprintf(message,
" KCH=%lf\n\n",statres.
KCH);
878 else exit(EXIT_FAILURE);
884 affiche((
char*)
"\n---> 4. CLCHD\n");
886 calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
889 statres.
GCH=1./6.*(sigxy/epsxy+sigyz/epsyz+sigxz/epsxz);
893 sprintf(message,
" GCH=%lf\n ECH=%lf\n",statres.
GCH,statres.
ECH);
896 else exit(EXIT_FAILURE);
899 affiche((
char*)
"\n\n Résultats \n\n");
901 sprintf(message,
" KDH=%lf;GDH=%lf;EDH=%lf;",statres.
KDH,statres.
GDH,statres.
EDH);
903 sprintf(message,
" KCH=%lf;GCH=%lf;ECH=%lf;\n",statres.
KCH,statres.
GCH,statres.
ECH);
913 if (enregistreresultat==1)
917 std::string nomcumul1 = nomcumul+
".txt";
918 std::string nomcumul2 = nomcumul+
".gnu";
919 std::string nomcumul3 = nomcumul+
".svg";
920 FILE *outtest=fopen((
char*)nomcumul1.c_str(),
"rt");
922 if (outtest!=NULL) {
existe=
true;fclose(outtest);}
924 FILE *out=fopen((
char*)nomcumul1.c_str(),
"at");
926 { fprintf(out,
"Nbcristaux;degre;dg;KDH;GDH;EDH;KCH;GCH;ECH;ori1_11;ori1_12;ori1_13;ori1_21;ori1_22;ori1_23;ori1_31;ori1_32;ori1_33;ori2_11;ori2_12;ori2_13;ori2_21;ori2_22;ori2_23;ori2_31;ori2_32;ori2_33;ori3_11;ori3_12;ori3_13;ori3_21;ori3_22;ori3_23;ori3_31;ori3_32;ori3_33;Nbphase;");
927 for (
int i=0;i<statres.
nbphase;i++)
928 fprintf(out,
"N%d;VPh%d;MPh%d;CDMx%d;CDMy%d;CDMz%d;",i+1,i+1,i+1,i+1,i+1,i+1);
929 fprintf(out,
"VPhtot;MPhtot;CDMxtot;CDMytot;CDMztot,Kv,Gv,Ev,nuv,Kr,Gr,Er,nur\n");
932 fprintf(out,
"%lf;%lf;%lf;",statres.
KDH,statres.
GDH,statres.
EDH);
933 fprintf(out,
"%lf;%lf;%lf;",statres.
KCH,statres.
GCH,statres.
ECH);
934 for (
int i=0;i<9;i++)
935 fprintf(out,
"%lf;",statres.
tens1[i]);
936 for (
int i=0;i<9;i++)
937 fprintf(out,
"%lf;",statres.
tens2[i]);
938 for (
int i=0;i<9;i++)
939 fprintf(out,
"%lf;",statres.
tens3[i]);
940 fprintf(out,
"%d;",statres.
nbphase);
941 for (
int i=0;i<statres.
nbphase;i++)
989 affiche((
char*)
"Enregistrement");
998 int MSTRUCT_GENERATEUR_POLYCRISTAUX::calcule_cacteristique_mecanique(
MG_GESTIONNAIRE *gest,
FEM_MAILLAGE* fem,
double& epsx,
double& epsy,
double& epsz,
double& epsxy,
double& epsxz,
double& epsyz,
double& sigx,
double& sigy,
double& sigz,
double& sigxy,
double& sigxz,
double& sigyz)
1007 if (erreur!=0)
return erreur;
1009 for (
int i=0;i<nb;i++)
1013 std::string nom=sol->
get_nom();
1047 if (typeborne==1) bornerafmin=bornerafmin*dg;
1049 std::multimap<MG_NOEUD*,MG_NOEUD*> lst1;
1050 std::map<MG_NOEUD*,MG_NOEUD*> lst2;
1051 LISTE_MG_SEGMENT::iterator it;
1054 if (seg->get_longueur()<bornerafmin)
1056 int nb1=seg->get_noeud1()->get_lien_tetra()->
get_nb();
1057 int nb2=seg->get_noeud2()->get_lien_tetra()->get_nb();
1066 std::map<MG_NOEUD*,MG_NOEUD*>::iterator itn=lst2.find(no1);
1067 if (itn!=lst2.end())
1069 std::pair<MG_NOEUD*,MG_NOEUD*> tmp1(no1,no2);
1070 std::pair<MG_NOEUD*,MG_NOEUD*> tmp2(no2,no1);
1071 std::pair<std::map<MG_NOEUD*,MG_NOEUD*>::iterator,
bool> ret=lst2.insert(tmp2);
1072 if (ret.second==
false)
continue;
1074 for (
int i=0;i<nb1;i++)
1075 for (
int j=0;j<nb2;j++)
1076 if (seg->get_noeud1()->get_lien_tetra()->get(i)==seg->get_noeud2()->get_lien_tetra()->get(j))
1086 for (std::multimap<MG_NOEUD*,MG_NOEUD*>::iterator itn=lst1.begin();itn!=lst1.end();itn++)
1094 for (
int i=0;i<nb;i++)
1105 for (
int i=0;i<lsttetaconstruire.
get_nb()/4;i++)
1108 if (qual<1e-14) std::cout << qual << std::endl;