22 #include "base_spectral.hpp"
25 double summation_1d_pasprevu (
double,
const Array<double>&) {
26 cout <<
"Summation_1d not implemented." << endl ;
30 double summation_1d_cheb (
double xx,
const Array<double>& tab) {
31 assert (tab.get_ndim()==1) ;
32 int nr = tab.get_size(0) ;
37 double res = tab(0)*tm2 ;
40 for (
int i=2 ; i<nr ; i++) {
49 double summation_1d_cheb_even (
double xx,
const Array<double>& tab) {
50 assert (tab.get_ndim()==1) ;
51 int nr = tab.get_size(0) ;
56 double res = tab(0)*tm2 ;
57 for (
int i=1 ; i<nr ; i++) {
69 double summation_1d_cheb_odd (
double xx,
const Array<double>& tab) {
70 assert (tab.get_ndim()==1) ;
71 int nr = tab.get_size(0) ;
77 double res = tab(0)*tm1 ;
78 for (
int i=1 ; i<nr ; i++) {
90 double summation_1d_leg(
double xx,
const Array<double>& tab) {
91 assert (tab.get_ndim()==1) ;
92 int nr = tab.get_size(0) ;
97 double res = tab(0)*plm2 ;
100 for (
int l=2 ; l<nr ; l++) {
101 pl = ((2*l-1)*xx*plm1 - (l-1)*plm2)/l ;
109 double summation_1d_leg_even (
double xx,
const Array<double>& tab) {
111 assert (tab.get_ndim()==1) ;
112 int nr = tab.get_size(0) ;
117 double res = tab(0)*plm2 ;
119 for (
int l=1 ; l<nr ; l++) {
121 pl = ((2*courant-1)*xx*plm1 - (courant-1)*plm2)/courant ;
126 pl = ((2*courant-1)*xx*plm1 - (courant-1)*plm2)/courant ;
135 double summation_1d_leg_odd (
double xx,
const Array<double>& tab) {
136 assert (tab.get_ndim()==1) ;
137 int nr = tab.get_size(0) ;
142 double res = tab(0)*plm1 ;
144 for (
int l=1 ; l<nr ; l++) {
146 pl = ((2*courant-1)*xx*plm1 - (courant-1)*plm2)/courant ;
150 pl = ((2*courant-1)*xx*plm1 - (courant-1)*plm2)/courant ;
158 double summation_1d_cossin (
double xx,
const Array<double>& tab) {
159 assert (tab.get_ndim()==1) ;
160 int nbr = tab.get_size(0) ;
162 for (
int i=0 ; i<nbr ; i++)
163 res += (i%2==0) ? tab(i)*cos((i/2)*xx) : tab(i)*sin((i-1)/2*xx) ;
168 double summation_1d_cossin_even (
double xx,
const Array<double>& tab) {
169 assert (tab.get_ndim()==1) ;
170 int nbr = tab.get_size(0) ;
172 for (
int i=0 ; i<nbr ; i++)
173 res += (i%2==0) ? tab(i)*cos(i*xx) : tab(i)*sin((i-1)*xx);
177 double summation_1d_cossin_odd (
double xx,
const Array<double>& tab) {
178 assert (tab.get_ndim()==1) ;
179 int nbr = tab.get_size(0) ;
181 for (
int i=0 ; i<nbr ; i++)
182 res += (i%2==0) ? tab(i)*cos((i+1)*xx) : tab(i)*sin(i*xx);
186 double summation_1d_cos (
double xx,
const Array<double>& tab) {
187 assert (tab.get_ndim()==1) ;
188 int nbr = tab.get_size(0) ;
190 for (
int i=0 ; i<nbr ; i++)
191 res += tab(i)*cos(i*xx) ;
195 double summation_1d_sin (
double xx,
const Array<double>& tab) {
196 assert (tab.get_ndim()==1) ;
197 int nbr = tab.get_size(0) ;
199 for (
int i=1 ; i<nbr ; i++)
200 res += tab(i)*sin(i*xx) ;
204 double summation_1d_cos_even (
double xx,
const Array<double>& tab) {
205 assert (tab.get_ndim()==1) ;
206 int nbr = tab.get_size(0) ;
208 for (
int i=0 ; i<nbr ; i++)
209 res += tab(i)*cos(2*i*xx) ;
213 double summation_1d_cos_odd (
double xx,
const Array<double>& tab) {
214 assert (tab.get_ndim()==1) ;
215 int nbr = tab.get_size(0) ;
217 for (
int i=0 ; i<nbr ; i++)
218 res += tab(i)*cos((2*i+1)*xx) ;
222 double summation_1d_sin_even (
double xx,
const Array<double>& tab) {
223 assert (tab.get_ndim()==1) ;
224 int nbr = tab.get_size(0) ;
226 for (
int i=1 ; i<nbr ; i++)
227 res += tab(i)*sin(2*i*xx) ;
231 double summation_1d_sin_odd (
double xx,
const Array<double>& tab) {
232 assert (tab.get_ndim()==1) ;
233 int nbr = tab.get_size(0) ;
235 for (
int i=0 ; i<nbr ; i++)
236 res += tab(i)*sin((2*i+1)*xx) ;
241 double summation_1d (
int base,
double xx,
const Array<double>& tab) {
243 static double (*summation_1d[NBR_MAX_BASE])(double,
const Array<double>&) ;
244 static bool premier_appel = true ;
247 premier_appel = false ;
249 for (
int i=0; i<NBR_MAX_BASE; i++)
250 summation_1d[i] = summation_1d_pasprevu ;
252 summation_1d[CHEB] = summation_1d_cheb ;
253 summation_1d[CHEB_EVEN] = summation_1d_cheb_even ;
254 summation_1d[CHEB_ODD] = summation_1d_cheb_odd ;
255 summation_1d[COSSIN] = summation_1d_cossin ;
256 summation_1d[COS_EVEN] = summation_1d_cos_even ;
257 summation_1d[COS_ODD] = summation_1d_cos_odd ;
258 summation_1d[SIN_ODD] = summation_1d_sin_odd ;
259 summation_1d[SIN_EVEN] = summation_1d_sin_even ;
260 summation_1d[COS] = summation_1d_cos ;
261 summation_1d[SIN] = summation_1d_sin ;
262 summation_1d[LEG] = summation_1d_leg ;
263 summation_1d[LEG_EVEN] = summation_1d_leg_even ;
264 summation_1d[LEG_ODD] = summation_1d_leg_odd ;
265 summation_1d[COSSIN_EVEN] = summation_1d_cossin_even ;
266 summation_1d[COSSIN_ODD] = summation_1d_cossin_odd ;
269 return summation_1d[base](xx, tab) ;
278 for (
int d=0 ; d<
ndim-1 ; d++) {
279 int dim_output =
ndim-1-d ;
281 for (
int k=0 ; k<dim_output ; k++)
282 nbr_output.
set(k) = nbr_coefs(k+d+1) ;
285 Index inout (nbr_output) ;
294 for (
int k=0 ; k<dim_output ; k++)
295 incourant.
set(k+1) = inout(k) ;
296 for (
int k=0 ; k<cf.
get_size(d) ; k++) {
297 incourant.
set(0) = k ;
298 tab_1d.
set(k) = (*courant)(incourant) ;
300 output.
set(inout) = summation_1d (base, num(d+1), tab_1d) ;
reference set(const Index &pos)
Read/write of an element.
int get_ndim() const
Returns the number of dimensions.
int get_size(int i) const
Returns the size of a given dimension.
const Dim_array & get_dimensions() const
Returns the Dim_array of the Array.
Bases_container bases_1d
Arrays containing the various basis of decomposition.
double summation(const Point &num, const Array< double > &tab) const
Computes the spectral summation.
int ndim
Number of dimensions.
Class for storing the dimensions of an array.
int & set(int i)
Read/write of the size of a given dimension.
Class that gives the position inside a multi-dimensional Array.
int & set(int i)
Read/write of the position in a given dimension.
bool inc(int increm, int var=0)
Increments the position of the Index.
The class Point is used to store the coordinates of a point.