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