Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:34

0001 #ifndef _ClebschGordanCoefficientSet_h_
0002 #define _ClebschGordanCoefficientSet_h_
0003 #include <map>
0004 #include <algorithm>
0005 #include <cmath>
0006 namespace Genfun {
0007 
0008   class ClebschGordanCoefficientSet {
0009 
0010   public:
0011 
0012     double operator () (unsigned int l1, unsigned int l2, int m1, int m2, int L, int M) const; 
0013     
0014   private:
0015 
0016     // Key used to optimize access (look up previously calcuated results).
0017     class Key {
0018 
0019     public:
0020       
0021       inline Key(unsigned int xl1, unsigned int xl2, int xm1, int xm2, unsigned int xL):
0022     l1(xl1),l2(xl2),m1(xm1),m2(xm2),L(xL) {}
0023       
0024       inline bool operator < (const Key & o) const {
0025     if ( l1!=o.l1) return l1<o.l1;
0026     if ( l2!=o.l2) return l2<o.l2;
0027     if ( m1!=o.m1) return m1<o.m1;
0028     if ( m2!=o.m2) return m2<o.m2;
0029     if ( L!=o.L  ) return L<o.L;
0030     return false;
0031       }
0032       
0033       
0034       inline bool operator== (const Key & o) const {
0035     return l1==o.l1 && l2 == o.l2 && m1==o.m1 && m2==o.m2 && L == o.L;
0036       }
0037 
0038     private:
0039       
0040       unsigned int l1;
0041       unsigned     l2;
0042       int          m1;
0043       int          m2;
0044       unsigned int L;
0045       // M=m1+m2;
0046       
0047     };
0048     
0049 
0050     mutable std::map<Key, double> coeff;
0051 
0052     static double calcCoefficient(int l1, int l2, int L, int m1, int m2, int M);
0053 
0054   };
0055 
0056 
0057 
0058 
0059   inline double ClebschGordanCoefficientSet::operator () (unsigned int l1, unsigned int l2, int m1, int m2, int L, int M) const {
0060     if ((m1+m2)!=M) return 0;
0061     
0062     Key key(l1,l2,m1,m2,L);
0063     std::map<Key,double>::iterator i=coeff.find(key),end=coeff.end();
0064     if (i==end) {
0065       double c = calcCoefficient(l1, l2, L, m1, m2,M);
0066       coeff[key]=c;
0067       return c;
0068     }
0069 
0070     return (*i).second;
0071    
0072   }
0073 }
0074 
0075 #endif