1 |
francois |
283 |
//------------------------------------------------------------ |
2 |
|
|
//------------------------------------------------------------ |
3 |
|
|
// MAGiC |
4 |
|
|
// Jean Christophe Cuilli�re et Vincent FRANCOIS |
5 |
|
|
// D�partement de G�nie M�canique - UQTR |
6 |
|
|
//------------------------------------------------------------ |
7 |
|
|
// Le projet MAGIC est un projet de recherche du d�partement |
8 |
|
|
// de g�nie m�canique de l'Universit� du Qu�bec � |
9 |
|
|
// Trois Rivi�res |
10 |
|
|
// Les librairies ne peuvent �tre utilis�es sans l'accord |
11 |
|
|
// des auteurs (contact : francois@uqtr.ca) |
12 |
|
|
//------------------------------------------------------------ |
13 |
|
|
//------------------------------------------------------------ |
14 |
|
|
// |
15 |
|
|
// mg_solution.cpp |
16 |
|
|
// |
17 |
|
|
//------------------------------------------------------------ |
18 |
|
|
//------------------------------------------------------------ |
19 |
|
|
// COPYRIGHT 2000 |
20 |
|
|
// Version du 02/03/2006 � 11H22 |
21 |
|
|
//------------------------------------------------------------ |
22 |
|
|
//------------------------------------------------------------ |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "gestionversion.h" |
26 |
|
|
#include <math.h> |
27 |
|
|
#include <iostream> |
28 |
|
|
#include <stdlib.h> |
29 |
|
|
#include <string.h> |
30 |
|
|
|
31 |
|
|
#include "mg_solution.h" |
32 |
|
|
#include "mg_maillage.h" |
33 |
|
|
#include "ot_mathematique.h" |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
#include <stdio.h> // pour la fonction remove() qui remplace DeleteFile |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
MG_SOLUTION::MG_SOLUTION(MG_MAILLAGE* mai,int nb,char* chemin,int code,std::string nomsol,int entite):MG_IDENTIFICATEUR(),nb_champs(nb),mgmai(mai),nomsolution(nomsol),typeentite(entite) |
44 |
|
|
{ |
45 |
|
|
nom_fichier=new char[strlen(chemin)+2]; |
46 |
|
|
legende=new std::string[nb]; |
47 |
|
|
for (int i=0;i<nb;i++) |
48 |
|
|
{ |
49 |
|
|
char mess[15]; |
50 |
|
|
sprintf(mess,"Champs_%d",i); |
51 |
|
|
legende[i]=mess ; |
52 |
|
|
} |
53 |
|
|
strcpy(nom_fichier,chemin); |
54 |
|
|
if (code!=0) |
55 |
|
|
{ |
56 |
|
|
in=fopen(nom_fichier,"wb"); |
57 |
|
|
for (int i=0;i<code;i++) |
58 |
|
|
for (int j=0;j<nb;j++) |
59 |
|
|
{ |
60 |
|
|
double val=0.0; |
61 |
|
|
fwrite(&val,sizeof(double),1,in); |
62 |
|
|
} |
63 |
|
|
fclose(in); |
64 |
|
|
} |
65 |
|
|
in=fopen(nom_fichier,"r+b"); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
MG_SOLUTION::MG_SOLUTION(unsigned long num,MG_MAILLAGE* mai,int nb,char* chemin,int code,std::string nomsol,int entite):MG_IDENTIFICATEUR(num),nb_champs(nb),mgmai(mai),nomsolution(nomsol),typeentite(entite) |
69 |
|
|
{ |
70 |
|
|
nom_fichier=new char[strlen(chemin)+2]; |
71 |
|
|
legende=new std::string[nb]; |
72 |
|
|
for (int i=0;i<nb;i++) |
73 |
|
|
{ |
74 |
|
|
char mess[15]; |
75 |
|
|
sprintf(mess,"Champs_%d",i); |
76 |
|
|
legende[i]=mess ; |
77 |
|
|
} |
78 |
|
|
strcpy(nom_fichier,chemin); |
79 |
|
|
if (code!=0) |
80 |
|
|
{ |
81 |
|
|
in=fopen(nom_fichier,"wb"); |
82 |
|
|
for (int i=0;i<code;i++) |
83 |
|
|
for (int j=0;j<nb;j++) |
84 |
|
|
{ |
85 |
|
|
double val=0.0; |
86 |
|
|
fwrite(&val,sizeof(double),1,in); |
87 |
|
|
} |
88 |
|
|
fclose(in); |
89 |
|
|
} |
90 |
|
|
in=fopen(nom_fichier,"r+b"); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
MG_SOLUTION::~MG_SOLUTION() |
94 |
|
|
{ |
95 |
|
|
delete [] nom_fichier; |
96 |
|
|
delete [] legende; |
97 |
|
|
if (in!=NULL) fclose(in); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
void MG_SOLUTION::efface(void) |
101 |
|
|
{ |
102 |
|
|
fclose(in); |
103 |
|
|
remove(nom_fichier); |
104 |
|
|
// DeleteFile(nom_fichier); |
105 |
|
|
in=NULL; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
double MG_SOLUTION::lire(int i,int j) |
109 |
|
|
{ |
110 |
|
|
long pos=(nb_champs*i+j)*sizeof(double); |
111 |
|
|
fseek(in,pos,SEEK_SET); |
112 |
|
|
double val; |
113 |
|
|
size_t res=fread(&val,sizeof(double),1,in); |
114 |
|
|
return (val); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
void MG_SOLUTION::ecrire(int i,int j,double val) |
118 |
|
|
{ |
119 |
|
|
long pos=(nb_champs*i+j)*sizeof(double); |
120 |
|
|
fseek(in,pos,SEEK_SET); |
121 |
|
|
fwrite(&val,sizeof(double),1,in); |
122 |
|
|
fflush(in); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
|
126 |
|
|
void MG_SOLUTION::change_legende(int num,std::string val) |
127 |
|
|
{ |
128 |
|
|
legende[num]=val; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
std::string MG_SOLUTION::get_legende(int num) |
132 |
|
|
{ |
133 |
|
|
return legende[num]; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
int MG_SOLUTION::get_nb_champ(void) |
137 |
|
|
{ |
138 |
|
|
return nb_champs; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
MG_MAILLAGE* MG_SOLUTION::get_maillage(void) |
142 |
|
|
{ |
143 |
|
|
return mgmai; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
double MG_SOLUTION::get_legende_min(void) |
147 |
|
|
{ |
148 |
|
|
return solmin; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
double MG_SOLUTION::get_legende_max(void) |
152 |
|
|
{ |
153 |
|
|
return solmax; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
void MG_SOLUTION::active_solution(int num) |
157 |
|
|
{ |
158 |
|
|
int nb; |
159 |
|
|
solmax=-1e308; |
160 |
|
|
solmin=1e308; |
161 |
|
|
int i=0; |
162 |
|
|
if (typeentite==ENTITE_NOEUD) |
163 |
|
|
{ |
164 |
|
|
LISTE_MG_NOEUD::iterator it; |
165 |
|
|
for (MG_NOEUD* no=mgmai->get_premier_noeud(it);no!=NULL;no=mgmai->get_suivant_noeud(it)) |
166 |
|
|
{ |
167 |
|
|
double val=lire(i,num); |
168 |
|
|
no->change_solution(val); |
169 |
|
|
if (val<solmin) solmin=val; |
170 |
|
|
if (val>solmax) solmax=val; |
171 |
|
|
i++; |
172 |
|
|
} |
173 |
|
|
} |
174 |
francois |
308 |
if (typeentite==ENTITE_ELEMENT_1D) |
175 |
francois |
283 |
{ |
176 |
|
|
LISTE_MG_SEGMENT::iterator it; |
177 |
|
|
for (MG_SEGMENT* seg=mgmai->get_premier_segment(it);seg!=NULL;seg=mgmai->get_suivant_segment(it)) |
178 |
|
|
{ |
179 |
|
|
double val=lire(i,num); |
180 |
|
|
seg->change_solution(val); |
181 |
|
|
if (val<solmin) solmin=val; |
182 |
|
|
if (val>solmax) solmax=val; |
183 |
|
|
i++; |
184 |
|
|
} |
185 |
|
|
} |
186 |
francois |
308 |
if (typeentite==ENTITE_ELEMENT_2D) |
187 |
francois |
283 |
{ |
188 |
|
|
LISTE_MG_TRIANGLE::iterator it; |
189 |
|
|
for (MG_TRIANGLE* tri=mgmai->get_premier_triangle(it);tri!=NULL;tri=mgmai->get_suivant_triangle(it)) |
190 |
|
|
{ |
191 |
|
|
double val=lire(i,num); |
192 |
|
|
tri->change_solution(val); |
193 |
|
|
if (val<solmin) solmin=val; |
194 |
|
|
if (val>solmax) solmax=val; |
195 |
|
|
i++; |
196 |
|
|
} |
197 |
francois |
308 |
LISTE_MG_QUADRANGLE::iterator it2; |
198 |
|
|
for (MG_QUADRANGLE* quad=mgmai->get_premier_quadrangle(it2);quad!=NULL;quad=mgmai->get_suivant_quadrangle(it2)) |
199 |
|
|
{ |
200 |
|
|
double val=lire(i,num); |
201 |
|
|
quad->change_solution(val); |
202 |
|
|
if (val<solmin) solmin=val; |
203 |
|
|
if (val>solmax) solmax=val; |
204 |
|
|
i++; |
205 |
|
|
} |
206 |
francois |
283 |
} |
207 |
francois |
308 |
if (typeentite==ENTITE_ELEMENT_3D) |
208 |
francois |
283 |
{ |
209 |
|
|
LISTE_MG_TETRA::iterator it; |
210 |
|
|
for (MG_TETRA* tet=mgmai->get_premier_tetra(it);tet!=NULL;tet=mgmai->get_suivant_tetra(it)) |
211 |
|
|
{ |
212 |
|
|
double val=lire(i,num); |
213 |
|
|
tet->change_solution(val); |
214 |
|
|
if (val<solmin) solmin=val; |
215 |
|
|
if (val>solmax) solmax=val; |
216 |
|
|
i++; |
217 |
|
|
} |
218 |
francois |
308 |
LISTE_MG_HEXA::iterator it2; |
219 |
|
|
for (MG_HEXA* hex=mgmai->get_premier_hexa(it2);hex!=NULL;hex=mgmai->get_suivant_hexa(it2)) |
220 |
|
|
{ |
221 |
|
|
double val=lire(i,num); |
222 |
|
|
hex->change_solution(val); |
223 |
|
|
if (val<solmin) solmin=val; |
224 |
|
|
if (val>solmax) solmax=val; |
225 |
|
|
i++; |
226 |
|
|
} |
227 |
francois |
283 |
} |
228 |
|
|
if (OPERATEUR::egal(fabs(solmin-solmax),0.,1e-10)==1) |
229 |
|
|
solmax=solmin+1e-10; |
230 |
|
|
} |
231 |
|
|
|
232 |
|
|
std::string MG_SOLUTION::get_nom(void) |
233 |
|
|
{ |
234 |
|
|
return nomsolution; |
235 |
|
|
} |
236 |
|
|
|
237 |
|
|
void MG_SOLUTION::enregistrer(std::ostream& o) |
238 |
|
|
{ |
239 |
|
|
o << "%" << get_id() << "=SOLUTION(" << typeentite << "," << nomsolution << ",$" << mgmai->get_id() << "," << nb_champs << "," << nom_fichier << ",("; |
240 |
|
|
for (int i=0;i<nb_champs;i++) |
241 |
|
|
{ |
242 |
|
|
o << legende[i]; |
243 |
|
|
if (i!=nb_champs-1) o<<","; |
244 |
|
|
else o<<")"; |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
|
248 |
|
|
o << ");" << std::endl; |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
int MG_SOLUTION::get_type_solution(void) |
252 |
|
|
{ |
253 |
|
|
return typeentite; |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
std::ostream& operator << (std::ostream& o,MG_SOLUTION& sol) |
259 |
|
|
{ |
260 |
|
|
sol.enregistrer(o); |
261 |
|
|
return o; |
262 |
|
|
} |
263 |
|
|
|
264 |
|
|
|