FLAGLET  1.0b1
Exact wavelets on the ball
src/main/c/flaglet_tiling.c
Go to the documentation of this file.
00001 // FLAGLET package
00002 // Copyright (C) 2012 
00003 // Boris Leistedt & Jason McEwen
00004 
00005 #include "flaglet.h"
00006 #include <stdlib.h>
00007 #include <math.h>
00008 #include <s2let.h>
00009 
00021 void flaglet_tiling_axisym_allocate(double **kappa_lp, double **kappa0_lp, int B_l, int B_p, int L, int P)
00022 {
00023     int J_l = s2let_j_max(L, B_l);
00024     int J_p = s2let_j_max(P, B_p);
00025     *kappa_lp = (double*)calloc( (J_p+1) * (J_l+1) * L * P, sizeof(double));
00026     *kappa0_lp = (double*)calloc( L * P, sizeof(double));
00027 }
00028 
00042 void flaglet_tiling_axisym(double *kappa_lp, double *kappa0_lp, int B_l, int B_p, int L, int P, int J_min_l, int J_min_p)
00043 {
00044     int l, n, jl, jp;
00045     int J_l = s2let_j_max(L, B_l);
00046     int J_p = s2let_j_max(P, B_p);
00047     double temp;
00048 
00049     double *phi2_l = (double*)calloc((J_l+2) * L, sizeof(double));
00050     double *phi2_n = (double*)calloc((J_p+2) * P, sizeof(double));
00051 
00052     s2let_tiling_phi2_s2dw(phi2_l, B_l, L, J_min_l);
00053     s2let_tiling_phi2_s2dw(phi2_n, B_p, P, J_min_p);
00054 
00055     int el_max = ceil(pow(B_l,J_min_l))+1;
00056     int en_max = ceil(pow(B_p,J_min_p))+1;
00057 
00058     for (n = 0; n < en_max; n++){
00059         for (l = 0; l < el_max; l++){
00060             temp = sqrt(
00061                 phi2_l[l+J_min_l*L] * phi2_n[n+(J_min_p+1)*P]
00062                 + phi2_l[l+(J_min_l+1)*L] * phi2_n[n+J_min_p*P]
00063                 - phi2_l[l+J_min_l*L] * phi2_n[n+J_min_p*P]
00064             );
00065             if( isnan(temp) || isinf(temp) )
00066                 kappa0_lp[n * L + l] = 0.0;
00067             else
00068                 kappa0_lp[n * L + l] = temp;
00069         }
00070     }
00071     for (n = en_max; n < P; n++){
00072         for (l = 0; l < L; l++){
00073             temp = sqrt(phi2_l[l+J_min_l*L]);
00074             if( isnan(temp) || isinf(temp) )
00075                 kappa0_lp[n * L + l] = 0.0;
00076             else
00077                 kappa0_lp[n * L + l] = temp;
00078         }
00079     }
00080     for (n = 0; n < P; n++){
00081         for (l = el_max; l < L; l++){
00082             temp = sqrt(phi2_n[n+J_min_p*P]);
00083             if( isnan(temp) || isinf(temp) )
00084                 kappa0_lp[n * L + l] = 0.0;
00085             else
00086                 kappa0_lp[n * L + l] = temp;
00087         }
00088     }
00089 
00090     /*for (n = 0; n < P; n++){
00091         for (l = 0; l < L; l++){
00092             printf("  %f  ",kappa0_lp[n * L + l]);
00093         }
00094         printf("\n");
00095     }*/
00096 
00097     for (jp = J_min_p; jp <= J_p; jp++){
00098         for (jl = J_min_l; jl <= J_l; jl++){
00099             //printf("- j_l = %i - j_p = %i -\n",jl,jp);
00100             for (n = 0; n < P; n++){
00101                 for (l = 0; l < L; l++){
00102                     temp =
00103                         sqrt(phi2_l[l+(jl+1)*L] - phi2_l[l+jl*L])
00104                         * sqrt(phi2_n[n+(jp+1)*P] - phi2_n[n+jp*P]);
00105                     if( isnan(temp) || isinf(temp) ){
00106                         kappa_lp[ jp*(J_l+1)*L*P  + jl*L*P + n*L + l ] = 0.0;
00107                     }else
00108                         kappa_lp[ jp*(J_l+1)*L*P  + jl*L*P + n*L + l ] = temp;
00109                     
00110                     //printf(" %f ",kappa_lp[ jp*(J_l+1)*L*P  + jl*L*P + n*L + l ]);
00111                 }
00112                 //printf("\n");
00113             }
00114         }
00115     }
00116 
00117     free(phi2_l);
00118     free(phi2_n);
00119 }
00120 
00134 double flaglet_tiling_axisym_check_identity(double *kappa_lp, double *kappa0_lp, int B_l, int B_p, int L, int P, int J_min_l, int J_min_p)
00135 {
00136     int jl, jp, l, n;
00137     int J_l = s2let_j_max(L, B_l);
00138     int J_p = s2let_j_max(P, B_p);
00139         
00140     double *ident;
00141     ident = (double*)calloc(L * P, sizeof(double));
00142 
00143     //printf("Tilling identity: \n");
00144     for (n = 0; n < P; n++){
00145         for (l = 0; l < L; l++){
00146             ident[l+n*L] = pow(kappa0_lp[n * L + l], 2.0);
00147         }
00148     }
00149 
00150     double sum = 0.0;
00151     for (n = 0; n < P; n++){
00152         for (l = 0; l < L; l++){
00153             for (jp = J_min_p; jp <= J_p; jp++){
00154                 for (jl = J_min_l; jl <= J_l; jl++){
00155                     //printf(" %f ",kappa_lp[ jp*(J_l+1)*L*P  + jl*L*P + n*L + l ]);
00156                     ident[l+n*L] += pow(kappa_lp[ jp*(J_l+1)*L*P  + jl*L*P + n*L + l ], 2.0);
00157                 }
00158             }
00159             //printf(" %2.2f ", ident[l+n*L]);
00160             sum += ident[l+n*L] - 1.000;
00161         }
00162         //printf("\n");
00163     }
00164 
00165     free(ident);
00166     
00167     return sum;
00168 }
00169 
00170 
00171 
 All Files Functions Defines