forked from SebWouters/CheMPS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.cpp.in
131 lines (109 loc) · 4.59 KB
/
test3.cpp.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry
Copyright (C) 2013-2018 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 <iostream>
#include <math.h>
#include <string.h>
#include "Initialize.h"
#include "DMRG.h"
#include "FCI.h"
#include "MPIchemps2.h"
using namespace std;
int main(void){
#ifdef CHEMPS2_MPI_COMPILATION
CheMPS2::MPIchemps2::mpi_init();
#endif
CheMPS2::Initialize::Init();
//The path to the matrix elements
string matrixelements = "${CMAKE_SOURCE_DIR}/tests/matrixelements/CH4.STO3G.FCIDUMP";
//The Hamiltonian
const int psi4groupnumber = 5; // c2v -- see Irreps.h and CH4.sto3g.out
CheMPS2::Hamiltonian * Ham = new CheMPS2::Hamiltonian( matrixelements, psi4groupnumber );
cout << "The group was found to be " << CheMPS2::Irreps::getGroupName(Ham->getNGroup()) << endl;
//The targeted state
int TwoS = 0;
int N = 10;
int Irrep = 0;
CheMPS2::Problem * Prob = new CheMPS2::Problem(Ham, TwoS, N, Irrep);
//The convergence scheme
CheMPS2::ConvergenceScheme * OptScheme = new CheMPS2::ConvergenceScheme(2);
//OptScheme->setInstruction(instruction, DSU(2), Econvergence, maxSweeps, noisePrefactor);
OptScheme->setInstruction(0, 30, 1e-10, 3, 0.1);
OptScheme->setInstruction(1, 1000, 1e-10, 10, 0.0);
//Run ground state calculation
CheMPS2::DMRG * theDMRG = new CheMPS2::DMRG(Prob, OptScheme);
const double EnergyDMRG = theDMRG->Solve();
theDMRG->calc2DMandCorrelations();
//Calculate FCI reference energy and compare the DMRG and FCI 2-RDMs
double EnergyFCI = 0.0;
double RMSerror2DM = 0.0;
#ifdef CHEMPS2_MPI_COMPILATION
if ( CheMPS2::MPIchemps2::mpi_rank() == MPI_CHEMPS2_MASTER )
#endif
{
const int Nel_up = ( N + TwoS ) / 2;
const int Nel_down = ( N - TwoS ) / 2;
const double maxMemWorkMB = 10.0;
const int FCIverbose = 1;
CheMPS2::FCI * theFCI = new CheMPS2::FCI(Ham, Nel_up, Nel_down, Irrep, maxMemWorkMB, FCIverbose);
double * inoutput = new double[theFCI->getVecLength(0)];
theFCI->ClearVector(theFCI->getVecLength(0), inoutput);
inoutput[ theFCI->LowestEnergyDeterminant() ] = 1.0;
EnergyFCI = theFCI->GSDavidson(inoutput);
theFCI->CalcSpinSquared(inoutput);
const int L = Ham->getL();
double * TwoDMspace = new double[ L*L*L*L ];
theFCI->Fill2RDM(inoutput, TwoDMspace);
for (int orb1=0; orb1<L; orb1++){
for (int orb2=0; orb2<L; orb2++){
for (int orb3=0; orb3<L; orb3++){
for (int orb4=0; orb4<L; orb4++){
const double difference = TwoDMspace[orb1 + L*(orb2 + L*(orb3 + L*orb4))]
- theDMRG->get2DM()->getTwoDMA_HAM(orb1, orb2, orb3, orb4);
RMSerror2DM += difference * difference;
}
}
}
}
delete [] TwoDMspace;
delete [] inoutput;
delete theFCI;
RMSerror2DM = sqrt(RMSerror2DM);
cout << "Frobenius norm of the difference of the DMRG and FCI 2-RDMs = " << RMSerror2DM << endl;
}
#ifdef CHEMPS2_MPI_COMPILATION
CheMPS2::MPIchemps2::broadcast_array_double( &EnergyFCI, 1, MPI_CHEMPS2_MASTER );
CheMPS2::MPIchemps2::broadcast_array_double( &RMSerror2DM, 1, MPI_CHEMPS2_MASTER );
#endif
//Clean up DMRG
if (CheMPS2::DMRG_storeMpsOnDisk){ theDMRG->deleteStoredMPS(); }
if (CheMPS2::DMRG_storeRenormOptrOnDisk){ theDMRG->deleteStoredOperators(); }
delete theDMRG;
delete OptScheme;
delete Prob;
delete Ham;
//Check success
const bool success = (( fabs( EnergyDMRG - EnergyFCI ) < 1e-8 ) && ( RMSerror2DM < 1e-3 )) ? true : false;
#ifdef CHEMPS2_MPI_COMPILATION
CheMPS2::MPIchemps2::mpi_finalize();
#endif
cout << "================> Did test 3 succeed : ";
if (success){
cout << "yes" << endl;
return 0; //Success
}
cout << "no" << endl;
return 7; //Fail
}