/* Copyright (C) 2008 Jiri Pittner or This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _GELFAND_H_ #define _GELFAND_H_ #include "la.h" #include "sparsemat.h" #include "fourindex.h" #include "matexp.h" #include "basic.h" using namespace std; using namespace LA; struct abcrow; //indexed from 1 class gelfweight : public NRVec { public: gelfweight(): NRVec() {}; gelfweight(const int n):NRVec(n) {}; inline occnum& operator[](const int i) {return v[i-1];} inline const occnum& operator[](const int i) const {return v[i-1];} }; extern ostream& operator<<(ostream &s, const gelfweight &x); //this inheritance makes a convenient, but not the most efficient implementation, since reference counting is not essential here class gelfpat : public NRSMat { public: gelfpat(): NRSMat() {}; gelfpat(const int n):NRSMat(n) {}; gelfpat(const gelfpat &rhs) : NRSMat(rhs) {}; inline int orbnum() const {return nn;} inline int partnum() const {int i,s=0; for(i=0; i == != ASSUME THE SAME TOP ROW - patterns belonging to the same basis //storage order of the patterns corresponds to lexicographic order inline bool operator==(const gelfpat &rhs) const {return !memcmp(v+nn,rhs.v+nn,sizeof(occnum)*nn*(nn-1)/2);} inline int operator!=(const gelfpat &rhs) const {return memcmp(v+nn,rhs.v+nn,sizeof(occnum)*nn*(nn-1)/2);} inline bool operator<(const gelfpat &rhs) const {return memcmp(v+nn,rhs.v+nn,sizeof(occnum)*nn*(nn-1)/2)<0;} inline bool operator>(const gelfpat &rhs) const {return memcmp(v+nn,rhs.v+nn,sizeof(occnum)*nn*(nn-1)/2)>0;} int find(const gelfpat *basis, int bassize) const; void weight(gelfweight &w) const; //calculate its weight }; extern istream& operator>>(istream &s, gelfpat &x); extern ostream& operator<<(ostream &s, const gelfpat &x); class MyPartition : public NRVec { public: MyPartition() : NRVec() {}; explicit MyPartition(const int n):NRVec(n) {}; MyPartition(const int a, const int n):NRVec(a,n) {}; inline MyPartition(const gelfpat &g) : NRVec(0,g.orbnum()) {int n=g.orbnum(); for(int i=0;i inline REAL contract(const oper &op, const bool tr, const vector &bra, const vector &ket) { return tr?ket*(op*bra):bra*(op*ket); } //and specialization for bra,ket==sparse matrix with one dimension ==1 template inline T contract(const SparseMat &op, const bool tr, const SparseMat &bra, const SparseMat &ket) { if(bra.nrows()!=1 && bra.ncols()!=1 || ket.nrows()!=1 && ket.ncols()!=1 ) laerror("dimension of bra or ket != 1 in contract"); SparseMat tmp(tr?op.ncols():op.nrows(),1),result(1,1); tmp.gemm((T)0,op,tr?'t':'n',ket,ket.nrows()==1?'t':'n',(T)1); result.gemm((T)1,bra,bra.ncols()==1?'t':'n',tmp,'n',(T)1); return result.trace(); } //functions for CI coupling coefficients extern int gelfpat_gener(const gelfpat &g); extern SparseMat twobodyop(const Ugenerators &E, const int r,const int s,const int t,const int u,const bool onlyhalf=1,const bool normal=1); extern SparseMat symtwobodyop(const Ugenerators &E, const int r,const int s,const int t,const int u,const bool onlyhalf=1,const bool normal=1); //for CC amplitudes extern SparseMat antisymonebodyop(const Ugenerators &E, const int p, const int q, const bool onlyhalf=1); extern SparseMat antisymtwobodyop(const Ugenerators &E, const int r,const int s,const int t,const int u,const bool onlyhalf=1,const bool normal=1); extern fourindex > allantisymtwobodyop(const Ugenerators &E, const bool onlyhalf=1, const bool normal=1); extern fourindex > allantisymonebodyop(const Ugenerators &E, const bool onlyhalf=1); //functions to get density matrices, for both dense and sparse CI vectors template NRSMat onedensity(const Ugenerators &E, const vector &ket) { int n,i,j; n=E.nrows(); NRSMat result(n); for(i=1;i<=n;++i) for(j=i;j<=n;++j) result(i,j)=contract(E(i,j),0,ket,ket); return result; } template NRMat onetrdensity(const Ugenerators &E, const vector &bra, const vector &ket) { int n,i,j; n=E.nrows(); NRMat result(n,n); for(i=1;i<=n;++i) for(j=1;j<=n;++j) result(i,j)=contract(E(i,j),E.transp(i,j),bra,ket); return result; } //twodensity template fourindex twodensity(const Ugenerators &E, const vector &ket) { int r,s,t,u; int n=E.nrows(); fourindex result(n); for(r=1; r<=n; r++) for(s=1; s<=r; s++) for(t=1; t<=r; t++) { int h=t; if(t==r && s=tu if r==t*/ for(u=1; u<=h; u++) { REAL tmp= contract(symtwobodyop(E,r,s,t,u,0),ket,ket);//generate full representation to support contraction with sparse ket #ifdef SPARSEEPSILON if(abs(tmp)>SPARSEEPSILON) #else if(tmp) #endif result.add(r,s,t,u,tmp); } } return result; } //commutator of E matrices inline SparseMat Ecommutator(const Ugenerators &E, const int p, const int q, const int r, const int s) { return commutator(E(p,q),E(r,s),E.transp(p,q),E.transp(r,s)); } //generation of gelfand basis extern int gelfpat_gener(const gelfpat &g, NRVec *gelfbasis, Ugenerators *E); //generation of partitions extern int partgener(int size,int n,int typ,void (*process) (int,MyPartition &)); extern double ifact(const int i); #endif