LORENE
som_r_1d.C
1 /*
2  * Copyright (c) 2024 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  * Functions for direct spectral summation in the radial direction and a 1D array.
27  *
28  * SYNOPSYS:
29  * double som_r_1d_XX(double* ti, int nr, double x)
30  *
31  * ti : array of spectral coefficients
32  * nr : size of the above array
33  * x : point where to compute the summation; x in [0, 1] or x in [-1, 1]
34  */
35 
36 
37 // Headers C
38 #include <cstdlib>
39 
40 #include "headcpp.h"
41 #include "proto.h"
42 
43 namespace Lorene {
44  //-----------------------------
45  //--- Non-implemented cases ---
46  //-----------------------------
47 
48  double som_r_1d_pas_prevu(const double*, int, double)
49  {
50  throw(invalid_argument("som_r_1d : r basis not implemented yet !")) ;
51  return 0. ;
52  }
53 
54  //--------------
55  //--- R_CHEB ---
56  //--------------
57 
58  double som_r_1d_cheb(const double* ti, int nr, double x)
59  {
60  int i;
61  const double* pi = ti ; // pi points on the array of coefficients
62  double resu = 0. ;
63 
64  double cheb0 = 1 ;
65  resu += (*pi)*cheb0 ;
66  pi++ ;
67  double cheb1 = x ;
68  if (nr > 1) {
69  resu += (*pi)*cheb1 ;
70  pi++ ;
71  }
72  for (i=2; i<nr; i++) {
73  double cheb2 = 2*x* cheb1 - cheb0 ; // Chebyshev recursion formula
74  resu += (*pi)*cheb2 ;
75  pi++ ;
76  cheb0 = cheb1 ;
77  cheb1 = cheb2 ;
78  }
79 
80  return resu ;
81  }
82 
83 
84  //---------------
85  //--- R_CHEBP ---
86  //---------------
87 
88  double som_r_1d_chebp(const double* ti, int nr, double x)
89  {
90  int i ;
91  const double* pi = ti ; // pi points on the array of coefficients
92  double resu = 0. ;
93 
94  double cheb0 = 1. ;
95  resu += (*pi)*cheb0 ;
96  pi++ ;
97  double cheb1 = x ;
98 
99  for (i=2; i<2*nr-1; i++) {
100  double cheb2 = 2*x*cheb1 - cheb0 ; // Chebyshev recursion formula
101  cheb0 = cheb1 ;
102  cheb1 = cheb2 ;
103  if (i%2 == 0) {
104  resu += (*pi)*cheb2 ;
105  pi++ ;
106  }
107  }
108  return resu ;
109  }
110 
111 
112  //---------------
113  //--- R_CHEBI ---
114  //---------------
115 
116  double som_r_1d_chebi(const double* ti, int nr, double x)
117  {
118  int i ;
119  const double* pi = ti ; // pi points on the array of coefficients
120  double resu = 0. ;
121 
122  double cheb0 = 1 ;
123  double cheb1 = x ;
124  resu += (*pi)*cheb1 ;
125  pi++ ;
126 
127  for (i=2; i<2*nr; i++) {
128  double cheb2 = 2*x*cheb1 - cheb0 ; // Chebyshev recursion formula
129  cheb0 = cheb1 ;
130  cheb1 = cheb2 ;
131  if (i%2 == 1) {
132  resu += (*pi)*cheb2 ;
133  pi++ ;
134  }
135  }
136  return resu ;
137  }
138 
139  //--------------
140  //--- R_LEG ---
141  //--------------
142 
143  double som_r_1d_leg(const double* ti, const int nr, double x)
144  {
145  int i ;
146  const double* pi = ti ; // pi points on the array of coefficients
147  double resu = 0. ;
148 
149  double leg0 = 1. ;
150  resu += (*pi)*leg0 ;
151  pi++ ;
152  double leg1 = x ;
153  if (nr > 1) {
154  resu += (*pi)*leg1 ;
155  pi++ ;
156  }
157 
158  for (i=2; i<nr; i++) {
159  // Legendre recursion formula
160  double leg2 = (double(2*i-1)*x* leg1 - double(i-1)*leg0) / double(i) ;
161  resu += (*pi)*leg2 ;
162  pi++ ;
163  leg0 = leg1 ;
164  leg1 = leg2 ;
165  }
166  return resu ;
167  }
168 
169 
170  //--------------
171  //--- R_LEGP ---
172  //--------------
173 
174  double som_r_1d_legp(const double* ti, const int nr, double x)
175  {
176  int i ;
177  const double* pi = ti ; // pi points on the array of coefficients
178  double resu = 0. ;
179 
180  double leg0 = 1. ;
181  resu += (*pi)*leg0 ;
182  pi++ ;
183  double leg1 = x ;
184  for (i=2; i<2*nr-1; i++) {
185  // Legendre recursion formula
186  double leg2 = (double(2*i-1)*x* leg1 - double(i-1)*leg0) / double(i) ;
187  leg0 = leg1 ;
188  leg1 = leg2 ;
189  if (i%2 == 0) {
190  resu += (*pi)*leg2 ;
191  pi++ ;
192  }
193  }
194  return resu ;
195  }
196 
197 
198  //--------------
199  //--- R_LEGI ---
200  //--------------
201 
202  double som_r_1d_legi(const double* ti, int nr, double x)
203  {
204  int i ;
205  const double* pi = ti ; // pi points on the array of coefficients
206  double resu = 0. ;
207 
208  double leg0 = 1. ;
209  double leg1 = x ;
210  resu += (*pi)*leg1 ;
211  pi++ ;
212  for (i=2; i<2*nr; i++)
213  {
214  // Legendre recursion formula
215  double leg2 = (double(2*i-1)*x* leg1 - double(i-1)*leg0) / double(i) ;
216  leg0 = leg1 ;
217  leg1 = leg2 ;
218  if (i%2 == 1) {
219  resu += (*pi)*leg2 ;
220  pi++ ;
221  }
222  }
223  return resu ;
224  }
225 
226  //----------------
227  //--- R_JACO02 ---
228  //----------------
229 
230  double som_r_1d_jaco02(const double* ti, int nr, double x)
231  {
232  int i;
233  const double* pi = ti ; // pi points on the array of coefficients
234  double resu = 0. ;
235 
236  // Jacobi(0,2) polynomial values at x, up to degree nr-1
237  double* jaco = jacobi(nr-1,x) ;
238  for (i=0 ; i<nr ; i++) {
239  resu += (*pi) * jaco[i] ;
240  pi++ ; // R suivant
241  }
242  return resu ;
243  }
244 
245 } // end of namespace
Lorene prototypes.
Definition: app_hor.h:67