pax_global_header00006660000000000000000000000064125674417270014531gustar00rootroot0000000000000052 comment=0c68cc362588a0b3e82a993e6fdc188b43e78351 CheMPS2-1.6/000077500000000000000000000000001256744172700125405ustar00rootroot00000000000000CheMPS2-1.6/.gitignore000066400000000000000000000001561256744172700145320ustar00rootroot00000000000000mycompilation build Build objects *~ *.o *.swp integrals/pyscf/*.pyc PyCheMPS2/build PyCheMPS2/PyCheMPS2.cpp CheMPS2-1.6/CHANGELOG.md000066400000000000000000000016751256744172700143620ustar00rootroot00000000000000#### Version 1.6 (2015-08-26): * Disk i/o improvements with HDF5's hyperslab * Performance counters in DMRG class * Faster preconditioner FCI Green's function solver * Bug fix FCIDUMP read-in * chemps2 binary * manpage.1 for binary #### Version 1.5 (2015-06-18): * DMRG-CI plugin pyscf * DMRG-SCF plugin psi4 (official release for psi4) * Fix bug small electron number FCI class * FCIDUMP file support * Sphinx documentation * DMRG class supports 4-fold permutation symmetry (i.o. 8-fold) * Hybrid MPI & OpenMP for DMRG + 2-RDM (not for DMRG-SCF yet) #### Version 1.4 (2014-11-23): * 2-RDM storage class * Optimization OpenMP over symmetry blocks Heff * DIIS acceleration DMRG-SCF * Two-orbital mutual information and correlation functions * Augmented Hessian NR Edmiston-Ruedenberg orbital localization * PyCheMPS2: python interface to libchemps2 * FCI Green's function solver * State-averaged DMRG-SCF #### Version 1.0 (2014-04-08): * Initial release CheMPS2-1.6/CMake/000077500000000000000000000000001256744172700135205ustar00rootroot00000000000000CheMPS2-1.6/CMake/FindGSL.cmake000066400000000000000000000101631256744172700157510ustar00rootroot00000000000000# Try to find gnu scientific library GSL # See # http://www.gnu.org/software/gsl/ and # http://gnuwin32.sourceforge.net/packages/gsl.htm # # Based on a script of Felix Woelk and Jan Woetzel # (www.mip.informatik.uni-kiel.de) # # It defines the following variables: # GSL_FOUND - system has GSL lib # GSL_INCLUDE_DIRS - where to find headers # GSL_LIBRARIES - full path to the libraries # GSL_LIBRARY_DIRS, the directory where the PLplot library is found. # CMAKE_GSL_CXX_FLAGS = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`" # GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix # GSL_EXE_LINKER_FLAGS = rpath on Unix set( GSL_FOUND OFF ) set( GSL_CBLAS_FOUND OFF ) # Windows, but not for Cygwin and MSys where gsl-config is available if( WIN32 AND NOT CYGWIN AND NOT MSYS ) # look for headers find_path( GSL_INCLUDE_DIR NAMES gsl/gsl_cdf.h gsl/gsl_randist.h ) if( GSL_INCLUDE_DIR ) # look for gsl library find_library( GSL_LIBRARY NAMES gsl ) if( GSL_LIBRARY ) set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} ) get_filename_component( GSL_LIBRARY_DIRS ${GSL_LIBRARY} PATH ) set( GSL_FOUND ON ) endif( GSL_LIBRARY ) # look for gsl cblas library find_library( GSL_CBLAS_LIBRARY NAMES gslcblas ) if( GSL_CBLAS_LIBRARY ) set( GSL_CBLAS_FOUND ON ) endif( GSL_CBLAS_LIBRARY ) set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ) endif( GSL_INCLUDE_DIR ) mark_as_advanced( GSL_INCLUDE_DIR GSL_LIBRARY GSL_CBLAS_LIBRARY ) else( WIN32 AND NOT CYGWIN AND NOT MSYS ) if( UNIX OR MSYS ) find_program( GSL_CONFIG_EXECUTABLE gsl-config /usr/bin/ /usr/local/bin ) if( GSL_CONFIG_EXECUTABLE ) set( GSL_FOUND ON ) # run the gsl-config program to get cxxflags execute_process( COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --cflags OUTPUT_VARIABLE GSL_CFLAGS RESULT_VARIABLE RET ERROR_QUIET ) if( RET EQUAL 0 ) string( STRIP "${GSL_CFLAGS}" GSL_CFLAGS ) separate_arguments( GSL_CFLAGS ) # parse definitions from cflags; drop -D* from CFLAGS string( REGEX MATCHALL "-D[^;]+" GSL_DEFINITIONS "${GSL_CFLAGS}" ) string( REGEX REPLACE "-D[^;]+;" "" GSL_CFLAGS "${GSL_CFLAGS}" ) # parse include dirs from cflags; drop -I prefix string( REGEX MATCHALL "-I[^;]+" GSL_INCLUDE_DIRS "${GSL_CFLAGS}" ) string( REPLACE "-I" "" GSL_INCLUDE_DIRS "${GSL_INCLUDE_DIRS}") string( REGEX REPLACE "-I[^;]+;" "" GSL_CFLAGS "${GSL_CFLAGS}") message("GSL_DEFINITIONS=${GSL_DEFINITIONS}") message("GSL_INCLUDE_DIRS=${GSL_INCLUDE_DIRS}") message("GSL_CFLAGS=${GSL_CFLAGS}") else( RET EQUAL 0 ) set( GSL_FOUND FALSE ) endif( RET EQUAL 0 ) # run the gsl-config program to get the libs execute_process( COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --libs OUTPUT_VARIABLE GSL_LIBRARIES RESULT_VARIABLE RET ERROR_QUIET ) if( RET EQUAL 0 ) string(STRIP "${GSL_LIBRARIES}" GSL_LIBRARIES ) separate_arguments( GSL_LIBRARIES ) # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES) string( REGEX MATCHALL "-L[^;]+" GSL_LIBRARY_DIRS "${GSL_LIBRARIES}" ) string( REPLACE "-L" "" GSL_LIBRARY_DIRS "${GSL_LIBRARY_DIRS}" ) else( RET EQUAL 0 ) set( GSL_FOUND FALSE ) endif( RET EQUAL 0 ) MARK_AS_ADVANCED( GSL_CFLAGS ) message( STATUS "Using GSL from ${GSL_PREFIX}" ) else( GSL_CONFIG_EXECUTABLE ) message( STATUS "FindGSL: gsl-config not found.") endif( GSL_CONFIG_EXECUTABLE ) endif( UNIX OR MSYS ) endif( WIN32 AND NOT CYGWIN AND NOT MSYS ) if( GSL_FOUND ) if( NOT GSL_FIND_QUIETLY ) message( STATUS "FindGSL: Found both GSL headers and library" ) endif( NOT GSL_FIND_QUIETLY ) else( GSL_FOUND ) if( GSL_FIND_REQUIRED ) message( FATAL_ERROR "FindGSL: Could not find GSL headers or library" ) endif( GSL_FIND_REQUIRED ) endif( GSL_FOUND )CheMPS2-1.6/CMake/FindSphinx.cmake000066400000000000000000000020751256744172700166000ustar00rootroot00000000000000# - This module looks for Sphinx # Find the Sphinx documentation generator # # This modules defines # SPHINX_EXECUTABLE # SPHINX_FOUND #============================================================================= # Copyright 2002-2009 Kitware, Inc. # Copyright 2009-2011 Peter Colberg # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file COPYING-CMAKE-SCRIPTS for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) find_program(SPHINX_EXECUTABLE NAMES sphinx-build HINTS $ENV{SPHINX_DIR} PATH_SUFFIXES bin DOC "Sphinx documentation generator" ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE ) mark_as_advanced( SPHINX_EXECUTABLE ) CheMPS2-1.6/CMakeLists.txt000066400000000000000000000074131256744172700153050ustar00rootroot00000000000000project (CheMPS2) set (CheMPS2_VERSION "1.6") set (CheMPS2_AUTHORS "Sebastian Wouters") set (CheMPS2_DESCRIPTION "A spin-adapted implementation of DMRG for ab initio quantum chemistry") set (CheMPS2_EMAIL "sebastianwouters@gmail.com") set (CheMPS2_URL "https://github.com/SebWouters/CheMPS2") set (CheMPS2_LICENSE "GNU General Public License, version 2") set (CheMPS2_LIB_SOVERSION 1) include (GNUInstallDirs) cmake_minimum_required (VERSION 2.8.11) option (MKL "Compile using the MKL" OFF) option (BUILD_DOXYGEN "Use Doxygen to create a HTML/PDF manual" OFF) option (BUILD_SPHINX "Build the user manual with Sphinx" OFF) option (STATIC_ONLY "Compile only the static library" OFF) option (ENABLE_TESTS "Compile the tests" ON) option (ENABLE_XHOST "Enable processor-specific optimizations" ON) option (ENABLE_GENERIC "Enable mostly static linking in shared library" OFF) option (WITH_MPI "Build the library with MPI" OFF) set (CMAKE_VERBOSE_MAKEFILE OFF) find_package (OpenMP) if (OPENMP_FOUND) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif (OPENMP_FOUND) include (CheckCXXCompilerFlag) if (ENABLE_XHOST) check_cxx_compiler_flag (-xHost HAS_XHOST) check_cxx_compiler_flag (-march=native HAS_MARCH_NATIVE) if (HAS_XHOST) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost") elseif (HAS_MARCH_NATIVE) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") endif () endif (ENABLE_XHOST) set (CMAKE_CXX_FLAGS "-g -O3 ${CMAKE_CXX_FLAGS}") check_cxx_compiler_flag (-ipo HAS_IPO) if (HAS_IPO) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") endif (HAS_IPO) check_cxx_compiler_flag (-flto HAS_FLTO) if (HAS_FLTO) set (CMAKE_CXX_FLAGS "-flto ${CMAKE_CXX_FLAGS}") endif (HAS_FLTO) if (ENABLE_GENERIC) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc") check_cxx_compiler_flag (-static-intel HAS_INTEL_COMPILERS) if (HAS_INTEL_COMPILERS) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd10237") endif (HAS_INTEL_COMPILERS) endif (ENABLE_GENERIC) set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CheMPS2_SOURCE_DIR}/CMake/") link_directories ($ENV{LD_LIBRARY_PATH}) if (MKL) set ( ENV{BLA_VENDOR} "Intel10_64lp" ) endif (MKL) if (WITH_MPI) add_definitions (-DCHEMPS2_MPI_COMPILATION) endif (WITH_MPI) if (LAPACK_LIBRARIES) message(STATUS "LAPACK detection suppressed. Using: ${LAPACK_LIBRARIES}") else (LAPACK_LIBRARIES) find_package (LAPACK REQUIRED) endif (LAPACK_LIBRARIES) if (HDF5_LIBRARIES AND HDF5_INCLUDE_DIRS) message(STATUS "HDF5 detection suppressed. Using: ${HDF5_LIBRARIES} and includes ${HDF5_INCLUDE_DIRS}") else (HDF5_LIBRARIES AND HDF5_INCLUDE_DIRS) find_package (HDF5 REQUIRED) endif (HDF5_LIBRARIES AND HDF5_INCLUDE_DIRS) if (GSL_LIBRARIES) message(STATUS "GSL detection suppressed. Using: ${GSL_LIBRARIES}") else (GSL_LIBRARIES) find_package (GSL REQUIRED) endif (GSL_LIBRARIES) enable_testing () add_subdirectory (CheMPS2) if (ENABLE_TESTS) add_subdirectory (tests) endif (ENABLE_TESTS) if (BUILD_SPHINX) add_subdirectory (sphinx) endif (BUILD_SPHINX) if (BUILD_DOXYGEN) find_package (Doxygen) if (NOT DOXYGEN_FOUND) message (FATAL_ERROR "Doxygen is needed to build the documentation. Please install it correctly.") endif (NOT DOXYGEN_FOUND) configure_file (${CheMPS2_SOURCE_DIR}/CheMPS2/Doxyfile.in ${CheMPS2_BINARY_DIR}/Doxyfile @ONLY IMMEDIATE) add_custom_target (doc COMMAND ${DOXYGEN_EXECUTABLE} ${CheMPS2_BINARY_DIR}/Doxyfile SOURCES ${CheMPS2_BINARY_DIR}/Doxyfile) endif (BUILD_DOXYGEN) CheMPS2-1.6/CheMPS2/000077500000000000000000000000001256744172700137015ustar00rootroot00000000000000CheMPS2-1.6/CheMPS2/CASSCF.cpp000066400000000000000000000410011256744172700153430ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include "CASSCF.h" #include "Lapack.h" using std::string; using std::ifstream; using std::cout; using std::endl; CheMPS2::CASSCF::CASSCF(const string filename){ HamOrig = new Hamiltonian(filename); shouldHamOrigBeDeleted = true; L = HamOrig->getL(); SymmInfo.setGroup(HamOrig->getNGroup()); numberOfIrreps = SymmInfo.getNumberOfIrreps(); allocateAndFillOCC(filename); setupStartCalled = false; } CheMPS2::CASSCF::CASSCF(Hamiltonian * HamIn, int * DOCCin, int * SOCCin){ HamOrig = HamIn; shouldHamOrigBeDeleted = false; L = HamOrig->getL(); SymmInfo.setGroup(HamOrig->getNGroup()); numberOfIrreps = SymmInfo.getNumberOfIrreps(); allocateAndFillOCC(DOCCin, SOCCin); setupStartCalled = false; } CheMPS2::CASSCF::~CASSCF(){ if (shouldHamOrigBeDeleted){ delete HamOrig; } delete [] DOCC; delete [] SOCC; if (setupStartCalled){ delete theRotatedTEI; delete [] DMRG1DM; delete [] DMRG2DM; //The following objects depend on iHandler: delete them first delete theFmatrix; delete theQmatOCC; delete theQmatACT; delete theQmatWORK; delete theTmatrix; delete wmattilde; delete unitary; delete iHandler; if (theDIIS!=NULL){ delete theDIIS; } } } int CheMPS2::CASSCF::getNumberOfIrreps(){ return numberOfIrreps; } void CheMPS2::CASSCF::copy2DMover(TwoDM * theDMRG2DM, const int totOrbDMRG, double * localDMRG2DM){ for (int i1=0; i1getTwoDMA_HAM(i1, i2, i3, i4); } } } } } void CheMPS2::CASSCF::setDMRG1DM(const int nDMRGelectrons, const int totOrbDMRG, double * localDMRG1DM, double * localDMRG2DM){ const double prefactor = 1.0/(nDMRGelectrons-1.0); for (int cnt1=0; cnt1getNirreps(); const int totOrbDMRG = localIdx->getDMRGcumulative( numIrreps ); const int size = totOrbDMRG * totOrbDMRG; for (int cnt=0; cntgetNDMRG(irrep); if (NDMRG>0){ double * blockUnit = unitary->getBlock(irrep); double * blockEigs = eigenvecs + passed * ( 1 + totOrbDMRG ); for (int row=0; rowgetNirreps(); int totOrbDMRG = localIdx->getDMRGcumulative( numIrreps ); int size = totOrbDMRG * totOrbDMRG; double * eigenval = workmem + size; for (int cnt=0; cntgetNDMRG(irrep); if (NDMRG > 0){ //Calculate the eigenvectors and values per block dsyev_(&jobz, &uplo, &NDMRG, eigenvecs + passed*(1+totOrbDMRG), &totOrbDMRG, eigenval + passed, workmem, &size, &info); //Sort the eigenvecs for (int col=0; col Gamma_{ajkl} dgemm_(&tran,¬r,&power1,&power3,&power1,&alpha,eigenvecs,&power1,localDMRG2DM,&power1,&beta,work,&power1); //2DM: Gamma_{ajkl} --> Gamma_{ajkd} dgemm_(¬r,¬r,&power3,&power1,&power1,&alpha,work,&power3,eigenvecs,&power1,&beta,localDMRG2DM,&power3); //2DM: Gamma_{ajkd} --> Gamma_{ajcd} for (int cnt=0; cnt Gamma_{abcd} for (int cnt=0; cntgetNORB(irrep); double * Umat = unitary->getBlock(irrep); double * work = theQmatWORK->getBlock(irrep); double * block = myMatrix->getBlock(irrep); double alpha = 1.0; double beta = 0.0; char trans = 'T'; char notrans = 'N'; dgemm_(¬rans, ¬rans, &linsize, &linsize, &linsize, &alpha, Umat, &linsize, block, &linsize, &beta, work, &linsize); dgemm_(¬rans, &trans, &linsize, &linsize, &linsize, &alpha, work, &linsize, Umat, &linsize, &beta, block, &linsize); } } void CheMPS2::CASSCF::constructCoulombAndExchangeMatrixInOrigIndices(DMRGSCFmatrix * densityMatrix, DMRGSCFmatrix * resultMatrix){ for (int irrepQ = 0; irrepQ < numberOfIrreps; irrepQ++){ const int linearsizeQ = iHandler->getNORB(irrepQ); const int numberOfUniqueIndices = (linearsizeQ * (linearsizeQ + 1))/2; #pragma omp parallel for schedule(static) for (int combinedindex = 0; combinedindex < numberOfUniqueIndices; combinedindex++){ int colQ = 1; while ( (colQ*(colQ+1))/2 <= combinedindex ){ colQ++; } colQ -= 1; int rowQ = combinedindex - (colQ*(colQ+1))/2; const int HamIndexI = iHandler->getOrigNOCCstart(irrepQ) + rowQ; const int HamIndexJ = iHandler->getOrigNOCCstart(irrepQ) + colQ; double theValue = 0.0; for (int irrepN = 0; irrepN < numberOfIrreps; irrepN++){ const int linearsizeN = iHandler->getNORB( irrepN ); for (int rowN = 0; rowN < linearsizeN; rowN++){ const int HamIndexS = iHandler->getOrigNOCCstart( irrepN ) + rowN; theValue += densityMatrix->get(irrepN, rowN, rowN) * ( HamOrig->getVmat(HamIndexI,HamIndexS,HamIndexJ,HamIndexS) - 0.5 * HamOrig->getVmat(HamIndexI,HamIndexJ,HamIndexS,HamIndexS) ); for (int colN = rowN+1; colN < linearsizeN; colN++){ const int HamIndexT = iHandler->getOrigNOCCstart( irrepN ) + colN; theValue += densityMatrix->get(irrepN, rowN, colN) * ( 2 * HamOrig->getVmat(HamIndexI,HamIndexS,HamIndexJ,HamIndexT) - 0.5 * HamOrig->getVmat(HamIndexI,HamIndexJ,HamIndexS,HamIndexT) - 0.5 * HamOrig->getVmat(HamIndexI,HamIndexJ,HamIndexT,HamIndexS) ); } } } resultMatrix->set( irrepQ, rowQ, colQ, theValue ); resultMatrix->set( irrepQ, colQ, rowQ, theValue ); } } } void CheMPS2::CASSCF::buildQmatOCC(){ for (int irrep = 0; irrep < numberOfIrreps; irrep++){ int linsize = iHandler->getNORB(irrep); int NOCC = iHandler->getNOCC(irrep); double alpha = 2.0; double beta = 0.0; char trans = 'T'; char notrans = 'N'; double * Umat = unitary->getBlock(irrep); double * work = theQmatWORK->getBlock(irrep); dgemm_(&trans, ¬rans, &linsize, &linsize, &NOCC, &alpha, Umat, &linsize, Umat, &linsize, &beta, work, &linsize); } constructCoulombAndExchangeMatrixInOrigIndices( theQmatWORK, theQmatOCC ); rotateOldToNew( theQmatOCC ); } void CheMPS2::CASSCF::buildQmatACT(){ for (int irrep = 0; irrep < numberOfIrreps; irrep++){ int linsize = iHandler->getNORB(irrep); int NDMRG = iHandler->getNDMRG(irrep); double alpha = 1.0; double beta = 0.0; char trans = 'T'; char notrans = 'N'; double * Umat = unitary->getBlock(irrep) + iHandler->getNOCC(irrep); double * work = theQmatWORK->getBlock(irrep); double * work2 = theQmatACT->getBlock(irrep); double * RDM = DMRG1DM + iHandler->getDMRGcumulative(irrep) * ( 1 + nOrbDMRG ); dgemm_(&trans, ¬rans, &linsize, &NDMRG, &NDMRG, &alpha, Umat, &linsize, RDM, &nOrbDMRG, &beta, work2, &linsize); dgemm_(¬rans, ¬rans, &linsize, &linsize, &NDMRG, &alpha, work2, &linsize, Umat, &linsize, &beta, work, &linsize); } constructCoulombAndExchangeMatrixInOrigIndices( theQmatWORK, theQmatACT ); rotateOldToNew( theQmatACT ); } void CheMPS2::CASSCF::buildTmatrix(){ for (int irrep = 0; irrep < numberOfIrreps; irrep++){ const int NumORB = iHandler->getNORB(irrep); for (int row = 0; row < NumORB; row++){ const int HamIndexRow = iHandler->getOrigNOCCstart(irrep) + row; for (int col = 0; col < NumORB; col++){ const int HamIndexCol = iHandler->getOrigNOCCstart(irrep) + col; theTmatrix->set( irrep, row, col, HamOrig->getTmat(HamIndexRow, HamIndexCol) ); } } } rotateOldToNew( theTmatrix ); } void CheMPS2::CASSCF::fillConstAndTmatDMRG(Hamiltonian * HamDMRG) const{ //Constant part of the energy double value = HamOrig->getEconst(); for (int irrep = 0; irrep < numberOfIrreps; irrep++){ for (int orb = 0; orb < iHandler->getNOCC(irrep); orb++){ value += 2 * theTmatrix->get(irrep, orb, orb) + theQmatOCC->get(irrep, orb, orb); } } HamDMRG->setEconst(value); //One-body terms: diagonal in the irreps for (int irrep=0; irrepgetDMRGcumulative(irrep); const int linsizeDMRG = iHandler->getNDMRG(irrep); const int NumOCC = iHandler->getNOCC(irrep); for (int cnt1=0; cnt1setTmat( passedDMRG+cnt1, passedDMRG+cnt2, theTmatrix->get(irrep, NumOCC+cnt1, NumOCC+cnt2) + theQmatOCC->get(irrep, NumOCC+cnt1, NumOCC+cnt2) ); } } } } void CheMPS2::CASSCF::allocateAndFillOCC(int * DOCCin, int * SOCCin){ DOCC = new int[numberOfIrreps]; SOCC = new int[numberOfIrreps]; for (int cnt=0; cntgetDMRGcumulative(numberOfIrreps); DMRG1DM = new double[nOrbDMRG * nOrbDMRG]; DMRG2DM = new double[nOrbDMRG * nOrbDMRG * nOrbDMRG * nOrbDMRG]; //To calculate the F-matrix and Q-matrix(occ,act) elements only once, and to store them for future access theFmatrix = new DMRGSCFmatrix( iHandler ); theFmatrix->clear(); theQmatOCC = new DMRGSCFmatrix( iHandler ); theQmatOCC->clear(); theQmatACT = new DMRGSCFmatrix( iHandler ); theQmatACT->clear(); theQmatWORK= new DMRGSCFmatrix( iHandler );theQmatWORK->clear(); theTmatrix = new DMRGSCFmatrix( iHandler ); theTmatrix->clear(); //To calculate the w_tilde elements only once, and store them for future access wmattilde = new DMRGSCFwtilde( iHandler ); //Print the MO info. This requires the indexHandler to be created... checkHF(); //Print what we have just set up. iHandler->Print(); cout << "DMRGSCF::setupStart : Number of variables in the x-matrix = " << unitary->getNumVariablesX() << endl; } CheMPS2-1.6/CheMPS2/CASSCFdebug.cpp000066400000000000000000000157421256744172700163670ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include "CASSCF.h" using std::cout; using std::endl; void CheMPS2::CASSCF::checkHF(){ double EnergyHF = HamOrig->getEconst(); int passed = 0; int irrep = 0; cout << "Single particle energy levels : " << endl; for (int cnt=0; cntgetTmat(cnt,cnt); if (cnt-passed < DOCC[irrep]){ EnergyHF += 2*HamOrig->getTmat(cnt,cnt); } else{ if (cnt-passed < SOCC[irrep] + DOCC[irrep]) EnergyHF += HamOrig->getTmat(cnt,cnt); } int passed2 = 0; int irrep2 = 0; for (int cnt2=0; cnt2getVmat(cnt,cnt2,cnt,cnt2) - HamOrig->getVmat(cnt,cnt,cnt2,cnt2); } else { if (cnt2-passed2 < SOCC[irrep2] + DOCC[irrep2]) SPenergy += HamOrig->getVmat(cnt,cnt2,cnt,cnt2) - HamOrig->getVmat(cnt,cnt,cnt2,cnt2); } if ((cnt-passed < DOCC[irrep]) && (cnt2-passed2 < DOCC[irrep2])){ EnergyHF += 2*HamOrig->getVmat(cnt,cnt2,cnt,cnt2) - HamOrig->getVmat(cnt,cnt,cnt2,cnt2); } if ((cnt-passed >= DOCC[irrep]) && (cnt-passed < SOCC[irrep] + DOCC[irrep]) && (cnt2-passed2 < DOCC[irrep2])){ EnergyHF += HamOrig->getVmat(cnt,cnt2,cnt,cnt2) - 0.5*HamOrig->getVmat(cnt,cnt,cnt2,cnt2); } if ((cnt-passed < DOCC[irrep]) && (cnt2-passed2 >= DOCC[irrep2]) && (cnt2-passed2 < SOCC[irrep2] + DOCC[irrep2])){ EnergyHF += HamOrig->getVmat(cnt,cnt2,cnt,cnt2) - 0.5*HamOrig->getVmat(cnt,cnt,cnt2,cnt2); } if ((cnt-passed >= DOCC[irrep]) && (cnt-passed < SOCC[irrep] + DOCC[irrep]) && (cnt2-passed2 >= DOCC[irrep2]) && (cnt2-passed2 < SOCC[irrep2] + DOCC[irrep2])){ EnergyHF += 0.5*HamOrig->getVmat(cnt,cnt2,cnt,cnt2) - 0.5*HamOrig->getVmat(cnt,cnt,cnt2,cnt2); } if (cnt2-passed2 == iHandler->getNORB(irrep2)-1){ passed2 += iHandler->getNORB(irrep2); irrep2++; } } cout << " Orb " << cnt << " : "<< cnt-passed+1 << SymmInfo.getIrrepName(irrep) << " = " << SPenergy << endl; if ((cnt-passed == iHandler->getNORB(irrep)-1) && (irrepgetNORB(irrep); irrep++; } } cout << "HF energy = " << EnergyHF << endl; } void CheMPS2::CASSCF::PrintCoeff_C2(DMRG * theDMRG){ //cc-pVDZ full active space : Ag 7 / B1g 1 / B2g 3 / B3g 3 / Au 1 / B1u 7 / B2u 3 / B3u 3 ==> total 28 orbitals //cc-pCVDZ full active space : Ag 9 / B1g 1 / B2g 4 / B3g 4 / Au 1 / B1u 9 / B2u 4 / B3u 4 ==> total 36 orbitals int * coeff1 = new int[nOrbDMRG]; //1pi_x^2 int * coeff2 = new int[nOrbDMRG]; //1pi_y^2 //Fill coeff1 with | 1Ag^2 1B1u^2 2Ag^2 2B1u^2 1B3u^2 3Ag^2 > or | 1pi_x^2 > //Fill coeff2 with | 1Ag^2 1B1u^2 2Ag^2 2B1u^2 1B2u^2 3Ag^2 > or | 1pi_y^2 > for (int cnt=0; cntgetNOCC(irrep); orb<3; orb++){ //1-3 Ag : double coeff1[passed+orb] = coeff2[passed+orb] = 2; } } if (irrep==5){ //B1u for (int orb=iHandler->getNOCC(irrep); orb<2; orb++){ //1-2 B1u : double coeff1[passed+orb] = coeff2[passed+orb] = 2; } } if (irrep==7){ //B3u assert( iHandler->getNOCC(irrep)==0 ); //Condensed B3u orbitals not allowed. coeff1[passed+0] = 2; //1 B3u : double for | 1pi_x^2 > } if (irrep==6){ //B2u assert( iHandler->getNOCC(irrep)==0 ); //Condensed B2u orbitals not allowed. coeff2[passed+0] = 2; //1 B2u : double for | 1pi_y^2 > } passed += iHandler->getNDMRG(irrep); } int * coeff3 = new int[nOrbDMRG]; //1pi_x^1 1pi_x^{*1} int * coeff4 = new int[nOrbDMRG]; //1pi_y^1 1pi_y^{*1} //Fill coeff3 with | 1Ag^2 1B1u^2 2Ag^2 2B1u^2 1B3u^1 3Ag^2 1B2g^1 > or | 1pi_x^1 1pi_x^{*1} > //Fill coeff4 with | 1Ag^2 1B1u^2 2Ag^2 2B1u^2 1B2u^1 3Ag^2 1B3g^1 > or | 1pi_y^1 1pi_y^{*1} > for (int cnt=0; cntgetNOCC(irrep); orb<3; orb++){ //1-3 Ag : double coeff3[passed+orb] = coeff4[passed+orb] = 2; } } if (irrep==5){ //B1u for (int orb=iHandler->getNOCC(irrep); orb<2; orb++){ //1-2 B1u : double coeff3[passed+orb] = coeff4[passed+orb] = 2; } } if (irrep==7){ //B3u assert( iHandler->getNOCC(irrep)==0 ); //Condensed B3u orbitals not allowed. coeff3[passed+0] = 1; //1 B3u : single for | 1pi_x^1 1pi_x^{*1} > } if (irrep==6){ //B2u assert( iHandler->getNOCC(irrep)==0 ); //Condensed B2u orbitals not allowed. coeff4[passed+0] = 1; //1 B2u : single for | 1pi_y^1 1pi_y^{*1} > } if (irrep==2){ //B2g assert( iHandler->getNOCC(irrep)==0 ); //Condensed B2g orbitals not allowed. coeff3[passed+0] = 1; //1 B2g : single for | 1pi_x^1 1pi_x^{*1} > } if (irrep==3){ //B3g assert( iHandler->getNOCC(irrep)==0 ); //Condensed B3g orbitals not allowed. coeff4[passed+0] = 1; //1 B3g : single for | 1pi_y^1 1pi_y^{*1} > } passed += iHandler->getNDMRG(irrep); } double thecoeff1 = theDMRG->getSpecificCoefficient(coeff1); cout << "Coeff of 1pi_x^2 = " << thecoeff1 << endl; double thecoeff2 = theDMRG->getSpecificCoefficient(coeff2); cout << "Coeff of 1pi_y^2 = " << thecoeff2 << endl; double thecoeff3 = theDMRG->getSpecificCoefficient(coeff3); cout << "Coeff of 1pi_x^1 1pi_x^{*1} = " << thecoeff3 << endl; double thecoeff4 = theDMRG->getSpecificCoefficient(coeff4); cout << "Coeff of 1pi_y^1 1pi_y^{*1} = " << thecoeff4 << endl; delete [] coeff1; delete [] coeff2; delete [] coeff3; delete [] coeff4; } CheMPS2-1.6/CheMPS2/CASSCFnewtonraphson.cpp000066400000000000000000001115721256744172700202040ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include "CASSCF.h" #include "Lapack.h" #include "DMRGSCFVmatRotations.h" #include "EdmistonRuedenberg.h" #include "Davidson.h" using std::string; using std::ifstream; using std::cout; using std::endl; using std::max; double CheMPS2::CASSCF::doCASSCFnewtonraphson(const int Nelectrons, const int TwoS, const int Irrep, ConvergenceScheme * OptScheme, const int rootNum, DMRGSCFoptions * theDMRGSCFoptions){ //Convergence variables double gradNorm = 1.0; double updateNorm = 1.0; double * gradient = new double[unitary->getNumVariablesX()]; for (int cnt=0; cntgetNumVariablesX(); cnt++){ gradient[cnt] = 0.0; } double * theDIISparameterVector = NULL; int theDIISvectorParamSize = 0; double Energy = 1e8; //The CheMPS2::Problem for the inner DMRG calculation Hamiltonian * HamDMRG = new Hamiltonian(nOrbDMRG, SymmInfo.getGroupNumber(), iHandler->getIrrepOfEachDMRGorbital()); int N = Nelectrons; for (int irrep=0; irrepgetNOCC(irrep); } Problem * Prob = new Problem(HamDMRG, TwoS, N, Irrep); Prob->SetupReorderD2h(); //Doesn't matter if the group isn't D2h, Prob checks it. //Determine the maximum NORB(irrep); and the maximum NORB(irrep) which is OK according to the cutoff. int maxlinsize = 0; int maxlinsizeOK = 0; for (int irrep=0; irrepgetNORB(irrep); theDIISvectorParamSize += linsize_irrep*(linsize_irrep-1)/2; if (linsize_irrep > maxlinsize ) { maxlinsize = linsize_irrep; } if ((linsize_irrep > maxlinsizeOK) && (linsize_irrep <= CheMPS2::DMRGSCF_maxlinsizeCutoff)){ maxlinsizeOK = linsize_irrep; } } const bool doBlockWise = (maxlinsize <= CheMPS2::DMRGSCF_maxlinsizeCutoff) ? false : true; //Only if bigger, do we want to work blockwise //Determine the blocksize for the 2-body transformation int maxBlockSize = maxlinsize; if (doBlockWise){ int factor = (int) (ceil( (1.0 * maxlinsize) / CheMPS2::DMRGSCF_maxlinsizeCutoff ) + 0.01); maxBlockSize = max( (int) (ceil( (1.0 * maxlinsize) / factor ) + 0.01) , maxlinsizeOK ); //If a particular index can be rotated at once.... cout << "DMRGSCF info: The max. # orb per irrep = " << maxlinsize << endl; cout << " The size cutoff for 2-body transfo = " << CheMPS2::DMRGSCF_maxlinsizeCutoff << endl; cout << " The max. # orb per irrep <= cutoff = " << maxlinsizeOK << endl; cout << " The blocksize for piecewise tfo = " << maxBlockSize << endl; } //Allocate 2-body rotation memory: One array is approx (maxBlockSize/273.0)^4 * 42 GiB --> [maxBlockSize=100 --> 750 MB] const int maxBSpower4 = maxBlockSize * maxBlockSize * maxBlockSize * maxBlockSize; //Note that 273**4 overfloats the 32 bit integer!!! const int nOrbDMRGpower4 = nOrbDMRG*nOrbDMRG*nOrbDMRG*nOrbDMRG; const int sizeWorkmem = max( max( maxBSpower4 , maxlinsize*maxlinsize*4 ) , nOrbDMRGpower4 ); //For (2-body tfo, updateUnitary, calcNOON, rotate2DM, rotateUnitaryNOeigenvecs) double * mem1 = new double[sizeWorkmem]; double * mem2 = new double[sizeWorkmem]; double * mem3 = NULL; if (doBlockWise){ mem3 = new double[maxBSpower4]; } //The two-body rotator and Edmiston-Ruedenberg active space localizer DMRGSCFVmatRotations theRotator(HamOrig, iHandler); EdmistonRuedenberg * theLocalizer = NULL; if (theDMRGSCFoptions->getWhichActiveSpace()==2){ theLocalizer = new EdmistonRuedenberg(HamDMRG); } //Load unitary from disk if (theDMRGSCFoptions->getStoreUnitary()){ struct stat stFileInfo; int intStat = stat((theDMRGSCFoptions->getUnitaryStorageName()).c_str(),&stFileInfo); if (intStat==0){ unitary->loadU(theDMRGSCFoptions->getUnitaryStorageName()); } } //Load DIIS from disk if ((theDMRGSCFoptions->getDoDIIS()) && (theDMRGSCFoptions->getStoreDIIS())){ struct stat stFileInfo; int intStat = stat((theDMRGSCFoptions->getDIISStorageName()).c_str(),&stFileInfo); if (intStat==0){ if (theDIIS == NULL){ theDIIS = new DIIS(theDIISvectorParamSize, unitary->getNumVariablesX(), theDMRGSCFoptions->getNumDIISVecs()); theDIISparameterVector = new double[ theDIISvectorParamSize ]; } theDIIS->loadDIIS(theDMRGSCFoptions->getDIISStorageName()); } } int nIterations = 0; /******************************* *** Actual DMRGSCF loops *** *******************************/ while ((gradNorm > theDMRGSCFoptions->getGradientThreshold()) && (nIterations < theDMRGSCFoptions->getMaxIterations())){ nIterations++; //Update the unitary transformation if (unitary->getNumVariablesX() > 0){ unitary->updateUnitary(mem1, mem2, gradient, true, true); //multiply = compact = true if ((theDMRGSCFoptions->getDoDIIS()) && (updateNorm <= theDMRGSCFoptions->getDIISGradientBranch())){ if (theDMRGSCFoptions->getWhichActiveSpace()==1){ cout << "DMRGSCF::doCASSCFnewtonraphson : DIIS has started. Active space not rotated to NOs anymore!" << endl; } if (theDMRGSCFoptions->getWhichActiveSpace()==2){ cout << "DMRGSCF::doCASSCFnewtonraphson : DIIS has started. Active space not rotated to localized orbitals anymore!" << endl; } if (theDIIS == NULL){ theDIIS = new DIIS(theDIISvectorParamSize, unitary->getNumVariablesX(), theDMRGSCFoptions->getNumDIISVecs()); theDIISparameterVector = new double[ theDIISvectorParamSize ]; unitary->makeSureAllBlocksDetOne(mem1, mem2); } unitary->getLog(theDIISparameterVector, mem1, mem2); theDIIS->appendNew(gradient, theDIISparameterVector); theDIIS->calculateParam(theDIISparameterVector); unitary->updateUnitary(mem1, mem2, theDIISparameterVector, false, false); //multiply = compact = false } } if ((theDMRGSCFoptions->getStoreUnitary()) && (gradNorm!=1.0)){ unitary->saveU( theDMRGSCFoptions->getUnitaryStorageName() ); } if ((theDMRGSCFoptions->getStoreDIIS()) && (updateNorm!=1.0) && (theDIIS!=NULL)){ theDIIS->saveDIIS( theDMRGSCFoptions->getDIISStorageName() ); } //Fill HamDMRG buildQmatOCC(); buildTmatrix(); fillConstAndTmatDMRG(HamDMRG); if (doBlockWise){ theRotator.fillVmatDMRGBlockWise(HamDMRG, unitary, mem1, mem2, mem3, maxBlockSize); } else { theRotator.fillVmatDMRG(HamDMRG, unitary, mem1, mem2); } //Localize the active space and reorder the orbitals within each irrep based on the exchange matrix if ((theDMRGSCFoptions->getWhichActiveSpace()==2) && (theDIIS==NULL)){ //When the DIIS has started: stop theLocalizer->Optimize(mem1, mem2, theDMRGSCFoptions->getStartLocRandom()); //Default EDMISTONRUED_gradThreshold and EDMISTONRUED_maxIter used theLocalizer->FiedlerExchange(maxlinsize, mem1, mem2); fillLocalizedOrbitalRotations(theLocalizer->getUnitary(), iHandler, mem1); unitary->rotateActiveSpaceVectors(mem1, mem2); buildQmatOCC(); //With an updated unitary, the Qocc, Tmat, and HamDMRG objects need to be updated as well. buildTmatrix(); fillConstAndTmatDMRG(HamDMRG); if (doBlockWise){ theRotator.fillVmatDMRGBlockWise(HamDMRG, unitary, mem1, mem2, mem3, maxBlockSize); } else { theRotator.fillVmatDMRG(HamDMRG, unitary, mem1, mem2); } cout << "DMRGSCF::doCASSCFnewtonraphson : Rotated the active space to localized orbitals, sorted according to the exchange matrix." << endl; } //Do the DMRG sweeps, and calculate the 2DM for (int cnt = 0; cnt < nOrbDMRGpower4; cnt++){ DMRG2DM[ cnt ] = 0.0; } //Clear the 2-RDM (to allow for state-averaged calculations) DMRG * theDMRG = new DMRG(Prob, OptScheme); for (int state = 0; state < rootNum; state++){ if (state > 0){ theDMRG->newExcitation( fabs( Energy ) ); } Energy = theDMRG->Solve(); if ( theDMRGSCFoptions->getStateAveraging() ){ // When SA-DMRGSCF: 2DM += current 2DM theDMRG->calc2DMandCorrelations(); copy2DMover( theDMRG->get2DM(), nOrbDMRG, DMRG2DM ); } if ((state == 0) && (rootNum > 1)){ theDMRG->activateExcitations( rootNum-1 ); } } if ( !(theDMRGSCFoptions->getStateAveraging()) ){ // When SS-DMRGSCF: 2DM += last 2DM theDMRG->calc2DMandCorrelations(); copy2DMover( theDMRG->get2DM(), nOrbDMRG, DMRG2DM ); } if (theDMRGSCFoptions->getDumpCorrelations()){ theDMRG->getCorrelations()->Print(); } // Correlations have been calculated in the loop (SA) or outside of the loop (SS) if (CheMPS2::DMRG_storeMpsOnDisk){ theDMRG->deleteStoredMPS(); } if (CheMPS2::DMRG_storeRenormOptrOnDisk){ theDMRG->deleteStoredOperators(); } delete theDMRG; if ((theDMRGSCFoptions->getStateAveraging()) && (rootNum > 1)){ const double averagingfactor = 1.0 / rootNum; for (int cnt = 0; cnt < nOrbDMRGpower4; cnt++){ DMRG2DM[ cnt ] *= averagingfactor; } } setDMRG1DM(N, nOrbDMRG, DMRG1DM, DMRG2DM); //Possibly rotate the active space to the natural orbitals if ((theDMRGSCFoptions->getWhichActiveSpace()==1) && (theDIIS==NULL)){ //When the DIIS has started: stop calcNOON(iHandler, mem1, mem2, DMRG1DM); rotate2DMand1DM(N, nOrbDMRG, mem1, mem2, DMRG1DM, DMRG2DM); unitary->rotateActiveSpaceVectors(mem1, mem2); //This rotation can change the determinant from +1 to -1 !!!! buildQmatOCC(); //With an updated unitary, the Qocc and Tmat matrices need to be updated as well. buildTmatrix(); cout << "DMRGSCF::doCASSCFnewtonraphson : Rotated the active space to natural orbitals, sorted according to the NOON." << endl; } //Calculate the matrix elements needed to calculate the gradient and hessian buildQmatACT(); if (doBlockWise){ theRotator.fillRotatedTEIBlockWise(theRotatedTEI, unitary, mem1, mem2, mem3, maxBlockSize); } else { theRotator.fillRotatedTEI( theRotatedTEI, unitary, mem1, mem2 ); } buildFmat( theFmatrix, theTmatrix, theQmatOCC, theQmatACT, iHandler, theRotatedTEI, DMRG2DM, DMRG1DM); buildWtilde(wmattilde, theTmatrix, theQmatOCC, theQmatACT, iHandler, theRotatedTEI, DMRG2DM, DMRG1DM); //Calculate the gradient, hessian and corresponding update. On return, gradient contains the rescaled gradient == the update. augmentedHessianNR(theFmatrix, wmattilde, iHandler, unitary, gradient, &updateNorm, &gradNorm); } delete [] mem1; delete [] mem2; if (doBlockWise){ delete [] mem3; } delete Prob; delete HamDMRG; delete [] gradient; if (theDIISparameterVector!=NULL){ delete [] theDIISparameterVector; } if (theLocalizer!=NULL){ delete theLocalizer; } return Energy; } void CheMPS2::CASSCF::augmentedHessianNR(const DMRGSCFmatrix * localFmat, const DMRGSCFwtilde * localwtilde, const DMRGSCFindices * localIdx, const DMRGSCFunitary * localUmat, double * theupdate, double * updateNorm, double * gradNorm){ /* A good read to understand (1) how the augmented Hessian arises from a rational function optimization (2) where the parameter lambda in Eq. (22) of Yanai, IJQC 109, 2178-2190 (2009) comes from (3) why the smallest algebraic eigenvalue + corresponding eigenvector should be retained for minimizations Banerjee, Adams, Simons, Shepard, "Search for stationary points on surfaces", J. Phys. Chem. 1985, volume 89, pages 52-57, doi:10.1021/j100247a015 */ //Calculate the gradient const int x_linearlength = localUmat->getNumVariablesX(); gradNorm[0] = calcGradient(localFmat, localIdx, localUmat, theupdate); //Calculate the Hessian int dim = x_linearlength + 1; int size = dim * dim; double * hessian = new double[size]; calcHessian(localFmat, localwtilde, localIdx, localUmat, hessian, dim); //Augment the gradient into the Hessian matrix for (int cnt=0; cnt CheMPS2::HEFF_DAVIDSON_PRECOND_CUTOFF ) ? whichpointers[1][cnt] : CheMPS2::HEFF_DAVIDSON_PRECOND_CUTOFF; whichpointers[0][cnt] = - theupdate[cnt] / denom; } whichpointers[0][x_linearlength] = 1.0; instruction = deBoskabouter.FetchInstruction( whichpointers ); while ( instruction == 'B' ){ char notrans = 'N'; int one = 1; double alpha = 1.0; double beta = 0.0; dgemm_(¬rans, ¬rans, &dim, &one, &dim, &alpha, hessian, &dim, whichpointers[0], &dim, &beta, whichpointers[1], &dim); instruction = deBoskabouter.FetchInstruction( whichpointers ); } assert( instruction == 'C' ); double scalar = 1.0 / whichpointers[0][x_linearlength]; cout << "DMRGSCF::augmentedHessianNR : Augmented Hessian update found with " << deBoskabouter.GetNumMultiplications() << " Davidson iterations." << endl; if (CheMPS2::DMRGSCF_debugPrint){ cout << "DMRGSCF::augmentedHessianNR : Lowest eigenvalue = " << whichpointers[1][0] << endl; cout << "DMRGSCF::augmentedHessianNR : The last number of the eigenvector (which will be rescaled to one) = " << scalar << endl; } for (int cnt = 0; cnt < x_linearlength; cnt++){ theupdate[cnt] = scalar * whichpointers[0][cnt]; } delete [] whichpointers; } //Calculate the update norm updateNorm[0] = 0.0; for (int cnt = 0; cnt < x_linearlength; cnt++){ updateNorm[0] += theupdate[cnt] * theupdate[cnt]; } updateNorm[0] = sqrt(updateNorm[0]); cout << "DMRGSCF::augmentedHessianNR : Norm of the update = " << updateNorm[0] << endl; delete [] hessian; } double CheMPS2::CASSCF::calcGradient(const DMRGSCFmatrix * localFmat, const DMRGSCFindices * localIdx, const DMRGSCFunitary * localUmat, double * gradient){ for (int cnt=0; cntgetNumVariablesX(); cnt++){ const int index1 = localUmat->getFirstIndex(cnt); const int index2 = localUmat->getSecondIndex(cnt); // irrep1 == irrep2 due to construction DMRGSCFunitary const int irrep = localIdx->getOrbitalIrrep( index1 ); const int shift = localIdx->getOrigNOCCstart( irrep ); const int relIndex1 = index1 - shift; const int relIndex2 = index2 - shift; gradient[cnt] = 2 * ( localFmat->get( irrep, relIndex1, relIndex2 ) - localFmat->get( irrep, relIndex2, relIndex1 ) ); } double gradNorm = 0.0; for (int cnt=0; cntgetNumVariablesX(); cnt++){ gradNorm += gradient[cnt] * gradient[cnt]; } gradNorm = sqrt(gradNorm); cout << "DMRGSCF::calcGradient : Norm of the gradient = " << gradNorm << endl; return gradNorm; } void CheMPS2::CASSCF::calcHessian(const DMRGSCFmatrix * localFmat, const DMRGSCFwtilde * localwtilde, const DMRGSCFindices * localIdx, const DMRGSCFunitary * localUmat, double * hessian, const int rowjump){ const int lindim = ( localUmat->getNumVariablesX() * ( localUmat->getNumVariablesX() + 1 ))/2; #pragma omp parallel for schedule(static) for (int count=0; countgetFirstIndex(row); const int q_index = localUmat->getSecondIndex(row); // irrep_p == irrep_q due to construction DMRGSCFunitary const int irrep_pq = localIdx->getOrbitalIrrep( p_index ); const int r_index = localUmat->getFirstIndex(col); const int s_index = localUmat->getSecondIndex(col); // irrep_r == irrep_s due to construction DMRGSCFunitary const int irrep_rs = localIdx->getOrbitalIrrep( r_index ); const int rel_p_index = p_index - localIdx->getOrigNOCCstart( irrep_pq ); const int rel_q_index = q_index - localIdx->getOrigNOCCstart( irrep_pq ); const int rel_r_index = r_index - localIdx->getOrigNOCCstart( irrep_rs ); const int rel_s_index = s_index - localIdx->getOrigNOCCstart( irrep_rs ); hessian[row + rowjump * col] = Wmat(localFmat, localwtilde, localIdx, irrep_pq, irrep_rs, rel_p_index, rel_q_index, rel_r_index, rel_s_index) - Wmat(localFmat, localwtilde, localIdx, irrep_pq, irrep_rs, rel_q_index, rel_p_index, rel_r_index, rel_s_index) - Wmat(localFmat, localwtilde, localIdx, irrep_pq, irrep_rs, rel_p_index, rel_q_index, rel_s_index, rel_r_index) + Wmat(localFmat, localwtilde, localIdx, irrep_pq, irrep_rs, rel_q_index, rel_p_index, rel_s_index, rel_r_index); hessian[col + rowjump * row] = hessian[row + rowjump * col]; } } double CheMPS2::CASSCF::Wmat(const DMRGSCFmatrix * localFmat, const DMRGSCFwtilde * localwtilde, const DMRGSCFindices * localIdx, const int irrep_pq, const int irrep_rs, const int relindexP, const int relindexQ, const int relindexR, const int relindexS){ double value = 0.0; if ( ( irrep_pq == irrep_rs ) && ( relindexQ == relindexR ) ) { value = localFmat->get(irrep_pq, relindexP, relindexS) + localFmat->get(irrep_pq, relindexS, relindexP); } if (relindexP >= localIdx->getNOCC(irrep_pq) + localIdx->getNDMRG(irrep_pq)){ return value; } if (relindexR >= localIdx->getNOCC(irrep_rs) + localIdx->getNDMRG(irrep_rs)){ return value; } //index1 and index3 are now certainly not virtual! value += localwtilde->get( irrep_pq, irrep_rs, relindexP, relindexQ, relindexR, relindexS ); return value; } void CheMPS2::CASSCF::buildWtilde(DMRGSCFwtilde * localwtilde, const DMRGSCFmatrix * localTmat, const DMRGSCFmatrix * localJKocc, const DMRGSCFmatrix * localJKact, const DMRGSCFindices * localIdx, const DMRGSCFintegrals * theInts, double * local2DM, double * local1DM){ localwtilde->clear(); const int numIrreps = localIdx->getNirreps(); const int totOrbDMRG = localIdx->getDMRGcumulative( numIrreps ); for (int irrep_pq = 0; irrep_pq < numIrreps; irrep_pq++){ const int NumOCCpq = localIdx->getNOCC( irrep_pq ); const int NumDMRGpq = localIdx->getNDMRG( irrep_pq ); const int NumORBpq = localIdx->getNORB( irrep_pq ); const int NumCOREpq = NumOCCpq + NumDMRGpq; //If irrep_pq == irrep_rs and P == R occupied --> QS only active or virtual #pragma omp parallel for schedule(static) for (int relindexP = 0; relindexP < NumOCCpq; relindexP++){ double * subblock = localwtilde->getBlock( irrep_pq, irrep_pq, relindexP, relindexP); for (int relindexS = NumOCCpq; relindexS < NumORBpq; relindexS++){ for (int relindexQ = NumOCCpq; relindexQ < NumORBpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 4 * ( localTmat->get( irrep_pq, relindexQ, relindexS) + localJKocc->get(irrep_pq, relindexQ, relindexS) + localJKact->get(irrep_pq, relindexQ, relindexS) ); } } } //If irrep_pq == irrep_rs and P,R active --> QS only occupied or virtual #pragma omp parallel for schedule(static) for (int combined = 0; combined < NumDMRGpq*NumDMRGpq; combined++){ const int relindexP = NumOCCpq + ( combined % NumDMRGpq ); const int relindexR = NumOCCpq + ( combined / NumDMRGpq ); double * subblock = localwtilde->getBlock( irrep_pq, irrep_pq, relindexP, relindexR ); const int DMRGindexP = relindexP - NumOCCpq + localIdx->getDMRGcumulative( irrep_pq ); const int DMRGindexR = relindexR - NumOCCpq + localIdx->getDMRGcumulative( irrep_pq ); const double OneDMvalue = local1DM[ DMRGindexP + totOrbDMRG * DMRGindexR ]; for (int relindexS = 0; relindexS < NumOCCpq; relindexS++){ for (int relindexQ = 0; relindexQ < NumOCCpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( localTmat->get( irrep_pq, relindexQ, relindexS) + localJKocc->get(irrep_pq, relindexQ, relindexS) ); } for (int relindexQ = NumCOREpq; relindexQ < NumORBpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( localTmat->get( irrep_pq, relindexQ, relindexS) + localJKocc->get(irrep_pq, relindexQ, relindexS) ); } } for (int relindexS = NumCOREpq; relindexS < NumORBpq; relindexS++){ for (int relindexQ = 0; relindexQ < NumOCCpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( localTmat->get( irrep_pq, relindexQ, relindexS) + localJKocc->get(irrep_pq, relindexQ, relindexS) ); } for (int relindexQ = NumCOREpq; relindexQ < NumORBpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( localTmat->get( irrep_pq, relindexQ, relindexS) + localJKocc->get(irrep_pq, relindexQ, relindexS) ); } } } for (int irrep_rs = 0; irrep_rs < numIrreps; irrep_rs++){ const int NumOCCrs = localIdx->getNOCC( irrep_rs ); const int NumDMRGrs = localIdx->getNDMRG( irrep_rs ); const int NumORBrs = localIdx->getNORB( irrep_rs ); const int NumCORErs = NumOCCrs + NumDMRGrs; const int productirrep = Irreps::directProd( irrep_pq, irrep_rs ); // P and R occupied --> QS only active or virtual #pragma omp parallel for schedule(static) for (int combined = 0; combined < NumOCCpq*NumOCCrs; combined++){ const int relindexP = combined % NumOCCpq; const int relindexR = combined / NumOCCpq; double * subblock = localwtilde->getBlock( irrep_pq, irrep_rs, relindexP, relindexR); for (int relindexS = NumOCCrs; relindexS < NumORBrs; relindexS++){ for (int relindexQ = NumOCCpq; relindexQ < NumORBpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 4 * ( 4 * theInts->FourIndexAPI(irrep_pq, irrep_rs, irrep_pq, irrep_rs, relindexQ, relindexS, relindexP, relindexR) - theInts->FourIndexAPI(irrep_pq, irrep_pq, irrep_rs, irrep_rs, relindexQ, relindexP, relindexS, relindexR) - theInts->FourIndexAPI(irrep_pq, irrep_rs, irrep_rs, irrep_pq, relindexQ, relindexS, relindexR, relindexP) ); } } } // End combined P and R occupied // P and R active --> QS only occupied or virtual #pragma omp parallel for schedule(static) for (int combined = 0; combined < NumDMRGpq*NumDMRGrs; combined++){ const int relindexP = NumOCCpq + ( combined % NumDMRGpq ); const int relindexR = NumOCCrs + ( combined / NumDMRGpq ); double * subblock = localwtilde->getBlock( irrep_pq, irrep_rs, relindexP, relindexR ); const int DMRGindexP = relindexP - NumOCCpq + localIdx->getDMRGcumulative( irrep_pq ); const int DMRGindexR = relindexR - NumOCCrs + localIdx->getDMRGcumulative( irrep_rs ); for (int irrep_alpha = 0; irrep_alpha < numIrreps; irrep_alpha++){ const int irrep_beta = Irreps::directProd( irrep_alpha, productirrep ); const int NumDMRGalpha = localIdx->getNDMRG( irrep_alpha ); const int NumDMRGbeta = localIdx->getNDMRG( irrep_beta ); for (int alpha = 0; alpha < NumDMRGalpha; alpha++){ const int DMRGalpha = localIdx->getDMRGcumulative( irrep_alpha ) + alpha; const int relalpha = localIdx->getNOCC( irrep_alpha ) + alpha; for (int beta = 0; beta < NumDMRGbeta; beta++){ const int DMRGbeta = localIdx->getDMRGcumulative( irrep_beta ) + beta; const int relbeta = localIdx->getNOCC( irrep_beta ) + beta; const double TwoDMvalue1 = local2DM[ DMRGindexR + totOrbDMRG * ( DMRGalpha + totOrbDMRG * ( DMRGindexP + totOrbDMRG * DMRGbeta ) ) ]; const double TwoDMvalue23 = local2DM[ DMRGindexR + totOrbDMRG * ( DMRGalpha + totOrbDMRG * ( DMRGbeta + totOrbDMRG * DMRGindexP ) ) ] + local2DM[ DMRGindexR + totOrbDMRG * ( DMRGindexP + totOrbDMRG * ( DMRGbeta + totOrbDMRG * DMRGalpha ) ) ]; for (int relindexS = 0; relindexS < NumOCCrs; relindexS++){ for (int relindexQ = 0; relindexQ < NumOCCpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * ( TwoDMvalue1 * theInts->FourIndexAPI( irrep_pq, irrep_alpha, irrep_rs, irrep_beta, relindexQ, relalpha, relindexS, relbeta) + TwoDMvalue23 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_alpha, irrep_beta, relindexQ, relindexS, relalpha, relbeta) ); } for (int relindexQ = NumCOREpq; relindexQ < NumORBpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * ( TwoDMvalue1 * theInts->FourIndexAPI( irrep_pq, irrep_alpha, irrep_rs, irrep_beta, relindexQ, relalpha, relindexS, relbeta) + TwoDMvalue23 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_alpha, irrep_beta, relindexQ, relindexS, relalpha, relbeta) ); } } for (int relindexS = NumCORErs; relindexS < NumORBrs; relindexS++){ for (int relindexQ = 0; relindexQ < NumOCCpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * ( TwoDMvalue1 * theInts->FourIndexAPI( irrep_pq, irrep_alpha, irrep_rs, irrep_beta, relindexQ, relalpha, relindexS, relbeta) + TwoDMvalue23 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_alpha, irrep_beta, relindexQ, relindexS, relalpha, relbeta) ); } for (int relindexQ = NumCOREpq; relindexQ < NumORBpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * ( TwoDMvalue1 * theInts->FourIndexAPI( irrep_pq, irrep_alpha, irrep_rs, irrep_beta, relindexQ, relalpha, relindexS, relbeta) + TwoDMvalue23 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_alpha, irrep_beta, relindexQ, relindexS, relalpha, relbeta) ); } } } } } } // End combined P and R active // P active and R occupied --> Q occupied or virtual // S active or virtual #pragma omp parallel for schedule(static) for (int combined = 0; combined < NumDMRGpq*NumOCCrs; combined++){ const int relindexP = NumOCCpq + ( combined % NumDMRGpq ); const int relindexR = combined / NumDMRGpq; double * subblock = localwtilde->getBlock( irrep_pq, irrep_rs, relindexP, relindexR ); const int DMRGindexP = relindexP - NumOCCpq + localIdx->getDMRGcumulative( irrep_pq ); for (int alpha = 0; alpha < NumDMRGpq; alpha++){ const int DMRGalpha = localIdx->getDMRGcumulative( irrep_pq ) + alpha; const int relalpha = localIdx->getNOCC( irrep_pq ) + alpha; const double OneDMvalue = local1DM[ DMRGalpha + totOrbDMRG * DMRGindexP ]; for (int relindexS = NumOCCrs; relindexS < NumORBrs; relindexS++){ for (int relindexQ = 0; relindexQ < NumOCCpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( 4 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_pq, irrep_rs, relindexQ, relindexS, relalpha, relindexR) - theInts->FourIndexAPI( irrep_pq, irrep_pq, irrep_rs, irrep_rs, relindexQ, relalpha, relindexS, relindexR) - theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_rs, irrep_pq, relindexQ, relindexS, relindexR, relalpha) ); } for (int relindexQ = NumCOREpq; relindexQ < NumORBpq; relindexQ++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( 4 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_pq, irrep_rs, relindexQ, relindexS, relalpha, relindexR) - theInts->FourIndexAPI( irrep_pq, irrep_pq, irrep_rs, irrep_rs, relindexQ, relalpha, relindexS, relindexR) - theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_rs, irrep_pq, relindexQ, relindexS, relindexR, relalpha) ); } } } } // End combined P active and R occupied // P occupied and R active --> Q active or virtual // S occupied or virtual #pragma omp parallel for schedule(static) for (int combined = 0; combined < NumOCCpq*NumDMRGrs; combined++){ const int relindexP = combined % NumOCCpq; const int relindexR = NumOCCrs + ( combined / NumOCCpq ); double * subblock = localwtilde->getBlock( irrep_pq, irrep_rs, relindexP, relindexR ); const int DMRGindexR = relindexR - NumOCCrs + localIdx->getDMRGcumulative( irrep_rs ); for (int beta = 0; beta < NumDMRGrs; beta++){ const int DMRGbeta = localIdx->getDMRGcumulative( irrep_rs ) + beta; const int relbeta = localIdx->getNOCC( irrep_rs ) + beta; const double OneDMvalue = local1DM[ DMRGindexR + totOrbDMRG * DMRGbeta ]; for (int relindexQ = NumOCCpq; relindexQ < NumORBpq; relindexQ++){ for (int relindexS = 0; relindexS < NumOCCrs; relindexS++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( 4 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_pq, irrep_rs, relindexQ, relindexS, relindexP, relbeta) - theInts->FourIndexAPI( irrep_pq, irrep_pq, irrep_rs, irrep_rs, relindexQ, relindexP, relindexS, relbeta) - theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_rs, irrep_pq, relindexQ, relindexS, relbeta, relindexP) ); } for (int relindexS = NumCORErs; relindexS < NumORBrs; relindexS++){ subblock[ relindexQ + NumORBpq * relindexS ] += 2 * OneDMvalue * ( 4 * theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_pq, irrep_rs, relindexQ, relindexS, relindexP, relbeta) - theInts->FourIndexAPI( irrep_pq, irrep_pq, irrep_rs, irrep_rs, relindexQ, relindexP, relindexS, relbeta) - theInts->FourIndexAPI( irrep_pq, irrep_rs, irrep_rs, irrep_pq, relindexQ, relindexS, relbeta, relindexP) ); } } } } // End combined P occupied and R active } } } void CheMPS2::CASSCF::buildFmat(DMRGSCFmatrix * localFmat, const DMRGSCFmatrix * localTmat, const DMRGSCFmatrix * localJKocc, const DMRGSCFmatrix * localJKact, const DMRGSCFindices * localIdx, const DMRGSCFintegrals * theInts, double * local2DM, double * local1DM){ localFmat->clear(); const int numIrreps = localIdx->getNirreps(); const int totOrbDMRG = localIdx->getDMRGcumulative( numIrreps ); for (int irrep_pq = 0; irrep_pq < numIrreps; irrep_pq++){ const int NumORB = localIdx->getNORB( irrep_pq ); const int NumOCC = localIdx->getNOCC( irrep_pq ); const int NumDMRG = localIdx->getNDMRG( irrep_pq ); const int NumOCCDMRG = NumOCC + NumDMRG; #pragma omp parallel for schedule(static) for (int p = 0; p < NumOCC; p++){ for (int q = 0; q < NumORB; q++){ localFmat->set( irrep_pq, p, q, 2 * ( localTmat->get( irrep_pq, q, p ) + localJKocc->get( irrep_pq, q, p ) + localJKact->get( irrep_pq, q, p ) ) ); } } #pragma omp parallel for schedule(static) for (int p = NumOCC; p < NumOCCDMRG; p++){ const int DMRGindex_p = p - NumOCC + localIdx->getDMRGcumulative( irrep_pq ); //One-body terms --> matrix multiplication? for (int r = NumOCC; r < NumOCCDMRG; r++){ const double OneDMvalue = local1DM[ DMRGindex_p + totOrbDMRG * ( DMRGindex_p + r - p ) ]; for (int q = 0; q < NumORB; q++){ localFmat->getBlock(irrep_pq)[ p + NumORB * q ] += OneDMvalue * ( localTmat->get( irrep_pq, q, r ) + localJKocc->get( irrep_pq, q, r) ); } } //Two-body terms --> matrix multiplication possible? for (int irrep_r = 0; irrep_r < numIrreps; irrep_r++){ const int irrep_product = Irreps::directProd(irrep_pq, irrep_r); for (int irrep_s = 0; irrep_s < numIrreps; irrep_s++){ const int irrep_t = Irreps::directProd(irrep_product, irrep_s); for (int r = localIdx->getNOCC(irrep_r); r < localIdx->getNOCC(irrep_r) + localIdx->getNDMRG(irrep_r); r++){ const int DMRGindex_r = r - localIdx->getNOCC( irrep_r ) + localIdx->getDMRGcumulative( irrep_r ); for (int s = localIdx->getNOCC(irrep_s); s < localIdx->getNOCC(irrep_s) + localIdx->getNDMRG(irrep_s); s++){ const int DMRGindex_s = s - localIdx->getNOCC( irrep_s ) + localIdx->getDMRGcumulative( irrep_s ); for (int t = localIdx->getNOCC(irrep_t); t < localIdx->getNOCC(irrep_t) + localIdx->getNDMRG(irrep_t); t++){ const int DMRGindex_t = t - localIdx->getNOCC( irrep_t ) + localIdx->getDMRGcumulative( irrep_t ); const double TwoDMvalue = local2DM[ DMRGindex_p + totOrbDMRG * ( DMRGindex_r + totOrbDMRG * ( DMRGindex_s + totOrbDMRG * DMRGindex_t ) ) ]; for (int q = 0; q < NumORB; q++){ localFmat->getBlock(irrep_pq)[ p + NumORB * q ] += TwoDMvalue * theInts->FourIndexAPI(irrep_pq, irrep_r, irrep_s, irrep_t, q, r, s, t); } } } } } } } } } CheMPS2-1.6/CheMPS2/CMakeLists.txt000066400000000000000000000053341256744172700164460ustar00rootroot00000000000000include_directories (${CheMPS2_SOURCE_DIR}/CheMPS2/include/chemps2/ ${HDF5_INCLUDE_DIRS}) set (CHEMPS2LIB_SOURCE_FILES "CASSCF.cpp" "CASSCFdebug.cpp" "CASSCFnewtonraphson.cpp" "ConvergenceScheme.cpp" "Correlations.cpp" "Davidson.cpp" "DIIS.cpp" "DMRG.cpp" "DMRGmpsio.cpp" "DMRGoperators.cpp" "DMRGSCFindices.cpp" "DMRGSCFintegrals.cpp" "DMRGSCFmatrix.cpp" "DMRGSCFoptions.cpp" "DMRGSCFunitary.cpp" "DMRGSCFVmatRotations.cpp" "DMRGSCFwtilde.cpp" "DMRGtechnics.cpp" "EdmistonRuedenberg.cpp" "FCI.cpp" "FourIndex.cpp" "Hamiltonian.cpp" "Heff.cpp" "HeffDiagonal.cpp" "HeffDiagrams1.cpp" "HeffDiagrams2.cpp" "HeffDiagrams3.cpp" "HeffDiagrams4.cpp" "HeffDiagrams5.cpp" "Initialize.cpp" "Irreps.cpp" "PrintLicense.cpp" "Problem.cpp" "Sobject.cpp" "SyBookkeeper.cpp" "TensorA.cpp" "TensorB.cpp" "TensorC.cpp" "TensorD.cpp" "TensorDiag.cpp" "TensorF0Cbase.cpp" "TensorF0.cpp" "TensorF1.cpp" "TensorF1Dbase.cpp" "TensorGYZ.cpp" "TensorK.cpp" "TensorL.cpp" "TensorM.cpp" "TensorO.cpp" "TensorQ.cpp" "TensorS0Abase.cpp" "TensorS0.cpp" "TensorS1Bbase.cpp" "TensorS1.cpp" "TensorSwap.cpp" "TensorT.cpp" "TensorX.cpp" "TwoDM.cpp" "TwoDMstorage.cpp" "TwoIndex.cpp") add_library (chemps2-base OBJECT ${CHEMPS2LIB_SOURCE_FILES}) if (NOT STATIC_ONLY) set_target_properties (chemps2-base PROPERTIES POSITION_INDEPENDENT_CODE 1) add_library (chemps2-shared SHARED $) target_link_libraries (chemps2-shared ${LAPACK_LIBRARIES} ${HDF5_LIBRARIES} ${GSL_LIBRARIES}) set_target_properties (chemps2-shared PROPERTIES SOVERSION ${CheMPS2_LIB_SOVERSION} CLEAN_DIRECT_OUTPUT 1 OUTPUT_NAME "chemps2") endif (NOT STATIC_ONLY) add_library (chemps2-static STATIC $) target_link_libraries (chemps2-static ${LAPACK_LIBRARIES} ${HDF5_LIBRARIES} ${GSL_LIBRARIES}) set_target_properties (chemps2-static PROPERTIES CLEAN_DIRECT_OUTPUT 1 OUTPUT_NAME "chemps2") if (NOT STATIC_ONLY) install (TARGETS chemps2-shared DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) endif (NOT STATIC_ONLY) install (TARGETS chemps2-static DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) install (DIRECTORY include/chemps2/ DESTINATION include/chemps2 FILES_MATCHING PATTERN "*.h") link_directories (${CMAKE_BINARY_DIR}/CheMPS2) add_executable (chemps2bin executable.cpp) if (STATIC_ONLY) add_dependencies (chemps2bin chemps2-static) target_link_libraries (chemps2bin chemps2 ${LAPACK_LIBRARIES} ${HDF5_LIBRARIES} ${GSL_LIBRARIES}) else (STATIC_ONLY) add_dependencies (chemps2bin chemps2-shared) target_link_libraries (chemps2bin chemps2) endif (STATIC_ONLY) set_target_properties (chemps2bin PROPERTIES OUTPUT_NAME "chemps2") install (TARGETS chemps2bin DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}) CheMPS2-1.6/CheMPS2/CheMPS2logo.pdf000066400000000000000000000100541256744172700164160ustar00rootroot00000000000000%PDF-1.5 %µí®û 3 0 obj << /Length 4 0 R /Filter /FlateDecode >> stream xœ+ä*ä2T0B©k ghjnj®œË¥Ÿh ^¬ _aªà’Ï„Êè ` endstream endobj 4 0 obj 46 endobj 2 0 obj << /ExtGState << /a0 << /CA 1 /ca 1 >> >> /XObject << /x5 5 0 R >> >> endobj 6 0 obj << /Type /Page /Parent 1 0 R /MediaBox [ 0 0 385.595581 64.84243 ] /Contents 3 0 R /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Resources 2 0 R >> endobj 5 0 obj << /Length 8 0 R /Filter /FlateDecode /Type /XObject /Subtype /Form /BBox [ 0 0 386 65 ] /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Resources 7 0 R >> stream xœuYË®%5 Üç+úhâ¼óHH,€%b]šY ,ø}ªl'Ý÷ÜAÝSN:qìò#™/!üï§ïŽo‹Çÿ„|¶‡ZÏØÇÑòÓñùyv™GKçãøt¤Sb=r:s€’9{k€øXz:ðìÀ??B‡[™:üÏv¥ãŒqp»vÖX®ï÷"Îð•5Ú)ãHýL©c‰ÔÎ<+5N}é`vùû#WlP2÷½bv†³v òè Û8¤bÖÊ9Z?®…ƒd|=u1šA`œ”¡ö, búÀ¯¶Ç?APž„<ê™ÓåjÆrŽ`‘ZõsÃ8^œúmƒéû@~$ÐÅ0¦óÄ3¯ Ø­Gx£©ÀÄY°ÑÀRñĉ¹|…ºyœ† —3ߟœ2 ø|`¹*Äs¤ÅÒYG[ûÃÓpHXê„#„œ¨½Ü0«Ÿ®[”Ÿ (W儲!79“ˆC®^ô0†‰hÁÚϨK*mÁKOÚ*,¼& 37ï½oˆ£æn¦vA<Ëäzð¸À£8Q.T¦Ÿ97R‹\¹^iôéx ?áp Å bÏA\¤Їgƒ©o0±Ðú©†æ- !µ’TÂ\0õ$7  9¯e.¸``s'ãX¤/ŒÓP'(°~u×ë9=¬Ï 18‚>kä…á‚Ø•,]êÅ J\[PÁýeUb.TܸàqE”*L*ÀQÄ|ê("ç,Ïôl;NÕ²X†(Τ +ÂT3­1D28ëY¨Âý¾ÅE<Î&4@)Øb"ê:ÓÏ,¤0Ã4M]ˆÁ…ˆë R# ¶L‚ÑÌH øs£Ò¶ s;Ka|÷|fì‡p­ÒH޽ Ž‹sÄfAÐ:¼d‡”ÇÂ@$K†j ÔBC5¼®Å`väúhPßX¡a ÅÐÔ—P@°Î\¹‚3Ï…BŠÐÔæÃnô§«höÆž¥Ìc¹bÀZ#;œñJ#áܦ†ÁÂHÅí˜Q}²72 ‹âo0h¿ÉX+21a"‰Í#¡Pƒ9RÈ„Ö õlˆ¬às-Ó¬aGÆÌ…†=æˆÌÔ€ùÆêqû$e/]¸hìÃìj¬®öEjø³e!D“ n÷vrUÉìLÕ]dJAŽqŒÌ– c˦’,µDf0ß]ÇŸòØ[Ó3+¼V¤£E› D /’‹m2Â:rMA“ é$[XÄø‘×÷thHʉ]ÿ (žÔuŸÚxâ‚ÙmwŽ\2Äž 1.“¢ {HDÑÉ݉·VZ¬äI´¢Ú(ô¢†Nö°1Ò•«í4°ŸÂ½,’DñèðRB1<ÆY[ˤMºÒÎ×âô¤.ð4'±k¨: §7KQHµzº@¢h³ÕÙJl¸µqcE|N${QÔd»›$¡H[ó1)Q5XÁHa~¨‹ Ûg+= MŠyaO@Ùè,¿äž#0¢eóƒaÛŒ‡Íì¾ *=5«.¾}E=8kC w×F} &e,ÚXVvXú£'±ÆÖç‡W Œ7ÂÌå¶ý>Q§÷ @#4#9kÃÃF:± 2Ä¢ 9 «Ú!,çi&i¦j ë2»B0È£B¿u ÃK™¦½Ç¹ª!d7x¦Þ› JQ©Jß1YŠ™‡&‹œv=Hì§Ìì5§û‚½c½ˆ¶ð8 C–µ¨­BŒþUƒÞk2áÂ@¯ø¡”që½û`ð`Ï_<4{QŠÁ¸¼ˆ{@3p«ô}aM(Ç\WÄ®U°hŸféâ†'q}ešþ^X o³ã Ùq_·u@ÇATv'¼å1Á&ÓÆ1çg-D.àöäÃz ¿æd}6áU÷ReˆÅp¸òÌ–[9¤œ¬i9ÚâîùYù—õôe Ÿb”4àË“6C)7}‘óö8¦¼ê{iæêœ‡È)Ú9úv|²2[(bcû]̬ET˜,lñv‡U×~Í •‡fÿÏ|ííü?†i^­…÷¾3á ~»¼ÊÝ…¹y‡u˜Tù³¸€‹v½HŽM{|ƒøŒÑxÝÑæ&ùÓ“ /ìÈ¢ìœß2µR$äV-¾N°Þtè7a|Ðãð¹…]1Éù~ÿ)Goh·ì-ú¦¤_ƒ buFkpŒùÆî5Ž"ÈÌ{âÁ©hʸ€ˆîN¨_2ç õ¡Ê!³Ö‡˜CârÈå¾°¼ æ%ØñßE{¥GŠpÉN"þÉ+Þ™Ë7}ä‡W5 z<ÙéŠ9Þ‹Žwí¼Ã[KŸ>Hî“ñy¢Ì‚‡^/J@­™´ ÁÉŒpè5³z+’fÕË–l¶nƹ ,NΪç†E½íó“FäM“„ïf×nêïëÓ{~f 4õž¡àÂ"SJ0ANvá°Léid-ØôA-óÅ:êóR’© ‘k|b(öérÞ <ãrF‚xG¶áô¦g ª¶tÙ^6³vÊ\ˆ…ÿÌ LÆE˜[W>ZðJu ¾ú‚YDóvpŒù’ôÉqO(ÚQàs&–ŒÞ¤h~éöB­ÑXÛÁKhÍAŸZì Êz0_‚hOô7d¤roV©>M›©Ožeê‹Â²M~ÀûsúÐ<¶ÕqLÈàp{i'í±×êɯÐŽOo—Jô}WH‹Ìg3&ÑvmÃbO{[ãô-ÚZæ¬÷•qçêM7xÓ›ÅÿfÁª”°›d:•.H|³±­EcÍ ïëØ‹V X³µ±äL‡ý¼Ž^J.„jÔùôÅ[dÔ d]0xA½¶„M€º˾呡,™ÃÿÑ&M{?sA`ÌñaÄoîÚ3ßu ¬n²·——•_‚'ÍÛ¯9ç- ÜéÃîN˜ôÆNd VÞËÙ²×AX¹S%¿Wþ[›ÜùðöoáÇðº}ß endstream endobj 8 0 obj 2785 endobj 7 0 obj << /ExtGState << /a0 << /CA 1 /ca 1 >> >> >> endobj 1 0 obj << /Type /Pages /Kids [ 6 0 R ] /Count 1 >> endobj 9 0 obj << /Creator (cairo 1.10.2 (http://cairographics.org)) /Producer (cairo 1.10.2 (http://cairographics.org)) >> endobj 10 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 11 0000000000 65535 f 0000003590 00000 n 0000000159 00000 n 0000000015 00000 n 0000000138 00000 n 0000000471 00000 n 0000000259 00000 n 0000003518 00000 n 0000003495 00000 n 0000003655 00000 n 0000003782 00000 n trailer << /Size 11 /Root 10 0 R /Info 9 0 R >> startxref 3835 %%EOF CheMPS2-1.6/CheMPS2/CheMPS2logo.png000066400000000000000000000074701256744172700164410ustar00rootroot00000000000000‰PNG  IHDRÊ"rFGsBIT|dˆ pHYs-ã-ã‘RHtEXtSoftwarewww.inkscape.org›î<µIDATxœí{ôUÇ?ß>ˆP(””ò¨˜ZI‚–‰ðQf©«·aZVføH«ÄØC3Ì ‰Y–š¦"hˆšHa–ŠJ±L4Ÿ¿ä¥ìþØg~÷p™;÷Þ¹¿Ÿ²ø®5kfÎÙsξ3³ÏÙ¯3WfF-Hš|9*²Œ}^]²_ œbfSkvÜIô@QÑ+föRWñS I}¶¨h¹™½ê¼£ê’ef¶¬|l•Õ¤nÀ–Uõ/™Ù+%ô» ðöªâçÍlM³m†™ånÀ`à5`5ðtØþ¶g¢íÙ°=¶çÃöB´½ꎮÕognÀJ\“íâ®æ©Š¿ö*þ¦Fu½«ê ø^‹øÈìØ>¥~\IýÒöÐÎ|¥ ñÑìë¤Y Œ’½¾föHgô œ ÜŽ—½HÒÀQÀùf¶¼L†$ g5%ƒ|ð—püï2ùˆðÑèø'4Çÿ ÇmXÒ¶À®ÀnÀ»ðAö`þ»’¾{×g9·Ï^À'ÀN@àaà!`¦™½Ðæ Š¤ñÀ^À à(IG–ÀßZàL3ûcJç_À§Ùn¡l{3[RB¿µð°™Í©ç‚ $ÞÜÜ]3’>Ülifs£ò2.y Iý€Ã]€mm€ÍªÈÖàšÂSøË>ÓÌþ‘TÆíKÊRM˜Ù=Y|¤ðu0 Ø=ƒä¸ªþ“@ß»hÛ9}n|8cìögIš\dfk󦻸šT=啱MËès`ð³@·´“T›•À¸nbô›¾^"?Ûâ/뢔º›IW½Èhk0 WŸ †„ç—qµ..«Þ{¥´{éªW!•„Ï–‹oû‡g7áó±GÕïmHõ6nˆÚœì ŒÅg”¤þ´Zª× pðݺz±¸7­ÂÌV÷IJ¦Ù;Jì·x_t<øQ³ JÚ W-¶ÂÕŽFÛÙ8 ü,NÆGS€÷™Ù¿$µ[[ûŸ>˜Ð³$}ÉÌ®j”Ÿ*ÞvÇgËkãÌ쵨úf+àV\8˜Œ÷¦N|Ž'gUõ›¤‹€Ÿ_&Jº5UP$mœˆ4G›Ù¢¬ÃÃþÍ&(M!¼°WEíþ½Ávv®Àm•=,òIÚ>®À3[KÅ)³¸@ÒüE~;> Ït‹™=ßOQÿƒq5õ`lÕKÚ3{ZÒÅTŸg›é7ÂvÀ2`B¢Î¥ô½ZÒ7ðAæÀ˜¶4Bàà-À…-$ÁÍø‘pú†I=€@rHªvÖ‹ó©ŒvЀ HêÌúã£uµ uû°_$ÁÙ“Ê Ú w*4‹S^À­¶ëøÉ°¿øU }‹;‰²œ˜»½çÎ × Š¤½Oá£Ë%1W>ˆ™Ï˜ÙC]ÐQ솾—Ee{4Ú˜¤¯âúqÿhdF9è Œ1³´Qx»°¸VCæÇßDE{6ÀO$õÄmp¼ã¶×P3{±™¾˜cEAòÄã:pA Sÿ´pú]3û_ÌÕ‰7‹}2סï®*«’öÃÝð× Å+¨Ã½a°“™]›ÒÏ[¨'k JÀ Ññ¿à'Æ0\SØ7h™0³ÌìOy4-Fr¯«žQÆàÞˆ¿—v*K¼Ye4nÞ¼ʆÕÛˆ¤]€™À߀#BÕ?óT£,˜Ù%f–%`‹ JÏè¸Y÷÷Âèø½À9’ŠÄòº ƒÂ~~‡ ÿô™átl#©YO͇Ãé’v•tФßJš%é4Iýëh¯MÒa’¦JºCÒ=’¦5kKb8p[гUC¬\´-ñ»÷ê¬v Õ ò5Ç*þ‘Iµ.urž™55x™Ù3ÀuQÑ·€{%½¿™v[0Û} œÎê$I«$5Õ¯0s^ƒð‡™Y’ò10"ûOüe!”¹5†â6Åh3»¯ ÂsAÅæÙï—46ÜŸ.CÐ&‡ÓšÙ’dF¹gv MxnJ@"(/â/Ъªúîa¿3ÉtÜy`Šßþ[ßÚƒAµ…GÄ)û¸þ—¸3ÆÌfGÕ± <Ý9ýn $*εx”t > Œ6³\úF`f3÷àÐÄÓט <$ixÖµ€ÓqCþy‚9Ò&i4®’<‡äçHêžÙD‹òo÷ãéf–6¢&ÑâG3ÚèÌÀ…à×f––Üx ®v<Ø «CðéxNRŒçÅátd oÎñ$ʉf6£ª.¶¿žj¿,¼O‚G‰¤mð™{‡ÏÆIŒ£'å AÒç©ÈÃŒ8(ÙFŵ .I¯'IzWç±TÔ®ß[ú¢©øL±œl×fâ1{å={\. çW4’Ù膫2›Q?.Ôß’ÓÆƒæ2|tî´è»Pö0nWÜ“S¿8ô¿ ªüØP>èžsýÂ@÷xM]ÙÃf'*Ù°Gáû×pŸÆáƽë|^¹Ùø˜déîWgÛFüލªk*{8£¿RY¼·_Ú°.M ¼>MÆÝ•Izý°VE £Ý#FwÍ ¹+Ô§®ŽÄg›Wi`e]‚2 ϟʪ?;zÀ»‡²#ñ÷ùÀæ5Ú*\;7‡¦A95Ð,z”ôÌj Ê÷Âù“ ´}ItûVÕ•*(¸ÍùRhóQ`›4ºÄëuîñ:w©N åÓ‚ºÑjì‰g¨>cÑB¡A †{¬~•ï‘õ#,ö¢xÔ¹0$ Âc;WçÅê××%ÂõìEø‹œ©Î„ûœÄ‡Jõxá¹{×Y kØ âaßȪÏ~a½y²%´'n—o†¯AÙÛÌžH£m0Ͼ7¦§à¹øâÒö…V1aDØg‡àºãM¼’ŽÀ]‹ ž â5ÉÍ‘’´yð²ÕƒñÀå–“œgfó©,Ã=O(\ Œ4³çj´ß‡Š ·×É[&‚»ø€ô•u3¥#ä×ÝŠÏP q/ÓGæÏÀ3†ÀGï$ûý°˜¨•H ùÛ3ê÷ û8vñÜ¥€™­¤’ò¾uVG’¶ý|8‹&åš~À§ñåµäÈmŠOé#-ÝÕ]8Û ÌûÌ&ϲn´eÏâñ¨èªÄ+‚‹qÏ×3+]3t8nnôÀ=|ÃkÍ\‚bž)œ¬dœ†î¿ÃWÚÚ †¡c]GâÒÍ”$wW¸fg|¹ì¬*º$óù¤ ¬š› L7÷°¤Ñ´I:_R칚 ÜhÅ>t1Ïýjö7³Ô˜O âu#[¼¦o×L3{5—²\LŽwf‡%©´›¤ÙxöÀÞi*xôeÜû¹ ð{üÕÎ’¯2lÚp»á)$ýqCw%0  ã)Řú{"‡æLü£áAÑyÀºî¸gé W•xr(ÑNḋQ1$ÁÓSÖ¦õ—Ãï®ÀÀ:ïÃQ¿/áym'áñŒ†ŒyƒJšÅ #include #include "ConvergenceScheme.h" CheMPS2::ConvergenceScheme::ConvergenceScheme(const int nInstructions){ this->nInstructions = nInstructions; assert( nInstructions>0 ); nD = new int[ nInstructions]; fEconv = new double[nInstructions]; nMaxSweeps = new int[ nInstructions]; fNoisePrefactor = new double[nInstructions]; } CheMPS2::ConvergenceScheme::~ConvergenceScheme(){ delete [] nD; delete [] fEconv; delete [] nMaxSweeps; delete [] fNoisePrefactor; } int CheMPS2::ConvergenceScheme::getNInstructions(){ return nInstructions; } void CheMPS2::ConvergenceScheme::setInstruction(const int instruction, const int D, const double Econv, const int nMax, const double noisePrefactor){ assert( instruction>=0 ); assert( instruction0 ); assert( Econv>0.0 ); assert( nMax>0 ); assert( noisePrefactor>=0.0 ); nD[instruction] = D; fEconv[instruction] = Econv; nMaxSweeps[instruction] = nMax; fNoisePrefactor[instruction] = noisePrefactor; } int CheMPS2::ConvergenceScheme::getD(const int instruction){ return nD[instruction]; } double CheMPS2::ConvergenceScheme::getEconv(const int instruction){ return fEconv[instruction]; } int CheMPS2::ConvergenceScheme::getMaxSweeps(const int instruction){ return nMaxSweeps[instruction]; } double CheMPS2::ConvergenceScheme::getNoisePrefactor(const int instruction){ return fNoisePrefactor[instruction]; } CheMPS2-1.6/CheMPS2/Correlations.cpp000066400000000000000000000710751256744172700170630ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include "Correlations.h" #include "Lapack.h" #include "MPIchemps2.h" using std::cout; using std::cerr; using std::endl; using std::max; using std::min; CheMPS2::Correlations::Correlations(const SyBookkeeper * denBKIn, const Problem * ProbIn, TwoDM * the2DMin){ denBK = denBKIn; Prob = ProbIn; the2DM = the2DMin; L = denBK->gL(); OneRDM = new double[L*L]; Cspin = new double[L*L]; Cdens = new double[L*L]; Cspinflip = new double[L*L]; Cdirad = new double[L*L]; MutInfo = new double[L*L]; for (int cnt=0; cntgN() - 1.0 ); for (int row=0; rowgetTwoDMA_DMRG(row,third,col,third); } OneRDM[row + L*col] *= prefactor; OneRDM[col + L*row] = OneRDM[row + L*col]; } } //Spin for (int row=0; rowgetTwoDMB_DMRG(row,col,row,col); } Cspin[row + L*row] += OneRDM[row + L*row]; } //Density for (int row=0; rowgetTwoDMA_DMRG(row,col,row,col) - OneRDM[row + L*row] * OneRDM[col + L*col]; } Cdens[row + L*row] += OneRDM[row + L*row]; } //Spin-flip for (int row=0; rowgetTwoDMB_DMRG(row,col,col,row) - the2DM->getTwoDMA_DMRG(row,col,col,row) ); } Cspinflip[row + L*row] += OneRDM[row + L*row]; } //Singlet diradical: partial fill for (int row=0; rowgetTwoDMA_DMRG(row,row,row,row) ) * ( OneRDM[col + L*col] - the2DM->getTwoDMA_DMRG(col,col,col,col) ); } } } double CheMPS2::Correlations::getCspin_DMRG(const int row, const int col) const{ return Cspin[row + L*col]; } double CheMPS2::Correlations::getCspin_HAM(const int row, const int col) const{ //Prob assumes you use DMRG orbs... f1 converts HAM orbs to DMRG orbs if ( Prob->gReorderD2h() ){ return getCspin_DMRG( Prob->gf1(row), Prob->gf1(col) ); } return getCspin_DMRG( row, col ); } double CheMPS2::Correlations::getCdens_DMRG(const int row, const int col) const{ return Cdens[row + L*col]; } double CheMPS2::Correlations::getCdens_HAM(const int row, const int col) const{ //Prob assumes you use DMRG orbs... f1 converts HAM orbs to DMRG orbs if ( Prob->gReorderD2h() ){ return getCdens_DMRG( Prob->gf1(row), Prob->gf1(col) ); } return getCdens_DMRG( row, col ); } double CheMPS2::Correlations::getCspinflip_DMRG(const int row, const int col) const{ return Cspinflip[row + L*col]; } double CheMPS2::Correlations::getCspinflip_HAM(const int row, const int col) const{ //Prob assumes you use DMRG orbs... f1 converts HAM orbs to DMRG orbs if ( Prob->gReorderD2h() ){ return getCspinflip_DMRG( Prob->gf1(row), Prob->gf1(col) ); } return getCspinflip_DMRG( row, col ); } double CheMPS2::Correlations::getCdirad_DMRG(const int row, const int col) const{ return Cdirad[row + L*col]; } double CheMPS2::Correlations::getCdirad_HAM(const int row, const int col) const{ //Prob assumes you use DMRG orbs... f1 converts HAM orbs to DMRG orbs if ( Prob->gReorderD2h() ){ return getCdirad_DMRG( Prob->gf1(row), Prob->gf1(col) ); } return getCdirad_DMRG( row, col ); } double CheMPS2::Correlations::getMutualInformation_DMRG(const int row, const int col) const{ return MutInfo[row + L*col]; } double CheMPS2::Correlations::getMutualInformation_HAM(const int row, const int col) const{ //Prob assumes you use DMRG orbs... f1 converts HAM orbs to DMRG orbs if ( Prob->gReorderD2h() ){ return getMutualInformation_DMRG( Prob->gf1(row), Prob->gf1(col) ); } return getMutualInformation_DMRG( row, col ); } double CheMPS2::Correlations::SingleOrbitalEntropy_DMRG(const int index) const{ const double val4 = 0.5 * the2DM->getTwoDMA_DMRG(index,index,index,index); const double val23 = 0.5 * ( OneRDM[index + L*index] - the2DM->getTwoDMA_DMRG(index,index,index,index) ); const double val1 = 1.0 - val4 - 2*val23; if (val1 < 0.0){ cerr << " Correlations::SingleOrbitalEntropy : Warning : val1 for orbital " << index << " = " << val1 << endl; } if (val23 < 0.0){ cerr << " Correlations::SingleOrbitalEntropy : Warning : val23 for orbital " << index << " = " << val23 << endl; } if (val4 < 0.0){ cerr << " Correlations::SingleOrbitalEntropy : Warning : val4 for orbital " << index << " = " << val4 << endl; } double entropy = 0.0; if (val1 > CheMPS2::CORRELATIONS_discardEig){ entropy -= val1 * log(val1 ); } if (val23 > CheMPS2::CORRELATIONS_discardEig){ entropy -= 2 * val23 * log(val23); } if (val4 > CheMPS2::CORRELATIONS_discardEig){ entropy -= val4 * log(val4 ); } return entropy; } double CheMPS2::Correlations::SingleOrbitalEntropy_HAM(const int index) const{ if ( Prob->gReorderD2h() ){ return SingleOrbitalEntropy_DMRG( Prob->gf1(index) ); } return SingleOrbitalEntropy_DMRG( index ); } double CheMPS2::Correlations::MutualInformationDistance(const double power) const{ double Idist = 0.0; for (int row=0; rowgIndex(); const int MAXDIM = max(denBK->gMaxDimAtBound(theindex), denBK->gMaxDimAtBound(theindex+1)); double * workmem = new double[MAXDIM*MAXDIM]; int lindimRDM = 16; double * RDM = new double[lindimRDM*lindimRDM]; int lwork = 3*lindimRDM - 1; double * work = new double[lwork]; double * eigs = new double[lindimRDM]; const double prefactorSpin = 1.0/(Prob->gTwoS() + 1.0); const double sqrt_one_half = sqrt(0.5); for (int previousindex=0; previousindexgIrrep(previousindex) == denBK->gIrrep(theindex)) ? true : false; const double diag1 = diagram3(denT, Gtensors[previousindex], workmem) * prefactorSpin * 0.5 * sqrt_one_half; const double diag2 = 0.125 * ( the2DM->getTwoDMB_DMRG(previousindex,theindex,theindex,previousindex) - the2DM->getTwoDMA_DMRG(previousindex,theindex,theindex,previousindex) ); const double val1 = diagram1(denT, Ytensors[previousindex], workmem) * prefactorSpin; //1x1 block N=0, Sz=0 const double val2 = diagram2(denT, Ztensors[previousindex], workmem) * prefactorSpin; //1x1 block N=4, Sz=0 const double val3 = diag1 + diag2; //1x1 block N=2, Sz=2*sigma const double val4 = diagram1(denT, Gtensors[previousindex], workmem) * prefactorSpin * sqrt_one_half; //2x2 block N=1, alpha_LL const double val5 = diagram3(denT, Ytensors[previousindex], workmem) * prefactorSpin * 0.5; //2x2 block N=1, alpha_RR const double val6 = (equalIrreps) ? ( diagram4(denT, Ktensors[previousindex], workmem) * prefactorSpin * 0.5 ) : 0.0 ; //2x2 block N=1, alpha_LR const double val7 = diagram2(denT, Gtensors[previousindex], workmem) * prefactorSpin * sqrt_one_half; //2x2 block N=3, alpha_LL const double val8 = diagram3(denT, Ztensors[previousindex], workmem) * prefactorSpin * 0.5; //2x2 block N=3, alpha_RR const double val9 = (equalIrreps) ? ( diagram5(denT, Mtensors[previousindex], workmem) * prefactorSpin * 0.5 ) : 0.0 ; //2x2 block N=3, alpha_LR //4x4 block N=2, Sz=0 const double alpha = diagram2(denT, Ytensors[previousindex], workmem) * prefactorSpin; const double gamma = diagram1(denT, Ztensors[previousindex], workmem) * prefactorSpin; const double beta = diag1 - diag2; const double lambda = 2*diag2; const double delta = (equalIrreps) ? ( - diagram5(denT, Ktensors[previousindex], workmem) * prefactorSpin * 0.5 ) : 0.0; const double epsilon = (equalIrreps) ? ( diagram4(denT, Mtensors[previousindex], workmem) * prefactorSpin * 0.5 ) : 0.0; const double kappa = 0.5 * the2DM->getTwoDMA_DMRG(previousindex,previousindex,theindex,theindex); /* [ val1 ] [ val4 val6 ] [ val6 val5 ] [ val4 val6 ] [ val6 val5 ] [ val3 ] [ alpha delta -delta kappa ] [ delta beta lambda epsilon ] [ -delta lambda beta -epsilon ] [ kappa epsilon -epsilon gamma ] [ val3 ] [ val7 val9 ] [ val9 val8 ] [ val7 val9 ] [ val9 val8 ] [ val2 ] */ for (int cnt=0; cntgetTwoDMA_DMRG(previousindex,previousindex,previousindex,previousindex); const double RDM_1orb_prev_23 = 0.5 * ( OneRDM[previousindex + L*previousindex] - the2DM->getTwoDMA_DMRG(previousindex,previousindex,previousindex,previousindex) ); const double RDM_1orb_prev_1 = 1.0 - RDM_1orb_prev_4 - 2*RDM_1orb_prev_23; const double RDM_1orb_curr_4 = 0.5 * the2DM->getTwoDMA_DMRG(theindex,theindex,theindex,theindex); const double RDM_1orb_curr_23 = 0.5 * ( OneRDM[theindex + L*theindex] - the2DM->getTwoDMA_DMRG(theindex,theindex,theindex,theindex) ); const double RDM_1orb_curr_1 = 1.0 - RDM_1orb_curr_4 - 2*RDM_1orb_curr_23; cout << " Correlations::FillSite : Looking at DMRG sites (" << previousindex << "," << theindex << ")." << endl; //Check 1 : full trace double fulltrace = 0.0; for (int cnt=0; cntgReorderD2h()) ? Prob->gf1(row) : row; int col2 = (Prob->gReorderD2h()) ? Prob->gf1(col) : col; if (table[row2 + L*col2] < 0.0){ thestream << prefix << table[row2 + L*col2]; } else { thestream << prefix << " " << table[row2 + L*col2]; } } } thestream << "\n"; } thestream << "\n"; } cout << thestream.str(); } void CheMPS2::Correlations::Print(const int precision, const int columnsPerLine) const{ cout << "--------------------------------------------------------" << endl; cout << "Spin correlation function = 4 * ( < S_i^z S_j^z > - < S_i^z > * < S_j^z > ) \nHamiltonian index order is used!\n" << endl; PrintTableNice( Cspin , precision, columnsPerLine ); cout << "--------------------------------------------------------" << endl; cout << "Spin-flip correlation function = < S_i^+ S_j^- > + < S_i^- S_j^+ > \nHamiltonian index order is used!\n" << endl; PrintTableNice( Cspinflip , precision, columnsPerLine); cout << "--------------------------------------------------------" << endl; cout << "Density correlation function = < n_i n_j > - < n_i > * < n_j > \nHamiltonian index order is used!\n" << endl; PrintTableNice( Cdens , precision, columnsPerLine ); cout << "--------------------------------------------------------" << endl; cout << "Singlet diradical correlation function = < d_i,up d_j,down > + < d_i,down d_j,up > - < d_i,up > * < d_j,down > - < d_i,down > * < d_j,up > \nHamiltonian index order is used!\n" << endl; PrintTableNice( Cdirad , precision, columnsPerLine ); cout << "--------------------------------------------------------" << endl; cout << "Two-orbital mutual information = 0.5 * ( s1(i) + s1(j) - s2(i,j) ) * ( 1 - delta(i,j) ) \nHamiltonian index order is used!\n" << endl; PrintTableNice( MutInfo , precision, columnsPerLine ); cout << "--------------------------------------------------------" << endl; } CheMPS2-1.6/CheMPS2/DIIS.cpp000066400000000000000000000242121256744172700151360ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include "MyHDF5.h" #include "Lapack.h" #include "DIIS.h" using std::string; using std::ifstream; using std::cout; using std::endl; CheMPS2::DIIS::DIIS(const int numVarsParamIn, const int numVarsErrorIn, const int numVecsIn){ numVarsParam = numVarsParamIn; numVarsError = numVarsErrorIn; numVecs = numVecsIn; errorVectors = new double*[numVecs]; paramVectors = new double*[numVecs]; currentNumVecs = 0; lastLinco = new double[numVarsParam]; } CheMPS2::DIIS::~DIIS(){ for (int cnt=0; cnt work for (int cnt=0; cnt work+lindim char trans = 'T'; char notra = 'N'; int one = 1; double alpha = 1.0; double beta = 0.0; dgemm_(&trans, ¬ra, &lindim, &one, &lindim, &alpha, matrix, &lindim, work, &lindim, &beta, work+lindim, &lindim); //Step 3: (1/eigs) V^T [vec(0), 1] --> work+lindim for (int cnt=0; cnt work dgemm_(¬ra, ¬ra, &lindim, &one, &lindim, &alpha, matrix, &lindim, work+lindim, &lindim, &beta, work, &lindim); //Fill newParam and make a copy in lastLinco for (int cnt=0; cnt older vectors) : "; for (int cnt=0; cnt=0 ); //Create just enough storage for the vectors to be loaded if (currentNumVecs < currentNumVecsBIS){ for (int cnt=currentNumVecs; cnt currentNumVecsBIS){ for (int cnt=currentNumVecs; cnt>currentNumVecsBIS; cnt--){ delete [] errorVectors[cnt-1]; delete [] paramVectors[cnt-1]; } currentNumVecs = currentNumVecsBIS; } for (int cnt=0; cnt #include #include #include #include #include #include #include #include #include "DMRG.h" #include "MPIchemps2.h" using std::cout; using std::cerr; using std::endl; CheMPS2::DMRG::DMRG(Problem * ProbIn, ConvergenceScheme * OptSchemeIn, const bool makechkpt, const string tmpfolder){ #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ){ PrintLicense(); } #else PrintLicense(); #endif assert( ProbIn->checkConsistency() ); Prob = ProbIn; L = Prob->gL(); Prob->construct_mxelem(); OptScheme = OptSchemeIn; thePID = getpid(); //PID is unique for each MPI process nStates = 1; Ltensors = new TensorL ** [L-1]; F0tensors = new TensorF0 *** [L-1]; F1tensors = new TensorF1 *** [L-1]; S0tensors = new TensorS0 *** [L-1]; S1tensors = new TensorS1 *** [L-1]; Atensors = new TensorA *** [L-1]; Btensors = new TensorB *** [L-1]; Ctensors = new TensorC *** [L-1]; Dtensors = new TensorD *** [L-1]; Qtensors = new TensorQ ** [L-1]; Xtensors = new TensorX * [L-1]; isAllocated = new int[L-1]; //0 not allocated, 1 allocated with movingRight true, 2 allocated with movingRight false for (int cnt=0; cntgetD(0)); assert( denBK->IsPossible() ); std::stringstream sstream; sstream << CheMPS2::DMRG_MPS_storage_prefix << nStates-1 << ".h5"; MPSstoragename.assign( sstream.str() ); struct stat stFileInfo; int intStat = stat(MPSstoragename.c_str(),&stFileInfo); loadedMPS = ((makecheckpoints) && (intStat==0))? true : false ; #ifdef CHEMPS2_MPI_COMPILATION assert( MPIchemps2::all_booleans_equal( loadedMPS ) ); #endif if (loadedMPS){ loadDIM(MPSstoragename,denBK); } MPS = new TensorT * [L]; for (int cnt=0; cntgIrrep(cnt),denBK); } if (loadedMPS){ bool isConverged; loadMPS(MPSstoragename, MPS, &isConverged); #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ) #endif { cout << "Loaded MPS " << MPSstoragename << " converged y/n? : " << isConverged << endl; } } else { for (int cnt=0; cntrandom(); MPS[cnt]->QR(Dstor); delete Dstor; #ifdef CHEMPS2_MPI_COMPILATION } MPIchemps2::broadcast_tensor(MPS[cnt], MPI_CHEMPS2_MASTER); #endif } } } CheMPS2::DMRG::~DMRG(){ if (the2DMallocated){ delete the2DM; } if (theCorrAllocated){ delete theCorr; } deleteAllBoundaryOperators(); delete [] Ltensors; delete [] F0tensors; delete [] F1tensors; delete [] S0tensors; delete [] S1tensors; delete [] Atensors; delete [] Btensors; delete [] Ctensors; delete [] Dtensors; delete [] Qtensors; delete [] Xtensors; delete [] isAllocated; for (int site=0; sitegetNInstructions(); instruction++){ int nIterations = 0; double EnergyPrevious = Energy + 10 * OptScheme->getEconv(instruction); //Guarantees that there's always at least 1 left-right sweep while ( (fabs(Energy-EnergyPrevious) > OptScheme->getEconv(instruction) ) && ( nIterations < OptScheme->getMaxSweeps(instruction) )){ for (int timecnt=0; timecnt S.join = " << timings[ CHEMPS2_TIME_S_JOIN ] << " seconds" << endl; cout << "*** |--> S.solve = " << timings[ CHEMPS2_TIME_S_SOLVE ] << " seconds" << endl; cout << "*** |--> S.split = " << timings[ CHEMPS2_TIME_S_SPLIT ] << " seconds" << endl; cout << "*** |--> Tensor update = " << timings[ CHEMPS2_TIME_TENS_TOTAL ] << " seconds" << endl; cout << "*** |--> create = " << timings[ CHEMPS2_TIME_TENS_ALLOC ] << " seconds" << endl; cout << "*** |--> destroy = " << timings[ CHEMPS2_TIME_TENS_FREE ] << " seconds" << endl; cout << "*** |--> disk write = " << timings[ CHEMPS2_TIME_DISK_WRITE ] << " seconds" << endl; cout << "*** |--> disk read = " << timings[ CHEMPS2_TIME_DISK_READ ] << " seconds" << endl; cout << "*** |--> calc = " << timings[ CHEMPS2_TIME_TENS_CALC ] << " seconds" << endl; cout << "*** Disk write bandwidth = " << num_double_write_disk * sizeof(double) / ( timings[ CHEMPS2_TIME_DISK_WRITE ] * 1048576 ) << " MB/s" << endl; cout << "*** Disk read bandwidth = " << num_double_read_disk * sizeof(double) / ( timings[ CHEMPS2_TIME_DISK_READ ] * 1048576 ) << " MB/s" << endl; cout << "*** Minimum energy = " << LastMinEnergy << endl; cout << "*** Maximum discarded weight = " << MaxDiscWeightLastSweep << endl; } if (!change) change = true; //rest of sweeps: variable virtual dimensions for (int timecnt=0; timecnt S.join = " << timings[ CHEMPS2_TIME_S_JOIN ] << " seconds" << endl; cout << "*** |--> S.solve = " << timings[ CHEMPS2_TIME_S_SOLVE ] << " seconds" << endl; cout << "*** |--> S.split = " << timings[ CHEMPS2_TIME_S_SPLIT ] << " seconds" << endl; cout << "*** |--> Tensor update = " << timings[ CHEMPS2_TIME_TENS_TOTAL ] << " seconds" << endl; cout << "*** |--> create = " << timings[ CHEMPS2_TIME_TENS_ALLOC ] << " seconds" << endl; cout << "*** |--> destroy = " << timings[ CHEMPS2_TIME_TENS_FREE ] << " seconds" << endl; cout << "*** |--> disk write = " << timings[ CHEMPS2_TIME_DISK_WRITE ] << " seconds" << endl; cout << "*** |--> disk read = " << timings[ CHEMPS2_TIME_DISK_READ ] << " seconds" << endl; cout << "*** |--> calc = " << timings[ CHEMPS2_TIME_TENS_CALC ] << " seconds" << endl; cout << "*** Disk write bandwidth = " << num_double_write_disk * sizeof(double) / ( timings[ CHEMPS2_TIME_DISK_WRITE ] * 1048576 ) << " MB/s" << endl; cout << "*** Disk read bandwidth = " << num_double_read_disk * sizeof(double) / ( timings[ CHEMPS2_TIME_DISK_READ ] * 1048576 ) << " MB/s" << endl; cout << "*** Minimum energy = " << LastMinEnergy << endl; cout << "*** Maximum discarded weight = " << MaxDiscWeightLastSweep << endl; if ( makecheckpoints ){ saveMPS(MPSstoragename, MPS, denBK, false); } // Only the master proc makes MPS checkpoints !! } nIterations++; if ( am_i_master ){ cout << "*** Energy difference with respect to previous leftright sweep = " << fabs(Energy-EnergyPrevious) << endl; } if (Exc_activated){ calcOverlapsWithLowerStates(); } } if ( am_i_master ){ cout << "****************************************************************************" << endl; cout << "*** Information on completed instruction " << instruction << ":" << endl; cout << "*** The reduced virtual dimension DSU(2) = " << OptScheme->getD(instruction) << endl; cout << "*** Minimum energy encountered during all instructions = " << TotalMinEnergy << endl; cout << "*** Minimum energy encountered during the last sweep = " << LastMinEnergy << endl; cout << "*** Maximum discarded weight during the last sweep = " << MaxDiscWeightLastSweep << endl; cout << "****************************************************************************" << endl; } } return TotalMinEnergy; } double CheMPS2::DMRG::sweepleft(const bool change, const int instruction, const bool am_i_master){ double Energy = 0.0; double NoiseLevel = OptScheme->getNoisePrefactor(instruction) * MaxDiscWeightLastSweep; MaxDiscWeightLastSweep = 0.0; LastMinEnergy = 1e8; struct timeval start, end; for (int index = L-2; index>0; index--){ //Construct S gettimeofday(&start, NULL); Sobject * denS = new Sobject(index,denBK->gIrrep(index),denBK->gIrrep(index+1),denBK); //Each MPI process joins the MPS tensors. Before a matrix-vector multiplication the vector is broadcasted anyway. denS->Join(MPS[index],MPS[index+1]); gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_S_JOIN ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); //Feed everything to the solver gettimeofday(&start, NULL); Heff Solver(denBK, Prob); double ** VeffTilde = NULL; if (Exc_activated){ VeffTilde = prepare_excitations(denS); } //Each MPI process returns the correct energy. Only MPI_CHEMPS2_MASTER has the correct denS solution. Energy = Solver.SolveDAVIDSON(denS, Ltensors, Atensors, Btensors, Ctensors, Dtensors, S0tensors, S1tensors, F0tensors, F1tensors, Qtensors, Xtensors, nStates-1, VeffTilde); if (Exc_activated){ cleanup_excitations(VeffTilde); } Energy += Prob->gEconst(); if (Energy0.0 ) && ( am_i_master )){ denS->addNoise(NoiseLevel); } //MPI_CHEMPS2_MASTER decomposes denS. Each MPI process returns the correct discWeight and now has the new MPS tensors set. double discWeight = denS->Split(MPS[index],MPS[index+1],OptScheme->getD(instruction),false,change); delete denS; if (discWeight > MaxDiscWeightLastSweep){ MaxDiscWeightLastSweep = discWeight; } gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_S_SPLIT ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); //Print info if ( am_i_master ){ cout << "Energy at sites (" << index << ", " << (index+1) << ") is " << Energy << endl; if (CheMPS2::DMRG_printDiscardedWeight && change){ cout << " Info(DMRG) : Discarded weight in SVD decomp. (non-reduced) = " << discWeight << endl; } } //Prepare for next step gettimeofday(&start, NULL); updateMovingLeftSafe(index); gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_TENS_TOTAL ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); } return Energy; } double CheMPS2::DMRG::sweepright(const bool change, const int instruction, const bool am_i_master){ double Energy=0.0; double NoiseLevel = OptScheme->getNoisePrefactor(instruction) * MaxDiscWeightLastSweep; MaxDiscWeightLastSweep = 0.0; LastMinEnergy = 1e8; struct timeval start, end; for (int index = 0; indexgIrrep(index),denBK->gIrrep(index+1),denBK); //Each MPI process joins the MPS tensors. Before a matrix-vector multiplication the vector is broadcasted anyway. denS->Join(MPS[index],MPS[index+1]); gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_S_JOIN ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); //Feed everything to solver gettimeofday(&start, NULL); Heff Solver(denBK, Prob); double ** VeffTilde = NULL; if (Exc_activated){ VeffTilde = prepare_excitations(denS); } //Each MPI process returns the correct energy. Only MPI_CHEMPS2_MASTER has the correct denS solution. Energy = Solver.SolveDAVIDSON(denS, Ltensors, Atensors, Btensors, Ctensors, Dtensors, S0tensors, S1tensors, F0tensors, F1tensors, Qtensors, Xtensors, nStates-1, VeffTilde); if (Exc_activated){ cleanup_excitations(VeffTilde); } Energy += Prob->gEconst(); if (Energy0.0 ) && ( am_i_master )){ denS->addNoise(NoiseLevel); } //MPI_CHEMPS2_MASTER decomposes denS. Each MPI process returns the correct discWeight and now has the new MPS tensors set. double discWeight = denS->Split(MPS[index],MPS[index+1],OptScheme->getD(instruction),true,change); delete denS; if (discWeight > MaxDiscWeightLastSweep){ MaxDiscWeightLastSweep = discWeight; } gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_S_SPLIT ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); //Print info if ( am_i_master ){ cout << "Energy at sites (" << index << ", " << (index+1) << ") is " << Energy << endl; if (CheMPS2::DMRG_printDiscardedWeight && change){ cout << " Info(DMRG) : Discarded weight in SVD decomp. (non-reduced) = " << discWeight << endl; } } //Prepare for next step gettimeofday(&start, NULL); updateMovingRightSafe(index); gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_TENS_TOTAL ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); } return Energy; } void CheMPS2::DMRG::activateExcitations(const int maxExcIn){ Exc_activated = true; maxExc = maxExcIn; Exc_Eshifts = new double[maxExc]; Exc_MPSs = new TensorT ** [maxExc]; Exc_BKs = new SyBookkeeper * [maxExc]; Exc_Overlaps = new TensorO ** [maxExc]; } void CheMPS2::DMRG::newExcitation(const double EshiftIn){ assert( Exc_activated ); assert( nStates-1 < maxExc ); if (the2DMallocated){ delete the2DM; the2DMallocated = false; } if (theCorrAllocated){ delete theCorr; theCorrAllocated = false; } deleteAllBoundaryOperators(); Exc_Eshifts[nStates-1] = EshiftIn; #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_specific_excitation( L, nStates-1 ) == MPIchemps2::mpi_rank() ){ #endif Exc_MPSs[nStates-1] = MPS; Exc_BKs[nStates-1] = denBK; Exc_Overlaps[nStates-1] = new TensorO*[L-1]; #ifdef CHEMPS2_MPI_COMPILATION } else { for (int site=0; site #include #include #include "DMRGSCFVmatRotations.h" #include "Lapack.h" using std::min; using std::max; CheMPS2::DMRGSCFVmatRotations::DMRGSCFVmatRotations(Hamiltonian * HamOrigIn, DMRGSCFindices * iHandlerIn){ HamOrig = HamOrigIn; iHandler = iHandlerIn; SymmInfo.setGroup(HamOrig->getNGroup()); numberOfIrreps = SymmInfo.getNumberOfIrreps(); } CheMPS2::DMRGSCFVmatRotations::~DMRGSCFVmatRotations(){ } void CheMPS2::DMRGSCFVmatRotations::fillVmatRotated(FourIndex * VmatRotated, DMRGSCFunitary * unitary, double * temp1, double * temp2) const{ //Two-body terms --> use eightfold permutation symmetry for (int irrep1 = 0; irrep1=irrep2){ int linsize1 = iHandler->getNORB(irrep1); int linsize2 = iHandler->getNORB(irrep2); int linsize3 = iHandler->getNORB(irrep3); int linsize4 = iHandler->getNORB(irrep4); if ((linsize1>0) && (linsize2>0) && (linsize3>0) && (linsize4>0)){ for (int cnt1=0; cnt1getVmat( iHandler->getOrigNOCCstart(irrep1) + cnt1, iHandler->getOrigNOCCstart(irrep2) + cnt2, iHandler->getOrigNOCCstart(irrep3) + cnt3, iHandler->getOrigNOCCstart(irrep4) + cnt4 ); } } } } char trans = 'T'; char notra = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int rightdim = linsize2 * linsize3 * linsize4; //(ijkl) -> (ajkl) dgemm_(¬ra,¬ra,&linsize1,&rightdim,&linsize1, &alpha, unitary->getBlock(irrep1),&linsize1,temp1,&linsize1, &beta,temp2,&linsize1); int leftdim = linsize1 * linsize2 * linsize3; //(ajkl) -> (ajkd) dgemm_(¬ra,&trans,&leftdim,&linsize4,&linsize4, &alpha,temp2,&leftdim, unitary->getBlock(irrep4),&linsize4, &beta,temp1,&leftdim); int jump = leftdim; //(ajkd) -> (ajcd) leftdim = linsize1 * linsize2; for (int bla=0; blagetBlock(irrep3),&linsize3, &beta,temp2+jump*bla,&leftdim); } jump = leftdim; rightdim = linsize3*linsize4; for (int bla=0; blagetBlock(irrep2),&linsize2,&beta,temp1+jump*bla,&linsize1); } for (int cnt1=0; cnt1set(irrep1, irrep2, irrep3, irrep4, cnt1, cnt2, cnt3, cnt4, temp1[cnt1 + linsize1 * ( cnt2 + linsize2 * (cnt3 + linsize3 * cnt4) ) ] ); } } } } } } } } } } void CheMPS2::DMRGSCFVmatRotations::fillVmatDMRG(Hamiltonian * HamDMRG, DMRGSCFunitary * unitary, double * temp1, double * temp2) const{ //Two-body terms --> use eightfold permutation symmetry in the irreps :-) for (int irrep1 = 0; irrep1=irrep2){ int linsizeDMRG1 = iHandler->getNDMRG(irrep1); int linsizeDMRG2 = iHandler->getNDMRG(irrep2); int linsizeDMRG3 = iHandler->getNDMRG(irrep3); int linsizeDMRG4 = iHandler->getNDMRG(irrep4); if ((linsizeDMRG1>0) && (linsizeDMRG2>0) && (linsizeDMRG3>0) && (linsizeDMRG4>0)){ int linsizeORIG1 = iHandler->getNORB(irrep1); int linsizeORIG2 = iHandler->getNORB(irrep2); int linsizeORIG3 = iHandler->getNORB(irrep3); int linsizeORIG4 = iHandler->getNORB(irrep4); for (int cnt1=0; cnt1getVmat( iHandler->getOrigNOCCstart(irrep1) + cnt1, iHandler->getOrigNOCCstart(irrep2) + cnt2, iHandler->getOrigNOCCstart(irrep3) + cnt3, iHandler->getOrigNOCCstart(irrep4) + cnt4 ); } } } } char trans = 'T'; char notra = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int rightdim = linsizeORIG2 * linsizeORIG3 * linsizeORIG4; //(ijkl) -> (ajkl) double * Umx = unitary->getBlock(irrep1) + iHandler->getNOCC(irrep1); dgemm_(¬ra, ¬ra, &linsizeDMRG1, &rightdim, &linsizeORIG1, &alpha, Umx, &linsizeORIG1, temp1, &linsizeORIG1, &beta, temp2, &linsizeDMRG1); int leftdim = linsizeDMRG1 * linsizeORIG2 * linsizeORIG3; //(ajkl) -> (ajkd) Umx = unitary->getBlock(irrep4) + iHandler->getNOCC(irrep4); dgemm_(¬ra, &trans, &leftdim, &linsizeDMRG4, &linsizeORIG4, &alpha, temp2, &leftdim, Umx, &linsizeORIG4, &beta, temp1, &leftdim); int jump1 = linsizeDMRG1 * linsizeORIG2 * linsizeORIG3; //(ajkd) -> (ajcd) int jump2 = linsizeDMRG1 * linsizeORIG2 * linsizeDMRG3; leftdim = linsizeDMRG1 * linsizeORIG2; Umx = unitary->getBlock(irrep3) + iHandler->getNOCC(irrep3); for (int bla=0; blagetBlock(irrep2) + iHandler->getNOCC(irrep2); for (int bla=0; blasetVmat( iHandler->getDMRGcumulative(irrep1) + cnt1, iHandler->getDMRGcumulative(irrep2) + cnt2, iHandler->getDMRGcumulative(irrep3) + cnt3, iHandler->getDMRGcumulative(irrep4) + cnt4, temp1[cnt1 + linsizeDMRG1 * ( cnt2 + linsizeDMRG2 * (cnt3 + linsizeDMRG3 * cnt4) ) ] ); } } } } } } } } } } void CheMPS2::DMRGSCFVmatRotations::fillRotatedTEI(DMRGSCFintegrals * theRotatedTEI, DMRGSCFunitary * unitary, double * temp1, double * temp2) const{ // First do Coulomb object : ( c1 <= c2 | a1 <= a2 ) for (int Ic1 = 0; Ic1 < numberOfIrreps; Ic1++){ for (int Ic2 = Ic1; Ic2 < numberOfIrreps; Ic2++){ const int Icc = Irreps::directProd( Ic1, Ic2 ); for (int Ia1 = 0; Ia1 < numberOfIrreps; Ia1++){ const int Ia2 = Irreps::directProd( Ia1, Icc ); if ( Ia1 <= Ia2 ){ int linsize_orig_c1 = iHandler->getNORB( Ic1 ); int linsize_orig_c2 = iHandler->getNORB( Ic2 ); int linsize_small_c1 = iHandler->getNOCC( Ic1 ) + iHandler->getNDMRG( Ic1 ); int linsize_small_c2 = iHandler->getNOCC( Ic2 ) + iHandler->getNDMRG( Ic2 ); int linsize_a1 = iHandler->getNORB( Ia1 ); int linsize_a2 = iHandler->getNORB( Ia2 ); if (( linsize_small_c1 > 0 ) && ( linsize_small_c2 > 0 ) && ( linsize_a1 > 0 ) && ( linsize_a2 > 0 )){ for (int c1 = 0; c1 < linsize_orig_c1; c1++){ for (int c2 = 0; c2 < linsize_orig_c2; c2++){ for (int a1 = 0; a1 < linsize_a1; a1++){ for (int a2 = 0; a2 < linsize_a2; a2++){ // We try to make the Coulomb elements ! temp1[ c1 + linsize_orig_c1 * ( c2 + linsize_orig_c2 * ( a1 + linsize_a1 * a2 ) ) ] = HamOrig->getVmat( iHandler->getOrigNOCCstart( Ic1 ) + c1, iHandler->getOrigNOCCstart( Ia1 ) + a1, iHandler->getOrigNOCCstart( Ic2 ) + c2, iHandler->getOrigNOCCstart( Ia2 ) + a2 ); } } } } char trans = 'T'; char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int rightdim = linsize_orig_c2 * linsize_a1 * linsize_a2; //( ij | kl ) -> ( c1 j | kl ) double * Umx = unitary->getBlock( Ic1 ); dgemm_(¬rans, ¬rans, &linsize_small_c1, &rightdim, &linsize_orig_c1, &alpha, Umx, &linsize_orig_c1, temp1, &linsize_orig_c1, &beta, temp2, &linsize_small_c1); rightdim = linsize_a1 * linsize_a2; //( c1 j | kl ) -> ( c1 c2 | kl ) int jump1 = linsize_small_c1 * linsize_small_c2; int jump2 = linsize_small_c1 * linsize_orig_c2; Umx = unitary->getBlock( Ic2 ); for (int loop = 0; loop < rightdim; loop++){ dgemm_(¬rans, &trans, &linsize_small_c1, &linsize_small_c2, &linsize_orig_c2, &alpha, temp2+loop*jump2, &linsize_small_c1, Umx, &linsize_orig_c2, &beta, temp1+loop*jump1, &linsize_small_c1); } int leftdim = linsize_small_c1 * linsize_small_c2 * linsize_a1; //( c1 c2 | kl ) -> ( c1 c2 | k a2 ) Umx = unitary->getBlock( Ia2 ); dgemm_(¬rans, &trans, &leftdim, &linsize_a2, &linsize_a2, &alpha, temp1, &leftdim, Umx, &linsize_a2, &beta, temp2, &leftdim); jump1 = linsize_small_c1 * linsize_small_c2 * linsize_a1; //( c1 c2 | k a2 ) -> ( c1 c2 | a1 a2 ) leftdim = linsize_small_c1 * linsize_small_c2; Umx = unitary->getBlock( Ia1 ); for (int loop = 0; loop < linsize_a2; loop++){ dgemm_(¬rans, &trans, &leftdim, &linsize_a1, &linsize_a1, &alpha, temp2+jump1*loop, &leftdim, Umx, &linsize_a1, &beta, temp1+jump1*loop, &leftdim); } for (int c1 = 0; c1 < linsize_small_c1; c1++){ for (int c2 = 0; c2 < linsize_small_c2; c2++){ for (int a1 = 0; a1 < linsize_a1; a1++){ for (int a2 = 0; a2 < linsize_a2; a2++){ theRotatedTEI->set_coulomb( Ic1, Ic2, Ia1, Ia2, c1, c2, a1, a2, temp1[ c1 + linsize_small_c1 * ( c2 + linsize_small_c2 * ( a1 + linsize_a1 * a2 ) ) ] ); } } } } } } } } } // Now do Exchange object ( c1 v1 | c2 v2 ) with c1 <= c2 for (int Ic1 = 0; Ic1 < numberOfIrreps; Ic1++){ for (int Ic2 = Ic1; Ic2 < numberOfIrreps; Ic2++){ const int Icc = Irreps::directProd( Ic1, Ic2 ); for (int Iv1 = 0; Iv1 < numberOfIrreps; Iv1++){ const int Iv2 = Irreps::directProd( Iv1, Icc ); int linsize_orig_c1 = iHandler->getNORB( Ic1 ); int linsize_orig_c2 = iHandler->getNORB( Ic2 ); int linsize_small_c1 = iHandler->getNOCC( Ic1 ) + iHandler->getNDMRG( Ic1 ); int linsize_small_c2 = iHandler->getNOCC( Ic2 ) + iHandler->getNDMRG( Ic2 ); int linsize_orig_v1 = iHandler->getNORB( Iv1 ); int linsize_orig_v2 = iHandler->getNORB( Iv2 ); int linsize_small_v1 = iHandler->getNVIRT( Iv1 ); int linsize_small_v2 = iHandler->getNVIRT( Iv2 ); if (( linsize_small_c1 > 0 ) && ( linsize_small_c2 > 0 ) && ( linsize_small_v1 > 0 ) && ( linsize_small_v2 > 0 )){ for (int c1 = 0; c1 < linsize_orig_c1; c1++){ for (int c2 = 0; c2 < linsize_orig_c2; c2++){ for (int v1 = 0; v1 < linsize_orig_v1; v1++){ for (int v2 = 0; v2 < linsize_orig_v2; v2++){ // We try to make the Exchange elements ! temp1[ c1 + linsize_orig_c1 * ( c2 + linsize_orig_c2 * ( v1 + linsize_orig_v1 * v2 ) ) ] = HamOrig->getVmat( iHandler->getOrigNOCCstart( Ic1 ) + c1, iHandler->getOrigNOCCstart( Ic2 ) + c2, iHandler->getOrigNOCCstart( Iv1 ) + v1, iHandler->getOrigNOCCstart( Iv2 ) + v2 ); } } } } char trans = 'T'; char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! const int shiftv1 = linsize_orig_v1 - linsize_small_v1; const int shiftv2 = linsize_orig_v2 - linsize_small_v2; int rightdim = linsize_orig_c2 * linsize_orig_v1 * linsize_orig_v2; //( ij | kl ) -> ( c1 j | kl ) double * Umx = unitary->getBlock( Ic1 ); dgemm_(¬rans, ¬rans, &linsize_small_c1, &rightdim, &linsize_orig_c1, &alpha, Umx, &linsize_orig_c1, temp1, &linsize_orig_c1, &beta, temp2, &linsize_small_c1); rightdim = linsize_orig_v1 * linsize_orig_v2; //( c1 j | kl ) -> ( c1 j | c2 l ) int jump1 = linsize_small_c1 * linsize_small_c2; int jump2 = linsize_small_c1 * linsize_orig_c2; Umx = unitary->getBlock( Ic2 ); for (int loop = 0; loop < rightdim; loop++){ dgemm_(¬rans, &trans, &linsize_small_c1, &linsize_small_c2, &linsize_orig_c2, &alpha, temp2+loop*jump2, &linsize_small_c1, Umx, &linsize_orig_c2, &beta, temp1+loop*jump1, &linsize_small_c1); } int leftdim = linsize_small_c1 * linsize_small_c2 * linsize_orig_v1; //( c1 j | c2 l ) -> ( c1 j | c2 v2 ) Umx = unitary->getBlock( Iv2 ) + shiftv2; dgemm_(¬rans, &trans, &leftdim, &linsize_small_v2, &linsize_orig_v2, &alpha, temp1, &leftdim, Umx, &linsize_orig_v2, &beta, temp2, &leftdim); jump1 = linsize_small_c1 * linsize_small_c2 * linsize_orig_v1; //( c1 j | c2 v2 ) -> ( c1 v1 | c2 v2 ) jump2 = linsize_small_c1 * linsize_small_c2 * linsize_small_v1; leftdim = linsize_small_c1 * linsize_small_c2; Umx = unitary->getBlock( Iv1 ) + shiftv1; for (int loop = 0; loop < linsize_small_v2; loop++){ dgemm_(¬rans, &trans, &leftdim, &linsize_small_v1, &linsize_orig_v1, &alpha, temp2+jump1*loop, &leftdim, Umx, &linsize_orig_v1, &beta, temp1+jump2*loop, &leftdim); } for (int c1 = 0; c1 < linsize_small_c1; c1++){ for (int c2 = 0; c2 < linsize_small_c2; c2++){ for (int v1 = 0; v1 < linsize_small_v1; v1++){ for (int v2 = 0; v2 < linsize_small_v2; v2++){ theRotatedTEI->set_exchange( Ic1, Ic2, Iv1, Iv2, c1, c2, shiftv1 + v1, shiftv2 + v2, temp1[ c1 + linsize_small_c1 * ( c2 + linsize_small_c2 * ( v1 + linsize_small_v1 * v2 ) ) ] ); } } } } } } } } } void CheMPS2::DMRGSCFVmatRotations::fillVmatRotatedBlockWise(FourIndex * VmatRotated, DMRGSCFunitary * unitary, double * mem1, double * mem2, double * mem3, const int maxBlockSize, const bool cutCorners) const{ /*********************************************************** ** Two-body terms; use eightfold permutation symmetry ** ** Requires 3 buffers of size maxBlockSize^4 ** ** maxBlockSize = ceil(maxlinsize/factor) at alloc ** ***********************************************************/ for (int irrep1 = 0; irrep1=irrep2){ const int linsize1 = iHandler->getNORB(irrep1); const int linsize2 = iHandler->getNORB(irrep2); const int linsize3 = iHandler->getNORB(irrep3); const int linsize4 = iHandler->getNORB(irrep4); const bool caseA = ((irrep1 == irrep2) && (irrep1 == irrep3) && (irrep1 == irrep4)); //I1 = I2 = I3 = I4 const bool caseB = ((!caseA) && (irrep1 == irrep2) && (irrep3 == irrep4)); //I1 = I2 < I3 = I4 const bool caseC = ((!caseA) && (irrep1 == irrep3) && (irrep2 == irrep4)); //I1 = I3 < I2 = I4 //caseD : All irreps different /* if (cutCorners): For the Gradient and Hessian, not all matrix elements are required: Maximum two indices are virtual. Thereto split up all target indices in an OA (occupied + active) part and a V (virtual) part and see that max. two indices are virtual. CASE A: if I1 = I2 = I3 = I4 the following combinations are allowed 0: OA OA OA OA 1: OA OA OA V 1: OA OA V OA 2: OA OA V V 2: OA V OA V due to either ( i1 < i2 <= i4 and i1 <= i3 ) or ( i1 = i2 <= i3 <= i4 ) . CASE B: if I1 = I2 < I3 = I4 the following combinations are allowed 0: OA OA OA OA 1: OA OA OA V 1: OA OA V OA 1: OA V OA OA 2: OA OA V V 2: OA V V OA 2: OA V OA V 2: V V OA OA due to either ( i1 < i2 and i3,i4 all ) or ( i1 = i2 <= i3 <= i4 ) . CASE C: if I1 = I3 < I2 = I4 the following combinations are allowed 0: OA OA OA OA 1: OA OA OA V 1: OA OA V OA 2: OA OA V V 2: V OA V OA 2: OA V OA V due to either ( i1 <= i3 and i2 <= i4 ) . CASE D: all irreps different: max two blocks virtual . */ if ((linsize1>0) && (linsize2>0) && (linsize3>0) && (linsize4>0)){ /** The scheme: Split up each of the linsizes into factor parts of size (linsize/factor). Make sure the boundaries are clear. Algorithm: Reset the FourIndex object for the particular symmetry case under consideration --> Vmat(i,j,k,l) = 0.0 Loop block1, block2, block3, block4 --> factor^4: Loop block1 --> factor: Copy HamOrig->getVmat(i,j,k,l) for the particular block into mem2_ijkl --> cost (linsize/factor)^4 Rotate mem1_ajkl = U_ai mem2_ijkl (but only block1 indices) --> cost(linsize/factor)^5 Loop block2 --> factor: Rotate mem2_abkl = U_bj mem1_ajkl (only block2 indices) --> cost (linsize/factor)^5 Loop block3 --> factor: Rotate mem3_abcl = U_ck mem2_abkl (only block3 indices) --> cost (linsize/factor)^5 Loop block4 --> factor: Calculate V_partial_abcd = U_dl mem3_abcl (only block4 indices) --> cost (linsize/factor)^5 Add (not set!!!) V_partial_abcd to FourIndex (for the different ijkl-blocks) --> cost (linsize/factor)^4 Total cost: f^4 * ( (l/f)^4 + f * ( (l/f)^5 + f * ( (l/f)^5 + f * ( (l/f)^5 + f * ( (l/f)^5 + (l/f)^4 ) ) ) ) ) = f^3 * l^5 */ //Split up the linsizes for the original Hamiltonian int factor1 = max( (int) ( ceil((1.0 * linsize1) / maxBlockSize) + 0.01 ) , 1 ); //factor >= linsize/maxBlockSize int factor2 = max( (int) ( ceil((1.0 * linsize2) / maxBlockSize) + 0.01 ) , 1 ); int factor3 = max( (int) ( ceil((1.0 * linsize3) / maxBlockSize) + 0.01 ) , 1 ); int factor4 = max( (int) ( ceil((1.0 * linsize4) / maxBlockSize) + 0.01 ) , 1 ); const int blocksize1 = min( (int) ( ceil( (1.0 * linsize1) / factor1 ) + 0.01 ) , maxBlockSize ); //Hence at most maxBlockSize const int blocksize2 = min( (int) ( ceil( (1.0 * linsize2) / factor2 ) + 0.01 ) , maxBlockSize ); const int blocksize3 = min( (int) ( ceil( (1.0 * linsize3) / factor3 ) + 0.01 ) , maxBlockSize ); const int blocksize4 = min( (int) ( ceil( (1.0 * linsize4) / factor4 ) + 0.01 ) , maxBlockSize ); while (factor1 * blocksize1 < linsize1){ factor1++; } while (factor2 * blocksize2 < linsize2){ factor2++; } while (factor3 * blocksize3 < linsize3){ factor3++; } while (factor4 * blocksize4 < linsize4){ factor4++; } //Split up the linsizes for the rotated Hamiltonian const int linsizeV1 = iHandler->getNVIRT(irrep1); const int linsizeOA1 = linsize1 - linsizeV1; const int linsizeV2 = iHandler->getNVIRT(irrep2); const int linsizeOA2 = linsize2 - linsizeV2; const int linsizeV3 = iHandler->getNVIRT(irrep3); const int linsizeOA3 = linsize3 - linsizeV3; const int linsizeV4 = iHandler->getNVIRT(irrep4); const int linsizeOA4 = linsize4 - linsizeV4; int factorV1 = (linsizeV1 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeV1) / maxBlockSize) + 0.01 ) , 1 ); int factorV2 = (linsizeV2 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeV2) / maxBlockSize) + 0.01 ) , 1 ); int factorV3 = (linsizeV3 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeV3) / maxBlockSize) + 0.01 ) , 1 ); int factorV4 = (linsizeV4 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeV4) / maxBlockSize) + 0.01 ) , 1 ); const int blocksizeV1 = (linsizeV1 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeV1) / factorV1 ) + 0.01 ) , maxBlockSize ); const int blocksizeV2 = (linsizeV2 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeV2) / factorV2 ) + 0.01 ) , maxBlockSize ); const int blocksizeV3 = (linsizeV3 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeV3) / factorV3 ) + 0.01 ) , maxBlockSize ); const int blocksizeV4 = (linsizeV4 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeV4) / factorV4 ) + 0.01 ) , maxBlockSize ); if (linsizeV1 > 0){ while (factorV1 * blocksizeV1 < linsizeV1){ factorV1++; } } if (linsizeV2 > 0){ while (factorV2 * blocksizeV2 < linsizeV2){ factorV2++; } } if (linsizeV3 > 0){ while (factorV3 * blocksizeV3 < linsizeV3){ factorV3++; } } if (linsizeV4 > 0){ while (factorV4 * blocksizeV4 < linsizeV4){ factorV4++; } } int factorOA1 = (linsizeOA1 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA1) / maxBlockSize) + 0.01 ) , 1 ); int factorOA2 = (linsizeOA2 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA2) / maxBlockSize) + 0.01 ) , 1 ); int factorOA3 = (linsizeOA3 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA3) / maxBlockSize) + 0.01 ) , 1 ); int factorOA4 = (linsizeOA4 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA4) / maxBlockSize) + 0.01 ) , 1 ); const int blocksizeOA1 = (linsizeOA1 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA1) / factorOA1 ) + 0.01 ) , maxBlockSize ); const int blocksizeOA2 = (linsizeOA2 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA2) / factorOA2 ) + 0.01 ) , maxBlockSize ); const int blocksizeOA3 = (linsizeOA3 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA3) / factorOA3 ) + 0.01 ) , maxBlockSize ); const int blocksizeOA4 = (linsizeOA4 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA4) / factorOA4 ) + 0.01 ) , maxBlockSize ); if (linsizeOA1 > 0){ while (factorOA1 * blocksizeOA1 < linsizeOA1){ factorOA1++; } } if (linsizeOA2 > 0){ while (factorOA2 * blocksizeOA2 < linsizeOA2){ factorOA2++; } } if (linsizeOA3 > 0){ while (factorOA3 * blocksizeOA3 < linsizeOA3){ factorOA3++; } } if (linsizeOA4 > 0){ while (factorOA4 * blocksizeOA4 < linsizeOA4){ factorOA4++; } } //Reset the FourIndex object for (int cnt1=0; cnt1set(irrep1, irrep2, irrep3, irrep4, cnt1, cnt2, cnt3, cnt4, 0.0); } } } } //Loop original blocks for (int origBlock1=0; origBlock1getVmat(i,j,k,l) for the particular ORIGINAL block into mem2_ijkl for (int origIndex1=0; origIndex1getVmat( iHandler->getOrigNOCCstart(irrep1) + origStart1 + origIndex1, iHandler->getOrigNOCCstart(irrep2) + origStart2 + origIndex2, iHandler->getOrigNOCCstart(irrep3) + origStart3 + origIndex3, iHandler->getOrigNOCCstart(irrep4) + origStart4 + origIndex4 ); } } } } //Rotate mem1_ajkl = U_ai mem2_ijkl (but only orig and target block1 indices) { char notra = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int rightdim = origSize2 * origSize3 * origSize4; int leftdim = targetSize1; int middledim = origSize1; double * rotationBlock = unitary->getBlock(irrep1) + targetStart1 + linsize1 * origStart1; // --> lda = linsize1; int lda = linsize1; dgemm_(¬ra,¬ra,&leftdim,&rightdim,&middledim, &alpha,rotationBlock,&lda,mem2,&middledim, &beta,mem1,&leftdim); } //Loop the target block 2 int startTB2 = (irrep1==irrep2) ? targetBlock1 : 0; int stopTB2 = factorOA2 + factorV2; if (cutCorners){ //case A: First index was forced to OA. Second one can be both OA and V //case B: First index can be OA and V. If the first one is V, the second one must be V as well. if ((caseB) && (!block1_OA)){ startTB2 = max( startTB2 , factorOA2 ); } //case C: First index can be OA and V. If the first index is V, the second one must be OA. if ((caseC) && (!block1_OA)){ stopTB2 = factorOA2; } //case D: At most two indices can be virtual: no restrictions yet. } for (int targetBlock2 = startTB2; targetBlock2 < stopTB2; targetBlock2++){ const bool block2_OA = (targetBlock2 < factorOA2) ? true : false; const int targetStart2 = (block2_OA) ? (targetBlock2 * blocksizeOA2) : (linsizeOA2 + (targetBlock2 - factorOA2) * blocksizeV2); const int targetStop2 = (block2_OA) ? min( targetStart2 + blocksizeOA2 , linsizeOA2 ) : min( targetStart2 + blocksizeV2 , linsize2 ); const int targetSize2 = max( targetStop2 - targetStart2 , 0 ); //Rotate mem2_abkl = U_bj mem1_ajkl (only block2 indices) { char trans = 'T'; char notra = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int loop = origSize3 * origSize4; int jump_mem1 = targetSize1*origSize2; int jump_mem2 = targetSize1*targetSize2; int rightdim = targetSize2; int leftdim = targetSize1; int middledim = origSize2; double * rotationBlock = unitary->getBlock(irrep2) + targetStart2 + linsize2 * origStart2; // --> lda = linsize2; int ldb = linsize2; for (int cntloop=0; cntloop second one V as well. Third must be OA, but imposed by first if statement above. // First index OA --> (2,3) can be (OA,OA); (OA,V); (V,OA) and (V,V) --> no restrictions. if (caseC){ if (!block1_OA){ startTB3 = max( startTB3 , factorOA3 ); } // First index V --> (2,3) must be (OA,V) if ((block1_OA) && (!block2_OA)){ stopTB3 = factorOA3; } // First index OA --> if index2 is V, the index3 must be OA. } } for (int targetBlock3 = startTB3; targetBlock3 < stopTB3; targetBlock3++){ const bool block3_OA = (targetBlock3 < factorOA3) ? true : false; const int targetStart3 = (block3_OA) ? (targetBlock3 * blocksizeOA3) : (linsizeOA3 + (targetBlock3 - factorOA3) * blocksizeV3); const int targetStop3 = (block3_OA) ? min( targetStart3 + blocksizeOA3 , linsizeOA3 ) : min( targetStart3 + blocksizeV3 , linsize3 ); const int targetSize3 = max( targetStop3 - targetStart3 , 0 ); //Rotate mem3_abcl = U_ck mem2_abkl (only block3 indices) { char trans = 'T'; char notra = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int loop = origSize4; int jump_mem2 = targetSize1*targetSize2*origSize3; int jump_mem3 = targetSize1*targetSize2*targetSize3; int rightdim = targetSize3; int leftdim = targetSize1*targetSize2; int middledim = origSize3; double * rotationBlock = unitary->getBlock(irrep3) + targetStart3 + linsize3 * origStart3; // --> lda = linsize3; int ldb = linsize3; for (int cntloop=0; cntloopgetOrigNOCCstart(irrep1) + targetStart1 + targetIndex1; const int hamIndex2 = iHandler->getOrigNOCCstart(irrep2) + targetStart2 + targetIndex2; const int hamIndex3 = iHandler->getOrigNOCCstart(irrep3) + targetStart3 + targetIndex3; //Only once per unique matrix element, does the relevant term need to be added if ((hamIndex1 <= hamIndex2) && (hamIndex1 <= hamIndex3)){ //Loop the target INDEX 4 int startTI4 = (irrep2==irrep4) ? targetStart2 + targetIndex2 : 0; //hamIndex2 <= hamIndex4 int stopTI4 = linsizeOA4 + linsizeV4; if (cutCorners){ //Get the number of virtuals int numV = 0; if (!block1_OA){ numV++; } if (!block2_OA){ numV++; } if (!block3_OA){ numV++; } //All cases: max two virtuals if (numV>=2){ stopTI4 = linsizeOA4; } //case A: With (1,2,3)=(OA,OA,OA) index4 can be both OA and V // With (1,2,3)=(OA,OA,V) index4 van be both OA and V // With (1,2,3)=(OA,V,OA) index4 must be V! if ((caseA) && (!block2_OA)){ startTI4 = max( startTI4, linsizeOA4 ); } //case B: For all cases not constrained by numV<=2, index4 can be both OA and V. //case C: For all cases not constrained by numV<=2, index4 can be both OA and V, except if the second index is V if ((caseC) && (!block2_OA)){ startTI4 = max( startTI4, linsizeOA4 ); } } for (int targetIndex4 = startTI4; targetIndex4 < stopTI4; targetIndex4++){ const int hamIndex4 = iHandler->getOrigNOCCstart(irrep4) + targetIndex4; //Only once per unique matrix element, add contribution; hamIndex2 <= hamIndex4 ensured by targetStart4 if ( (hamIndex1 != hamIndex2) || ( (hamIndex1 == hamIndex2) && (hamIndex3 <= hamIndex4) ) ){ double value = 0.0; double * rotatedBlock = unitary->getBlock(irrep4) + linsize4 * origStart4; for (int origIndex4=0; origIndex4add(irrep1, irrep2, irrep3, irrep4, targetStart1 + targetIndex1, targetStart2 + targetIndex2, targetStart3 + targetIndex3, targetIndex4, value); } } } }//End of of last rotation V_partial_abcd = U_dl mem3_abcl } } } } // End of loop original blocks } } } } // End of non-zero irrep block (all linsizes > 0) } } } } } void CheMPS2::DMRGSCFVmatRotations::fillVmatDMRGBlockWise(Hamiltonian * HamDMRG, DMRGSCFunitary * unitary, double * mem1, double * mem2, double * mem3, const int maxBlockSize) const{ /*********************************************************** ** Two-body terms; use eightfold permutation symmetry ** ** Requires 3 buffers of size maxBlockSize^4 ** ** maxBlockSize = ceil(maxlinsize/factor) at alloc ** ***********************************************************/ for (int irrep1 = 0; irrep1=irrep2){ const int linsizeDMRG1 = iHandler->getNDMRG(irrep1); const int linsizeDMRG2 = iHandler->getNDMRG(irrep2); const int linsizeDMRG3 = iHandler->getNDMRG(irrep3); const int linsizeDMRG4 = iHandler->getNDMRG(irrep4); int factorDMRG1 = max( (int) ( ceil((1.0 * linsizeDMRG1) / maxBlockSize) + 0.01 ) , 1 ); //factor >= linsize/maxBlockSize int factorDMRG2 = max( (int) ( ceil((1.0 * linsizeDMRG2) / maxBlockSize) + 0.01 ) , 1 ); int factorDMRG3 = max( (int) ( ceil((1.0 * linsizeDMRG3) / maxBlockSize) + 0.01 ) , 1 ); const int blocksizeDMRG1 = min( (int) ( ceil( (1.0 * linsizeDMRG1) / factorDMRG1 ) + 0.01 ) , maxBlockSize ); //Hence at most maxBlockSize const int blocksizeDMRG2 = min( (int) ( ceil( (1.0 * linsizeDMRG2) / factorDMRG2 ) + 0.01 ) , maxBlockSize ); const int blocksizeDMRG3 = min( (int) ( ceil( (1.0 * linsizeDMRG3) / factorDMRG3 ) + 0.01 ) , maxBlockSize ); while (factorDMRG1 * blocksizeDMRG1 < linsizeDMRG1){ factorDMRG1++; } while (factorDMRG2 * blocksizeDMRG2 < linsizeDMRG2){ factorDMRG2++; } while (factorDMRG3 * blocksizeDMRG3 < linsizeDMRG3){ factorDMRG3++; } if ((linsizeDMRG1>0) && (linsizeDMRG2>0) && (linsizeDMRG3>0) && (linsizeDMRG4>0)){ const int linsizeORIG1 = iHandler->getNORB(irrep1); const int linsizeORIG2 = iHandler->getNORB(irrep2); const int linsizeORIG3 = iHandler->getNORB(irrep3); const int linsizeORIG4 = iHandler->getNORB(irrep4); int factorORIG1 = max( (int) ( ceil((1.0 * linsizeORIG1) / maxBlockSize) + 0.01 ) , 1 ); //factor >= linsize/maxBlockSize int factorORIG2 = max( (int) ( ceil((1.0 * linsizeORIG2) / maxBlockSize) + 0.01 ) , 1 ); int factorORIG3 = max( (int) ( ceil((1.0 * linsizeORIG3) / maxBlockSize) + 0.01 ) , 1 ); int factorORIG4 = max( (int) ( ceil((1.0 * linsizeORIG4) / maxBlockSize) + 0.01 ) , 1 ); const int blocksizeORIG1 = min( (int) ( ceil( (1.0 * linsizeORIG1) / factorORIG1 ) + 0.01 ) , maxBlockSize ); //Hence at most maxBlockSize const int blocksizeORIG2 = min( (int) ( ceil( (1.0 * linsizeORIG2) / factorORIG2 ) + 0.01 ) , maxBlockSize ); const int blocksizeORIG3 = min( (int) ( ceil( (1.0 * linsizeORIG3) / factorORIG3 ) + 0.01 ) , maxBlockSize ); const int blocksizeORIG4 = min( (int) ( ceil( (1.0 * linsizeORIG4) / factorORIG4 ) + 0.01 ) , maxBlockSize ); while (factorORIG1 * blocksizeORIG1 < linsizeORIG1){ factorORIG1++; } while (factorORIG2 * blocksizeORIG2 < linsizeORIG2){ factorORIG2++; } while (factorORIG3 * blocksizeORIG3 < linsizeORIG3){ factorORIG3++; } while (factorORIG4 * blocksizeORIG4 < linsizeORIG4){ factorORIG4++; } //Reset the FourIndex object for (int cnt1=0; cnt1setVmat( iHandler->getDMRGcumulative(irrep1) + cnt1, iHandler->getDMRGcumulative(irrep2) + cnt2, iHandler->getDMRGcumulative(irrep3) + cnt3, iHandler->getDMRGcumulative(irrep4) + cnt4, 0.0 ); } } } } //Loop original blocks for (int origBlock1=0; origBlock1getVmat(i,j,k,l) for the particular ORIGINAL block into mem2_ijkl for (int origIndex1=0; origIndex1getVmat( iHandler->getOrigNOCCstart(irrep1) + origStart1 + origIndex1, iHandler->getOrigNOCCstart(irrep2) + origStart2 + origIndex2, iHandler->getOrigNOCCstart(irrep3) + origStart3 + origIndex3, iHandler->getOrigNOCCstart(irrep4) + origStart4 + origIndex4 ); } } } } //Rotate mem1_ajkl = U_ai mem2_ijkl (but only orig and target block1 indices) { char notra = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int rightdim = origSize2 * origSize3 * origSize4; int leftdim = dmrgSize1; int middledim = origSize1; double * rotationBlock = unitary->getBlock(irrep1) + iHandler->getNOCC(irrep1) + dmrgStart1 + linsizeORIG1 * origStart1; int lda = linsizeORIG1; dgemm_(¬ra,¬ra,&leftdim,&rightdim,&middledim, &alpha,rotationBlock,&lda,mem2,&middledim, &beta,mem1,&leftdim); } //Loop the target block 2 for (int dmrgBlock2=((irrep1==irrep2)?dmrgBlock1:0); dmrgBlock2getBlock(irrep2) + iHandler->getNOCC(irrep2) + dmrgStart2 + linsizeORIG2 * origStart2; int ldb = linsizeORIG2; for (int cntloop=0; cntloopgetBlock(irrep3) + iHandler->getNOCC(irrep3) + dmrgStart3 + linsizeORIG3 * origStart3; int ldb = linsizeORIG3; for (int cntloop=0; cntloopgetDMRGcumulative(irrep1) + dmrgStart1 + dmrgIndex1; const int hamIndex2 = iHandler->getDMRGcumulative(irrep2) + dmrgStart2 + dmrgIndex2; const int hamIndex3 = iHandler->getDMRGcumulative(irrep3) + dmrgStart3 + dmrgIndex3; //Only once per unique matrix element, does the relevant term need to be added if ((hamIndex1 <= hamIndex2) && (hamIndex1 <= hamIndex3)){ int dmrgStart4 = (irrep2==irrep4) ? dmrgStart2 + dmrgIndex2 : 0; //hamIndex2 <= hamIndex4 for (int dmrgIndex4=dmrgStart4; dmrgIndex4getDMRGcumulative(irrep4) + dmrgIndex4; //Only once per unique matrix element, add contribution; hamIndex2 <= hamIndex4 ensured by targetStart4 if ( (hamIndex1 != hamIndex2) || ( (hamIndex1 == hamIndex2) && (hamIndex3 <= hamIndex4) ) ){ double value = 0.0; double * rotatedBlock = unitary->getBlock(irrep4) + iHandler->getNOCC(irrep4) + linsizeORIG4 * origStart4; for (int origIndex4=0; origIndex4addToVmat( hamIndex1, hamIndex2, hamIndex3, hamIndex4, value ); } } } }//End of of last rotation V_partial_abcd = U_dl mem3_abcl } } } } // End of loop original blocks } } } } // End of non-zero irrep block (all linsizes > 0) } } } } } void CheMPS2::DMRGSCFVmatRotations::fillRotatedTEIBlockWise(DMRGSCFintegrals * theRotatedTEI, DMRGSCFunitary * unitary, double * mem1, double * mem2, double * mem3, const int maxBlockSize) const{ // First do Coulomb object : ( c1 <= c2 | a3 <= a4 ) for (int Ic1 = 0; Ic1 < numberOfIrreps; Ic1++){ for (int Ic2 = Ic1; Ic2 < numberOfIrreps; Ic2++){ const int Icc = Irreps::directProd( Ic1, Ic2 ); for (int Ia3 = 0; Ia3 < numberOfIrreps; Ia3++){ const int Ia4 = Irreps::directProd( Ia3, Icc ); if ( Ia3 <= Ia4 ){ int linsize1 = iHandler->getNORB( Ic1 ); int linsize2 = iHandler->getNORB( Ic2 ); int linsize3 = iHandler->getNORB( Ia3 ); int linsize4 = iHandler->getNORB( Ia4 ); int linsizeOA1 = iHandler->getNOCC( Ic1 ) + iHandler->getNDMRG( Ic1 ); int linsizeOA2 = iHandler->getNOCC( Ic2 ) + iHandler->getNDMRG( Ic2 ); if (( linsizeOA1 > 0 ) && ( linsizeOA2 > 0 ) && ( linsize3 > 0 ) && ( linsize4 > 0 )){ int factor1 = max( (int) ( ceil((1.0 * linsize1) / maxBlockSize) + 0.01 ) , 1 ); //factor >= linsize/maxBlockSize int factor2 = max( (int) ( ceil((1.0 * linsize2) / maxBlockSize) + 0.01 ) , 1 ); int factor3 = max( (int) ( ceil((1.0 * linsize3) / maxBlockSize) + 0.01 ) , 1 ); int factor4 = max( (int) ( ceil((1.0 * linsize4) / maxBlockSize) + 0.01 ) , 1 ); const int blocksize1 = min( (int) ( ceil( (1.0 * linsize1) / factor1 ) + 0.01 ) , maxBlockSize ); //Hence at most maxBlockSize const int blocksize2 = min( (int) ( ceil( (1.0 * linsize2) / factor2 ) + 0.01 ) , maxBlockSize ); const int blocksize3 = min( (int) ( ceil( (1.0 * linsize3) / factor3 ) + 0.01 ) , maxBlockSize ); const int blocksize4 = min( (int) ( ceil( (1.0 * linsize4) / factor4 ) + 0.01 ) , maxBlockSize ); while (factor1 * blocksize1 < linsize1){ factor1++; } while (factor2 * blocksize2 < linsize2){ factor2++; } while (factor3 * blocksize3 < linsize3){ factor3++; } while (factor4 * blocksize4 < linsize4){ factor4++; } int factorOA1 = (linsizeOA1 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA1) / maxBlockSize) + 0.01 ) , 1 ); int factorOA2 = (linsizeOA2 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA2) / maxBlockSize) + 0.01 ) , 1 ); const int blocksizeOA1 = (linsizeOA1 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA1) / factorOA1 ) + 0.01 ) , maxBlockSize ); const int blocksizeOA2 = (linsizeOA2 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA2) / factorOA2 ) + 0.01 ) , maxBlockSize ); if (linsizeOA1 > 0){ while (factorOA1 * blocksizeOA1 < linsizeOA1){ factorOA1++; } } if (linsizeOA2 > 0){ while (factorOA2 * blocksizeOA2 < linsizeOA2){ factorOA2++; } } //Clear the Coulomb object for (int c1 = 0; c1 < linsizeOA1; c1++){ for (int c2 = 0; c2 < linsizeOA2; c2++){ for (int a3 = 0; a3 < linsize3; a3++){ for (int a4 = 0; a4 < linsize4; a4++){ theRotatedTEI->set_coulomb( Ic1, Ic2, Ia3, Ia4, c1, c2, a3, a4, 0.0 ); } } } } //Loop original blocks for (int origBlock1 = 0; origBlock1 < factor1; origBlock1++){ const int origStart1 = origBlock1 * blocksize1; const int origStop1 = min( (origBlock1 + 1) * blocksize1 , linsize1 ); const int origSize1 = max( origStop1 - origStart1 , 0 ); for (int origBlock2 = 0; origBlock2 < factor2; origBlock2++){ const int origStart2 = origBlock2 * blocksize2; const int origStop2 = min( (origBlock2 + 1) * blocksize2 , linsize2 ); const int origSize2 = max( origStop2 - origStart2 , 0 ); for (int origBlock3 = 0; origBlock3 < factor3; origBlock3++){ const int origStart3 = origBlock3 * blocksize3; const int origStop3 = min( (origBlock3 + 1) * blocksize3 , linsize3 ); const int origSize3 = max( origStop3 - origStart3 , 0 ); for (int origBlock4 = 0; origBlock4 < factor4; origBlock4++){ const int origStart4 = origBlock4 * blocksize4; const int origStop4 = min( (origBlock4 + 1) * blocksize4 , linsize4 ); const int origSize4 = max( origStop4 - origStart4 , 0 ); //Loop target blocks for (int targetBlock1 = 0; targetBlock1 < factorOA1; targetBlock1++){ const int targetStart1 = targetBlock1 * blocksizeOA1; const int targetStop1 = min( (targetBlock1 + 1) * blocksizeOA1 , linsizeOA1 ); const int targetSize1 = max( targetStop1 - targetStart1 , 0 ); //Copy HamOrig->getVmat(c1,a3,c2,a4) for the particular ORIGINAL block into mem2[c1,c2,a3,a4] for (int origIndex1 = 0; origIndex1 < origSize1; origIndex1++){ for (int origIndex2 = 0; origIndex2 < origSize2; origIndex2++){ for (int origIndex3 = 0; origIndex3 < origSize3; origIndex3++){ for (int origIndex4 = 0; origIndex4 < origSize4; origIndex4++){ mem2[ origIndex1 + origSize1 * (origIndex2 + origSize2 * (origIndex3 + origSize3 * origIndex4) ) ] = HamOrig->getVmat( iHandler->getOrigNOCCstart( Ic1 ) + origStart1 + origIndex1, iHandler->getOrigNOCCstart( Ia3 ) + origStart3 + origIndex3, iHandler->getOrigNOCCstart( Ic2 ) + origStart2 + origIndex2, iHandler->getOrigNOCCstart( Ia4 ) + origStart4 + origIndex4 ); } } } } //Rotate mem1[ c1, j, k, l ] = U[ c1, i ] * mem2[ i, j, k, l ] { char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int rightdim = origSize2 * origSize3 * origSize4; int leftdim = targetSize1; int middledim = origSize1; double * rotationBlock = unitary->getBlock( Ic1 ) + targetStart1 + linsize1 * origStart1; // --> lda = linsize1; int lda = linsize1; dgemm_(¬rans, ¬rans ,&leftdim, &rightdim, &middledim, &alpha, rotationBlock, &lda, mem2, &middledim, &beta, mem1, &leftdim); } //Loop target block 2 for (int targetBlock2 = (( Icc==0 ) ? targetBlock1 : 0); targetBlock2 < factorOA2; targetBlock2++){ const int targetStart2 = targetBlock2 * blocksizeOA2; const int targetStop2 = min( (targetBlock2 + 1) * blocksizeOA2 , linsizeOA2 ); const int targetSize2 = max( targetStop2 - targetStart2 , 0 ); //Rotate mem2[ c1, c2, k, l ] = U[ c2, j ] * mem1[ c1, j, k, l ] { char trans = 'T'; char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int loopsize = origSize3 * origSize4; int jump_mem1 = targetSize1 * origSize2; int jump_mem2 = targetSize1 * targetSize2; int rightdim = targetSize2; int leftdim = targetSize1; int middledim = origSize2; double * rotationBlock = unitary->getBlock( Ic2 ) + targetStart2 + linsize2 * origStart2; // --> ldb = linsize2; int ldb = linsize2; for (int cntloop = 0; cntloop < loopsize; cntloop++){ dgemm_(¬rans, &trans, &leftdim, &rightdim, &middledim, &alpha, mem1 + cntloop * jump_mem1, &leftdim, rotationBlock, &ldb, &beta, mem2 + cntloop * jump_mem2, &leftdim); } } //Loop target block 3 for (int targetBlock3 = 0; targetBlock3 < factor3; targetBlock3++){ const int targetStart3 = targetBlock3 * blocksize3; const int targetStop3 = min( (targetBlock3 + 1) * blocksize3 , linsize3 ); const int targetSize3 = max( targetStop3 - targetStart3 , 0 ); //Rotate mem3[ c1, c2, a3, l ] = U[ a3, k ] * mem2[ c1, c2, l, l ] { char trans = 'T'; char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int jump_mem2 = targetSize1 * targetSize2 * origSize3; int jump_mem3 = targetSize1 * targetSize2 * targetSize3; int rightdim = targetSize3; int leftdim = targetSize1 * targetSize2; int middledim = origSize3; double * rotationBlock = unitary->getBlock( Ia3 ) + targetStart3 + linsize3 * origStart3; // --> ldb = linsize3; int ldb = linsize3; for (int cntloop = 0; cntloop < origSize4; cntloop++){ dgemm_(¬rans, &trans, &leftdim, &rightdim, &middledim, &alpha, mem2 + cntloop * jump_mem2, &leftdim, rotationBlock, &ldb, &beta, mem3 + cntloop * jump_mem3, &leftdim); } } //Calculate ( c1 c2 | a3 a4 )_partial and add to the relevant parts of the Coulomb object const int loopsize = targetSize1 * targetSize2 * targetSize3; #pragma omp parallel for schedule(static) for (int counter = 0; counter < loopsize; counter++){ const int c1_rel = counter % targetSize1; int temp = ( counter - c1_rel ) / targetSize1; const int c2_rel = temp % targetSize2; const int a3_rel = ( temp - c2_rel ) / targetSize2; const int c1 = c1_rel + targetStart1; const int c2 = c2_rel + targetStart2; const int a3 = a3_rel + targetStart3; int a4start = 0; const int a4stop = linsize4; // If Icc==0 --> be careful that ( c1 <= c2 | a3 <= a4 ) valid // If Icc!=0 --> automatically OK because Ic1 < Ic2 and Ia3 < Ia4 checked at beginning if ( Icc == 0 ){ a4start = (( c1 <= c2 ) ? a3 : a4stop); } for (int a4 = a4start; a4 < a4stop; a4++){ double value = 0.0; double * rotatedBlock = unitary->getBlock( Ia4 ) + linsize4 * origStart4; for (int origIndex4 = 0; origIndex4 < origSize4; origIndex4++){ value += mem3[counter + loopsize * origIndex4] * rotatedBlock[a4 + linsize4 * origIndex4]; } theRotatedTEI->add_coulomb( Ic1, Ic2, Ia3, Ia4, c1, c2, a3, a4, value ); } } } } }//targetBlock1 } } } }//origBlock1 } } } } } // Then do Exchange object : ( c1 v3 | c2 v4 ) for (int Ic1 = 0; Ic1 < numberOfIrreps; Ic1++){ for (int Ic2 = Ic1; Ic2 < numberOfIrreps; Ic2++){ const int Icc = Irreps::directProd( Ic1, Ic2 ); for (int Iv3 = 0; Iv3 < numberOfIrreps; Iv3++){ const int Iv4 = Irreps::directProd( Iv3, Icc ); //No restriction on Iv4, only Ic1 <= Ic2 int linsize1 = iHandler->getNORB( Ic1 ); int linsize2 = iHandler->getNORB( Ic2 ); int linsize3 = iHandler->getNORB( Iv3 ); int linsize4 = iHandler->getNORB( Iv4 ); int linsizeOA1 = iHandler->getNOCC( Ic1 ) + iHandler->getNDMRG( Ic1 ); int linsizeOA2 = iHandler->getNOCC( Ic2 ) + iHandler->getNDMRG( Ic2 ); int linsizeV3 = iHandler->getNVIRT( Iv3 ); int linsizeV4 = iHandler->getNVIRT( Iv4 ); const int shiftv3 = iHandler->getNOCC( Iv3 ) + iHandler->getNDMRG( Iv3 ); const int shiftv4 = iHandler->getNOCC( Iv4 ) + iHandler->getNDMRG( Iv4 ); if (( linsizeOA1 > 0 ) && ( linsizeOA2 > 0 ) && ( linsizeV3 > 0 ) && ( linsizeV4 > 0 )){ int factor1 = max( (int) ( ceil((1.0 * linsize1) / maxBlockSize) + 0.01 ) , 1 ); //factor >= linsize/maxBlockSize int factor2 = max( (int) ( ceil((1.0 * linsize2) / maxBlockSize) + 0.01 ) , 1 ); int factor3 = max( (int) ( ceil((1.0 * linsize3) / maxBlockSize) + 0.01 ) , 1 ); int factor4 = max( (int) ( ceil((1.0 * linsize4) / maxBlockSize) + 0.01 ) , 1 ); const int blocksize1 = min( (int) ( ceil( (1.0 * linsize1) / factor1 ) + 0.01 ) , maxBlockSize ); //Hence at most maxBlockSize const int blocksize2 = min( (int) ( ceil( (1.0 * linsize2) / factor2 ) + 0.01 ) , maxBlockSize ); const int blocksize3 = min( (int) ( ceil( (1.0 * linsize3) / factor3 ) + 0.01 ) , maxBlockSize ); const int blocksize4 = min( (int) ( ceil( (1.0 * linsize4) / factor4 ) + 0.01 ) , maxBlockSize ); while (factor1 * blocksize1 < linsize1){ factor1++; } while (factor2 * blocksize2 < linsize2){ factor2++; } while (factor3 * blocksize3 < linsize3){ factor3++; } while (factor4 * blocksize4 < linsize4){ factor4++; } int factorOA1 = (linsizeOA1 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA1) / maxBlockSize) + 0.01 ) , 1 ); int factorOA2 = (linsizeOA2 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeOA2) / maxBlockSize) + 0.01 ) , 1 ); int factorV3 = (linsizeV3 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeV3 ) / maxBlockSize) + 0.01 ) , 1 ); int factorV4 = (linsizeV4 == 0) ? 0 : max( (int) ( ceil((1.0 * linsizeV4 ) / maxBlockSize) + 0.01 ) , 1 ); const int blocksizeOA1 = (linsizeOA1 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA1) / factorOA1 ) + 0.01 ) , maxBlockSize ); const int blocksizeOA2 = (linsizeOA2 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeOA2) / factorOA2 ) + 0.01 ) , maxBlockSize ); const int blocksizeV3 = (linsizeV3 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeV3 ) / factorV3 ) + 0.01 ) , maxBlockSize ); const int blocksizeV4 = (linsizeV4 == 0) ? 1 : min( (int) ( ceil( (1.0 * linsizeV4 ) / factorV4 ) + 0.01 ) , maxBlockSize ); if (linsizeOA1 > 0){ while (factorOA1 * blocksizeOA1 < linsizeOA1){ factorOA1++; } } if (linsizeOA2 > 0){ while (factorOA2 * blocksizeOA2 < linsizeOA2){ factorOA2++; } } if (linsizeV3 > 0){ while (factorV3 * blocksizeV3 < linsizeV3 ){ factorV3++; } } if (linsizeV4 > 0){ while (factorV4 * blocksizeV4 < linsizeV4 ){ factorV4++; } } //Clear the Exchange object for (int c1 = 0; c1 < linsizeOA1; c1++){ for (int c2 = 0; c2 < linsizeOA2; c2++){ for (int v3 = 0; v3 < linsizeV3; v3++){ for (int v4 = 0; v4 < linsizeV4; v4++){ theRotatedTEI->set_exchange( Ic1, Ic2, Iv3, Iv4, c1, c2, shiftv3 + v3, shiftv4 + v4, 0.0 ); } } } } //Loop original blocks for (int origBlock1 = 0; origBlock1 < factor1; origBlock1++){ const int origStart1 = origBlock1 * blocksize1; const int origStop1 = min( (origBlock1 + 1) * blocksize1 , linsize1 ); const int origSize1 = max( origStop1 - origStart1 , 0 ); for (int origBlock2 = 0; origBlock2 < factor2; origBlock2++){ const int origStart2 = origBlock2 * blocksize2; const int origStop2 = min( (origBlock2 + 1) * blocksize2 , linsize2 ); const int origSize2 = max( origStop2 - origStart2 , 0 ); for (int origBlock3 = 0; origBlock3 < factor3; origBlock3++){ const int origStart3 = origBlock3 * blocksize3; const int origStop3 = min( (origBlock3 + 1) * blocksize3 , linsize3 ); const int origSize3 = max( origStop3 - origStart3 , 0 ); for (int origBlock4 = 0; origBlock4 < factor4; origBlock4++){ const int origStart4 = origBlock4 * blocksize4; const int origStop4 = min( (origBlock4 + 1) * blocksize4 , linsize4 ); const int origSize4 = max( origStop4 - origStart4 , 0 ); //Loop target blocks for (int targetBlock1 = 0; targetBlock1 < factorOA1; targetBlock1++){ const int targetStart1 = targetBlock1 * blocksizeOA1; const int targetStop1 = min( (targetBlock1 + 1) * blocksizeOA1 , linsizeOA1 ); const int targetSize1 = max( targetStop1 - targetStart1 , 0 ); //Copy HamOrig->getVmat(c1,c2,v3,v4) for the particular ORIGINAL block into mem2[c1,c2,v3,v4] for (int origIndex1 = 0; origIndex1 < origSize1; origIndex1++){ for (int origIndex2 = 0; origIndex2 < origSize2; origIndex2++){ for (int origIndex3 = 0; origIndex3 < origSize3; origIndex3++){ for (int origIndex4 = 0; origIndex4 < origSize4; origIndex4++){ mem2[ origIndex1 + origSize1 * (origIndex2 + origSize2 * (origIndex3 + origSize3 * origIndex4) ) ] = HamOrig->getVmat( iHandler->getOrigNOCCstart( Ic1 ) + origStart1 + origIndex1, iHandler->getOrigNOCCstart( Ic2 ) + origStart2 + origIndex2, iHandler->getOrigNOCCstart( Iv3 ) + origStart3 + origIndex3, iHandler->getOrigNOCCstart( Iv4 ) + origStart4 + origIndex4 ); } } } } //Rotate mem1[ c1, j, k, l ] = U[ c1, i ] * mem2[ i, j, k, l ] { char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int rightdim = origSize2 * origSize3 * origSize4; int leftdim = targetSize1; int middledim = origSize1; double * rotationBlock = unitary->getBlock( Ic1 ) + targetStart1 + linsize1 * origStart1; // --> lda = linsize1; int lda = linsize1; dgemm_(¬rans, ¬rans ,&leftdim, &rightdim, &middledim, &alpha, rotationBlock, &lda, mem2, &middledim, &beta, mem1, &leftdim); } //Loop target block 2 for (int targetBlock2 = (( Icc==0 ) ? targetBlock1 : 0); targetBlock2 < factorOA2; targetBlock2++){ const int targetStart2 = targetBlock2 * blocksizeOA2; const int targetStop2 = min( (targetBlock2 + 1) * blocksizeOA2 , linsizeOA2 ); const int targetSize2 = max( targetStop2 - targetStart2 , 0 ); //Rotate mem2[ c1, c2, k, l ] = U[ c2, j ] * mem1[ c1, j, k, l ] { char trans = 'T'; char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int loopsize = origSize3 * origSize4; int jump_mem1 = targetSize1 * origSize2; int jump_mem2 = targetSize1 * targetSize2; int rightdim = targetSize2; int leftdim = targetSize1; int middledim = origSize2; double * rotationBlock = unitary->getBlock( Ic2 ) + targetStart2 + linsize2 * origStart2; // --> ldb = linsize2; int ldb = linsize2; for (int cntloop = 0; cntloop < loopsize; cntloop++){ dgemm_(¬rans, &trans, &leftdim, &rightdim, &middledim, &alpha, mem1 + cntloop * jump_mem1, &leftdim, rotationBlock, &ldb, &beta, mem2 + cntloop * jump_mem2, &leftdim); } } //Loop target block 3 for (int targetBlock3 = 0; targetBlock3 < factorV3; targetBlock3++){ const int targetStart3 = shiftv3 + targetBlock3 * blocksizeV3; const int targetStop3 = shiftv3 + min( (targetBlock3 + 1) * blocksizeV3 , linsizeV3 ); const int targetSize3 = max( targetStop3 - targetStart3 , 0 ); //Rotate mem3[ c1, c2, v3, l ] = U[ v3, k ] * mem2[ c1, c2, l, l ] { char trans = 'T'; char notrans = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! int jump_mem2 = targetSize1 * targetSize2 * origSize3; int jump_mem3 = targetSize1 * targetSize2 * targetSize3; int rightdim = targetSize3; int leftdim = targetSize1 * targetSize2; int middledim = origSize3; double * rotationBlock = unitary->getBlock( Iv3 ) + targetStart3 + linsize3 * origStart3; // --> ldb = linsize3; int ldb = linsize3; for (int cntloop = 0; cntloop < origSize4; cntloop++){ dgemm_(¬rans, &trans, &leftdim, &rightdim, &middledim, &alpha, mem2 + cntloop * jump_mem2, &leftdim, rotationBlock, &ldb, &beta, mem3 + cntloop * jump_mem3, &leftdim); } } //Calculate ( c1 c2 | v3 v4 )_partial and add to the relevant parts of the Exchange object const int loopsize = targetSize1 * targetSize2 * targetSize3; #pragma omp parallel for schedule(static) for (int counter = 0; counter < loopsize; counter++){ const int c1_rel = counter % targetSize1; int temp = ( counter - c1_rel ) / targetSize1; const int c2_rel = temp % targetSize2; const int v3_rel = ( temp - c2_rel ) / targetSize2; const int c1 = c1_rel + targetStart1; const int c2 = c2_rel + targetStart2; const int v3 = v3_rel + targetStart3; int v4start = shiftv4; const int v4stop = linsize4; // If Icc==0 --> be careful that c1 <= c2 is valid // If Icc!=0 --> automatically OK because Ic1 < Ic2 if (( Icc == 0 ) && ( c1 > c2 )){ v4start = v4stop; } for (int v4 = v4start; v4 < v4stop; v4++){ double value = 0.0; double * rotatedBlock = unitary->getBlock( Iv4 ) + linsize4 * origStart4; for (int origIndex4 = 0; origIndex4 < origSize4; origIndex4++){ value += mem3[counter + loopsize * origIndex4] * rotatedBlock[v4 + linsize4 * origIndex4]; } theRotatedTEI->add_exchange( Ic1, Ic2, Iv3, Iv4, c1, c2, v3, v4, value ); } } } } }//targetBlock1 } } } }//origBlock1 } } } } } CheMPS2-1.6/CheMPS2/DMRGSCFindices.cpp000066400000000000000000000106331256744172700170340ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include "DMRGSCFindices.h" using std::cout; using std::endl; CheMPS2::DMRGSCFindices::DMRGSCFindices(const int L, const int Group, int * NOCCin, int * NDMRGin, int * NVIRTin){ this->L = L; this->Group = Group; SymmInfo.setGroup(Group); this->Nirreps = SymmInfo.getNumberOfIrreps(); NORB = new int[Nirreps]; NOCC = new int[Nirreps]; NDMRG = new int[Nirreps]; NVIRT = new int[Nirreps]; NORBcumulative = new int[Nirreps+1]; NDMRGcumulative = new int[Nirreps+1]; int totalNumOrbs = 0; NORBcumulative[0] = 0; NDMRGcumulative[0] = 0; for (int irrep=0; irrep=0 ); assert( NDMRGin[irrep]>=0 ); assert( NVIRTin[irrep]>=0 ); NORB[ irrep] = NOCCin[ irrep] + NDMRGin[irrep] + NVIRTin[irrep]; NOCC[ irrep] = NOCCin[ irrep]; NDMRG[irrep] = NDMRGin[irrep]; NVIRT[irrep] = NVIRTin[irrep]; totalNumOrbs += NORB[irrep]; NORBcumulative[ irrep+1] = NORBcumulative[ irrep] + NORB[irrep]; NDMRGcumulative[irrep+1] = NDMRGcumulative[irrep] + NDMRG[irrep]; } assert( totalNumOrbs==L ); irrepOfEachDMRGorbital = new int[NDMRGcumulative[Nirreps]]; irrepOfEachOrbital = new int[L]; for (int irrep=0; irrep #include "DMRGSCFintegrals.h" CheMPS2::DMRGSCFintegrals::DMRGSCFintegrals(DMRGSCFindices * iHandler){ numberOfIrreps = iHandler->getNirreps(); NCORE = new int[ numberOfIrreps ]; NVIRTUAL = new int[ numberOfIrreps ]; NTOTAL = new int[ numberOfIrreps ]; for (int irrep = 0; irrep < numberOfIrreps; irrep++){ NCORE[ irrep ] = iHandler->getNOCC( irrep ) + iHandler->getNDMRG( irrep ); NVIRTUAL[ irrep ] = iHandler->getNVIRT( irrep ); NTOTAL[ irrep ] = iHandler->getNORB( irrep ); } coulomb_size = calcNumCoulombElements( true ); exchange_size = calcNumExchangeElements( true ); coulomb_array = new double[ coulomb_size ]; exchange_array = new double[ exchange_size ]; } long long CheMPS2::DMRGSCFintegrals::calcNumCoulombElements(const bool allocate){ // The object sizes long long theSize = 0; if (allocate){ coulomb_ptr = new long long***[ numberOfIrreps ]; } for (int I_cc = 0; I_cc < numberOfIrreps; I_cc++){ // Loop the irrep I_cc = I_c1 x I_c2 = I_a1 x I_a2 if (allocate){ coulomb_ptr[ I_cc ] = new long long**[ numberOfIrreps ]; } for (int I_c1 = 0; I_c1 < numberOfIrreps; I_c1++){ const int I_c2 = Irreps::directProd( I_cc , I_c1 ); if ( ( NCORE[ I_c1 ] > 0 ) && ( NCORE[ I_c2 ] > 0 ) && ( I_c1 <= I_c2 ) ){ if (allocate){ coulomb_ptr[ I_cc ][ I_c1 ] = new long long*[ numberOfIrreps ]; } for (int I_a1 = 0; I_a1 < numberOfIrreps; I_a1++){ const int I_a2 = Irreps::directProd( I_cc, I_a1 ); if ( ( NTOTAL[ I_a1 ] > 0 ) && ( NTOTAL[ I_a2 ] > 0 ) && ( I_a1 <= I_a2 ) ){ if ( I_cc == 0 ){ // I_c1 == I_c2 and I_a1 == I_a2 if (allocate){ const long long coretriangle = ( NCORE[ I_c1 ] * ( NCORE[ I_c1 ] + 1 ) ) / 2; const long long alltriangle = ( NTOTAL[ I_a1 ] * ( NTOTAL[ I_a1 ] + 1 ) ) / 2; coulomb_ptr[ I_cc ][ I_c1 ][ I_a1 ] = new long long[ coretriangle ]; for (int combinedcore = 0; combinedcore < coretriangle; combinedcore++){ coulomb_ptr[ I_cc ][ I_c1 ][ I_a1 ][ combinedcore ] = theSize; theSize += alltriangle; } } else { delete [] coulomb_ptr[ I_cc ][ I_c1 ][ I_a1 ]; } } else { // I_c1 < I_c2 and I_a1 < I_a2 if (allocate){ const long long coresquare = NCORE[ I_c1 ] * NCORE[ I_c2 ]; const long long allsquare = NTOTAL[ I_a1 ] * NTOTAL[ I_a2 ]; coulomb_ptr[ I_cc ][ I_c1 ][ I_a1 ] = new long long[ coresquare ]; for (int combinedcore = 0; combinedcore < coresquare; combinedcore++){ coulomb_ptr[ I_cc ][ I_c1 ][ I_a1 ][ combinedcore ] = theSize; theSize += allsquare; } } else { delete [] coulomb_ptr[ I_cc ][ I_c1 ][ I_a1 ]; } } } } if (!allocate){ delete [] coulomb_ptr[ I_cc ][ I_c1 ]; } } } if (!allocate){ delete [] coulomb_ptr[ I_cc ]; } } if (!allocate){ delete [] coulomb_ptr; } return theSize; } long long CheMPS2::DMRGSCFintegrals::calcNumExchangeElements(const bool allocate){ // The object sizes long long theSize = 0; if (allocate){ exchange_ptr = new long long***[ numberOfIrreps ]; } for (int I_cc = 0; I_cc < numberOfIrreps; I_cc++){ // Loop the irrep I_cc = I_c1 x I_c2 = I_v1 x I_v2 if (allocate){ exchange_ptr[ I_cc ] = new long long**[ numberOfIrreps ]; } for (int I_c1 = 0; I_c1 < numberOfIrreps; I_c1++){ const int I_c2 = Irreps::directProd( I_cc , I_c1 ); if ( ( NCORE[ I_c1 ] > 0 ) && ( NCORE[ I_c2 ] > 0 ) && ( I_c1 <= I_c2 ) ){ if (allocate){ exchange_ptr[ I_cc ][ I_c1 ] = new long long*[ numberOfIrreps ]; } for (int I_v1 = 0; I_v1 < numberOfIrreps; I_v1++){ const int I_v2 = Irreps::directProd( I_cc, I_v1 ); if ( ( NTOTAL[ I_v1 ] > 0 ) && ( NTOTAL[ I_v2 ] > 0 ) ){ // Here no I_v1 <= I_v2 !! const long long virtualsquare = NVIRTUAL[ I_v1 ] * NVIRTUAL[ I_v2 ]; if ( I_cc == 0 ){ // I_c1 == I_c2 and I_v1 == I_v2 if (allocate){ const long long coretriangle = ( NCORE[ I_c1 ] * ( NCORE[ I_c1 ] + 1 ) ) / 2; exchange_ptr[ I_cc ][ I_c1 ][ I_v1 ] = new long long[ coretriangle ]; for (int combinedcore = 0; combinedcore < coretriangle; combinedcore++){ exchange_ptr[ I_cc ][ I_c1 ][ I_v1 ][ combinedcore ] = theSize; theSize += virtualsquare; } } else { delete [] exchange_ptr[ I_cc ][ I_c1 ][ I_v1 ]; } } else { // I_c1 < I_c2 and I_v1 != I_v2 if (allocate){ const long long coresquare = NCORE[ I_c1 ] * NCORE[ I_c2 ]; exchange_ptr[ I_cc ][ I_c1 ][ I_v1 ] = new long long[ coresquare ]; for (int combinedcore = 0; combinedcore < coresquare; combinedcore++){ exchange_ptr[ I_cc ][ I_c1 ][ I_v1 ][ combinedcore ] = theSize; theSize += virtualsquare; } } else { delete [] exchange_ptr[ I_cc ][ I_c1 ][ I_v1 ]; } } } } if (!allocate){ delete [] exchange_ptr[ I_cc ][ I_c1 ]; } } } if (!allocate){ delete [] exchange_ptr[ I_cc ]; } } if (!allocate){ delete [] exchange_ptr; } return theSize; } CheMPS2::DMRGSCFintegrals::~DMRGSCFintegrals(){ delete [] coulomb_array; delete [] exchange_array; calcNumCoulombElements( false ); calcNumExchangeElements( false ); delete [] NCORE; delete [] NVIRTUAL; delete [] NTOTAL; } void CheMPS2::DMRGSCFintegrals::clear(){ for (long long counter = 0; counter < coulomb_size; counter++){ coulomb_array[ counter ] = 0.0; } for (long long counter = 0; counter < exchange_size; counter++){ exchange_array[ counter ] = 0.0; } } long long CheMPS2::DMRGSCFintegrals::get_coulomb_ptr( const int Ic1, const int Ic2, const int Ia1, const int Ia2, const int c1, const int c2, const int a1, const int a2 ) const{ const int Icc = Irreps::directProd( Ic1, Ic2 ); assert( Icc == Irreps::directProd( Ia1, Ia2 ) ); if ( Icc == 0 ){ // Ic1 == Ic2 and Ia1 == Ia2 const int index_c = ( c1 <= c2 ) ? c1 + (c2 * ( c2 + 1 ))/2 : c2 + (c1 * ( c1 + 1 ))/2 ; const int index_a = ( a1 <= a2 ) ? a1 + (a2 * ( a2 + 1 ))/2 : a2 + (a1 * ( a1 + 1 ))/2 ; return coulomb_ptr[ Icc ][ Ic1 ][ Ia1 ][ index_c ] + index_a ; } // Ic1 != Ic2 and Ia1 != Ia2 const int irrep_c = ( Ic1 < Ic2 ) ? Ic1 : Ic2 ; const int irrep_a = ( Ia1 < Ia2 ) ? Ia1 : Ia2 ; const int index_c = ( Ic1 < Ic2 ) ? c1 + NCORE[ Ic1 ] * c2 : c2 + NCORE[ Ic2 ] * c1 ; const int index_a = ( Ia1 < Ia2 ) ? a1 + NTOTAL[ Ia1 ] * a2 : a2 + NTOTAL[ Ia2 ] * a1 ; return coulomb_ptr[ Icc ][ irrep_c ][ irrep_a ][ index_c ] + index_a ; } void CheMPS2::DMRGSCFintegrals::set_coulomb(const int Ic1, const int Ic2, const int Ia1, const int Ia2, const int c1, const int c2, const int a1, const int a2, const double val){ coulomb_array[ get_coulomb_ptr( Ic1, Ic2, Ia1, Ia2, c1, c2, a1, a2 ) ] = val; } void CheMPS2::DMRGSCFintegrals::add_coulomb(const int Ic1, const int Ic2, const int Ia1, const int Ia2, const int c1, const int c2, const int a1, const int a2, const double val){ coulomb_array[ get_coulomb_ptr( Ic1, Ic2, Ia1, Ia2, c1, c2, a1, a2 ) ] += val; } double CheMPS2::DMRGSCFintegrals::get_coulomb(const int Ic1, const int Ic2, const int Ia1, const int Ia2, const int c1, const int c2, const int a1, const int a2) const{ return coulomb_array[ get_coulomb_ptr( Ic1, Ic2, Ia1, Ia2, c1, c2, a1, a2 ) ]; } long long CheMPS2::DMRGSCFintegrals::get_exchange_ptr( const int Ic1, const int Ic2, const int Iv1, const int Iv2, const int c1, const int c2, const int v1, const int v2 ) const{ const int Icc = Irreps::directProd( Ic1, Ic2 ); assert( Icc == Irreps::directProd( Iv1, Iv2 ) ); if ( Icc == 0 ){ // Ic1 == Ic2 and Iv1 == Iv2 if ( c1 <= c2 ){ return exchange_ptr[ Icc ][ Ic1 ][ Iv1 ][ c1 + (c2 * ( c2 + 1 ))/2 ] + v1 - NCORE[ Iv1 ] + NVIRTUAL[ Iv1 ] * ( v2 - NCORE[ Iv2 ] ) ; } else { return exchange_ptr[ Icc ][ Ic2 ][ Iv2 ][ c2 + (c1 * ( c1 + 1 ))/2 ] + v2 - NCORE[ Iv2 ] + NVIRTUAL[ Iv2 ] * ( v1 - NCORE[ Iv1 ] ) ; } } else { // Ic1 != Ic2 if ( Ic1 < Ic2 ){ return exchange_ptr[ Icc ][ Ic1 ][ Iv1 ][ c1 + NCORE[ Ic1 ] * c2 ] + v1 - NCORE[ Iv1 ] + NVIRTUAL[ Iv1 ] * ( v2 - NCORE[ Iv2 ] ) ; } else { return exchange_ptr[ Icc ][ Ic2 ][ Iv2 ][ c2 + NCORE[ Ic2 ] * c1 ] + v2 - NCORE[ Iv2 ] + NVIRTUAL[ Iv2 ] * ( v1 - NCORE[ Iv1 ] ) ; } } return -1; } void CheMPS2::DMRGSCFintegrals::set_exchange(const int Ic1, const int Ic2, const int Iv1, const int Iv2, const int c1, const int c2, const int v1, const int v2, const double val){ exchange_array[ get_exchange_ptr( Ic1, Ic2, Iv1, Iv2, c1, c2, v1, v2 ) ] = val; } void CheMPS2::DMRGSCFintegrals::add_exchange(const int Ic1, const int Ic2, const int Iv1, const int Iv2, const int c1, const int c2, const int v1, const int v2, const double val){ exchange_array[ get_exchange_ptr( Ic1, Ic2, Iv1, Iv2, c1, c2, v1, v2 ) ] += val; } double CheMPS2::DMRGSCFintegrals::get_exchange(const int Ic1, const int Ic2, const int Iv1, const int Iv2, const int c1, const int c2, const int v1, const int v2) const{ return exchange_array[ get_exchange_ptr( Ic1, Ic2, Iv1, Iv2, c1, c2, v1, v2 ) ]; } double CheMPS2::DMRGSCFintegrals::FourIndexAPI(const int I1, const int I2, const int I3, const int I4, const int index1, const int index2, const int index3, const int index4) const{ assert( Irreps::directProd( I1, I2 ) == Irreps::directProd( I3, I4 ) ); const bool core1 = ( index1 < NCORE[I1] ) ? true : false; const bool core2 = ( index2 < NCORE[I2] ) ? true : false; const bool core3 = ( index3 < NCORE[I3] ) ? true : false; const bool core4 = ( index4 < NCORE[I4] ) ? true : false; const int numCore = ( ( core1 ) ? 1 : 0 ) + ( ( core2 ) ? 1 : 0 ) + ( ( core3 ) ? 1 : 0 ) + ( ( core4 ) ? 1 : 0 ); assert( numCore >= 2 ); if ( numCore == 4 ){ return get_coulomb(I1, I3, I2, I4, index1, index3, index2, index4); } if ( numCore == 3 ){ if (( !core1 ) || ( !core3 )){ return get_coulomb(I2, I4, I1, I3, index2, index4, index1, index3); } if (( !core2 ) || ( !core4 )){ return get_coulomb(I1, I3, I2, I4, index1, index3, index2, index4); } } if ( numCore == 2 ){ if ( !core1 ){ if ( !core2 ){ return get_exchange(I3, I4, I1, I2, index3, index4, index1, index2); } if ( !core3 ){ return get_coulomb( I2, I4, I1, I3, index2, index4, index1, index3); } if ( !core4 ){ return get_exchange(I3, I2, I1, I4, index3, index2, index1, index4); } } if ( !core2 ){ if ( !core3 ){ return get_exchange(I4, I1, I2, I3, index4, index1, index2, index3); } if ( !core4 ){ return get_coulomb( I1, I3, I2, I4, index1, index3, index2, index4); } } return get_exchange(I1, I2, I3, I4, index1, index2, index3, index4); } assert( 0 == 1 ); return 0.0; } CheMPS2-1.6/CheMPS2/DMRGSCFmatrix.cpp000066400000000000000000000040201256744172700167130ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "DMRGSCFmatrix.h" CheMPS2::DMRGSCFmatrix::DMRGSCFmatrix(DMRGSCFindices * iHandler_in){ iHandler = iHandler_in; entries = new double*[ iHandler->getNirreps() ]; for (int irrep = 0; irrep < iHandler->getNirreps(); irrep++){ entries[ irrep ] = new double[ iHandler->getNORB( irrep ) * iHandler->getNORB( irrep ) ]; } } CheMPS2::DMRGSCFmatrix::~DMRGSCFmatrix(){ for (int irrep = 0; irrep < iHandler->getNirreps(); irrep++){ delete [] entries[ irrep ]; } delete [] entries; } void CheMPS2::DMRGSCFmatrix::set(const int irrep, const int p, const int q, const double val){ entries[ irrep ][ p + iHandler->getNORB( irrep ) * q ] = val; } void CheMPS2::DMRGSCFmatrix::clear(){ for (int irrep = 0; irrep < iHandler->getNirreps(); irrep++){ for (int counter = 0; counter < iHandler->getNORB( irrep ) * iHandler->getNORB( irrep ); counter++){ entries[ irrep ][ counter ] = 0.0; } } } double CheMPS2::DMRGSCFmatrix::get(const int irrep, const int p, const int q) const{ return entries[ irrep ][ p + iHandler->getNORB( irrep ) * q ]; } double * CheMPS2::DMRGSCFmatrix::getBlock(const int irrep){ return entries[ irrep ]; } CheMPS2-1.6/CheMPS2/DMRGSCFoptions.cpp000066400000000000000000000111041256744172700171030ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "DMRGSCFoptions.h" CheMPS2::DMRGSCFoptions::DMRGSCFoptions(){ DoDIIS = CheMPS2::DMRGSCF_doDIIS; DIISGradientBranch = CheMPS2::DMRGSCF_DIISgradientBranch; NumDIISVecs = CheMPS2::DMRGSCF_numDIISvecs; StoreDIIS = CheMPS2::DMRGSCF_storeDIIS; DIISStorageName = CheMPS2::DMRGSCF_DIISstorageName; MaxIterations = CheMPS2::DMRGSCF_maxIterations; GradientThreshold = CheMPS2::DMRGSCF_gradientNormThreshold; StoreUnitary = CheMPS2::DMRGSCF_storeUnitary; UnitaryStorageName = CheMPS2::DMRGSCF_unitaryStorageName; StateAveraging = CheMPS2::DMRGSCF_stateAveraged; WhichActiveSpace = CheMPS2::DMRGSCF_whichActiveSpace; DumpCorrelations = CheMPS2::DMRGSCF_dumpCorrelations; StartLocRandom = CheMPS2::DMRGSCF_startLocRandom; } CheMPS2::DMRGSCFoptions::~DMRGSCFoptions(){ } bool CheMPS2::DMRGSCFoptions::getDoDIIS() const{ return DoDIIS; } double CheMPS2::DMRGSCFoptions::getDIISGradientBranch() const{ return DIISGradientBranch; } int CheMPS2::DMRGSCFoptions::getNumDIISVecs() const{ return NumDIISVecs; } bool CheMPS2::DMRGSCFoptions::getStoreDIIS() const{ return StoreDIIS; } string CheMPS2::DMRGSCFoptions::getDIISStorageName() const{ return DIISStorageName; } int CheMPS2::DMRGSCFoptions::getMaxIterations() const{ return MaxIterations; } double CheMPS2::DMRGSCFoptions::getGradientThreshold() const{ return GradientThreshold; } bool CheMPS2::DMRGSCFoptions::getStoreUnitary() const{ return StoreUnitary; } string CheMPS2::DMRGSCFoptions::getUnitaryStorageName() const{ return UnitaryStorageName; } bool CheMPS2::DMRGSCFoptions::getStateAveraging() const{ return StateAveraging; } int CheMPS2::DMRGSCFoptions::getWhichActiveSpace() const{ return WhichActiveSpace; } bool CheMPS2::DMRGSCFoptions::getDumpCorrelations() const{ return DumpCorrelations; } bool CheMPS2::DMRGSCFoptions::getStartLocRandom() const{ return StartLocRandom; } void CheMPS2::DMRGSCFoptions::setDoDIIS(const bool DoDIIS_in){ DoDIIS = DoDIIS_in; } void CheMPS2::DMRGSCFoptions::setDIISGradientBranch(const double DIISGradientBranch_in){ DIISGradientBranch = DIISGradientBranch_in; } void CheMPS2::DMRGSCFoptions::setNumDIISVecs(const int NumDIISVecs_in){ NumDIISVecs = NumDIISVecs_in; } void CheMPS2::DMRGSCFoptions::setStoreDIIS(const bool StoreDIIS_in){ StoreDIIS = StoreDIIS_in; } void CheMPS2::DMRGSCFoptions::setDIISStorageName(const string DIISStorageName_in){ DIISStorageName = DIISStorageName_in; } void CheMPS2::DMRGSCFoptions::setMaxIterations(const int MaxIterations_in){ MaxIterations = MaxIterations_in; } void CheMPS2::DMRGSCFoptions::setGradientThreshold(const double GradientThreshold_in){ GradientThreshold = GradientThreshold_in; } void CheMPS2::DMRGSCFoptions::setStoreUnitary(const bool StoreUnitary_in){ StoreUnitary = StoreUnitary_in; } void CheMPS2::DMRGSCFoptions::setUnitaryStorageName(const string UnitaryStorageName_in){ UnitaryStorageName = UnitaryStorageName_in; } void CheMPS2::DMRGSCFoptions::setStateAveraging(const bool StateAveraging_in){ StateAveraging = StateAveraging_in; } void CheMPS2::DMRGSCFoptions::setWhichActiveSpace(const int WhichActiveSpace_in){ WhichActiveSpace = WhichActiveSpace_in; } void CheMPS2::DMRGSCFoptions::setDumpCorrelations(const bool DumpCorrelations_in){ DumpCorrelations = DumpCorrelations_in; } void CheMPS2::DMRGSCFoptions::setStartLocRandom(const bool StartLocRandom_in){ StartLocRandom = StartLocRandom_in; } CheMPS2-1.6/CheMPS2/DMRGSCFunitary.cpp000066400000000000000000001023471256744172700171150ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include "MyHDF5.h" #include "Lapack.h" #include "DMRGSCFunitary.h" using std::string; using std::ifstream; using std::cout; using std::endl; CheMPS2::DMRGSCFunitary::DMRGSCFunitary(DMRGSCFindices * iHandlerIn){ this->iHandler = iHandlerIn; //Allocate the unitary and set to I unitary = new double*[ iHandler->getNirreps() ]; for (int irrep=0; irrepgetNirreps(); irrep++){ const int linsize = iHandler->getNORB(irrep); const int size = linsize * linsize; unitary[irrep] = new double[size]; for (int cnt=0; cntgetNirreps(); irrep++){ x_linearlength += iHandler->getNOCC(irrep)*iHandler->getNDMRG(irrep) + iHandler->getNDMRG(irrep)*iHandler->getNVIRT(irrep) + iHandler->getNOCC(irrep)*iHandler->getNVIRT(irrep); } if (x_linearlength==0){ return; } x_firstindex = new int[x_linearlength]; x_secondindex = new int[x_linearlength]; jumper = new int*[ iHandler->getNirreps() ]; int jumper_previous = 0; int x_linearlength2 = 0; for (int irrep=0; irrepgetNirreps(); irrep++){ jumper[ irrep ] = new int[ 3 ]; for (int geval=0; geval<3; geval++){ if (geval==0){ for (int cntOcc=0; cntOccgetNOCC(irrep); cntOcc++){ for (int cntDMRG=0; cntDMRGgetNDMRG(irrep); cntDMRG++){ //DMRG is the row index, hence fast moving one x_firstindex[x_linearlength2] = iHandler->getOrigNDMRGstart(irrep)+ cntDMRG; x_secondindex[x_linearlength2] = iHandler->getOrigNOCCstart(irrep) + cntOcc; x_linearlength2++; } } jumper[irrep][geval] = jumper_previous; jumper_previous += iHandler->getNOCC(irrep)*iHandler->getNDMRG(irrep); } if (geval==1){ for (int cntDMRG=0; cntDMRGgetNDMRG(irrep); cntDMRG++){ for (int cntVirt=0; cntVirtgetNVIRT(irrep); cntVirt++){ //Virt is the row index, hence fast moving one x_firstindex[x_linearlength2] = iHandler->getOrigNVIRTstart(irrep) + cntVirt; x_secondindex[x_linearlength2] = iHandler->getOrigNDMRGstart(irrep) + cntDMRG; x_linearlength2++; } } jumper[irrep][geval] = jumper_previous; jumper_previous += iHandler->getNDMRG(irrep)*iHandler->getNVIRT(irrep); } if (geval==2){ for (int cntOcc=0; cntOccgetNOCC(irrep); cntOcc++){ for (int cntVirt=0; cntVirtgetNVIRT(irrep); cntVirt++){ //Virt is the row index, hence fast moving one x_firstindex[x_linearlength2] = iHandler->getOrigNVIRTstart(irrep) + cntVirt; x_secondindex[x_linearlength2] = iHandler->getOrigNOCCstart(irrep) + cntOcc; x_linearlength2++; } } jumper[irrep][geval] = jumper_previous; jumper_previous += iHandler->getNOCC(irrep)*iHandler->getNVIRT(irrep); } } } assert( x_linearlength==x_linearlength2 ); assert( x_linearlength==jumper_previous ); } CheMPS2::DMRGSCFunitary::~DMRGSCFunitary(){ for (int irrep=0; irrepgetNirreps(); irrep++){ delete [] unitary[irrep]; } delete [] unitary; if (x_linearlength!=0){ delete [] x_firstindex; delete [] x_secondindex; for (int irrep=0; irrepgetNirreps(); irrep++){ delete [] jumper[irrep]; } delete [] jumper; } } int CheMPS2::DMRGSCFunitary::getNumVariablesX() const{ return x_linearlength; } int CheMPS2::DMRGSCFunitary::getJumper( const int irrep, const int geval ) const{ return jumper[ irrep ][ geval ]; } int CheMPS2::DMRGSCFunitary::getLinearIndex(const int p_index, const int q_index) const{ int irrep_p = iHandler->getNirreps() - 1; int irrep_q = iHandler->getNirreps() - 1; while ( p_index < iHandler->getOrigNOCCstart( irrep_p ) ){ irrep_p--; } while ( q_index < iHandler->getOrigNOCCstart( irrep_q ) ){ irrep_q--; } assert( irrep_p == irrep_q ); const int irrep = irrep_p; const bool p_virt = ( p_index >= iHandler->getOrigNVIRTstart( irrep )) ? true : false; const bool p_dmrg = ((p_index >= iHandler->getOrigNDMRGstart( irrep )) && (!( p_virt ))) ? true : false; const bool q_occ = ( q_index < iHandler->getOrigNDMRGstart( irrep )) ? true : false; const bool q_dmrg = ((q_index < iHandler->getOrigNVIRTstart( irrep )) && (!( q_occ ))) ? true : false; // 0 : p DMRG q OCC // 1 : p VIRT q DMRG // 2 : p VIRT q OCC if ((p_dmrg) && (q_occ)){ // geval 0 const int p_rel = p_index - iHandler->getOrigNDMRGstart( irrep ); const int q_rel = q_index - iHandler->getOrigNOCCstart( irrep ); const int theLinIndex = getJumper( irrep, 0 ) + p_rel + iHandler->getNDMRG( irrep ) * q_rel; assert( p_index == x_firstindex[ theLinIndex ] ); assert( q_index == x_secondindex[ theLinIndex ] ); return theLinIndex; } if ((p_virt) && (q_dmrg)){ // geval 1 const int p_rel = p_index - iHandler->getOrigNVIRTstart( irrep ); const int q_rel = q_index - iHandler->getOrigNDMRGstart( irrep ); const int theLinIndex = getJumper( irrep, 1 ) + p_rel + iHandler->getNVIRT( irrep ) * q_rel; assert( p_index == x_firstindex[ theLinIndex ] ); assert( q_index == x_secondindex[ theLinIndex ] ); return theLinIndex; } if ((p_virt) && (q_occ)){ // geval 2 const int p_rel = p_index - iHandler->getOrigNVIRTstart( irrep ); const int q_rel = q_index - iHandler->getOrigNOCCstart( irrep ); const int theLinIndex = getJumper( irrep, 2 ) + p_rel + iHandler->getNVIRT( irrep ) * q_rel; assert( p_index == x_firstindex[ theLinIndex ] ); assert( q_index == x_secondindex[ theLinIndex ] ); return theLinIndex; } assert( 0 == 1 ); return -1; } int CheMPS2::DMRGSCFunitary::getFirstIndex(const int linearindex) const{ return x_firstindex[linearindex]; } int CheMPS2::DMRGSCFunitary::getSecondIndex(const int linearindex) const{ return x_secondindex[linearindex]; } double * CheMPS2::DMRGSCFunitary::getBlock(const int irrep){ return unitary[irrep]; } void CheMPS2::DMRGSCFunitary::buildSkewSymmX(const int irrep, double * result, double * Xelem, const bool compact) const{ const int linsize = iHandler->getNORB(irrep); for (int cnt=0; cntgetNOCC(irrep); cntOcc++){ for (int cntDMRG=0; cntDMRGgetNDMRG(irrep); cntDMRG++){ const int xsolindex = getJumper( irrep , 0 ) + cntDMRG + iHandler->getNDMRG( irrep ) * cntOcc; const int index1 = iHandler->getNOCC(irrep) + cntDMRG; //Index within irrep block result[ index1 + linsize*cntOcc ] = Xelem[xsolindex]; result[ cntOcc + linsize*index1 ] = - Xelem[xsolindex]; } } for (int cntDMRG=0; cntDMRGgetNDMRG(irrep); cntDMRG++){ for (int cntVirt=0; cntVirtgetNVIRT(irrep); cntVirt++){ const int xsolindex = getJumper( irrep , 1 ) + cntVirt + iHandler->getNVIRT( irrep ) * cntDMRG; const int index1 = iHandler->getNOCC(irrep) + iHandler->getNDMRG(irrep) + cntVirt; //Index within irrep block const int index2 = iHandler->getNOCC(irrep) + cntDMRG; //Index within irrep block result[ index1 + linsize*index2 ] = Xelem[xsolindex]; result[ index2 + linsize*index1 ] = - Xelem[xsolindex]; } } for (int cntOcc=0; cntOccgetNOCC(irrep); cntOcc++){ for (int cntVirt=0; cntVirtgetNVIRT(irrep); cntVirt++){ const int xsolindex = getJumper( irrep , 2 ) + cntVirt + iHandler->getNVIRT( irrep ) * cntOcc; const int index1 = iHandler->getNOCC(irrep) + iHandler->getNDMRG(irrep) + cntVirt; //Index within irrep block result[ index1 + linsize*cntOcc ] = Xelem[xsolindex]; result[ cntOcc + linsize*index1 ] = - Xelem[xsolindex]; } } } else { //NOT compact int jump = 0; for (int cnt=0; cntgetNORB(cnt); jump += linsizeCNT * (linsizeCNT-1) / 2; } for (int row=0; rowgetNirreps(); irrep++){ int linsize = iHandler->getNORB(irrep); int size = linsize * linsize; if (linsize>1){ //linsize is op z'n minst 2 dus temp1, temp1+size, temp1+2*size,temp1+3*size zijn zeker ok double * xblock = temp1; //linsize*linsize double * Bmat = temp1 + size; //linsize*linsize double * work1 = temp1 + 2*size; //linsize*linsize double * work2 = temp1 + 3*size; //linsize*linsize double * workLARGE = temp2; //4*size int lworkLARGE = 4*size; //4*size = 4*linsize*linsize > 3*linsize-1 //Construct the antisymmetric x-matrix buildSkewSymmX(irrep, xblock, vector, compact); //Bmat <= xblock * xblock char notr = 'N'; double alpha = 1.0; double beta = 0.0; //SET !!! dgemm_(¬r,¬r,&linsize,&linsize,&linsize,&alpha,xblock,&linsize,xblock,&linsize,&beta,Bmat,&linsize); //Bmat * work1 * Bmat^T <= xblock * xblock char uplo = 'U'; char jobz = 'V'; int info; dsyev_(&jobz, &uplo, &linsize, Bmat, &linsize, work1, workLARGE, &lworkLARGE, &info); //work2 <= Bmat^T * xblock * Bmat dgemm_(¬r,¬r,&linsize,&linsize,&linsize,&alpha,xblock,&linsize,Bmat,&linsize,&beta,work1,&linsize); char trans = 'T'; dgemm_(&trans,¬r,&linsize,&linsize,&linsize,&alpha,Bmat,&linsize,work1,&linsize,&beta,work2,&linsize); if (CheMPS2::DMRGSCF_debugPrint){ cout << " DMRGSCFunitary::updateUnitary : Lambdas of irrep block " << irrep << " : " << endl; for (int cnt=0; cnt work2 alpha = -1.0; beta = 1.0; //ADD dgemm_(¬rans, ¬rans, &linsize, &linsize, &linsize, &alpha, work1, &linsize, xblock, &linsize, &beta, work2, &linsize); //work2 = [X,[X,Y]] beta = 0.0; //SET alpha = 1.0; dgemm_(¬rans, ¬rans, &linsize, &linsize, &linsize, &alpha, theY, &linsize, work1, &linsize, &beta, work3, &linsize); //Y * [X,Y] --> work3 alpha = -1.0; beta = 1.0; //ADD dgemm_(¬rans, ¬rans, &linsize, &linsize, &linsize, &alpha, work1, &linsize, theY, &linsize, &beta, work3, &linsize); //work3 = [Y,[X,Y]] alpha = 1 / 12.0; daxpy_(&size, &alpha, work2, &inc, result, &inc); alpha = - 1 / 12.0; daxpy_(&size, &alpha, work3, &inc, result, &inc); if (CheMPS2::DMRGSCF_debugPrint){ double RMSmat = 0.0; for (int cnt=0; cnt work4 alpha = -1.0; beta = 1.0; //ADD dgemm_(¬rans, ¬rans, &linsize, &linsize, &linsize, &alpha, work2, &linsize, theY, &linsize, &beta, work4, &linsize); //work4 = [Y,[X,[X,Y]]] alpha = - 1 / 24.0; daxpy_(&size, &alpha, work4, &inc, result, &inc); if (CheMPS2::DMRGSCF_debugPrint){ double RMSmat = 0.0; for (int cnt=0; cntgetNirreps(); irrep++){ std::stringstream irrepname; irrepname << "irrep_" << irrep; hsize_t dimarray = iHandler->getNORB(irrep) * iHandler->getNORB(irrep); hid_t dataspace_id = H5Screate_simple(1, &dimarray, NULL); hid_t dataset_id = H5Dcreate(group_id, irrepname.str().c_str(), H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, unitary[irrep]); H5Dclose(dataset_id); H5Sclose(dataspace_id); } H5Gclose(group_id); H5Fclose(file_id); } void CheMPS2::DMRGSCFunitary::loadU(const string filename){ hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); hid_t group_id = H5Gopen(file_id, "/Data",H5P_DEFAULT); for (int irrep=0; irrepgetNirreps(); irrep++){ std::stringstream irrepname; irrepname << "irrep_" << irrep; hid_t dataset_id = H5Dopen(group_id, irrepname.str().c_str(), H5P_DEFAULT); H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, unitary[irrep]); H5Dclose(dataset_id); } H5Gclose(group_id); H5Fclose(file_id); } void CheMPS2::DMRGSCFunitary::deleteStoredUnitary(const string filename) const{ std::stringstream temp; temp << "rm " << filename; int info = system(temp.str().c_str()); cout << "Info on DMRGSCF::Unitary rm call to system: " << info << endl; } CheMPS2-1.6/CheMPS2/DMRGSCFwtilde.cpp000066400000000000000000000076011256744172700167070ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "DMRGSCFwtilde.h" CheMPS2::DMRGSCFwtilde::DMRGSCFwtilde(DMRGSCFindices * iHandler_in){ iHandler = iHandler_in; Nocc_dmrg = new int[ iHandler->getNirreps() ]; for (int irrep = 0; irrep < iHandler->getNirreps(); irrep++){ Nocc_dmrg[ irrep ] = iHandler->getNOCC( irrep ) + iHandler->getNDMRG( irrep ); } wmattilde = new double***[ iHandler->getNirreps() ]; for (int irrep_pq = 0; irrep_pq < iHandler->getNirreps(); irrep_pq++){ wmattilde[ irrep_pq ] = new double**[ iHandler->getNirreps() ]; for (int irrep_rs = 0; irrep_rs < iHandler->getNirreps(); irrep_rs++){ const unsigned int sizeblock_pr = Nocc_dmrg[ irrep_pq ] * Nocc_dmrg[ irrep_rs ]; const unsigned int sizeblock_qs = iHandler->getNORB( irrep_pq ) * iHandler->getNORB( irrep_rs ); wmattilde[ irrep_pq ][ irrep_rs ] = new double*[ sizeblock_pr ]; for (unsigned int combined_pr = 0; combined_pr < sizeblock_pr; combined_pr++){ wmattilde[ irrep_pq ][ irrep_rs ][ combined_pr ] = new double[ sizeblock_qs ]; } } } } CheMPS2::DMRGSCFwtilde::~DMRGSCFwtilde(){ for (int irrep_pq = 0; irrep_pq < iHandler->getNirreps(); irrep_pq++){ for (int irrep_rs = 0; irrep_rs < iHandler->getNirreps(); irrep_rs++){ const unsigned int sizeblock_pr = Nocc_dmrg[ irrep_pq ] * Nocc_dmrg[ irrep_rs ]; for (unsigned int combined_pr = 0; combined_pr < sizeblock_pr; combined_pr++){ delete [] wmattilde[ irrep_pq ][ irrep_rs ][ combined_pr ]; } delete [] wmattilde[ irrep_pq ][ irrep_rs ]; } delete [] wmattilde[ irrep_pq ]; } delete [] wmattilde; delete [] Nocc_dmrg; } void CheMPS2::DMRGSCFwtilde::clear(){ for (int irrep_pq = 0; irrep_pq < iHandler->getNirreps(); irrep_pq++){ for (int irrep_rs = 0; irrep_rs < iHandler->getNirreps(); irrep_rs++){ const unsigned int sizeblock_pr = Nocc_dmrg[ irrep_pq ] * Nocc_dmrg[ irrep_rs ]; const unsigned int sizeblock_qs = iHandler->getNORB( irrep_pq ) * iHandler->getNORB( irrep_rs ); for (unsigned int combined_pr = 0; combined_pr < sizeblock_pr; combined_pr++){ for (unsigned int combined_qs = 0; combined_qs < sizeblock_qs; combined_qs++){ wmattilde[ irrep_pq ][ irrep_rs ][ combined_pr ][ combined_qs ] = 0.0; } } } } } void CheMPS2::DMRGSCFwtilde::set(const int irrep_pq, const int irrep_rs, const int p, const int q, const int r, const int s, const double val){ wmattilde[ irrep_pq ][ irrep_rs ][ p + Nocc_dmrg[ irrep_pq ] * r ][ q + iHandler->getNORB(irrep_pq) * s ] = val; } double CheMPS2::DMRGSCFwtilde::get(const int irrep_pq, const int irrep_rs, const int p, const int q, const int r, const int s) const{ return wmattilde[ irrep_pq ][ irrep_rs ][ p + Nocc_dmrg[ irrep_pq ] * r ][ q + iHandler->getNORB(irrep_pq) * s ]; } double * CheMPS2::DMRGSCFwtilde::getBlock(const int irrep_pq, const int irrep_rs, const int p, const int r){ return wmattilde[ irrep_pq ][ irrep_rs ][ p + Nocc_dmrg[ irrep_pq ] * r ]; } CheMPS2-1.6/CheMPS2/DMRGmpsio.cpp000066400000000000000000000151771256744172700162210ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include "DMRG.h" void CheMPS2::DMRG::saveMPS(const std::string name, TensorT ** MPSlocation, SyBookkeeper * BKlocation, bool isConverged) const{ //The hdf5 file hid_t file_id = H5Fcreate(name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); //Whether the MPS was converged or not hid_t group_id = H5Gcreate(file_id, "/Convergence", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hsize_t dimarray = 1; //One integer hid_t dataspace_id = H5Screate_simple(1, &dimarray, NULL); hid_t dataset_id = H5Dcreate(group_id, "Converged_yn", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); int toWrite = (isConverged)?1:0; H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &toWrite); H5Dclose(dataset_id); H5Sclose(dataspace_id); H5Gclose(group_id); //The current virtual dimensions for (int bound=0; bound<=BKlocation->gL(); bound++){ for (int N=BKlocation->gNmin(bound); N<=BKlocation->gNmax(bound); N++){ for (int TwoS=BKlocation->gTwoSmin(bound,N); TwoS<=BKlocation->gTwoSmax(bound,N); TwoS+=2){ for (int Irrep=0; IrrepgetNumberOfIrreps(); Irrep++){ std::stringstream sstream; sstream << "/VirtDim_" << bound << "_" << N << "_" << TwoS << "_" << Irrep; hid_t group_id2 = H5Gcreate(file_id, sstream.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hsize_t dimarray2 = 1; //One integer hid_t dataspace_id2 = H5Screate_simple(1, &dimarray2, NULL); hid_t dataset_id2 = H5Dcreate(group_id2, "Value", H5T_STD_I32LE, dataspace_id2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); int toWrite2 = BKlocation->gCurrentDim(bound,N,TwoS,Irrep); H5Dwrite(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &toWrite2); H5Dclose(dataset_id2); H5Sclose(dataspace_id2); H5Gclose(group_id2); } } } } //The MPS for (int site=0; sitegL(); site++){ std::stringstream sstream; sstream << "/MPS_" << site; hid_t group_id3 = H5Gcreate(file_id, sstream.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hsize_t dimarray3 = MPSlocation[site]->gKappa2index(MPSlocation[site]->gNKappa()); //An array of doubles hid_t dataspace_id3 = H5Screate_simple(1, &dimarray3, NULL); hid_t dataset_id3 = H5Dcreate(group_id3, "Values", H5T_IEEE_F64LE, dataspace_id3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(dataset_id3, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, MPSlocation[site]->gStorage()); H5Dclose(dataset_id3); H5Sclose(dataspace_id3); H5Gclose(group_id3); } H5Fclose(file_id); } void CheMPS2::DMRG::loadDIM(const std::string name, SyBookkeeper * BKlocation){ //The hdf5 file hid_t file_id = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); //The current virtual dimensions for (int bound=0; bound<=BKlocation->gL(); bound++){ for (int N=BKlocation->gNmin(bound); N<=BKlocation->gNmax(bound); N++){ for (int TwoS=BKlocation->gTwoSmin(bound,N); TwoS<=BKlocation->gTwoSmax(bound,N); TwoS+=2){ for (int Irrep=0; IrrepgetNumberOfIrreps(); Irrep++){ std::stringstream sstream; sstream << "/VirtDim_" << bound << "_" << N << "_" << TwoS << "_" << Irrep; hid_t group_id2 = H5Gopen(file_id, sstream.str().c_str(), H5P_DEFAULT); hid_t dataset_id2 = H5Dopen(group_id2, "Value", H5P_DEFAULT); int toRead; H5Dread(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &toRead); BKlocation->SetDim(bound, N, TwoS, Irrep, toRead); H5Dclose(dataset_id2); H5Gclose(group_id2); } } } } H5Fclose(file_id); } void CheMPS2::DMRG::loadMPS(const std::string name, TensorT ** MPSlocation, bool * isConverged){ //The hdf5 file hid_t file_id = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); //Whether the MPS was converged or not hid_t group_id = H5Gopen(file_id, "/Convergence", H5P_DEFAULT); hid_t dataset_id = H5Dopen(group_id, "Converged_yn", H5P_DEFAULT); int toRead; H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &toRead); isConverged[0] = (toRead==0)?false:true; H5Dclose(dataset_id); H5Gclose(group_id); //The MPS for (int site=0; sitegStorage()); H5Dclose(dataset_id3); H5Gclose(group_id3); } H5Fclose(file_id); } void CheMPS2::DMRG::deleteStoredMPS(){ std::stringstream thestream; thestream << "rm " << CheMPS2::DMRG_MPS_storage_prefix << "*.h5"; int info = system(thestream.str().c_str()); std::cout << "Info on DMRG::MPS rm call to system: " << info << std::endl; } CheMPS2-1.6/CheMPS2/DMRGoperators.cpp000066400000000000000000001755331256744172700171130ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include "DMRG.h" #include "Lapack.h" #include "MPIchemps2.h" void CheMPS2::DMRG::updateMovingRightSafeFirstTime(const int cnt){ if (isAllocated[cnt]==2){ deleteTensors(cnt, false); isAllocated[cnt]=0; } if (isAllocated[cnt]==0){ allocateTensors(cnt, true); isAllocated[cnt]=1; } updateMovingRight(cnt); if (CheMPS2::DMRG_storeRenormOptrOnDisk){ if (cnt>0){ if (isAllocated[cnt-1]==1){ OperatorsOnDisk(cnt-1, true, true); deleteTensors(cnt-1, true); isAllocated[cnt-1]=0; } } } } void CheMPS2::DMRG::updateMovingRightSafe(const int cnt){ if (isAllocated[cnt]==2){ deleteTensors(cnt, false); isAllocated[cnt]=0; } if (isAllocated[cnt]==0){ allocateTensors(cnt, true); isAllocated[cnt]=1; } updateMovingRight(cnt); if (CheMPS2::DMRG_storeRenormOptrOnDisk){ if (cnt>0){ if (isAllocated[cnt-1]==1){ OperatorsOnDisk(cnt-1, true, true); deleteTensors(cnt-1, true); isAllocated[cnt-1]=0; } } if (cnt+1=0){ if (isAllocated[cnt-1]==1){ deleteTensors(cnt-1, true); isAllocated[cnt-1]=0; } } if (cnt-2>=0){ if (isAllocated[cnt-2]==2){ deleteTensors(cnt-2, false); isAllocated[cnt-2]=0; } if (isAllocated[cnt-2]==0){ allocateTensors(cnt-2, true); isAllocated[cnt-2]=1; } OperatorsOnDisk(cnt-2, true, false); } } } void CheMPS2::DMRG::updateMovingLeftSafe2DM(const int cnt){ if (isAllocated[cnt]==1){ deleteTensors(cnt, true); isAllocated[cnt]=0; } if (isAllocated[cnt]==0){ allocateTensors(cnt, false); isAllocated[cnt]=2; } updateMovingLeft(cnt); if (CheMPS2::DMRG_storeRenormOptrOnDisk){ if (cnt+1=0){ if (isAllocated[cnt-1]==2){ deleteTensors(cnt-1, false); isAllocated[cnt-1]=0; } if (isAllocated[cnt-1]==0){ allocateTensors(cnt-1, true); isAllocated[cnt-1]=1; } OperatorsOnDisk(cnt-1, true, false); } } } void CheMPS2::DMRG::deleteAllBoundaryOperators(){ for (int cnt=0; cntgMaxDimAtBound(index); const int dimR = denBK->gMaxDimAtBound(index+1); #ifdef CHEMPS2_MPI_COMPILATION const int MPIRANK = MPIchemps2::mpi_rank(); #endif #pragma omp parallel { double * workmem = new double[dimL*dimR]; //Ltensors : all processes own all Ltensors #pragma omp for schedule(static) nowait for (int cnt2=0; cnt2<(index+1) ; cnt2++){ if (cnt2==0){ Ltensors[index][cnt2]->makenew(MPS[index]); } else { Ltensors[index][cnt2]->update( Ltensors[index-1][cnt2-1] , MPS[index] , workmem ); } } //Two-operator tensors : certain processes own certain two-operator tensors const int k1 = index+1; const int upperbound1 = (k1*(k1+1))/2; //After this parallel region, WAIT because F0,F1,S0,S1[index][cnt2][cnt3==0] is required for the complementary operators #ifdef CHEMPS2_MPI_COMPILATION #pragma omp for schedule(dynamic) #else #pragma omp for schedule(static) #endif for (int glob=0; globmakenew(MPS[index]); F1tensors[index][cnt2][cnt3]->makenew(MPS[index]); S0tensors[index][cnt2][cnt3]->makenew(MPS[index]); //S1[index][0][cnt3] doesn't exist } else { F0tensors[index][cnt2][cnt3]->makenew(Ltensors[index-1][cnt2-1],MPS[index],workmem); F1tensors[index][cnt2][cnt3]->makenew(Ltensors[index-1][cnt2-1],MPS[index],workmem); S0tensors[index][cnt2][cnt3]->makenew(Ltensors[index-1][cnt2-1],MPS[index],workmem); S1tensors[index][cnt2][cnt3]->makenew(Ltensors[index-1][cnt2-1],MPS[index],workmem); } } else { #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_cdf( L, siteindex1, siteindex2 ) == MPIRANK ) #endif { F0tensors[index][cnt2][cnt3]->update(F0tensors[index-1][cnt2][cnt3-1],MPS[index],workmem); F1tensors[index][cnt2][cnt3]->update(F1tensors[index-1][cnt2][cnt3-1],MPS[index],workmem); } #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_absigma( siteindex1, siteindex2 ) == MPIRANK ) #endif { S0tensors[index][cnt2][cnt3]->update(S0tensors[index-1][cnt2][cnt3-1],MPS[index],workmem); if (cnt2>0){ S1tensors[index][cnt2][cnt3]->update(S1tensors[index-1][cnt2][cnt3-1],MPS[index],workmem); } } } } //Complementary two-operator tensors : certain processes own certain complementary two-operator tensors const int k2 = L-1-index; const int upperbound2 = (k2*(k2+1))/2; #ifdef CHEMPS2_MPI_COMPILATION #pragma omp for schedule(dynamic) #else #pragma omp for schedule(static) nowait #endif for (int glob=0; globgIrrep(siteindex1), denBK->gIrrep(siteindex2) ); #ifdef CHEMPS2_MPI_COMPILATION const bool do_absigma = ( MPIchemps2::owner_absigma( siteindex1, siteindex2 ) == MPIRANK ); const bool do_cdf = ( MPIchemps2::owner_cdf( L, siteindex1, siteindex2 ) == MPIRANK ); #endif if (index==0){ #ifdef CHEMPS2_MPI_COMPILATION if ( do_absigma ) #endif { Atensors[index][cnt2][cnt3]->ClearStorage(); if (cnt2>0){ Btensors[index][cnt2][cnt3]->ClearStorage(); } } #ifdef CHEMPS2_MPI_COMPILATION if ( do_cdf ) #endif { Ctensors[index][cnt2][cnt3]->ClearStorage(); Dtensors[index][cnt2][cnt3]->ClearStorage(); } } else { #ifdef CHEMPS2_MPI_COMPILATION if ( do_absigma ) #endif { Atensors[index][cnt2][cnt3]->update(Atensors[index-1][cnt2][cnt3+1],MPS[index],workmem); if (cnt2>0){ Btensors[index][cnt2][cnt3]->update(Btensors[index-1][cnt2][cnt3+1],MPS[index],workmem); } } #ifdef CHEMPS2_MPI_COMPILATION if ( do_cdf ) #endif { Ctensors[index][cnt2][cnt3]->update(Ctensors[index-1][cnt2][cnt3+1],MPS[index],workmem); Dtensors[index][cnt2][cnt3]->update(Dtensors[index-1][cnt2][cnt3+1],MPS[index],workmem); } } for (int num=0; num<(index+1); num++){ if ( irrep_prod == S0tensors[index][num][0]->gIdiff() ){ //Then the matrix elements are not 0 due to symm. #ifdef CHEMPS2_MPI_COMPILATION if ( do_absigma ) #endif { double alpha = Prob->gMxElement(index-num,index,siteindex1,siteindex2); if ((cnt2==0) && (num==0)){ alpha *= 0.5; } if ((cnt2>0) && (num>0)){ alpha += Prob->gMxElement(index-num,index,siteindex2,siteindex1); } Atensors[index][cnt2][cnt3]->AddATerm(alpha, S0tensors[index][num][0]); if ((num>0) && (cnt2>0)){ alpha = Prob->gMxElement(index-num,index,siteindex1,siteindex2) - Prob->gMxElement(index-num,index,siteindex2,siteindex1); Btensors[index][cnt2][cnt3]->AddATerm(alpha,S1tensors[index][num][0]); } } #ifdef CHEMPS2_MPI_COMPILATION if ( do_cdf ) #endif { double alpha = 2 * Prob->gMxElement(index-num,siteindex1,index,siteindex2) - Prob->gMxElement(index-num,siteindex1,siteindex2,index); Ctensors[index][cnt2][cnt3]->AddATerm(alpha,F0tensors[index][num][0]); alpha = - Prob->gMxElement(index-num,siteindex1,siteindex2,index); // Second line for Ctensors Dtensors[index][cnt2][cnt3]->AddATerm(alpha,F1tensors[index][num][0]); if (num>0){ alpha = 2 * Prob->gMxElement(index-num,siteindex2,index,siteindex1) - Prob->gMxElement(index-num,siteindex2,siteindex1,index); Ctensors[index][cnt2][cnt3]->AddATermTranspose(alpha,F0tensors[index][num][0]); alpha = - Prob->gMxElement(index-num,siteindex2,siteindex1,index); // Second line for Ctensors Dtensors[index][cnt2][cnt3]->AddATermTranspose(alpha,F1tensors[index][num][0]); } } } } } //Qtensors : certain processes own certain Qtensors --- You don't want to locally parallellize when sending and receiving buffers! #ifdef CHEMPS2_MPI_COMPILATION #pragma omp single #else #pragma omp for schedule(static) nowait #endif for (int cnt2=0; cnt2ClearStorage(); Qtensors[index][cnt2]->AddTermSimple(MPS[index]); } } else { #ifdef CHEMPS2_MPI_COMPILATION const int owner_absigma = MPIchemps2::owner_absigma( index, siteindex ); const int owner_cdf = MPIchemps2::owner_cdf( L, index, siteindex ); if (( owner_q == owner_absigma ) && ( owner_q == owner_cdf ) && ( owner_q == MPIRANK )){ // No MPI needed #endif double * workmemBIS = new double[dimL*dimL]; Qtensors[index][cnt2]->update(Qtensors[index-1][cnt2+1],MPS[index],workmem); Qtensors[index][cnt2]->AddTermSimple(MPS[index]); Qtensors[index][cnt2]->AddTermsL(Ltensors[index-1],MPS[index], workmemBIS, workmem); Qtensors[index][cnt2]->AddTermsAB(Atensors[index-1][cnt2+1][0], Btensors[index-1][cnt2+1][0], MPS[index], workmemBIS, workmem); Qtensors[index][cnt2]->AddTermsCD(Ctensors[index-1][cnt2+1][0], Dtensors[index-1][cnt2+1][0], MPS[index], workmemBIS, workmem); delete [] workmemBIS; #ifdef CHEMPS2_MPI_COMPILATION } else { //There's going to have to be some communication if (( owner_q == MPIRANK ) || ( owner_absigma == MPIRANK ) || ( owner_cdf == MPIRANK )){ TensorQ * tempQ = new TensorQ(index+1,denBK->gIrrep(siteindex),true,denBK,Prob,siteindex); tempQ->ClearStorage(); //Everyone creates his/her piece double * workmemBIS = new double[dimL*dimL]; if ( owner_q == MPIRANK ){ tempQ->update(Qtensors[index-1][cnt2+1],MPS[index],workmem); tempQ->AddTermSimple(MPS[index]); tempQ->AddTermsL(Ltensors[index-1],MPS[index], workmemBIS, workmem); } if ( owner_absigma == MPIRANK ){ tempQ->AddTermsAB(Atensors[index-1][cnt2+1][0], Btensors[index-1][cnt2+1][0], MPS[index], workmemBIS, workmem); } if ( owner_cdf == MPIRANK ){ tempQ->AddTermsCD(Ctensors[index-1][cnt2+1][0], Dtensors[index-1][cnt2+1][0], MPS[index], workmemBIS, workmem); } delete [] workmemBIS; //Add everything to owner_q's Qtensors[index][cnt2]: replace later with custom communication group? int inc = 1; int arraysize = tempQ->gKappa2index(tempQ->gNKappa()); double alpha = 1.0; if ( owner_q == MPIRANK ){ dcopy_(&arraysize, tempQ->gStorage(), &inc, Qtensors[index][cnt2]->gStorage(), &inc); } if ( owner_q != owner_absigma ){ MPIchemps2::sendreceive_tensor( tempQ, owner_absigma, owner_q, 2*siteindex ); if ( owner_q == MPIRANK ){ daxpy_(&arraysize, &alpha, tempQ->gStorage(), &inc, Qtensors[index][cnt2]->gStorage(), &inc); } } if (( owner_q != owner_cdf ) && ( owner_absigma != owner_cdf )){ MPIchemps2::sendreceive_tensor( tempQ, owner_cdf, owner_q, 2*siteindex+1 ); if ( owner_q == MPIRANK ){ daxpy_(&arraysize, &alpha, tempQ->gStorage(), &inc, Qtensors[index][cnt2]->gStorage(), &inc); } } delete tempQ; } } #endif } } delete [] workmem; } //Xtensors #ifdef CHEMPS2_MPI_COMPILATION const int owner_x = MPIchemps2::owner_x(); #endif if ( index == 0 ){ #ifdef CHEMPS2_MPI_COMPILATION if ( owner_x == MPIRANK ) #endif { Xtensors[index]->update(MPS[index]); } } else { #ifdef CHEMPS2_MPI_COMPILATION //Make sure that owner_x has all required tensors to construct X. Not as optimal as Q-tensor case, but easier hack. const int owner_q = MPIchemps2::owner_q( L, index ); const int owner_absigma = MPIchemps2::owner_absigma( index, index ); const int owner_cdf = MPIchemps2::owner_cdf( L, index, index ); const int Idiff = Irreps::directProd( denBK->gIrrep(index), denBK->gIrrep(index) ); // Will be num ^ num --> 0 if ( owner_x != owner_q ){ if ( owner_x == MPIRANK ){ Qtensors[index-1][0] = new TensorQ( index, denBK->gIrrep(index), true, denBK, Prob, index ); } if (( owner_x == MPIRANK ) || ( owner_q == MPIRANK )){ MPIchemps2::sendreceive_tensor( Qtensors[index-1][0], owner_q, owner_x, 3*L+3 ); } } if ( owner_x != owner_absigma ){ if ( owner_x == MPIRANK ){ Atensors[index-1][0][0] = new TensorA( index, Idiff, true, denBK ); } if (( owner_x == MPIRANK ) || ( owner_absigma == MPIRANK )){ MPIchemps2::sendreceive_tensor( Atensors[index-1][0][0], owner_absigma, owner_x, 3*L+4 ); } } if ( owner_x != owner_cdf ){ if ( owner_x == MPIRANK ){ Ctensors[index-1][0][0] = new TensorC( index, Idiff, true, denBK ); Dtensors[index-1][0][0] = new TensorD( index, Idiff, true, denBK ); } if (( owner_x == MPIRANK ) || ( owner_cdf == MPIRANK )){ MPIchemps2::sendreceive_tensor( Ctensors[index-1][0][0], owner_cdf, owner_x, 3*L+5 ); MPIchemps2::sendreceive_tensor( Dtensors[index-1][0][0], owner_cdf, owner_x, 3*L+6 ); } } if ( owner_x == MPIRANK ){ #endif Xtensors[index]->update(MPS[index], Ltensors[index-1], Xtensors[index-1], Qtensors[index-1][0], Atensors[index-1][0][0], Ctensors[index-1][0][0], Dtensors[index-1][0][0]); #ifdef CHEMPS2_MPI_COMPILATION if ( owner_x != owner_q ){ delete Qtensors[index-1][0]; } if ( owner_x != owner_absigma ){ delete Atensors[index-1][0][0]; } if ( owner_x != owner_cdf ){ delete Ctensors[index-1][0][0]; delete Dtensors[index-1][0][0]; } } #endif } //Otensors : certain processes own certain excitations if (Exc_activated){ for (int state=0; stateupdate(Exc_MPSs[state][index],MPS[index]); } else { Exc_Overlaps[state][index]->update(Exc_MPSs[state][index],MPS[index],Exc_Overlaps[state][index-1]); } } } } gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_TENS_CALC ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); } void CheMPS2::DMRG::updateMovingLeft(const int index){ struct timeval start, end; gettimeofday(&start, NULL); const int dimL = denBK->gMaxDimAtBound(index+1); const int dimR = denBK->gMaxDimAtBound(index+2); #ifdef CHEMPS2_MPI_COMPILATION const int MPIRANK = MPIchemps2::mpi_rank(); #endif #pragma omp parallel { double * workmem = new double[dimL*dimR]; //Ltensors : all processes own all Ltensors #pragma omp for schedule(static) nowait for (int cnt2=0; cnt2makenew(MPS[index+1]); } else { Ltensors[index][cnt2]->update( Ltensors[index+1][cnt2-1] , MPS[index+1] , workmem ); } } //Two-operator tensors : certain processes own certain two-operator tensors const int k1 = L-1-index; const int upperbound1 = k1*(k1+1)/2; //After this parallel region, WAIT because F0,F1,S0,S1[index][cnt2][cnt3==0] is required for the complementary operators #ifdef CHEMPS2_MPI_COMPILATION #pragma omp for schedule(dynamic) #else #pragma omp for schedule(static) #endif for (int glob=0; globmakenew(MPS[index+1]); F1tensors[index][cnt2][cnt3]->makenew(MPS[index+1]); S0tensors[index][cnt2][cnt3]->makenew(MPS[index+1]); //S1[index][0] doesn't exist } else { F0tensors[index][cnt2][cnt3]->makenew(Ltensors[index+1][cnt2-1],MPS[index+1],workmem); F1tensors[index][cnt2][cnt3]->makenew(Ltensors[index+1][cnt2-1],MPS[index+1],workmem); S0tensors[index][cnt2][cnt3]->makenew(Ltensors[index+1][cnt2-1],MPS[index+1],workmem); S1tensors[index][cnt2][cnt3]->makenew(Ltensors[index+1][cnt2-1],MPS[index+1],workmem); } } else { #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_cdf( L, siteindex1, siteindex2 ) == MPIRANK ) #endif { F0tensors[index][cnt2][cnt3]->update(F0tensors[index+1][cnt2][cnt3-1],MPS[index+1],workmem); F1tensors[index][cnt2][cnt3]->update(F1tensors[index+1][cnt2][cnt3-1],MPS[index+1],workmem); } #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_absigma( siteindex1, siteindex2 ) == MPIRANK ) #endif { S0tensors[index][cnt2][cnt3]->update(S0tensors[index+1][cnt2][cnt3-1],MPS[index+1],workmem); if (cnt2>0){ S1tensors[index][cnt2][cnt3]->update(S1tensors[index+1][cnt2][cnt3-1],MPS[index+1],workmem); } } } } //Complementary two-operator tensors : certain processes own certain complementary two-operator tensors const int k2 = index+1; const int upperbound2 = k2*(k2+1)/2; #ifdef CHEMPS2_MPI_COMPILATION #pragma omp for schedule(dynamic) #else #pragma omp for schedule(static) nowait #endif for (int glob=0; globgIrrep(siteindex1),denBK->gIrrep(siteindex2)); #ifdef CHEMPS2_MPI_COMPILATION const bool do_absigma = ( MPIchemps2::owner_absigma( siteindex1, siteindex2 ) == MPIRANK ); const bool do_cdf = ( MPIchemps2::owner_cdf( L, siteindex1, siteindex2 ) == MPIRANK ); #endif if (index==L-2){ #ifdef CHEMPS2_MPI_COMPILATION if ( do_absigma ) #endif { Atensors[index][cnt2][cnt3]->ClearStorage(); if (cnt2>0){ Btensors[index][cnt2][cnt3]->ClearStorage(); } } #ifdef CHEMPS2_MPI_COMPILATION if ( do_cdf ) #endif { Ctensors[index][cnt2][cnt3]->ClearStorage(); Dtensors[index][cnt2][cnt3]->ClearStorage(); } } else { #ifdef CHEMPS2_MPI_COMPILATION if ( do_absigma ) #endif { Atensors[index][cnt2][cnt3]->update(Atensors[index+1][cnt2][cnt3+1],MPS[index+1],workmem); if (cnt2>0){ Btensors[index][cnt2][cnt3]->update(Btensors[index+1][cnt2][cnt3+1],MPS[index+1],workmem); } } #ifdef CHEMPS2_MPI_COMPILATION if ( do_cdf ) #endif { Ctensors[index][cnt2][cnt3]->update(Ctensors[index+1][cnt2][cnt3+1],MPS[index+1],workmem); Dtensors[index][cnt2][cnt3]->update(Dtensors[index+1][cnt2][cnt3+1],MPS[index+1],workmem); } } for (int num=0; numgIdiff() ){ //Then the matrix elements are not 0 due to symm. #ifdef CHEMPS2_MPI_COMPILATION if ( do_absigma ) #endif { double alpha = Prob->gMxElement(siteindex1,siteindex2,index+1,index+1+num); if ((cnt2==0) && (num==0)) alpha *= 0.5; if ((cnt2>0) && (num>0)) alpha += Prob->gMxElement(siteindex1,siteindex2,index+1+num,index+1); Atensors[index][cnt2][cnt3]->AddATerm(alpha,S0tensors[index][num][0]); if ((num>0) && (cnt2>0)){ alpha = Prob->gMxElement(siteindex1,siteindex2,index+1,index+1+num) - Prob->gMxElement(siteindex1,siteindex2,index+1+num,index+1); Btensors[index][cnt2][cnt3]->AddATerm(alpha,S1tensors[index][num][0]); } } #ifdef CHEMPS2_MPI_COMPILATION if ( do_cdf ) #endif { double alpha = 2 * Prob->gMxElement(siteindex1,index+1,siteindex2,index+1+num) - Prob->gMxElement(siteindex1,index+1,index+1+num,siteindex2); Ctensors[index][cnt2][cnt3]->AddATerm(alpha,F0tensors[index][num][0]); alpha = - Prob->gMxElement(siteindex1,index+1,index+1+num,siteindex2); // Second line for Ctensors Dtensors[index][cnt2][cnt3]->AddATerm(alpha,F1tensors[index][num][0]); if (num>0){ alpha = 2 * Prob->gMxElement(siteindex1,index+1+num,siteindex2,index+1) - Prob->gMxElement(siteindex1,index+1+num,index+1,siteindex2); Ctensors[index][cnt2][cnt3]->AddATermTranspose(alpha,F0tensors[index][num][0]); alpha = - Prob->gMxElement(siteindex1,index+1+num,index+1,siteindex2); // Second line for Ctensors Dtensors[index][cnt2][cnt3]->AddATermTranspose(alpha,F1tensors[index][num][0]); } } } } } //Qtensors : certain processes own certain Qtensors --- You don't want to locally parallellize when sending and receiving buffers! #ifdef CHEMPS2_MPI_COMPILATION #pragma omp single #else #pragma omp for schedule(static) nowait #endif for (int cnt2=0; cnt2ClearStorage(); Qtensors[index][cnt2]->AddTermSimple(MPS[index+1]); } } else { #ifdef CHEMPS2_MPI_COMPILATION const int owner_absigma = MPIchemps2::owner_absigma( siteindex, index+1 ); const int owner_cdf = MPIchemps2::owner_cdf( L, siteindex, index+1 ); if (( owner_q == owner_absigma ) && ( owner_q == owner_cdf ) && ( owner_q == MPIRANK )){ // No MPI needed #endif double * workmemBIS = new double[dimR*dimR]; Qtensors[index][cnt2]->update(Qtensors[index+1][cnt2+1],MPS[index+1],workmem); Qtensors[index][cnt2]->AddTermSimple(MPS[index+1]); Qtensors[index][cnt2]->AddTermsL(Ltensors[index+1],MPS[index+1], workmemBIS, workmem); Qtensors[index][cnt2]->AddTermsAB(Atensors[index+1][cnt2+1][0], Btensors[index+1][cnt2+1][0], MPS[index+1], workmemBIS, workmem); Qtensors[index][cnt2]->AddTermsCD(Ctensors[index+1][cnt2+1][0], Dtensors[index+1][cnt2+1][0], MPS[index+1], workmemBIS, workmem); delete [] workmemBIS; #ifdef CHEMPS2_MPI_COMPILATION } else { // There's going to have to be some communication if (( owner_q == MPIRANK ) || ( owner_absigma == MPIRANK ) || ( owner_cdf == MPIRANK )){ TensorQ * tempQ = new TensorQ(index+1,denBK->gIrrep(siteindex),false,denBK,Prob,siteindex); tempQ->ClearStorage(); //Everyone creates his/her piece double * workmemBIS = new double[dimR*dimR]; if ( owner_q == MPIRANK ){ tempQ->update(Qtensors[index+1][cnt2+1],MPS[index+1],workmem); tempQ->AddTermSimple(MPS[index+1]); tempQ->AddTermsL(Ltensors[index+1],MPS[index+1], workmemBIS, workmem); } if ( owner_absigma == MPIRANK ){ tempQ->AddTermsAB(Atensors[index+1][cnt2+1][0], Btensors[index+1][cnt2+1][0], MPS[index+1], workmemBIS, workmem); } if ( owner_cdf == MPIRANK ){ tempQ->AddTermsCD(Ctensors[index+1][cnt2+1][0], Dtensors[index+1][cnt2+1][0], MPS[index+1], workmemBIS, workmem); } delete [] workmemBIS; //Add everything to owner_q's Qtensors[index][cnt2]: replace later with custom communication group? int inc = 1; int arraysize = tempQ->gKappa2index(tempQ->gNKappa()); double alpha = 1.0; if ( owner_q == MPIRANK ){ dcopy_(&arraysize, tempQ->gStorage(), &inc, Qtensors[index][cnt2]->gStorage(), &inc); } if ( owner_q != owner_absigma ){ MPIchemps2::sendreceive_tensor( tempQ, owner_absigma, owner_q, 2*siteindex ); if ( owner_q == MPIRANK ){ daxpy_(&arraysize, &alpha, tempQ->gStorage(), &inc, Qtensors[index][cnt2]->gStorage(), &inc); } } if (( owner_q != owner_cdf ) && ( owner_absigma != owner_cdf )){ MPIchemps2::sendreceive_tensor( tempQ, owner_cdf, owner_q, 2*siteindex+1 ); if ( owner_q == MPIRANK ){ daxpy_(&arraysize, &alpha, tempQ->gStorage(), &inc, Qtensors[index][cnt2]->gStorage(), &inc); } } delete tempQ; } } #endif } } delete [] workmem; } //Xtensors #ifdef CHEMPS2_MPI_COMPILATION const int owner_x = MPIchemps2::owner_x(); #endif if ( index == L-2 ){ #ifdef CHEMPS2_MPI_COMPILATION if ( owner_x == MPIRANK ) #endif { Xtensors[index]->update(MPS[index+1]); } } else { #ifdef CHEMPS2_MPI_COMPILATION //Make sure that owner_x has all required tensors to construct X. Not as optimal as Q-tensor case, but easier hack. const int owner_q = MPIchemps2::owner_q( L, index+1 ); const int owner_absigma = MPIchemps2::owner_absigma( index+1, index+1 ); const int owner_cdf = MPIchemps2::owner_cdf( L, index+1, index+1 ); const int Idiff = Irreps::directProd( denBK->gIrrep(index+1), denBK->gIrrep(index+1) ); // Will be num ^ num --> 0 if ( owner_x != owner_q ){ if ( owner_x == MPIRANK ){ Qtensors[index+1][0] = new TensorQ( index+2, denBK->gIrrep(index+1), false, denBK, Prob, index+1 ); } if (( owner_x == MPIRANK ) || ( owner_q == MPIRANK )){ MPIchemps2::sendreceive_tensor( Qtensors[index+1][0], owner_q, owner_x, 3*L+3 ); } } if ( owner_x != owner_absigma ){ if ( owner_x == MPIRANK ){ Atensors[index+1][0][0] = new TensorA( index+2, Idiff, false, denBK ); } if (( owner_x == MPIRANK ) || ( owner_absigma == MPIRANK )){ MPIchemps2::sendreceive_tensor( Atensors[index+1][0][0], owner_absigma, owner_x, 3*L+4 ); } } if ( owner_x != owner_cdf ){ if ( owner_x == MPIRANK ){ Ctensors[index+1][0][0] = new TensorC( index+2, Idiff, false, denBK ); Dtensors[index+1][0][0] = new TensorD( index+2, Idiff, false, denBK ); } if (( owner_x == MPIRANK ) || ( owner_cdf == MPIRANK )){ MPIchemps2::sendreceive_tensor( Ctensors[index+1][0][0], owner_cdf, owner_x, 3*L+5 ); MPIchemps2::sendreceive_tensor( Dtensors[index+1][0][0], owner_cdf, owner_x, 3*L+6 ); } } if ( owner_x == MPIRANK ){ #endif Xtensors[index]->update(MPS[index+1], Ltensors[index+1], Xtensors[index+1], Qtensors[index+1][0], Atensors[index+1][0][0], Ctensors[index+1][0][0], Dtensors[index+1][0][0]); #ifdef CHEMPS2_MPI_COMPILATION if ( owner_x != owner_q ){ delete Qtensors[index+1][0]; } if ( owner_x != owner_absigma ){ delete Atensors[index+1][0][0]; } if ( owner_x != owner_cdf ){ delete Ctensors[index+1][0][0]; delete Dtensors[index+1][0][0]; } } #endif } //Otensors if (Exc_activated){ for (int state=0; stateupdate(Exc_MPSs[state][index+1],MPS[index+1]); } else { Exc_Overlaps[state][index]->update(Exc_MPSs[state][index+1],MPS[index+1],Exc_Overlaps[state][index+1]); } } } } gettimeofday(&end, NULL); timings[ CHEMPS2_TIME_TENS_CALC ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); } void CheMPS2::DMRG::allocateTensors(const int index, const bool movingRight){ struct timeval start, end; gettimeofday(&start, NULL); #ifdef CHEMPS2_MPI_COMPILATION const int MPIRANK = MPIchemps2::mpi_rank(); #endif if (movingRight){ //Ltensors : all processes own all Ltensors //To right: Ltens[cnt][cnt2] = operator on site cnt-cnt2; at boundary cnt+1 Ltensors[index] = new TensorL * [index+1]; for (int cnt2=0; cnt2<(index+1) ; cnt2++){ Ltensors[index][cnt2] = new TensorL(index+1,denBK->gIrrep(index-cnt2),movingRight,denBK); } //Two-operator tensors : certain processes own certain two-operator tensors //To right: F0tens[cnt][cnt2][cnt3] = operators on sites cnt-cnt3-cnt2 and cnt-cnt3; at boundary cnt+1 F0tensors[index] = new TensorF0 ** [index+1]; F1tensors[index] = new TensorF1 ** [index+1]; S0tensors[index] = new TensorS0 ** [index+1]; S1tensors[index] = new TensorS1 ** [index+1]; for (int cnt2=0; cnt2<(index+1); cnt2++){ F0tensors[index][cnt2] = new TensorF0 * [index-cnt2+1]; F1tensors[index][cnt2] = new TensorF1 * [index-cnt2+1]; S0tensors[index][cnt2] = new TensorS0 * [index-cnt2+1]; if (cnt2>0){ S1tensors[index][cnt2] = new TensorS1 * [index-cnt2+1]; } for (int cnt3=0; cnt3<(index-cnt2+1); cnt3++){ const int Iprod = Irreps::directProd(denBK->gIrrep(index-cnt2-cnt3),denBK->gIrrep(index-cnt3)); #ifdef CHEMPS2_MPI_COMPILATION if (( cnt3 == 0 ) || ( MPIchemps2::owner_cdf(L, index-cnt2-cnt3, index-cnt3) == MPIRANK )){ #endif F0tensors[index][cnt2][cnt3] = new TensorF0(index+1,Iprod,movingRight,denBK); F1tensors[index][cnt2][cnt3] = new TensorF1(index+1,Iprod,movingRight,denBK); #ifdef CHEMPS2_MPI_COMPILATION } else { F0tensors[index][cnt2][cnt3] = NULL; F1tensors[index][cnt2][cnt3] = NULL; } if (( cnt3 == 0 ) || ( MPIchemps2::owner_absigma(index-cnt2-cnt3, index-cnt3) == MPIRANK )){ #endif S0tensors[index][cnt2][cnt3] = new TensorS0(index+1,Iprod,movingRight,denBK); if (cnt2>0){ S1tensors[index][cnt2][cnt3] = new TensorS1(index+1,Iprod,movingRight,denBK); } #ifdef CHEMPS2_MPI_COMPILATION } else { S0tensors[index][cnt2][cnt3] = NULL; if (cnt2>0){ S1tensors[index][cnt2][cnt3] = NULL; } } #endif } } //Complementary two-operator tensors : certain processes own certain complementary two-operator tensors //To right: Atens[cnt][cnt2][cnt3] = operators on sites cnt+1+cnt3 and cnt+1+cnt2+cnt3; at boundary cnt+1 Atensors[index] = new TensorA ** [L-1-index]; Btensors[index] = new TensorB ** [L-1-index]; Ctensors[index] = new TensorC ** [L-1-index]; Dtensors[index] = new TensorD ** [L-1-index]; for (int cnt2=0; cnt20){ Btensors[index][cnt2] = new TensorB * [L-1-index-cnt2]; } Ctensors[index][cnt2] = new TensorC * [L-1-index-cnt2]; Dtensors[index][cnt2] = new TensorD * [L-1-index-cnt2]; for (int cnt3=0; cnt3gIrrep(index+1+cnt2+cnt3),denBK->gIrrep(index+1+cnt3)); #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_absigma(index+1+cnt3, index+1+cnt2+cnt3) == MPIRANK ){ #endif Atensors[index][cnt2][cnt3] = new TensorA(index+1,Idiff,movingRight,denBK); if (cnt2>0){ Btensors[index][cnt2][cnt3] = new TensorB(index+1,Idiff,movingRight,denBK); } #ifdef CHEMPS2_MPI_COMPILATION } else { Atensors[index][cnt2][cnt3] = NULL; if (cnt2>0){ Btensors[index][cnt2][cnt3] = NULL; } } if ( MPIchemps2::owner_cdf(L, index+1+cnt3, index+1+cnt2+cnt3) == MPIRANK ){ #endif Ctensors[index][cnt2][cnt3] = new TensorC(index+1,Idiff,movingRight,denBK); Dtensors[index][cnt2][cnt3] = new TensorD(index+1,Idiff,movingRight,denBK); #ifdef CHEMPS2_MPI_COMPILATION } else { Ctensors[index][cnt2][cnt3] = NULL; Dtensors[index][cnt2][cnt3] = NULL; } #endif } } //Qtensors //To right: Qtens[cnt][cnt2] = operator on site cnt+1+cnt2; at boundary cnt+1 Qtensors[index] = new TensorQ * [L-1-index]; for (int cnt2=0; cnt2gIrrep(index+1+cnt2),movingRight,denBK,Prob,index+1+cnt2); #ifdef CHEMPS2_MPI_COMPILATION } else { Qtensors[index][cnt2] = NULL; } #endif } //Xtensors : a certain process owns the Xtensors #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_x() == MPIRANK ){ #endif Xtensors[index] = new TensorX(index+1,movingRight,denBK,Prob); #ifdef CHEMPS2_MPI_COMPILATION } else { Xtensors[index] = NULL; } #endif //Otensors : certain processes own certain excitations if (Exc_activated){ for (int state=0; stategIrrep(index+1+cnt2),movingRight,denBK); } //Two-operator tensors : certain processes own certain two-operator tensors //To left: F0tens[cnt][cnt2][cnt3] = operators on sites cnt+1+cnt3 and cnt+1+cnt3+cnt2; at boundary cnt+1 F0tensors[index] = new TensorF0 ** [L-1-index]; F1tensors[index] = new TensorF1 ** [L-1-index]; S0tensors[index] = new TensorS0 ** [L-1-index]; S1tensors[index] = new TensorS1 ** [L-1-index]; for (int cnt2=0; cnt20){ S1tensors[index][cnt2] = new TensorS1 * [L-1-index-cnt2]; } for (int cnt3=0; cnt3gIrrep(index+1+cnt3),denBK->gIrrep(index+1+cnt2+cnt3)); #ifdef CHEMPS2_MPI_COMPILATION if (( cnt3 == 0 ) || ( MPIchemps2::owner_cdf(L, index+1+cnt3, index+1+cnt2+cnt3) == MPIRANK )){ #endif F0tensors[index][cnt2][cnt3] = new TensorF0(index+1,Iprod,movingRight,denBK); F1tensors[index][cnt2][cnt3] = new TensorF1(index+1,Iprod,movingRight,denBK); #ifdef CHEMPS2_MPI_COMPILATION } else { F0tensors[index][cnt2][cnt3] = NULL; F1tensors[index][cnt2][cnt3] = NULL; } if (( cnt3 == 0 ) || ( MPIchemps2::owner_absigma(index+1+cnt3, index+1+cnt2+cnt3) == MPIRANK )){ #endif S0tensors[index][cnt2][cnt3] = new TensorS0(index+1,Iprod,movingRight,denBK); if (cnt2>0){ S1tensors[index][cnt2][cnt3] = new TensorS1(index+1,Iprod,movingRight,denBK); } #ifdef CHEMPS2_MPI_COMPILATION } else { S0tensors[index][cnt2][cnt3] = NULL; if (cnt2>0){ S1tensors[index][cnt2][cnt3] = NULL; } } #endif } } //Complementary two-operator tensors : certain processes own certain complementary two-operator tensors //To left: Atens[cnt][cnt2][cnt3] = operators on sites cnt-cnt2-cnt3 and cnt-cnt3; at boundary cnt+1 Atensors[index] = new TensorA ** [index+1]; Btensors[index] = new TensorB ** [index+1]; Ctensors[index] = new TensorC ** [index+1]; Dtensors[index] = new TensorD ** [index+1]; for (int cnt2=0; cnt20){ Btensors[index][cnt2] = new TensorB * [index + 1 - cnt2]; } Ctensors[index][cnt2] = new TensorC * [index + 1 - cnt2]; Dtensors[index][cnt2] = new TensorD * [index + 1 - cnt2]; for (int cnt3=0; cnt3gIrrep(index-cnt2-cnt3),denBK->gIrrep(index-cnt3)); #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_absigma(index-cnt2-cnt3, index-cnt3) == MPIRANK ){ #endif Atensors[index][cnt2][cnt3] = new TensorA(index+1,Idiff,movingRight,denBK); if (cnt2>0){ Btensors[index][cnt2][cnt3] = new TensorB(index+1,Idiff,movingRight,denBK); } #ifdef CHEMPS2_MPI_COMPILATION } else { Atensors[index][cnt2][cnt3] = NULL; if (cnt2>0){ Btensors[index][cnt2][cnt3] = NULL; } } if ( MPIchemps2::owner_cdf(L, index-cnt2-cnt3, index-cnt3) == MPIRANK ){ #endif Ctensors[index][cnt2][cnt3] = new TensorC(index+1,Idiff,movingRight,denBK); Dtensors[index][cnt2][cnt3] = new TensorD(index+1,Idiff,movingRight,denBK); #ifdef CHEMPS2_MPI_COMPILATION } else { Ctensors[index][cnt2][cnt3] = NULL; Dtensors[index][cnt2][cnt3] = NULL; } #endif } } //Qtensors : certain processes own certain Qtensors //To left: Qtens[cnt][cnt2] = operator on site cnt-cnt2; at boundary cnt+1 Qtensors[index] = new TensorQ*[index+1]; for (int cnt2=0; cnt2gIrrep(index-cnt2),movingRight,denBK,Prob,index-cnt2); #ifdef CHEMPS2_MPI_COMPILATION } else { Qtensors[index][cnt2] = NULL; } #endif } //Xtensors : a certain process owns the Xtensors #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_x() == MPIRANK ){ #endif Xtensors[index] = new TensorX(index+1,movingRight,denBK,Prob); #ifdef CHEMPS2_MPI_COMPILATION } else { Xtensors[index] = NULL; } #endif //Otensors : certain processes own certain excitations if (Exc_activated){ for (int state=0; stategKappa2index(batch[cnt]->gNKappa()); if ( tensor_size > 0 ){ const hsize_t start = offset; const hsize_t count = tensor_size; H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET, &start, NULL, &count, NULL); const hid_t memspace_id = H5Screate_simple(1, &count, NULL); H5Dread(dataset_id, H5T_NATIVE_DOUBLE, memspace_id, dataspace_id, H5P_DEFAULT, batch[cnt]->gStorage()); H5Sclose(memspace_id); offset += tensor_size; } } H5Dclose(dataset_id); H5Sclose(dataspace_id); H5Gclose(group_id); assert( totalsize == offset ); num_double_read_disk += totalsize; } void CheMPS2::DMRG::MY_HDF5_WRITE_BATCH( const hid_t file_id, const int number, Tensor ** batch, const long long totalsize, const std::string tag ){ const hid_t group_id = H5Gcreate(file_id, tag.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); const hsize_t dimarray = totalsize; const hid_t dataspace_id = H5Screate_simple(1, &dimarray, NULL); const hid_t dataset_id = H5Dcreate(group_id, "storage", H5T_NATIVE_DOUBLE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* Switch from H5T_IEEE_F64LE to H5T_NATIVE_DOUBLE to avoid processing of the doubles --> only MPS checkpoint is reused in between calculations anyway */ long long offset = 0; for (int cnt=0; cntgKappa2index(batch[cnt]->gNKappa()); if ( tensor_size > 0 ){ const hsize_t start = offset; const hsize_t count = tensor_size; H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET, &start, NULL, &count, NULL); const hid_t memspace_id = H5Screate_simple(1, &count, NULL); H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, memspace_id, dataspace_id, H5P_DEFAULT, batch[cnt]->gStorage()); H5Sclose(memspace_id); offset += tensor_size; } } H5Dclose(dataset_id); H5Sclose(dataspace_id); H5Gclose(group_id); assert( totalsize == offset ); num_double_write_disk += totalsize; } void CheMPS2::DMRG::OperatorsOnDisk(const int index, const bool movingRight, const bool store){ /* By working with hyperslabs and batches of tensors, there are exactly 11 groups which need to be written to the file ( 12 when there are excitations ). */ struct timeval start, end; gettimeofday(&start, NULL); const int Nbound = movingRight ? index+1 : L-1-index; const int Cbound = movingRight ? L-1-index : index+1; #ifdef CHEMPS2_MPI_COMPILATION const int MPIRANK = MPIchemps2::mpi_rank(); #endif std::stringstream thefilename; //The PID is different for each MPI process thefilename << tempfolder << "/" << CheMPS2::DMRG_OPERATOR_storage_prefix << thePID << "_index_" << index << ".h5"; //The hdf5 file const hid_t file_id = ( store ) ? H5Fcreate( thefilename.str().c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ) : H5Fopen( thefilename.str().c_str(), H5F_ACC_RDONLY, H5P_DEFAULT ); //Ltensors : all processes own all Ltensors { long long totalsizeL = 0; Tensor ** batchL = new Tensor*[ Nbound ]; for (int cnt2=0; cnt2gKappa2index(Ltensors[index][cnt2]->gNKappa()); batchL[cnt2] = Ltensors[index][cnt2]; } if ( totalsizeL > 0 ){ const std::string tag = "Ltensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, Nbound, batchL, totalsizeL, tag ); } else{ MY_HDF5_READ_BATCH( file_id, Nbound, batchL, totalsizeL, tag ); } } delete [] batchL; } //Renormalized two-operator tensors : certain processes own certain two-operator tensors { long long totalsizeF0 = 0; int numF0 = 0; Tensor ** batchF0 = new Tensor*[ (Nbound*(Nbound + 1))/2 ]; long long totalsizeF1 = 0; int numF1 = 0; Tensor ** batchF1 = new Tensor*[ (Nbound*(Nbound + 1))/2 ]; long long totalsizeS0 = 0; int numS0 = 0; Tensor ** batchS0 = new Tensor*[ (Nbound*(Nbound + 1))/2 ]; long long totalsizeS1 = 0; int numS1 = 0; Tensor ** batchS1 = new Tensor*[ (Nbound*(Nbound + 1))/2 ]; for (int cnt2=0; cnt2gKappa2index(batchF0[numF0]->gNKappa()); numF0++; batchF1[numF1] = F1tensors[index][cnt2][cnt3]; totalsizeF1 += batchF1[numF1]->gKappa2index(batchF1[numF1]->gNKappa()); numF1++; } #ifdef CHEMPS2_MPI_COMPILATION if (( cnt3 == 0 ) || ( MPIchemps2::owner_absigma(siteindex1, siteindex2) == MPIRANK )) #endif { batchS0[numS0] = S0tensors[index][cnt2][cnt3]; totalsizeS0 += batchS0[numS0]->gKappa2index(batchS0[numS0]->gNKappa()); numS0++; if (cnt2>0){ batchS1[numS1] = S1tensors[index][cnt2][cnt3]; totalsizeS1 += batchS1[numS1]->gKappa2index(batchS1[numS1]->gNKappa()); numS1++; } } } } if ( totalsizeF0 > 0 ){ const std::string tag = "F0tensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numF0, batchF0, totalsizeF0, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numF0, batchF0, totalsizeF0, tag ); } } if ( totalsizeF1 > 0 ){ const std::string tag = "F1tensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numF1, batchF1, totalsizeF1, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numF1, batchF1, totalsizeF1, tag ); } } if ( totalsizeS0 > 0 ){ const std::string tag = "S0tensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numS0, batchS0, totalsizeS0, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numS0, batchS0, totalsizeS0, tag ); } } if ( totalsizeS1 > 0 ){ const std::string tag = "S1tensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numS1, batchS1, totalsizeS1, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numS1, batchS1, totalsizeS1, tag ); } } delete [] batchF0; delete [] batchF1; delete [] batchS0; delete [] batchS1; } //Complementary two-operator tensors : certain processes own certain complementary two-operator tensors { long long totalsizeA = 0; int numA = 0; Tensor ** batchA = new Tensor*[ (Cbound*(Cbound + 1))/2 ]; long long totalsizeB = 0; int numB = 0; Tensor ** batchB = new Tensor*[ (Cbound*(Cbound + 1))/2 ]; long long totalsizeC = 0; int numC = 0; Tensor ** batchC = new Tensor*[ (Cbound*(Cbound + 1))/2 ]; long long totalsizeD = 0; int numD = 0; Tensor ** batchD = new Tensor*[ (Cbound*(Cbound + 1))/2 ]; for (int cnt2=0; cnt2gKappa2index(batchA[numA]->gNKappa()); numA++; if (cnt2>0){ batchB[numB] = Btensors[index][cnt2][cnt3]; totalsizeB += batchB[numB]->gKappa2index(batchB[numB]->gNKappa()); numB++; } } #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_cdf(L, siteindex1, siteindex2) == MPIRANK ) #endif { batchC[numC] = Ctensors[index][cnt2][cnt3]; totalsizeC += batchC[numC]->gKappa2index(batchC[numC]->gNKappa()); numC++; batchD[numD] = Dtensors[index][cnt2][cnt3]; totalsizeD += batchD[numD]->gKappa2index(batchD[numD]->gNKappa()); numD++; } } } if ( totalsizeA > 0 ){ const std::string tag = "Atensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numA, batchA, totalsizeA, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numA, batchA, totalsizeA, tag ); } } if ( totalsizeB > 0 ){ const std::string tag = "Btensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numB, batchB, totalsizeB, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numB, batchB, totalsizeB, tag ); } } if ( totalsizeC > 0 ){ const std::string tag = "Ctensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numC, batchC, totalsizeC, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numC, batchC, totalsizeC, tag ); } } if ( totalsizeD > 0 ){ const std::string tag = "Dtensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numD, batchD, totalsizeD, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numD, batchD, totalsizeD, tag ); } } delete [] batchA; delete [] batchB; delete [] batchC; delete [] batchD; } //Complementary Q-tensors : certain processes own certain complementary Q-tensors { long long totalsizeQ = 0; int numQ = 0; Tensor ** batchQ = new Tensor*[ Cbound ]; for (int cnt2=0; cnt2gKappa2index(batchQ[numQ]->gNKappa()); numQ++; } } if ( totalsizeQ > 0 ){ const std::string tag = "Qtensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numQ, batchQ, totalsizeQ, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numQ, batchQ, totalsizeQ, tag ); } } delete [] batchQ; } //Complementary X-tensor : one process owns the X-tensors #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_x() == MPIRANK ) #endif { Tensor ** batchX = new Tensor*[ 1 ]; const long long totalsizeX = Xtensors[index]->gKappa2index(Xtensors[index]->gNKappa()); batchX[0] = Xtensors[index]; if ( totalsizeX > 0 ){ const std::string tag = "Xtensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, 1, batchX, totalsizeX, tag ); } else{ MY_HDF5_READ_BATCH( file_id, 1, batchX, totalsizeX, tag ); } } delete [] batchX; } //O-tensors : certain processes own certain excitations if (Exc_activated){ long long totalsizeO = 0; int numO = 0; Tensor ** batchO = new Tensor*[ nStates-1 ]; for (int state=0; stategKappa2index(batchO[numO]->gNKappa()); numO++; } } if ( totalsizeO > 0 ){ const std::string tag = "Otensors"; if ( store ){ MY_HDF5_WRITE_BATCH( file_id, numO, batchO, totalsizeO, tag ); } else{ MY_HDF5_READ_BATCH( file_id, numO, batchO, totalsizeO, tag ); } } delete [] batchO; } H5Fclose(file_id); gettimeofday(&end, NULL); if ( store ){ timings[ CHEMPS2_TIME_DISK_WRITE ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); } else { timings[ CHEMPS2_TIME_DISK_READ ] += (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec); } } void CheMPS2::DMRG::deleteTensors(const int index, const bool movingRight){ struct timeval start, end; gettimeofday(&start, NULL); const int Nbound = movingRight ? index+1 : L-1-index; const int Cbound = movingRight ? L-1-index : index+1; #ifdef CHEMPS2_MPI_COMPILATION const int MPIRANK = MPIchemps2::mpi_rank(); #endif //Ltensors : all processes own all Ltensors for (int cnt2=0; cnt20){ delete S1tensors[index][cnt2][cnt3]; } } } delete [] F0tensors[index][cnt2]; delete [] F1tensors[index][cnt2]; delete [] S0tensors[index][cnt2]; if (cnt2>0){ delete [] S1tensors[index][cnt2]; } } delete [] F0tensors[index]; delete [] F1tensors[index]; delete [] S0tensors[index]; delete [] S1tensors[index]; //Complementary two-operator tensors : certain processes own certain complementary two-operator tensors for (int cnt2=0; cnt20){ delete Btensors[index][cnt2][cnt3]; } } #ifdef CHEMPS2_MPI_COMPILATION if ( MPIchemps2::owner_cdf(L, siteindex1, siteindex2) == MPIRANK ) #endif { delete Ctensors[index][cnt2][cnt3]; delete Dtensors[index][cnt2][cnt3]; } } delete [] Atensors[index][cnt2]; if (cnt2>0){ delete [] Btensors[index][cnt2]; } delete [] Ctensors[index][cnt2]; delete [] Dtensors[index][cnt2]; } delete [] Atensors[index]; delete [] Btensors[index]; delete [] Ctensors[index]; delete [] Dtensors[index]; //Qtensors : certain processes own certain Qtensors for (int cnt2=0; cnt2 #include #include #include #include #include #include #include "DMRG.h" #include "Lapack.h" #include "TensorK.h" #include "TensorM.h" #include "TensorGYZ.h" #include "Gsl.h" #include "Heff.h" #include "MPIchemps2.h" using std::cout; using std::endl; void CheMPS2::DMRG::calc2DMandCorrelations(){ #ifdef CHEMPS2_MPI_COMPILATION const bool am_i_master = ( MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ); #else const bool am_i_master = true; #endif //First get the whole MPS into left-canonical form int index = L-2; Sobject * denS = new Sobject(index,denBK->gIrrep(index),denBK->gIrrep(index+1),denBK); denS->Join(MPS[index],MPS[index+1]); //Each MPI process performs this task. Heff Solver(denBK, Prob); double Energy = 0.0; double ** VeffTilde = NULL; if (Exc_activated){ VeffTilde = prepare_excitations(denS); } //Each MPI process returns the correct energy. Only MPI_CHEMPS2_MASTER has the correct denS solution. Energy = Solver.SolveDAVIDSON(denS, Ltensors, Atensors, Btensors, Ctensors, Dtensors, S0tensors, S1tensors, F0tensors, F1tensors, Qtensors, Xtensors, nStates-1, VeffTilde); if (Exc_activated){ cleanup_excitations(VeffTilde); } Energy += Prob->gEconst(); if (EnergySplit(MPS[index],MPS[index+1],OptScheme->getD(OptScheme->getNInstructions()-1),true,true); delete denS; if ( am_i_master ){ cout << "**************************************" << endl; cout << "** 2DM and Correlations calculation **" << endl; cout << "**************************************" << endl; } updateMovingRightSafe(index); if ( am_i_master ){ TensorDiag * Norm = new TensorDiag(L, denBK); MPS[L-1]->QR(Norm); delete Norm; } #ifdef CHEMPS2_MPI_COMPILATION MPIchemps2::broadcast_tensor(MPS[L-1], MPI_CHEMPS2_MASTER); #endif //Allocate space for the 2DM if (the2DMallocated){ delete the2DM; the2DMallocated = false; } the2DM = new TwoDM(denBK, Prob); the2DMallocated = true; //Then calculate step by step the 2DM for (int siteindex=L-1; siteindex>=0; siteindex--){ //Specific 2-RDM entries are internally added per MPI processes; after which an allreduce is called the2DM->FillSite(MPS[siteindex], Ltensors, F0tensors, F1tensors, S0tensors, S1tensors); if (siteindex>0){ if ( am_i_master ){ TensorDiag * Left = new TensorDiag(siteindex, denBK); MPS[siteindex]->LQ(Left); MPS[siteindex-1]->RightMultiply(Left); delete Left; } #ifdef CHEMPS2_MPI_COMPILATION MPIchemps2::broadcast_tensor(MPS[siteindex], MPI_CHEMPS2_MASTER); MPIchemps2::broadcast_tensor(MPS[siteindex-1], MPI_CHEMPS2_MASTER); #endif updateMovingLeftSafe2DM(siteindex-1); } } #ifdef CHEMPS2_MPI_COMPILATION the2DM->mpi_allreduce(); #endif //Then perform two checks: double trace & energy if ( am_i_master ){ const double NtimesNminus1 = the2DM->doubletrace2DMA(); cout << " N(N-1) = " << denBK->gN() * (denBK->gN() - 1) << " and calculated by double trace of the 2DM-A = " << NtimesNminus1 << endl; const double Energy2DMA = the2DM->calcEnergy(); cout << " Energy obtained by Heffective at edge = " << Energy << " and as Econst + 0.5*trace(2DM-A*Ham) = " << Energy2DMA << endl; the2DM->printNOON(); } //Now the MPS has the gauge form CRRRRRRRRR //Allocate space for the Correlations if (theCorrAllocated){ delete theCorr; theCorrAllocated = false; } theCorr = new Correlations(denBK, Prob, the2DM); theCorrAllocated = true; //Then calculate step by step the mutual information. //Define the following tensor arrays thereto. The native DMRG ones are at the edge and are hence small. TensorGYZ ** Gtensors = ( am_i_master ) ? new TensorGYZ*[L-1] : NULL; TensorGYZ ** Ytensors = ( am_i_master ) ? new TensorGYZ*[L-1] : NULL; TensorGYZ ** Ztensors = ( am_i_master ) ? new TensorGYZ*[L-1] : NULL; TensorK ** Ktensors = ( am_i_master ) ? new TensorK *[L-1] : NULL; TensorM ** Mtensors = ( am_i_master ) ? new TensorM *[L-1] : NULL; //Do the actual work for (int siteindex=1; siteindexQR(Right); MPS[siteindex]->LeftMultiply(Right); delete Right; } #ifdef CHEMPS2_MPI_COMPILATION MPIchemps2::broadcast_tensor(MPS[siteindex-1], MPI_CHEMPS2_MASTER); MPIchemps2::broadcast_tensor(MPS[siteindex], MPI_CHEMPS2_MASTER); #endif if ( am_i_master ){ //Update the tensors const int dimL = denBK->gMaxDimAtBound(siteindex-1); const int dimR = denBK->gMaxDimAtBound(siteindex); double * workmemLR = new double[dimL*dimR]; for (int previousindex=0; previousindexgIrrep(previousindex), denBK); TensorM * newM = new TensorM(siteindex, denBK->gIrrep(previousindex), denBK); newG->update(MPS[siteindex-1], Gtensors[previousindex], workmemLR); newY->update(MPS[siteindex-1], Ytensors[previousindex], workmemLR); newZ->update(MPS[siteindex-1], Ztensors[previousindex], workmemLR); newK->update(Ktensors[previousindex], MPS[siteindex-1], workmemLR, false); newM->update(Mtensors[previousindex], MPS[siteindex-1], workmemLR, false); delete Gtensors[previousindex]; delete Ytensors[previousindex]; delete Ztensors[previousindex]; delete Ktensors[previousindex]; delete Mtensors[previousindex]; Gtensors[previousindex] = newG; Ytensors[previousindex] = newY; Ztensors[previousindex] = newZ; Ktensors[previousindex] = newK; Mtensors[previousindex] = newM; } delete [] workmemLR; //Construct the new tensors Gtensors[siteindex-1] = new TensorGYZ(siteindex, 'G', denBK); Ytensors[siteindex-1] = new TensorGYZ(siteindex, 'Y', denBK); Ztensors[siteindex-1] = new TensorGYZ(siteindex, 'Z', denBK); Ktensors[siteindex-1] = new TensorK(siteindex, denBK->gIrrep(siteindex-1), denBK); Mtensors[siteindex-1] = new TensorM(siteindex, denBK->gIrrep(siteindex-1), denBK); Gtensors[siteindex-1]->construct(MPS[siteindex-1]); Ytensors[siteindex-1]->construct(MPS[siteindex-1]); Ztensors[siteindex-1]->construct(MPS[siteindex-1]); Ktensors[siteindex-1]->construct(MPS[siteindex-1]); Mtensors[siteindex-1]->construct(MPS[siteindex-1]); //Process MPI_CHEMPS2_MASTER actually fills the sites; and broadcasts the results to the MPI_COMM_WORLD theCorr->FillSite(MPS[siteindex], Gtensors, Ytensors, Ztensors, Ktensors, Mtensors); } } #ifdef CHEMPS2_MPI_COMPILATION theCorr->mpi_broadcast(); #endif if ( am_i_master ){ //Clean-up for (int previousindex=0; previousindexSingleOrbitalEntropy_HAM(index) << " , "; } cout << theCorr->SingleOrbitalEntropy_HAM(L-1) << " ]." << endl; for (int power=0; power<=2; power++){ cout << " Idistance(" << power << ") = " << theCorr->MutualInformationDistance((double)power) << endl; } cout << "**************************************" << endl; } } double CheMPS2::DMRG::getSpecificCoefficient(int * coeff) const{ int * alpha = new int[ L ]; int * beta = new int[ L ]; for ( int orb=0; orb= 0 ) && ( coeff[orb] <= 2 ) ); if ( coeff[orb] == 0 ){ alpha[orb] = 0; beta[orb] = 0; } if ( coeff[orb] == 1 ){ alpha[orb] = 1; beta[orb] = 0; } if ( coeff[orb] == 2 ){ alpha[orb] = 1; beta[orb] = 1; } } const double FCIcoeff = getFCIcoefficient( alpha, beta ); delete [] alpha; delete [] beta; return FCIcoeff; } double CheMPS2::DMRG::getFCIcoefficient(int * alpha, int * beta, const bool mpi_chemps2_master_only) const{ //DMRGcoeff = alpha/beta[Hamindex = Prob->gf2(DMRGindex)] //Check if it's possible { int nTot = 0; int twoSz = 0; int iTot = 0; for (int DMRGindex=0; DMRGindexgReorderD2h()) ? Prob->gf2(DMRGindex) : DMRGindex; assert( ( alpha[HamIndex] == 0 ) || ( alpha[HamIndex] == 1 ) ); assert( ( beta[HamIndex] == 0 ) || ( beta[HamIndex] == 1 ) ); nTot += alpha[HamIndex] + beta[HamIndex]; twoSz += alpha[HamIndex] - beta[HamIndex]; if ((alpha[HamIndex]+beta[HamIndex])==1){ iTot = Irreps::directProd(iTot,denBK->gIrrep(DMRGindex)); } } if ( Prob->gN() != nTot ){ cout << "DMRG::getFCIcoefficient : Ndesired = " << Prob->gN() << " and Ntotal in alpha and beta strings = " << nTot << endl; return 0.0; } // 2Sz can be -Prob->2S() ; -Prob->2S()+2 ; -Prob->2S()+4 ; ... ; Prob->2S() if ( ( Prob->gTwoS() < twoSz ) || ( twoSz < -Prob->gTwoS() ) || ( ( Prob->gTwoS() - twoSz ) % 2 != 0 ) ){ cout << "DMRG::getFCIcoefficient : 2Sdesired = " << Prob->gTwoS() << " and Sz in alpha and beta strings = " << twoSz << endl; return 0.0; } if ( Prob->gIrrep() != iTot ){ cout << "DMRG::getFCIcoefficient : Idesired = " << Prob->gIrrep() << " and Irrep of alpha and beta strings = " << iTot << endl; return 0.0; } } double theCoeff = 2.0; // A FCI coefficient always lies in between -1.0 and 1.0 #ifdef CHEMPS2_MPI_COMPILATION if (( MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ) || ( mpi_chemps2_master_only == false )) #endif { //Construct necessary arrays int Dmax = 1; for (int DMRGindex=1; DMRGindexgTotDimAtBound(DMRGindex); if (DtotBound>Dmax){ Dmax = DtotBound; } } double * arrayL = new double[Dmax]; double * arrayR = new double[Dmax]; int * twoSL = new int[L]; int * twoSR = new int[L]; int * jumpL = new int[L+1]; int * jumpR = new int[L+1]; //Start the iterator int num_SL = 0; jumpL[num_SL] = 0; int dimFirst = 1; jumpL[num_SL+1] = jumpL[num_SL] + dimFirst; twoSL[num_SL] = 0; num_SL++; arrayL[0] = 1.0; int NL = 0; int IL = 0; int twoSLz = 0; for (int DMRGindex=0; DMRGindexgReorderD2h()) ? Prob->gf2(DMRGindex) : DMRGindex; const int Nlocal = alpha[HamIndex] + beta[HamIndex]; const int twoSzloc = alpha[HamIndex] - beta[HamIndex]; //The right symmetry sectors const int NR = NL + Nlocal; const int twoSRz = twoSLz + twoSzloc; const int IR = (( Nlocal == 1 ) ? (Irreps::directProd(IL,denBK->gIrrep(DMRGindex))) : IL); int num_SR = 0; jumpR[num_SR] = 0; const int spread = ( ( Nlocal == 1 ) ? 1 : 0 ); for ( int cntSL = 0; cntSL < num_SL; cntSL++ ){ for ( int TwoSRattempt = twoSL[cntSL] - spread; TwoSRattempt <= twoSL[cntSL] + spread; TwoSRattempt+=2 ){ bool encountered = false; for ( int cntSR = 0; cntSR < num_SR; cntSR++ ){ if ( twoSR[cntSR] == TwoSRattempt ){ encountered = true; } } if ( encountered == false ){ const int dimR = denBK->gCurrentDim(DMRGindex+1,NR,TwoSRattempt,IR); if ( dimR > 0 ){ jumpR[num_SR+1] = jumpR[num_SR] + dimR; twoSR[num_SR] = TwoSRattempt; num_SR++; } } } } assert( jumpR[num_SR] <= Dmax ); for ( int cntSR = 0; cntSR < num_SR; cntSR++ ){ int TwoSRvalue = twoSR[ cntSR ]; int dimR = jumpR[ cntSR+1 ] - jumpR[ cntSR ]; for ( int TwoSLvalue = TwoSRvalue - spread; TwoSLvalue <= TwoSRvalue + spread; TwoSLvalue += 2 ){ int indexSL = -1; for ( int cntSL = 0; cntSL < num_SL; cntSL++ ){ if ( twoSL[cntSL] == TwoSLvalue ){ indexSL = cntSL; cntSL = num_SL; //exit loop } } if ( indexSL != -1 ){ int dimL = jumpL[ indexSL+1 ] - jumpL[ indexSL ]; double * Tblock = MPS[DMRGindex]->gStorage(NL,TwoSLvalue,IL,NR,TwoSRvalue,IR); double prefactor = sqrt( TwoSRvalue + 1 ) * gsl_sf_coupling_3j(TwoSLvalue, spread, TwoSRvalue, twoSLz, twoSzloc, -twoSRz) * Heff::phase( -TwoSLvalue + spread - twoSRz ); double add2array = 1.0; char notrans = 'N'; dgemm_( ¬rans, ¬rans, &dimFirst, &dimR, &dimL, &prefactor, arrayL + jumpL[indexSL], &dimFirst, Tblock, &dimL, &add2array, arrayR + jumpR[cntSR], &dimFirst); } } } //Swap L <--> R { double * temp = arrayR; arrayR = arrayL; arrayL = temp; int * temp2 = twoSR; twoSR = twoSL; twoSL = temp2; temp2 = jumpR; jumpR = jumpL; jumpL = temp2; num_SL = num_SR; NL = NR; IL = IR; twoSLz = twoSRz; } } theCoeff = arrayL[0]; assert( num_SL == 1 ); assert( jumpL[1] == 1 ); assert( twoSL[0] == Prob->gTwoS() ); assert( NL == Prob->gN() ); assert( IL == Prob->gIrrep() ); delete [] arrayL; delete [] arrayR; delete [] twoSL; delete [] twoSR; delete [] jumpL; delete [] jumpR; } #ifdef CHEMPS2_MPI_COMPILATION if ( mpi_chemps2_master_only ){ MPIchemps2::broadcast_array_double( &theCoeff, 1, MPI_CHEMPS2_MASTER ); } #endif return theCoeff; } double ** CheMPS2::DMRG::prepare_excitations(Sobject * denS){ double ** VeffTilde = new double*[nStates-1]; for (int state=0; stategKappa2index(denS->gNKappa())]; calcVeffTilde(VeffTilde[state], denS, state); #ifdef CHEMPS2_MPI_COMPILATION } else { VeffTilde[state] = NULL; } #endif } return VeffTilde; } void CheMPS2::DMRG::cleanup_excitations(double ** VeffTilde) const{ for (int state=0; stategKappa2index(currentS->gNKappa()); for (int cnt=0; cntgIndex(); const int dimL = std::max(denBK->gMaxDimAtBound(index), Exc_BKs[state_number]->gMaxDimAtBound(index) ); const int dimR = std::max(denBK->gMaxDimAtBound(index+2), Exc_BKs[state_number]->gMaxDimAtBound(index+2) ); double * workmem = new double[dimL * dimR]; //Construct Sup Sobject * Sup = new Sobject(index,Exc_BKs[state_number]->gIrrep(index),Exc_BKs[state_number]->gIrrep(index+1),Exc_BKs[state_number]); Sup->Join(Exc_MPSs[state_number][index],Exc_MPSs[state_number][index+1]); //Construct VeffTilde const double prefactor = sqrt(Exc_Eshifts[state_number]) / (Prob->gTwoS() + 1.0); for (int ikappa=0; ikappagNKappa(); ikappa++){ int NL = currentS->gNL(ikappa); int TwoSL = currentS->gTwoSL(ikappa); int IL = currentS->gIL(ikappa); int N1 = currentS->gN1(ikappa); int N2 = currentS->gN2(ikappa); int TwoJ = currentS->gTwoJ(ikappa); int NR = currentS->gNR(ikappa); int TwoSR = currentS->gTwoSR(ikappa); int IR = currentS->gIR(ikappa); //Check if block also exists for other MPS int kappaSup = Sup->gKappa(NL, TwoSL, IL, N1, N2, TwoJ, NR, TwoSR, IR); if (kappaSup!=-1){ int dimLdown = denBK->gCurrentDim(index, NL,TwoSL,IL); int dimLup = Exc_BKs[state_number]->gCurrentDim(index, NL,TwoSL,IL); int dimRdown = denBK->gCurrentDim(index+2,NR,TwoSR,IR); int dimRup = Exc_BKs[state_number]->gCurrentDim(index+2,NR,TwoSR,IR); //Do sqrt( (TwoJR+1) * Eshift ) / (TwoStarget+1) times (OL * Sup)_{block} --> workmem double * SupPart = Sup->gStorage() + Sup->gKappa2index(kappaSup); double alpha = prefactor * sqrt(TwoSR+1.0); if (index==0){ int dimBlock = dimLup * dimRup; int inc = 1; dcopy_(&dimBlock,SupPart,&inc,workmem,&inc); dscal_(&dimBlock,&alpha,workmem,&inc); } else { char notrans = 'N'; double beta = 0.0; double * Opart = Exc_Overlaps[state_number][index-1]->gStorage(NL,TwoSL,IL,NL,TwoSL,IL); dgemm_(¬rans,¬rans,&dimLdown,&dimRup,&dimLup,&alpha,Opart,&dimLdown,SupPart,&dimLup,&beta,workmem,&dimLdown); } //Do (workmem * OR)_{block} --> result + jumpCurrentS int jumpCurrentS = currentS->gKappa2index(ikappa); if (index==L-2){ int dimBlock = dimLdown * dimRdown; int inc = 1; dcopy_(&dimBlock, workmem, &inc, result + jumpCurrentS, &inc); } else { char trans = 'T'; char notrans = 'N'; alpha = 1.0; double beta = 0.0; //set double * Opart = Exc_Overlaps[state_number][index+1]->gStorage(NR,TwoSR,IR,NR,TwoSR,IR); dgemm_(¬rans,&trans,&dimLdown,&dimRdown,&dimRup,&alpha,workmem,&dimLdown,Opart,&dimRdown,&beta,result+jumpCurrentS,&dimLdown); } } } //Deallocate everything delete Sup; delete [] workmem; } void CheMPS2::DMRG::calcOverlapsWithLowerStates(){ for (int state=0; stateupdate(Exc_MPSs[state][L-1], MPS[L-1], Exc_Overlaps[state][L-2]); overlap = Otemp->gStorage()[0]; delete Otemp; #ifdef CHEMPS2_MPI_COMPILATION } MPIchemps2::broadcast_array_double( &overlap, 1, OWNER ); if ( MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER ) #endif { cout << "The overlap between the current state and state " << state << " is : " << overlap << endl; } if (isAllocated[cnt]==1){ deleteTensors(cnt, true); isAllocated[cnt]=0; } } } CheMPS2-1.6/CheMPS2/Davidson.cpp000066400000000000000000000321531256744172700161600ustar00rootroot00000000000000/* CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry Copyright (C) 2013-2015 Sebastian Wouters 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include "Davidson.h" #include "Lapack.h" using std::cout; using std::endl; CheMPS2::Davidson::Davidson(const int veclength_in, const int MAX_NUM_VEC_in, const int NUM_VEC_KEEP_in, const double RTOL_in, const double DIAG_CUTOFF_in, const bool debugPrint_in){ debugPrint = debugPrint_in; veclength = veclength_in; state = 'I'; // nitialized Davidson nMultiplications = 0; MAX_NUM_VEC = MAX_NUM_VEC_in; NUM_VEC_KEEP = NUM_VEC_KEEP_in; DIAG_CUTOFF = DIAG_CUTOFF_in; RTOL = RTOL_in; // To store the vectors and the matrix x vectors num_vec = 0; vecs = new double*[ MAX_NUM_VEC ]; Hvecs = new double*[ MAX_NUM_VEC ]; num_allocated = 0; // The effective diagonalization problem mxM = new double[ MAX_NUM_VEC * MAX_NUM_VEC ]; mxM_eigs = new double[ MAX_NUM_VEC ]; mxM_vecs = new double[ MAX_NUM_VEC * MAX_NUM_VEC ]; mxM_lwork = 3 * MAX_NUM_VEC - 1; mxM_work = new double[ mxM_lwork ]; // Vector spaces diag = new double[ veclength ]; t_vec = new double[ veclength ]; u_vec = new double[ veclength ]; work_vec = new double[ veclength ]; // For the deflation Reortho_Lowdin = NULL; Reortho_Overlap_eigs = NULL; Reortho_Overlap = NULL; Reortho_Eigenvecs = NULL; } CheMPS2::Davidson::~Davidson(){ for (int cnt = 0; cnt < num_allocated; cnt++){ delete [] vecs[cnt]; delete [] Hvecs[cnt]; } delete [] vecs; delete [] Hvecs; delete [] mxM; delete [] mxM_eigs; delete [] mxM_vecs; delete [] mxM_work; delete [] diag; delete [] t_vec; delete [] u_vec; delete [] work_vec; if ( Reortho_Lowdin != NULL ){ delete [] Reortho_Lowdin; } if ( Reortho_Overlap_eigs != NULL ){ delete [] Reortho_Overlap_eigs; } if ( Reortho_Overlap != NULL ){ delete [] Reortho_Overlap; } if ( Reortho_Eigenvecs != NULL ){ delete [] Reortho_Eigenvecs; } } int CheMPS2::Davidson::GetNumMultiplications() const{ return nMultiplications; } char CheMPS2::Davidson::FetchInstruction(double ** whichpointers){ /* Possible states: - I : just initialized - U : just before the big loop, the initial guess and the diagonal are set - N : a new vector has just been added to the list and a matrix-vector multiplication has been performed - F : the space has been deflated and a few matrix-vector multiplications are required - C : convergence was reached Possible instructions: - A : copy the initial guess to whichpointers[0] and the diagonal to whichpointers[1] - B : perform whichpointers[1] = symmetric matrix times whichpointers[0] - C : copy the converged solution from whichpointers[0] back; whichpointers[1][0] contains the converged energy - D : there was an error */ if ( state == 'I' ){ whichpointers[0] = t_vec; whichpointers[1] = diag; state = 'U'; return 'A'; } if ( state == 'U' ){ SafetyCheckGuess(); AddNewVec(); whichpointers[0] = vecs[ num_vec ]; whichpointers[1] = Hvecs[ num_vec ]; nMultiplications++; state = 'N'; return 'B'; } if ( state == 'N' ){ const double rnorm = DiagonalizeSmallMatrixAndCalcResidual(); if ( rnorm > RTOL ){ // Not yet converged CalculateNewVec(); if ( num_vec == MAX_NUM_VEC ){ Deflation(); whichpointers[0] = vecs[ num_vec ]; whichpointers[1] = Hvecs[ num_vec ]; nMultiplications++; num_vec++; state = 'F'; return 'B'; } AddNewVec(); whichpointers[0] = vecs[ num_vec ]; whichpointers[1] = Hvecs[ num_vec ]; nMultiplications++; state = 'N'; return 'B'; } else { // Converged state = 'C'; whichpointers[0] = u_vec; whichpointers[1] = mxM_eigs; return 'C'; } } if ( state == 'F' ){ if ( num_vec == NUM_VEC_KEEP ){ MxMafterDeflation(); AddNewVec(); whichpointers[0] = vecs[ num_vec ]; whichpointers[1] = Hvecs[ num_vec ]; nMultiplications++; state = 'N'; return 'B'; } else { whichpointers[0] = vecs[ num_vec ]; whichpointers[1] = Hvecs[ num_vec ]; nMultiplications++; num_vec++; state = 'F'; return 'B'; } } return 'D'; } void CheMPS2::Davidson::SafetyCheckGuess(){ char frobenius = 'F'; int inc1 = 1; const double twonorm = dlange_( &frobenius, &veclength, &inc1, t_vec, &veclength, NULL ); // Work is not referenced for Frobenius norm if ( twonorm == 0.0 ){ for (int cnt = 0; cnt < veclength; cnt++){ t_vec[ cnt ] = ((double) rand())/RAND_MAX; } if ( debugPrint ){ cout << "WARNING AT DAVIDSON : Initial guess was a zero-vector. Now it is overwritten with random numbers." << endl; } } } void CheMPS2::Davidson::AddNewVec(){ int inc1 = 1; //1. Orthogonalize the new vector w.r.t. the old basis for (int cnt = 0; cnt < num_vec; cnt++){ double min_overlap = - ddot_( &veclength, t_vec, &inc1, vecs[ cnt ], &inc1 ); daxpy_( &veclength, &min_overlap, vecs[ cnt ], &inc1, t_vec, &inc1 ); } //2. Normalize the new vector char frobenius = 'F'; double alpha = 1.0 / dlange_( &frobenius, &veclength, &inc1, t_vec, &veclength, NULL ); // Work is not referenced for Frobenius norm dscal_( &veclength, &alpha, t_vec, &inc1 ); //3. The new vector becomes part of vecs if ( num_vec < num_allocated ){ double * temp = vecs[ num_vec ]; vecs[ num_vec ] = t_vec; t_vec = temp; } else { vecs[ num_allocated ] = t_vec; Hvecs[ num_allocated ] = new double[ veclength ]; t_vec = new double[ veclength ]; num_allocated++; } } double CheMPS2::Davidson::DiagonalizeSmallMatrixAndCalcResidual(){ int inc1 = 1; //4. mxM contains the Hamiltonian in the basis "vecs" for (int cnt = 0; cnt < num_vec; cnt++){ mxM[ cnt + MAX_NUM_VEC * num_vec ] = ddot_( &veclength, vecs[ num_vec ], &inc1, Hvecs[ cnt ], &inc1 ); mxM[ num_vec + MAX_NUM_VEC * cnt ] = mxM[ cnt + MAX_NUM_VEC * num_vec ]; } mxM [ num_vec + MAX_NUM_VEC * num_vec ] = ddot_( &veclength, vecs[ num_vec ], &inc1, Hvecs[ num_vec ], &inc1 ); //5. When t-vec was added to vecs, the number of vecs was actually increased by one. For convenience (doing 4.), only now the number is incremented. num_vec++; //6. Calculate the eigenvalues and vectors of mxM char jobz = 'V'; char uplo = 'U'; int info; for (int cnt1 = 0; cnt1 < num_vec; cnt1++){ for (int cnt2 = 0; cnt2 < num_vec; cnt2++){ mxM_vecs[ cnt1 + MAX_NUM_VEC * cnt2 ] = mxM[ cnt1 + MAX_NUM_VEC * cnt2 ]; } } dsyev_( &jobz, &uplo, &num_vec, mxM_vecs, &MAX_NUM_VEC, mxM_eigs, mxM_work, &mxM_lwork, &info ); // Ascending order of eigenvalues //7. Calculate u and r. r is stored in t_vec, u in u_vec. for (int cnt = 0; cnt < veclength; cnt++){ t_vec[ cnt ] = 0.0; } for (int cnt = 0; cnt < veclength; cnt++){ u_vec[ cnt ] = 0.0; } for (int cnt = 0; cnt < num_vec; cnt++){ double alpha = mxM_vecs[ cnt ]; // Eigenvector with lowest eigenvalue, hence mxM_vecs[ cnt + MAX_NUM_VEC * 0 ] daxpy_( &veclength, &alpha, Hvecs[ cnt ], &inc1, t_vec, &inc1 ); daxpy_( &veclength, &alpha, vecs[ cnt ], &inc1, u_vec, &inc1 ); } double theEigenvalue = -mxM_eigs[0]; daxpy_( &veclength, &theEigenvalue, u_vec, &inc1, t_vec, &inc1 ); //8. Calculate the norm of r char frobenius = 'F'; const double rnorm = dlange_( &frobenius, &veclength, &inc1, t_vec, &veclength, NULL ); // Work is not referenced for Frobenius norm return rnorm; } void CheMPS2::Davidson::CalculateNewVec(){ int inc1 = 1; //9a. Calculate the new t_vec based on the residual of the lowest eigenvalue, to add to the vecs. for (int cnt = 0; cnt < veclength; cnt++){ const double difference = diag[ cnt ] - mxM_eigs[0]; const double fabsdiff = fabs( difference ); if ( fabsdiff > DIAG_CUTOFF ){ work_vec[ cnt ] = u_vec[ cnt ] / difference; // work_vec = K^(-1) u_vec } else { work_vec[ cnt ] = u_vec[ cnt ] / DIAG_CUTOFF; if ( debugPrint ){ cout << "WARNING AT DAVIDSON : | (diag[" << cnt << "] - mxM_eigs[0]) | = " << fabsdiff << endl; } } } double alpha = - ddot_( &veclength, work_vec, &inc1, t_vec, &inc1 ) / ddot_( &veclength, work_vec, &inc1, u_vec, &inc1 ); // alpha = - (u^T K^(-1) r) / (u^T K^(-1) u) daxpy_( &veclength, &alpha, u_vec, &inc1, t_vec, &inc1 ); // t_vec = r - (u^T K^(-1) r) / (u^T K^(-1) u) u for (int cnt = 0; cnt < veclength; cnt++){ const double difference = diag[ cnt ] - mxM_eigs[0]; const double fabsdiff = fabs( difference ); if ( fabsdiff > DIAG_CUTOFF ){ t_vec[ cnt ] = - t_vec[ cnt ] / difference; //t_vec = - K^(-1) (r - (u^T K^(-1) r) / (u^T K^(-1) u) u) } else { t_vec[ cnt ] = - t_vec[ cnt ] / DIAG_CUTOFF; } } } void CheMPS2::Davidson::Deflation(){ int inc1 = 1; // 9b. When the maximum number of vectors is reached: construct the one with lowest eigenvalue & restart if ( NUM_VEC_KEEP <= 1 ){ char frobenius = 'F'; double alpha = 1.0 / dlange_( &frobenius, &veclength, &inc1, u_vec, &veclength, NULL ); // Work is not referenced for Frobenius norm dscal_( &veclength, &alpha, u_vec, &inc1 ); dcopy_( &veclength, u_vec, &inc1, vecs[0], &inc1 ); } else { if ( Reortho_Eigenvecs == NULL ){ Reortho_Eigenvecs = new double[ veclength * NUM_VEC_KEEP ]; } if ( Reortho_Overlap == NULL ){ Reortho_Overlap = new double[ NUM_VEC_KEEP * NUM_VEC_KEEP ]; } if ( Reortho_Overlap_eigs == NULL ){ Reortho_Overlap_eigs = new double[ NUM_VEC_KEEP ]; } if ( Reortho_Lowdin == NULL ){ Reortho_Lowdin = new double[ NUM_VEC_KEEP * NUM_VEC_KEEP ]; } //Construct the lowest NUM_VEC_KEEP eigenvectors dcopy_( &veclength, u_vec, &inc1, Reortho_Eigenvecs, &inc1 ); for (int cnt = 1; cnt < NUM_VEC_KEEP; cnt++){ for (int irow = 0; irow < veclength; irow++){ Reortho_Eigenvecs[ irow + veclength * cnt ] = 0.0; for (int ivec = 0; ivec < MAX_NUM_VEC; ivec++){ Reortho_Eigenvecs[ irow + veclength * cnt ] += vecs[ ivec ][ irow ] * mxM_vecs[ ivec + MAX_NUM_VEC * cnt ]; } } } //Calculate the overlap matrix char trans = 'T'; char notr = 'N'; double one = 1.0; double zero = 0.0; //set dgemm_( &trans, ¬r, &NUM_VEC_KEEP, &NUM_VEC_KEEP, &veclength, &one, Reortho_Eigenvecs, &veclength, Reortho_Eigenvecs, &veclength, &zero, Reortho_Overlap, &NUM_VEC_KEEP ); //Calculate the Lowdin tfo char jobz = 'V'; char uplo = 'U'; int info; dsyev_( &jobz, &uplo, &NUM_VEC_KEEP, Reortho_Overlap, &NUM_VEC_KEEP, Reortho_Overlap_eigs, mxM_work, &mxM_lwork, &info ); //Ascending order of eigs for (int icnt = 0; icnt < NUM_VEC_KEEP; icnt++){ Reortho_Overlap_eigs[ icnt ] = pow( Reortho_Overlap_eigs[ icnt ], -0.25 ); dscal_( &NUM_VEC_KEEP, Reortho_Overlap_eigs + icnt, Reortho_Overlap + NUM_VEC_KEEP * icnt, &inc1 ); } dgemm_( ¬r, &trans, &NUM_VEC_KEEP, &NUM_VEC_KEEP, &NUM_VEC_KEEP, &one, Reortho_Overlap, &NUM_VEC_KEEP, Reortho_Overlap, &NUM_VEC_KEEP, &zero, Reortho_Lowdin, &NUM_VEC_KEEP ); //Reortho: Put the Lowdin tfo eigenvecs in vecs for (int ivec = 0; ivec < NUM_VEC_KEEP; ivec++){ for (int loop = 0; loop < veclength; loop++){ vecs[ ivec ][ loop ] = 0.0; } for (int ivec2 = 0; ivec2 < NUM_VEC_KEEP; ivec2++){ daxpy_( &veclength, Reortho_Lowdin + ivec2 + NUM_VEC_KEEP * ivec, Reortho_Eigenvecs + veclength * ivec2, &inc1, vecs[ ivec ], &inc1 ); } } } num_vec = 0; } void CheMPS2::Davidson::MxMafterDeflation(){ int inc1 = 1; for (int ivec = 0; ivec < NUM_VEC_KEEP; ivec++){ for (int ivec2 = ivec; ivec2 < NUM_VEC_KEEP; ivec2++){ mxM[ ivec + MAX_NUM_VEC * ivec2 ] = ddot_( &veclength, vecs[ ivec ], &inc1, Hvecs[ ivec2 ], &inc1 ); mxM[ ivec2 + MAX_NUM_VEC * ivec ] = mxM[ ivec + MAX_NUM_VEC * ivec2 ]; } } } CheMPS2-1.6/CheMPS2/Doxyfile.in000066400000000000000000003043151256744172700160220ustar00rootroot00000000000000# Doxyfile 1.8.6 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. # # All text after a double hash (##) is considered a comment and is placed in # front of the TAG it is preceding. # # All text after a single hash (#) is considered a comment and will be ignored. # The format is: # TAG = value [value, ...] # For lists, items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (\" \"). #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all text # before the first occurrence of this tag. Doxygen uses libiconv (or the iconv # built into libc) for the transcoding. See http://www.gnu.org/software/libiconv # for the list of possible encodings. # The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded by # double-quotes, unless you are using Doxywizard) that should identify the # project for which the documentation is generated. This name is used in the # title of most generated pages and in a few other places. # The default value is: My Project. PROJECT_NAME = "CheMPS2" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version # control system is used. PROJECT_NUMBER = # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = # With the PROJECT_LOGO tag one can specify an logo or icon that is included in # the documentation. The maximum height of the logo should not exceed 55 pixels # and the maximum width should not exceed 200 pixels. Doxygen will copy the logo # to the output directory. PROJECT_LOGO = @CheMPS2_SOURCE_DIR@/CheMPS2/CheMPS2logo.png # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. OUTPUT_DIRECTORY = @CheMPS2_BINARY_DIR@/ # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and # will distribute the generated files over these directories. Enabling this # option can be useful when feeding doxygen a huge amount of source files, where # putting all generated files in the same directory would otherwise causes # performance problems for the file system. # The default value is: NO. CREATE_SUBDIRS = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, # Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), # Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, # Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), # Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, # Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, # Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, # Ukrainian and Vietnamese. # The default value is: English. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member # descriptions after the members that are listed in the file and class # documentation (similar to Javadoc). Set to NO to disable this. # The default value is: YES. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief # description of a member or function before the detailed description # # Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. # The default value is: YES. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator that is # used to form the text in various listings. Each string in this list, if found # as the leading text of the brief description, will be stripped from the text # and the result, after processing the whole list, is used as the annotated # text. Otherwise, the brief description is used as-is. If left blank, the # following values are used ($name is automatically replaced with the name of # the entity):The $name class, The $name widget, The $name file, is, provides, # specifies, contains, represents, a, an and the. ABBREVIATE_BRIEF = # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # doxygen will generate a detailed section even if there is only a brief # description. # The default value is: NO. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. # The default value is: NO. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the # shortest path that makes the file name unique will be used # The default value is: YES. FULL_PATH_NAMES = NO # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. # Stripping is only done if one of the specified strings matches the left-hand # part of the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the path to # strip. # # Note that you can specify absolute paths here, but also relative paths, which # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. STRIP_FROM_PATH = @CheMPS2_SOURCE_DIR@/CheMPS2 # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which # header file to include in order to use a class. If left blank only the name of # the header file containing the class definition is used. Otherwise one should # specify the list of include paths that are normally passed to the compiler # using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but # less readable) file names. This can be useful is your file systems doesn't # support long names like on DOS, Mac, or CD-ROM. # The default value is: NO. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the # first line (until the first dot) of a Javadoc-style comment as the brief # description. If set to NO, the Javadoc-style will behave just like regular Qt- # style comments (thus requiring an explicit @brief command for a brief # description.) # The default value is: NO. JAVADOC_AUTOBRIEF = NO # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If # set to NO, the Qt-style will behave just like regular Qt-style comments (thus # requiring an explicit \brief command for a brief description.) # The default value is: NO. QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a # multi-line C++ special comment block (i.e. a block of //! or /// comments) as # a brief description. This used to be the default behavior. The new default is # to treat a multi-line C++ comment block as a detailed description. Set this # tag to YES if you prefer the old behavior instead. # # Note that setting this tag to YES also means that rational rose comments are # not recognized any more. # The default value is: NO. MULTILINE_CPP_IS_BRIEF = NO # If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the # documentation from any documented member that it re-implements. # The default value is: YES. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a # new page for each member. If set to NO, the documentation of a member will be # part of the file/class/namespace that contains it. # The default value is: NO. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen # uses this value to replace tabs by spaces in code fragments. # Minimum value: 1, maximum value: 16, default value: 4. TAB_SIZE = 8 # This tag can be used to specify a number of aliases that act as commands in # the documentation. An alias has the form: # name=value # For example adding # "sideeffect=@par Side Effects:\n" # will allow you to put the command \sideeffect (or @sideeffect) in the # documentation, which will result in a user-defined paragraph with heading # "Side Effects:". You can put \n's in the value part of an alias to insert # newlines. ALIASES = # This tag can be used to specify a number of word-keyword mappings (TCL only). # A mapping has the form "name=value". For example adding "class=itcl::class" # will allow you to use the command class in the itcl::class meaning. TCL_SUBST = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For # instance, some of the names that are used will be different. The list of all # members will be omitted, etc. # The default value is: NO. OPTIMIZE_OUTPUT_FOR_C = NO # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or # Python sources only. Doxygen will then generate output that is more tailored # for that language. For instance, namespaces will be presented as packages, # qualified scopes will look different, etc. # The default value is: NO. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources. Doxygen will then generate output that is tailored for Fortran. # The default value is: NO. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for VHDL. # The default value is: NO. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, and # language is one of the parsers supported by doxygen: IDL, Java, Javascript, # C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make # doxygen treat .inc files as Fortran files (default is PHP), and .f files as C # (default is Fortran), use: inc=Fortran f=C. # # Note For files without extension you can use no_extension as a placeholder. # # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. EXTENSION_MAPPING = # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable # documentation. See http://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you can # mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in # case of backward compatibilities issues. # The default value is: YES. MARKDOWN_SUPPORT = YES # When enabled doxygen tries to link words that correspond to documented # classes, or namespaces to their corresponding documentation. Such a link can # be prevented in individual cases by by putting a % sign in front of the word # or globally by setting AUTOLINK_SUPPORT to NO. # The default value is: YES. AUTOLINK_SUPPORT = YES # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should set this # tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); # versus func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. # The default value is: NO. BUILTIN_STL_SUPPORT = YES # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. # The default value is: NO. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip (see: # http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen # will parse them like normal C++ but will assume all classes use public instead # of private inheritance when no explicit protection keyword is present. # The default value is: NO. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate # getter and setter methods for a property. Setting this option to YES will make # doxygen to replace the get and set methods by a property in the documentation. # This will only work if the methods are indeed getting or setting a simple # type. If this is not the case, or you want to show the methods anyway, you # should set this option to NO. # The default value is: YES. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. # The default value is: NO. DISTRIBUTE_GROUP_DOC = NO # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that # type (e.g. under the Public Functions section). Set it to NO to prevent # subgrouping. Alternatively, this can be done per class using the # \nosubgrouping command. # The default value is: YES. SUBGROUPING = YES # When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions # are shown inside the group in which they are included (e.g. using \ingroup) # instead of on a separate page (for HTML and Man pages) or section (for LaTeX # and RTF). # # Note that this feature does not work in combination with # SEPARATE_MEMBER_PAGES. # The default value is: NO. INLINE_GROUPED_CLASSES = NO # When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions # with only public data fields or simple typedef fields will be shown inline in # the documentation of the scope in which they are defined (i.e. file, # namespace, or group documentation), provided this scope is documented. If set # to NO, structs, classes, and unions are shown on a separate page (for HTML and # Man pages) or section (for LaTeX and RTF). # The default value is: NO. INLINE_SIMPLE_STRUCTS = NO # When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or # enum is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically be # useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. # The default value is: NO. TYPEDEF_HIDES_STRUCT = NO # The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This # cache is used to resolve symbols given their name and scope. Since this can be # an expensive process and often the same symbol appears multiple times in the # code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small # doxygen will become slower. If the cache is too large, memory is wasted. The # cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range # is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 # symbols. At the end of a run doxygen will report the cache usage and suggest # the optimal cache size from a speed point of view. # Minimum value: 0, maximum value: 9, default value: 0. LOOKUP_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in # documentation are documented, even if no documentation was available. Private # class members and static file members will be hidden unless the # EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. # Note: This will also disable the warnings about undocumented members that are # normally produced when WARNINGS is set to YES. # The default value is: NO. EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES all private members of a class will # be included in the documentation. # The default value is: NO. EXTRACT_PRIVATE = NO # If the EXTRACT_PACKAGE tag is set to YES all members with package or internal # scope will be included in the documentation. # The default value is: NO. EXTRACT_PACKAGE = NO # If the EXTRACT_STATIC tag is set to YES all static members of a file will be # included in the documentation. # The default value is: NO. EXTRACT_STATIC = NO # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined # locally in source files will be included in the documentation. If set to NO # only classes defined in header files are included. Does not have any effect # for Java sources. # The default value is: YES. EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. When set to YES local methods, # which are defined in the implementation section but not in the interface are # included in the documentation. If set to NO only methods in the interface are # included. # The default value is: NO. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base name of # the file that contains the anonymous namespace. By default anonymous namespace # are hidden. # The default value is: NO. EXTRACT_ANON_NSPACES = NO # If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all # undocumented members inside documented classes or files. If set to NO these # members will be included in the various overviews, but no documentation # section is generated. This option has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set # to NO these classes will be included in the various overviews. This option has # no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend # (class|struct|union) declarations. If set to NO these declarations will be # included in the documentation. # The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any # documentation blocks found inside the body of a function. If set to NO these # blocks will be appended to the function's detailed documentation block. # The default value is: NO. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation that is typed after a # \internal command is included. If the tag is set to NO then the documentation # will be excluded. Set it to YES to include the internal documentation. # The default value is: NO. INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file # names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. # The default value is: system dependent. CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with # their full class and namespace scopes in the documentation. If set to YES the # scope will be hidden. # The default value is: NO. HIDE_SCOPE_NAMES = NO # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. # The default value is: YES. SHOW_INCLUDE_FILES = YES # If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each # grouped member an include statement to the documentation, telling the reader # which file to include in order to use the member. # The default value is: NO. SHOW_GROUPED_MEMB_INC = NO # If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include # files with double quotes in the documentation rather than with sharp brackets. # The default value is: NO. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the # documentation for inline members. # The default value is: YES. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the # (detailed) documentation of file and class members alphabetically by member # name. If set to NO the members will appear in declaration order. # The default value is: YES. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief # descriptions of file, namespace and class members alphabetically by member # name. If set to NO the members will appear in declaration order. Note that # this will also influence the order of the classes in the class list. # The default value is: NO. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the # (brief and detailed) documentation of class members so that constructors and # destructors are listed first. If set to NO the constructors will appear in the # respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. # Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief # member documentation. # Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting # detailed member documentation. # The default value is: NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy # of group names into alphabetical order. If set to NO the group names will # appear in their defined order. # The default value is: NO. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by # fully-qualified names, including namespaces. If set to NO, the class list will # be sorted only by class name, not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the alphabetical # list. # The default value is: NO. SORT_BY_SCOPE_NAME = NO # If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper # type resolution of all parameters of a function it will reject a match between # the prototype and the implementation of a member function even if there is # only one candidate or it is obvious which candidate to choose by doing a # simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still # accept a match between prototype and implementation in such cases. # The default value is: NO. STRICT_PROTO_MATCHING = NO # The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the # todo list. This list is created by putting \todo commands in the # documentation. # The default value is: YES. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the # test list. This list is created by putting \test commands in the # documentation. # The default value is: YES. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug # list. This list is created by putting \bug commands in the documentation. # The default value is: YES. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) # the deprecated list. This list is created by putting \deprecated commands in # the documentation. # The default value is: YES. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional documentation # sections, marked by \if ... \endif and \cond # ... \endcond blocks. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the # initial value of a variable or macro / define can have for it to appear in the # documentation. If the initializer consists of more lines than specified here # it will be hidden. Use a value of 0 to hide initializers completely. The # appearance of the value of individual variables and macros / defines can be # controlled using \showinitializer or \hideinitializer command in the # documentation regardless of this setting. # Minimum value: 0, maximum value: 10000, default value: 30. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated at # the bottom of the documentation of classes and structs. If set to YES the list # will mention the files that were used to generate the documentation. # The default value is: YES. SHOW_USED_FILES = YES # Set the SHOW_FILES tag to NO to disable the generation of the Files page. This # will remove the Files entry from the Quick Index and from the Folder Tree View # (if specified). # The default value is: YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces # page. This will remove the Namespaces entry from the Quick Index and from the # Folder Tree View (if specified). # The default value is: YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command command input-file, where command is the value of the # FILE_VERSION_FILTER tag, and input-file is the name of an input file provided # by doxygen. Whatever the program writes to standard output is used as the file # version. For an example see the documentation. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. To create the layout file # that represents doxygen's defaults, run doxygen with the -l option. You can # optionally specify a file name after the option, if omitted DoxygenLayout.xml # will be used as the name of the layout file. # # Note that if you run doxygen from a directory containing a file called # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE # tag is left empty. LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib # extension is automatically appended if omitted. This requires the bibtex tool # to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the # search path. Do not use file names with spaces, bibtex cannot handle them. See # also \cite for info how to create references. CITE_BIB_FILES = #--------------------------------------------------------------------------- # Configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated to # standard output by doxygen. If QUIET is set to YES this implies that the # messages are off. # The default value is: NO. QUIET = YES # The WARNINGS tag can be used to turn on/off the warning messages that are # generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES # this implies that the warnings are on. # # Tip: Turn warnings on while writing the documentation. # The default value is: YES. WARNINGS = YES # If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate # warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag # will automatically be disabled. # The default value is: YES. WARN_IF_UNDOCUMENTED = YES # If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some parameters # in a documented function, or documenting parameters that don't exist or using # markup commands wrongly. # The default value is: YES. WARN_IF_DOC_ERROR = YES # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return # value. If set to NO doxygen will only warn about wrong or incomplete parameter # documentation, but not about the absence of documentation. # The default value is: NO. WARN_NO_PARAMDOC = NO # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which # will be replaced by the file and line number from which the warning originated # and the warning text. Optionally the format may contain $version, which will # be replaced by the version of the file (if it could be obtained via # FILE_VERSION_FILTER) # The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" # The WARN_LOGFILE tag can be used to specify a file to which warning and error # messages should be written. If left blank the output is written to standard # error (stderr). WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag is used to specify the files and/or directories that contain # documented source files. You may enter file names like myfile.cpp or # directories like /usr/src/myproject. Separate the files or directories with # spaces. # Note: If this tag is empty the current directory is searched. INPUT = @CheMPS2_SOURCE_DIR@/CheMPS2/include/chemps2 \ @CheMPS2_SOURCE_DIR@/CheMPS2/ \ @CheMPS2_SOURCE_DIR@ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv # documentation (see: http://www.gnu.org/software/libiconv) for the list of # possible encodings. # The default value is: UTF-8. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and # *.h) to filter out the source-files in the directories. If left blank the # following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, # *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, # *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, # *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, # *.qsf, *.as and *.js. FILE_PATTERNS = # The RECURSIVE tag can be used to specify whether or not subdirectories should # be searched for input files as well. # The default value is: NO. RECURSIVE = NO # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. # # Note that relative paths are relative to the directory from which doxygen is # run. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. # The default value is: NO. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories use the pattern */test/* EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or directories # that contain example code fragments that are included (see the \include # command). EXAMPLE_PATH = @CheMPS2_SOURCE_DIR@ # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and # *.h) to filter out the source-files in the directories. If left blank all # files are included. EXAMPLE_PATTERNS = # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude commands # irrespective of the value of the RECURSIVE tag. # The default value is: NO. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or directories # that contain images that are to be included in the documentation (see the # \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command: # # # # where is the value of the INPUT_FILTER tag, and is the # name of an input file. Doxygen will then use the output that the filter # program writes to standard output. If FILTER_PATTERNS is specified, this tag # will be ignored. # # Note that the filter must not add or remove lines; it is applied before the # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the # filter if there is a match. The filters are a list of the form: pattern=filter # (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how # filters are used. If the FILTER_PATTERNS tag is empty or if none of the # patterns match the file name, INPUT_FILTER is applied. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER ) will also be used to filter the input files that are used for # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # The default value is: NO. FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # pattern. A pattern will override the setting for FILTER_PATTERN (if any) and # it is also possible to disable source filtering for a specific pattern using # *.ext= (so without naming a filter). # This tag requires that the tag FILTER_SOURCE_FILES is set to YES. FILTER_SOURCE_PATTERNS = # If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that # is part of the input, its contents will be placed on the main page # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. USE_MDFILE_AS_MAINPAGE = README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will be # generated. Documented entities will be cross-referenced with these sources. # # Note: To get rid of all source code in the generated output, make sure that # also VERBATIM_HEADERS is set to NO. # The default value is: NO. SOURCE_BROWSER = YES # Setting the INLINE_SOURCES tag to YES will include the body of functions, # classes and enums directly into the documentation. # The default value is: NO. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any # special comment blocks from generated source code fragments. Normal C, C++ and # Fortran comments will always remain visible. # The default value is: YES. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES then for each documented # function all documented functions referencing it will be listed. # The default value is: NO. REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES then for each documented function # all documented entities called/used by that function will be listed. # The default value is: NO. REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set # to YES, then the hyperlinks from functions in REFERENCES_RELATION and # REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will # link to the documentation. # The default value is: YES. REFERENCES_LINK_SOURCE = YES # If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the # source code will show a tooltip with additional information such as prototype, # brief description and links to the definition and documentation. Since this # will make the HTML file larger and loading of large files a bit slower, you # can opt to disable this feature. # The default value is: YES. # This tag requires that the tag SOURCE_BROWSER is set to YES. SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system # (see http://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. # # To use it do the following: # - Install the latest version of global # - Enable SOURCE_BROWSER and USE_HTAGS in the config file # - Make sure the INPUT points to the root of the source tree # - Run doxygen as normal # # Doxygen will invoke htags (and that will in turn invoke gtags), so these # tools must be available from the command line (i.e. in the search path). # # The result: instead of the source browser generated by doxygen, the links to # source code will now point to the output of htags. # The default value is: NO. # This tag requires that the tag SOURCE_BROWSER is set to YES. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a # verbatim copy of the header file for each class for which an include is # specified. Set to NO to disable this. # See also: Section \class. # The default value is: YES. VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all # compounds will be generated. Enable this if the project contains a lot of # classes, structs, unions or interfaces. # The default value is: YES. ALPHABETICAL_INDEX = YES # The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in # which the alphabetical index list will be split. # Minimum value: 1, maximum value: 20, default value: 5. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. COLS_IN_ALPHA_INDEX = 5 # In case all classes in a project start with a common prefix, all classes will # be put under the same header in the alphabetical index. The IGNORE_PREFIX tag # can be used to specify a prefix (or a list of prefixes) that should be ignored # while generating the index headers. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES doxygen will generate HTML output # The default value is: YES. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for each # generated HTML page (for example: .htm, .php, .asp). # The default value is: .html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a user-defined HTML header file for # each generated HTML page. If the tag is left blank doxygen will generate a # standard header. # # To get valid HTML the header file that includes any scripts and style sheets # that doxygen needs, which is dependent on the configuration options used (e.g. # the setting GENERATE_TREEVIEW). It is highly recommended to start with a # default header using # doxygen -w html new_header.html new_footer.html new_stylesheet.css # YourConfigFile # and then modify the file new_header.html. See also section "Doxygen usage" # for information on how to generate the default header that doxygen normally # uses. # Note: The header is subject to change so you typically have to regenerate the # default header when upgrading to a newer version of doxygen. For a description # of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each # generated HTML page. If the tag is left blank doxygen will generate a standard # footer. See HTML_HEADER for more information on how to generate a default # footer and what special commands can be used inside the footer. See also # section "Doxygen usage" for information on how to generate the default footer # that doxygen normally uses. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading style # sheet that is used by each HTML page. It can be used to fine-tune the look of # the HTML output. If left blank doxygen will generate a default style sheet. # See also section "Doxygen usage" for information on how to generate the style # sheet that doxygen normally uses. # Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as # it is more robust and this tag (HTML_STYLESHEET) will in the future become # obsolete. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_STYLESHEET = # The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- # defined cascading style sheet that is included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the # standard style sheet and is therefor more robust against future updates. # Doxygen will copy the style sheet file to the output directory. For an example # see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the # $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these # files. In the HTML_STYLESHEET file, use the file name only. Also note that the # files will be copied as-is; there are no commands or markers available. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen # will adjust the colors in the stylesheet and background images according to # this color. Hue is specified as an angle on a colorwheel, see # http://en.wikipedia.org/wiki/Hue for more information. For instance the value # 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 # purple, and 360 is red again. # Minimum value: 0, maximum value: 359, default value: 220. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_HUE = 220 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors # in the HTML output. For a value of 0 the output will use grayscales only. A # value of 255 will produce the most vivid colors. # Minimum value: 0, maximum value: 255, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_SAT = 100 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the # luminance component of the colors in the HTML output. Values below 100 # gradually make the output lighter, whereas values above 100 make the output # darker. The value divided by 100 is the actual gamma applied, so 80 represents # a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not # change the gamma. # Minimum value: 40, maximum value: 240, default value: 80. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting this # to NO can help when comparing the output of multiple runs. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_SECTIONS = YES # With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries # shown in the various tree structured indices initially; the user can expand # and collapse entries dynamically later on. Doxygen will expand the tree to # such a level that at most the specified number of entries are visible (unless # a fully collapsed tree already exceeds this amount). So setting the number of # entries 1 will produce a full collapsed tree by default. 0 is a special value # representing an infinite number of entries and will result in a full expanded # tree by default. # Minimum value: 0, maximum value: 9999, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development # environment (see: http://developer.apple.com/tools/xcode/), introduced with # OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a # Makefile in the HTML output directory. Running make will produce the docset in # that directory and running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at # startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html # for more information. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_DOCSET = NO # This tag determines the name of the docset feed. A documentation feed provides # an umbrella under which multiple documentation sets from a single provider # (such as a company or product suite) can be grouped. # The default value is: Doxygen generated docs. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDNAME = "Doxygen generated docs" # This tag specifies a string that should uniquely identify the documentation # set bundle. This should be a reverse domain-name style string, e.g. # com.mycompany.MyDocSet. Doxygen will append .docset to the name. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_BUNDLE_ID = org.doxygen.Project # The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify # the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. # The default value is: org.doxygen.Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_ID = org.doxygen.Publisher # The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. # The default value is: Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # additional HTML index files: index.hhp, index.hhc, and index.hhk. The # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop # (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on # Windows. # # The HTML Help Workshop contains a compiler that can convert all HTML output # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML # files are now used as the Windows 98 help format, and will replace the old # Windows help format (.hlp) on all Windows platforms in the future. Compressed # HTML files also contain an index, a table of contents, and you can search for # words in the documentation. The HTML workshop also contains a viewer for # compressed HTML files. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_HTMLHELP = NO # The CHM_FILE tag can be used to specify the file name of the resulting .chm # file. You can add a path in front of the file if the result should not be # written to the html output directory. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_FILE = # The HHC_LOCATION tag can be used to specify the location (absolute path # including file name) of the HTML help compiler ( hhc.exe). If non-empty # doxygen will try to run the HTML help compiler on the generated index.hhp. # The file has to be specified with full path. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. HHC_LOCATION = # The GENERATE_CHI flag controls if a separate .chi index file is generated ( # YES) or that it should be included in the master .chm file ( NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO # The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) # and project file content. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_INDEX_ENCODING = # The BINARY_TOC flag controls whether a binary table of contents is generated ( # YES) or a normal table of contents ( NO) in the .chm file. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members to # the table of contents of the HTML help documentation and to the tree view. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that # can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help # (.qch) of the generated HTML documentation. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify # the file name of the resulting .qch file. The path specified is relative to # the HTML output folder. # This tag requires that the tag GENERATE_QHP is set to YES. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace # (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual # Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- # folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom # Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- # filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom # Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- # filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: # http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = # The QHG_LOCATION tag can be used to specify the location of Qt's # qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the # generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be # generated, together with the HTML files, they form an Eclipse help plugin. To # install this plugin and make it available under the help contents menu in # Eclipse, the contents of the directory containing the HTML and XML files needs # to be copied into the plugins directory of eclipse. The name of the directory # within the plugins directory should be the same as the ECLIPSE_DOC_ID value. # After copying Eclipse needs to be restarted before the help appears. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_ECLIPSEHELP = NO # A unique identifier for the Eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have this # name. Each documentation set should have its own identifier. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. ECLIPSE_DOC_ID = org.doxygen.Project # If you want full control over the layout of the generated HTML pages it might # be necessary to disable the index and replace it with your own. The # DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top # of each HTML page. A value of NO enables the index and the value YES disables # it. Since the tabs in the index contain the same information as the navigation # tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. DISABLE_INDEX = NO # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. If the tag # value is set to YES, a side panel will be generated containing a tree-like # index structure (just like the one that is generated for HTML Help). For this # to work a browser that supports JavaScript, DHTML, CSS and frames is required # (i.e. any modern browser). Windows users are probably better off using the # HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can # further fine-tune the look of the index. As an example, the default style # sheet generated by doxygen has an example that shows how to put an image at # the root of the tree instead of the PROJECT_NAME. Since the tree basically has # the same information as the tab index, you could consider setting # DISABLE_INDEX to YES when enabling this option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_TREEVIEW = YES # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. # # Note that a value of 0 will completely suppress the enum values from appearing # in the overview section. # Minimum value: 0, maximum value: 20, default value: 4. # This tag requires that the tag GENERATE_HTML is set to YES. ENUM_VALUES_PER_LINE = 4 # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used # to set the initial width (in pixels) of the frame in which the tree is shown. # Minimum value: 0, maximum value: 1500, default value: 250. # This tag requires that the tag GENERATE_HTML is set to YES. TREEVIEW_WIDTH = 250 # When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to # external symbols imported via tag files in a separate window. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO # Use this tag to change the font size of LaTeX formulas included as images in # the HTML documentation. When you change the font size after a successful # doxygen run you need to manually remove any form_*.png images from the HTML # output directory to force them to be regenerated. # Minimum value: 8, maximum value: 50, default value: 10. # This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_FONTSIZE = 10 # Use the FORMULA_TRANPARENT tag to determine whether or not the images # generated for formulas are transparent PNGs. Transparent PNGs are not # supported properly for IE 6.0, but are supported on all modern browsers. # # Note that when changing this option you need to delete any form_*.png files in # the HTML output directory before the changes have effect. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_TRANSPARENT = YES # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see # http://www.mathjax.org) which uses client side Javascript for the rendering # instead of using prerendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path # to it using the MATHJAX_RELPATH option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. USE_MATHJAX = NO # When MathJax is enabled you can set the default output format to be used for # the MathJax output. See the MathJax site (see: # http://docs.mathjax.org/en/latest/output.html) for more details. # Possible values are: HTML-CSS (which is slower, but has the best # compatibility), NativeMML (i.e. MathML) and SVG. # The default value is: HTML-CSS. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_FORMAT = HTML-CSS # When MathJax is enabled you need to specify the location relative to the HTML # output directory using the MATHJAX_RELPATH option. The destination directory # should contain the MathJax.js script. For instance, if the mathjax directory # is located at the same level as the HTML output directory, then # MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax # Content Delivery Network so you can quickly see the result without installing # MathJax. However, it is strongly recommended to install a local copy of # MathJax from http://www.mathjax.org before deployment. # The default value is: http://cdn.mathjax.org/mathjax/latest. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://www.mathjax.org/mathjax # The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax # extension names that should be enabled during MathJax rendering. For example # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site # (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_CODEFILE = # When the SEARCHENGINE tag is enabled doxygen will generate a search box for # the HTML output. The underlying search engine uses javascript and DHTML and # should work on any modern browser. Note that when using HTML help # (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) # there is already a search function so this one should typically be disabled. # For large projects the javascript based search engine can be slow, then # enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to # search using the keyboard; to jump to the search box use + S # (what the is depends on the OS and browser, but it is typically # , /