LORENE
chb_legmi_sin.C
1 /*
2  * Copyright (c) 1999-2001 Eric Gourgoulhon
3  * Copyright (c) 2009 Jerome Novak
4  *
5  * This file is part of LORENE.
6  *
7  * LORENE is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * LORENE is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with LORENE; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 
23 
24 
25 
26 /*
27  * Calcule les coefficients du developpement (suivant theta)
28  * en sin(j theta)
29  * a partir des coefficients du developpement en fonctions
30  * associees de Legendre P_l^m(cos(theta)) (m impair)
31  * pour une une fonction 3-D antisymetrique par le retournement
32  * (x, y, z) --> (-x, -y, z).
33  *
34  * Entree:
35  * -------
36  * const int* deg : tableau du nombre effectif de degres de liberte dans chacune
37  * des 3 dimensions:
38  * deg[0] = np : nombre de points de collocation en phi
39  * deg[1] = nt : nombre de points de collocation en theta
40  * deg[2] = nr : nombre de points de collocation en r
41  *
42  * const double* cfi : tableau des coefficients a_j du develop. en fonctions de
43  * Legendre associees P_n^m:
44  *
45  * f(theta) =
46  * som_{l=m}^{nt-2} a_j P_j^m( cos(theta) )
47  *
48  * (m impair)
49  *
50  * ou P_l^m(x) represente la fonction de Legendre associee
51  * de degre l et d'ordre m normalisee de facon a ce que
52  *
53  * int_0^pi [ P_l^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_j (0 <= j <= nt-1) doit etre stoke dans le
59  * tableau cfi comme suit
60  * a_j = cfi[ nr*nt* k + i + nr* j ]
61  * ou k et i sont les indices correspondant a phi et r
62  * respectivement: m = 2 (k/2).
63  * NB: pour j<m, a_j = 0
64  *
65  * Sortie:
66  * -------
67  * double* cfo : tableau des coefficients c_j du develop. en sin definis
68  * comme suit (a r et phi fixes) :
69  *
70  * f(theta) = som_{j=0}^{nt-2} c_j sin( j theta )
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 c_j (0 <= j <= nt-1) est stoke dans le
76  * tableau cfo comme suit
77  * c_j = cfo[ nr*nt* k + i + nr* j ]
78  * ou k et i sont les indices correspondant a
79  * phi et r respectivement.
80  * NB: c_{nt-1} = 0.
81  *
82  *
83  * NB:
84  * ---
85  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
86  */
87 
88 /*
89  * $Id: chb_legmi_sin.C,v 1.4 2016/12/05 16:18:01 j_novak Exp $
90  * $Log: chb_legmi_sin.C,v $
91  * Revision 1.4 2016/12/05 16:18:01 j_novak
92  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
93  *
94  * Revision 1.3 2014/10/13 08:53:11 j_novak
95  * Lorene classes and functions now belong to the namespace Lorene.
96  *
97  * Revision 1.2 2014/10/06 15:16:00 j_novak
98  * Modified #include directives to use c++ syntax.
99  *
100  * Revision 1.1 2009/10/23 12:54:47 j_novak
101  * New base T_LEG_MI
102  *
103  *
104  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legmi_sin.C,v 1.4 2016/12/05 16:18:01 j_novak Exp $
105  *
106  */
107 
108 // headers du C
109 #include <cstdlib>
110 #include <cassert>
111 
112 // Headers Lorene
113 #include "headcpp.h"
114 #include "proto.h"
115 
116 namespace Lorene {
117 //******************************************************************************
118 
119 void chb_legmi_sin(const int* deg , const double* cfi, double* cfo) {
120 
121 int k2, l, 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 Legendre --> cos/sin
135  double* bb = mat_legmi_sin(np, nt) ;
136 
137 // Increment en m pour la matrice bb :
138  int mbb = 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  //... premier coef en j=0 mis a zero:
154  for (i=0; i<nr; i++) {
155  *resu = 0 ;
156  resu++ ;
157  }
158 
159  // Boucle sur l'indice j du developpement en sin( j theta)
160 
161  for (j=1; j<nt-1; j++) {
162 
163  // ... produit matriciel
164  for (i=0; i<nr; i++) {
165  som[i] = 0 ;
166  }
167 
168  for (l=1; l<nt-1; l++) {
169  double bmjl = bb[nt*j + l] ;
170  for (i=0; i<nr; i++) {
171  som[i] += bmjl * cc[nr*l + 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 j
181 
182  // Dernier coef en j=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  // On passe au phi suivant :
200  cc = cc + ntnr ;
201  k++ ;
202 
203  // Cas k=1 : tout est mis a zero
204  // -----------------------------
205 
206  for (l=0; l<nt; l++) {
207  for (i=0; i<nr; i++) {
208  *resu = 0 ;
209  resu++ ;
210  }
211  }
212 
213  // On passe au phi suivant :
214  cc = cc + ntnr ;
215  k++ ;
216 
217  // Cas k=2 (m=1 : sin(phi))
218  // ------------------------
219 
220  //... premier coef en j=0 mis a zero:
221  for (i=0; i<nr; i++) {
222  *resu = 0 ;
223  resu++ ;
224  }
225 
226  // Boucle sur l'indice j du developpement en sin( j theta)
227 
228  for (j=1; j<nt-1; j++) {
229 
230  // ... produit matriciel
231  for (i=0; i<nr; i++) {
232  som[i] = 0 ;
233  }
234 
235  for (l=1; l<nt-1; l++) {
236  double bmjl = bb[nt*j + l] ;
237  for (i=0; i<nr; i++) {
238  som[i] += bmjl * cc[nr*l + 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 j
248 
249  // Dernier coef en j=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  bb += mbb ; // 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  // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
270 
271  //... premier coef en j=0 mis a zero:
272  for (i=0; i<nr; i++) {
273  *resu = 0 ;
274  resu++ ;
275  }
276 
277  for (j=1; j<nt-1; j++) {
278 
279  // ... produit matriciel
280  for (i=0; i<nr; i++) {
281  som[i] = 0 ;
282  }
283 
284  for (l=m; l<nt-1; l++) {
285  double bmjl = bb[nt*j + l] ;
286  for (i=0; i<nr; i++) {
287  som[i] += bmjl * cc[nr*l + 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 j
297 
298  // Dernier coef en j=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  bb += mbb ; // pointeur sur la nouvelle matrice de passage
312 
313  } // fin de la boucle (m) sur phi
314 
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