forked from sanshar/Block
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fci.C
157 lines (131 loc) · 4.82 KB
/
fci.C
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
Developed by Sandeep Sharma and Garnet K.-L. Chan, 2012
Copyright (c) 2012, Garnet K.-L. Chan
This program is integrated in Molpro with the permission of
Sandeep Sharma and Garnet K.-L. Chan
*/
#include "sweep.h"
#include "global.h"
#include "solver.h"
#include "initblocks.h"
#include "initblocks.h"
#include "MatrixBLAS.h"
#include <boost/format.hpp>
#include "op_components.h"
#ifndef SERIAL
#include <boost/mpi/communicator.hpp>
#include <boost/mpi.hpp>
#endif
using namespace boost;
using namespace std;
void SpinAdapted::Sweep::fullci(double sweep_tol)
{
int integralIndex = 0;
SweepParams sweepParams;
sweepParams.set_sweep_parameters();
SpinBlock system;
InitBlocks::InitStartingBlock(system, true, 0, 0, sweepParams.get_forward_starting_size(), sweepParams.get_backward_starting_size(), 0, false, true, integralIndex);
int numsites = dmrginp.spinAdapted() ? dmrginp.last_site() : dmrginp.last_site()/2;
int forwardsites = numsites/2+numsites%2;
int backwardsites = numsites - forwardsites;
SpinQuantum hq(0,SpinSpace(0),IrrepSpace(0));
for (int i=0; i<forwardsites-1; i++) {
SpinBlock sysdot(i+1, i+1, integralIndex, true);
SpinBlock newSystem;
system.addAdditionalCompOps();
newSystem.set_integralIndex() = integralIndex;
newSystem.default_op_components(false, system, sysdot, false, true, true);
newSystem.setstoragetype(DISTRIBUTED_STORAGE);
newSystem.BuildSumBlock (NO_PARTICLE_SPIN_NUMBER_CONSTRAINT, system, sysdot);
system = newSystem;
}
SpinBlock environment;
InitBlocks::InitStartingBlock(environment, false, 0, 0, sweepParams.get_forward_starting_size(), sweepParams.get_backward_starting_size(), 0, false, true, integralIndex);
pout << environment<<endl;
for (int i=0;i <backwardsites-1; i++) {
SpinBlock envdot(numsites-2-i, numsites-2-i, integralIndex, true);
SpinBlock newEnvironment;
environment.addAdditionalCompOps();
newEnvironment.set_integralIndex() = integralIndex;
newEnvironment.default_op_components(false, environment, envdot, true, true, true);
newEnvironment.setstoragetype(DISTRIBUTED_STORAGE);
newEnvironment.BuildSumBlock (NO_PARTICLE_SPIN_NUMBER_CONSTRAINT, environment, envdot);
environment = newEnvironment;
}
pout <<"\t\t\t System Block :: "<< system;
pout <<"\t\t\t Environment Block :: "<< environment;
SpinBlock big;
InitBlocks::InitBigBlock(system, environment, big);
//SpinBlock systemp(0,1), envtmp(2,3);
//InitBlocks::InitBigBlock(systemp, envtmp, big);
int nroots = dmrginp.nroots(0);
std::vector<Wavefunction> solution(nroots);
std::vector<double> energies(nroots);
double tol = sweepParams.get_davidson_tol();
pout << "\t\t\t Solving the Wavefunction "<<endl;
int currentState = 0;
std::vector<Wavefunction> lowerStates;
Solver::solve_wavefunction(solution, energies, big, tol, BASIC, false, true, false, sweepParams.get_additional_noise(), currentState, lowerStates);
for (int i=0; i<nroots; i++) {
pout << "fullci energy "<< energies[i]<<endl;
}
if (!mpigetrank())
{
#ifndef MOLPRO
FILE* f = fopen("dmrg.e", "wb");
#else
std::string efile;
efile = str(boost::format("%s%s") % dmrginp.load_prefix() % "/dmrg.e" );
FILE* f = fopen(efile.c_str(), "wb");
#endif
for(int j=0;j<nroots;++j) {
double e = energies[j];
fwrite( &e, 1, sizeof(double), f);
}
fclose(f);
}
}
void SpinAdapted::Sweep::tiny(double sweep_tol)
{
#ifndef SERIAL
if(mpigetrank() == 0) {
#endif
pout.precision(12);
int nroots = dmrginp.nroots(0);
SweepParams sweepParams;
sweepParams.set_sweep_parameters();
SpinBlock system(0,dmrginp.last_site()-1, 0, true);
const StateInfo& sinfo = system.get_stateInfo();
SpinQuantum hq(0,SpinSpace(0),IrrepSpace(0));
for (int i=0; i<sinfo.totalStates; i++) {
if (sinfo.quanta[i] == dmrginp.molecule_quantum()) {
Matrix& h = system.get_op_rep(HAM, hq)->operator_element(i,i);
DiagonalMatrix energies(h.Nrows()); energies = 0.0;
Matrix vec(h.Nrows(), h.Ncols()); vec = 0.0;
diagonalise(h, energies, vec);
for (int x=0; x<nroots; x++)
pout << "fullci energy "<< energies(x+1)<<endl;
if (mpigetrank() == 0)
{
#ifndef MOLPRO
FILE* f = fopen("dmrg.e", "wb");
#else
std::string efile;
efile = str(boost::format("%s%s") % dmrginp.load_prefix() % "/dmrg.e" );
FILE* f = fopen(efile.c_str(), "wb");
#endif
for(int j=0;j<nroots;++j) {
double e = energies(j+1);
fwrite( &e, 1, sizeof(double), f);
}
fclose(f);
}
return;
}
}
pout << "The wavefunction symmetry is not possible with the orbitals supplied."<<endl;
abort();
#ifndef SERIAL
}
#endif
}