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