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