LORENE
map_af_primr.C
1 /*
2  * Method Map_af::primr
3  *
4  * (see file map.h for documentation).
5  *
6  */
7 
8 /*
9  * Copyright (c) 2004 Eric Gourgoulhon
10  *
11  * This file is part of LORENE.
12  *
13  * LORENE is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License version 2
15  * as published by the Free Software Foundation.
16  *
17  * LORENE is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with LORENE; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  */
27 
28 
29 
30 /*
31  * $Id: map_af_primr.C,v 1.10 2021/06/01 14:20:51 j_novak Exp $
32  * $Log: map_af_primr.C,v $
33  * Revision 1.10 2021/06/01 14:20:51 j_novak
34  * Correction of the case without CED: added a test l<nzm1.
35  *
36  * Revision 1.9 2017/02/22 17:11:33 j_novak
37  * Addition of new Legendre basis.
38  *
39  * Revision 1.8 2016/12/05 16:17:57 j_novak
40  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
41  *
42  * Revision 1.7 2014/10/13 08:53:03 j_novak
43  * Lorene classes and functions now belong to the namespace Lorene.
44  *
45  * Revision 1.6 2014/10/06 15:13:12 j_novak
46  * Modified #include directives to use c++ syntax.
47  *
48  * Revision 1.5 2013/04/25 15:46:05 j_novak
49  * Added special treatment in the case np = 1, for type_p = NONSYM.
50  *
51  * Revision 1.4 2007/12/20 09:11:05 jl_cornou
52  * Correction of an error in op_sxpun about Jacobi(0,2) polynomials
53  *
54  * Revision 1.3 2004/07/26 16:02:23 j_novak
55  * Added a flag to specify whether the primitive should be zero either at r=0
56  * or at r going to infinity.
57  *
58  * Revision 1.1 2004/06/14 15:25:34 e_gourgoulhon
59  * First version.
60  *
61  *
62  * $Header: /cvsroot/Lorene/C++/Source/Map/map_af_primr.C,v 1.10 2021/06/01 14:20:51 j_novak Exp $
63  *
64  */
65 
66 
67 // C headers
68 #include <cstdlib>
69 
70 // Lorene headers
71 #include "map.h"
72 #include "tensor.h"
73 
74 namespace Lorene {
75 void _primr_pas_prevu(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
76 void _primr_r_cheb(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
77 void _primr_r_chebp(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
78 void _primr_r_chebi(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
79 void _primr_r_leg(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
80 void _primr_r_legp(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
81 void _primr_r_legi(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
82 void _primr_r_chebpim_p(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
83 void _primr_r_chebpim_i(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
84 void _primr_r_jaco02(const Tbl&, int, const Tbl&, Tbl&, int&, Tbl&) ;
85 
86 void Map_af::primr(const Scalar& uu, Scalar& resu, bool null_infty) const {
87 
88  static void (*prim_domain[MAX_BASE])(const Tbl&, int bin, const Tbl&,
89  Tbl&, int&, Tbl& ) ;
90  static bool first_call = true ;
91 
92  // Initialisation at first call of the array of primitive functions
93  // depending upon the basis in r
94  // ----------------------------------------------------------------
95  if (first_call) {
96  for (int i=0 ; i<MAX_BASE ; i++) prim_domain[i] = _primr_pas_prevu ;
97 
98  prim_domain[R_CHEB >> TRA_R] = _primr_r_cheb ;
99  prim_domain[R_CHEBU >> TRA_R] = _primr_r_cheb ;
100  prim_domain[R_CHEBP >> TRA_R] = _primr_r_chebp ;
101  prim_domain[R_CHEBI >> TRA_R] = _primr_r_chebi ;
102  prim_domain[R_LEG >> TRA_R] = _primr_r_leg ;
103  prim_domain[R_LEGP >> TRA_R] = _primr_r_legp ;
104  prim_domain[R_LEGI >> TRA_R] = _primr_r_legi ;
105  prim_domain[R_CHEBPIM_P >> TRA_R] = _primr_r_chebpim_p ;
106  prim_domain[R_CHEBPIM_I >> TRA_R] = _primr_r_chebpim_i ;
107  prim_domain[R_JACO02 >> TRA_R] = _primr_r_jaco02 ;
108 
109  first_call = false ;
110  }
111 
112  // End of first call operations
113  // ----------------------------
114 
115  assert(uu.get_etat() != ETATNONDEF) ;
116  assert(uu.get_mp().get_mg() == mg) ;
117  assert(resu.get_mp().get_mg() == mg) ;
118 
119  // Special case of vanishing input:
120  if (uu.get_etat() == ETATZERO) {
121  resu.set_etat_zero() ;
122  return ;
123  }
124 
125  // General case
126  assert( (uu.get_etat() == ETATQCQ) || (uu.get_etat() == ETATUN) ) ;
127  assert(uu.check_dzpuis(2)) ;
128 
129  int nz = mg->get_nzone() ;
130  int nzm1 = nz - 1 ;
131  int np = mg->get_np(0) ;
132  int nt = mg->get_nt(0) ;
133 #ifndef NDEBUG
134  for (int l=1; l<nz; l++) {
135  assert (mg->get_np(l) == np) ;
136  assert (mg->get_nt(l) == nt) ;
137  }
138 #endif
139 
140  const Valeur& vuu = uu.get_spectral_va() ;
141  vuu.coef() ;
142 
143  const Mtbl_cf& cuu = *(vuu.c_cf) ;
144  assert(cuu.t != 0x0) ;
145 
146  const Base_val& buu = vuu.get_base() ; // spectral bases of the input
147 
148  resu.set_etat_qcq() ; // result in ordinary state
149  Valeur& vprim = resu.set_spectral_va() ;
150  vprim.set_etat_cf_qcq() ; // allocates the Mtbl_cf for the coefficients
151  // of the result
152  Mtbl_cf& cprim = *(vprim.c_cf) ;
153  cprim.set_etat_qcq() ; // allocates the Tbl's to store the coefficients
154  // of the result in each domain
155 
156  Base_val& bprim = cprim.base ; // spectral bases of the result
157 
158  Tbl val_rmin(np+2,nt) ; // Values of primitive at the left boundary
159  // in the current domain
160  Tbl val_rmax(np+2,nt) ; // same but for the right boundary
161 
162  val_rmin.set_etat_zero() ; // initialisation: primitive = 0 at r=0
163 
164  int lmax = (mg->get_type_r(nzm1) == UNSURR) ? nz-2 : nzm1 ;
165 
166  for (int l=0; l<=lmax; l++) {
167  assert(cuu.t[l] != 0x0) ;
168  assert(cprim.t[l] != 0x0) ;
169  const Tbl& cfuu = *(cuu.t[l]) ;
170  Tbl& cfprim = *(cprim.t[l]) ;
171 
172  int buu_dom = buu.get_b(l) ;
173  int base_r = (buu_dom & MSQ_R) >> TRA_R ;
174 
175  prim_domain[base_r](cfuu, buu_dom, val_rmin, cfprim, bprim.b[l],
176  val_rmax) ;
177 
178  cfprim *= alpha[l] ;
179  if (l<nzm1)
180  val_rmin = alpha[l] * val_rmax / alpha[l+1] ; // for next domain
181  }
182 
183  // Special case of compactified external domain (CED)
184  // --------------------------------------------------
185  if (mg->get_type_r(nzm1) == UNSURR) {
186  val_rmin = - val_rmin ;
187  const Tbl& cfuu = *(cuu.t[nzm1]) ;
188  Tbl& cfprim = *(cprim.t[nzm1]) ;
189 
190  int buu_dom = buu.get_b(nzm1) ;
191  int base_r = (buu_dom & MSQ_R) >> TRA_R ;
192  assert(base_r == R_CHEBU) ;
193 
194  prim_domain[base_r](cfuu, buu_dom, val_rmin, cfprim, bprim.b[nzm1],
195  val_rmax) ;
196 
197  cfprim *= - alpha[nzm1] ;
198  }
199 
200  if (null_infty)
201  for (int k=0; k<np; k++) //## not very elegant!
202  for(int j=0; j<nt; j++)
203  val_rmax.set(k,j) = cprim.val_out_bound_jk(nzm1, j, k) ;
204 
205  // The output spectral bases (set on the Mtbl_cf) are copied to the Valeur:
206  vprim.set_base(bprim) ;
207 
208  if (null_infty)
209  for (int l=0; l<nz; l++) //## not very elegant!
210  for (int k=0; k<np; k++)
211  for(int j=0; j<nt; j++)
212  for (int i=0; i<mg->get_nr(l); i++)
213  vprim.set(l, k, j, i) -= val_rmax(k,j) ;
214 
215 
216 }
217 }
Mtbl_cf * c_cf
Coefficients of the spectral expansion of the function.
Definition: valeur.h:312
virtual void primr(const Scalar &uu, Scalar &resu, bool null_infty) const
Computes the radial primitive which vanishes for .
Definition: map_af_primr.C:86
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:479
void set_etat_cf_qcq()
Sets the logical state to ETATQCQ (ordinary state) for values in the configuration space (Mtbl_cf c_c...
Definition: valeur.C:715
void coef() const
Computes the coeffcients of *this.
Definition: valeur_coef.C:151
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: scalar.C:330
double * alpha
Array (size: mg->nzone ) of the values of in each domain.
Definition: map.h:2054
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
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:393
Values and coefficients of a (real-value) function.
Definition: valeur.h:297
#define R_LEGP
base de Legendre paire (rare) seulement
Definition: type_parite.h:184
int get_etat() const
Returns the logical state ETATNONDEF (undefined), ETATZERO (null) or ETATQCQ (ordinary).
Definition: scalar.h:560
#define R_LEGI
base de Legendre impaire (rare) seulement
Definition: type_parite.h:186
virtual void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: scalar.C:359
void set_base(const Base_val &)
Sets the bases for spectral expansions (member base )
Definition: valeur.C:813
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
Definition: type_parite.h:188
double val_out_bound_jk(int l, int j, int k) const
Computes the angular coefficient of index j,k of the field represented by *this at by means of the s...
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
#define R_CHEBI
base de Cheb. impaire (rare) seulement
Definition: type_parite.h:170
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
int * b
Array (size: nzone ) of the spectral basis in each domain.
Definition: base_val.h:334
#define MSQ_R
Extraction de l&#39;info sur R.
Definition: type_parite.h:152
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: mtbl_cf.C:303
#define R_CHEBPIM_I
Cheb. pair-impair suivant m, impair pour m=0.
Definition: type_parite.h:178
#define R_CHEBPIM_P
Cheb. pair-impair suivant m, pair pour m=0.
Definition: type_parite.h:176
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: tbl.C:350
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition: grilles.h:469
const Mg3d * mg
Pointer on the multi-grid Mgd3 on which this is defined.
Definition: map.h:694
Bases of the spectral expansions.
Definition: base_val.h:325
int get_b(int l) const
Returns the code for the expansion basis in domain no. l.
Definition: base_val.h:392
Coefficients storage for the multi-domain spectral method.
Definition: mtbl_cf.h:196
Base_val base
Bases of the spectral expansions.
Definition: mtbl_cf.h:210
Basic array class.
Definition: tbl.h:164
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:474
Valeur & set_spectral_va()
Returns va (read/write version)
Definition: scalar.h:610
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
Definition: grilles.h:491
bool check_dzpuis(int dzi) const
Returns false if the last domain is compactified and *this is not zero in this domain and dzpuis is n...
Definition: scalar.C:879
const Map & get_mp() const
Returns the mapping.
Definition: tensor.h:874
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
Tbl ** t
Array (size nzone ) of pointers on the Tbl &#39;s which contain the spectral coefficients in each domain...
Definition: mtbl_cf.h:215
const Valeur & get_spectral_va() const
Returns va (read only version)
Definition: scalar.h:607
const Base_val & get_base() const
Return the bases for spectral expansions (member base )
Definition: valeur.h:490
Tbl & set(int l)
Read/write of the value in a given domain (configuration space).
Definition: valeur.h:373
#define R_LEG
base de Legendre ordinaire (fin)
Definition: type_parite.h:182
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166