LORENE
map_af_integ.C
1 /*
2  * Method of the class Map_af for computing the integral of a Cmp over
3  * all space.
4  */
5 
6 /*
7  * Copyright (c) 1999-2003 Eric Gourgoulhon
8  *
9  * This file is part of LORENE.
10  *
11  * LORENE is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * LORENE is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with LORENE; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  *
25  */
26 
27 
28 
29 
30 /*
31  * $Id: map_af_integ.C,v 1.10 2016/12/05 16:17:56 j_novak Exp $
32  * $Log: map_af_integ.C,v $
33  * Revision 1.10 2016/12/05 16:17:56 j_novak
34  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
35  *
36  * Revision 1.9 2014/10/13 08:53:02 j_novak
37  * Lorene classes and functions now belong to the namespace Lorene.
38  *
39  * Revision 1.8 2014/10/06 15:13:12 j_novak
40  * Modified #include directives to use c++ syntax.
41  *
42  * Revision 1.7 2009/10/08 16:20:47 j_novak
43  * Addition of new bases T_COS and T_SIN.
44  *
45  * Revision 1.6 2008/08/27 08:48:05 jl_cornou
46  * Added R_JACO02 case
47  *
48  * Revision 1.5 2007/10/05 15:56:19 j_novak
49  * Addition of new bases for the non-symmetric case in theta.
50  *
51  * Revision 1.4 2003/12/19 16:21:43 j_novak
52  * Shadow hunt
53  *
54  * Revision 1.3 2003/10/19 19:58:15 e_gourgoulhon
55  * Access to Base_val::b now via Base_val::get_b().
56  *
57  * Revision 1.2 2003/10/15 10:35:27 e_gourgoulhon
58  * Changed cast (double *) into static_cast<double*>.
59  *
60  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
61  * LORENE
62  *
63  * Revision 1.2 2000/01/28 16:09:37 eric
64  * Remplacement du ci.get_dzpuis() == 4 par ci.check_dzpuis(4).
65  *
66  * Revision 1.1 1999/12/09 10:45:43 eric
67  * Initial revision
68  *
69  *
70  * $Header: /cvsroot/Lorene/C++/Source/Map/map_af_integ.C,v 1.10 2016/12/05 16:17:56 j_novak Exp $
71  *
72  */
73 
74 // Headers C
75 #include <cstdlib>
76 #include <cmath>
77 
78 
79 // Headers Lorene
80 #include "map.h"
81 #include "cmp.h"
82 
83 namespace Lorene {
84 Tbl* Map_af::integrale(const Cmp& ci) const {
85 
86  static double* cx_tcp = 0 ; // Coefficients theta, dev. en cos(2l theta)
87  static double* cx_rrp = 0 ; // Coefficients r rare, dev. en T_{2i}
88  static double* cx_rf_x2 = 0 ; // Coefficients r fin, int. en r^2
89  static double* cx_rf_x = 0 ; // Coefficients r fin, int en r
90  static double* cx_rf = 0 ; // Coefficients r fin, int en cst.
91 
92  static int nt_cp_pre = 0 ;
93  static int nr_p_pre = 0 ;
94  static int nr_f_pre = 0 ;
95 
96  assert(ci.get_etat() != ETATNONDEF) ;
97 
98  int nz = mg->get_nzone() ;
99 
100  Tbl* resu = new Tbl(nz) ;
101 
102  if (ci.get_etat() == ETATZERO) {
103  resu->annule_hard() ;
104  return resu ;
105  }
106 
107  assert( ci.get_etat() == ETATQCQ ) ;
108 
109  (ci.va).coef() ; // The spectral coefficients are required
110 
111  const Mtbl_cf* p_mti = (ci.va).c_cf ;
112 
113  assert( ci.check_dzpuis(4) ) ; // dzpuis must be equal to 4
114 
115  assert(p_mti->get_etat() == ETATQCQ) ;
116 
117  resu->set_etat_qcq() ; // Allocates the memory for the array of double
118 
119  // Loop of the various domains
120  // ---------------------------
121  for (int l=0 ; l<nz ; l++) {
122 
123  const Tbl* p_tbi = p_mti->t[l] ;
124 
125  if ( p_tbi->get_etat() == ETATZERO ) {
126  resu->t[l] = 0 ;
127  }
128  else { // Case where the computation must be done
129 
130  assert( p_tbi->get_etat() == ETATQCQ ) ;
131 
132  int nt = mg->get_nt(l) ;
133  int nr = mg->get_nr(l) ;
134 
135  int base = (p_mti->base).get_b(l) ;
136  int base_r = base & MSQ_R ;
137  int base_t = base & MSQ_T ;
138  int base_p = base & MSQ_P ;
139 
140  // ----------------------------------
141  // Integration on theta -> array in r
142  // ----------------------------------
143 
144  double* s_tr = new double[nr] ; // Partial integral on theta
145  double* x_spec = p_tbi->t ; // Pointer on the spectral coefficients
146 
147  switch (base_t) {
148 
149  case T_COS_P: case T_COSSIN_CP: {
150  if (nt > nt_cp_pre) { // Initialization of factors for summation
151  nt_cp_pre = nt ;
152  cx_tcp
153  = static_cast<double*>(realloc(cx_tcp, nt*sizeof(double))) ;
154  for (int j=0 ; j<nt ; j++) {
155  cx_tcp[j] = 2./(1. - 4.*j*j) ; // Factor 2 symmetry
156  }
157  }
158 
159  // Summation :
160  for (int i=0 ; i<nr ; i++) s_tr[i] = 0 ;
161  for (int j=0 ; j<nt ; j++) {
162  for (int i=0 ; i<nr ; i++) {
163  s_tr[i] += cx_tcp[j] * x_spec[i] ;
164  }
165  x_spec += nr ; // Next theta
166  }
167  break ;
168  }
169  case T_COSSIN_C: case T_COS: {
170  // Summation :
171  for (int i=0 ; i<nr ; i++) s_tr[i] = 0 ;
172  for (int j=0 ; j<nt ; j++) {
173  if ((j%2)==0)
174  for (int i=0 ; i<nr ; i++) {
175  s_tr[i] += (2. / (1.-j*j)) * x_spec[i] ;
176  }
177  x_spec += nr ; // Next theta
178  }
179  break ;
180  }
181  default: {
182  cout << "Map_af::integrale: unknown theta basis ! " << endl ;
183  abort () ;
184  break ;
185  }
186 
187  } // End of the various cases on base_t
188 
189  // ----------------
190  // Integration on r
191  // ----------------
192 
193  double som = 0 ;
194  double som_x2 = 0;
195  double som_x = 0 ;
196  double som_c = 0 ;
197 
198  switch(base_r) {
199  case R_CHEBP: case R_CHEBPIM_P: case R_CHEBPI_P :{
200  assert(beta[l] == 0) ;
201  if (nr > nr_p_pre) { // Initialization of factors for summation
202  nr_p_pre = nr ;
203  cx_rrp = static_cast<double*>(realloc(cx_rrp, nr*sizeof(double))) ;
204  for (int i=0 ; i<nr ; i++) {
205  cx_rrp[i] = (3. - 4.*i*i) /
206  (9. - 40. * i*i + 16. * i*i*i*i) ;
207  }
208  }
209 
210  for (int i=0 ; i<nr ; i++) {
211  som += cx_rrp[i] * s_tr[i] ;
212  }
213  double rmax = alpha[l] ;
214  som *= rmax*rmax*rmax ;
215  break ;
216  }
217 
218  case R_CHEB: {
219  if (nr > nr_f_pre) { // Initialization of factors for summation
220  nr_f_pre = nr ;
221  cx_rf_x2 = static_cast<double*>(realloc(cx_rf_x2, nr*sizeof(double))) ;
222  cx_rf_x = static_cast<double*>(realloc(cx_rf_x, nr*sizeof(double))) ;
223  cx_rf = static_cast<double*>(realloc(cx_rf, nr*sizeof(double))) ;
224  for (int i=0 ; i<nr ; i +=2 ) {
225  cx_rf_x2[i] = 2.*(3. - i*i)/(9. - 10. * i*i + i*i*i*i) ;
226  cx_rf_x[i] = 0 ;
227  cx_rf[i] = 2./(1. - i*i) ;
228  }
229  for (int i=1 ; i<nr ; i +=2 ) {
230  cx_rf_x2[i] = 0 ;
231  cx_rf_x[i] = 2./(4. - i*i) ;
232  cx_rf[i] = 0 ;
233  }
234  }
235 
236  for (int i=0 ; i<nr ; i +=2 ) {
237  som_x2 += cx_rf_x2[i] * s_tr[i] ;
238  }
239  for (int i=1 ; i<nr ; i +=2 ) {
240  som_x += cx_rf_x[i] * s_tr[i] ;
241  }
242  for (int i=0 ; i<nr ; i +=2 ) {
243  som_c += cx_rf[i] * s_tr[i] ;
244  }
245  double a = alpha[l] ;
246  double b = beta[l] ;
247  som = a*a*a * som_x2 + 2.*a*a*b * som_x + a*b*b * som_c ;
248  break ;
249  }
250 
251  case R_JACO02: {
252  if (nr > nr_f_pre) { // Initialization of factors for summation
253  nr_f_pre = nr ;
254  cx_rf_x2 = static_cast<double*>(realloc(cx_rf_x2, nr*sizeof(double))) ;
255  cx_rf_x = static_cast<double*>(realloc(cx_rf_x, nr*sizeof(double))) ;
256  cx_rf = static_cast<double*>(realloc(cx_rf, nr*sizeof(double))) ;
257  double signe = 1 ;
258  for (int i=0 ; i<nr ; i +=1 ) {
259  cx_rf_x2[i] = 0 ;
260  cx_rf_x[i] = 2*signe/double(i+1)/double(i+2);
261  cx_rf[i] = 2*signe ;
262  signe = - signe ;
263  }
264  cx_rf_x2[0] = double(8)/double(3) ;
265  }
266 
267  for (int i=0 ; i<nr ; i +=1 ) {
268  som_x2 += cx_rf_x2[i] * s_tr[i] ;
269  }
270  for (int i=1 ; i<nr ; i +=1 ) {
271  som_x += cx_rf_x[i] * s_tr[i] ;
272  }
273  for (int i=0 ; i<nr ; i +=1 ) {
274  som_c += cx_rf[i] * s_tr[i] ;
275  }
276  double a = alpha[l] ;
277  double b = beta[l] ;
278  assert(b == a) ;
279  som = a*a*a * som_x2 + 2.*a*a*(b-a) * som_x + a*(b-a)*(b-a) * som_c ;
280  break ;
281  }
282 
283  case R_CHEBU: {
284  assert(beta[l] == - alpha[l]) ;
285  if (nr > nr_f_pre) { // Initialization of factors for summation
286  nr_f_pre = nr ;
287  cx_rf = static_cast<double*>(realloc(cx_rf, nr*sizeof(double))) ;
288  for (int i=0 ; i<nr ; i +=2 ) {
289  cx_rf[i] = 2./(1. - i*i) ;
290  }
291  for (int i=1 ; i<nr ; i +=2 ) {
292  cx_rf[i] = 0 ;
293  }
294  }
295 
296  for (int i=0 ; i<nr ; i +=2 ) {
297  som_c += cx_rf[i] * s_tr[i] ;
298  }
299  som = - alpha[l] * som_c ;
300  break ;
301  }
302 
303 
304  default: {
305  cout << "Map_af::integrale: unknown r basis ! " << endl ;
306  abort () ;
307  break ;
308  }
309 
310  } // End of the various cases on base_r
311 
312  // ------------------
313  // Integration on phi
314  // ------------------
315 
316  switch (base_p) {
317 
318  case P_COSSIN: {
319  som *= 2. * M_PI ;
320  break ;
321  }
322 
323  case P_COSSIN_P: {
324  som *= 2. * M_PI ;
325  break ;
326  }
327 
328  default: {
329  cout << "Map_af::integrale: unknown phi basis ! " << endl ;
330  abort () ;
331  break ;
332  }
333 
334  } // End of the various cases on base_p
335 
336  // Final result for this domain:
337  // ----------------------------
338 
339  resu->t[l] = som ;
340  delete [] s_tr ;
341 
342  } // End of the case where the computation must be done
343 
344 
345  } // End of the loop onto the domains
346 
347  return resu ;
348 
349 }
350 }
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition: cmp.h:446
#define P_COSSIN
dev. standart
Definition: type_parite.h:245
double * alpha
Array (size: mg->nzone ) of the values of in each domain.
Definition: map.h:2054
Lorene prototypes.
Definition: app_hor.h:67
int get_etat() const
Returns the logical state.
Definition: cmp.h:899
#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
int get_etat() const
Gives the logical state.
Definition: tbl.h:414
virtual Tbl * integrale(const Cmp &) const
Computes the integral over all space of a Cmp.
Definition: map_af_integ.C:84
int get_etat() const
Returns the logical state.
Definition: mtbl_cf.h:466
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
Definition: type_parite.h:188
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
#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
double * t
The array of double.
Definition: tbl.h:176
#define MSQ_R
Extraction de l&#39;info sur R.
Definition: type_parite.h:152
double * beta
Array (size: mg->nzone ) of the values of in each domain.
Definition: map.h:2056
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
#define R_CHEBPIM_P
Cheb. pair-impair suivant m, pair pour m=0.
Definition: type_parite.h:176
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
#define R_CHEBPI_P
Cheb. pair-impair suivant l pair pour l=0.
Definition: type_parite.h:172
Coefficients storage for the multi-domain spectral method.
Definition: mtbl_cf.h:196
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: cmp.C:718
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
#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_COSSIN_CP
cos pair-sin impair alternes, cos pour m=0
Definition: type_parite.h:208
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition: tbl.C:375
Valeur va
The numerical value of the Cmp.
Definition: cmp.h:464
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 R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166