File: chb_legpi_sini.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,472 kB
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (330 lines) | stat: -rw-r--r-- 8,484 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
 *   Copyright (c) 1999-2001 Eric Gourgoulhon
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   LORENE is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


char chb_legpi_sini_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpi_sini.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $" ;

/*
 *  Calcule les coefficients du developpement (suivant theta) 
 *  en sin((2j+1) theta) 
 *  a partir des coefficients du developpement en fonctions
 *  associees de Legendre P_l^m(cos(theta)) (l impair et m impair)
 *  pour une une fonction 3-D symetrique par rapport au plan equatorial
 *  z = 0 et antisymetrique par le retournement (x, y, z) --> (-x, -y, z). 
 * 
 * Entree:
 * -------
 *  const int* deg : tableau du nombre effectif de degres de liberte dans chacune 
 *		     des 3 dimensions: 
 *			deg[0] = np : nombre de points de collocation en phi
 *			deg[1] = nt : nombre de points de collocation en theta
 *			deg[2] = nr : nombre de points de collocation en r
 *
 *  const double* cfi : tableau des coefficients a_j du develop. en fonctions de
 *		    Legendre associees P_n^m:
 *
 *		    f(theta) = 
 *			    som_{l=(m-1)/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
 *			  
 *		(m impair) 
 *
 *		    ou P_l^m(x) represente la fonction de Legendre associee
 *		       de degre l et d'ordre m normalisee de facon a ce que
 *
 *			int_0^pi [ P_l^m(cos(theta)) ]^2  sin(theta) dtheta = 1
 *
 * 		    L'espace memoire correspondant au pointeur cfi doit etre 
 *	            nr*nt*(np+2) et doit avoir ete alloue avant 
 *		    l'appel a la routine.	 
 *		    Le coefficient a_j (0 <= j <= nt-1) doit etre stoke dans le 
 *		    tableau cfi comme suit
 *		          a_j = cfi[ nr*nt* k + i + nr* j ]
 *		    ou k et i sont les indices correspondant a phi et r 
 *		    respectivement: m = 2 (k/2).
 *		    NB: pour j<(m-1)/2,  a_j = 0
 *
 * Sortie:
 * -------
 *   double* cfo :  tableau des coefficients c_j du develop. en sin definis
 *			  comme suit (a r et phi fixes) :
 *
 *			f(theta) = som_{j=0}^{nt-2} c_j sin( (2j+1) theta ) 
 *			  
 * 		    L'espace memoire correspondant au pointeur cfo doit etre 
 *	            nr*nt*(np+2) et doit avoir ete alloue avant 
 *		    l'appel a la routine.	 
 *		    Le coefficient c_j (0 <= j <= nt-1) est stoke dans le 
 *		    tableau cfo comme suit
 *		          c_j = cfo[ nr*nt* k + i + nr* j ]
 *		    ou k et i sont les indices correspondant a
 *		    phi et r respectivement.
 *	            NB:	    c_{nt-1} = 0.
 *
 *
 * NB:
 * ---
 *  Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
 */

/*
 * $Id: chb_legpi_sini.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $
 * $Log: chb_legpi_sini.C,v $
 * Revision 1.6  2014/10/13 08:53:11  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.5  2014/10/06 15:16:00  j_novak
 * Modified #include directives to use c++ syntax.
 *
 * Revision 1.4  2005/02/18 13:14:11  j_novak
 * Changing of malloc/free to new/delete + suppression of some unused variables
 * (trying to avoid compilation warnings).
 *
 * Revision 1.3  2003/01/31 10:31:23  e_gourgoulhon
 * Suppressed the directive #include <malloc.h> for malloc is defined
 * in <stdlib.h>
 *
 * Revision 1.2  2002/10/16 14:36:52  j_novak
 * Reorganization of #include instructions of standard C++, in order to
 * use experimental version 3 of gcc.
 *
 * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
 * LORENE
 *
 * Revision 2.1  2000/11/14  15:12:11  eric
 * Traitement du cas np=1
 *
 * Revision 2.0  2000/09/29  16:07:35  eric
 * *** empty log message ***
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpi_sini.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $
 *
 */

// headers du C
#include <cstdlib>
#include <cassert>

// Headers Lorene
#include "headcpp.h"
#include "proto.h"

