1 |
francois |
239 |
#include "gestionversion.h" |
2 |
|
|
#include "mgopt.h" |
3 |
|
|
#include "mg_file.h" |
4 |
|
|
#include "fct_generateur_frontiere.h" |
5 |
|
|
#include "fct_generateur_constante.h" |
6 |
|
|
#include "fct_generateur_fichier.h" |
7 |
francois |
468 |
#include "fct_taille_fem_solution.h" |
8 |
francois |
239 |
#include "mailleur_bloc.h" |
9 |
francois |
243 |
#include "mg_export.h" |
10 |
francois |
239 |
#include <string.h> |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
francois |
494 |
MGOPT::MGOPT(bool save):gestd(NULL),gestnd(NULL),carte(NULL),savedbg(save) |
24 |
francois |
239 |
{ |
25 |
francois |
494 |
strcpy(nomfichierdbg,"mailleurautomatiqueoptimisation.magicdbg"); |
26 |
francois |
396 |
params.ajouter("maille",0.,OT_PARAMETRES::DOUBLE,"0. le maillage est effectue ou numero de maillage a utiliser" ); |
27 |
|
|
params.ajouter("dg",7.,OT_PARAMETRES::DOUBLE,"Ecart nodal constant de la carte de taille"); |
28 |
francois |
468 |
params.ajouter("typecarte",1.,OT_PARAMETRES::DOUBLE,"0. calcul d'une nouvelle carte de taille 1. utilisation d'une carte existante 2. calcul d'une nouvelle carte de taille (nouvelle version) 3. utilisation d'une carte existante (nouvelle version)"); |
29 |
francois |
396 |
params.ajouter("fechantillonnage",20.,OT_PARAMETRES::DOUBLE,"Nombre de cellules de la carte de taille dans une direction"); |
30 |
|
|
params.ajouter("festimation",1.,OT_PARAMETRES::DOUBLE,"nombre d'échantillons dans une direction"); |
31 |
|
|
params.ajouter("fichiercarte","bielle.ctt",OT_PARAMETRES::STRING,"Fichier carte de taille a utiliser quand typecarte vaut 1."); |
32 |
|
|
params.ajouter("degre",1.,OT_PARAMETRES::DOUBLE,"1. maillage lineaire 2. maillage quadratique"); |
33 |
|
|
params.ajouter("enregistrementsimple",0.,OT_PARAMETRES::DOUBLE,"1. Enregistrement dans un format simplifie"); |
34 |
francois |
239 |
} |
35 |
|
|
|
36 |
francois |
494 |
MGOPT::MGOPT(MGOPT &mdd):savedbg(mdd.savedbg) |
37 |
francois |
239 |
{ |
38 |
francois |
494 |
strcpy(nomfichierdbg,mdd.nomfichierdbg); |
39 |
francois |
239 |
params=mdd.params; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
MGOPT::~MGOPT() |
44 |
|
|
{ |
45 |
|
|
if (gestd!=NULL) delete gestd; |
46 |
|
|
if (gestd!=NULL) delete gestnd; |
47 |
|
|
if (carte!=NULL) delete carte; |
48 |
|
|
} |
49 |
|
|
|
50 |
francois |
493 |
|
51 |
|
|
void MGOPT::affiche(char *mess) |
52 |
|
|
{ |
53 |
|
|
if (affichageactif==1) affiche_ptr(mess); |
54 |
|
|
} |
55 |
|
|
|
56 |
francois |
239 |
void MGOPT::active_affichage(void (*fonc)(char*)) |
57 |
|
|
{ |
58 |
francois |
493 |
affiche_ptr=fonc; |
59 |
francois |
239 |
affichageactif=1; |
60 |
|
|
} |
61 |
|
|
void MGOPT::lire_params(char *fichier) |
62 |
|
|
{ |
63 |
|
|
params.vide(); |
64 |
|
|
params.lire(fichier); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
void MGOPT::optimise(char *fichier) |
68 |
|
|
{ |
69 |
francois |
272 |
affiche((char*)""); |
70 |
|
|
affiche((char*)"*************************"); |
71 |
|
|
affiche((char*)"Optimisation de topologie"); |
72 |
|
|
affiche((char*)"*************************"); |
73 |
|
|
affiche((char*)""); |
74 |
|
|
affiche((char*)""); |
75 |
|
|
affiche((char*)""); |
76 |
|
|
affiche((char*)"Écriture d'un fichier de parametres par défaut"); |
77 |
francois |
239 |
params.enregistrer(fichier); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
void MGOPT::optimise(char *nomgestd,char *nomgestnd,char *nomsortie,char *nomparam) |
81 |
|
|
{ |
82 |
francois |
272 |
affiche((char*)""); |
83 |
|
|
affiche((char*)"*************************"); |
84 |
|
|
affiche((char*)"Optimisation de topologie"); |
85 |
|
|
affiche((char*)"*************************"); |
86 |
|
|
affiche((char*)""); |
87 |
|
|
affiche((char*)""); |
88 |
|
|
affiche((char*)""); |
89 |
francois |
271 |
time_t heuredeb = time(NULL); |
90 |
|
|
tdebut = *localtime(&heuredeb); |
91 |
francois |
239 |
if (nomparam!=NULL) lire_params(nomparam); |
92 |
|
|
char *p=strchr(nomgestd,'.'); |
93 |
|
|
strncpy(nometude,nomgestd,p-nomgestd); |
94 |
|
|
nometude[p-nomgestd]=0; |
95 |
francois |
243 |
p=strchr(nomsortie,'.'); |
96 |
|
|
strncpy(nometudesortie,nomsortie,p-nomsortie); |
97 |
|
|
nometudesortie[p-nomsortie]=0; |
98 |
francois |
272 |
affiche((char*)"Preparation du modèle"); |
99 |
francois |
239 |
gestd=new MG_FILE(nomgestd); |
100 |
|
|
gestnd=new MG_FILE(nomgestnd); |
101 |
|
|
unsigned long maille=(unsigned long)params.get_valeur("maille"); |
102 |
|
|
FEM_MAILLAGE* fem; |
103 |
|
|
if (maille==0) fem=prepare_model(gestd,gestnd); |
104 |
|
|
else fem=gestd->get_fem_maillageid(maille); |
105 |
francois |
272 |
affiche((char*)"Debut optimisation"); |
106 |
francois |
239 |
optimisation(fem); |
107 |
francois |
272 |
affiche((char*)"Enregistrement resultat"); |
108 |
francois |
239 |
gestd->enregistrer(nomsortie); |
109 |
francois |
384 |
int sauvesimple=params.get_valeur("enregistrementsimple"); |
110 |
|
|
if (sauvesimple==1) |
111 |
|
|
{ |
112 |
|
|
affiche((char*)"Enregistrement resultat simplifie"); |
113 |
|
|
char nomfichier[500]; |
114 |
|
|
sprintf(nomfichier,"%s.opt",nometudesortie); |
115 |
|
|
enregistre_simple(nomfichier,fem); |
116 |
|
|
} |
117 |
francois |
272 |
affiche((char*)"Enregistrement resultat sous GMSH"); |
118 |
francois |
243 |
MG_EXPORT exp; |
119 |
|
|
char nomfichier[500]; |
120 |
|
|
sprintf(nomfichier,"%s_mg",nometudesortie); |
121 |
|
|
exp.gmsh(fem->get_mg_maillage(),nomfichier); |
122 |
|
|
sprintf(nomfichier,"%s_fem",nometudesortie); |
123 |
|
|
exp.gmsh(fem,nomfichier); |
124 |
francois |
239 |
} |
125 |
|
|
|
126 |
|
|
FEM_MAILLAGE* MGOPT::prepare_model(MG_GESTIONNAIRE *gestd,MG_GESTIONNAIRE *gestnd) |
127 |
|
|
{ |
128 |
francois |
272 |
affiche((char*)"Carte de taille"); |
129 |
francois |
239 |
int typecarte=(int)params.get_valeur("typecarte"); |
130 |
|
|
if (typecarte==0) |
131 |
|
|
{ |
132 |
francois |
272 |
affiche((char*)" Calcul"); |
133 |
francois |
239 |
double eng=params.get_valeur("dg"); |
134 |
|
|
int fechan=(int)params.get_valeur("fechantillonnage"); |
135 |
|
|
int festim=(int)params.get_valeur("festimation"); |
136 |
|
|
carte=new FCT_GENERATEUR_CONSTANTE(*gestd,eng); |
137 |
francois |
468 |
FCT_GENERATEUR_CONSTANTE *carte2=(FCT_GENERATEUR_CONSTANTE*)carte; |
138 |
francois |
239 |
carte2->construit(fechan,festim); |
139 |
francois |
468 |
char nomfichiersortie[300]; |
140 |
francois |
239 |
sprintf(nomfichiersortie,"%s.ctt",nometude); |
141 |
|
|
carte2->enregistrer(nomfichiersortie); |
142 |
|
|
} |
143 |
francois |
468 |
else if (typecarte==1) |
144 |
francois |
239 |
{ |
145 |
francois |
272 |
affiche((char*)" Lecture"); |
146 |
francois |
239 |
carte=new FCT_GENERATEUR_3D<4>; |
147 |
|
|
std::string fichiercarte=params.get_nom("fichiercarte"); |
148 |
|
|
carte->lire((char *)fichiercarte.c_str()); |
149 |
|
|
} |
150 |
francois |
468 |
else if (typecarte==3) |
151 |
|
|
{ |
152 |
|
|
|
153 |
|
|
} |
154 |
|
|
else if (typecarte==4) |
155 |
|
|
{ |
156 |
|
|
affiche((char*)" Lecture"); |
157 |
|
|
std::string fichiercarte=params.get_nom("fichiercarte"); |
158 |
|
|
carte=new FCT_TAILLE_FEM_SOLUTION((char*)fichiercarte.c_str()); |
159 |
|
|
} |
160 |
francois |
272 |
affiche((char*)"Maillage par le mailleur bloc"); |
161 |
francois |
239 |
FCT_TAILLE* metrique=carte; |
162 |
francois |
494 |
MAILLEUR_BLOC m(gestd,gestnd,0,0,metrique,savedbg); |
163 |
|
|
if (savedbg) m.change_nom_fichierdbg(nomfichierdbg); |
164 |
francois |
493 |
if (affichageactif==1) m.active_affichage(affiche_ptr); |
165 |
francois |
239 |
m.maille(); |
166 |
francois |
272 |
affiche((char*)"Creation du maillage FEM"); |
167 |
francois |
239 |
MG_MAILLAGE* mai=gestd->get_mg_maillage(gestd->get_nb_mg_maillage()-1); |
168 |
|
|
int degre=params.get_valeur("degre"); |
169 |
|
|
FEM_MAILLAGE* fem=new FEM_MAILLAGE(mai->get_mg_geometrie(),mai,degre); |
170 |
|
|
gestd->ajouter_fem_maillage(fem); |
171 |
|
|
fem->construire(0); |
172 |
|
|
return fem; |
173 |
francois |
384 |
} |
174 |
|
|
|
175 |
|
|
|
176 |
|
|
void MGOPT::enregistre_simple(char* nomfichier,class FEM_MAILLAGE* fem) |
177 |
|
|
{ |
178 |
|
|
FILE* out=fopen(nomfichier,"wt"); |
179 |
|
|
fprintf(out,"%d %d\n",fem->get_nb_fem_noeud(),fem->get_nb_fem_element3()); |
180 |
|
|
LISTE_FEM_NOEUD::iterator it; |
181 |
|
|
int i=0; |
182 |
|
|
for (FEM_NOEUD* no=fem->get_premier_noeud(it);no!=NULL;no=fem->get_suivant_noeud(it)) |
183 |
|
|
{ |
184 |
|
|
i++; |
185 |
|
|
no->change_numero(i); |
186 |
|
|
fprintf(out,"%d %lf %lf %lf\n",i,no->get_x(),no->get_y(),no->get_z()); |
187 |
|
|
} |
188 |
|
|
LISTE_FEM_ELEMENT3::iterator it2; |
189 |
|
|
i=0; |
190 |
|
|
for (FEM_ELEMENT3* tet=fem->get_premier_element3(it2);tet!=NULL;tet=fem->get_suivant_element3(it2)) |
191 |
|
|
{ |
192 |
|
|
i++; |
193 |
|
|
fprintf(out,"%d %d %d %d %d %lf\n",i,tet->get_fem_noeud(0)->get_numero(),tet->get_fem_noeud(1)->get_numero(),tet->get_fem_noeud(2)->get_numero(),tet->get_fem_noeud(3)->get_numero(),tet->get_solution()); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
fclose(out); |
197 |
|
|
|
198 |
francois |
494 |
} |
199 |
|
|
|
200 |
|
|
void MGOPT::change_nom_fichierdbg(char *nom) |
201 |
|
|
{ |
202 |
|
|
strcpy(nomfichierdbg,nom); |
203 |
francois |
239 |
} |