OptIndex::OptIndex(const CheMPS2::Hamiltonian &ham) { SymmInfo.setGroup(ham.getNGroup()); this->L = ham.L; this->Nirreps = ham.SymmInfo.getNumberOfIrreps(); NORB.resize(Nirreps); NORBcumulative.resize(Nirreps+1); int sum_check = 0; NORBcumulative[0] = 0; for (int irrep=0; irrep<Nirreps; irrep++) { NORB[irrep] = ham.irrep2num_orb[irrep]; sum_check += NORB[irrep]; NORBcumulative[irrep+1] = NORBcumulative[irrep] + NORB[irrep]; } if (sum_check != L) std::cerr << "OptIndex::OptIndex : Sum over all orbitals is not L." << std::endl; irrep_each_orbital.resize(NORBcumulative[Nirreps]); for (int irrep=0; irrep<Nirreps; irrep++) for (int cnt=0; cnt<NORB[irrep]; cnt++) irrep_each_orbital[ NORBcumulative[irrep] + cnt ] = irrep; }
int main(void){ #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::mpi_init(); #endif CheMPS2::Initialize::Init(); //The Hamiltonian: 1D Hubbard model const int L = 10; const int Group = 0; const double U = 2.0; const double T = -1.0; int * irreps = new int[L]; for (int cnt=0; cnt<L; cnt++){ irreps[cnt] = 0; } //The Hamiltonian initializes all its matrix elements to 0.0 CheMPS2::Hamiltonian * Ham = new CheMPS2::Hamiltonian(L, Group, irreps); delete [] irreps; for (int cnt=0; cnt<L; cnt++){ Ham->setVmat(cnt,cnt,cnt,cnt,U); } for (int cnt=0; cnt<L-1; cnt++){ Ham->setTmat(cnt,cnt+1,T); } //The targeted state const int TwoS = 5; const int N = 9; const int Irrep = 0; CheMPS2::Problem * Prob = new CheMPS2::Problem(Ham, TwoS, N, Irrep); //The convergence scheme CheMPS2::ConvergenceScheme * OptScheme = new CheMPS2::ConvergenceScheme(2); //OptScheme->setInstruction(instruction, DSU(2), Econvergence, maxSweeps, noisePrefactor); OptScheme->setInstruction(0, 30, 1e-10, 3, 0.1); OptScheme->setInstruction(1, 1000, 1e-10, 10, 0.0); //Run ground state calculation CheMPS2::DMRG * theDMRG = new CheMPS2::DMRG(Prob, OptScheme); const double EnergyDMRG = theDMRG->Solve(); theDMRG->calc2DMandCorrelations(); #ifdef CHEMPS2_MPI_COMPILATION if ( CheMPS2::MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ) #endif { theDMRG->getCorrelations()->Print(); } //Clean up DMRG if (CheMPS2::DMRG_storeMpsOnDisk){ theDMRG->deleteStoredMPS(); } if (CheMPS2::DMRG_storeRenormOptrOnDisk){ theDMRG->deleteStoredOperators(); } delete theDMRG; delete OptScheme; delete Prob; //Calculate FCI reference energy double EnergyFCI = 0.0; #ifdef CHEMPS2_MPI_COMPILATION if ( CheMPS2::MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ) #endif { const int Nel_up = ( N + TwoS ) / 2; const int Nel_down = ( N - TwoS ) / 2; const double maxMemWorkMB = 10.0; const int FCIverbose = 1; CheMPS2::FCI * theFCI = new CheMPS2::FCI(Ham, Nel_up, Nel_down, Irrep, maxMemWorkMB, FCIverbose); EnergyFCI = theFCI->GSDavidson(NULL); delete theFCI; } #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::broadcast_array_double( &EnergyFCI, 1, MPI_CHEMPS2_MASTER ); #endif //Clean up the Hamiltonian delete Ham; //Check succes const bool success = ( fabs( EnergyDMRG - EnergyFCI ) < 1e-8 ) ? true : false; #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::mpi_finalize(); #endif cout << "================> Did test 4 succeed : "; if (success){ cout << "yes" << endl; return 0; //Success } cout << "no" << endl; return 7; //Fail }
int main(void){ #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::mpi_init(); #endif CheMPS2::Initialize::Init(); //Square 2D Hubbard model with PBC const int L_linear = 3; // Linear size const int L_square = L_linear * L_linear; // Number of orbitals const int group = 0; // C1 symmetry const double U = 5.0; // On-site repulsion const double T = -1.0; // Hopping term const int N = 9; // Number of electrons const int TwoS = 1; // Two times the spin const int Irrep = 0; // Irrep = A (C1 symmetry) //Create the Hamiltonian (eightfold permutation symmetry is OK for site basis) int * irreps = new int[L_square]; for (int cnt=0; cnt<L_square; cnt++){ irreps[cnt] = 0; } //The Hamiltonian initializes all its matrix elements to 0.0 CheMPS2::Hamiltonian * Ham = new CheMPS2::Hamiltonian(L_square, group, irreps); delete [] irreps; //Fill with the site-basis matrix elements for (int cnt=0; cnt<L_square; cnt++){ Ham->setVmat(cnt,cnt,cnt,cnt,U); } for (int ix=0; ix<L_linear; ix++){ for (int iy=0; iy<L_linear; iy++){ const int idx1 = ix + L_linear * iy; // This site const int idx2 = (( ix + 1 ) % L_linear) + L_linear * iy; // Right neighbour (PBC) const int idx3 = ix + L_linear * ((( iy + 1 ) % L_linear)); //Upper neighbour (PBC) Ham->setTmat(idx1,idx2,T); Ham->setTmat(idx1,idx3,T); } } //The problem object CheMPS2::Problem * Prob = new CheMPS2::Problem(Ham, TwoS, N, Irrep); //The convergence scheme CheMPS2::ConvergenceScheme * OptScheme = new CheMPS2::ConvergenceScheme(2); //OptScheme->setInstruction(instruction, DSU(2), Econvergence, maxSweeps, noisePrefactor); OptScheme->setInstruction(0, 500, 1e-10, 3, 0.05); OptScheme->setInstruction(1, 1000, 1e-10, 10, 0.0 ); //Run ground state calculation CheMPS2::DMRG * theDMRG = new CheMPS2::DMRG(Prob, OptScheme); const double EnergySite = theDMRG->Solve(); theDMRG->calc2DMandCorrelations(); //Clean up DMRG if (CheMPS2::DMRG_storeMpsOnDisk){ theDMRG->deleteStoredMPS(); } if (CheMPS2::DMRG_storeRenormOptrOnDisk){ theDMRG->deleteStoredOperators(); } delete theDMRG; //Hack: overwrite the matrix elements in momentum space (4-fold symmetry!!!) directly in the Problem object theDMRG = new CheMPS2::DMRG(Prob, OptScheme); // Prob->construct_mxelem() is called now for (int orb1=0; orb1<L_square; orb1++){ const int k1x = orb1 % L_linear; const int k1y = orb1 / L_linear; const double Telem1 = 2*T*( cos((2*M_PI*k1x)/L_linear) + cos((2*M_PI*k1y)/L_linear) ); for (int orb2=0; orb2<L_square; orb2++){ const int k2x = orb2 % L_linear; const int k2y = orb2 / L_linear; const double Telem2 = 2*T*( cos((2*M_PI*k2x)/L_linear) + cos((2*M_PI*k2y)/L_linear) ); for (int orb3=0; orb3<L_square; orb3++){ const int k3x = orb3 % L_linear; const int k3y = orb3 / L_linear; for (int orb4=0; orb4<L_square; orb4++){ const int k4x = orb4 % L_linear; const int k4y = orb4 / L_linear; const bool kx_conservation = (((k1x+k2x) % L_linear) == ((k3x+k4x) % L_linear))?true:false; const bool ky_conservation = (((k1y+k2y) % L_linear) == ((k3y+k4y) % L_linear))?true:false; double temp = 0.0; if ( kx_conservation && ky_conservation ){ temp += U/L_square; } if (( orb1 == orb3 ) && ( orb2 == orb4 )){ temp += (Telem1+Telem2)/(N-1); } Prob->setMxElement(orb1,orb2,orb3,orb4,temp); } } } } theDMRG->PreSolve(); // New matrix elements require reconstruction of complementary renormalized operators const double EnergyMomentum = theDMRG->Solve(); theDMRG->calc2DMandCorrelations(); //Clean up if (CheMPS2::DMRG_storeMpsOnDisk){ theDMRG->deleteStoredMPS(); } if (CheMPS2::DMRG_storeRenormOptrOnDisk){ theDMRG->deleteStoredOperators(); } delete theDMRG; delete OptScheme; delete Prob; delete Ham; //Check succes const bool success = ( fabs( EnergySite - EnergyMomentum ) < 1e-8 ) ? true : false; #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::mpi_finalize(); #endif cout << "================> Did test 10 succeed : "; if (success){ cout << "yes" << endl; return 0; //Success } cout << "no" << endl; return 7; //Fail }
int main(void){ double RMS = 1.0; double RMS2 = 1.0; #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::mpi_init(); if ( CheMPS2::MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ) #endif { CheMPS2::Initialize::Init(); //The path to the matrix elements string matrixelements = "/home/ankit/cheMPS_tzgnd/tests/matrixelements/O2.CCPVDZ.FCIDUMP"; //The Hamiltonian const int psi4groupnumber = 7; // d2h -- see Irreps.h and O2.ccpvdz.out CheMPS2::Hamiltonian * Ham = new CheMPS2::Hamiltonian( matrixelements, psi4groupnumber ); Ham->save(); const int L = Ham->getL(); const int GroupNumber = Ham->getNGroup(); int * OrbitalIrreps = new int[ L ]; for (int orb = 0; orb < L; orb++){ OrbitalIrreps[orb] = Ham->getOrbitalIrrep(orb); } //Use the other initializer CheMPS2::Hamiltonian * HamLoaded = new CheMPS2::Hamiltonian(L, GroupNumber, OrbitalIrreps); delete [] OrbitalIrreps; HamLoaded->read(); //Test whether it's the same thing RMS = 0.0; double RMSabs = 0.0; double temp = 0.0; temp = Ham->getEconst(); RMSabs += temp * temp; temp = Ham->getEconst() - HamLoaded->getEconst(); RMS += temp * temp; for (int i1=0; i1<L; i1++){ for (int i2=0; i2<L; i2++){ temp = Ham->getTmat(i1,i2); RMSabs += temp * temp; temp = Ham->getTmat(i1,i2) - HamLoaded->getTmat(i1,i2); RMS += temp * temp; for (int i3=0; i3<L; i3++){ for (int i4=0; i4<L; i4++){ temp = Ham->getVmat(i1,i2,i3,i4); RMSabs += temp * temp; temp = Ham->getVmat(i1,i2,i3,i4) - HamLoaded->getVmat(i1,i2,i3,i4); RMS += temp * temp; } } } } RMS = sqrt(RMS); RMSabs = sqrt(RMSabs); cout << "The 2-norm of all Hamiltonian matrix elements is " << RMSabs << endl; cout << "The RMS difference between Ham and HamLoaded is " << RMS << endl; delete HamLoaded; //To load an HDF5 dump and immediately fill the Hamiltonian const bool fileh5 = true; CheMPS2::Hamiltonian * HamLoaded2 = new CheMPS2::Hamiltonian( fileh5 ); //Test whether it's the same thing RMS2 = 0.0; temp = Ham->getEconst() - HamLoaded2->getEconst(); RMS2 += temp * temp; for (int i1=0; i1<L; i1++){ for (int i2=0; i2<L; i2++){ temp = Ham->getTmat(i1,i2) - HamLoaded2->getTmat(i1,i2); RMS2 += temp * temp; for (int i3=0; i3<L; i3++){ for (int i4=0; i4<L; i4++){ temp = Ham->getVmat(i1,i2,i3,i4) - HamLoaded2->getVmat(i1,i2,i3,i4); RMS2 += temp * temp; } } } } RMS2 = sqrt(RMS2); cout << "The RMS difference between Ham and HamLoaded2 is " << RMS2 << endl; //Clean up delete Ham; delete HamLoaded2; stringstream temp1; temp1 << "rm " << CheMPS2::HAMILTONIAN_TmatStorageName; int info = system(temp1.str().c_str()); stringstream temp2; temp2 << "rm " << CheMPS2::HAMILTONIAN_VmatStorageName; info = system(temp2.str().c_str()); stringstream temp3; temp3 << "rm " << CheMPS2::HAMILTONIAN_ParentStorageName; info = system(temp3.str().c_str()); } #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::broadcast_array_double( &RMS, 1, MPI_CHEMPS2_MASTER ); CheMPS2::MPIchemps2::broadcast_array_double( &RMS2, 1, MPI_CHEMPS2_MASTER ); #endif //Check succes const bool success = (( RMS < 1e-10 ) && ( RMS2 < 1e-10 )) ? true : false; #ifdef CHEMPS2_MPI_COMPILATION CheMPS2::MPIchemps2::mpi_finalize(); #endif cout << "================> Did test 7 succeed : "; if (success){ cout << "yes" << endl; return 0; //Success } cout << "no" << endl; return 7; //Fail }