LORENE
mtbl.C
1/*
2 * Methods of class Mtbl
3 *
4 * (see file mtbl.h for documentation)
5 *
6 */
7
8/*
9 * Copyright (c) 1999-2000 Jean-Alain Marck
10 * Copyright (c) 1999-2001 Eric Gourgoulhon
11 *
12 * This file is part of LORENE.
13 *
14 * LORENE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * LORENE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with LORENE; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30
31
32
33/*
34 * $Id: mtbl.C,v 1.10 2016/12/05 16:17:59 j_novak Exp $
35 * $Log: mtbl.C,v $
36 * Revision 1.10 2016/12/05 16:17:59 j_novak
37 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
38 *
39 * Revision 1.9 2014/10/13 08:53:08 j_novak
40 * Lorene classes and functions now belong to the namespace Lorene.
41 *
42 * Revision 1.8 2014/10/06 15:13:15 j_novak
43 * Modified #include directives to use c++ syntax.
44 *
45 * Revision 1.7 2008/08/19 06:42:00 j_novak
46 * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
47 * cast-type operations, and constant strings that must be defined as const char*
48 *
49 * Revision 1.6 2008/02/18 13:53:40 j_novak
50 * Removal of special indentation instructions.
51 *
52 * Revision 1.5 2002/10/16 14:36:43 j_novak
53 * Reorganization of #include instructions of standard C++, in order to
54 * use experimental version 3 of gcc.
55 *
56 * Revision 1.4 2002/09/06 15:37:46 e_gourgoulhon
57 * Performed a forgotten replacement
58 * t = new (Tbl *[nzone]) --> t = new Tbl*[nzone]
59 * to ensure compatibility with the xlC_r compiler on IBM Regatta
60 *
61 * Revision 1.3 2002/05/07 07:36:03 e_gourgoulhon
62 * Compatibilty with xlC compiler on IBM SP2:
63 * suppressed the parentheses around argument of instruction new:
64 * e.g. t = new (Tbl *[nzone]) --> t = new Tbl*[nzone]
65 *
66 * Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon
67 *
68 * All writing/reading to a binary file are now performed according to
69 * the big endian convention, whatever the system is big endian or
70 * small endian, thanks to the functions fwrite_be and fread_be
71 *
72 * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
73 * LORENE
74 *
75 * Revision 2.10 2000/08/16 10:30:04 eric
76 * Suppression du membre dzpuis.
77 *
78 * Revision 2.9 1999/11/23 13:33:04 eric
79 * Le constructeur Tbl::Tbl(const Grille3d* ) est devenu Tbl::Tbl(const Grille3d& ).
80 *
81 * Revision 2.8 1999/10/29 15:06:24 eric
82 * Suppression des fonctions membres min() et max():
83 * elles deviennent des fonctions externes.
84 *
85 * Revision 2.7 1999/10/18 15:16:05 eric
86 * *** empty log message ***
87 *
88 * Revision 2.6 1999/10/18 15:08:22 eric
89 * La fonction membre annule() est rebaptisee annule_hard().
90 * Introduction de la fonction membre annule(int, int).
91 *
92 * Revision 2.5 1999/10/01 12:35:54 eric
93 * Ajout de la fonction affiche_seuil.
94 *
95 * Revision 2.4 1999/10/01 10:08:41 eric
96 * Depoussierage.
97 * Documentation.
98 *
99 * Revision 2.3 1999/03/02 16:26:26 eric
100 * Modif des indentations dans <<
101 *
102 * Revision 2.2 1999/03/02 15:34:08 eric
103 * Anglicisation des commentaires...
104 *
105 * Revision 2.1 1999/02/22 15:24:13 hyc
106 * *** empty log message ***
107 *
108 *
109 * Revision 2.0 1999/01/15 09:10:39 hyc
110 * *** empty log message ***
111 *
112 * $Header: /cvsroot/Lorene/C++/Source/Mtbl/mtbl.C,v 1.10 2016/12/05 16:17:59 j_novak Exp $
113 *
114 */
115// headers C
116#include <cassert>
117
118// headers Lorene
119#include "mtbl.h"
120#include "coord.h"
121#include "type_parite.h"
122#include "utilitaires.h"
123
124// Constructeurs
125// -------------
126namespace Lorene {
127Mtbl::Mtbl(const Mg3d& g) : mg(&g), etat(ETATNONDEF), t(0x0) {
128
129 nzone = g.get_nzone() ;
130
131}
132
133Mtbl::Mtbl(const Mg3d* g) : mg(g), etat(ETATNONDEF), t(0x0) {
134
135 nzone = g->get_nzone() ;
136
137}
138
139Mtbl::Mtbl(const Coord& c1) {
140
141 // La coordonnee est-elle a jour ?
142 if (c1.c == 0x0) c1.fait() ;
143
144 // Les donnees fixes
145 mg = c1.c->get_mg() ;
146 nzone = mg->get_nzone() ;
147
148 // L'etat
149 t = 0x0 ;
150 etat = ETATNONDEF ;
151
152 // La transformation
153 *this = *(c1.c) ;
154}
155
156
157// Destructeur
158// -----------
160 del_t() ;
161}
162
163// Copie
164// -----
165Mtbl::Mtbl(const Mtbl& mtc) : mg(mtc.mg), nzone(mtc.nzone) {
166
167 // Protection
168 assert(mtc.get_etat() != ETATNONDEF) ;
169
170 t = 0x0 ;
171 etat = ETATNONDEF ;
172 if (mtc.etat == ETATQCQ) {
173 set_etat_qcq() ;
174 for (int i=0 ; i<nzone ; i++) {
175 *t[i] = *mtc.t[i] ;
176 }
177 }
178 else {
179 assert(mtc.etat == ETATZERO) ; // sinon...
180 }
181 etat = mtc.etat ;
182}
183
184// Constructeur a partir d'une grille et d'un fichier
185Mtbl::Mtbl(const Mg3d & g, FILE* fd) : mg(&g) {
186
187 // La multi-grille
188 Mg3d* mg_tmp = new Mg3d(fd) ; // la multi-grille d'origine
189 if (*mg != *mg_tmp) {
190 cout << "Mtbl::Mtbl(Mg3d & , FILE*): grid not consistent !" << endl ;
191 abort() ;
192 }
193 delete mg_tmp ;
194
195 // Lecture
196 nzone = mg->get_nzone() ;
197 fread_be(&etat, sizeof(int), 1, fd) ; // etat
198
199 // Le tableau
200 t = 0x0 ;
201 if (etat == ETATQCQ) {
202 t = new Tbl*[nzone] ;
203 for (int i=0 ; i<nzone ; i++) {
204 t[i] = new Tbl(fd) ;
205 }
206 }
207 int dzpuis_vieux ;
208 fread_be(&dzpuis_vieux, sizeof(int), 1, fd) ; // le vieux dzpuis
209}
210
211// Sauvegarde sur un fichier
212void Mtbl::sauve(FILE* fd) const {
213
214 mg->sauve(fd) ; // la multi-grille
215 fwrite_be(&etat, sizeof(int), 1, fd) ; // etat
216 if (etat == ETATQCQ) {
217 for (int i=0 ; i<nzone ; i++) {
218 t[i]->sauve(fd) ;
219 }
220 }
221 int dzpuis_vieux = 0 ;
222 fwrite_be(&dzpuis_vieux, sizeof(int), 1, fd) ; // le vieux dzpuis
223}
224
225// Affectations
226// ------------
227void Mtbl::operator=(const Mtbl& mtc)
228{
229 // Protection
230 assert (mg == mtc.mg) ;
231 assert(mtc.get_etat() != ETATNONDEF) ;
232
233 // Gestion des donnees
234 if (mtc.get_etat() == ETATZERO) {
235 set_etat_zero() ;
236 }
237 else {
238 assert(mtc.get_etat() == ETATQCQ) ; // sinon...
239 set_etat_qcq() ;
240 for (int i=0 ; i<nzone ; i++) {
241 *t[i] = *mtc.t[i] ;
242 }
243 }
244}
245
246void Mtbl::operator=(double x)
247{
248 if (x == double(0)) {
249 set_etat_zero() ;
250 }
251 else {
252 set_etat_qcq() ;
253 for (int i=0 ; i<nzone ; i++) {
254 *t[i] = x ;
255 }
256 }
257
258}
259
261{
262 if (m == 0) {
263 set_etat_zero() ;
264 }
265 else {
266 set_etat_qcq() ;
267 for (int i=0 ; i<nzone ; i++) {
268 *t[i] = m ;
269 }
270 }
271
272}
273
274
275 //-----------------//
276 // Gestion memoire //
277 //-----------------//
278
279// Destructeur logique
281 if (t != 0x0) {
282 for (int l=0 ; l<nzone ; l++) {
283 delete t[l] ;
284 }
285 delete [] t ;
286 t = 0x0 ;
287 }
288}
289// ETATZERO
291 if (etat == ETATZERO) return ;
292 del_t() ;
293 etat = ETATZERO ;
294}
295// ETATNONDEF
297 if (etat == ETATNONDEF) return ;
298 del_t() ;
299 etat = ETATNONDEF ;
300}
301// ETATQCQ
303 if (etat == ETATQCQ) return ;
304
305 // Protection
306 assert( (etat == ETATZERO) || (etat == ETATNONDEF) ) ; // sinon...
307
308 t = new Tbl*[nzone] ;
309 for (int i=0 ; i<nzone ; i++) {
310 t[i] = new Tbl( *(mg->get_grille3d(i)) ) ;
311 }
312 etat = ETATQCQ ;
313}
314// ZERO hard
316 if (t == 0x0) {
317 t = new Tbl*[nzone] ;
318 for (int i=0 ; i<nzone ; i++) {
319 t[i] = new Tbl( *(mg->get_grille3d(i)) ) ;
320 }
321 }
322
323 for (int i=0 ; i<nzone ; i++) {
324 t[i]->annule_hard() ;
325 }
326 etat = ETATQCQ ;
327}
328
329// Sets the {\tt Mtbl} to zero in some domains
330// -------------------------------------------
331
332void Mtbl::annule(int l_min, int l_max) {
333
334 assert( (l_min >= 0) && (l_min < nzone) ) ;
335 assert( (l_max >= 0) && (l_max < nzone) ) ;
336
337 // Cas particulier: annulation globale :
338 if ( (l_min == 0) && (l_max == nzone-1) ) {
339 set_etat_zero() ;
340 return ;
341 }
342
343 assert( etat != ETATNONDEF ) ;
344
345 if ( etat == ETATZERO ) {
346 return ; // rien n'a faire si c'est deja zero
347 }
348 else {
349 assert( etat == ETATQCQ ) ; // sinon...
350 for (int l=l_min; l<=l_max; l++) {
351 t[l]->set_etat_zero() ;
352 }
353
354 }
355
356}
357
358
359
360 //------------------------//
361 // Display //
362 //------------------------//
363
364//-----------
365// Operator<<
366//-----------
367
368ostream& operator<<(ostream& o, const Mtbl& mt) {
369 // Protection
370 assert(mt.get_etat() != ETATNONDEF) ;
371
372 int nzone = mt.get_nzone() ;
373 o.precision(4);
374 o.setf(ios::showpoint);
375 o << "*** Mtbl " << nzone << " domains" << endl ;
376
377 if (mt.get_etat() == ETATZERO) {
378 o << "Logically NULL" << endl ;
379 }
380 else {
381 for (int l=0 ; l<nzone ; l++) {
382 o << " Domain #" << l << endl ;
383 o << *(mt.t[l]) ;
384 o << endl ;
385 }
386 }
387
388 o << endl ;
389 return o ;
390}
391
392//---------------
393// Affiche_seuil
394//---------------
395
396void Mtbl::affiche_seuil(ostream& ost, int precis, double seuil) const {
397 ost << "*** Mtbl " << nzone << " domains" << endl ;
398
399 // Cas particuliers
400 //-----------------
401
402 if (etat == ETATNONDEF) {
403 ost << " state: UNDEFINED" << endl ;
404 return ;
405 }
406
407 if (etat == ETATZERO) {
408 ost << " state: ZERO" << endl ;
409 return ;
410 }
411
412 // Affichage des Tbl
413 //------------------
414
415 for (int l=0; l < nzone; l++) {
416 t[l]->affiche_seuil( ost , precis, seuil ) ;
417 }
418
419
420}
421
422
423// To be done
424//-----------
425
426void Mtbl::operator+=(double ) {
427 const char* f = __FILE__ ;
428 c_est_pas_fait(f) ;
429}
430
431void Mtbl::operator-=(double ) {
432 const char* f = __FILE__ ;
433 c_est_pas_fait(f) ;
434}
435
436void Mtbl::operator*=(double ) {
437 const char* f = __FILE__ ;
438 c_est_pas_fait(f) ;
439}
440
441void Mtbl::operator/=(double ) {
442 const char* f = __FILE__ ;
443 c_est_pas_fait(f) ;
444}
445
446
447}
Active physical coordinates and mapping derivatives.
Definition coord.h:90
void fait() const
Computes, at each point of the grid, the value of the coordinate or mapping derivative represented by...
Definition coord.C:119
Mtbl * c
The coordinate values at each grid point.
Definition coord.h:97
Multi-domain grid.
Definition grilles.h:279
int get_nzone() const
Returns the number of domains.
Definition grilles.h:465
void sauve(FILE *) const
Save in a file.
Definition mtbl.C:212
void annule(int l_min, int l_max)
Sets the Mtbl to zero in some domains.
Definition mtbl.C:332
const Mg3d * get_mg() const
Gives the Mg3d on which the Mtbl is defined.
Definition mtbl.h:274
friend ostream & operator<<(ostream &, const Mtbl &)
Display.
Definition mtbl.C:368
~Mtbl()
Destructor.
Definition mtbl.C:159
int get_etat() const
Gives the logical state.
Definition mtbl.h:277
void del_t()
Logical destructor: dellocates the memory occupied by the Tbl array t .
Definition mtbl.C:280
void affiche_seuil(ostream &ostr, int precision=4, double threshold=1.e-7) const
Prints only the values greater than a given threshold.
Definition mtbl.C:396
Mtbl(const Mg3d &mgrid)
Constructor.
Definition mtbl.C:127
void operator/=(const Mtbl &)
/= Mtbl
const Mg3d * mg
Pointer on the multi-grid Mgd3 on which this is defined.
Definition mtbl.h:124
void operator+=(const Mtbl &)
+= Mtbl
Tbl ** t
Array (size nzone ) of pointers on the Tbl 's.
Definition mtbl.h:132
void operator=(const Mtbl &)
Assignement to another Mtbl.
Definition mtbl.C:227
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition mtbl.C:302
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition mtbl.C:296
int nzone
Number of domains (zones).
Definition mtbl.h:126
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition mtbl.C:290
int get_nzone() const
Gives the number of zones (domains).
Definition mtbl.h:280
void operator*=(const Mtbl &)
*= Mtbl
int etat
Logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition mtbl.h:128
void annule_hard()
Sets the Mtbl to zero in a hard way.
Definition mtbl.C:315
void operator-=(const Mtbl &)
-= Mtbl
Basic array class.
Definition tbl.h:161
void c_est_pas_fait(const char *)
Helpful function to say something is not implemented yet.
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Definition fread_be.C:72
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Definition fwrite_be.C:73
Lorene prototypes.
Definition app_hor.h:67
Coord x
x coordinate centered on the grid
Definition map.h:738