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
00033
00034 #ifndef PLANCK_ALM_H
00035 #define PLANCK_ALM_H
00036
00037 #include "arr.h"
00038
00039
00040 template<typename T> class Alm
00041 {
00042 private:
00043 int lmax, mmax, tval;
00044 arr<T> alm;
00045
00046 public:
00047
00048 Alm (int lmax_=0, int mmax_=0)
00049 : lmax(lmax_), mmax(mmax_), tval(2*lmax+1),
00050 alm (((mmax+1)*(mmax+2))/2 + (mmax+1)*(lmax-mmax))
00051 { planck_assert(mmax<=lmax,"mmax must not be larger than mmax"); }
00052
00053
00054
00055 void Set (int lmax_, int mmax_)
00056 {
00057 lmax=lmax_;
00058 mmax=mmax_;
00059 tval=2*lmax+1;
00060 planck_assert(mmax<=lmax,"mmax must not be larger than mmax");
00061 int num_alms = ((mmax+1)*(mmax+2))/2 + (mmax+1)*(lmax-mmax);
00062 alm.alloc(num_alms);
00063 }
00064
00065
00066 void SetToZero ()
00067 { alm.fill (0); }
00068
00069
00070 template<typename T2> void Scale (const T2 &factor)
00071 { for (int m=0; m<alm.size(); ++m) alm[m]*=factor; }
00072
00073 template<typename T2> void ScaleL (const arr<T2> &factor)
00074 {
00075 planck_assert(factor.size()>lmax, "alm.ScaleL: factor array too short");
00076 for (int m=0; m<=mmax; ++m)
00077 for (int l=m; l<=lmax; ++l)
00078 operator()(l,m)*=factor[l];
00079 }
00080
00081 template<typename T2> void Add (const T2 &num)
00082 { alm[0]+=num; }
00083
00084
00085 T &operator() (int l, int m)
00086 { return alm[((m*(tval-m))>>1) + l]; }
00087
00088 const T &operator() (int l, int m) const
00089 { return alm[((m*(tval-m))>>1) + l]; }
00090
00091
00092
00093 T *mstart (int m)
00094 { return &alm[(m*(tval-m))>>1]; }
00095
00096
00097 const T *mstart (int m) const
00098 { return &alm[(m*(tval-m))>>1]; }
00099
00100
00101 int Lmax() const { return lmax; }
00102
00103 int Mmax() const { return mmax; }
00104
00105
00106 const arr<T> &Alms () const { return alm; }
00107
00108
00109 void swap (Alm &other)
00110 {
00111 std::swap(lmax, other.lmax);
00112 std::swap(mmax, other.mmax);
00113 std::swap(tval, other.tval);
00114 alm.swap(other.alm);
00115 }
00116
00117
00118
00119 bool conformable (const Alm &other) const
00120 { return ((lmax==other.lmax) && (mmax==other.mmax)); }
00121 };
00122
00123 #endif