/home/pxiang/workspace_new/CalculateGreenFunction/src/formMatrix/formMatrix.h

Go to the documentation of this file.
00001 /*
00002  * formMatrix.h
00003  *
00004  *  Created on: Jun 17, 2014
00005  *      Author: pxiang
00006  */
00007 
00008 #ifndef FORMMATRIX_H_
00009 #define FORMMATRIX_H_
00010 
00011 #include "../basis_set/basis.h"
00012 #include "../Utility/misc.h"
00013 #include "../Utility/random_generator.h"
00014 #include "../IO/binaryIO.h"
00015 
00016 /* this InteractionData struct contains no information about the size of the lattice*/
00017 // the lattice geometry information is stored in class LatticeShape
00024 typedef struct {
00025         double onsiteE, hop, dyn;
00026         bool randomOnSite, randomHop, randomDyn;
00027         int maxDistance; // beyond which the interaction is set to zero
00028         unsigned seed;
00029         bool longRangeHop;
00030         bool longRangeDyn;
00031 } InteractionData;
00032 
00033 
00034 
00044 class Interaction {
00045 public:
00046         Interaction(LatticeShape& lattice, InteractionData& interactionData) {
00047                 dim = lattice.getDim();
00048                 seed = interactionData.seed;
00049                 rng.SetSeed(seed);
00050                 if (dim==1) {
00051                         int xsite = lattice.getXmax() + 1;
00052                         maxDistance = interactionData.maxDistance;
00053                         // initialize the hopping matrix
00054                         t = DMatrix::Zero(xsite,xsite);
00055                         hop_maxDistance = interactionData.longRangeHop?maxDistance:1;
00056                         if (interactionData.randomHop) {
00057                                 setRandomMatrix(t, interactionData.hop, hop_maxDistance, seed+10);
00058                         } else {
00059                                 // set all element to constant
00060                                 setConstantMatrix(t, interactionData.hop, hop_maxDistance);
00061                         }
00062 
00063                         // initialize the dynamic matrix
00064                         d = DMatrix::Zero(xsite,xsite);
00065                         dyn_maxDistance = interactionData.longRangeDyn?maxDistance:1;
00066                         if (interactionData.randomDyn) {
00067                                 setRandomMatrix(d, interactionData.dyn, dyn_maxDistance, seed+20);
00068                         } else {
00069                                 // set all element to constant
00070                                 setConstantMatrix(d, interactionData.dyn, dyn_maxDistance);
00071                         }
00072 
00073                         // initialize the dynamic matrix
00074                         e = DVector::Zero(xsite);
00075                         if (interactionData.randomOnSite) {
00076                                 setRandomVector(e, interactionData.onsiteE);
00077                         } else {
00078                                 // set all element to constant
00079                                 setConstantVector(e, interactionData.onsiteE);
00080                         }
00081                 } //end of if for dim=1
00082 
00083 
00084         }
00085 
00086         double hop(Basis& basis1, Basis& basis2) {
00087                 double result;
00088                 // for 1D case
00089                 switch (dim) {
00090                 case 1:
00091                         if (basis1[0]==basis2[0]) {
00092                                 result = t(basis1[1], basis2[1]);
00093                         } else if (basis1[1]==basis2[1]) {
00094                                 result = t(basis1[0], basis2[0]);
00095                         } else {
00096                                 result = 0.0;
00097                         }
00098                         break;
00099                 case 2:
00100                 case 3:
00101                 default:
00102                         result = 0.0;
00103                 }
00104                 return result;
00105         }
00106 
00107         double dyn(Basis& basis) {
00108                 double result;
00109                 switch (dim) {
00110                 case 1:
00111                         result = d(basis[0], basis[1]);
00112                         break;
00113                 case 2:
00114                 case 3:
00115                 default:
00116                         result = 0.0;
00117                 }
00118                 return result;
00119         }
00120 
00121         double onsiteE(Basis& basis) {
00122                 double result;
00123                 switch (dim) {
00124                 case 1:
00125                         result = e(basis[0]) +  e(basis[1]);
00126                         break;
00127                 case 2:
00128                 case 3:
00129                 default:
00130                         result = 0.0;
00131                 }
00132                 return result;
00133         }
00134 
00135         // if the seed is not set, use the default one
00136         void setRandomSeed(unsigned inputSeed) {
00137                 seed = inputSeed;
00138                 rng.SetSeed(seed);
00139         }
00140 
00141         // obtain the range of interactions
00142         int getMaxDistance() {
00143                 return maxDistance;
00144         }
00145 
00146         // obtain the range of hopping interactions
00147         int getMaxDistanceHop() {
00148                 return hop_maxDistance;
00149         }
00150 
00151         // obtain the range of dynamic interactions
00152         int getMaxDistanceDyn() {
00153                 return dyn_maxDistance;
00154         }
00155 
00156         // destructor
00157         ~Interaction() {
00158                 // release the memory of the matrices
00159                 t.resize(0,0);
00160                 d.resize(0,0);
00161                 e.resize(0);
00162         }
00163 
00164 private:
00165         DMatrix t;
00166         DMatrix d;
00167         DVector e;
00168         int maxDistance;
00169         int hop_maxDistance, dyn_maxDistance;
00170         int dim;
00171         unsigned seed;
00172         RandomNumberGenerator rng;
00173 
00174 
00175         void setRandomMatrix(DMatrix& m, double maxVal, int maxDistance, unsigned seed_) {
00176                 //RandomNumberMatrix rnm(m.rows(), m.cols(), seed_);
00177                 //rng.SetSeed(seed_);
00178                 srand(seed_);
00179                 DMatrix rnm = DMatrix::Random(m.rows(), m.cols());
00180                 int xsite = m.rows();
00181                 for (int i=0; i<xsite-1; ++i) {
00182                         for (int incr=1; incr<=maxDistance && i+incr<xsite; ++incr) {
00183                                 m(i,i+incr) = maxVal*rnm(i, i+incr)/std::pow(incr,3.0); // range [0, hop)
00184                                 m(i+incr,i) = m(i,i+incr);
00185                         }
00186                 }
00187         }
00188 
00189 
00190 
00191         void setConstantMatrix(DMatrix& m, double maxVal, int maxDistance) {
00192                 int xsite = m.rows();
00193                 for (int i=0; i<xsite-1; ++i) {
00194                         for (int incr=1; incr<=maxDistance && i+incr<xsite; ++incr) {
00195                                 m(i,i+incr) = maxVal/std::pow(incr,3.0); // range [0, hop)
00196                                 m(i+incr,i) = m(i,i+incr);
00197                         }
00198                 }
00199         }
00200 
00201         void setRandomVector(DVector& v, double maxVal) {
00202                 for (int i=0; i<v.size(); ++i) {
00203                         // set v(i) a random value between [-maxVal/2, maxVal/2)
00204                         v(i) = maxVal*(2*rng.randomReal()-1.0)/2;
00205                 }
00206         }
00207 
00208         void setConstantVector(DVector& v, double maxVal) {
00209                 for (int i=0; i<v.size(); ++i) {
00210                         v(i) = maxVal;
00211                 }
00212         }
00213 
00214 };
00215 
00216 // a pointer to an Interaction object
00217 extern Interaction *pInteraction;
00218 extern LatticeShape *pLattice;
00219 
00220 void getMSize(int K, int Kp, int& rows, int& cols);
00221 
00222 void getZSize(int K, int& rows, int& cols);
00223 
00224 void setInteractions(LatticeShape& lattice, InteractionData& interactionData);
00225 
00226 void formMatrixZ(int K, dcomplex Energy, CDMatrix& ZK);
00227 
00228 void formMatrixM(int K, int Kp, CDMatrix& MKKp);
00229 
00230 void formMatrixW(int K, dcomplex energy, CDMatrix& WK);
00231 
00232 void formMatrixAlpha(int K, CDMatrix& AlphaK);
00233 
00234 void formMatrixBeta(int K, CDMatrix& BetaK);
00235 
00236 #endif /* FORMMATRIX_H_ */

Generated on Fri Oct 31 16:58:45 2014 for CalculateGreenFunction by  doxygen 1.4.7