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