namespace Lorene {
//******************************************************************************

void chb_legpi_sini(const int* deg , const double* cfi, double* cfo) {

int k2, l, j, i, m ;
 
// Nombres de degres de liberte en phi et theta :
    int np = deg[0] ;
    int nt = deg[1] ;
    int nr = deg[2] ;

    assert(np < 4*nt) ;
    assert( cfi != cfo ) ; 

    // Tableau de travail
    double* som = new double[nr] ; 

// Recherche de la matrice de passage  Legendre -->  cos/sin 
    double* bb = mat_legpi_sini(np, nt) ;
    
// Increment en m pour la matrice bb :
    int mbb = nt * nt  ;
   
// Pointeurs de travail :
    double* resu = cfo ;
    const double* cc = cfi ;

// Increment en phi :
    int ntnr = nt * nr ;

// Indice courant en phi :
    int k = 0 ;

    // Cas k=0 (m=1 : cos(phi)) 
    // ------------------------

    // Boucle sur l'indice j du developpement en sin( (2j+1) theta) 

    for (j=0; j<nt-1; j++) {

	// ... produit matriciel (parallelise sur r)
	for (i=0; i<nr; i++) {
	    som[i] = 0 ; 
	}

	for (l=0; l<nt-1; l++) {
	    double bmjl = bb[nt*j + l] ;
	    for (i=0; i<nr; i++) {
		som[i] += bmjl * cc[nr*l + i] ;
	    }
	}
		    
	for (i=0; i<nr; i++) {
	    *resu = som[i]  ;
	    resu++ ;  
	}
		    
    }  // fin de la boucle sur j 

    // Dernier coef en j=nt-1 mis a zero pour le cas m impair : 
    for (i=0; i<nr; i++) {
	*resu = 0  ;
	resu++ ;  
    }
		
    // Special case np=1 (axisymmetry)
    // -------------------------------
    if (np==1) {
	for (i=0; i<2*ntnr; i++) {
	    *resu = 0 ;
	    resu++ ; 
	}
	delete []  som  ; 
	return ; 			    
    }
	
    // On passe au phi suivant :
    cc = cc + ntnr	; 
    k++ ;
		
    // Cas k=1 : tout est mis a zero
    // -----------------------------	

    for (l=0; l<nt; l++) {
	for (i=0; i<nr; i++) {
	    *resu = 0 ;
	    resu++ ; 
	}		    
    }

    // On passe au phi suivant :
    cc = cc + ntnr	; 
    k++ ;
		
    // Cas k=2 (m=1 : sin(phi)) 
    // ------------------------

    // Boucle sur l'indice j du developpement en sin( (2j+1) theta) 

    for (j=0; j<nt-1; j++) {

	// ... produit matriciel (parallelise sur r)
	for (i=0; i<nr; i++) {
	    som[i] = 0 ; 
	}

	for (l=0; l<nt-1; l++) {
	    double bmjl = bb[nt*j + l] ;
	    for (i=0; i<nr; i++) {
		som[i] += bmjl * cc[nr*l + i] ;
	    }
	}
		    
	for (i=0; i<nr; i++) {
	    *resu = som[i]  ;
	    resu++ ;  
	}
		    
    }  // fin de la boucle sur j 

    // Dernier coef en j=nt-1 mis a zero pour le cas m impair : 
    for (i=0; i<nr; i++) {
	*resu = 0  ;
	resu++ ;  
    }
		
    // On passe au phi suivant :
    cc = cc + ntnr	; 
    k++ ;
		
    // On passe au m suivant :
    bb += mbb ;	// pointeur sur la nouvelle matrice de passage 

    // Cas k >= 3
    // ----------

    for (m=3; m < np ; m+=2) {	    
    	
	for (k2=0; k2 < 2; k2++) {  // k2=0 : cos(m phi)  ;   k2=1 : sin(m phi)
	
	    // Boucle sur l'indice j du developpement en sin( (2j+1) theta) 

	    for (j=0; j<nt-1; j++) {

		// ... produit matriciel (parallelise sur r)
		for (i=0; i<nr; i++) {
		    som[i] = 0 ; 
		}

		for (l=(m-1)/2; l<nt-1; l++) {
		    double bmjl = bb[nt*j + l] ;
		    for (i=0; i<nr; i++) {
			som[i] += bmjl * cc[nr*l + i] ;
		    }
		}
		    
		for (i=0; i<nr; i++) {
		    *resu = som[i]  ;
		    resu++ ;  
		}
		    
	    }  // fin de la boucle sur j 

	    // Dernier coef en j=nt-1 mis a zero pour le cas m impair : 
	    for (i=0; i<nr; i++) {
		*resu = 0  ;
		resu++ ;  
	    }
		
	    // On passe au phi suivant :
	    cc = cc + ntnr	; 
	    k++ ;
		
	}  //  fin de la boucle sur k2 
	
	// On passe a l'harmonique en phi suivante :
	bb += mbb ;	// pointeur sur la nouvelle matrice de passage 
	
    }	// fin de la boucle (m) sur phi  


    // Cas k=np+1 : tout est mis a zero
    // --------------------------------	

    for (l=0; l<nt; l++) {
	for (i=0; i<nr; i++) {
	    *resu = 0 ;
	    resu++ ; 
	}		    
    }


//## verif : 
    assert(resu == cfo + (np+2)*ntnr) ;

    // Menage
    delete [] som ;
    
}
}