forked from sanshar/Block
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renormalise.C
168 lines (133 loc) · 5.54 KB
/
renormalise.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
157
158
159
160
161
162
163
164
165
166
167
168
/*
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 "spinblock.h"
#include <boost/bind.hpp>
#include <boost/functional.hpp>
#include <boost/function.hpp>
#include <boost/make_shared.hpp>
#include "solver.h"
#include "operatorloops.h"
#include <numeric>
#include "Operators.h"
#include "wavefunction.h"
#include "rotationmat.h"
#include "density.h"
#include "initblocks.h"
#include "guess_wavefunction.h"
#include "linear.h"
#include "davidson.h"
#include <stdlib.h>
//#include "diis.h"
#ifndef SERIAL
#include <boost/mpi.hpp>
#endif
#include "pario.h"
using namespace boost;
using namespace std;
namespace SpinAdapted{
void SpinBlock::RenormaliseFrom(vector<double> &energies, vector<double> &spins, double& error,
vector<Matrix>& rotateMatrix, const int keptstates,
const int keptqstates, const double tol, SpinBlock& big,
const guessWaveTypes &guesswavetype, const double noise,
const double additional_noise, const bool &onedot, SpinBlock& System,
SpinBlock& sysDot, SpinBlock& environment, const bool& dot_with_sys,
const bool& warmUp, int sweepiter, int currentRoot,
std::vector<Wavefunction>& lowerStates, DensityMatrix* ReducedDM)
{
int nroots = dmrginp.nroots(sweepiter);
vector<Wavefunction> wave_solutions(nroots);
dmrginp.davidsonT -> start();
if (dmrginp.outputlevel() > 0)
mcheck("before davidson but after all blocks are built");
dmrginp.solvewf -> start();
Solver::solve_wavefunction(wave_solutions, energies, big, tol, guesswavetype, onedot,
dot_with_sys, warmUp, additional_noise, currentRoot, lowerStates);
dmrginp.solvewf -> stop();
SpinBlock newsystem;
SpinBlock newenvironment;
SpinBlock newbig;
dmrginp.postwfrearrange -> start();
if (onedot && !dot_with_sys)
{
InitBlocks::InitNewSystemBlock(System, sysDot, newsystem, currentRoot, currentRoot,
sysDot.size(), dmrginp.direct(), System.get_integralIndex(), DISTRIBUTED_STORAGE, false, true);
InitBlocks::InitBigBlock(newsystem, environment, newbig);
for (int i=0; i<nroots&& mpigetrank()==0; i++)
{
Wavefunction tempwave = wave_solutions[i];
GuessWave::onedot_shufflesysdot(big.get_stateInfo(), newbig.get_stateInfo(),wave_solutions[i],
tempwave);
wave_solutions[i] = tempwave;
}
*this = newsystem;
big.get_rightBlock()->clear();
big.clear();
}
else
newbig = big;
dmrginp.postwfrearrange -> stop();
if (dmrginp.outputlevel() > 0)
mcheck("after davidson before noise");
dmrginp.davidsonT -> stop();
dmrginp.rotmatrixT -> start();
DensityMatrix tracedMatrix(braStateInfo);
tracedMatrix.allocate(braStateInfo);
bool normalnoise = warmUp;
if (newbig.get_rightBlock()->size() < 2)
normalnoise = true;
dmrginp.addnoise -> start();
double twodotnoise = 0.0;
if (dmrginp.noise_type() == RANDOM)
twodotnoise = additional_noise;
tracedMatrix.makedensitymatrix(wave_solutions, newbig, dmrginp.weights(sweepiter), noise, twodotnoise, normalnoise);
//this will return the RDM back. It is required when we are doing LCC using DMRG. The H0 has almost all the operatorsand is needed to add an effective noise.
if (ReducedDM != 0)
*ReducedDM = tracedMatrix;
dmrginp.addnoise -> stop();
if (dmrginp.outputlevel() > 0)
mcheck("after density matrix before rotation matrix");
if (!mpigetrank())
error = makeRotateMatrix(tracedMatrix, rotateMatrix, keptstates, keptqstates);
#ifndef SERIAL
mpi::communicator world;
broadcast(world, rotateMatrix, 0);
#endif
SaveRotationMatrix (newbig.leftBlock->sites, rotateMatrix);
for (int i=0; i<nroots; i++) {
int state = dmrginp.setStateSpecific() ? currentRoot : i;
if (dmrginp.solve_method() == CONJUGATE_GRADIENT)
state = currentRoot;
SaveRotationMatrix (newbig.leftBlock->sites, rotateMatrix, state);
wave_solutions[i].SaveWavefunctionInfo (newbig.braStateInfo, newbig.leftBlock->sites, state);
}
dmrginp.rotmatrixT -> stop();
if (dmrginp.outputlevel() > 0)
mcheck("after noise and calculation of density matrix");
}
double makeRotateMatrix(DensityMatrix& tracedMatrix, vector<Matrix>& rotateMatrix, const int& keptstates, const int& keptqstates, vector<DiagonalMatrix> *eigs)
{
// find and sort weight info
DensityMatrix transformmatrix = tracedMatrix;
std::vector<DiagonalMatrix> eigenMatrix;
if (dmrginp.hamiltonian() == BCS)
svd_densitymat(tracedMatrix, transformmatrix, eigenMatrix);
else
diagonalise_dm(tracedMatrix, transformmatrix, eigenMatrix);
if (eigs != 0)
*eigs = eigenMatrix;
vector<pair<int, int> > inorderwts;
vector<vector<int> > wtsbyquanta;
sort_weights(eigenMatrix, inorderwts, wtsbyquanta);
// make transformation matrix by various algorithms
int totalstatesbydm = min(static_cast<int>(inorderwts.size()), keptstates);
int totalstatesbyquanta = min(static_cast<int>(inorderwts.size()), keptstates + keptqstates) - totalstatesbydm;
if (totalstatesbyquanta < 0) totalstatesbyquanta = 0;
p3out << "\t\t\t total states using dm and quanta " << totalstatesbydm << " " << totalstatesbyquanta << endl;
return assign_matrix_by_dm(rotateMatrix, eigenMatrix, transformmatrix, inorderwts, wtsbyquanta, totalstatesbydm,
totalstatesbyquanta, 0, 0);
}
}