NASA - Jet Propulsion Laboratory
    + View the NASA Portal
Search JPL
Jet Propulsion Laboratory Home Earth Solar System Stars & Galaxies Technology
Introduction Background Software Links

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, 2006, 2007 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     /*! Returns the number of coefficients in an Alm object with maximum
00048         quantum numbers \a l and \a m. */
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     /*! Constructs an Alm object with given \a lmax and \a mmax. */
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     /*! Deletes the old coefficients and allocates storage according to
00062         \a lmax and \a mmax. */
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     /*! Deallocates the old coefficients and uses the content of \a data
00072         for storage. \a data is deallocated during the call. */
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     /*! Sets all coefficients to zero. */
00083     void SetToZero ()
00084       { alm.fill (0); }
00085 
00086     /*! Multiplies all coefficients by \a factor. */
00087     template<typename T2> void Scale (const T2 &factor)
00088       { for (int m=0; m<alm.size(); ++m) alm[m]*=factor; }
00089     /*! \a a(l,m) *= \a factor[l] for all \a l,m. */
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     /*! Adds \a num to a_00. */
00098     template<typename T2> void Add (const T2 &num)
00099       { alm[0]+=num; }
00100 
00101     /*! Returns a reference to the specified coefficient. */
00102     T &operator() (int l, int m)
00103       { return alm[((m*(tval-m))>>1) + l]; }
00104     /*! Returns a constant reference to the specified coefficient. */
00105     const T &operator() (int l, int m) const
00106       { return alm[((m*(tval-m))>>1) + l]; }
00107 
00108     /*! Returns a pointer for a given m, from which the address of a_lm
00109         can be obtained by adding l. */
00110     T *mstart (int m)
00111       { return &alm[(m*(tval-m))>>1]; }
00112     /*! Returns a pointer for a given m, from which the address of a_lm
00113         can be obtained by adding l. */
00114     const T *mstart (int m) const
00115       { return &alm[(m*(tval-m))>>1]; }
00116 
00117     /*! Returns the maximum \a l */
00118     int Lmax() const { return lmax; }
00119     /*! Returns the maximum \a m */
00120     int Mmax() const { return mmax; }
00121 
00122     /*! Returns a constant reference to the a_lm data. */
00123     const arr<T> &Alms () const { return alm; }
00124 
00125     /*! Swaps the contents of two A_lm objects. */
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     /*! Returns \a true, if both objects have the same \a lmax and \a mmax,
00135         else  \a false. */
00136     bool conformable (const Alm &other) const
00137       { return ((lmax==other.lmax) && (mmax==other.mmax)); }
00138 
00139     /*! Adds all coefficients from \a other to the own coefficients. */
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

Generated on Fri Jun 18 16:12:30 2010 for Healpix C++
Privacy / Copyright
FIRST GOV Contact: NASA Home Page Site Manager:
Webmaster:

CL 03-2650