LORENE
scalar_r_manip.C
1 /*
2  * Member functions of the class Scalar for various r manipulations
3  *
4  * See file scalar.h for documentation.
5  */
6 
7 /*
8  * Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak
9  *
10  * Copyright (c) 1999-2001 Eric Gourgoulhon (for a preceding Cmp version)
11  * Copyright (c) 1999-2001 Philippe Grandclement (for a preceding Cmp version)
12  * Copyright (c) 2001 Jerome Novak (for a preceding Cmp version)
13  *
14  * This file is part of LORENE.
15  *
16  * LORENE is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * LORENE is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with LORENE; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  *
30  */
31 
32 
33 
34 
35 /*
36  * $Id: scalar_r_manip.C,v 1.24 2016/12/05 16:18:19 j_novak Exp $
37  * $Log: scalar_r_manip.C,v $
38  * Revision 1.24 2016/12/05 16:18:19 j_novak
39  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
40  *
41  * Revision 1.23 2014/10/13 08:53:47 j_novak
42  * Lorene classes and functions now belong to the namespace Lorene.
43  *
44  * Revision 1.22 2005/05/25 16:11:05 j_novak
45  * Better handling of the case with no compactified domain.
46  *
47  * Revision 1.21 2005/05/18 11:45:46 j_novak
48  * Added del_deriv() calls at the end of inc/dec_dzpuis.
49  *
50  * Revision 1.20 2004/10/11 15:09:04 j_novak
51  * The radial manipulation functions take Scalar as arguments, instead of Cmp.
52  * Added a conversion operator from Scalar to Cmp.
53  * The Cmp radial manipulation function make conversion to Scalar, call to the
54  * Map_radial version with a Scalar argument and back.
55  *
56  * Revision 1.19 2004/10/08 13:34:37 j_novak
57  * Scalar::div_r() does not need to pass through Cmp version anymore.
58  *
59  * Revision 1.18 2004/05/12 14:22:12 f_limousin
60  * Treated the case ETATZERO in dec_dzpuis and inc_dzpuis (-> return).
61  *
62  * Revision 1.17 2004/01/29 09:31:44 j_novak
63  * Better treatment of ETATUN
64  *
65  * Revision 1.16 2004/01/28 10:34:27 j_novak
66  * Corrected some errors.
67  *
68  * Revision 1.15 2004/01/27 15:10:02 j_novak
69  * New methods Scalar::div_r_dzpuis(int) and Scalar_mult_r_dzpuis(int)
70  * which replace div_r_inc*. Tried to clean the dzpuis handling.
71  * WARNING: no testing at this point!!
72  *
73  * Revision 1.14 2004/01/22 16:11:30 e_gourgoulhon
74  * Added (provisory method) div_r_inc1().
75  * Case inc = 3 treated in inc_dzpuis.
76  *
77  * Revision 1.13 2003/11/04 23:02:21 e_gourgoulhon
78  * -- Method dec_dzpuis(int decrem) : the case decrem = 1 is now treated.
79  * -- Method div_tant() is now defined in file scalar_th_manip.C.
80  *
81  * Revision 1.12 2003/11/03 22:36:37 e_gourgoulhon
82  * Method dec_dzpuis: changed the name of argument dec --> decrem
83  * (in order not to shadow some globally defined dec).
84  *
85  * Revision 1.11 2003/11/03 10:25:05 e_gourgoulhon
86  * Scalar::dec_dzpuis(int dec) : treated the case dec = 0
87  * Scalar::inc_dzpuis(int inc) : treated the case inc = 0
88  *
89  * Revision 1.10 2003/10/29 11:02:13 e_gourgoulhon
90  * Functions dec_dzpuis and inc_dzpuis have now an integer argument to
91  * specify by which amount dzpuis is to be increased.
92  * Accordingly methods dec2_dzpuis and inc2_dzpuis have been suppressed
93  *
94  * Revision 1.9 2003/10/16 15:29:08 e_gourgoulhon
95  * Name of method div_r_ced() changed to div_r_inc2().
96  * Name of method div_rsint_ced() changed to div_rsint_inc2().
97  *
98  * Revision 1.8 2003/10/15 10:44:21 e_gourgoulhon
99  * Added new method div_tant.
100  *
101  * Revision 1.7 2003/10/13 20:50:16 e_gourgoulhon
102  * Replaced "va.base" by "va.get_base()".
103  *
104  * Revision 1.6 2003/10/10 15:57:29 j_novak
105  * Added the state one (ETATUN) to the class Scalar
106  *
107  * Revision 1.5 2003/10/08 14:24:10 j_novak
108  * replaced mult_r_zec with mult_r_ced
109  *
110  * Revision 1.4 2003/10/08 12:26:03 j_novak
111  * Second part of the bug (sorry!)
112  *
113  * Revision 1.3 2003/10/08 12:19:12 j_novak
114  * Bug corrected, thanks to purify
115  *
116  * Revision 1.2 2003/10/05 21:16:41 e_gourgoulhon
117  * Added methods div_r_ced() and div_rsint_ced().
118  *
119  * Revision 1.1 2003/09/25 09:12:01 e_gourgoulhon
120  * First version (uses Cmp as intermediate variable).
121  *
122  *
123  * $Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_r_manip.C,v 1.24 2016/12/05 16:18:19 j_novak Exp $
124  *
125  */
126 
127 #include "tensor.h"
128 #include "cmp.h"
129 
130 
131  //-------------------//
132  // div_r //
133  //-------------------//
134 
135 namespace Lorene {
137 
138  mp->div_r(*this) ; // Call of the appropriate routine of the mapping
139 
140  del_deriv() ; // Delete the derived members
141 
142 }
143 
144 
145  //---------------------//
146  // div_r_dzpuis //
147  //---------------------//
148 
149 
150 void Scalar::div_r_dzpuis(int ced_mult_r) {
151 
152  assert (etat != ETATNONDEF) ;
153 
154  Base_val lbase = va.base ;
155 
156  if (etat != ETATZERO) {
157 
158  assert((etat == ETATQCQ) || (etat == ETATUN)) ;
159 
160  set_etat_qcq() ;
161 
162  int nzm1 = mp->get_mg()->get_nzone() - 1 ; // index of the CED
163  bool ced = mp->get_mg()->get_type_r(nzm1) == UNSURR ;
164 
165  // Copy of the CED part of *this into uu_ext
166  Scalar uu_ext(*mp) ;
167  if (ced) {
168  uu_ext.allocate_all() ;
169  uu_ext.annule(0,nzm1-1) ; // zero in all domains but the CED
170  uu_ext.set_domain(nzm1) = domain(nzm1) ;
171  uu_ext.set_spectral_base(va.get_base()) ;
172 
173  // Division by r in all domains but the CED
174  annule(nzm1, nzm1) ; // zero in the CED
175  }
176  div_r() ;
177 
178  if (ced) { // Add the CED part
179  set_domain(nzm1) = uu_ext.domain(nzm1) ;
180  dzpuis += 1 ;
181  }
182  }
183 
184  int diff_dzpuis = ced_mult_r - dzpuis ;
185  (diff_dzpuis >= 0) ? inc_dzpuis(diff_dzpuis) : dec_dzpuis(-diff_dzpuis) ;
186 
187  lbase.sx() ;
188  set_spectral_base(lbase) ;
189 
190  del_deriv() ; // Delete the derived members
191 
192  return ;
193 }
194 
195  //---------------------------//
196  // div_r_ced //
197  //---------------------------//
198 
200 
201  mp->div_r_zec(*this) ; // Call of the appropriate routine of the mapping
202 
203  del_deriv() ; // Delete the derived members
204 
205 }
206 
207  //---------------------------//
208  // mult_r //
209  //---------------------------//
210 
212 
213  mp->mult_r(*this) ; // Call of the appropriate routine of the mapping
214 
215  del_deriv() ; // Delete the derived members
216 
217 }
218 
219  //---------------------//
220  // mult_r_dzpuis //
221  //---------------------//
222 
223 
224 void Scalar::mult_r_dzpuis(int ced_mult_r) {
225 
226  assert (etat != ETATNONDEF) ;
227 
228  Base_val lbase = va.base ;
229 
230  if (etat != ETATZERO) {
231 
232  assert((etat == ETATQCQ) || (etat == ETATUN)) ;
233 
234  set_etat_qcq() ;
235 
236  int nzm1 = mp->get_mg()->get_nzone() - 1 ; // index of the CED
237  bool ced = mp->get_mg()->get_type_r(nzm1) == UNSURR ;
238  Scalar uu_ext(*mp) ;
239 
240  if (ced) {// Copy of the CED part of *this into uu_ext
241  uu_ext.allocate_all() ;
242  uu_ext.annule(0,nzm1-1) ; // zero in all domains but the CED
243  uu_ext.set_domain(nzm1) = domain(nzm1) ;
244  uu_ext.set_spectral_base(va.get_base()) ;
245 
246  // Division by r in all domains but the CED
247  annule(nzm1, nzm1) ; // zero in the CED
248  }
249  mult_r() ;
250 
251  if (ced) {// Add the CED part
252  set_domain(nzm1) = uu_ext.domain(nzm1) ;
253  dzpuis -= 1 ;
254  }
255  }
256 
257  int diff_dzpuis = ced_mult_r - dzpuis ;
258  (diff_dzpuis >= 0) ? inc_dzpuis(diff_dzpuis) : dec_dzpuis(-diff_dzpuis) ;
259 
260  lbase.mult_x() ;
261  set_spectral_base(lbase) ;
262 
263  del_deriv() ; // Delete the derived members
264 
265  return ;
266 }
267 
268  //---------------------------//
269  // mult_r_ced //
270  //---------------------------//
271 
273 
274  mp->mult_r_zec(*this) ; // Call of the appropriate routine of the mapping
275 
276  del_deriv() ; // Delete the derived members
277 
278 }
279 
280  //---------------------------//
281  // mult_rsint //
282  //---------------------------//
283 
285 
286  mp->mult_rsint(*this) ; // Call of the appropriate routine of the mapping
287 
288  del_deriv() ; // Delete the derived members
289 
290 }
291 
292  //-------------------------//
293  // mult_rsint_dzpuis //
294  //-------------------------//
295 
296 
297 void Scalar::mult_rsint_dzpuis(int ced_mult_r) {
298 
299  assert (etat != ETATNONDEF) ;
300 
301  Base_val lbase = va.base ;
302  int nzm1 = mp->get_mg()->get_nzone() - 1 ; // index of the CED
303  bool ced = mp->get_mg()->get_type_r(nzm1) == UNSURR ;
304 
305  if (etat != ETATZERO) {
306 
307  assert((etat == ETATQCQ) || (etat == ETATUN)) ;
308 
309  set_etat_qcq() ;
310  Scalar uu_ext(*mp) ;
311 
312  if (ced) {// Copy of the CED part of *this into uu_ext and multiplication by r
313  uu_ext.allocate_all() ;
314  uu_ext.annule(0,nzm1-1) ; // zero in all domains but the CED
315  uu_ext.set_domain(nzm1) = domain(nzm1) ;
316  uu_ext.set_spectral_base(va.get_base()) ;
317  int dzpuis_ext = dzpuis - 1 ;
318  uu_ext.set_dzpuis(dzpuis_ext) ;
319  int diff_dzpuis = ced_mult_r - dzpuis_ext ;
320  (diff_dzpuis >= 0) ? uu_ext.inc_dzpuis(diff_dzpuis)
321  : uu_ext.dec_dzpuis(-diff_dzpuis) ;
322 
323  // Multiplication by sin(theta) in the CED :
324  // what follows does not apply if the mapping is not radial:
325  assert( dynamic_cast<const Map_radial*>(mp) != 0x0 ) ;
326  uu_ext.mult_sint() ;
327 
328  // Multiplication by r sin(theta) in all domains but the CED
329  annule(nzm1, nzm1) ; // zero in the CED
330  }
331  mult_rsint() ;
332 
333  if (ced) // Add the CED part
334  set_domain(nzm1) = uu_ext.domain(nzm1) ;
335  }
336 
337  if (ced) dzpuis = ced_mult_r ;
338 
339  lbase.mult_x() ;
340  lbase.mult_sint() ;
341  set_spectral_base(lbase) ;
342 
343  del_deriv() ; // Delete the derived members
344 
345 }
346 
347  //---------------------------//
348  // div_rsint //
349  //---------------------------//
350 
352 
353  mp->div_rsint(*this) ; // Call of the appropriate routine of the mapping
354 
355  del_deriv() ; // Delete the derived members
356 
357 }
358 
359 
360  //-------------------------//
361  // div_rsint_dzpuis //
362  //-------------------------//
363 
364 
365 void Scalar::div_rsint_dzpuis(int ced_mult_r) {
366 
367  assert (etat != ETATNONDEF) ;
368 
369  Base_val lbase = va.base ;
370  int nzm1 = mp->get_mg()->get_nzone() - 1 ; // index of the CED
371  bool ced = mp->get_mg()->get_type_r(nzm1) == UNSURR ;
372 
373  if (etat != ETATZERO) {
374 
375  assert((etat == ETATQCQ) || (etat == ETATUN)) ;
376 
377  set_etat_qcq() ;
378  Scalar uu_ext(*mp) ;
379 
380  if (ced) {// Copy of the CED part of *this into uu_ext and multiplication by r
381  uu_ext.allocate_all() ;
382  uu_ext.annule(0,nzm1-1) ; // zero in all domains but the CED
383  uu_ext.set_domain(nzm1) = domain(nzm1) ;
384  uu_ext.set_spectral_base(va.get_base()) ;
385  int dzpuis_ext = dzpuis + 1 ;
386  uu_ext.set_dzpuis(dzpuis_ext) ;
387  int diff_dzpuis = ced_mult_r - dzpuis_ext ;
388  (diff_dzpuis >= 0) ? uu_ext.inc_dzpuis(diff_dzpuis)
389  : uu_ext.dec_dzpuis(-diff_dzpuis) ;
390 
391  // Division by sin(theta) in the CED :
392  // what follows does not apply if the mapping is not radial:
393  assert( dynamic_cast<const Map_radial*>(mp) != 0x0 ) ;
394  uu_ext.div_sint() ;
395 
396  // Division by r sin(theta) in all domains but the CED
397  annule(nzm1, nzm1) ; // zero in the CED
398  }
399  div_rsint() ;
400 
401  if (ced) // Add the CED part
402  set_domain(nzm1) = uu_ext.domain(nzm1) ;
403 
404  }
405  if (ced)
406  dzpuis = ced_mult_r ;
407 
408  lbase.sx() ;
409  lbase.ssint() ;
410  set_spectral_base(lbase) ;
411 
412  del_deriv() ; // Delete the derived members
413 
414 }
415 
416 
417  //-----------------------//
418  // dec_dzpuis //
419  //-----------------------//
420 
421 void Scalar::dec_dzpuis(int decrem) {
422 
423  if (decrem == 0) return ;
424 
425  if (etat == ETATZERO) {
426 //## dzpuis -= decrem ; // a voir...
427  return ;
428  }
429 
430  switch (decrem) {
431 
432  case 0 : {
433  break ;
434  }
435 
436  case 1 : {
437  mp->dec_dzpuis(*this) ;
438  break ;
439  }
440 
441  case 2 : {
442  mp->dec2_dzpuis(*this) ;
443  break ;
444  }
445 
446  case 3 : {
447  mp->dec2_dzpuis(*this) ;
448  mp->dec_dzpuis(*this) ;
449  break ;
450  }
451 
452  case 4 : {
453  mp->dec2_dzpuis(*this) ;
454  mp->dec2_dzpuis(*this) ;
455  break ;
456  }
457 
458  default : {
459  cout << "Scalar::dec_dzpuis : unexpected value of decrem !"
460  << endl << " decrem = " << decrem << endl ;
461  abort() ;
462  break ;
463  }
464  }
465  del_deriv() ;
466 
467 }
468 
469  //-----------------------//
470  // inc_dzpuis //
471  //-----------------------//
472 
473 void Scalar::inc_dzpuis(int inc) {
474 
475  if (inc == 0) return ;
476 
477  if (etat == ETATZERO) {
478 //## dzpuis += inc ; // a voir ...
479  return ;
480  }
481 
482  switch (inc) {
483 
484  case 0 : {
485  break ;
486  }
487 
488  case 1 : {
489  mp->inc_dzpuis(*this) ;
490  break ;
491  }
492 
493  case 2 : {
494  mp->inc2_dzpuis(*this) ;
495  break ;
496  }
497 
498  case 3 : {
499  mp->inc_dzpuis(*this) ;
500  mp->inc2_dzpuis(*this) ;
501  break ;
502  }
503 
504  case 4 : {
505  mp->inc2_dzpuis(*this) ;
506  mp->inc2_dzpuis(*this) ;
507  break ;
508  }
509 
510  default : {
511  cout << "Scalar::inc_dzpuis : unexpected value of inc !"
512  << endl << " inc = " << inc << endl ;
513  abort() ;
514  break ;
515  }
516  }
517  del_deriv() ;
518 
519 }
520 
521 
522 
523 }
void mult_r()
Multiplication by r everywhere; dzpuis is not changed.
void sx()
The basis is transformed as with a multiplication.
virtual void annule(int l_min, int l_max)
Sets the Scalar to zero in several domains.
Definition: scalar.C:397
const Tbl & domain(int l) const
Read-only of the value in a given domain.
Definition: scalar.h:631
Lorene prototypes.
Definition: app_hor.h:67
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:783
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:393
void mult_sint()
Multiplication by .
virtual void inc_dzpuis(Scalar &) const =0
Increases by 1 the value of dzpuis of a Scalar and changes accordingly its values in the compactifi...
virtual void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
Definition: scalar.C:371
virtual void mult_rsint(Scalar &) const =0
Multiplication by of a Scalar.
int dzpuis
Power of r by which the quantity represented by this must be divided in the compactified external do...
Definition: scalar.h:409
virtual void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: scalar.C:359
Tbl & set_domain(int l)
Read/write of the value in a given domain.
Definition: scalar.h:621
virtual void div_r_zec(Scalar &) const =0
Division by r (in the compactified external domain only) of a Scalar.
void set_dzpuis(int)
Modifies the dzpuis flag.
Definition: scalar.C:814
virtual void dec2_dzpuis(Scalar &) const =0
Decreases by 2 the value of dzpuis of a Scalar and changes accordingly its values in the compactifi...
void div_r()
Division by r everywhere; dzpuis is not changed.
virtual void del_deriv() const
Logical destructor of the derivatives.
Definition: scalar.C:293
virtual void div_rsint(Scalar &) const =0
Division by of a Scalar.
virtual void inc_dzpuis(int inc=1)
Increases by inc units the value of dzpuis and changes accordingly the values of the Scalar in the co...
Base_val base
Bases on which the spectral expansion is performed.
Definition: valeur.h:315
void mult_r_ced()
Multiplication by r in the compactified external domain (CED), the dzpuis flag is not changed...
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
Valeur va
The numerical value of the Scalar.
Definition: scalar.h:411
void div_rsint_dzpuis(int ced_mult_r)
Division by but with the output flag dzpuis set to ced_mult_r .
void mult_rsint()
Multiplication by everywhere; dzpuis is not changed.
void ssint()
The basis is transformed as with a multiplication.
void set_spectral_base(const Base_val &)
Sets the spectral bases of the Valeur va
Definition: scalar.C:803
virtual void mult_r(Scalar &uu) const =0
Multiplication by r of a Scalar , the dzpuis of uu is not changed.
virtual void inc2_dzpuis(Scalar &) const =0
Increases by 2 the value of dzpuis of a Scalar and changes accordingly its values in the compactifi...
Bases of the spectral expansions.
Definition: base_val.h:325
int etat
The logical state ETATNONDEF (undefined), ETATZERO (null), ETATUN (one), or ETATQCQ (ordinary)...
Definition: scalar.h:402
void mult_x()
The basis is transformed as with a multiplication by .
void div_sint()
Division by .
void div_rsint()
Division by everywhere; dzpuis is not changed.
virtual void mult_r_zec(Scalar &) const =0
Multiplication by r (in the compactified external domain only) of a Scalar.
void mult_rsint_dzpuis(int ced_mult_r)
Multiplication by but with the output flag dzpuis set to ced_mult_r .
void mult_sint()
The basis is transformed as with a multiplication.
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
Definition: grilles.h:491
virtual void dec_dzpuis(Scalar &) const =0
Decreases by 1 the value of dzpuis of a Scalar and changes accordingly its values in the compactifi...
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition: tensor.h:301
void div_r_dzpuis(int ced_mult_r)
Division by r everywhere but with the output flag dzpuis set to ced_mult_r .
void div_r_ced()
Division by r in the compactified external domain (CED), the dzpuis flag is not changed.
virtual void div_r(Scalar &) const =0
Division by r of a Scalar.
virtual void dec_dzpuis(int dec=1)
Decreases by dec units the value of dzpuis and changes accordingly the values of the Scalar in the co...
void mult_r_dzpuis(int ced_mult_r)
Multiplication by r everywhere but with the output flag dzpuis set to ced_mult_r ...
const Base_val & get_base() const
Return the bases for spectral expansions (member base )
Definition: valeur.h:490