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