LORENE
mtbl_cf.C
1/*
2 * Methods of class Mtbl_cf
3 *
4 * (see file mtbl_cf.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_cf.C,v 1.10 2016/12/05 16:17:59 j_novak Exp $
35 * $Log: mtbl_cf.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:41 j_novak
50 * Removal of special indentation instructions.
51 *
52 * Revision 1.5 2003/10/19 19:51:23 e_gourgoulhon
53 * Access to Base_val::nzone now via the method Base_val::get_nzone().
54 *
55 * Revision 1.4 2002/10/16 14:36:43 j_novak
56 * Reorganization of #include instructions of standard C++, in order to
57 * use experimental version 3 of gcc.
58 *
59 * Revision 1.3 2002/05/07 07:36:03 e_gourgoulhon
60 * Compatibilty with xlC compiler on IBM SP2:
61 * suppressed the parentheses around argument of instruction new:
62 * e.g. t = new (Tbl *[nzone]) --> t = new Tbl*[nzone]
63 *
64 * Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon
65 *
66 * All writing/reading to a binary file are now performed according to
67 * the big endian convention, whatever the system is big endian or
68 * small endian, thanks to the functions fwrite_be and fread_be
69 *
70 * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
71 * LORENE
72 *
73 * Revision 2.13 2000/08/16 10:43:09 eric
74 * Suppression du membre dzpuis.
75 *
76 * Revision 2.12 2000/02/25 10:27:44 eric
77 * Suppression des appels a nettoie() dans l'affichage.
78 *
79 * Revision 2.11 1999/10/29 15:07:27 eric
80 * Suppression des fonctions membres min() et max():
81 * elles deviennent des fonctions externes.
82 *
83 * Revision 2.10 1999/10/21 13:42:05 eric
84 * *** empty log message ***
85 *
86 * Revision 2.9 1999/10/18 15:16:12 eric
87 * *** empty log message ***
88 *
89 * Revision 2.8 1999/10/18 15:08:44 eric
90 * La fonction membre annule() est rebaptisee annule_hard().
91 * Introduction de la fonction membre annule(int, int).
92 *
93 * Revision 2.7 1999/10/13 15:52:03 eric
94 * Depoussierage.
95 * Ajout du membre base.
96 *
97 * Revision 2.6 1999/10/01 14:49:38 eric
98 * Depoussierage.
99 * Documentation.
100 *
101 * Revision 2.5 1999/03/03 10:35:37 hyc
102 * *** empty log message ***
103 *
104 * Revision 2.4 1999/03/02 16:26:39 eric
105 * Modif des indentations dans <<
106 *
107 * Revision 2.3 1999/03/02 15:34:30 eric
108 * Anglicisation des messages...
109 *
110 *
111 * $Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf.C,v 1.10 2016/12/05 16:17:59 j_novak Exp $
112 *
113 */
114// headers C
115#include <cassert>
116#include <cstdlib>
117#include <cmath>
118
119// headers Lorene
120#include "mtbl_cf.h"
121#include "utilitaires.h"
122
123// Constructeur
124// ------------
125
126namespace Lorene {
127Mtbl_cf::Mtbl_cf(const Mg3d& g, const Base_val& ba) : mg(&g),
128 etat(ETATNONDEF),
129 base(ba),
130 t(0x0) {
131 nzone = g.get_nzone() ;
132 assert(base.get_nzone() == nzone) ;
133}
134
135Mtbl_cf::Mtbl_cf(const Mg3d* g, const Base_val& ba) : mg(g),
136 etat(ETATNONDEF),
137 base(ba),
138 t(0x0) {
139 nzone = g->get_nzone() ;
140 assert(base.get_nzone() == nzone) ;
141}
142
143
144// Destructeur
145// -----------
147
148 del_t() ;
149}
150
151// Copie
152// -----
153Mtbl_cf::Mtbl_cf(const Mtbl_cf& mtc) : mg(mtc.mg),
154 nzone(mtc.nzone),
155 base(mtc.base) {
156
157 // Protection
158 assert(mtc.get_etat() != ETATNONDEF) ;
159
160 t = 0x0 ;
161 etat = ETATNONDEF ;
162 if (mtc.etat == ETATQCQ) {
163 set_etat_qcq() ;
164 for (int i=0 ; i<nzone ; i++) {
165 *t[i] = *mtc.t[i] ;
166 }
167 }
168 else {
169 assert(mtc.etat == ETATZERO) ; // sinon...
170 }
171 etat = mtc.etat ;
172}
173
174// Constructeur a partir d'une grille et d'un fichier
175// --------------------------------------------------
176Mtbl_cf::Mtbl_cf(const Mg3d& g, FILE* fd) : mg(&g),
177 base(fd) {
178
179 // La multi-grille
180 Mg3d* mg_tmp = new Mg3d(fd) ; // la multi-grille d'origine
181 if (*mg != *mg_tmp) {
182 cout << "Mtbl_cf::Mtbl_cf(const Mg3d& , FILE*): grid not consistent !"
183 << endl ;
184 abort() ;
185 }
186 delete mg_tmp ;
187
188 // Lecture
189 nzone = mg->get_nzone() ;
190 assert(base.get_nzone() == nzone) ;
191 fread_be(&etat, sizeof(int), 1, fd) ; // etat
192
193 // Le tableau
194 t = 0x0 ;
195 if (etat == ETATQCQ) {
196 t = new Tbl*[nzone] ;
197 for (int i=0 ; i<nzone ; i++) {
198 t[i] = new Tbl(fd) ;
199 }
200 }
201 int dzpuis_vieux ;
202 fread_be(&dzpuis_vieux, sizeof(int), 1, fd) ; // le vieux dzpuis !
203}
204
205// Sauvegarde sur un fichier
206// -------------------------
207void Mtbl_cf::sauve(FILE* fd) const {
208
209 base.sauve(fd) ; // la base
210 mg->sauve(fd) ; // la multi-grille
211 fwrite_be(&etat, sizeof(int), 1, fd) ; // etat
212 if (etat == ETATQCQ) {
213 for (int i=0 ; i<nzone ; i++) {
214 t[i]->sauve(fd) ;
215 }
216 }
217 int dzpuis_vieux = 0 ;
218 fwrite_be(&dzpuis_vieux, sizeof(int), 1, fd) ; // le vieux dzpuis !
219}
220
221// Affectations
222// ------------
224{
225 // Protection
226 assert (mg == mtc.mg) ;
227 assert(mtc.get_etat() != ETATNONDEF) ;
228
229 // Les choses fixes
230 base = mtc.base ;
231
232 // Gestion des donnees
233 if (mtc.get_etat() == ETATZERO) {
234 set_etat_zero() ;
235 }
236 else {
237 assert(mtc.get_etat() == ETATQCQ) ; // sinon...
238 set_etat_qcq() ;
239 for (int i=0 ; i<nzone ; i++) {
240 *t[i] = *mtc.t[i] ;
241 }
242 }
243}
244
246{
247 if ( x == double(0) ) {
248 set_etat_zero() ;
249 }
250 else {
251 set_etat_qcq() ;
252 for (int i=0 ; i<nzone ; i++) {
253 *t[i] = x ;
254 }
255 }
256
257}
258
260{
261 if (m == 0) {
262 set_etat_zero() ;
263 }
264 else {
265 set_etat_qcq() ;
266 for (int i=0 ; i<nzone ; i++) {
267 *t[i] = m ;
268 }
269 }
270
271}
272
273
274 //-----------------//
275 // Gestion memoire //
276 //-----------------//
277
278// Destructeur logique
280 // Detruit le mtbl_cf
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 etat = ETATNONDEF ;
289}
290// ETATZERO
292 if (etat == ETATZERO) return ;
293 del_t() ;
294 etat = ETATZERO ;
295}
296// ETATNONDEF
298 if (etat == ETATNONDEF) return ;
299 del_t() ;
300 etat = ETATNONDEF ;
301}
302// ETATQCQ
304 if (etat == ETATQCQ) return ;
305 t = new Tbl*[nzone] ;
306 for (int i=0 ; i<nzone ; i++) {
307 int nbr = mg->get_nr(i) ;
308 int nbt = mg->get_nt(i) ;
309 int nbp = mg->get_np(i) ;
310 t[i] = new Tbl(nbp+2, nbt, nbr) ;
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 int nbr = mg->get_nr(i) ;
320 int nbt = mg->get_nt(i) ;
321 int nbp = mg->get_np(i) ;
322 t[i] = new Tbl(nbp+2, nbt, nbr) ;
323 }
324 }
325
326 for (int i=0 ; i<nzone ; i++) {
327 t[i]->annule_hard() ;
328 }
329 etat = ETATQCQ ;
330}
331
332// Sets the {\tt Mtbl_cf} to zero in some domains
333// ----------------------------------------------
334
335void Mtbl_cf::annule(int l_min, int l_max) {
336
337 assert( (l_min >= 0) && (l_min < nzone) ) ;
338 assert( (l_max >= 0) && (l_max < nzone) ) ;
339
340 // Cas particulier: annulation globale :
341 if ( (l_min == 0) && (l_max == nzone-1) ) {
342 set_etat_zero() ;
343 return ;
344 }
345
346 assert( etat != ETATNONDEF ) ;
347
348 if ( etat == ETATZERO ) {
349 return ; // rien n'a faire si c'est deja zero
350 }
351 else {
352 assert( etat == ETATQCQ ) ; // sinon...
353 for (int l=l_min; l<=l_max; l++) {
354 t[l]->set_etat_zero() ;
355 }
356
357 }
358
359}
360
361 //------------------------//
362 // Display //
363 //------------------------//
364
365//-----------
366// Operator<<
367//-----------
368
369ostream& operator<<(ostream& o, const Mtbl_cf& mt) {
370 // Protection
371 assert(mt.get_etat() != ETATNONDEF) ;
372
373 int nzone = mt.get_nzone() ;
374 o.precision(4);
375 o.setf(ios::showpoint);
376 o << "*** MTBL_CF " << nzone << " domains" << endl ;
377
378 o << mt.base << endl ;
379
380 o << "Values of the coefficients : " << endl ;
381 if (mt.get_etat() == ETATZERO) {
382 o << "Logically NUL" << endl ;
383 }
384 else {
385 for (int l=0 ; l<nzone ; l++) {
386 o << " Domain #" << l << endl ;
387 o << *(mt.t[l]) ;
388 o << endl ;
389 }
390 }
391
392 o << endl ;
393 return o ;
394}
395
396//---------------
397// Affiche_seuil
398//---------------
399
400void Mtbl_cf::affiche_seuil(ostream& ost, int precis, double seuil) const {
401 ost << "*** Mtbl_cf " << nzone << " domains" << endl ;
402 ost << base << endl ;
403 ost << "Values of the coefficients : " << endl ;
404
405 // Cas particuliers
406 //-----------------
407
408 if (etat == ETATNONDEF) {
409 ost << " state: UNDEFINED" << endl ;
410 return ;
411 }
412
413 if (etat == ETATZERO) {
414 ost << " state: ZERO" << endl ;
415 return ;
416 }
417
418 // Affichage des Tbl
419 //------------------
420 assert( t != 0x0 ) ;
421
422 for (int l=0; l < nzone; l++) {
423 t[l]->affiche_seuil( ost , precis, seuil ) ;
424 }
425
426}
427
428
429// To be done
430//-----------
431
432void Mtbl_cf::operator*=(double ) {
433 const char* f = __FILE__ ;
434 c_est_pas_fait(f) ;
435}
436
437void Mtbl_cf::operator/=(double ) {
438 const char* f = __FILE__ ;
439 c_est_pas_fait(f) ;
440}
441
442
443}
Bases of the spectral expansions.
Definition base_val.h:325
Multi-domain grid.
Definition grilles.h:279
int get_nzone() const
Returns the number of domains.
Definition grilles.h:465
Base_val base
Bases of the spectral expansions.
Definition mtbl_cf.h:210
void del_t()
Logical destructor: dellocates the memory occupied by the Tbl array t .
Definition mtbl_cf.C:279
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition mtbl_cf.C:297
~Mtbl_cf()
Destructor.
Definition mtbl_cf.C:146
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition mtbl_cf.C:291
int get_etat() const
Returns the logical state.
Definition mtbl_cf.h:466
const Mg3d * mg
Pointer on the multi-grid Mgd3 on which this is defined.
Definition mtbl_cf.h:202
void operator*=(double)
*= double
Definition mtbl_cf.C:432
void annule(int l_min, int l_max)
Sets the Mtbl_cf to zero in some domains.
Definition mtbl_cf.C:335
void sauve(FILE *) const
Save in a file.
Definition mtbl_cf.C:207
int get_nzone() const
Returns the number of zones (domains).
Definition mtbl_cf.h:469
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_cf.C:400
void operator=(const Mtbl_cf &)
Assignement to another Mtbl_cf.
Definition mtbl_cf.C:223
int etat
Logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition mtbl_cf.h:206
Tbl ** t
Array (size nzone ) of pointers on the Tbl 's which contain the spectral coefficients in each domain.
Definition mtbl_cf.h:215
Mtbl_cf(const Mg3d &mgrid, const Base_val &basis)
Constructor.
Definition mtbl_cf.C:127
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition mtbl_cf.C:303
void annule_hard()
Sets the Mtbl_cf to zero in a hard way.
Definition mtbl_cf.C:315
void operator/=(double)
/= double
Definition mtbl_cf.C:437
friend ostream & operator<<(ostream &, const Mtbl_cf &)
Display.
Definition mtbl_cf.C:369
int nzone
Number of domains (zones).
Definition mtbl_cf.h:204
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