Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

alm.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.jpl.nasa.gov
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*! \file alm.h
00028  *  Class for storing spherical harmonic coefficients.
00029  *
00030  *  Copyright (C) 2003, 2004, 2005 Max-Planck-Society
00031  *  \author Martin Reinecke
00032  */
00033 
00034 #ifndef PLANCK_ALM_H
00035 #define PLANCK_ALM_H
00036 
00037 #include "arr.h"
00038 
00039 /*! Class for storing spherical harmonic coefficients. */
00040 template<typename T> class Alm
00041   {
00042   private:
00043     int lmax, mmax, tval;
00044     arr<T> alm;
00045 
00046   public:
00047     /*! Constructs an Alm object with given \a lmax and \a mmax. */
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     /*! Deletes the old coefficients and allocates storage according to
00054         \a lmax and \a mmax. */
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     /*! Sets all coefficients to zero. */
00066     void SetToZero ()
00067       { alm.fill (0); }
00068 
00069     /*! Multiplies all coefficients by \a factor. */
00070     template<typename T2> void Scale (const T2 &factor)
00071       { for (int m=0; m<alm.size(); ++m) alm[m]*=factor; }
00072     /*! \a a(l,m) *= \a factor[l] for all \a l,m. */
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     /*! Adds \a num to a_00. */
00081     template<typename T2> void Add (const T2 &num)
00082       { alm[0]+=num; }
00083 
00084     /*! Returns a reference to the specified coefficient. */
00085     T &operator() (int l, int m)
00086       { return alm[((m*(tval-m))>>1) + l]; }
00087     /*! Returns a constant reference to the specified coefficient. */
00088     const T &operator() (int l, int m) const
00089       { return alm[((m*(tval-m))>>1) + l]; }
00090 
00091     /*! Returns a pointer for a given m, from which the address of a_lm
00092         can be obtained by adding l. */
00093     T *mstart (int m)
00094       { return &alm[(m*(tval-m))>>1]; }
00095     /*! Returns a pointer for a given m, from which the address of a_lm
00096         can be obtained by adding l. */
00097     const T *mstart (int m) const
00098       { return &alm[(m*(tval-m))>>1]; }
00099 
00100     /*! Returns the maximum \a l */
00101     int Lmax() const { return lmax; }
00102     /*! Returns the maximum \a m */
00103     int Mmax() const { return mmax; }
00104 
00105     /*! Returns a constant reference to the a_lm data. */
00106     const arr<T> &Alms () const { return alm; }
00107 
00108     /*! Swaps the contents of two A_lm objects. */
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     /*! Returns \a true, if both objects have the same \a lmax and \a mmax,
00118         else  \a false. */
00119     bool conformable (const Alm &other) const
00120       { return ((lmax==other.lmax) && (mmax==other.mmax)); }
00121   };
00122 
00123 #endif

Generated on Fri Jul 8 09:37:15 2005 for Healpix C++