1 |
|
5 |
//------------------------------------------------------------
|
2 |
|
|
//------------------------------------------------------------
|
3 |
|
|
// MAGiC
|
4 |
francois |
174 |
// Jean Christophe Cuilli�re et Vincent FRANCOIS
|
5 |
|
|
// D�partement de G�nie M�canique - UQTR
|
6 |
|
5 |
//------------------------------------------------------------
|
7 |
francois |
174 |
// 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 |
|
5 |
// des auteurs (contact : francois@uqtr.ca)
|
12 |
|
|
//------------------------------------------------------------
|
13 |
|
|
//------------------------------------------------------------
|
14 |
|
|
//
|
15 |
|
|
// mg_solution.cpp
|
16 |
|
|
//
|
17 |
|
|
//------------------------------------------------------------
|
18 |
|
|
//------------------------------------------------------------
|
19 |
|
|
// COPYRIGHT 2000
|
20 |
francois |
174 |
// Version du 02/03/2006 � 11H22
|
21 |
|
5 |
//------------------------------------------------------------
|
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 |
francois |
174 |
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 |
|
5 |
{
|
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 |
francois |
174 |
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 |
|
5 |
{
|
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 |
|
|
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 |
francois |
174 |
int nb;
|
159 |
francois |
239 |
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 |
|
|
if (typeentite==ENTITE_SEGMENT)
|
175 |
|
|
{
|
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 |
|
|
if (typeentite==ENTITE_TRIANGLE)
|
187 |
|
|
{
|
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 |
|
|
}
|
198 |
|
|
if (typeentite==ENTITE_TETRA)
|
199 |
|
|
{
|
200 |
|
|
LISTE_MG_TETRA::iterator it;
|
201 |
|
|
for (MG_TETRA* tet=mgmai->get_premier_tetra(it);tet!=NULL;tet=mgmai->get_suivant_tetra(it))
|
202 |
|
|
{
|
203 |
|
|
double val=lire(i,num);
|
204 |
|
|
tet->change_solution(val);
|
205 |
|
|
if (val<solmin) solmin=val;
|
206 |
|
|
if (val>solmax) solmax=val;
|
207 |
|
|
i++;
|
208 |
|
|
}
|
209 |
|
|
}
|
210 |
|
5 |
if (OPERATEUR::egal(fabs(solmin-solmax),0.,1e-10)==1)
|
211 |
|
|
solmax=solmin+1e-10;
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
std::string MG_SOLUTION::get_nom(void)
|
215 |
|
|
{
|
216 |
|
|
return nomsolution;
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
void MG_SOLUTION::enregistrer(std::ostream& o)
|
220 |
|
|
{
|
221 |
francois |
174 |
o << "%" << get_id() << "=SOLUTION(" << typeentite << "," << nomsolution << ",$" << mgmai->get_id() << "," << nb_champs << "," << nom_fichier << ",(";
|
222 |
|
5 |
for (int i=0;i<nb_champs;i++)
|
223 |
|
|
{
|
224 |
|
|
o << legende[i];
|
225 |
|
|
if (i!=nb_champs-1) o<<","; else o<<")";
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
o << ");" << std::endl;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
francois |
174 |
int MG_SOLUTION::get_type_solution(void)
|
233 |
|
|
{
|
234 |
|
|
return typeentite;
|
235 |
|
|
}
|
236 |
|
5 |
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
std::ostream& operator << (std::ostream& o,MG_SOLUTION& sol)
|
240 |
|
|
{
|
241 |
|
|
sol.enregistrer(o);
|
242 |
|
|
return o;
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
|