MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
mstruct_generateur_dcr.cpp
Aller à la documentation de ce fichier.
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// mstruct_generateur_dcr.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:58:57 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 #ifdef PROJECT_CHRONO
23 #include "mstruct_generateur_dcr.h"
24 #include "mg_gestionnaire.h"
25 #include "chrono/physics/ChSystemNSC.h"
26 #include "chrono/physics/ChBodyEasy.h"
27 #include "chrono/physics/ChParticlesClones.h"
28 #include "chrono/physics/ChLinkMotorRotationSpeed.h"
29 #include "chrono/assets/ChTexture.h"
30 #include <random>
31 #include "mg_cg.h"
34 #include "mg_cg_assemblage.h"
35 #include "mg_sous_geometrie.h"
36 #include "mstruct_definition.h"
37 
38 MSTRUCT_GROUPE_PARTICULE::MSTRUCT_GROUPE_PARTICULE(std::string nom, int type_particule)
39 {
40  m_nom=nom;
41  m_type_particule=type_particule;
42 }
43 
44 MSTRUCT_GROUPE_PARTICULE::~MSTRUCT_GROUPE_PARTICULE(void)
45 {
46  std::vector<MSTRUCT_CHRONO_PARTICULE*>::iterator it;
47  for(it=m_vector_particule_chrono.begin();it!=m_vector_particule_chrono.end();it++) delete *it;
48 }
49 
50 
51 std::vector<MSTRUCT_CHRONO_PARTICULE*>* MSTRUCT_GROUPE_PARTICULE::get_vector_particule(void)
52 {
53  return &m_vector_particule_chrono;
54 }
55 
56 int MSTRUCT_GROUPE_PARTICULE::get_type_particule(void)
57 {
58  return m_type_particule;
59 }
60 
61 std::string MSTRUCT_GROUPE_PARTICULE::get_nom(void)
62 {
63  return m_nom;
64 }
65 
66 MSTRUCT_CHRONO_PARTICULE::MSTRUCT_CHRONO_PARTICULE(std::shared_ptr< chrono::ChBody > particule)
67 {
68  m_particule=particule;
69  m_porosite=false;
70 }
71 
72 std::shared_ptr< chrono::ChBody > MSTRUCT_CHRONO_PARTICULE::get_ChBody(void)
73 {
74  return m_particule;
75 }
76 
77 bool MSTRUCT_CHRONO_PARTICULE::est_porosite()
78 {
79  return m_porosite;
80 }
81 
82 void MSTRUCT_CHRONO_PARTICULE::est_porosite(bool porosite)
83 {
84  m_porosite=porosite;
85 }
86 
87 MSTRUCT_CHRONO_PARTICULE_SPHERE::MSTRUCT_CHRONO_PARTICULE_SPHERE(std::shared_ptr< chrono::ChBody > particule, double rayon_ini, double rayon_sim): MSTRUCT_CHRONO_PARTICULE(particule)
88 {
89  m_rayon_ini=rayon_ini;
90  m_rayon_sim=rayon_sim;
91 }
92 
93 double MSTRUCT_CHRONO_PARTICULE_SPHERE::get_rayon_ini(void)
94 {
95  return m_rayon_ini;
96 }
97 
98 double MSTRUCT_CHRONO_PARTICULE_SPHERE::get_rayon_sim(void)
99 {
100  return m_rayon_sim;
101 }
102 
103 MSTRUCT_CHRONO_PARTICULE_CYLINDRE::MSTRUCT_CHRONO_PARTICULE_CYLINDRE(std::shared_ptr< chrono::ChBody > particule,
104  double rayon_ini, double rayon_sim, double longueur_ini, double longueur_sim): MSTRUCT_CHRONO_PARTICULE(particule)
105 {
106  m_rayon_ini=rayon_ini;
107  m_rayon_sim=rayon_sim;
108  m_longueur_ini=longueur_ini;
109  m_longueur_sim=m_longueur_sim;
110 }
111 
112 double MSTRUCT_CHRONO_PARTICULE_CYLINDRE::get_rayon_ini(void)
113 {
114  return m_rayon_ini;
115 }
116 
117 double MSTRUCT_CHRONO_PARTICULE_CYLINDRE::get_rayon_sim(void)
118 {
119  return m_rayon_sim;
120 }
121 
122 double MSTRUCT_CHRONO_PARTICULE_CYLINDRE::get_longueur_ini(void)
123 {
124  return m_longueur_ini;
125 }
126 
127 double MSTRUCT_CHRONO_PARTICULE_CYLINDRE::get_longueur_sim(void)
128 {
129  return m_longueur_sim;
130 }
131 
132 
133 
134 MSTRUCT_GENERATEUR_DCR::MSTRUCT_GENERATEUR_DCR(MG_GESTIONNAIRE* mg_gestionnaire, char* nom_mgcg_modele): MSTRUCT_GENERATEUR(mg_gestionnaire, nom_mgcg_modele)
135 {
136  m_boite3d_ves=BOITE_3D(0.0,0.0,0.0,1.0,1.0,1.0);
137  m_boite3d_distribution=m_boite3d_ves;
138  m_intersection_bords_ves=true;
139  m_angle_min=0.0;
140  m_longueur_min=0.0;
141  m_aire_min=0.0;
142  m_volume_min=0.0;
143  m_distance_min=0.0;
144  m_nb_pas_grille=20;
145  m_nb_pas_echantillonnage=32;
146  m_precision=1.e-06;
147  m_grille_init=false;
148  m_avec_interface_graphique=false;
149  m_matrice=NULL;
150  m_systeme_physique=NULL;
151  m_irrapp=NULL;
152  creer_systeme_physique();
153 }
154 
155 MSTRUCT_GENERATEUR_DCR::~MSTRUCT_GENERATEUR_DCR(void)
156 {
157  delete m_irrapp;
158  delete m_systeme_physique;
159  std::map<std::string,MSTRUCT_GROUPE_PARTICULE*>::iterator it_gr_particule;
160  for(it_gr_particule=m_map_groupe_particule.begin();it_gr_particule!=m_map_groupe_particule.end();it_gr_particule++)
161  {
162  delete it_gr_particule->second;
163  }
164 }
165 
166 int MSTRUCT_GENERATEUR_DCR::get_type()
167 {
169 }
170 
171 
172 void MSTRUCT_GENERATEUR_DCR::change_friction(double friction)
173 {
174  m_friction=friction;
175 }
176 
177 void MSTRUCT_GENERATEUR_DCR::change_facteur_reduction_vitesse(double facteur_reduction_vitesse)
178 {
179  m_facteur_reduction_vitesse=facteur_reduction_vitesse;
180 }
181 
182 void MSTRUCT_GENERATEUR_DCR::change_eps_vitesse(double eps_vitesse)
183 {
184  m_eps_vitesse=eps_vitesse;
185 }
186 
187 void MSTRUCT_GENERATEUR_DCR::change_pas_temps(double pas_temps)
188 {
189  m_pas_temps=pas_temps;
190 }
191 
192 void MSTRUCT_GENERATEUR_DCR::change_temps_max_sim(double temps)
193 {
194  m_temps_max_sim=temps;
195 }
196 
197 
198 int MSTRUCT_GENERATEUR_DCR::ajouter_spheres(std::string nom, double mu_rayon, double sigma_rayon, int type_distribution_rayon, double fraction_volumique_cible, double eps_frac_vol,bool porosite)
199 {
200  MSTRUCT_GROUPE_PARTICULE* groupe_particule = new MSTRUCT_GROUPE_PARTICULE(nom,MSTRUCT::TYPE_INCLUSION::SPHERE);
201  m_map_groupe_particule.insert(std::pair<std::string,MSTRUCT_GROUPE_PARTICULE*>(groupe_particule->get_nom(),groupe_particule));;
202  std::random_device seed;
203  std::mt19937_64 generateur(seed());
204  std::uniform_real_distribution<double> uniform_distribution_position_x(m_boite3d_distribution.get_xmin(),m_boite3d_distribution.get_xmax());
205  std::uniform_real_distribution<double> uniform_distribution_position_y(m_boite3d_distribution.get_ymin(),m_boite3d_distribution.get_ymax());
206  std::uniform_real_distribution<double> uniform_distribution_position_z(m_boite3d_distribution.get_zmin(),m_boite3d_distribution.get_zmax());
207  std::normal_distribution<double> normal_distribution_rayon(mu_rayon,sigma_rayon);
208  std::uniform_real_distribution<double> uniform_distribution_rayon(mu_rayon-sigma_rayon,mu_rayon+sigma_rayon);
209  double fraction_volumique=0.0;
210 
211  double volume_particule=0;
212  while(fraction_volumique<fraction_volumique_cible-eps_frac_vol)
213  {
214  double centre[3];
215  centre[0]=uniform_distribution_position_x(generateur);
216  centre[1]=uniform_distribution_position_y(generateur);
217  centre[2]=uniform_distribution_position_z(generateur);
218  double rayon=-1;
219  if(type_distribution_rayon==MSTRUCT::TYPE_DISTRIBUTION::FIXE) while(rayon<0.0) rayon=mu_rayon;
220  else if(type_distribution_rayon==MSTRUCT::TYPE_DISTRIBUTION::UNIFORME) while(rayon<0.0) rayon=uniform_distribution_rayon(generateur);
221  else if(type_distribution_rayon==MSTRUCT::TYPE_DISTRIBUTION::NORMALE) while(rayon<0.0) rayon=normal_distribution_rayon(generateur);
222  double rayon_sim=rayon+1.1*m_distance_min;
223  auto sphere = std::make_shared<chrono::ChBodyEasySphere>(rayon_sim,1,true,true);
224  sphere->SetPos(chrono::ChVector<>(centre[0],centre[1],centre[2]));
225  sphere->GetMaterialSurfaceNSC()->SetFriction(m_friction);
226  sphere->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
227  sphere->GetMaterialSurfaceNSC()->SetRestitution(1.0);
228  if(!porosite)
229  {
230  auto couleur = std::make_shared<chrono::ChColorAsset>(0.0,0.0,1.0);
231  sphere->AddAsset(couleur);
232  }
233  else
234  {
235  auto couleur = std::make_shared<chrono::ChColorAsset>(0.2,0.2,0.2);
236  sphere->AddAsset(couleur);
237  }
238  m_systeme_physique->Add(sphere);
239  m_vector_particule_chrono.push_back(sphere);
240  MSTRUCT_CHRONO_PARTICULE_SPHERE* particule = new MSTRUCT_CHRONO_PARTICULE_SPHERE(sphere,rayon,rayon_sim);
241  if(porosite) particule->est_porosite(true);
242  groupe_particule->get_vector_particule()->push_back(particule);
243  volume_particule+=(4.0/3.0)*M_PI*rayon*rayon*rayon;
244  fraction_volumique=volume_particule/m_boite3d_distribution.get_volume();
245  }
246  return OK;
247 }
248 
249 int MSTRUCT_GENERATEUR_DCR::ajouter_cylindres(std::string nom,
250  double mu_rayon, double sigma_rayon, int type_distribution_rayon,
251  double mu_longueur, double sigma_longueur, int type_distribution_longueur,
252  double mu_theta, double sigma_theta, int type_distribution_theta,
253  double mu_phi, double sigma_phi, int type_distribution_phi,
254  double fraction_volumique_cible, double eps_frac_vol,bool porosite)
255 {
256  MSTRUCT_GROUPE_PARTICULE* groupe_particule = new MSTRUCT_GROUPE_PARTICULE(nom,MSTRUCT::TYPE_INCLUSION::CYLINDRE);
257  m_map_groupe_particule.insert(std::pair<std::string,MSTRUCT_GROUPE_PARTICULE*>(groupe_particule->get_nom(),groupe_particule));;
258  std::random_device seed;
259  std::mt19937_64 generateur(seed());
260  std::uniform_real_distribution<double> uniform_distribution_position_x(m_boite3d_distribution.get_xmin(),m_boite3d_distribution.get_xmax());
261  std::uniform_real_distribution<double> uniform_distribution_position_y(m_boite3d_distribution.get_ymin(),m_boite3d_distribution.get_ymax());
262  std::uniform_real_distribution<double> uniform_distribution_position_z(m_boite3d_distribution.get_zmin(),m_boite3d_distribution.get_zmax());
263  std::normal_distribution<double> normal_distribution_rayon(mu_rayon,sigma_rayon);
264  std::uniform_real_distribution<double> uniform_distribution_rayon(mu_rayon-sigma_rayon,mu_rayon+sigma_rayon);
265  std::normal_distribution<double> normal_distribution_longueur(mu_longueur,sigma_longueur);
266  std::uniform_real_distribution<double> uniform_distribution_longueur(mu_longueur-sigma_longueur,mu_longueur+sigma_longueur);
267  std::normal_distribution<double> normal_distribution_theta(mu_theta,sigma_theta);
268  std::uniform_real_distribution<double> uniform_distribution_theta(0,sigma_theta);
269  std::normal_distribution<double> normal_distribution_phi(mu_phi,sigma_phi);
270  std::uniform_real_distribution<double> uniform_distribution_phi(0,sigma_phi);
271  double fraction_volumique=0.0;
272  double volume_particule=0;
273  while(fraction_volumique<fraction_volumique_cible-eps_frac_vol)
274  {
275  double centre[3];
276  centre[0]=uniform_distribution_position_x(generateur);
277  centre[1]=uniform_distribution_position_y(generateur);
278  centre[2]=uniform_distribution_position_z(generateur);
279  double rayon=-1;
280  if(type_distribution_rayon==MSTRUCT::TYPE_DISTRIBUTION::FIXE) while(rayon<0.0) rayon=mu_rayon;
281  else if(type_distribution_rayon==MSTRUCT::TYPE_DISTRIBUTION::UNIFORME) while(rayon<0.0) rayon=uniform_distribution_rayon(generateur);
282  else if(type_distribution_rayon==MSTRUCT::TYPE_DISTRIBUTION::NORMALE) while(rayon<0.0) rayon=normal_distribution_rayon(generateur);
283  double longueur=-1;
284  if(type_distribution_longueur==MSTRUCT::TYPE_DISTRIBUTION::FIXE) while(longueur<0.0) longueur=mu_longueur;
285  else if(type_distribution_longueur==MSTRUCT::TYPE_DISTRIBUTION::UNIFORME) while(longueur<0.0) rayon=uniform_distribution_longueur(generateur);
286  else if(type_distribution_longueur==MSTRUCT::TYPE_DISTRIBUTION::NORMALE) while(longueur<0.0) rayon=normal_distribution_longueur(generateur);
287  double rayon_sim=rayon+1.05*m_distance_min/2.0;
288  double longueur_sim=longueur+1.05*m_distance_min;
289 
290  double theta=-1;
291  if(type_distribution_theta==MSTRUCT::TYPE_DISTRIBUTION::FIXE) while(theta<0.0) theta=mu_rayon;
292  else if(type_distribution_theta==MSTRUCT::TYPE_DISTRIBUTION::UNIFORME) while(theta<0.0) theta=uniform_distribution_theta(generateur);
293  else if(type_distribution_theta==MSTRUCT::TYPE_DISTRIBUTION::NORMALE) while(theta<0.0) theta=normal_distribution_theta(generateur);
294  double phi=-1;
295  if(type_distribution_phi==MSTRUCT::TYPE_DISTRIBUTION::FIXE) while(phi<0.0) phi=mu_rayon;
296  else if(type_distribution_phi==MSTRUCT::TYPE_DISTRIBUTION::UNIFORME) while(phi<0.0) phi=uniform_distribution_phi(generateur);
297  else if(type_distribution_phi==MSTRUCT::TYPE_DISTRIBUTION::NORMALE) while(phi<0.0) phi=normal_distribution_phi(generateur);
298  double axe[3];
299  theta = 2.0*M_PI*theta;
300  phi=acos(2.0*phi-1.0);
301  axe[0]=sin(phi)*cos(theta);
302  axe[1]=sin(phi)*sin(theta);
303  axe[2]=cos(phi);
304  auto cylindre=std::make_shared<chrono::ChBodyEasyCylinder>(rayon_sim,longueur_sim,1,true,true);
305  cylindre->SetPos(chrono::ChVector<>(centre[0],centre[1],centre[2]));
306  chrono::ChQuaternion<> qua;
307  qua.Q_from_Euler123(chrono::ChVector<>(phi,theta,0.0));
308  cylindre->SetRot(qua);
309  cylindre->GetMaterialSurfaceNSC()->SetFriction(m_friction);
310  cylindre->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
311  cylindre->GetMaterialSurfaceNSC()->SetRestitution(1.0);
312  auto couleur = std::make_shared<chrono::ChColorAsset>(1.0,0.0,0.0);
313  cylindre->AddAsset(couleur);
314  m_systeme_physique->Add(cylindre);
315  m_vector_particule_chrono.push_back(cylindre);
316  MSTRUCT_CHRONO_PARTICULE_CYLINDRE* particule = new MSTRUCT_CHRONO_PARTICULE_CYLINDRE(cylindre,rayon,rayon_sim,longueur,longueur_sim);
317  if(porosite) particule->est_porosite(true);
318  groupe_particule->get_vector_particule()->push_back(particule);
319  volume_particule+=M_PI*rayon*rayon*longueur;
320  fraction_volumique=volume_particule/m_boite3d_distribution.get_volume();
321  }
322  return OK;
323 }
324 
325 
326 int MSTRUCT_GENERATEUR_DCR::creer_systeme_physique(void)
327 {
328  m_systeme_physique = new chrono::ChSystemNSC();
329  chrono::collision::ChCollisionModel::SetDefaultSuggestedEnvelope(0.001);
330  chrono::collision::ChCollisionModel::SetDefaultSuggestedMargin(0.0001);
331  return 0;
332 }
333 
334 int MSTRUCT_GENERATEUR_DCR::creer_frontiere_boite(void)
335 {
336  double boite_dx=m_boite3d_distribution.get_xmax()-m_boite3d_distribution.get_xmin();
337  double boite_dy=m_boite3d_distribution.get_ymax()-m_boite3d_distribution.get_ymin();
338  double boite_dz=m_boite3d_distribution.get_zmax()-m_boite3d_distribution.get_zmin();
339  auto plan_xy_z0 = std::make_shared<chrono::ChBodyEasyBox>(boite_dx+2,boite_dy+2,1, 1, true, false);
340  plan_xy_z0->SetPos(chrono::ChVector<>(boite_dx/2.0,boite_dy/2.0,m_boite3d_distribution.get_zmin()-0.5+1.05*m_distance_min/2.0));
341  plan_xy_z0->SetBodyFixed(true);
342  plan_xy_z0->GetMaterialSurfaceNSC()->SetRestitution(1.0);
343  plan_xy_z0->GetMaterialSurfaceNSC()->SetFriction(m_friction);
344  plan_xy_z0->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
345  m_systeme_physique->Add(plan_xy_z0);
346  auto plan_xy_z1 = std::make_shared<chrono::ChBodyEasyBox>(boite_dx+2,boite_dy+2,1, 1, true, false);
347  plan_xy_z1->SetPos(chrono::ChVector<>(boite_dx/2.0,boite_dy/2.0,m_boite3d_distribution.get_zmax()+0.5-1.05*m_distance_min/2.0));
348  plan_xy_z1->SetBodyFixed(true);
349  plan_xy_z1->GetMaterialSurfaceNSC()->SetRestitution(1.0);
350  plan_xy_z1->GetMaterialSurfaceNSC()->SetFriction(m_friction);
351  plan_xy_z1->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
352  m_systeme_physique->Add(plan_xy_z1);
353  auto plan_x0_yz = std::make_shared<chrono::ChBodyEasyBox>(1,boite_dy+2,boite_dz+2, 1, true, false);
354  plan_x0_yz->SetPos(chrono::ChVector<>(m_boite3d_distribution.get_xmin()-0.5+1.05*m_distance_min/2.0,boite_dy/2.0,boite_dz/2.0));
355  plan_x0_yz->SetBodyFixed(true);
356  plan_x0_yz->GetMaterialSurfaceNSC()->SetRestitution(1.0);
357  plan_x0_yz->GetMaterialSurfaceNSC()->SetFriction(m_friction);
358  plan_x0_yz->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
359  m_systeme_physique->Add(plan_x0_yz);
360  auto plan_x1_yz = std::make_shared<chrono::ChBodyEasyBox>(1,boite_dy+2,boite_dz+2, 1, true, false);
361  plan_x1_yz->SetPos(chrono::ChVector<>(m_boite3d_distribution.get_xmax()+0.5-1.05*m_distance_min/2.0,boite_dy/2.0,boite_dz/2.0));
362  plan_x1_yz->SetBodyFixed(true);
363  plan_x1_yz->GetMaterialSurfaceNSC()->SetRestitution(1.0);
364  plan_x1_yz->GetMaterialSurfaceNSC()->SetFriction(m_friction);
365  plan_x1_yz->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
366  m_systeme_physique->Add(plan_x1_yz);
367  auto plan_x_y0_z = std::make_shared<chrono::ChBodyEasyBox>(boite_dx+2,1,boite_dz+2, 1, true, false);
368  plan_x_y0_z->SetPos(chrono::ChVector<>(boite_dx/2.0,m_boite3d_distribution.get_ymin()-0.5+1.05*m_distance_min/2.0,boite_dz/2.0));
369  plan_x_y0_z->SetBodyFixed(true);
370  plan_x_y0_z->GetMaterialSurfaceNSC()->SetRestitution(1.0);
371  plan_x_y0_z->GetMaterialSurfaceNSC()->SetFriction(m_friction);
372  plan_x_y0_z->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
373  m_systeme_physique->Add(plan_x_y0_z);
374  auto plan_x_y1_z = std::make_shared<chrono::ChBodyEasyBox>(boite_dx+2,1,boite_dz+2, 1, true, false);
375  plan_x_y1_z->SetPos(chrono::ChVector<>(boite_dx/2.0,m_boite3d_distribution.get_ymax()+0.5-1.05*m_distance_min/2.0,boite_dz/2.0));
376  plan_x_y1_z->SetBodyFixed(true);
377  plan_x_y1_z->GetMaterialSurfaceNSC()->SetRestitution(1.0);
378  plan_x_y1_z->GetMaterialSurfaceNSC()->SetFriction(m_friction);
379  plan_x_y1_z->GetMaterialSurfaceNSC()->SetRollingFriction(m_friction);
380  m_systeme_physique->Add(plan_x_y1_z);
381  return 0;
382 }
383 
384 void MSTRUCT_GENERATEUR_DCR::ralentir_particules(void)
385 {
386  std::vector<std::shared_ptr<chrono::ChBody>>::iterator it;
387  for(it=m_vector_particule_chrono.begin();it!=m_vector_particule_chrono.end();it++)
388  {
389  std::shared_ptr<chrono::ChBody> particule = *it;
390  chrono::ChVector<double> vect=particule->GetPos_dt();
391  if(vect.Length()>m_eps_vitesse)
392  {
393  vect.Mul(vect,m_facteur_reduction_vitesse);
394  particule->SetPos_dt(vect);
395  }
396  else
397  {
398  vect.Set(0.0,0.0,0.0);
399  particule->SetPos_dt(vect);
400  }
401  chrono::ChQuaternion<double> qua=particule->GetRot_dt();
402  if(qua.Length()>m_eps_vitesse)
403  {
404  qua.Mul(qua,m_facteur_reduction_vitesse);
405  particule->SetRot_dt(qua);
406  }
407  else
408  {
409  qua.Set(0.0,0.0,0.0,0.0);
410  particule->SetRot_dt(qua);
411  }
412  }
413 }
414 
415 int MSTRUCT_GENERATEUR_DCR::lancer_simulation(void)
416 {
417  if(m_avec_interface_graphique) cree_interface_graphique();
418  creer_frontiere_boite();
419  if(m_avec_interface_graphique)
420  {
421  m_irrapp->AssetBindAll();
422  m_irrapp->AssetUpdateAll();
423  }
424  m_systeme_physique->SetSolverType(chrono::ChSolver::Type::SOR);
425  m_systeme_physique->SetMaxItersSolverSpeed(20);
426  m_systeme_physique->SetMaxItersSolverStab(5);
427  m_systeme_physique->SetUseSleeping(true);
428  m_systeme_physique->Set_G_acc(0.0);
429  m_systeme_physique->SetMinBounceSpeed(0.0);
430  double temps_simulation=0;
431  char message[5000];
432  long nb_objet=m_vector_particule_chrono.size();
433  std::sprintf(message,"Temps simulation [%.4lf / %.4lf]",temps_simulation,m_temps_max_sim);affiche(message);
434  if(m_avec_interface_graphique)
435  {
436  m_irrapp->SetStepManage(true);
437  m_irrapp->SetTimestep(m_pas_temps);
438  while(m_irrapp->GetDevice()->run() && m_systeme_physique->GetNbodiesSleeping()<nb_objet && temps_simulation<m_temps_max_sim)
439  {
440  temps_simulation+=m_pas_temps;
441  std::sprintf(message,"\033[1A\033[KTemps simulation [%.4lf / %.4lf] Nb objet au repos [%i / %li]",temps_simulation,m_temps_max_sim,m_systeme_physique->GetNbodiesSleeping(),nb_objet);affiche(message);
442  m_irrapp->BeginScene(true,true,irr::video::SColor(255,140,161,192));
443  m_irrapp->DrawAll();
444  m_irrapp->DoStep();
445  m_irrapp->EndScene();
446  ralentir_particules();
447  }
448  std::sprintf(message,"\033[1A\033[KTemps simulation [%.4lf / %.4lf] Nb objet au repos [%i / %li]",temps_simulation,m_temps_max_sim,m_systeme_physique->GetNbodiesSleeping(),nb_objet);affiche(message);
449  m_irrapp->GetDevice()->closeDevice();
450  }
451  else
452  {
453  while(m_systeme_physique->GetNbodiesSleeping()<nb_objet && temps_simulation<m_temps_max_sim)
454  {
455  temps_simulation+=m_pas_temps;
456  std::sprintf(message,"\033[1A\033[KTemps simulation [%.4lf / %.4lf] Nb objet au repos [%i / %li]",temps_simulation,m_temps_max_sim,m_systeme_physique->GetNbodiesSleeping(),nb_objet);affiche(message);
457  m_systeme_physique->DoStepDynamics(temps_simulation);
458  ralentir_particules();
459  }
460  std::sprintf(message,"\033[1A\033[KTemps simulation [%.4lf / %.4lf] Nb objet au repos [%i / %li]",temps_simulation,m_temps_max_sim,m_systeme_physique->GetNbodiesSleeping(),nb_objet);affiche(message);
461  }
462  if(m_systeme_physique->GetNbodiesSleeping()<nb_objet) return FAIL;
463  return OK;
464 }
465 
466  int MSTRUCT_GENERATEUR_DCR::generer_geometrie()
467 {
468  initialiser_grille();
469  m_matrice=MG_CG::creer_MG_CG_FORME_VOLUME_BOITE(m_mgcg_modele,
470  m_boite3d_ves.get_xmin(),m_boite3d_ves.get_ymin(),m_boite3d_ves.get_zmin(),
471  m_boite3d_ves.get_xmax(),m_boite3d_ves.get_ymax(),m_boite3d_ves.get_zmax());
472  m_matrice->construire();
473  m_cube_initial=(MG_CG_FORME_VOLUME*)m_matrice;
474 
475 
476  std::map<std::string,MSTRUCT_GROUPE_PARTICULE*>::iterator it_groupe_particule;
477  for(it_groupe_particule=m_map_groupe_particule.begin();it_groupe_particule!=m_map_groupe_particule.end();it_groupe_particule++)
478  {
479 
480  MSTRUCT_GROUPE_PARTICULE* groupe_particule=it_groupe_particule->second;
481  if(groupe_particule->get_type_particule()==MSTRUCT::TYPE_INCLUSION::SPHERE)
482  {
483  MG_CG_GROUPE_FORME* groupe_forme = MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,groupe_particule->get_nom());
484  m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
485  std::vector<MSTRUCT_CHRONO_PARTICULE*>::iterator it_particule;
486  std::vector<MSTRUCT_CHRONO_PARTICULE*>* vector_particule = groupe_particule->get_vector_particule();
487  double fraction_volumique_totale=0;
488  double fraction_volumique_finale=0;
489  long nb_inclusion=0;
490  for(it_particule=vector_particule->begin();it_particule!=vector_particule->end();it_particule++)
491  {
492  MSTRUCT_CHRONO_PARTICULE_SPHERE* sphere = (MSTRUCT_CHRONO_PARTICULE_SPHERE*)*it_particule;
493  std::shared_ptr<chrono::ChBody> chrono_sphere = sphere->get_ChBody();
494  chrono::ChVector<double> bbmin;
495  chrono::ChVector<double> bbmax;
496  chrono_sphere->GetTotalAABB(bbmin,bbmax);
497  BOITE_3D boite_3d(bbmin[0],bbmin[1],bbmin[2],bbmax[0],bbmax[1],bbmax[2]);
498  if(m_boite3d_ves.get_intersection(boite_3d)==0) continue;
499  chrono::ChVector<double> chvector_centre = chrono_sphere->GetPos();
500  double centre[3];
501  centre[0]=chvector_centre[0];
502  centre[1]=chvector_centre[1];
503  centre[2]=chvector_centre[2];
504  double rayon = sphere->get_rayon_ini();
506  MG_CG_FORME_VOLUME_SPHERE* sphere_test = MG_CG::creer_MG_CG_FORME_VOLUME_SPHERE(m_mgcg_modele,centre[0],centre[1],centre[2],rayon);
507  sphere_test->construire();
508  std::vector<MG_CG_FORME*> vector_forme;
509  int position_relative;
510  double fraction_volumique=0;
511  if(insertion_inclusion(sphere_test,fraction_volumique,vector_forme,position_relative)==OK)
512  {
513  nb_inclusion++;
514  fraction_volumique_totale+=fraction_volumique;
515  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
516  std::vector<MG_CG_FORME*>::iterator it_forme;
517  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
518  {
519  MG_CG_FORME* forme=*it_forme;
520  groupe_forme->ajouter_mgcg_forme(forme);
521  if(it_forme==vector_forme.begin())
522  {
523  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"CENTRE",3,centre);
524  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
525  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",sphere_test->get_id());
526  }
527  if(sphere->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
528  }
529  char message[5000];
530  char position[100];
531  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
532  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
533  sprintf(message,"Sphere # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
534  affiche(message);
535  }
537  }
538  }
539  if(groupe_particule->get_type_particule()==MSTRUCT::TYPE_INCLUSION::CYLINDRE)
540  {
541  MG_CG_GROUPE_FORME* groupe_forme = MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,groupe_particule->get_nom());
542  m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
543  std::vector<MSTRUCT_CHRONO_PARTICULE*>::iterator it_particule;
544  std::vector<MSTRUCT_CHRONO_PARTICULE*>* vector_particule = groupe_particule->get_vector_particule();
545  double fraction_volumique_totale=0;
546  double fraction_volumique_finale=0;
547  long nb_inclusion=0;
548 
549  for(it_particule=vector_particule->begin();it_particule!=vector_particule->end();it_particule++)
550  {
551  MSTRUCT_CHRONO_PARTICULE_CYLINDRE* cylindre = (MSTRUCT_CHRONO_PARTICULE_CYLINDRE*)*it_particule;
552  std::shared_ptr<chrono::ChBody> chrono_cylindre = cylindre->get_ChBody();
553  chrono::ChVector<double> bbmin;
554  chrono::ChVector<double> bbmax;
555  chrono_cylindre->GetTotalAABB(bbmin,bbmax);
556  BOITE_3D boite_3d(bbmin[0],bbmin[1],bbmin[2],bbmax[0],bbmax[1],bbmax[2]);
557  if(m_boite3d_ves.get_intersection(boite_3d)==0) continue;
558  chrono::ChVector<double> chvector_centre = chrono_cylindre->GetPos();
559  chrono::ChVector<double> chvector_axe = chrono_cylindre->GetRot().GetYaxis();
560  double axe[3];
561  axe[0]=chvector_axe[0];
562  axe[1]=chvector_axe[1];
563  axe[2]=chvector_axe[2];
564  double rayon = cylindre->get_rayon_ini();
565  double longueur = cylindre->get_longueur_ini();
566  double extremite[3];
567  extremite[0]=chvector_centre[0]-longueur/2.*axe[0];
568  extremite[1]=chvector_centre[1]-longueur/2.*axe[1];
569  extremite[2]=chvector_centre[2]-longueur/2.*axe[2];
572  extremite[0],extremite[1],extremite[2],
573  axe[0],axe[1],axe[2],rayon,longueur);
574  cylindre_test->construire();
575  std::vector<MG_CG_FORME*> vector_forme;
576  int position_relative;
577  double fraction_volumique=0;
578  if(insertion_inclusion(cylindre_test,fraction_volumique,vector_forme,position_relative)==OK)
579  {
580  nb_inclusion++;
581  fraction_volumique_totale+=fraction_volumique;
582  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
583  std::vector<MG_CG_FORME*>::iterator it_forme;
584  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
585  {
586  MG_CG_FORME* forme=*it_forme;
587  groupe_forme->ajouter_mgcg_forme(forme);
588  if(it_forme==vector_forme.begin())
589  {
590  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"EXTREMITE",3,extremite);
591  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"AXE",3,axe);
592  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
593  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"LONGUEUR",longueur);
594  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",cylindre_test->get_id());
595  }
596  if(cylindre->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
597  }
598  char message[5000];
599  char position[100];
600  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
601  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
602  sprintf(message,"Cylindre # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
603  affiche(message);
604  }
605  }
606  }
607  }
608 
609 return 0;
610 }
611 
612 int MSTRUCT_GENERATEUR_DCR::generer_geometrie_avec_changement()
613 {
614  initialiser_grille();
615  m_matrice=MG_CG::creer_MG_CG_FORME_VOLUME_BOITE(m_mgcg_modele,
616  m_boite3d_ves.get_xmin(),m_boite3d_ves.get_ymin(),m_boite3d_ves.get_zmin(),
617  m_boite3d_ves.get_xmax(),m_boite3d_ves.get_ymax(),m_boite3d_ves.get_zmax());
618  m_matrice->construire();
619  m_cube_initial=(MG_CG_FORME_VOLUME*)m_matrice;
620 
621  std::map<std::string,MSTRUCT_GROUPE_PARTICULE*>::iterator it_groupe_particule;
622  for(it_groupe_particule=m_map_groupe_particule.begin();it_groupe_particule!=m_map_groupe_particule.end();it_groupe_particule++)
623  {
624 
625  MSTRUCT_GROUPE_PARTICULE* groupe_particule=it_groupe_particule->second;
626  if(groupe_particule->get_type_particule()==MSTRUCT::TYPE_INCLUSION::SPHERE)
627  {
628  MG_CG_GROUPE_FORME* groupe_forme = MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,groupe_particule->get_nom());
629  m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
630  std::vector<MSTRUCT_CHRONO_PARTICULE*>::iterator it_particule;
631  std::vector<MSTRUCT_CHRONO_PARTICULE*>* vector_particule = groupe_particule->get_vector_particule();
632  double fraction_volumique_totale=0;
633  double fraction_volumique_finale=0;
634  long nb_inclusion=0;
635  long nb_inc_corrected=0;
636  for(it_particule=vector_particule->begin();it_particule!=vector_particule->end();it_particule++)
637  {
638  MSTRUCT_CHRONO_PARTICULE_SPHERE* sphere = (MSTRUCT_CHRONO_PARTICULE_SPHERE*)*it_particule;
639  std::shared_ptr<chrono::ChBody> chrono_sphere = sphere->get_ChBody();
640  chrono::ChVector<double> bbmin;
641  chrono::ChVector<double> bbmax;
642  chrono_sphere->GetTotalAABB(bbmin,bbmax);
643  BOITE_3D boite_3d(bbmin[0],bbmin[1],bbmin[2],bbmax[0],bbmax[1],bbmax[2]);
644  if(m_boite3d_ves.get_intersection(boite_3d)==0) continue;
645  chrono::ChVector<double> chvector_centre = chrono_sphere->GetPos();
646  double centre[3];
647  centre[0]=chvector_centre[0];
648  centre[1]=chvector_centre[1];
649  centre[2]=chvector_centre[2];
650  double rayon = sphere->get_rayon_ini();
652  MG_CG_FORME_VOLUME_SPHERE* sphere_test = MG_CG::creer_MG_CG_FORME_VOLUME_SPHERE(m_mgcg_modele,centre[0],centre[1],centre[2],rayon);
653  sphere_test->construire();
654  std::vector<MG_CG_FORME*> vector_forme;
655  int position_relative;
656  double fraction_volumique=0;
657  if(insertion_inclusion(sphere_test,fraction_volumique,vector_forme,position_relative)==OK)
658  {
659  nb_inclusion++;
660  fraction_volumique_totale+=fraction_volumique;
661  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
662  std::vector<MG_CG_FORME*>::iterator it_forme;
663  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
664  {
665  MG_CG_FORME* forme=*it_forme;
666  groupe_forme->ajouter_mgcg_forme(forme);
667  if(it_forme==vector_forme.begin())
668  {
669  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"CENTRE",3,centre);
670  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
671  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",sphere_test->get_id());
672  }
673  if(sphere->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
674  }
675  char message[5000];
676  char position[100];
677  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
678  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
679  sprintf(message,"Sphere # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
680  affiche(message);
681  }
682 
683  }
684  for(it_particule=vector_particule->begin();it_particule!=vector_particule->end();it_particule++)
685  {
686  MSTRUCT_CHRONO_PARTICULE_SPHERE* sphere = (MSTRUCT_CHRONO_PARTICULE_SPHERE*)*it_particule;
687  std::shared_ptr<chrono::ChBody> chrono_sphere = sphere->get_ChBody();
688  chrono::ChVector<double> bbmin;
689  chrono::ChVector<double> bbmax;
690  chrono_sphere->GetTotalAABB(bbmin,bbmax);
691  BOITE_3D boite_3d(bbmin[0],bbmin[1],bbmin[2],bbmax[0],bbmax[1],bbmax[2]);
692  if(m_boite3d_ves.get_intersection(boite_3d)==0) continue;
693  chrono::ChVector<double> chvector_centre = chrono_sphere->GetPos();
694  double centre[3];
695  centre[0]=chvector_centre[0];
696  centre[1]=chvector_centre[1];
697  centre[2]=chvector_centre[2];
698  double rayon = sphere->get_rayon_ini();
700  MG_CG_FORME_VOLUME_SPHERE* sphere_test = MG_CG::creer_MG_CG_FORME_VOLUME_SPHERE(m_mgcg_modele,centre[0],centre[1],centre[2],rayon);
701  sphere_test->construire();
702  std::vector<MG_CG_FORME*> vector_forme;
703  int position_relative;
704  double fraction_volumique=0;
705 
706  int it_i=0; int it_iii=0; int check=0; double centre_tri[3];
707 
708  if(!insertion_inclusion(sphere_test,fraction_volumique,vector_forme,position_relative)==OK)
709  {
710 
711  while(it_i<3)
712  {
713  rayon=rayon*0.9;
714  MG_CG_FORME_VOLUME_SPHERE* sphere_test = MG_CG::creer_MG_CG_FORME_VOLUME_SPHERE(m_mgcg_modele,centre[0],centre[1],centre[2],rayon);
715  sphere_test->construire();
716  if(insertion_inclusion(sphere_test,fraction_volumique,vector_forme,position_relative)==OK)
717  {
718  nb_inclusion++;
719  fraction_volumique_totale+=fraction_volumique;
720  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
721  std::vector<MG_CG_FORME*>::iterator it_forme;
722  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
723  {
724  MG_CG_FORME* forme=*it_forme;
725  groupe_forme->ajouter_mgcg_forme(forme);
726  if(it_forme==vector_forme.begin())
727  {
728  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"CENTRE",3,centre);
729  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
730  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",sphere_test->get_id());
731  }
732  if(sphere->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
733  }
734  char message[5000];
735  char position[100];
736  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
737  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
738  sprintf(message,"Sphere_rayon # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
739  affiche(message);
740  it_i=10;
741  check=3;
742  nb_inc_corrected++;
743 
744  }
745  it_i++;
746  }
747 
748  if(check==0)
749  while(it_iii<17)
750  {
751  if (it_iii % 2==0)
752  {
753  centre_tri[0]=centre[0]+((it_iii+1)*m_distance_min/5);
754  centre_tri[1]=centre[1]+((it_iii+1)*m_distance_min/5);
755  centre_tri[2]=centre[2]+((it_iii+1)*m_distance_min/5);
756  }
757 
758  else
759  {
760  centre_tri[0]=centre[0]-((it_iii+1)*m_distance_min/5);
761  centre_tri[1]=centre[1]-((it_iii+1)*m_distance_min/5);
762  centre_tri[2]=centre[2]-((it_iii+1)*m_distance_min/5);
763  }
764 
765  MG_CG_FORME_VOLUME_SPHERE* sphere_test = MG_CG::creer_MG_CG_FORME_VOLUME_SPHERE(m_mgcg_modele,centre_tri[0],centre_tri[1],centre_tri[2],rayon);
766  sphere_test->construire();
767 
768  if(insertion_inclusion(sphere_test,fraction_volumique,vector_forme,position_relative)==OK)
769  {
770  nb_inclusion++;
771  fraction_volumique_totale+=fraction_volumique;
772  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
773  std::vector<MG_CG_FORME*>::iterator it_forme;
774  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
775  {
776  MG_CG_FORME* forme=*it_forme;
777  groupe_forme->ajouter_mgcg_forme(forme);
778  if(it_forme==vector_forme.begin())
779  {
780  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"CENTRE",3,centre);
781  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
782  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",sphere_test->get_id());
783  }
784  if(sphere->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
785  }
786  char message[5000];
787  char position[100];
788  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
789  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
790  sprintf(message,"Sphere_position # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
791  affiche(message);
792  it_iii=10;
793  check=3;
794  nb_inc_corrected++;
795 
796  }
797  it_iii++;
798  }
799  }
800  }
801 
802  char message1[5000];
803  sprintf(message1,"Nb_inclusion_corrected # [%4li] ",nb_inc_corrected);
804  affiche(message1);
805 
806  }
807 
808  if(groupe_particule->get_type_particule()==MSTRUCT::TYPE_INCLUSION::CYLINDRE)
809  {
810  MG_CG_GROUPE_FORME* groupe_forme = MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,groupe_particule->get_nom());
811  m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
812  std::vector<MSTRUCT_CHRONO_PARTICULE*>::iterator it_particule;
813  std::vector<MSTRUCT_CHRONO_PARTICULE*>* vector_particule = groupe_particule->get_vector_particule();
814  double fraction_volumique_totale=0;
815  double fraction_volumique_finale=0;
816  long nb_inclusion=0;
817  long nb_inc_corrected=0;
818  for(it_particule=vector_particule->begin();it_particule!=vector_particule->end();it_particule++)
819  {
820  MSTRUCT_CHRONO_PARTICULE_CYLINDRE* cylindre = (MSTRUCT_CHRONO_PARTICULE_CYLINDRE*)*it_particule;
821  std::shared_ptr<chrono::ChBody> chrono_cylindre = cylindre->get_ChBody();
822  chrono::ChVector<double> bbmin;
823  chrono::ChVector<double> bbmax;
824  chrono_cylindre->GetTotalAABB(bbmin,bbmax);
825  BOITE_3D boite_3d(bbmin[0],bbmin[1],bbmin[2],bbmax[0],bbmax[1],bbmax[2]);
826  if(m_boite3d_ves.get_intersection(boite_3d)==0) continue;
827  chrono::ChVector<double> chvector_centre = chrono_cylindre->GetPos();
828  chrono::ChVector<double> chvector_axe = chrono_cylindre->GetRot().GetYaxis();
829  double axe[3];
830  axe[0]=chvector_axe[0];
831  axe[1]=chvector_axe[1];
832  axe[2]=chvector_axe[2];
833  double rayon = cylindre->get_rayon_ini();
834  double longueur = cylindre->get_longueur_ini();
835  double extremite[3];
836  extremite[0]=chvector_centre[0]-longueur/2.*axe[0];
837  extremite[1]=chvector_centre[1]-longueur/2.*axe[1];
838  extremite[2]=chvector_centre[2]-longueur/2.*axe[2];
841  extremite[0],extremite[1],extremite[2],
842  axe[0],axe[1],axe[2],rayon,longueur);
843  cylindre_test->construire();
844  std::vector<MG_CG_FORME*> vector_forme;
845  int position_relative;
846  double fraction_volumique=0;
847  if(insertion_inclusion(cylindre_test,fraction_volumique,vector_forme,position_relative)==OK)
848  {
849  nb_inclusion++;
850  fraction_volumique_totale+=fraction_volumique;
851  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
852  std::vector<MG_CG_FORME*>::iterator it_forme;
853  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
854  {
855  MG_CG_FORME* forme=*it_forme;
856  groupe_forme->ajouter_mgcg_forme(forme);
857  if(it_forme==vector_forme.begin())
858  {
859  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"EXTREMITE",3,extremite);
860  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"AXE",3,axe);
861  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
862  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"LONGUEUR",longueur);
863  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",cylindre_test->get_id());
864  }
865  if(cylindre->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
866  }
867  char message[5000];
868  char position[100];
869  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
870  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
871  sprintf(message,"Cylindre # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
872  affiche(message);
873  }
874 }
875 
876 
877  for(it_particule=vector_particule->begin();it_particule!=vector_particule->end();it_particule++)
878  {
879  MSTRUCT_CHRONO_PARTICULE_CYLINDRE* cylindre = (MSTRUCT_CHRONO_PARTICULE_CYLINDRE*)*it_particule;
880  std::shared_ptr<chrono::ChBody> chrono_cylindre = cylindre->get_ChBody();
881  chrono::ChVector<double> bbmin;
882  chrono::ChVector<double> bbmax;
883  chrono_cylindre->GetTotalAABB(bbmin,bbmax);
884  BOITE_3D boite_3d(bbmin[0],bbmin[1],bbmin[2],bbmax[0],bbmax[1],bbmax[2]);
885  if(m_boite3d_ves.get_intersection(boite_3d)==0) continue;
886  chrono::ChVector<double> chvector_centre = chrono_cylindre->GetPos();
887  chrono::ChVector<double> chvector_axe = chrono_cylindre->GetRot().GetYaxis();
888  double axe[3];
889  axe[0]=chvector_axe[0];
890  axe[1]=chvector_axe[1];
891  axe[2]=chvector_axe[2];
892  double rayon = cylindre->get_rayon_ini();
893  double longueur = cylindre->get_longueur_ini();
894  double extremite[3];
895  extremite[0]=chvector_centre[0]-longueur/2.*axe[0];
896  extremite[1]=chvector_centre[1]-longueur/2.*axe[1];
897  extremite[2]=chvector_centre[2]-longueur/2.*axe[2];
900  extremite[0],extremite[1],extremite[2],
901  axe[0],axe[1],axe[2],rayon,longueur);
902  cylindre_test->construire();
903  std::vector<MG_CG_FORME*> vector_forme;
904  int position_relative;
905  double fraction_volumique=0;
906 
908 
909  //-----------------NEW-----------------------------
910  int it_i=0; int it_ii=0; int it_iii=0; int it_it=0; int check=0;
911  double theta_deg; double theta_rad; double phi_deg; double phi_rad;
912  double theta_deg_tri; double theta_rad_tri; double phi_deg_tri; double phi_rad_tri;
913  double centre_tri[3];
914 
915  phi_rad=acos(axe[2]);
916  theta_rad=acos((axe[0])/(sin(phi_rad)));
917  phi_deg=phi_rad*180/3.14;
918  theta_deg=theta_rad*180/3.14;
919 
920  if(!insertion_inclusion(cylindre_test,fraction_volumique,vector_forme,position_relative)==OK)
921  {
922 
923  while(it_i<3)
924  {
925  longueur=longueur*0.9;
926  rayon=rayon*0.9;
927  extremite[0]=chvector_centre[0]-longueur/2.*axe[0];
928  extremite[1]=chvector_centre[1]-longueur/2.*axe[1];
929  extremite[2]=chvector_centre[2]-longueur/2.*axe[2];
932  extremite[0],extremite[1],extremite[2],
933  axe[0],axe[1],axe[2],rayon,longueur);
934  cylindre_test->construire();
935  if(insertion_inclusion(cylindre_test,fraction_volumique,vector_forme,position_relative)==OK)
936  {
937  nb_inclusion++;
938 
939  fraction_volumique_totale+=fraction_volumique;
940  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
941  std::vector<MG_CG_FORME*>::iterator it_forme;
942  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
943  {
944  MG_CG_FORME* forme=*it_forme;
945  groupe_forme->ajouter_mgcg_forme(forme);
946  if(it_forme==vector_forme.begin())
947  {
948  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"EXTREMITE",3,extremite);
949  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"AXE",3,axe);
950  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
951  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"LONGUEUR",longueur);
952  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",cylindre_test->get_id());
953  }
954  if(cylindre->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
955  }
956  char message[5000];
957  char position[100];
958  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
959  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
960  sprintf(message,"Cylindre_dimension # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
961  affiche(message);
962 
963  it_i=10;
964  check=3;
965  nb_inc_corrected++;
966 
967  }
968  it_i++;
969  }
970  if(check==0)
971  while(it_ii<8)
972  {
973  if (it_ii % 2==0)
974  {
975  theta_deg_tri=theta_deg+((it_ii+1)*6);
976  theta_rad_tri=theta_deg_tri*3.14/180;
977  phi_deg_tri=phi_deg+((it_ii+1)*6);
978  phi_rad_tri=phi_deg_tri*3.14/180;
979  }
980 
981  else
982  {
983  theta_deg_tri=theta_deg-((it_ii)*6);
984  theta_rad_tri=theta_deg*3.14/180;
985  phi_deg_tri=phi_deg-((it_ii)*6);
986  phi_rad_tri=phi_deg_tri*3.14/180;
987  }
988  axe[0]=sin(phi_rad_tri)*cos(theta_rad_tri);
989  axe[1]=sin(phi_rad_tri)*sin(theta_rad_tri);
990  axe[2]=cos(phi_rad_tri);
991 
992  extremite[0]=chvector_centre[0]-longueur/2.*axe[0];
993  extremite[1]=chvector_centre[1]-longueur/2.*axe[1];
994  extremite[2]=chvector_centre[2]-longueur/2.*axe[2];
995 
998  extremite[0],extremite[1],extremite[2],
999  axe[0],axe[1],axe[2],rayon,longueur);
1000  cylindre_test->construire();
1001  if(insertion_inclusion(cylindre_test,fraction_volumique,vector_forme,position_relative)==OK)
1002 {
1003  nb_inclusion++;
1004 
1005  fraction_volumique_totale+=fraction_volumique;
1006  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
1007  std::vector<MG_CG_FORME*>::iterator it_forme;
1008  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
1009  {
1010  MG_CG_FORME* forme=*it_forme;
1011  groupe_forme->ajouter_mgcg_forme(forme);
1012  if(it_forme==vector_forme.begin())
1013  {
1014  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"EXTREMITE",3,extremite);
1015  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"AXE",3,axe);
1016  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
1017  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"LONGUEUR",longueur);
1018  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",cylindre_test->get_id());
1019  }
1020  if(cylindre->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
1021  }
1022  char message[5000];
1023  char position[100];
1024  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
1025  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
1026  sprintf(message,"Cylindre_orientation # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
1027  affiche(message);
1028 
1029  it_ii=10;
1030  check=3;
1031  nb_inc_corrected++;
1032  }
1033  it_ii++;
1034  }
1035  if(check==0)
1036  while(it_iii<17)
1037  {
1038  if (it_iii % 2==0)
1039  {
1040  centre_tri[0]=chvector_centre[0]+((it_iii+1)*m_distance_min/5);
1041  centre_tri[1]=chvector_centre[1]+((it_iii+1)*m_distance_min/5);
1042  centre_tri[2]=chvector_centre[2]+((it_iii+1)*m_distance_min/5);
1043  }
1044 
1045  else
1046  {
1047  centre_tri[0]=chvector_centre[0]-((it_iii+1)*m_distance_min/5);
1048  centre_tri[1]=chvector_centre[1]-((it_iii+1)*m_distance_min/5);
1049  centre_tri[2]=chvector_centre[2]-((it_iii+1)*m_distance_min/5);
1050  }
1051 
1052  axe[0]=chvector_axe[0];
1053  axe[1]=chvector_axe[1];
1054  axe[2]=chvector_axe[2];
1055 
1056  extremite[0]=centre_tri[0]-longueur/2.*axe[0];
1057  extremite[1]=centre_tri[1]-longueur/2.*axe[1];
1058  extremite[2]=centre_tri[2]-longueur/2.*axe[2];
1059 
1062  extremite[0],extremite[1],extremite[2],
1063  axe[0],axe[1],axe[2],rayon,longueur);
1064  cylindre_test->construire();
1065  if(insertion_inclusion(cylindre_test,fraction_volumique,vector_forme,position_relative)==OK)
1066 {
1067  nb_inclusion++;
1068 
1069  fraction_volumique_totale+=fraction_volumique;
1070  fraction_volumique_finale=fraction_volumique_totale/(m_boite3d_ves.get_volume());
1071  std::vector<MG_CG_FORME*>::iterator it_forme;
1072  for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++)
1073  {
1074  MG_CG_FORME* forme=*it_forme;
1075  groupe_forme->ajouter_mgcg_forme(forme);
1076  if(it_forme==vector_forme.begin())
1077  {
1078  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"EXTREMITE",3,extremite);
1079  MG_CG::creer_MG_CG_INFO_VCT_DOUBLE(forme,(char*)"AXE",3,axe);
1080  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"RAYON",rayon);
1081  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"LONGUEUR",longueur);
1082  MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"ID_FORME_INI",cylindre_test->get_id());
1083  }
1084  if(cylindre->est_porosite()) MG_CG::creer_MG_CG_INFO_DOUBLE(forme,(char*)"POROSITE",1);
1085  }
1086  char message[5000];
1087  char position[100];
1088  if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) sprintf(position,"Interieur");
1089  else if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) sprintf(position,"Au_bord");
1090  sprintf(message,"Cylindre_position # [%4li] : Fraction volumique [%.6lf] : Position %s",nb_inclusion,fraction_volumique_finale,position);
1091  affiche(message);
1092 
1093  it_iii=10;
1094  check=3;
1095  nb_inc_corrected++;
1096  }
1097  it_iii++;
1098  }
1099 
1100  }
1101  }
1102 
1103 
1104  char message2[5000];
1105  sprintf(message2,"Nb_inclusion_corrected # [%4li] ",nb_inc_corrected);
1106  affiche(message2);
1107 
1108  }
1109 
1110  }
1111 
1112 return 0;
1113 }
1114 
1115 
1116 
1117 int MSTRUCT_GENERATEUR_DCR::construire(MSTRUCT_VES* ves)
1118 {
1119  ves->change_mgcg_modele(m_mgcg_modele);
1120  MG_CG_ASSEMBLAGE* assemblage = MG_CG::creer_MG_CG_ASSEMBLAGE(m_mgcg_modele,(char*)"VES");
1121  ves->change_mgcg_assemblage(assemblage);
1122  ves->change_mg_geometrie(assemblage->get_mg_sous_geometrie());
1123  std::vector<MG_CG_GROUPE_FORME*>::iterator it_gr_forme;
1124  for(it_gr_forme=m_vector_mgcg_groupe_forme_inclusion.begin();it_gr_forme!=m_vector_mgcg_groupe_forme_inclusion.end();it_gr_forme++)
1125  {
1126  MG_CG_GROUPE_FORME* groupe_forme = *it_gr_forme;
1127  std::map<long,MG_CG_FORME*>::iterator it_forme;
1128  for(MG_CG_FORME* forme=groupe_forme->get_premiere_mgcg_forme(it_forme);forme!=NULL;forme=groupe_forme->get_suivante_mgcg_forme(it_forme))
1129  {
1130  MG_CG_INFO* info_porosite = forme->get_mgcg_info((char*)"POROSITE");
1131  if(info_porosite!=NULL) continue;
1132  assemblage->ajouter_mgcg_forme(forme);
1133  }
1134  }
1135  assemblage->ajouter_mgcg_forme(m_matrice);
1136  MG_CG_GROUPE_FORME* groupe_forme_matrice=MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,(char*)"Matrice");
1137  groupe_forme_matrice->ajouter_mgcg_forme(m_matrice);
1138  return OK;
1139 }
1140 
1141 void MSTRUCT_GENERATEUR_DCR::active_interface_graphique(bool avec_interface_graphique)
1142 {
1143  if(m_avec_interface_graphique==false)
1144  {
1145  m_avec_interface_graphique=avec_interface_graphique;
1146  }
1147 }
1148 
1149 int MSTRUCT_GENERATEUR_DCR::cree_interface_graphique(void)
1150 {
1151  if(!m_avec_interface_graphique) return FAIL;
1152  m_irrapp = new chrono::irrlicht::ChIrrApp(m_systeme_physique,(const wchar_t*)"MSTRUCT_GENERATEUR_DCR",irr::core::dimension2d<irr::u32>(800,600),false);
1153  chrono::irrlicht::ChIrrWizard::add_typical_Sky(m_irrapp->GetDevice());
1154  chrono::irrlicht::ChIrrWizard::add_typical_Lights(m_irrapp->GetDevice());
1155  double distance = m_boite3d_distribution.get_rayon();
1156  chrono::irrlicht::ChIrrWizard::add_typical_Camera(m_irrapp->GetDevice(), irr::core::vector3df(distance+0.5, distance+0.5, distance+0.5));
1157 return 0;
1158 
1159 }
1160 
1161 
1162 
1163 
1164 
1165 
1166 
1167 
1168 #endif
virtual int ajouter_mgcg_forme(MG_CG_FORME *mgcg_forme, bool avec_mg_element=true)
virtual MG_SOUS_GEOMETRIE * get_mg_sous_geometrie(void)
virtual int construire(void)=0
virtual int construire(void)=0
MG_CG_FORME * get_suivante_mgcg_forme(std::map< long, MG_CG_FORME * >::iterator &it)
MG_CG_FORME * get_premiere_mgcg_forme(std::map< long, MG_CG_FORME * >::iterator &it)
int ajouter_mgcg_forme(MG_CG_FORME *mgcg_forme)
static MG_CG_INFO_VCT_DOUBLE * creer_MG_CG_INFO_VCT_DOUBLE(MG_CONSTRUCTION_GEOMETRIQUE *mg_construction_geometrique, std::string identifiant, std::vector< double > &valeur)
Definition: mg_cg.cpp:137
static MG_CG_FORME_VOLUME_SPHERE * creer_MG_CG_FORME_VOLUME_SPHERE(MG_CG_MODELE *mgcg_modele, double centre_x, double centre_y, double centre_z, double rayon)
Definition: mg_cg.cpp:215
static MG_CG_INFO_DOUBLE * creer_MG_CG_INFO_DOUBLE(MG_CONSTRUCTION_GEOMETRIQUE *mg_construction_geometrique, std::string identifiant, double valeur)
Definition: mg_cg.cpp:127
static MG_CG_ASSEMBLAGE * creer_MG_CG_ASSEMBLAGE(MG_CG_MODELE *mgcg_modele, std::string nom_mgcg_assemblage)
Definition: mg_cg.cpp:97
static MG_CG_GROUPE_FORME * creer_MG_CG_GROUPE_FORME(MG_CG_MODELE *mgcg_modele, std::string nom)
Definition: mg_cg.cpp:107
static MG_CG_FORME_VOLUME_CYLINDRE * creer_MG_CG_FORME_VOLUME_CYLINDRE(MG_CG_MODELE *mgcg_modele, double extremite_x, double extremite_y, double extremite_z, double direction_x, double direction_y, double direction_z, double rayon, double longueur)
Definition: mg_cg.cpp:243
static MG_CG_FORME_VOLUME_BOITE * creer_MG_CG_FORME_VOLUME_BOITE(MG_CG_MODELE *mgcg_modele, double x1, double y1, double z1, double x2, double y2, double z2)
Definition: mg_cg.cpp:201
virtual void change_mgcg_assemblage(MG_CG_ASSEMBLAGE *mgcg_assemblage)
virtual void change_mg_geometrie(MG_GEOMETRIE *mg_geometrie)
virtual void change_mgcg_modele(MG_CG_MODELE *mgcg_modele)
const int OK
Definition: mg_definition.h:38
const int FAIL
Definition: mg_definition.h:39
void affiche(char *message)
double2 sin(double2 &val)
double2 acos(double2 &val)
double2 cos(double2 &val)
@ SPHERE
Definition: ve_definition.h:32
@ CYLINDRE
Definition: ve_definition.h:33