ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/microstructure/src/ve_ves.cpp
Revision: 1158
Committed: Thu Jun 13 22:18:49 2024 UTC (11 months, 1 week ago) by francois
File size: 32854 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

# User Rev Content
1 francois 1158 //####//------------------------------------------------------------
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     //####// ve_ves.cpp
15     //####//
16     //####//------------------------------------------------------------
17     //####//------------------------------------------------------------
18     //####// COPYRIGHT 2000-2024
19     //####// jeu 13 jun 2024 11:58:56 EDT
20     //####//------------------------------------------------------------
21     //####//------------------------------------------------------------
22 francois 756
23 couturad 801 #include "ve_ves.h"
24     #include "ve_definition.h"
25 francois 756 #include "gestionversion.h"
26 couturad 801 #include "mg_gestionnaire.h"
27     #include "mg_arbre.h"
28     #include "mg_assemblage.h"
29     #include "mg_primitive.h"
30     #include "mg_primitive_boite.h"
31     #include "mg_primitive_sphere.h"
32     #include "mg_primitive_cylindre.h"
33     #include "mg_primitive_cone.h"
34     #include "mg_primitive_tore.h"
35     #include "mg_primitive_complexe.h"
36     #include "mg_operateur_boolean.h"
37     #include "mg_operateur_boolean_difference.h"
38     #include "mg_operateur_boolean_intersection.h"
39     #include "mg_operateur_boolean_union.h"
40     #include "mg_sommet_noeud.h"
41     #include "fct_taille.h"
42     #include "fct_generateur_frontiere.h"
43     #include "fct_generateur_constante.h"
44     #include "fct_generateur_fichier.h"
45     #include "fct_taille_fem_solution_generateur_constant.h"
46     #include "fct_taille_fem_solution_generateur_echantillon_frontiere.h"
47     #include "fct_taille_fem_solution_generateur_fichier.h"
48     #include "mailleur.h"
49     #include "mailleur0d.h"
50     #include "mailleur1d.h"
51     #include "mailleur2d.h"
52     #include "mailleur3d.h"
53 francois 883 #include "mailleur_fem.h"
54 couturad 801 #include "tpl_map_entite.h"
55     #include "ot_mathematique.h"
56     #include "fem_maillage.h"
57     #include "mgaster.h"
58     #include "mg_export.h"
59     #include "sphere_grille.h"
60     #include <string.h>
61     #include <map>
62     #include <random>
63     #include <stdio.h>
64     #include <iostream>
65     #include <chrono>
66 francois 756
67 couturad 801 VE_VES::VE_VES()
68     {
69     gest = new MG_GESTIONNAIRE;
70     arbre = new MG_ARBRE("Arbre");
71     assemblage = new MG_ASSEMBLAGE("Assemblage");
72     param_ver = new OT_PARAMETRES();
73     gest->ajouter_mg_arbre(arbre);
74     arbre->ajouter_mg_assemblage(assemblage);
75     ini_param_VER(param_ver);
76     dim_VES[0] = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_Dim_longueur_x]);
77     dim_VES[1] = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_Dim_longueur_y]);
78     dim_VES[2] = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_Dim_longueur_z]);
79     }
80 francois 756
81 couturad 801 VE_VES::VE_VES(VE_VES& mdd)
82     {
83 francois 756
84 couturad 801 }
85    
86     VE_VES::~VE_VES()
87 francois 756 {
88 couturad 801 delete assemblage;
89     delete param_ver;
90     delete gest;
91     }
92 francois 756
93 couturad 801 int VE_VES::construire(void)
94     {
95     int type_ver = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_Type]);
96     switch(type_ver)
97     {
98     case VE_TYPE_VER::HOMOGENE:
99     {
100     generer_VES_homogene();
101     break;
102     }
103     case VE_TYPE_VER::UNE_INCLUSION:
104     {
105     generer_VES_une_inclusion();
106     break;
107     }
108     case VE_TYPE_VER::ALEATOIRE:
109     {
110     generer_VES_aleatoire();
111     break;
112     }
113     }
114 couturad 814 affiche((char*)"Evaluation de la geometrie :\n");
115 couturad 801 evaluer_geometrie();
116     creer_carte();
117     creer_mg_maillage();
118     appliquer_conditions_limites(param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_CL_CHARGEMENT_type]));
119     appliquer_materiaux();
120     creer_fem_maillage();
121     calcul_aster();
122     homogeneisation();
123     return 0;
124 francois 756 }
125    
126 couturad 801 MG_GESTIONNAIRE* VE_VES::get_gestionnaire(void)
127     {
128     return gest;
129     }
130 francois 756
131 couturad 801 MG_ARBRE* VE_VES::get_arbre(void)
132     {
133     return arbre;
134     }
135 francois 756
136 couturad 801 MG_ASSEMBLAGE* VE_VES::get_assemblage(void)
137 francois 756 {
138 couturad 801 return assemblage;
139     }
140 francois 756
141 couturad 801 void VE_VES::active_affichage(fonction_affiche* fonc)
142     {
143     fonc_affiche = fonc;
144     affichageactif = 1;
145 francois 756 }
146    
147 couturad 801 void VE_VES::affiche(char* message)
148     {
149     if(affichageactif==1) fonc_affiche(message);
150     }
151 francois 756
152 couturad 801 void VE_VES::lire_param_VES(char* fichier)
153     {
154     param_ver->lire(fichier);
155     dim_VES[0] = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_Dim_longueur_x]);
156     dim_VES[1] = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_Dim_longueur_y]);
157     dim_VES[2] = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_Dim_longueur_z]);
158     }
159 francois 756
160 couturad 801 void VE_VES::ecrire_param_VES(char* fichier)
161 francois 756 {
162 couturad 801 param_ver->enregistrer(fichier);
163     }
164 francois 756
165 couturad 801 int VE_VES::generer_VES_homogene(void)
166     {
167     affiche((char*)"Generation VER Homogene :\n");
168     MG_PRIMITIVE_BOITE *cube = new MG_PRIMITIVE_BOITE(0,0,0,dim_VES[0],dim_VES[1],dim_VES[2]);
169     arbre->ajouter_mg_primitive(cube);
170     cube->construit();
171     assemblage->ajouter_mg_primitive(cube);
172     return 0;
173 francois 756 }
174 couturad 801
175     int VE_VES::generer_VES_une_inclusion(void)
176     {
177     affiche((char*)"Generation VER Une Inclusion :\n");
178     MG_PRIMITIVE_BOITE *cube = new MG_PRIMITIVE_BOITE(0,0,0,dim_VES[0],dim_VES[1],dim_VES[2]);
179     arbre->ajouter_mg_primitive(cube);
180     cube->construit();
181    
182     MG_PRIMITIVE *matrice;
183     MG_PRIMITIVE *inclusion;
184     MG_PRIMITIVE *inclusion_outil;
185    
186    
187     int type_inclusion = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Type_INCLUSION]);
188     switch(type_inclusion)
189     {
190     case VE_TYPE_INCLUSION::BOITE:
191     {
192     double xmin,ymin,zmin,xmax,ymax,zmax;
193     double longueur_x,longueur_y,longueur_z;
194     longueur_x = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_longueur_x]);
195     longueur_y = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_longueur_y]);
196     longueur_z = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_longueur_z]);
197     xmin = dim_VES[0]/2.-(longueur_x/2.);
198     ymin = dim_VES[1]/2.-(longueur_y/2.);
199     zmin = dim_VES[2]/2.-(longueur_z/2.);
200     xmax = dim_VES[0]/2.+(longueur_x/2.);
201     ymax = dim_VES[1]/2.+(longueur_y/2.);
202     zmax = dim_VES[2]/2.+(longueur_z/2.);
203     inclusion = new MG_PRIMITIVE_BOITE(xmin,ymin,zmin,xmax,ymax,zmax);
204     inclusion_outil = new MG_PRIMITIVE_BOITE(xmin,ymin,zmin,xmax,ymax,zmax);
205     break;
206     }
207     case VE_TYPE_INCLUSION::SPHERE:
208     {
209     double rayon;
210     rayon = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_rayon]);
211     inclusion = new MG_PRIMITIVE_SPHERE(dim_VES[0]/2.,dim_VES[1]/2.,dim_VES[2]/2.,rayon);
212     inclusion_outil = new MG_PRIMITIVE_SPHERE(dim_VES[0]/2.,dim_VES[1]/2.,dim_VES[2]/2.,rayon);
213     break;
214     }
215     case VE_TYPE_INCLUSION::CYLINDRE:
216     {
217     break;
218     }
219     }
220     arbre->ajouter_mg_primitive(inclusion_outil);
221     arbre->ajouter_mg_primitive(inclusion);
222     inclusion_outil->construit();
223     inclusion->construit();
224     MG_OPERATEUR_BOOLEAN_DIFFERENCE *op_difference=new MG_OPERATEUR_BOOLEAN_DIFFERENCE(MAGIC::SEMANTIQUECSG::SOUSTRACTION,cube,inclusion_outil);
225     matrice=op_difference->construit();
226     arbre->ajouter_mg_operateur_boolean(op_difference);
227     arbre->ajouter_mg_primitive(matrice);
228     assemblage->ajouter_mg_primitive(inclusion);
229     assemblage->ajouter_mg_primitive(matrice);
230     return 0;
231     }
232    
233     int VE_VES::generer_VES_aleatoire(void)
234     {
235 couturad 814 affiche((char*)"Generation VES Aleatoire :\n");
236     MG_PRIMITIVE_BOITE *cube = new MG_PRIMITIVE_BOITE(0,0,0,dim_VES[0],dim_VES[1],dim_VES[2]);
237     arbre->ajouter_mg_primitive(cube);
238     cube->construit();
239     TPL_GRILLE<SPHERE_GRILLE*> grille;
240     double cible_frac_volumique = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_pourcentage_volumique]);
241     long nb_max_inclusion = (long)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_nb_max]);
242     int type_inclusion = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Type_INCLUSION]);
243     double facteur_distance=1.1;
244     switch(type_inclusion)
245     {
246     case VE_TYPE_INCLUSION::BOITE:
247     {
248     double mu_longueur_x = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_longueur_x]);
249     double sigma_longueur_x = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_sigma_longueur_x]);
250     double mu_longueur_y = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_longueur_y]);
251     double sigma_longueur_y = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_sigma_longueur_y]);
252     double mu_longueur_z = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_longueur_z]);
253     double sigma_longueur_z = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_sigma_longueur_z]);
254     std::random_device seed;
255     std::mt19937_64 generateur(seed());
256     std::normal_distribution<double> distribution_longueur_x(mu_longueur_x,sigma_longueur_x);
257     std::normal_distribution<double> distribution_longueur_y(mu_longueur_y,sigma_longueur_y);
258     std::normal_distribution<double> distribution_longueur_z(mu_longueur_z,sigma_longueur_z);
259    
260     std::uniform_real_distribution<double> distribution_position_x(-mu_longueur_x,dim_VES[0]+mu_longueur_x);
261     std::uniform_real_distribution<double> distribution_position_y(-mu_longueur_y,dim_VES[1]+mu_longueur_y);
262     std::uniform_real_distribution<double> distribution_position_z(-mu_longueur_z,dim_VES[2]+mu_longueur_z);
263     double frac_volumique=0;
264     double volume_inclusion=0;
265     long nb_inclusion=0;
266     long it_max=10000;
267     long it=0;
268     double nb_pas_grille;
269     nb_pas_grille = std::max(dim_VES[0]/(mu_longueur_x-3*sigma_longueur_x),dim_VES[1]/(mu_longueur_y-3*sigma_longueur_y));
270     nb_pas_grille = std::max(nb_pas_grille,dim_VES[2]/(mu_longueur_z-3*sigma_longueur_z));
271     grille.initialiser(0,0,0,dim_VES[0],dim_VES[1],dim_VES[2],nb_pas_grille,nb_pas_grille,nb_pas_grille);
272     long id_sphere_grille=0;
273     std::vector<SPHERE_GRILLE*> vector_sphere_grille;
274     MG_PRIMITIVE* matrice_ves = cube;
275     while(frac_volumique< cible_frac_volumique && nb_inclusion<nb_max_inclusion && it<it_max)
276     {
277     double position[3];
278     position[0] = distribution_position_x(generateur);
279     position[1] = distribution_position_y(generateur);
280     position[2] = distribution_position_z(generateur);
281     double longueur[3];
282     longueur[0] = distribution_longueur_x(generateur);
283     longueur[1] = distribution_longueur_y(generateur);
284     longueur[2] = distribution_longueur_z(generateur);
285     double rayon_sphere_grille = sqrt(0.5*longueur[0]*0.5*longueur[0]+0.5*longueur[1]*0.5*longueur[1]+0.5*longueur[2]*0.5*longueur[2]);
286     bool ok_position=true;
287     if((position[0])<0.05) ok_position=false;
288     else if((position[1])<0.05) ok_position=false;
289     else if((position[2])<0.05) ok_position=false;
290     else if((position[0]+longueur[0])>(dim_VES[0]-0.05)) ok_position=false;
291     else if((position[1]+longueur[1])>(dim_VES[1]-0.05)) ok_position=false;
292     else if((position[2]+longueur[2])>(dim_VES[2]-0.05)) ok_position=false;
293     if(ok_position)
294     {
295     double rayon_recherche = rayon_sphere_grille*facteur_distance;
296     TPL_MAP_ENTITE<SPHERE_GRILLE*> map_recherche;
297     grille.rechercher(position[0]+0.5*longueur[0],position[1]+0.5*longueur[1],position[2]+0.5*longueur[2],rayon_recherche,map_recherche);
298     bool ok_insert=true;
299     if(map_recherche.get_nb()>0)
300     {
301     TPL_MAP_ENTITE<SPHERE_GRILLE*>::ITERATEUR it_map_recherche;
302     for(SPHERE_GRILLE* sph = map_recherche.get_premier(it_map_recherche);sph!=NULL;sph=map_recherche.get_suivant(it_map_recherche))
303     {
304     double xyz_sph[3];
305     sph->get_xyz(xyz_sph);
306     if(sqrt((xyz_sph[0]-(position[0]+0.5*longueur[0]))*(xyz_sph[0]-(position[0]+0.5*longueur[0]))+
307     (xyz_sph[1]-(position[1]+0.5*longueur[1]))*(xyz_sph[1]-(position[1]+0.5*longueur[1]))+
308     (xyz_sph[2]-(position[2]+0.5*longueur[2]))*(xyz_sph[2]-(position[2]+0.5*longueur[2])))<(1.1*(sph->get_rayon()+rayon_sphere_grille)))
309     ok_insert=false;
310     }
311     }
312     else if(map_recherche.get_nb()==0) ok_insert=true;
313     if(ok_insert)
314     {
315     MG_PRIMITIVE_BOITE *boite = new MG_PRIMITIVE_BOITE(position[0],position[1],position[2],position[0]+longueur[0],position[1]+longueur[1],position[2]+longueur[2]);
316     boite->construit();
317     MG_PRIMITIVE_BOITE *boite_outil = new MG_PRIMITIVE_BOITE(position[0],position[1],position[2],position[0]+longueur[0],position[1]+longueur[1],position[2]+longueur[2]);
318     boite_outil->construit();
319     if(((position[0] > 0.0) && ((position[0]+longueur[0]) < dim_VES[0])) &&
320     ((position[1] > 0.0) && ((position[1]+longueur[1]) < dim_VES[1])) &&
321     ((position[2] > 0.0) && ((position[2]+longueur[2]) < dim_VES[0])))
322     {
323     char message[1000];
324     sprintf(message,"Inclusion #%li",id_sphere_grille);
325     affiche(message);
326     nb_inclusion++;
327     arbre->ajouter_mg_primitive(boite);
328     arbre->ajouter_mg_primitive(boite_outil);
329     MG_OPERATEUR_BOOLEAN_DIFFERENCE *op_difference=new MG_OPERATEUR_BOOLEAN_DIFFERENCE(MAGIC::SEMANTIQUECSG::SANS,matrice_ves,boite_outil);
330     matrice_ves=op_difference->construit();
331     arbre->ajouter_mg_operateur_boolean(op_difference);
332     assemblage->ajouter_mg_primitive(boite);
333     volume_inclusion+=boite->get_volume();
334     SPHERE_GRILLE *sp = new SPHERE_GRILLE(position[0]+0.5*longueur[0],position[1]+0.5*longueur[1],position[2]+0.5*longueur[2],rayon_sphere_grille,id_sphere_grille);
335     vector_sphere_grille.push_back(sp);
336     grille.inserer(sp);
337     id_sphere_grille++;
338     it=0;
339     }
340     else
341     {
342    
343     MG_PRIMITIVE_BOITE *cube_inter = new MG_PRIMITIVE_BOITE(0,0,0,dim_VES[0],dim_VES[1],dim_VES[2]);
344     cube_inter->construit();
345     MG_OPERATEUR_BOOLEAN_INTERSECTION *op_intersection = new MG_OPERATEUR_BOOLEAN_INTERSECTION(MAGIC::SEMANTIQUECSG::SANS,boite,cube_inter);
346     //MG_OPERATEUR_BOOLEAN_INTERSECTION *op_intersection = new MG_OPERATEUR_BOOLEAN_INTERSECTION(MAGIC::SEMANTIQUECSG::SANS,cube_inter,boite);
347     MG_PRIMITIVE *boite_inter = op_intersection->construit();
348     if(boite_inter->get_volume()> 0.25*(boite->get_volume()))
349     {
350     volume_inclusion+=boite_inter->get_volume();
351     char message[1000];
352     sprintf(message,"Inclusion #%li : COUPÉE",id_sphere_grille);
353     affiche(message);
354     nb_inclusion++;
355     MG_OPERATEUR_BOOLEAN_DIFFERENCE *op_difference=new MG_OPERATEUR_BOOLEAN_DIFFERENCE(MAGIC::SEMANTIQUECSG::SANS,matrice_ves,boite_outil);
356     matrice_ves=op_difference->construit();
357     arbre->ajouter_mg_primitive(boite);
358     arbre->ajouter_mg_primitive(boite_outil);
359     arbre->ajouter_mg_operateur_boolean(op_difference);
360     arbre->ajouter_mg_primitive(boite_inter);
361     arbre->ajouter_mg_primitive(cube_inter);
362     assemblage->ajouter_mg_primitive(boite_inter);
363     SPHERE_GRILLE *sp = new SPHERE_GRILLE(position[0]+0.5*longueur[0],position[1]+0.5*longueur[1],position[2]+0.5*longueur[2],rayon_sphere_grille,id_sphere_grille);
364     vector_sphere_grille.push_back(sp);
365     grille.inserer(sp);
366     id_sphere_grille++;
367     it=0;
368     }
369     else
370     {
371     delete boite;
372     delete boite_outil;
373     delete boite_inter;
374     delete cube_inter;
375     delete op_intersection;
376     }
377     }
378     frac_volumique = volume_inclusion/(cube->get_volume());
379     }
380     it++;
381     }
382     }
383     arbre->ajouter_mg_primitive(matrice_ves);
384     assemblage->ajouter_mg_primitive(matrice_ves);
385     char message[1000];
386     sprintf(message,"echo -n %li:%lf: >> resultats.txt",nb_inclusion,frac_volumique);
387     system(message);
388     break;
389     }
390     }
391     return 0;
392 couturad 801 }
393    
394     int VE_VES::evaluer_geometrie(void)
395     {
396     char nom_fichier[1000];
397     sprintf(nom_fichier,"%s",param_ver->get_nom(VE_PARAM_CHAR[VE_PARAM::VE_IO_nom_fichier_STEP_BREP]).c_str());
398     bool export_STEP, avec_fusion,import_STL;
399     export_STEP = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_IO_Bool_export_STEP]);
400     avec_fusion = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_IO_Bool_fusion]);
401     import_STL = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_IO_Bool_import_STL]);
402     double precision,eps;
403     precision = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_Dim_precision]);
404     eps = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_IO_STL_eps]);
405     arbre->evaluer_geometrie(assemblage,nom_fichier,avec_fusion,export_STEP,import_STL,precision,eps);
406     return 0;
407     }
408    
409     int VE_VES::creer_mg_maillage(void)
410     {
411     affiche((char*)"Maillage du VER :");
412     MG_GEOMETRIE *geo = gest->get_mg_geometrie(0);
413     MG_MAILLAGE *maillage = new MG_MAILLAGE(geo);
414     gest->ajouter_mg_maillage(maillage);
415     MAILLEUR0D m0d(maillage,geo);
416     affiche((char*)" Maillage 0D :");
417     m0d.maille();
418     MAILLEUR1D m1d(maillage,geo,metrique);
419     affiche((char*)" Maillage 1D :");
420     //m1d.active_affichage(fonc_affiche);
421     m1d.maille();
422     MAILLEUR2D m2d(maillage,geo,metrique);
423     affiche((char*)" Maillage 2D :");
424     //m2d.active_affichage(fonc_affiche);
425     m2d.maille();
426     MAILLEUR3D m3d(maillage,geo,metrique,false);
427     affiche((char*)" Maillage 3D :");
428     m3d.active_affichage(fonc_affiche);
429     m3d.maille();
430     return 0;
431     }
432    
433     int VE_VES::creer_carte(void)
434     {
435     int type_carte = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_CARTE_Type]);
436     switch(type_carte)
437     {
438     case VE_TYPE_CARTE::CONSTANTE:
439     {
440     affiche((char*)"Generation de carte de taille constante V1");
441     double ecart_nodal = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_CARTE_Dim_ecart_nodal]);
442     double fechantillonnage = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_CARTE_Dim_fechantillonnage]);
443     double festimation = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_CARTE_Dim_festimation]);
444     FCT_GENERATEUR_CONSTANTE *carte = new FCT_GENERATEUR_CONSTANTE(*gest,ecart_nodal);
445     affiche((char*)"Construction de la carte");
446     carte->construit(fechantillonnage,festimation);
447     affiche((char*)"Enregistrement de la carte");
448     char nom_fichier[1000];
449     sprintf(nom_fichier,"%s",param_ver->get_nom(VE_PARAM_CHAR[VE_PARAM::VE_IO_nom_fichier_CARTE]).c_str());
450     carte->enregistrer(nom_fichier);
451     metrique = carte;
452     affiche((char*)"Fin");
453     break;
454     }
455     }
456     return 0;
457     }
458    
459     int VE_VES::appliquer_conditions_limites_plan(TPL_MAP_ENTITE< MG_FACE* >* plan, char* condition, double valeur,bool topo_sous_jacente)
460     {
461     TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face_plan;
462     for(MG_FACE *face = plan->get_premier(it_face_plan);face!=NULL;face=plan->get_suivant(it_face_plan))
463     {
464     face->ajouter_ccf(condition,valeur);
465     if(topo_sous_jacente==true)
466     {
467     TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> map_topo;
468     face->get_topologie_sousjacente(&map_topo);
469     TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*>::ITERATEUR it_topo;
470     for(MG_ELEMENT_TOPOLOGIQUE *topo=map_topo.get_premier(it_topo);topo!=NULL;topo=map_topo.get_suivant(it_topo))
471     {
472     topo->ajouter_ccf(condition,valeur);
473     }
474     }
475     }
476 francois 1075 return 0;
477    
478 couturad 801 }
479    
480     int VE_VES::appliquer_conditions_limites_plan(TPL_MAP_ENTITE< MG_FACE* >* plan, char* condition, std::string formule,std::vector<std::string> &listvariable,bool topo_sous_jacente)
481     {
482     TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face_plan;
483     for(MG_FACE *face = plan->get_premier(it_face_plan);face!=NULL;face=plan->get_suivant(it_face_plan))
484     {
485     face->ajouter_ccf(condition,formule,listvariable);
486     if(topo_sous_jacente==true)
487     {
488     TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> map_topo;
489     face->get_topologie_sousjacente(&map_topo);
490     TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*>::ITERATEUR it_topo;
491     for(MG_ELEMENT_TOPOLOGIQUE *topo=map_topo.get_premier(it_topo);topo!=NULL;topo=map_topo.get_suivant(it_topo))
492     {
493     topo->ajouter_ccf(condition,formule,listvariable);
494     }
495     }
496     }
497 francois 1075 return 0;
498    
499 couturad 801 }
500    
501     int VE_VES::appliquer_conditions_limites(int type_chargement)
502     {
503     TPL_MAP_ENTITE<MG_FACE*> plan_xy_z0;
504     TPL_MAP_ENTITE<MG_FACE*> plan_xy_z1;
505     TPL_MAP_ENTITE<MG_FACE*> plan_yz_x0;
506     TPL_MAP_ENTITE<MG_FACE*> plan_yz_x1;
507     TPL_MAP_ENTITE<MG_FACE*> plan_xz_y0;
508     TPL_MAP_ENTITE<MG_FACE*> plan_xz_y1;
509     MG_SOMMET* sommet_origine;
510     MG_SOMMET* sommet_x1y0z0;
511     MG_SOMMET* sommet_x0y1z0;
512     MG_SOMMET* sommet_x0y0z1;
513     double eps = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_Dim_precision]);
514    
515     MG_GEOMETRIE *geo = gest->get_mg_geometrie(0);
516     std::map<unsigned long,MG_FACE*,std::less<unsigned long>>::iterator it_face;
517     for(MG_FACE *face = geo->get_premier_face(it_face);face!=NULL;face=geo->get_suivant_face(it_face))
518     {
519     TPL_SET<MG_ELEMENT_MAILLAGE*> *liste_element_maillage = face->get_lien_maillage();
520     MG_TRIANGLE *tri = (MG_TRIANGLE*)liste_element_maillage->get(0);
521     MG_NOEUD *nd[3];
522     nd[0] = tri->get_noeud1();
523     nd[1] = tri->get_noeud2();
524     nd[2] = tri->get_noeud3();
525    
526     if(OPERATEUR::egal(nd[0]->get_z(),0,eps) && OPERATEUR::egal(nd[1]->get_z(),0,eps) && OPERATEUR::egal(nd[2]->get_z(),0,eps))
527     {
528     plan_xy_z0.ajouter(face);
529     }
530     else if(OPERATEUR::egal(nd[0]->get_z(),dim_VES[2],eps) && OPERATEUR::egal(nd[1]->get_z(),dim_VES[2],eps) && OPERATEUR::egal(nd[2]->get_z(),dim_VES[2],eps))
531     {
532     plan_xy_z1.ajouter(face);
533     }
534     else if(OPERATEUR::egal(nd[0]->get_x(),0,eps) && OPERATEUR::egal(nd[1]->get_x(),0,eps) && OPERATEUR::egal(nd[2]->get_x(),0,eps))
535     {
536     plan_yz_x0.ajouter(face);
537     }
538     else if(OPERATEUR::egal(nd[0]->get_x(),dim_VES[0],eps) && OPERATEUR::egal(nd[1]->get_x(),dim_VES[0],eps) && OPERATEUR::egal(nd[2]->get_x(),dim_VES[0],eps))
539     {
540     plan_yz_x1.ajouter(face);
541     }
542     else if(OPERATEUR::egal(nd[0]->get_y(),0,eps) && OPERATEUR::egal(nd[1]->get_y(),0,eps) && OPERATEUR::egal(nd[2]->get_y(),0,eps))
543     {
544     plan_xz_y0.ajouter(face);
545     }
546     else if(OPERATEUR::egal(nd[0]->get_y(),dim_VES[1],eps) && OPERATEUR::egal(nd[1]->get_y(),dim_VES[1],eps) && OPERATEUR::egal(nd[2]->get_y(),dim_VES[1],eps))
547     {
548     plan_xz_y1.ajouter(face);
549     }
550     }
551    
552     std::map<unsigned long,MG_SOMMET*,std::less<unsigned long>>::iterator it_sommet;
553     for(MG_SOMMET* som=geo->get_premier_sommet(it_sommet);som!=NULL;som=geo->get_suivant_sommet(it_sommet))
554     {
555     TPL_SET<MG_ELEMENT_MAILLAGE*> *liste_element_maillage = som->get_lien_maillage();
556     MG_NOEUD* nd = (MG_NOEUD*)liste_element_maillage->get(0);
557     if(OPERATEUR::egal(nd->get_x(),0,eps) && OPERATEUR::egal(nd->get_y(),0,eps) && OPERATEUR::egal(nd->get_z(),0,eps))
558     {
559     sommet_origine=som;
560     }
561     else if(OPERATEUR::egal(nd->get_x(),dim_VES[0],eps) && OPERATEUR::egal(nd->get_y(),0,eps) && OPERATEUR::egal(nd->get_z(),0,eps))
562     {
563     sommet_x1y0z0=som;
564     }
565     else if(OPERATEUR::egal(nd->get_x(),0,eps) && OPERATEUR::egal(nd->get_y(),dim_VES[1],eps) && OPERATEUR::egal(nd->get_z(),0,eps))
566     {
567     sommet_x0y1z0=som;
568     }
569     else if(OPERATEUR::egal(nd->get_x(),0,eps) && OPERATEUR::egal(nd->get_y(),0,eps) && OPERATEUR::egal(nd->get_z(),dim_VES[2],eps))
570     {
571     sommet_x0y0z1=som;
572     }
573     }
574    
575     int type_cl = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_CL_Type]);
576     double valeur_cl = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_CL_Dim_valeur]);
577    
578     switch(type_chargement)
579     {
580     case VE_TYPE_CHARGEMENT::SPHERIQUE:
581     {
582     switch(type_cl)
583     {
584     case VE_TYPE_CL::DEFORMATION_HOMOGENE:
585     {
586     appliquer_conditions_limites_plan(&plan_xy_z0,(char*)"Dz",0.0,true);
587     appliquer_conditions_limites_plan(&plan_xy_z1,(char*)"Dz",valeur_cl,true);
588     appliquer_conditions_limites_plan(&plan_yz_x0,(char*)"Dx",0.0,true);
589     appliquer_conditions_limites_plan(&plan_yz_x1,(char*)"Dx",valeur_cl,true);
590     appliquer_conditions_limites_plan(&plan_xz_y0,(char*)"Dy",0.0,true);
591     appliquer_conditions_limites_plan(&plan_xz_y1,(char*)"Dy",valeur_cl,true);
592     break;
593     }
594     case VE_TYPE_CL::CONTRAINTE_HOMOGENE:
595     {
596     appliquer_conditions_limites_plan(&plan_xy_z0,(char*)"Dz",0.0,true);
597     appliquer_conditions_limites_plan(&plan_xy_z1,(char*)"Pz",valeur_cl,false);
598     appliquer_conditions_limites_plan(&plan_yz_x0,(char*)"Dx",0.0,true);
599     appliquer_conditions_limites_plan(&plan_yz_x1,(char*)"Px",valeur_cl,false);
600     appliquer_conditions_limites_plan(&plan_xz_y0,(char*)"Dy",0.0,true);
601     appliquer_conditions_limites_plan(&plan_xz_y1,(char*)"Py",valeur_cl,false);
602     break;
603     }
604     case VE_TYPE_CL::FLUX_CHALEUR_HOMOGENE:
605     {
606     break;
607     }
608     case VE_TYPE_CL::GRADIENT_TEMPERATURE_HOMOGENE:
609     {
610     break;
611     }
612     }
613     break;
614     }
615    
616     case VE_TYPE_CHARGEMENT::DEVIATORIQUE:
617     {
618     switch(type_cl)
619     {
620     case VE_TYPE_CL::DEFORMATION_HOMOGENE:
621     {
622     char chr_valeur_cl[1000];
623     sprintf(chr_valeur_cl,"%lf",valeur_cl);
624     std::string str_valeur_cl = chr_valeur_cl;
625     std::string formule_Dx = str_valeur_cl+ "*Y";
626     std::string formule_Dy = str_valeur_cl+ "*Z";
627     std::string formule_Dz = str_valeur_cl+ "*X";
628     std::vector<std::string> liste_variable_formule_Dx;
629     std::vector<std::string> liste_variable_formule_Dy;
630     std::vector<std::string> liste_variable_formule_Dz;
631     liste_variable_formule_Dx.push_back((std::string)"Y");
632     liste_variable_formule_Dy.push_back((std::string)"Z");
633     liste_variable_formule_Dz.push_back((std::string)"X");
634     appliquer_conditions_limites_plan(&plan_xy_z0,(char*)"Dx",formule_Dx,liste_variable_formule_Dx,true);
635     appliquer_conditions_limites_plan(&plan_xy_z0,(char*)"Dy",formule_Dy,liste_variable_formule_Dy,true);
636     appliquer_conditions_limites_plan(&plan_xy_z0,(char*)"Dz",formule_Dz,liste_variable_formule_Dz,true);
637     appliquer_conditions_limites_plan(&plan_xy_z1,(char*)"Dx",formule_Dx,liste_variable_formule_Dx,true);
638     appliquer_conditions_limites_plan(&plan_xy_z1,(char*)"Dy",formule_Dy,liste_variable_formule_Dy,true);
639     appliquer_conditions_limites_plan(&plan_xy_z1,(char*)"Dz",formule_Dz,liste_variable_formule_Dz,true);
640     appliquer_conditions_limites_plan(&plan_yz_x0,(char*)"Dx",formule_Dx,liste_variable_formule_Dx,true);
641     appliquer_conditions_limites_plan(&plan_yz_x0,(char*)"Dy",formule_Dy,liste_variable_formule_Dy,true);
642     appliquer_conditions_limites_plan(&plan_yz_x0,(char*)"Dz",formule_Dz,liste_variable_formule_Dz,true);
643     appliquer_conditions_limites_plan(&plan_yz_x1,(char*)"Dx",formule_Dx,liste_variable_formule_Dx,true);
644     appliquer_conditions_limites_plan(&plan_yz_x1,(char*)"Dy",formule_Dy,liste_variable_formule_Dy,true);
645     appliquer_conditions_limites_plan(&plan_yz_x1,(char*)"Dz",formule_Dz,liste_variable_formule_Dz,true);
646     appliquer_conditions_limites_plan(&plan_xz_y0,(char*)"Dx",formule_Dx,liste_variable_formule_Dx,true);
647     appliquer_conditions_limites_plan(&plan_xz_y0,(char*)"Dy",formule_Dy,liste_variable_formule_Dy,true);
648     appliquer_conditions_limites_plan(&plan_xz_y0,(char*)"Dz",formule_Dz,liste_variable_formule_Dz,true);
649     appliquer_conditions_limites_plan(&plan_xz_y1,(char*)"Dx",formule_Dx,liste_variable_formule_Dx,true);
650     appliquer_conditions_limites_plan(&plan_xz_y1,(char*)"Dy",formule_Dy,liste_variable_formule_Dy,true);
651     appliquer_conditions_limites_plan(&plan_xz_y1,(char*)"Dz",formule_Dz,liste_variable_formule_Dz,true);
652     break;
653     }
654    
655     case VE_TYPE_CL::CONTRAINTE_HOMOGENE:
656     {
657     sommet_origine->ajouter_ccf((char*)"Dt",0.0);
658     sommet_x1y0z0->ajouter_ccf((char*)"Dy",0.0);
659     sommet_x1y0z0->ajouter_ccf((char*)"Dz",0.0);
660     sommet_x0y1z0->ajouter_ccf((char*)"Dz",0.0);
661     appliquer_conditions_limites_plan(&plan_xy_z0,(char*)"Px",-valeur_cl,true);
662     appliquer_conditions_limites_plan(&plan_xy_z0,(char*)"Py",-valeur_cl,true);
663     appliquer_conditions_limites_plan(&plan_xy_z1,(char*)"Px",valeur_cl,true);
664     appliquer_conditions_limites_plan(&plan_xy_z1,(char*)"Py",valeur_cl,true);
665     appliquer_conditions_limites_plan(&plan_xz_y0,(char*)"Px",-valeur_cl,true);
666     appliquer_conditions_limites_plan(&plan_xz_y0,(char*)"Pz",-valeur_cl,true);
667     appliquer_conditions_limites_plan(&plan_xz_y1,(char*)"Px",valeur_cl,true);
668     appliquer_conditions_limites_plan(&plan_xz_y1,(char*)"Pz",valeur_cl,true);
669     appliquer_conditions_limites_plan(&plan_yz_x0,(char*)"Py",-valeur_cl,true);
670     appliquer_conditions_limites_plan(&plan_yz_x0,(char*)"Pz",-valeur_cl,true);
671     appliquer_conditions_limites_plan(&plan_yz_x1,(char*)"Py",valeur_cl,true);
672     appliquer_conditions_limites_plan(&plan_yz_x1,(char*)"Pz",valeur_cl,true);
673     break;
674     }
675     case VE_TYPE_CL::FLUX_CHALEUR_HOMOGENE:
676     {
677     break;
678     }
679     case VE_TYPE_CL::GRADIENT_TEMPERATURE_HOMOGENE:
680     {
681     break;
682     }
683     }
684     break;
685     }
686     }
687     return 0;
688     }
689    
690     int VE_VES::appliquer_materiaux(void)
691     {
692     double nu_inclu = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_nu]);
693     double nu_matrice = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_MATRICE_Dim_mu_nu]);
694     double Em_inclu = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_INCLU_Dim_mu_Em]);
695     double Em_matrice = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_MATRICE_Dim_mu_Em]);
696     MG_GEOMETRIE *geo = gest->get_mg_geometrie(0);
697     MG_VOLUME *matrice = geo->get_mg_volume(geo->get_nb_mg_volume()-1);
698     std::map<unsigned long,MG_VOLUME*,std::less<unsigned long>>::iterator it_volume;
699     for(MG_VOLUME *volume = geo->get_premier_volume(it_volume);volume!=matrice;volume=geo->get_suivant_volume(it_volume))
700     {
701     volume->ajouter_ccf((char*)"nu",nu_inclu);
702     volume->ajouter_ccf((char*)"Em",Em_inclu);
703     }
704     matrice->ajouter_ccf((char*)"nu",nu_matrice);
705     matrice->ajouter_ccf((char*)"Em",Em_matrice);
706     return 0;
707     }
708    
709     int VE_VES::creer_fem_maillage(void)
710     {
711     MG_GEOMETRIE *geo = gest->get_mg_geometrie(0);
712     MG_MAILLAGE *mai = gest->get_mg_maillage(gest->get_nb_mg_maillage()-1);
713     int degre_mail = (int)param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_MAIL_Dim_degre_maillage]);
714     FEM_MAILLAGE *fem = new FEM_MAILLAGE(geo,mai,degre_mail);
715     gest->ajouter_fem_maillage(fem);
716 francois 883 MAILLEUR_FEM m;
717     m.maille(fem);
718 couturad 801 return 0;
719     }
720    
721     int VE_VES::calcul_aster(void)
722     {
723     char coderesu[500];
724     char nomparam[500];
725     char nometude[500];
726     sprintf(nometude,"%s",param_ver->get_nom(VE_PARAM_CHAR[VE_PARAM::VE_IO_nom_fichier_ETUDE]).c_str());
727     sprintf(nomparam,"%s",param_ver->get_nom(VE_PARAM_CHAR[VE_PARAM::VE_IO_nom_fichier_param_ASTER]).c_str());
728     sprintf(coderesu,"%s",param_ver->get_nom(VE_PARAM_CHAR[VE_PARAM::VE_IO_code_resu]).c_str());
729     MGASTER mgaster;
730     mgaster.active_affichage(fonc_affiche);
731     mgaster.calcule(nomparam,gest->get_fem_maillage(0),nometude,MAGIC::CALCUL_ASTER::ELASTIQUE,coderesu);
732 francois 1075 return 0;
733 couturad 801 }
734    
735     int VE_VES::homogeneisation(void)
736     {
737     FEM_SOLUTION* sol=gest->get_fem_solution(1);
738     FEM_SOLUTION* sol2=gest->get_fem_solution(2);
739     double exx=sol->get_moyenne_volumique_champs(NULL,0);
740     double eyy=sol->get_moyenne_volumique_champs(NULL,1);
741     double ezz=sol->get_moyenne_volumique_champs(NULL,2);
742     double exy=sol->get_moyenne_volumique_champs(NULL,3);
743     double exz=sol->get_moyenne_volumique_champs(NULL,4);
744     double eyz=sol->get_moyenne_volumique_champs(NULL,5);
745     double sxx=sol2->get_moyenne_volumique_champs(NULL,0);
746     double syy=sol2->get_moyenne_volumique_champs(NULL,1);
747     double szz=sol2->get_moyenne_volumique_champs(NULL,2);
748     double sxy=sol2->get_moyenne_volumique_champs(NULL,3);
749     double sxz=sol2->get_moyenne_volumique_champs(NULL,4);
750     double syz=sol2->get_moyenne_volumique_champs(NULL,5);
751     double traces=sxx+syy+szz;
752     double tracee=exx+eyy+ezz;
753     char message[1000];
754     affiche((char*)"");
755     sprintf(message, "Tenseur des deformations :"); affiche(message);
756     sprintf(message, " | exx=% 3.2le exy=% 3.2le exz=% 3.2le |",exx,exy,exz); affiche(message);
757     sprintf(message, " | exy=% 3.2le eyy=% 3.2le eyz=% 3.2le |",exy,eyy,eyz); affiche(message);
758     sprintf(message, " | exz=% 3.2le eyz=% 3.2le ezz=% 3.2le |",exz,eyz,ezz); affiche(message);
759     affiche((char*)"");
760     sprintf(message, " Trace e = % 3.2le",tracee); affiche(message);
761     affiche((char*)"");
762     sprintf(message, "Tenseur des contraintes :"); affiche(message);
763     sprintf(message, " | sxx=% 3.2le sxy=% 3.2le sxz=% 3.2le |",sxx,sxy,sxz); affiche(message);
764     sprintf(message, " | sxy=% 3.2le syy=% 3.2le syz=% 3.2le |",sxy,syy,syz); affiche(message);
765     sprintf(message, " | sxz=% 3.2le syz=% 3.2le szz=% 3.2le |",sxz,syz,szz); affiche(message);
766     affiche((char*)"");
767     sprintf(message, " Trace s = % 3.2le",traces); affiche(message);
768     affiche((char*)"");
769     int type_chargement = param_ver->get_valeur(VE_PARAM_CHAR[VE_PARAM::VE_VER_CL_CHARGEMENT_type]);
770     if(type_chargement==VE_TYPE_CHARGEMENT::SPHERIQUE)
771     {
772     double K = traces/3./tracee;
773     sprintf(message, "Module de compressibilite apparent :"); affiche(message);
774     sprintf(message, " Kapp = % 3.5le",K); affiche(message);
775 couturad 814 char messagesortie[1000];
776     sprintf(messagesortie,"echo %lf >> resultats.txt",K);
777     system(messagesortie);
778 couturad 801 }
779     else if(type_chargement==VE_TYPE_CHARGEMENT::DEVIATORIQUE)
780     {
781     double G = (1./3.)*((syz/(2.*eyz))+(sxz/(2.*exz))+(sxy/(2.*exy)));
782     sprintf(message, "Module de cisaillement apparent :"); affiche(message);
783     sprintf(message, " Gapp = % 3.5le",G); affiche(message);
784 couturad 814 char messagesortie[1000];
785     sprintf(messagesortie,"echo %lf >> resultats.txt",G);
786     system(messagesortie);
787 couturad 801 }
788 francois 1075 return 0;
789 couturad 801 }