LORENE
valeur_coef_i.C
1 /*
2  * Computations of the values at the collocation points from the spectral
3  * coefficients
4  *
5  */
6 
7 /*
8  * Copyright (c) 1999-2003 Eric Gourgoulhon
9  *
10  * This file is part of LORENE.
11  *
12  * LORENE is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
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 /*
32  * $Id: valeur_coef_i.C,v 1.18 2016/12/05 16:18:20 j_novak Exp $
33  * $Log: valeur_coef_i.C,v $
34  * Revision 1.18 2016/12/05 16:18:20 j_novak
35  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
36  *
37  * Revision 1.17 2014/10/13 08:53:49 j_novak
38  * Lorene classes and functions now belong to the namespace Lorene.
39  *
40  * Revision 1.16 2014/10/06 15:13:22 j_novak
41  * Modified #include directives to use c++ syntax.
42  *
43  * Revision 1.15 2013/06/06 15:31:33 j_novak
44  * Functions to compute Legendre coefficients (not fully tested yet).
45  *
46  * Revision 1.14 2012/01/17 15:08:02 j_penner
47  * using MAX_BASE_2 for the phi coordinate
48  *
49  * Revision 1.13 2009/10/23 12:56:29 j_novak
50  * New base T_LEG_MI
51  *
52  * Revision 1.12 2009/10/13 13:49:58 j_novak
53  * New base T_LEG_MP.
54  *
55  * Revision 1.11 2009/10/08 16:23:14 j_novak
56  * Addition of new bases T_COS and T_SIN.
57  *
58  * Revision 1.10 2008/10/07 15:01:58 j_novak
59  * The case nt=1 is now treated separately.
60  *
61  * Revision 1.9 2007/12/11 15:28:25 jl_cornou
62  * Jacobi(0,2) polynomials partially implemented
63  *
64  * Revision 1.8 2004/11/23 15:17:19 m_forot
65  * Added the bases for the cases without any equatorial symmetry
66  * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
67  *
68  * Revision 1.7 2004/08/24 09:14:52 p_grandclement
69  * Addition of some new operators, like Poisson in 2d... It now requieres the
70  * GSL library to work.
71  *
72  * Also, the way a variable change is stored by a Param_elliptic is changed and
73  * no longer uses Change_var but rather 2 Scalars. The codes using that feature
74  * will requiere some modification. (It should concern only the ones about monopoles)
75  *
76  * Revision 1.6 2003/10/13 20:51:25 e_gourgoulhon
77  * Replaced malloc by new
78  *
79  * Revision 1.5 2003/09/17 12:30:22 j_novak
80  * New checks for changing to T_LEG* bases.
81  *
82  * Revision 1.4 2003/09/16 13:07:41 j_novak
83  * New files for coefficient trnasformation to/from the T_LEG_II base.
84  *
85  * Revision 1.3 2002/11/12 17:44:35 j_novak
86  * Added transformation function for T_COS basis.
87  *
88  * Revision 1.2 2002/10/16 14:37:15 j_novak
89  * Reorganization of #include instructions of standard C++, in order to
90  * use experimental version 3 of gcc.
91  *
92  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
93  * LORENE
94  *
95  * Revision 2.9 2000/10/04 14:41:40 eric
96  * Ajout des bases T_LEG_IP et T_LEG_PI
97  *
98  * Revision 2.8 2000/09/07 15:14:44 eric
99  * Ajout de la base P_COSSIN_I
100  *
101  * Revision 2.7 2000/08/16 10:33:04 eric
102  * Suppression de Mtbl::dzpuis.
103  *
104  * Revision 2.6 1999/12/16 16:41:48 phil
105  * *** empty log message ***
106  *
107  * Revision 2.5 1999/11/30 12:43:03 eric
108  * Valeur::base est desormais du type Base_val et non plus Base_val*.
109  *
110  * Revision 2.4 1999/10/28 07:44:20 eric
111  * Modif commentaires.
112  *
113  * Revision 2.3 1999/10/13 15:51:33 eric
114  * Anglisation.
115  *
116  * Revision 2.2 1999/06/22 15:10:02 phil
117  * ajout de dzpuis
118  *
119  * Revision 2.1 1999/02/22 15:40:25 hyc
120  * *** empty log message ***
121  *
122  *
123  * $Header: /cvsroot/Lorene/C++/Source/Valeur/valeur_coef_i.C,v 1.18 2016/12/05 16:18:20 j_novak Exp $
124  *
125  */
126 
127 #include <cmath>
128 
129 // Header Lorene
130 #include "valeur.h"
131 #include "proto.h"
132 
133 namespace Lorene {
134 void c_est_pas_fait(char * ) ;
135 
136 void ipasprevu_r(const int*, const int*, double*, const int*, double*) ;
137 void ipasprevu_t(const int*, const int*, double*, const int*, double*) ;
138 void ipasprevu_p(const int* , const int* , const int* , double* , double* ) ;
139 void ibase_non_def_r(const int*, const int*, double*, const int*, double*) ;
140 void ibase_non_def_t(const int*, const int*, double*, const int*, double*) ;
141 void ibase_non_def_p(const int* , const int* , const int* , double* , double* ) ;
142 
143 void Valeur::coef_i() const {
144 
145  // Variables statiques
146  static void (*invcf_r[MAX_BASE])(const int*, const int*, double*, const int*, double*) ;
147  static void (*invcf_t[MAX_BASE])(const int*, const int*, double*, const int*, double*) ;
148  static void (*invcf_p[MAX_BASE_2])(const int* , const int* , const int*, double* , double* ) ;
149  static int premier_appel = 1 ;
150 
151  // Premier appel
152  if (premier_appel) {
153  premier_appel = 0 ;
154 
155  for (int i=0; i<MAX_BASE; i++) {
156  invcf_r[i] = ipasprevu_r ;
157  invcf_t[i] = ipasprevu_t ;
158  if(i%2==0){
159  invcf_p[i/2] = ipasprevu_p ; // saves a loop
160  }
161  }
162 
163  invcf_r[NONDEF] = ibase_non_def_r ;
164  invcf_r[R_CHEB >> TRA_R] = circheb ;
165  invcf_r[R_CHEBU >> TRA_R] = circheb ;
166  invcf_r[R_CHEBP >> TRA_R] = circhebp ;
167  invcf_r[R_CHEBI >> TRA_R] = circhebi ;
168  invcf_r[R_CHEBPIM_P >> TRA_R] = circhebpimp ;
169  invcf_r[R_CHEBPIM_I >> TRA_R] = circhebpimi ;
170  invcf_r[R_CHEBPI_P >> TRA_R] = circhebpip ;
171  invcf_r[R_CHEBPI_I >> TRA_R] = circhebpii ;
172  invcf_r[R_LEG >> TRA_R] = cirleg ;
173  invcf_r[R_LEGP >> TRA_R] = cirlegp ;
174  invcf_r[R_LEGI >> TRA_R] = cirlegi ;
175  invcf_r[R_JACO02 >> TRA_R] = cirjaco02 ;
176 
177  invcf_t[NONDEF] = ibase_non_def_t ;
178  invcf_t[T_COS >> TRA_T] = citcos ;
179  invcf_t[T_SIN >> TRA_T] = citsin ;
180  invcf_t[T_COS_P >> TRA_T] = citcosp ;
181  invcf_t[T_COS_I >> TRA_T] = citcosi ;
182  invcf_t[T_SIN_P >> TRA_T] = citsinp ;
183  invcf_t[T_SIN_I >> TRA_T] = citsini ;
184  invcf_t[T_COSSIN_CP >> TRA_T] = citcossincp ;
185  invcf_t[T_COSSIN_SI >> TRA_T] = citcossinsi ;
186  invcf_t[T_COSSIN_SP >> TRA_T] = citcossinsp ;
187  invcf_t[T_COSSIN_CI >> TRA_T] = citcossinci ;
188  invcf_t[T_COSSIN_S >> TRA_T] = citcossins ;
189  invcf_t[T_COSSIN_C >> TRA_T] = citcossinc ;
190  invcf_t[T_LEG_P >> TRA_T] = citlegp ;
191  invcf_t[T_LEG_PP >> TRA_T] = citlegpp ;
192  invcf_t[T_LEG_I >> TRA_T] = citlegi ;
193  invcf_t[T_LEG_IP >> TRA_T] = citlegip ;
194  invcf_t[T_LEG_PI >> TRA_T] = citlegpi ;
195  invcf_t[T_LEG_II >> TRA_T] = citlegii ;
196  invcf_t[T_LEG_MP >> TRA_T] = citlegmp ;
197  invcf_t[T_LEG_MI >> TRA_T] = citlegmi ;
198  invcf_t[T_LEG >> TRA_T] = citleg ;
199 
200  invcf_p[NONDEF] = ibase_non_def_p ;
201  invcf_p[P_COSSIN >> TRA_P] = cipcossin ;
202  invcf_p[P_COSSIN_P >> TRA_P] = cipcossin ;
203  invcf_p[P_COSSIN_I >> TRA_P] = cipcossini ;
204 
205  } // fin des operation de premier appel
206 
207  //------------------//
208  // DEBUT DU CALCUL //
209  //------------------//
210 
211  // Tout null ?
212  if (etat == ETATZERO) {
213  return ;
214  }
215 
216  // Protection
217  assert(etat != ETATNONDEF) ;
218 
219  // Peut-etre rien a faire
220  if (c != 0x0) {
221  return ;
222  }
223 
224  // Il faut bosser
225  assert(c_cf != 0x0) ; // ..si on peut
226  assert(c_cf->base == base) ; // Consistence des bases
227 
228  c = new Mtbl(mg) ;
229  c->set_etat_qcq() ;
230 
231  // Boucles sur les zones
232  int nz = mg->get_nzone() ;
233  for (int l=0; l<nz; l++) {
234 
235  // Initialisation des valeurs de this->c_cf avec celle de this->c :
236  Tbl* f = (c->t)[l] ;
237  const Tbl* cf = (c_cf->t)[l] ;
238 
239  if (cf->get_etat() == ETATZERO) {
240  f->set_etat_zero() ;
241  continue ; // on ne fait rien si le tbl(cf) = 0
242  }
243 
244  f->set_etat_qcq() ;
245 
246  int np = f->get_dim(2) ;
247  int nt = f->get_dim(1) ;
248  int nr = f->get_dim(0) ;
249 
250  int np_c = cf->get_dim(2) ;
251  int nt_c = cf->get_dim(1) ;
252  int nr_c = cf->get_dim(0) ;
253 
254  // Attention a ce qui suit... (deg et dim)
255  int deg[3] ;
256  deg[0] = np ;
257  deg[1] = nt ;
258  deg[2] = nr ;
259 
260  int dimc[3] ;
261  dimc[0] = np_c ;
262  dimc[1] = nt_c ;
263  dimc[2] = nr_c ;
264 
265  // Allocation de l'espace memoire pour le tableau de travail trav
266  int ntot = cf->get_taille() ;
267  double* trav = new double[ntot] ;
268 
269  // On recupere les bases en r, theta et phi :
270  int base_r = ( base.b[l] & MSQ_R ) >> TRA_R ;
271  int base_t = ( base.b[l] & MSQ_T ) >> TRA_T ;
272  int base_p = ( base.b[l] & MSQ_P ) >> TRA_P ;
273  int vbase_t = base.b[l] & MSQ_T ;
274  int vbase_p = base.b[l] & MSQ_P ;
275 
276  assert(base_r < MAX_BASE) ;
277  assert(base_t < MAX_BASE) ;
278  assert(base_p < MAX_BASE_2) ;
279 
280  // Transformation inverse en r:
281  if ( nr == 1 ) {
282  for (int i=0; i<ntot; i++) {
283  trav[i] = cf->t[i] ; // simple recopie cf --> trav
284  }
285  }
286  else {
287  invcf_r[base_r]( deg, dimc, (cf->t), dimc, trav ) ;
288  }
289 
290  // Partie angulaire
291  if ( np == 1) {
292  if (nt==1) {
293  for (int i=0 ; i<f->get_taille() ; i++)
294  f->t[i] = trav[i] ;
295  if ((vbase_t == T_LEG_PP) || (vbase_t == T_LEG_PI) ||
296  (vbase_t == T_LEG_IP) || (vbase_t == T_LEG_II) ||
297  (vbase_t == T_LEG_P) || (vbase_t == T_LEG_I) ||
298  (vbase_t == T_LEG_MP) || (vbase_t == T_LEG_MI) ||
299  (vbase_t == T_LEG) ) {
300 
301  *f /=sqrt(2.) ;
302  }
303  }
304 
305  else {
306  bool pair = ( (vbase_t == T_LEG_PP) || (vbase_t == T_LEG_IP)
307  || (vbase_t == T_LEG_MP) ) ;
308  bool impair = ( (vbase_t == T_LEG_PI) || (vbase_t == T_LEG_II)
309  || (vbase_t == T_LEG_MI)) ;
310 
311  if ((pair && (vbase_p == P_COSSIN_I)) ||
312  (impair && (vbase_p == P_COSSIN_P)) )
313  ipasprevu_t(deg, dimc, trav, deg, (f->t) ) ;
314  else
315  invcf_t[base_t]( deg, dimc, trav, deg, (f->t) ) ;
316  }
317  }
318  else {
319  // Cas 3-D
320  // ...... Transformation inverse en theta:
321  bool pair = ( (vbase_t == T_LEG_PP) || (vbase_t == T_LEG_IP)
322  || (vbase_t == T_LEG_MP) ) ;
323  bool impair = ( (vbase_t == T_LEG_PI) || (vbase_t == T_LEG_II)
324  || (vbase_t == T_LEG_MI) ) ;
325 
326  if ((pair && (vbase_p == P_COSSIN_I)) ||
327  (impair && (vbase_p == P_COSSIN_P)) )
328  ipasprevu_t(deg, dimc, trav, dimc, trav ) ;
329  else
330  invcf_t[base_t]( deg, dimc, trav, dimc, trav ) ;
331  // ...... Transformation inverse en phi:
332  invcf_p[base_p]( deg, dimc, deg, trav, (f->t) ) ;
333  }
334  // Menage
335  delete [] trav ;
336  } // fin de la boucle sur les differentes zones
337 
338 }
339 
340  //------------------------//
341  // Les machins pas prevus //
342  //------------------------//
343 
344 void ipasprevu_r(const int*, const int*, double*, const int*, double*) {
345  cout << "Valeur::coef_i: the required expansion basis in r " << endl ;
346  cout << " is not implemented !" << endl ;
347  abort() ;
348 }
349 
350 void ipasprevu_t(const int*, const int*, double*, const int*, double* ) {
351  cout << "Valeur::coef_i: the required expansion basis in theta " << endl ;
352  cout << " is not implemented !" << endl ;
353  abort() ;
354 }
355 
356 void ipasprevu_p(const int*, const int*, const int*, double*, double* ) {
357  cout << "Valeur::coef_i: the required expansion basis in phi " << endl ;
358  cout << " is not implemented !" << endl ;
359  abort() ;
360 }
361 
362 void ibase_non_def_r(const int*, const int*, double*, const int*, double*) {
363  cout << "Valeur::coef_i: the expansion basis in r is undefined !" << endl ;
364  abort() ;
365 }
366 
367 void ibase_non_def_t(const int*, const int*, double*, const int*, double*) {
368  cout << "Valeur::coef_i: the expansion basis in theta is undefined !"
369  << endl ;
370  abort() ;
371 }
372 
373 void ibase_non_def_p(const int*, const int*, const int*, double*, double*) {
374  cout << "Valeur::coef_i: the expansion basis in phi is undefined !" << endl ;
375  abort() ;
376 }
377 
378 }
#define T_LEG
fct. de Legendre associees
Definition: type_parite.h:236
#define MAX_BASE_2
Smaller maximum bases used for phi (and higher dimensions for now)
Definition: type_parite.h:146
Mtbl_cf * c_cf
Coefficients of the spectral expansion of the function.
Definition: valeur.h:312
#define T_LEG_MP
fct. de Legendre associees avec m pair
Definition: type_parite.h:238
#define P_COSSIN
dev. standart
Definition: type_parite.h:245
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
#define T_LEG_PI
fct. de Legendre associees paires avec m impair
Definition: type_parite.h:224
#define TRA_P
Translation en Phi, used for a bitwise shift (in hex)
Definition: type_parite.h:162
Multi-domain array.
Definition: mtbl.h:118
#define R_CHEBPI_I
Cheb. pair-impair suivant l impair pour l=0.
Definition: type_parite.h:174
#define T_LEG_MI
fct. de Legendre associees avec m impair
Definition: type_parite.h:240
Lorene prototypes.
Definition: app_hor.h:67
#define TRA_T
Translation en Theta, used for a bitwise shift (in hex)
Definition: type_parite.h:160
void coef_i() const
Computes the physical value of *this.
#define MSQ_P
Extraction de l&#39;info sur Phi.
Definition: type_parite.h:156
#define T_COS
dev. cos seulement
Definition: type_parite.h:196
#define T_COSSIN_SP
sin pair-cos impair alternes, sin pour m=0
Definition: type_parite.h:210
int get_etat() const
Gives the logical state.
Definition: tbl.h:414
#define R_LEGP
base de Legendre paire (rare) seulement
Definition: type_parite.h:184
#define R_LEGI
base de Legendre impaire (rare) seulement
Definition: type_parite.h:186
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
Definition: type_parite.h:188
#define T_SIN
dev. sin seulement
Definition: type_parite.h:198
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
const Mg3d * mg
Multi-grid Mgd3 on which this is defined.
Definition: valeur.h:302
#define T_LEG_I
fct. de Legendre associees impaires
Definition: type_parite.h:220
#define T_COS_I
dev. cos seulement, harmoniques impaires
Definition: type_parite.h:204
#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
#define T_COS_P
dev. cos seulement, harmoniques paires
Definition: type_parite.h:200
#define MSQ_T
Extraction de l&#39;info sur Theta.
Definition: type_parite.h:154
#define T_COSSIN_C
dev. cos-sin alternes, cos pour m=0
Definition: type_parite.h:192
Base_val base
Bases on which the spectral expansion is performed.
Definition: valeur.h:315
double * t
The array of double.
Definition: tbl.h:176
Mtbl * c
Values of the function at the points of the multi-grid.
Definition: valeur.h:309
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
#define T_SIN_P
dev. sin seulement, harmoniques paires
Definition: type_parite.h:202
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
int get_dim(int i) const
Gives the i-th dimension (ie dim.dim[i])
Definition: tbl.h:423
#define T_COSSIN_SI
sin impair-cos pair alternes, sin pour m=0
Definition: type_parite.h:214
#define T_LEG_IP
fct. de Legendre associees impaires avec m pair
Definition: type_parite.h:222
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: mtbl.C:302
#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
#define T_LEG_P
fct. de Legendre associees paires
Definition: type_parite.h:216
#define R_CHEBPI_P
Cheb. pair-impair suivant l pair pour l=0.
Definition: type_parite.h:172
void c_est_pas_fait(const char *)
Helpful function to say something is not implemented yet.
#define NONDEF
base inconnue
Definition: type_parite.h:150
#define T_COSSIN_CI
cos impair-sin pair alternes, cos pour m=0
Definition: type_parite.h:212
int get_taille() const
Gives the total size (ie dim.taille)
Definition: tbl.h:417
Base_val base
Bases of the spectral expansions.
Definition: mtbl_cf.h:210
int etat
Logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition: valeur.h:305
#define P_COSSIN_I
dev. sur Phi = 2*phi, freq. impaires
Definition: type_parite.h:249
Basic array class.
Definition: tbl.h:164
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
#define P_COSSIN_P
dev. sur Phi = 2*phi, freq. paires
Definition: type_parite.h:247
#define T_LEG_II
fct. de Legendre associees impaires avec m impair
Definition: type_parite.h:226
Tbl ** t
Array (size nzone ) of pointers on the Tbl &#39;s.
Definition: mtbl.h:132
#define T_COSSIN_CP
cos pair-sin impair alternes, cos pour m=0
Definition: type_parite.h:208
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
#define T_SIN_I
dev. sin seulement, harmoniques impaires
Definition: type_parite.h:206
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
#define T_LEG_PP
fct. de Legendre associees paires avec m pair
Definition: type_parite.h:218
#define T_COSSIN_S
dev. cos-sin alternes, sin pour m=0
Definition: type_parite.h:194
#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