alm.h
Go to the documentation of this file.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
00049 static long Num_Alms (int l, int m)
00050 {
00051 planck_assert(m<=l,"mmax must not be larger than lmax");
00052 return ((m+1)*(m+2))/2 + (m+1)*(l-m);
00053 }
00054
00055
00056 Alm (int lmax_=0, int mmax_=0)
00057 : lmax(lmax_), mmax(mmax_), tval(2*lmax+1),
00058 alm (Num_Alms(lmax,mmax))
00059 {}
00060
00061
00062
00063 void Set (int lmax_, int mmax_)
00064 {
00065 lmax=lmax_;
00066 mmax=mmax_;
00067 tval=2*lmax+1;
00068 alm.alloc(Num_Alms(lmax,mmax));
00069 }
00070
00071
00072
00073 void Set (arr<T> &data, int lmax_, int mmax_)
00074 {
00075 planck_assert (Num_Alms(lmax_,mmax_)==data.size(),"wrong array size");
00076 lmax=lmax_;
00077 mmax=mmax_;
00078 tval=2*lmax+1;
00079 alm.transfer(data);
00080 }
00081
00082
00083 void SetToZero ()
00084 { alm.fill (0); }
00085
00086
00087 template<typename T2> void Scale (const T2 &factor)
00088 { for (int m=0; m<alm.size(); ++m) alm[m]*=factor; }
00089
00090 template<typename T2> void ScaleL (const arr<T2> &factor)
00091 {
00092 planck_assert(factor.size()>lmax, "alm.ScaleL: factor array too short");
00093 for (int m=0; m<=mmax; ++m)
00094 for (int l=m; l<=lmax; ++l)
00095 operator()(l,m)*=factor[l];
00096 }
00097
00098 template<typename T2> void Add (const T2 &num)
00099 { alm[0]+=num; }
00100
00101
00102 T &operator() (int l, int m)
00103 { return alm[((m*(tval-m))>>1) + l]; }
00104
00105 const T &operator() (int l, int m) const
00106 { return alm[((m*(tval-m))>>1) + l]; }
00107
00108
00109
00110 T *mstart (int m)
00111 { return &alm[(m*(tval-m))>>1]; }
00112
00113
00114 const T *mstart (int m) const
00115 { return &alm[(m*(tval-m))>>1]; }
00116
00117
00118 int Lmax() const { return lmax; }
00119
00120 int Mmax() const { return mmax; }
00121
00122
00123 const arr<T> &Alms () const { return alm; }
00124
00125
00126 void swap (Alm &other)
00127 {
00128 std::swap(lmax, other.lmax);
00129 std::swap(mmax, other.mmax);
00130 std::swap(tval, other.tval);
00131 alm.swap(other.alm);
00132 }
00133
00134
00135
00136 bool conformable (const Alm &other) const
00137 { return ((lmax==other.lmax) && (mmax==other.mmax)); }
00138
00139
00140 void Add (const Alm &other)
00141 {
00142 planck_assert (conformable(other), "A_lm are not conformable");
00143 for (int m=0; m<alm.size(); ++m)
00144 alm[m] += other.alm[m];
00145 }
00146 };
00147
00148 #endif