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