27 #ifdef PROJECT_POLYCRISTAUX
66 MSTRUCT_GENERATEUR_POLYCRISTAUX_RESULTAT::MSTRUCT_GENERATEUR_POLYCRISTAUX_RESULTAT(
MSTRUCT_GENERATEUR_POLYCRISTAUX_RESULTAT& mdd):nbcristaux(mdd.nbcristaux),degre(mdd.degre),dg(mdd.dg),KDH(mdd.KDH),GDH(mdd.GDH),EDH(mdd.EDH),KCH(mdd.KCH),GCH(mdd.GCH),ECH(mdd.ECH),nbphase(mdd.nbphase),nbcristauxphase(mdd.nbcristauxphase),masse(mdd.masse),volume(mdd.volume),cdm(mdd.cdm)
116 FILE *out=fopen(fichierout,
"wt");
117 LISTE_MG_POINT::iterator it;
119 if (pt->get_type()==MG_ELEMENT_GEOMETRIQUE::TYPE_ELEMENT_GEOMETRIQUE::LC_POINT)
123 fprintf(out,
"%e %e %e\n",xyz[0],xyz[1],xyz[2]);
171 std::vector<double> lstphase;
172 lstphase.push_back(0.68);
173 lstphase.push_back(0.32);
175 std::vector<double> lstdens;
176 lstdens.push_back(5.);
177 lstdens.push_back(12.);
179 std::vector<double> lst1,lst2,lst3;
180 lst1.push_back(66.69e9);
181 lst1.push_back(120.1e9);
182 lst2.push_back(0.4189);
184 lst3.push_back(75.4e9);
185 lst3.push_back(85.2e9);
210 affiche((
char*)
"\nCreation du fichier de parametre");
218 FILE *paraout2=fopen(nom2,
"wt");
219 fprintf(paraout2,
"-> %s\n",nom);
220 fprintf(paraout2,
"operationaeffectuer = 3.000000\n");
221 fprintf(paraout2,
"reprise_geo = 1.000000\n");
222 fprintf(paraout2,
"reprise_ori = 1.000000\n");
223 fprintf(paraout2,
"reprise_mai = 1.000000\n");
224 fprintf(paraout2,
"enregistrerres = 1.000000\n");
232 FILE *out = fopen(
"vasy",
"wt");
233 fprintf(out,
"#!/bin/bash\n");
234 fprintf(out,
"for ((c=1;c<=$1;c++))\n");
235 fprintf(out,
"do\n");
236 fprintf(out,
"timeout 900s %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom);
237 fprintf(out,
"VAR=$?\n");
238 fprintf(out,
"if (( $VAR )) ; then\n");
239 fprintf(out,
" echo \"Timeout\"\n");
240 fprintf(out,
"else\n");
241 fprintf(out,
" %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom2);
242 fprintf(out,
"fi\n");
243 fprintf(out,
"done\n");
247 out = fopen(
"vasy_par",
"wt");
248 fprintf(out,
"#!/bin/bash\n");
249 fprintf(out,
"VAR=1\n");
250 fprintf(out,
"while (($VAR))\n");
251 fprintf(out,
"do\n");
252 bool chemindanspath=
false;
253 if ((nomexe[0]>=
'a') && (nomexe[0]<=
'z')) chemindanspath=
true;
254 if ((nomexe[0]>=
'A') && (nomexe[0]<=
'Z')) chemindanspath=
true;
256 fprintf(out,
"timeout 1800s %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom);
258 fprintf(out,
"timeout 1800s ../%s -polycristaux -out cristal.magic -param %s\n", nomexe,nom);
259 fprintf(out,
"VAR=$?\n");
260 fprintf(out,
"if (( $VAR )) ; then\n");
261 fprintf(out,
" echo \"Timeout\"\n");
262 fprintf(out,
"else\n");
264 fprintf(out,
" %s -polycristaux -out cristal.magic -param %s\n", nomexe,nom2);
266 fprintf(out,
" ../%s -polycristaux -out cristal.magic -param %s\n", nomexe,nom2);
267 fprintf(out,
"fi\n");
268 fprintf(out,
"done\n");
272 chmod (
"vasy",strtol(
"0777", NULL,8));
273 chmod (
"vasy_par",strtol(
"0777", NULL,8));
290 #ifdef PROJECT_POLYCRISTAUX
300 std::string nomfichierbrep=nomfichier+
".brep";
301 std::string nomfichierocaf=nomfichier+
".ocaf";
302 std::string nomfichiercarte=nomfichier+
".sol";
303 std::string nomfichierborne=nomfichier+
".borne";
310 BOITE_3D boite(xmin,ymin,zmin,xmax,ymax,zmax);
315 std::random_device seed;
316 std::mt19937_64 generateur(seed());
317 affiche((
char*)
"\nInitialisation");
335 affiche((
char*)
"Generation de cristaux aléatoires");
336 double rayon=
param.
get_valeur(
"rayon")*0.3333333333333333333*(dx+dy+dz);
337 std::uniform_real_distribution<double> distribution_position_x(boite.
get_xmin(),boite.
get_xmax());
338 std::uniform_real_distribution<double> distribution_position_y(boite.
get_ymin(),boite.
get_ymax());
339 std::uniform_real_distribution<double> distribution_position_z(boite.
get_zmin(),boite.
get_zmax());
342 std::vector<POLYCRISTAUX::POINT_TIRE*> listepointainserer;
343 std::vector<double> listedepointvoro;
344 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmin());
345 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmin());
346 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmin());
347 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmin());
348 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmax());
349 listedepointvoro.push_back(boite.
get_xmin());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmax());
350 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymax());listedepointvoro.push_back(boite.
get_zmax());
351 listedepointvoro.push_back(boite.
get_xmax());listedepointvoro.push_back(boite.
get_ymin());listedepointvoro.push_back(boite.
get_zmax());
353 while (nbinsere<nbainsere)
355 double x=distribution_position_x(generateur);
356 double y=distribution_position_y(generateur);
357 double z=distribution_position_z(generateur);
369 listedepointvoro.push_back(x);
370 listedepointvoro.push_back(y);
371 listedepointvoro.push_back(z);
374 listepointainserer.push_back(pt);
379 for (
int i=0;i<listepointainserer.size();i++)
380 delete listepointainserer[i];
383 sprintf(message,
" Construction des Voronoi avec borne de fusion de %lf",epsfusion);
385 Polycristal poly(listedepointvoro,(
char*)nomfichierbrep.c_str(),epsfusion);
389 if (valeur==0) avecstep=
false;
390 if (valeur==1) avecstep=
true;
396 int nb=listedepointvoro.size()/3;
397 for (
int i=8;i<nb;i++)
399 double x=listedepointvoro[3*i];
400 double y=listedepointvoro[3*i+1];
401 double z=listedepointvoro[3*i+2];
409 affiche((
char*)
"Reprise de calcul d'un ancien polycristal");
417 sprintf(mess,
" Nombre de cristaux MAGiC assemblés = %d ", mggeo->
get_nb_mg_volume());;
419 double tens1[9],tens2[9],tens3[9];
420 for (
int i=0;i<9;i++)
428 std::uniform_real_distribution<double> distribution_angle1(0.,360.);
429 std::uniform_real_distribution<double> distribution_angle2(-1.,1.);
430 std::uniform_real_distribution<double> distribution_angle3(0.,360.);
431 affiche((
char*)
"Conditions aux limites");
432 LISTE_MG_VOLUME::iterator it;
441 std::vector<double> volume(nbphase);
442 std::vector<double> tirage(nbphase);
443 std::vector<OT_VECTEUR_3D> cdm(nbphase);
444 std::vector<double> cible(nbphase);
445 std::vector<int> ordrecible(nbphase);
446 std::vector<double> densite(nbphase);
447 std::vector<int> nbcristaux(nbphase);
450 for (
int i=0;i<nbphase;i++)
494 std::shuffle(ordrecible.begin(),ordrecible.end(),generateur);
495 std::vector<MG_VOLUME*> listevolume;
497 listevolume.push_back(vol);
498 std::shuffle(listevolume.begin(),listevolume.end(),generateur);
501 std::vector<double> deno(nbphase);
502 for (
int i=0;i<nbphase;i++)
504 for (
int i=0;i<nbphase;i++)
506 nume=nume*densite[i];
507 for (
int j=0;j<nbphase;j++)
508 if (i!=j) deno[j]=deno[j]*densite[i];
509 else deno[j]=deno[j]*cible[i];
512 for (
int i=0;i<nbphase;i++)
513 massetot=massetot+deno[i];
514 massetot=nume/massetot;
517 for (
int i=0;i<listevolume.size();i++)
523 if (tirage[ordrecible[j]]/massetot<cible[ordrecible[j]]) tir=ordrecible[j];
530 double dens=densite[tir];
532 volume[tir]=volume[tir]+volu;
533 tirage[tir]=tirage[tir]+masse;
534 cdm[tir]=cdm[tir]+masse*cdm2;
535 nbcristaux[tir]=nbcristaux[tir]+1;
560 double a1=distribution_angle1(generateur);
561 double a3=distribution_angle3(generateur);
562 double a2=distribution_angle2(generateur);
563 a2=
acos(a2)/M_PI*180.;
567 double x1[3],x2[3],x3[3];
568 double psi=a1/180.*M_PI;
569 double teta=a2/180.*M_PI;
570 double phi=a3/180.*M_PI;
578 x3[1]=-
sin(teta)*
cos(psi);
580 for (
int i=0;i<3;i++)
581 for (
int j=0;j<3;j++)
583 tens1[i*3+j]+=x1[i]*x1[j];
584 tens2[i*3+j]+=x2[i]*x2[j];
585 tens3[i*3+j]+=x3[i]*x3[j];
589 double massetotale=0.;
590 double volumetotal=0.;
591 for (
int i=0;i<nbphase;i++)
593 volumetotal=volumetotal+volume[i];
594 massetotale=massetotale+tirage[i];
597 sprintf(mess,
" Masse estimée %lf calculée %lf",massetot,massetotale);
599 statres.
masse[nbphase]=massetotale;
600 statres.
volume[nbphase]=volumetotal;
601 for (
int i=0;i<nbphase;i++)
604 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.);
606 sprintf(mess,
" Centre de masse x = %lf ",cdm[i].get_x()/tirage[i]);
608 sprintf(mess,
" y = %lf ",cdm[i].get_y()/tirage[i]);
610 sprintf(mess,
" z = %lf ",cdm[i].get_z()/tirage[i]);
612 statres.
masse[i]=tirage[i];
613 statres.
volume[i]=volume[i];
614 statres.
cdm[i]=cdm[i]/tirage[i];
615 statres.
cdm[nbphase]=statres.
cdm[nbphase]+cdm[i];
619 sprintf(mess,
" Centre de masse global x = %lf ",statres.
cdm[statres.
nbphase].get_x());
621 sprintf(mess,
" y = %lf ",statres.
cdm[statres.
nbphase].get_y());
623 sprintf(mess,
" z = %lf ",statres.
cdm[statres.
nbphase].get_z());
628 affiche((
char*)
"Reprise conditions aux limites");
629 LISTE_MG_VOLUME::iterator it;
635 for (
int i=0;i<statres.
nbphase;i++)
640 statres.
cdm[i].change_x(0.);
641 statres.
cdm[i].change_y(0.);
642 statres.
cdm[i].change_z(0.);
647 vol->get_valeur_ccf((
char*)
"a1",a1);
648 vol->get_valeur_ccf((
char*)
"a2",a2);
649 vol->get_valeur_ccf((
char*)
"a3",a3);
650 double x1[3],x2[3],x3[3];
651 double psi=a1/180.*M_PI;
652 double teta=a2/180.*M_PI;
653 double phi=a3/180.*M_PI;
661 x3[1]=-
sin(teta)*
cos(psi);
663 for (
int i=0;i<3;i++)
664 for (
int j=0;j<3;j++)
666 tens1[i*3+j]+=x1[i]*x1[j];
667 tens2[i*3+j]+=x2[i]*x2[j];
668 tens3[i*3+j]+=x3[i]*x3[j];
671 vol->get_valeur_ccf((
char*)
"Ph",val);
672 int numphase=(int)val;
673 vol->get_valeur_ccf((
char*)
"Ro",val);
678 vol->get_propriete_massique(gest->
get_mg_maillage(0),volu,mass,cdm2,m1,m2,dens,-1);
680 statres.
masse[numphase]=statres.
masse[numphase]+mass;
682 statres.
cdm[numphase]=statres.
cdm[numphase]+mass*cdm2;
689 for (
int i=0;i<statres.
nbphase;i++)
693 statres.
cdm[i]=(1./statres.
masse[i])*statres.
cdm[i];
697 for (
int i=0;i<statres.
nbphase;i++)
704 sprintf(mess,
" Centre de masse x = %lf ",statres.
cdm[i].get_x());
706 sprintf(mess,
" y = %lf ",statres.
cdm[i].get_y());
708 sprintf(mess,
" z = %lf ",statres.
cdm[i].get_z());
712 sprintf(mess,
" Centre de masse global x = %lf ",statres.
cdm[statres.
nbphase].get_x());
714 sprintf(mess,
" y = %lf ",statres.
cdm[statres.
nbphase].get_y());
716 sprintf(mess,
" z = %lf ",statres.
cdm[statres.
nbphase].get_z());
721 for (
int i=0;i<9;i++)
741 affiche((
char*)
"Carte de taille");
743 std::vector<double> lstpoint;
747 if (typeborne==1) bornerafmin=bornerafmin*dg;
748 for (
int i=0;i<nbarete;i++)
752 if (val<epsfusion) std::cout<<
" pb" << std::endl;
757 lstpoint.push_back(xyz[0]);
758 lstpoint.push_back(xyz[1]);
759 lstpoint.push_back(xyz[2]);
760 lstpoint.push_back(std::max(val,bornerafmin));
765 sprintf(message,
" Écart nodal demande : %lf Écart nodal minimal : %lf",dg,bornerafmin);
767 sprintf(message,
" %d points de raffinement",(
int)(lstpoint.size())/4);
794 LISTE_MG_VOLUME::iterator it;
int ii=0;
812 sprintf(mess,
"Maillage FEM degre %d",degre);
819 affiche((
char*)
"Reprise de calcul d'un ancien maillage");
825 LISTE_FEM_ELEMENT3::iterator it;
837 double vol=fabs(pvec*vec3);
842 sprintf(message,
" Volume des mailles = %lf",volume);
852 double epsx,epsy,epsz,epsxy,epsxz,epsyz;
853 double sigx,sigy,sigz,sigxy,sigxz,sigyz;
854 affiche((
char*)
"\n---> 1. CLDHS\n");
856 int erreur=
calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
859 statres.
KDH=1./3.*(sigx+sigy+sigz)/(epsx+epsy+epsz);
862 sprintf(message,
" KDH=%lf",statres.
KDH);
865 else exit(EXIT_FAILURE);
870 affiche((
char*)
"\n---> 2. CLDHD\n");
872 erreur=
calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
875 statres.
GDH=1./6.*(sigxy/epsxy+sigyz/epsyz+sigxz/epsxz);
879 sprintf(message,
" GDH=%lf\n EDH=%lf\n",statres.
GDH,statres.
EDH);
882 else exit(EXIT_FAILURE);
887 affiche((
char*)
"\n---> 3. CLCHS\n");
889 erreur=
calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
892 statres.
KCH=1./3.*(sigx+sigy+sigz)/(epsx+epsy+epsz);
895 sprintf(message,
" KCH=%lf\n\n",statres.
KCH);
898 else exit(EXIT_FAILURE);
904 affiche((
char*)
"\n---> 4. CLCHD\n");
906 calcule_cacteristique_mecanique(gest,fem,epsx,epsy,epsz,epsxy,epsxz,epsyz,sigx,sigy,sigz,sigxy,sigxz,sigyz);
909 statres.
GCH=1./6.*(sigxy/epsxy+sigyz/epsyz+sigxz/epsxz);
913 sprintf(message,
" GCH=%lf\n ECH=%lf\n",statres.
GCH,statres.
ECH);
916 else exit(EXIT_FAILURE);
919 affiche((
char*)
"\n\n Résultats \n\n");
921 sprintf(message,
" KDH=%lf;GDH=%lf;EDH=%lf;",statres.
KDH,statres.
GDH,statres.
EDH);
923 sprintf(message,
" KCH=%lf;GCH=%lf;ECH=%lf;\n",statres.
KCH,statres.
GCH,statres.
ECH);
933 if (enregistreresultat==1)
941 std::string nomcumul1 = nomcumul+
".txt";
942 std::string nomcumul2 = nomcumul+
".gnu";
943 std::string nomcumul3 = nomcumul+
".svg";
944 FILE *outtest=fopen((
char*)nomcumul1.c_str(),
"rt");
946 if (outtest!=NULL) {
existe=
true;fclose(outtest);}
948 FILE *out=fopen((
char*)nomcumul1.c_str(),
"at");
950 { 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;");
951 for (
int i=0;i<statres.
nbphase;i++)
952 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);
953 fprintf(out,
"VPhtot;MPhtot;CDMxtot;CDMytot;CDMztot,Kv,Gv,Ev,nuv,Kr,Gr,Er,nur\n");
956 fprintf(out,
"%lf;%lf;%lf;",statres.
KDH,statres.
GDH,statres.
EDH);
957 fprintf(out,
"%lf;%lf;%lf;",statres.
KCH,statres.
GCH,statres.
ECH);
958 for (
int i=0;i<9;i++)
959 fprintf(out,
"%lf;",statres.
tens1[i]);
960 for (
int i=0;i<9;i++)
961 fprintf(out,
"%lf;",statres.
tens2[i]);
962 for (
int i=0;i<9;i++)
963 fprintf(out,
"%lf;",statres.
tens3[i]);
964 fprintf(out,
"%d;",statres.
nbphase);
965 for (
int i=0;i<statres.
nbphase;i++)
1013 affiche((
char*)
"Enregistrement");
1022 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)
1031 if (erreur!=0)
return erreur;
1033 for (
int i=0;i<nb;i++)
1037 std::string nom=sol->
get_nom();
1071 if (typeborne==1) bornerafmin=bornerafmin*dg;
1073 std::multimap<MG_NOEUD*,MG_NOEUD*> lst1;
1074 std::map<MG_NOEUD*,MG_NOEUD*> lst2;
1075 LISTE_MG_SEGMENT::iterator it;
1078 if (seg->get_longueur()<bornerafmin)
1080 int nb1=seg->get_noeud1()->get_lien_tetra()->
get_nb();
1081 int nb2=seg->get_noeud2()->get_lien_tetra()->get_nb();
1090 std::map<MG_NOEUD*,MG_NOEUD*>::iterator itn=lst2.find(no1);
1091 if (itn!=lst2.end())
1093 std::pair<MG_NOEUD*,MG_NOEUD*> tmp1(no1,no2);
1094 std::pair<MG_NOEUD*,MG_NOEUD*> tmp2(no2,no1);
1095 std::pair<std::map<MG_NOEUD*,MG_NOEUD*>::iterator,
bool> ret=lst2.insert(tmp2);
1096 if (ret.second==
false)
continue;
1098 for (
int i=0;i<nb1;i++)
1099 for (
int j=0;j<nb2;j++)
1100 if (seg->get_noeud1()->get_lien_tetra()->get(i)==seg->get_noeud2()->get_lien_tetra()->get(j))
1110 for (std::multimap<MG_NOEUD*,MG_NOEUD*>::iterator itn=lst1.begin();itn!=lst1.end();itn++)
1118 for (
int i=0;i<nb;i++)
1129 for (
int i=0;i<lsttetaconstruire.
get_nb()/4;i++)
1132 if (qual<1e-14) std::cout << qual << std::endl;
1150 for (
int i=0;i<echantillon.
nbphase;i++)
1161 OT_TENSEUR rig(6,6),rigphase(6,6),souphase(6,6);
1165 rigphase=proportion*rigphase;
1166 souphase=proportion*souphase;
1167 rigtot=rigtot+rigphase;
1168 soutot=soutot+souphase;
1170 double Ev,Gv,Kv,nuv;
1171 double Er,Gr,Kr,nur;
1174 statborne.
Kvoigt=Kv/3.*1e9;
1175 statborne.
Gvoigt=Gv/2.*1e9;
1178 statborne.
Kreuss=Kr/3.*1e9;
1179 statborne.
Greuss=Gr/2.*1e9;