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