16 #define MAX(a,b) ((a) > (b) ? (a) : (b))
18 double maxerr_cplx(complex
double *a, complex
double *b,
int size)
22 for(i = 0; i<size; i++){
24 value =
MAX( cabs( a[i]-b[i] ), value );
29 double maxerr(
double *a,
double *b,
int size)
33 for(i = 0; i<size; i++){
34 value =
MAX( abs( a[i]-b[i] ), value );
41 int IM1=2147483563,IM2=2147483399,IMM1=IM1-1,
42 IA1=40014,IA2=40692,IQ1=53668,IQ2=52774,IR1=12211,IR2=3791,
43 NTAB=32,NDIV=1+IMM1/NTAB;
45 double AM=1./IM1,EPS=1.2e-7,RNMX=1.-EPS;
47 static int iv[32],iy,idum2 = 123456789;
51 idum= (-idum>1 ? -idum : 1);
53 for(j=NTAB+8;j>=1;j--) {
55 idum=IA1*(idum-k*IQ1)-k*IR1;
56 if (idum < 0) idum=idum+IM1;
57 if (j < NTAB) iv[j-1]=idum;
62 idum=IA1*(idum-k*IQ1)-k*IR1;
63 if (idum < 0) idum=idum+IM1;
65 idum2=IA2*(idum2-k*IQ2)-k*IR2;
66 if (idum2 < 0) idum2=idum2+IM2;
71 return (AM*iy < RNMX ? AM*iy : RNMX);
89 flmn[i] = (2.0*
ran2_dp(seed) - 1.0) + I * (2.0*
ran2_dp(seed) - 1.0);
95 int en, el, m, msign, i, i_op, offset;
98 for (en=0; en<N; en++) {
99 offset = en * flmsize;
100 for (el=0; el<L; el++) {
102 ssht_sampling_elm2ind(&i, el, m);
103 flmn[offset+i] = (2.0*
ran2_dp(seed) - 1.0);
104 for (m=1; m<=el; m++) {
105 ssht_sampling_elm2ind(&i, el, m);
106 flmn[offset+i] = (2.0*
ran2_dp(seed) - 1.0) + I * (2.0*
ran2_dp(seed) - 1.0);
107 ssht_sampling_elm2ind(&i_op, el, -m);
109 msign = 1 - msign - msign;
110 flmn[offset+i_op] = msign * conj(flmn[offset+i]);
116 void print_f(
const complex
double *f,
int L,
int N)
121 printf(
"\n -- Layer %i -- \n", n);
122 for(j=0;j<mapsize;j++){
123 printf(
" (%f,%f) ",creal(f[n*mapsize+j]),cimag(f[n*mapsize+j]));
134 printf(
"\n -- Layer %i -- \n", n);
135 for(j=0;j<mapsize;j++){
136 printf(
" %f ",(f[n*mapsize+j]));
147 printf(
"\n -- Layer %i -- \n", n);
148 for(j=0;j<mapsize;j++){
149 printf(
" (%f,%f) ",creal(flmn[n*mapsize+j]),cimag(flmn[n*mapsize+j]));
157 clock_t time_start, time_end;
173 double *f = (
double*)calloc(Nnodes,
sizeof(
double));
174 double *nodes = (
double*)calloc(Nnodes,
sizeof(
double));
175 double *weights = (
double*)calloc(N,
sizeof(
double));
178 for (n=0; n<Nnodes; n++)
179 f[n] = pow(nodes[n], -2.0);
181 double *fn = (
double*)calloc(N,
sizeof(
double));
185 double *kvalues = (
double*)calloc(Nk,
sizeof(
double));
187 kvalues[n] = kmin + (kmax - kmin)*(double)n/(
double)Nk;
192 double *flk_anal = (
double*)calloc(Nk,
sizeof(
double));
193 for (n=0; n<Nnodes; n++)
194 flk_anal[n] = 1.253314137 / kvalues[n];
199 double *flk_int = (
double*)calloc(Nk,
sizeof(
double));
200 double r1, r2, f1, f2, h = (rmax - rmin) / Ninte;
201 for (n=0; n<Nnodes; n++){
203 for (i = 0; i < Ninte; i++){
206 r2 = rmin + (i + 1) * h;
208 if(!isnan(f1) && !isinf(f1) && !isnan(f2) && !isinf(f2))
209 flk_int[n] += ((f1 + f2) * h) / (2.0 * kvalues[n]);
214 printf(
"Running flag_spherlaguerre2spherbessel\n");
215 double *flk_slag = (
double*)calloc(Nk,
sizeof(
double));
217 printf(
"Finished flag_spherlaguerre2spherbessel\n");
222 for (n = 0; n < Nk; n++){
223 printf(
"> k = %f : integ = %f / analyt = %f / spherlag = %f\n", kvalues[n], flk_int[n], flk_anal[n], flk_slag[n]);
225 for (n = 0; n < Nk; n++){
226 printf(
"> k = %f : spherlag / analyt = %f \n", kvalues[n], flk_slag[n] / flk_anal[n]);
242 double *f = (
double*)calloc(N,
sizeof(
double));
243 double *nodes = (
double*)calloc(N,
sizeof(
double));
244 double *weights = (
double*)calloc(N,
sizeof(
double));
248 f[n] =
j_ell(Kval * nodes[n], ell);
251 double *fn = (
double*)calloc(N,
sizeof(
double));
256 double *fn_bis = (
double*)calloc(N,
sizeof(
double));
258 for (n = 0; n < N; n++){
259 fn_bis[n] = fn_bis[n] * pow(tau, -3.0);
260 printf(
"> n = %i : fn = %f <-> fn_bis = %f <-> ratio = %16.2e\n", n, fn[n], fn_bis[n], fn_bis[n]/fn[n]);
264 double *f_rec = (
double*)calloc(N,
sizeof(
double));
270 double *kvalues = (
double*)calloc(Nk,
sizeof(
double));
272 kvalues[n] = kmin + (kmax - kmin)*(double)n/(
double)Nk;
273 double *flk = (
double*)calloc(Nk,
sizeof(
double));
276 for (n = 0; n < Nk; n++){
289 int main(
int argc,
char *argv[])
291 const int NREPEAT = 4;
292 const int NSCALE = 5;
293 const double Kval = 0.15;
299 const double R = 1.0 / tau;
300 const int seed = (int)(10000.0*(
double)clock()/(double)CLOCKS_PER_SEC);
302 printf(
"==========================================================\n");
303 printf(
"PARAMETERS : ");
304 printf(
" L = %i N = %i R = %4.1f seed = %i\n", L, N, R, seed);
305 printf(
"----------------------------------------------------------\n");
310 printf(
"----------------------------------------------------------\n");
315 printf(
"==========================================================\n");
316 printf(
" L = %i N = %i R = %4.1f seed = %i\n", L, N, R, seed);
void flag_sbesselslag(double *sbesselslag, int ell, double *kvalues, int Nk, int N, double tau)
int flag_core_flmn_size(int L, int N)
int main(int argc, char *argv[])
double maxerr_cplx(complex double *a, complex double *b, int size)
void flag_spherlaguerre2spherbessel(double *flk, const double *fn, double *kvalues, int Nk, int N, int ell, double tau)
void flag_sbesselslag_test_jlK(double Kval, int ell, int Nk, int N, double R, int seed)
void print_flmn(const complex double *flmn, int L, int N)
void flag_sbesselslag_test_simple(int Nk, int N, double R, int seed)
double flag_spherlaguerre_tau(double R, int N)
int ssht_fr_size_mw(int L)
void flag_random_flmn(complex double *flmn, int L, int N, int seed)
double j_ell(double X, int l)
void flag_random_flmn_real(complex double *flmn, int L, int N, int seed)
void flag_spherlaguerre_sampling(double *nodes, double *weights, double tau, int N)
int flag_core_f_size_mw(int L, int N)
double maxerr(double *a, double *b, int size)
void flag_random_f(complex double *f, int L, int N, int seed)
void print_f_real(const double *f, int L, int N)
void flag_spherlaguerre_synthesis(double *f, const double *fn, const double *nodes, int Nnodes, double tau, int N)
void flag_spherlaguerre_analysis(double *fn, const double *f, const double *nodes, const double *weights, double tau, int N)
void print_f(const complex double *f, int L, int N)