LORENE
chb_legmp_cos.C
1 /*
2  * Copyright (c) 1999-2001 Eric Gourgoulhon
3  * 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 cos(j*theta)
29  * a partir des coefficients du developpement en fonctions
30  * associees de Legendre P_l^m(cos(theta)) (m pair)
31  * pour une une fonction 3-D symetrique 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_l du develop. en fonctions de
42  * Legendre associees P_n^m:
43  *
44  * f(theta) = som_{l=m}^{nt-1} a_l P_l^m( cos(theta) )
45  *
46  * (m pair)
47  *
48  * ou P_n^m(x) represente la fonction de Legendre associee
49  * de degre n et d'ordre m normalisee de facon a ce que
50  *
51  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
52  *
53  * L'espace memoire correspondant au pointeur cfi doit etre
54  * nr*nt*(np+2) et doit avoir ete alloue avant
55  * l'appel a la routine.
56  * Le coefficient a_l (0 <= l <= nt-1) doit etre stoke dans le
57  * tableau cfi comme suit
58  * a_l = cfi[ nr*nt* k + i + nr* l ]
59  * ou k et i sont les indices correspondant a phi et r
60  * respectivement: m = 2 (k/2).
61  * NB: pour l < m, a_l = 0
62  *
63  * Sortie:
64  * -------
65  * double* cfo : tableau des coefficients c_j du develop. en cos/sin definis
66  * comme suit (a r et phi fixes) :
67  *
68  * f(theta) = som_{j=0}^{nt-1} c_j cos( j theta )
69  *
70  * L'espace memoire correspondant au pointeur cfo doit etre
71  * nr*nt*(np+2) et doit avoir ete alloue avant
72  * l'appel a la routine.
73  * Le coefficient c_j (0 <= j <= nt-1) est stoke dans le
74  * tableau cfo comme suit
75  * c_j = cfo[ nr*nt* k + i + nr* j ]
76  * ou k et i sont les indices correspondant a
77  * phi et r respectivement: m = 2 (k/2).
78  * Pour m impair, c_0 = c_{nt-1} = 0.
79  *
80  *
81  * NB:
82  * ---
83  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
84  */
85 
86 /*
87  * $Id: chb_legmp_cos.C,v 1.4 2016/12/05 16:18:01 j_novak Exp $
88  * $Log: chb_legmp_cos.C,v $
89  * Revision 1.4 2016/12/05 16:18:01 j_novak
90  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
91  *
92  * Revision 1.3 2014/10/13 08:53:11 j_novak
93  * Lorene classes and functions now belong to the namespace Lorene.
94  *
95  * Revision 1.2 2014/10/06 15:16:00 j_novak
96  * Modified #include directives to use c++ syntax.
97  *
98  * Revision 1.1 2009/10/13 13:49:36 j_novak
99  * New base T_LEG_MP.
100  *
101  *
102  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legmp_cos.C,v 1.4 2016/12/05 16:18:01 j_novak Exp $
103  *
104  */
105 
106 
107 
108 // headers du C
109 #include <cstdlib>
110 #include <cassert>
111 
112 // Prototypage
113 #include "headcpp.h"
114 #include "proto.h"
115 
116 namespace Lorene {
117 //******************************************************************************
118 
119 void chb_legmp_cos(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 
130  // Tableau de travail
131  double* som = new double[nr] ;
132 
133 // Recherche de la matrice de passage Legendre --> cos/sin
134  double* bb = mat_legmp_cos(np, nt) ;
135 
136 // Increment en m pour la matrice bb :
137  int mbb = nt * nt ;
138 
139 // Pointeurs de travail :
140  double* resu = cfo ;
141  const double* cc = cfi ;
142 
143 // Increment en phi :
144  int ntnr = nt * nr ;
145 
146 // Indice courant en phi :
147  int k = 0 ;
148 
149 //----------------------------------------------------------------
150 // Cas axisymetrique
151 //----------------------------------------------------------------
152 
153  if (np == 1) {
154 
155  m = 0 ;
156 
157 // Boucle sur l'indice j du developpement en cos(j theta)
158 
159  for (j=0; j<nt; j++) {
160 
161 // ... produit matriciel (parallelise sur r)
162  for (i=0; i<nr; i++) {
163  som[i] = 0 ;
164  }
165 
166  for (l=m; l<nt; l++) {
167 
168  double bmjl = bb[nt*j + l] ;
169  for (i=0; i<nr; i++) {
170  som[i] += bmjl * cc[nr*l + i] ;
171  }
172  }
173 
174  for (i=0; i<nr; i++) {
175  *resu = som[i] ;
176  resu++ ;
177  }
178 
179  } // fin de la boucle sur j
180 
181  // Mise a zero des coefficients k=1 et k=2 :
182  // ---------------------------------------
183 
184  for (i=ntnr; i<3*ntnr; i++) {
185  cfo[i] = 0 ;
186  }
187 
188  // On sort
189  delete [] som ;
190  return ;
191 
192  } // fin du cas np=1
193 
194 
195 //----------------------------------------------------------------
196 // Cas 3-D
197 //----------------------------------------------------------------
198 
199 
200 // Boucle sur phi :
201 
202  for (m=0; m < np + 1 ; m+=2) {
203 
204  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
205 
206  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
207  // et sin( np phi) a zero
208  for (j=0; j<nt; j++) {
209  for (i=0; i<nr; i++) {
210  *resu = 0 ;
211  resu++ ;
212  }
213  }
214  }
215  else {
216 
217 // Boucle sur l'indice j du developpement en cos(2 j theta)
218 
219  for (j=0; j<nt; j++) {
220 
221 // ... produit matriciel (parallelise sur r)
222  for (i=0; i<nr; i++) {
223  som[i] = 0 ;
224  }
225 
226  for (l=m; l<nt; l++) {
227 
228  double bmjl = bb[nt*j + l] ;
229  for (i=0; i<nr; i++) {
230  som[i] += bmjl * cc[nr*l + i] ;
231  }
232  }
233 
234  for (i=0; i<nr; i++) {
235  *resu = som[i] ;
236  resu++ ;
237  }
238 
239  } // fin de la boucle sur j
240 
241  } // fin du cas k != 1
242 
243 // On passe au phi suivant :
244  cc = cc + ntnr ;
245  k++ ;
246 
247  } // fin de la boucle sur k2
248 
249 // On passe a l'harmonique en phi suivante :
250 
251  bb += mbb ; // pointeur sur la nouvelle matrice de passage
252 
253  } // fin de la boucle (m) sur phi
254 
255 //## verif :
256  assert(resu == cfo + (np+2)*ntnr) ;
257 
258  // Menage
259  delete [] som ;
260 
261 }
262 }
Lorene prototypes.
Definition: app_hor.h:67