ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_solution.cpp
Revision: 5
Committed: Tue Jun 12 20:26:34 2007 UTC (17 years, 11 months ago)
Original Path: magic/lib/geometrie/geometrie/src/mg_solution.cpp
File size: 4882 byte(s)
Log Message:

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
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):MG_IDENTIFICATEUR(),nb_champs(nb),mgmai(mai),nomsolution(nomsol)
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):MG_IDENTIFICATEUR(num),nb_champs(nb),mgmai(mai),nomsolution(nomsol)
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     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_noeud=mgmai->get_nb_mg_noeud();
159     for (int i=0;i<nb_noeud;i++)
160     {
161     MG_NOEUD* noeud=mgmai->get_mg_noeud(i);
162     double val=lire(i,num);
163     noeud->change_solution(val);
164     if (i==0)
165     {
166     solmin=val;
167     solmax=val;
168     }
169     if (val<solmin) solmin=val;
170     if (val>solmax) solmax=val;
171     }
172     if (OPERATEUR::egal(fabs(solmin-solmax),0.,1e-10)==1)
173     solmax=solmin+1e-10;
174     }
175    
176     std::string MG_SOLUTION::get_nom(void)
177     {
178     return nomsolution;
179     }
180    
181     void MG_SOLUTION::enregistrer(std::ostream& o)
182     {
183     o << "%" << get_id() << "=SOLUTION(" << nomsolution << ",$" << mgmai->get_id() << "," << nb_champs << "," << nom_fichier << ",(";
184     for (int i=0;i<nb_champs;i++)
185     {
186     o << legende[i];
187     if (i!=nb_champs-1) o<<","; else o<<")";
188     }
189    
190    
191     o << ");" << std::endl;
192     }
193    
194    
195    
196    
197     std::ostream& operator << (std::ostream& o,MG_SOLUTION& sol)
198     {
199     sol.enregistrer(o);
200     return o;
201     }
202    
203