LevelS SHT library  3.50
sharp_cxx.h
Go to the documentation of this file.
1 /*
2  * This file is part of libsharp.
3  *
4  * libsharp is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * libsharp is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with libsharp; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * libsharp is being developed at the Max-Planck-Institut fuer Astrophysik
21  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
22  * (DLR).
23  */
24 
25 /*! \file sharp_cxx.h
26  * Spherical transform library
27  *
28  * Copyright (C) 2012-2017 Max-Planck-Society
29  * \author Martin Reinecke
30  */
31 
32 #ifndef PLANCK_SHARP_CXX_H
33 #define PLANCK_SHARP_CXX_H
34 
35 #include <complex>
36 #include "sharp_lowlevel.h"
37 #include "sharp_geomhelpers.h"
38 #include "sharp_almhelpers.h"
39 
40 class sharp_base
41  {
42  protected:
43  sharp_alm_info *ainfo;
44  sharp_geom_info *ginfo;
45 
46  public:
47  sharp_base()
48  : ainfo(0), ginfo(0) {}
49  ~sharp_base()
50  {
51  if (ginfo) sharp_destroy_geom_info(ginfo);
52  if (ainfo) sharp_destroy_alm_info(ainfo);
53  }
54 
55  void set_general_geometry (int nrings, const int *nph, const ptrdiff_t *ofs,
56  const int *stride, const double *phi0, const double *theta,
57  const double *wgt)
58  {
59  if (ginfo) sharp_destroy_geom_info(ginfo);
60  sharp_make_geom_info (nrings, nph, ofs, stride, phi0, theta, wgt, &ginfo);
61  }
62 
63  void set_ECP_geometry (int nrings, int nphi)
64  {
65  if (ginfo) sharp_destroy_geom_info(ginfo);
66  sharp_make_ecp_geom_info (nrings, nphi, 0., 1, nphi, &ginfo);
67  }
68 
69  void set_Gauss_geometry (int nrings, int nphi)
70  {
71  if (ginfo) sharp_destroy_geom_info(ginfo);
72  sharp_make_gauss_geom_info (nrings, nphi, 0., 1, nphi, &ginfo);
73  }
74 
75  void set_Healpix_geometry (int nside)
76  {
77  if (ginfo) sharp_destroy_geom_info(ginfo);
78  sharp_make_healpix_geom_info (nside, 1, &ginfo);
79  }
80 
81  void set_weighted_Healpix_geometry (int nside, const double *weight)
82  {
83  if (ginfo) sharp_destroy_geom_info(ginfo);
84  sharp_make_weighted_healpix_geom_info (nside, 1, weight, &ginfo);
85  }
86 
87  void set_triangular_alm_info (int lmax, int mmax)
88  {
89  if (ainfo) sharp_destroy_alm_info(ainfo);
90  sharp_make_triangular_alm_info (lmax, mmax, 1, &ainfo);
91  }
92 
93  const sharp_geom_info* get_geom_info() const { return ginfo; }
94  const sharp_alm_info* get_alm_info() const { return ainfo; }
95  };
96 
97 template<typename T> struct cxxjobhelper__ {};
98 
99 template<> struct cxxjobhelper__<double>
100  { enum {val=SHARP_DP}; };
101 
102 template<> struct cxxjobhelper__<float>
103  { enum {val=0}; };
104 
105 
106 template<typename T> class sharp_cxxjob: public sharp_base
107  {
108  private:
109  static void *conv (T *ptr)
110  { return reinterpret_cast<void *>(ptr); }
111  static void *conv (std::complex<T> *ptr)
112  { return reinterpret_cast<void *>(ptr); }
113  static void *conv (const T *ptr)
114  { return const_cast<void *>(reinterpret_cast<const void *>(ptr)); }
115  static void *conv (const std::complex<T> *ptr)
116  { return const_cast<void *>(reinterpret_cast<const void *>(ptr)); }
117 
118  public:
119  void alm2map (const T *alm, T *map, bool add) const
120  {
121  void *aptr=conv(alm), *mptr=conv(map);
122  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
123  sharp_execute (SHARP_ALM2MAP, 0, &aptr, &mptr, ginfo, ainfo, 1,
124  flags,0,0);
125  }
126  void alm2map (const std::complex<T> *alm, T *map, bool add) const
127  {
128  void *aptr=conv(alm), *mptr=conv(map);
129  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
130  sharp_execute (SHARP_ALM2MAP, 0, &aptr, &mptr, ginfo, ainfo, 1,
131  flags,0,0);
132  }
133  void alm2map_spin (const T *alm1, const T *alm2,
134  T *map1, T *map2, int spin, bool add) const
135  {
136  void *aptr[2], *mptr[2];
137  aptr[0]=conv(alm1); aptr[1]=conv(alm2);
138  mptr[0]=conv(map1); mptr[1]=conv(map2);
139  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
140  sharp_execute (SHARP_ALM2MAP,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
141  }
142  void alm2map_spin (const std::complex<T> *alm1, const std::complex<T> *alm2,
143  T *map1, T *map2, int spin, bool add) const
144  {
145  void *aptr[2], *mptr[2];
146  aptr[0]=conv(alm1); aptr[1]=conv(alm2);
147  mptr[0]=conv(map1); mptr[1]=conv(map2);
148  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
149  sharp_execute (SHARP_ALM2MAP,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
150  }
151  void alm2map_der1 (const T *alm, T *map1, T *map2, bool add) const
152  {
153  void *aptr=conv(alm), *mptr[2];
154  mptr[0]=conv(map1); mptr[1]=conv(map2);
155  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
156  sharp_execute (SHARP_ALM2MAP_DERIV1,1,&aptr,mptr,ginfo,ainfo,1,flags,0,0);
157  }
158  void alm2map_der1 (const std::complex<T> *alm, T *map1, T *map2, bool add)
159  const
160  {
161  void *aptr=conv(alm), *mptr[2];
162  mptr[0]=conv(map1); mptr[1]=conv(map2);
163  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
164  sharp_execute (SHARP_ALM2MAP_DERIV1,1,&aptr,mptr,ginfo,ainfo,1,flags,0,0);
165  }
166  void alm2map_adjoint (const T *map, T *alm, bool add) const
167  {
168  void *aptr=conv(alm), *mptr=conv(map);
169  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
170  sharp_execute (SHARP_Yt,0,&aptr,&mptr,ginfo,ainfo,1,flags,0,0);
171  }
172  void alm2map_adjoint (const T *map, std::complex<T> *alm, bool add) const
173  {
174  void *aptr=conv(alm), *mptr=conv(map);
175  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
176  sharp_execute (SHARP_Yt,0,&aptr,&mptr,ginfo,ainfo,1,flags,0,0);
177  }
178  void alm2map_spin_adjoint (const T *map1, const T *map2, T *alm1, T *alm2,
179  int spin, bool add) const
180  {
181  void *aptr[2], *mptr[2];
182  aptr[0]=conv(alm1); aptr[1]=conv(alm2);
183  mptr[0]=conv(map1); mptr[1]=conv(map2);
184  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
185  sharp_execute (SHARP_Yt,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
186  }
187  void alm2map_spin_adjoint (const T *map1, const T *map2,
188  std::complex<T> *alm1, std::complex<T> *alm2, int spin, bool add) const
189  {
190  alm2map_spin_adjoint (map1, map2, reinterpret_cast<T *>(alm1),
191  reinterpret_cast<T *>(alm2), spin, add);
192  }
193  void map2alm (const T *map, T *alm, bool add) const
194  {
195  void *aptr=conv(alm), *mptr=conv(map);
196  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
197  sharp_execute (SHARP_MAP2ALM,0,&aptr,&mptr,ginfo,ainfo,1,flags,0,0);
198  }
199  void map2alm (const T *map, std::complex<T> *alm, bool add) const
200  {
201  void *aptr=conv(alm), *mptr=conv(map);
202  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
203  sharp_execute (SHARP_MAP2ALM,0,&aptr,&mptr,ginfo,ainfo,1,flags,0,0);
204  }
205  void map2alm_spin (const T *map1, const T *map2, T *alm1, T *alm2,
206  int spin, bool add) const
207  {
208  void *aptr[2], *mptr[2];
209  aptr[0]=conv(alm1); aptr[1]=conv(alm2);
210  mptr[0]=conv(map1); mptr[1]=conv(map2);
211  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
212  sharp_execute (SHARP_MAP2ALM,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
213  }
214  void map2alm_spin (const T *map1, const T *map2, std::complex<T> *alm1,
215  std::complex<T> *alm2, int spin, bool add) const
216  {
217  void *aptr[2], *mptr[2];
218  aptr[0]=conv(alm1); aptr[1]=conv(alm2);
219  mptr[0]=conv(map1); mptr[1]=conv(map2);
220  int flags=cxxjobhelper__<T>::val | (add ? SHARP_ADD : 0);
221  sharp_execute (SHARP_MAP2ALM,spin,aptr,mptr,ginfo,ainfo,1,flags,0,0);
222  }
223  };
224 
225 #endif
void sharp_execute(sharp_jobtype type, int spin, void *alm, void *map, const sharp_geom_info *geom_info, const sharp_alm_info *alm_info, int ntrans, int flags, double *time, unsigned long long *opcnt)
Definition: sharp.c:950
void sharp_destroy_geom_info(sharp_geom_info *geom_info)
Definition: sharp.c:259
void sharp_make_triangular_alm_info(int lmax, int mmax, int stride, sharp_alm_info **alm_info)
void sharp_destroy_alm_info(sharp_alm_info *info)
Definition: sharp.c:191
void sharp_make_geom_info(int nrings, const int *nph, const ptrdiff_t *ofs, const int *stride, const double *phi0, const double *theta, const double *wgt, sharp_geom_info **geom_info)
Definition: sharp.c:198
void sharp_make_gauss_geom_info(int nrings, int nphi, double phi0, int stride_lon, int stride_lat, sharp_geom_info **geom_info)
void sharp_make_weighted_healpix_geom_info(int nside, int stride, const double *weight, sharp_geom_info **geom_info)

Generated on Mon Dec 10 2018 10:24:20 for LevelS SHT library