00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PLANCK_SHARP_CXX_H
00033 #define PLANCK_SHARP_CXX_H
00034
00035 #include <complex>
00036 #include "sharp_lowlevel.h"
00037 #include "sharp_geomhelpers.h"
00038 #include "sharp_almhelpers.h"
00039
00040 class sharp_base
00041 {
00042 protected:
00043 sharp_alm_info *ainfo;
00044 sharp_geom_info *ginfo;
00045
00046 public:
00047 sharp_base()
00048 : ainfo(0), ginfo(0) {}
00049 ~sharp_base()
00050 {
00051 sharp_destroy_geom_info(ginfo);
00052 sharp_destroy_alm_info(ainfo);
00053 }
00054
00055 void set_general_geometry (int nrings, const int *nph, const ptrdiff_t *ofs,
00056 const int *stride, const double *phi0, const double *theta,
00057 const double *wgt)
00058 {
00059 if (ginfo) sharp_destroy_geom_info(ginfo);
00060 sharp_make_geom_info (nrings, nph, ofs, stride, phi0, theta, wgt, &ginfo);
00061 }
00062
00063 void set_ECP_geometry (int nrings, int nphi)
00064 {
00065 if (ginfo) sharp_destroy_geom_info(ginfo);
00066 sharp_make_ecp_geom_info (nrings, nphi, 0., 1, nphi, &ginfo);
00067 }
00068
00069 void set_Gauss_geometry (int nrings, int nphi)
00070 {
00071 if (ginfo) sharp_destroy_geom_info(ginfo);
00072 sharp_make_gauss_geom_info (nrings, nphi, 0., 1, nphi, &ginfo);
00073 }
00074
00075 void set_Healpix_geometry (int nside)
00076 {
00077 if (ginfo) sharp_destroy_geom_info(ginfo);
00078 sharp_make_healpix_geom_info (nside, 1, &ginfo);
00079 }
00080
00081 void set_weighted_Healpix_geometry (int nside, const double *weight)
00082 {
00083 if (ginfo) sharp_destroy_geom_info(ginfo);
00084 sharp_make_weighted_healpix_geom_info (nside, 1, weight, &ginfo);
00085 }
00086
00087 void set_triangular_alm_info (int lmax, int mmax)
00088 {
00089 if (ainfo) sharp_destroy_alm_info(ainfo);
00090 sharp_make_triangular_alm_info (lmax, mmax, 1, &ainfo);
00091 }
00092
00093 const sharp_geom_info* get_geom_info() const { return ginfo; }
00094 const sharp_alm_info* get_alm_info() const { return ainfo; }
00095 };
00096
00097 template<typename T> struct cxxjobhelper__ {};
00098
00099 template<> struct cxxjobhelper__<double>
00100 { enum {val=SHARP_DP}; };
00101
00102 template<> struct cxxjobhelper__<float>
00103 { enum {val=0}; };
00104
00105
00106 template<typename T> class sharp_cxxjob: public sharp_base
00107 {
00108 private:
00109 static void *conv (T *ptr)
00110 { return reinterpret_cast<void *>(ptr); }
00111 static void *conv (std::complex<T> *ptr)
00112 { return reinterpret_cast<void *>(ptr); }
00113 static void *conv (const T *ptr)
00114 { return const_cast<void *>(reinterpret_cast<const void *>(ptr)); }
00115 static void *conv (const std::complex<T> *ptr)
00116 { return const_cast<void *>(reinterpret_cast<const void *>(ptr)); }
00117
00118 public:
00119 void alm2map (const T *alm, T *map, bool add)
00120 {
00121 void *aptr=conv(alm), *mptr=conv(map);
00122 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00123 sharp_execute (SHARP_ALM2MAP, 0, &aptr, &mptr, ginfo, ainfo, 1,
00124 flags,0,0);
00125 }
00126 void alm2map (const std::complex<T> *alm, T *map, bool add)
00127 {
00128 void *aptr=conv(alm), *mptr=conv(map);
00129 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00130 sharp_execute (SHARP_ALM2MAP, 0, &aptr, &mptr, ginfo, ainfo, 1,
00131 flags,0,0);
00132 }
00133 void alm2map_spin (const T *alm1, const T *alm2,
00134 T *map1, T *map2, int spin, bool add)
00135 {
00136 void *aptr[2], *mptr[2];
00137 aptr[0]=conv(alm1); aptr[1]=conv(alm2);
00138 mptr[0]=conv(map1); mptr[1]=conv(map2);
00139 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00140 sharp_execute (SHARP_ALM2MAP,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
00141 }
00142 void alm2map_spin (const std::complex<T> *alm1, const std::complex<T> *alm2,
00143 T *map1, T *map2, int spin, bool add)
00144 {
00145 void *aptr[2], *mptr[2];
00146 aptr[0]=conv(alm1); aptr[1]=conv(alm2);
00147 mptr[0]=conv(map1); mptr[1]=conv(map2);
00148 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00149 sharp_execute (SHARP_ALM2MAP,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
00150 }
00151 void alm2map_der1 (const T *alm, T *map1, T *map2, bool add)
00152 {
00153 void *aptr=conv(alm), *mptr[2];
00154 mptr[0]=conv(map1); mptr[1]=conv(map2);
00155 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00156 sharp_execute (SHARP_ALM2MAP_DERIV1,1,&aptr,mptr,ginfo,ainfo,1,flags,0,0);
00157 }
00158 void alm2map_der1 (const std::complex<T> *alm, T *map1, T *map2, bool add)
00159 {
00160 void *aptr=conv(alm), *mptr[2];
00161 mptr[0]=conv(map1); mptr[1]=conv(map2);
00162 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00163 sharp_execute (SHARP_ALM2MAP_DERIV1,1,&aptr,mptr,ginfo,ainfo,1,flags,0,0);
00164 }
00165 void map2alm (const T *map, T *alm, bool add)
00166 {
00167 void *aptr=conv(alm), *mptr=conv(map);
00168 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00169 sharp_execute (SHARP_MAP2ALM,0,&aptr,&mptr,ginfo,ainfo,1,flags,0,0);
00170 }
00171 void map2alm (const T *map, std::complex<T> *alm, bool add)
00172 {
00173 void *aptr=conv(alm), *mptr=conv(map);
00174 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00175 sharp_execute (SHARP_MAP2ALM,0,&aptr,&mptr,ginfo,ainfo,1,flags,0,0);
00176 }
00177 void map2alm_spin (const T *map1, const T *map2, T *alm1, T *alm2,
00178 int spin, bool add)
00179 {
00180 void *aptr[2], *mptr[2];
00181 aptr[0]=conv(alm1); aptr[1]=conv(alm2);
00182 mptr[0]=conv(map1); mptr[1]=conv(map2);
00183 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00184 sharp_execute (SHARP_MAP2ALM,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
00185 }
00186 void map2alm_spin (const T *map1, const T *map2, std::complex<T> *alm1,
00187 std::complex<T> *alm2, int spin, bool add)
00188 {
00189 void *aptr[2], *mptr[2];
00190 aptr[0]=conv(alm1); aptr[1]=conv(alm2);
00191 mptr[0]=conv(map1); mptr[1]=conv(map2);
00192 int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
00193 sharp_execute (SHARP_MAP2ALM,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
00194 }
00195 };
00196
00197 #endif