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