LORENE
chb_cossinc_leg.C
1 /*
2  * Copyright (c) 1999-2001 Eric Gourgoulhon
3  *
4  * This file is part of LORENE.
5  *
6  * LORENE is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * LORENE is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with LORENE; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 
23 char chb_cossinc_leg_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cossinc_leg.C,v 1.5 2014/10/13 08:53:10 j_novak Exp $" ;
24 
25 /*
26  * Calcule les coefficients du developpement (suivant theta) en fonctions
27  * associees de Legendre P_l^m(cos(theta)) a partir des coefficients du
28  * developpement en cos(j*theta) [m pair] / sin(j * theta) [m impair]
29  * representant une fonction 3-D.
30  *
31  * Entree:
32  * -------
33  * const int* deg : tableau du nombre effectif de degres de liberte dans chacune
34  * des 3 dimensions:
35  * deg[0] = np : nombre de points de collocation en phi
36  * deg[1] = nt : nombre de points de collocation en theta
37  * deg[2] = nr : nombre de points de collocation en r
38  *
39  * const double* cfi : tableau des coefficients c_j du develop. en cos/sin definis
40  * comme suit (a r et phi fixes)
41  *
42  * pour m pair: f(theta) = som_{j=0}^{nt-1} c_j cos( j theta )
43  *
44  * pour m impair: f(theta) = som_{j=0}^{nt-2} c_j sin( j theta )
45  *
46  * L'espace memoire correspondant au pointeur cfi doit etre
47  * nr*nt*(np+2) et doit avoir ete alloue avant
48  * l'appel a la routine.
49  * Le coefficient c_j (0 <= j <= nt-1) doit etre stoke dans le
50  * tableau cfi comme suit
51  * c_j = cfi[ nr*nt* k + i + nr* j ]
52  * ou k et i sont les indices correspondant a
53  * phi et r respectivement: m = k/2.
54  * Pour m impair, c_0 = c_{nt-1} = 0.
55  *
56  * Sortie:
57  * -------
58  * double* cfo : tableau des coefficients a_l du develop. en fonctions de
59  * Legendre associees P_n^m:
60  *
61  * pour m pair: f(theta) =
62  * som_{l=m}^{nt-1} a_l P_{l}^m( cos(theta) )
63  *
64  * pour m impair: f(theta) =
65  * som_{l=m}^{nt-2} a_l P_{l}^m( cos(theta) )
66  *
67  * ou P_n^m(x) represente la fonction de Legendre associee
68  * de degre n et d'ordre m normalisee de facon a ce que
69  *
70  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
71  *
72  * L'espace memoire correspondant au pointeur cfo doit etre
73  * nr*nt*(np+2) et doit avoir ete alloue avant
74  * l'appel a la routine.
75  * Le coefficient a_l (0 <= l <= nt-1) est stoke dans le
76  * tableau cfo comme suit
77  * a_l = cfo[ nr*nt* k + i + nr* l ]
78  * ou k et i sont les indices correspondant a phi et r
79  * respectivement: m = k/2.
80  * NB: pour m pair et l < m, a_l = 0
81  * pour m impair et l < m, a_l = 0
82  *
83  * NB:
84  * ---
85  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
86  */
87 
88 /*
89  * $Id: chb_cossinc_leg.C,v 1.5 2014/10/13 08:53:10 j_novak Exp $
90  * $Log: chb_cossinc_leg.C,v $
91  * Revision 1.5 2014/10/13 08:53:10 j_novak
92  * Lorene classes and functions now belong to the namespace Lorene.
93  *
94  * Revision 1.4 2014/10/06 15:16:00 j_novak
95  * Modified #include directives to use c++ syntax.
96  *
97  * Revision 1.3 2005/02/18 13:14:10 j_novak
98  * Changing of malloc/free to new/delete + suppression of some unused variables
99  * (trying to avoid compilation warnings).
100  *
101  * Revision 1.2 2005/02/16 15:23:23 m_forot
102  * Replace int1d_chebp by int1d_cheb
103  *
104  * Revision 1.1 2004/11/23 15:13:50 m_forot
105  * Added the bases for the cases without any equatorial symmetry
106  * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
107  *
108  *
109  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cossinc_leg.C,v 1.5 2014/10/13 08:53:10 j_novak Exp $
110  *
111  */
112 
113 // headers du C
114 #include <cassert>
115 #include <cstdlib>
116 
117 // Prototypage
118 #include "headcpp.h"
119 #include "proto.h"
120 
121 namespace Lorene {
122 //******************************************************************************
123 
124 void chb_cossinc_leg(const int* deg , const double* cfi, double* cfo) {
125 
126 // Espace de travail realloue eventuellement a chaque appel :
127 
128 int ip, k2, l, jmin, j, i, m ;
129 
130 // Nombres de degres de liberte en phi et theta :
131  int np = deg[0] ;
132  int nt = deg[1] ;
133  int nr = deg[2] ;
134 
135  assert(np < 4*nt) ;
136 
137  // Tableau de travail
138  double* som = new double[nr] ;
139 
140 // Recherche de la matrice de passage cos/sin --> Legendre
141  double* aa = mat_cossinc_leg(np, nt) ;
142 
143 // Increment en m pour la matrice aa :
144  int maa = nt * nt ;
145 
146 //## Test
147 // double* aat = aa ;
148 // for ( m=0; m < np/2+1 ; m++) {
149 // cout << "---------------------------------------" << endl ;
150 // cout << " m = " << m << endl ;
151 // cout << " " << endl ;
152 //
153 // for (l=m/2; l<nt; l++) {
154 // cout << " l = " << l << " : " ;
155 // for (j=0; j<nt; j++) {
156 // cout << aat[nt*l + j] << " " ;
157 // }
158 // cout << endl ;
159 // }
160 // arrete() ;
161 // aat += maa ; // pointeur sur la nouvelle matrice de passage
162 // }
163 //##
164 
165 // Pointeurs de travail :
166  double* resu = cfo ;
167  const double* cc = cfi ;
168 
169 // Increment en phi :
170  int ntnr = nt * nr ;
171 
172 // Indice courant en phi :
173  int k = 0 ;
174 
175 // Ordre des harmoniques du developpement de Fourier en phi :
176  m = 0 ;
177 
178 // --------------
179 // Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3
180 // -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1
181 // k2 = 0 1 0 1
182 
183  for (ip=0; ip < np/4 + 1 ; ip++) {
184 
185 //--------------------------------
186 // Partie m pair
187 //--------------------------------
188 
189 
190  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
191 
192  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
193  // et sin( np/2 phi) a zero
194  for (l=0; l<nt; l++) {
195  for (i=0; i<nr; i++) {
196  *resu = 0 ;
197  resu++ ;
198  }
199  }
200  }
201  else {
202 
203 // Boucle sur l'indice l du developpement en Legendre
204 
205  for (l=0; l<m; l++) {
206  for (i=0; i<nr; i++) {
207  *resu = 0 ;
208  resu++ ;
209  }
210  }
211 // ... produit matriciel (parallelise sur r)
212  for (l=m; l<nt; l++) {
213  for (i=0; i<nr; i++) {
214  som[i] = 0 ;
215  }
216 
217  jmin = ( m == 0 ) ? l : 0 ; // pour m=0, aa_lj = 0 pour j<l
218  for (j=jmin; j<nt; j++) {
219  double amlj = aa[nt*l + j] ;
220  for (i=0; i<nr; i++) {
221  som[i] += amlj * cc[nr*j + i] ;
222  }
223  }
224 
225  for (i=0; i<nr; i++) {
226  *resu = som[i] ;
227  resu++ ;
228  }
229 
230  } // fin de la boucle sur l
231 
232  } // fin du cas k != 1
233 
234 // On passe au phi suivant :
235  cc = cc + ntnr ;
236  k++ ;
237 
238  } // fin de la boucle sur k2
239 
240 // On passe a l'harmonique en phi suivante :
241  m++ ;
242  aa += maa ; // pointeur sur la nouvelle matrice de passage
243 
244 //--------------------------------
245 // Partie m impair
246 //--------------------------------
247 
248  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
249 
250  if ( k == np+1 ) { // On met les coef de
251  // sin( np/2 phi) a zero
252  for (l=0; l<nt; l++) {
253  for (i=0; i<nr; i++) {
254  *resu = 0 ;
255  resu++ ;
256  }
257  }
258  }
259 
260  if (k < np+1) {
261 
262 // Boucle sur l'indice l du developpement en Legendre
263  for (l=0; l<m; l++) {
264  for (i=0; i<nr; i++) {
265  *resu = 0 ;
266  resu++ ;
267  }
268  }
269 
270 // ... produit matriciel (parallelise sur r)
271  for (l=m; l<nt-1; l++) {
272  for (i=0; i<nr; i++) {
273  som[i] = 0 ;
274  }
275 
276  jmin = ( m == 1 ) ? l : 0 ; // pour m=1, aa_lj = 0 pour j<l
277 
278  for (j=jmin; j<nt-1; j++) {
279  double amlj = aa[nt*l + j] ;
280  for (i=0; i<nr; i++) {
281  som[i] += amlj * cc[nr*j + i] ;
282 
283  }
284  }
285 
286  for (i=0; i<nr; i++) {
287  *resu = som[i] ;
288  resu++ ;
289  }
290 
291  } // fin de la boucle sur l
292 
293 // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
294  for (i=0; i<nr; i++) {
295  *resu = 0 ;
296  resu++ ;
297  }
298 
299 
300 // On passe au phi suivant :
301  cc = cc + ntnr ;
302  k++ ;
303 
304  } // fin du cas k < np+1
305 
306  } // fin de la boucle sur k2
307 
308 
309 // On passe a l'harmonique en phi suivante :
310  m++ ;
311  aa += maa ; // pointeur sur la nouvelle matrice de passage
312 
313  } // fin de la boucle (ip) sur phi
314 
315 // Mise a zero des coefficients de sin( np/2 phi ) (k=np+1)
316 
317 //## verif :
318 // assert(resu == cfo + (np+2)*ntnr) ;
319 
320  // Menage
321  delete [] som ;
322 
323 }
324 }
Lorene prototypes.
Definition: app_hor.h:64