source: Sophya/trunk/SophyaLib/Samba/alm.h@ 729

Last change on this file since 729 was 729, checked in by ansari, 26 years ago

addition des Ylm etc.

File size: 3.5 KB
RevLine 
[729]1#ifndef ALM_SEEN
2#define ALM_SEEN
3#include "nbrandom.h"
4#include "nbmath.h"
5#include "tvector.h"
6#include "pexceptions.h"
7/*! Class for inferior triangular matrix (base class for the class Alm) */
8template <class T>
9class TriangularMatrix
10 {
11
12 public :
13
14TriangularMatrix() {};
15 /* instanciate a triangular matrix from the number of rows */
16TriangularMatrix(int rowSize) : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
17TriangularMatrix(const TriangularMatrix<T>& a, bool share=false) : elem_(a.elem_, share), long_diag_(a.long_diag_) {;}
18/*! resize the matrix with a new number of rows */
19inline void ReSizeRow(int rowSize)
20 {
21 long_diag_=(uint_4)rowSize;
22 elem_.ReSize(long_diag_*(long_diag_+1)/2);
23 }
24 inline void SetTemp(bool temp=false) const {elem_.SetTemp(temp);}
25
26inline TriangularMatrix<T>& operator = (const TriangularMatrix<T>& a)
27{
28 elem_=a.elem_;
29 long_diag_ = a.long_diag_;
30 return *this;
31}
32inline T& operator()(int l, int m)
33 {
34 return elem_(adr_ij(l,m));
35 }
36inline T const& operator()(int l, int m) const
37 {
38 return *(elem_.Begin()+ adr_ij(l,m));
39 }
40 inline int_4 rowNumber() const {return (int_4)long_diag_;}
41 private:
42 /*! compute the address of an element in the single array representing the matrix */
43inline uint_4 adr_ij(int i,int j) const
44{
45 int adr= i*(i+1)/2+j;
46 if ( adr >= elem_.Size() || adr <0 )
47{
48 cout << " attention depassement dans triangularMatrix " << endl;
49 cout << " l= " << i << " m= " << j << " tableau reserve longueur " << elem_.Size() << endl;
50}
51 return(i*(i+1)/2+j);
52}
53
54 uint_4 long_diag_;
55 NDataBlock<T> elem_;
56
57 };
58
59
60/*! class for the coefficients \f$a_{lm}\f$ of the development of a function defined on a sphere, in spherical harmonics */
61template <class T>
62class Alm : public TriangularMatrix<complex<T> >
63 {
64 public :
65
66Alm() : TriangularMatrix<complex<T> >() {};
67 /* instanciate the class from the maximum value of the index \f$l\f$ in the sequence of the \f$a_{lm}\f$'s */
68Alm(int nlmax) : TriangularMatrix<complex<T> >(nlmax+1) {;}
69Alm(const Alm<T>& a, bool share=false) : TriangularMatrix<complex<T> >(a, share) {;}
70
71Alm(const TVector<T>& clin, const r_8 fwhm) ;
72/*! resize with a new lmax */
73inline void ReSizeToLmax(int_4 nlmax) {ReSizeRow(nlmax+1);}
74inline int_4 Lmax() const {return rowNumber()-1;}
75TVector<T> powerSpectrum() const;
76
77
78};
79/*! class for a vector with an index running from \f$-m_{max}\f$ to \f$+m_{max}\f$ (then the size of the vector will be actually \f$2m_{max}+1)\f$ */
80template <class T>
81class Bm
82 {
83 public :
84Bm(): nmmax_(0) {;};
85 /* instanciate from the maximum absolute value of the index */
86Bm(int mmax) : nmmax_((uint_4)mmax) { bm_.ReSize( (uint_4)(2*mmax+1) );}
87 Bm(const Bm<T>& b, bool share=false) : nmmax_(b.nmmax_), bm_(b.bm_, share) {;}
88 /*! resize with a new value of mmax */
89inline void ReSizeToMmax(int_4 mmax)
90 {
91 nmmax_=(uint_4)l;
92 bm_.ReSize(2* nmmax_+1);
93 }
94//inline int_4 Size() const {return 2*nmmax_+1;};
95inline T& operator()(int m) {return bm_( adr_i(m));};
96inline T const& operator()(int m) const {return *(bm_.Begin()+ adr_i(m));};
97/*! return the current value of the maximum absolute value of the index */
98inline int_4 Mmax() const
99 {
100 return (int_4)nmmax_;
101 }
102inline Bm<T>& operator = (const Bm<T>& b)
103 {
104 if (this != &b)
105 {
106 nmmax_= b.nmmax_;
107 bm_= b.bm_;
108 }
109 return *this;
110 }
111
112 private:
113/*! return the address in the array representing the vector */
114inline uint_4 adr_i(int i) const
115{
116 return(uint_4)(i+nmmax_);
117}
118
119
120
121 uint_4 nmmax_;
122 NDataBlock<T> bm_;
123
124 };
125
126
127#endif
Note: See TracBrowser for help on using the repository browser.