forked from sanshar/Block
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initblocks.C
374 lines (335 loc) · 16.6 KB
/
initblocks.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
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 "global.h"
#include "initblocks.h"
#include "pario.h"
void SpinAdapted::InitBlocks::InitStartingBlock (SpinBlock& startingBlock, const bool &forward, int leftState, int rightState,
const int & forward_starting_size, const int &backward_starting_size,
const int& restartSize, const bool &restart, const bool& warmUp, int integralIndex)
{
if (restart && restartSize != 1)
{
int len = restart? restartSize : forward_starting_size;
vector<int> sites(len);
if (forward)
for (int i=0; i<len; i++)
sites[i] = i;
else
for (int i=0; i<len; i++)
sites[i] = dmrginp.last_site() - len +i ;
if (restart)
SpinBlock::restore (forward, sites, startingBlock, leftState, rightState);
else
SpinBlock::restore (true, sites, startingBlock, leftState, rightState);
}
else if (forward)
{
startingBlock = SpinBlock(0, forward_starting_size - 1, integralIndex, leftState==rightState, true);
if (dmrginp.add_noninteracting_orbs() && dmrginp.molecule_quantum().get_s().getirrep() != 0 && dmrginp.spinAdapted())
{
SpinQuantum s = dmrginp.molecule_quantum();
s = SpinQuantum(s.get_s().getirrep(), s.get_s(), IrrepSpace(0));
int qs = 1, ns = 1;
StateInfo addstate(ns, &s, &qs);
SpinBlock dummyblock(addstate, integralIndex);
SpinBlock newstartingBlock;
newstartingBlock.set_integralIndex() = integralIndex;
newstartingBlock.default_op_components(false, startingBlock, dummyblock, true, true, leftState==rightState);
newstartingBlock.setstoragetype(LOCAL_STORAGE);
newstartingBlock.BuildSumBlock(NO_PARTICLE_SPIN_NUMBER_CONSTRAINT, startingBlock, dummyblock);
startingBlock.clear();
startingBlock = newstartingBlock;
}
}
else
{
std::vector<int> backwardSites;
if(dmrginp.spinAdapted()) {
for (int i = 0; i < backward_starting_size; ++i)
backwardSites.push_back (dmrginp.last_site() - i - 1);
}
else {
for (int i = 0; i < backward_starting_size; ++i)
backwardSites.push_back (dmrginp.last_site()/2 - i - 1);
}
sort (backwardSites.begin (), backwardSites.end ());
startingBlock.set_integralIndex() = integralIndex;
startingBlock.default_op_components(false, leftState==rightState);
startingBlock.BuildTensorProductBlock (backwardSites);
}
}
void SpinAdapted::InitBlocks::InitNewSystemBlock(SpinBlock &system, SpinBlock &systemDot, SpinBlock &newSystem, int leftState, int rightState, const int& sys_add, const bool &direct, int integralIndex, const Storagetype &storage, bool haveNormops, bool haveCompops, int constraint)
{
newSystem.set_integralIndex() = integralIndex;
newSystem.default_op_components(direct, system, systemDot, haveNormops, haveCompops, leftState==rightState);
newSystem.setstoragetype(storage);
newSystem.BuildSumBlock (constraint, system, systemDot);
p2out << "\t\t\t NewSystem block " << endl << newSystem << endl;
newSystem.printOperatorSummary();
}
void SpinAdapted::InitBlocks::InitNewEnvironmentBlock(SpinBlock &environment, SpinBlock& environmentDot, SpinBlock &newEnvironment,
const SpinBlock &system, SpinBlock &systemDot, int leftState, int rightState,
const int &sys_add, const int &env_add, const bool &forward, const bool &direct,
const bool &onedot, const bool &nexact, const bool &useSlater, int integralIndex,
bool haveNormops, bool haveCompops, const bool& dot_with_sys, int constraint) {
// now initialise environment Dot
int systemDotStart, systemDotEnd, environmentDotStart, environmentDotEnd, environmentStart, environmentEnd;
int systemDotSize = sys_add - 1;
int environmentDotSize = env_add - 1;
if (forward) {
systemDotStart = dmrginp.spinAdapted() ? *system.get_sites().rbegin () + 1 : (*system.get_sites().rbegin ())/2 + 1 ;
systemDotEnd = systemDotStart + systemDotSize;
environmentDotStart = systemDotEnd + 1;
environmentDotEnd = environmentDotStart + environmentDotSize;
environmentStart = environmentDotEnd + 1;
environmentEnd = dmrginp.spinAdapted() ? dmrginp.last_site() - 1 : dmrginp.last_site()/2 - 1;
} else {
systemDotStart = dmrginp.spinAdapted() ? system.get_sites()[0] - 1 : (system.get_sites()[0])/2 - 1 ;
systemDotEnd = systemDotStart - systemDotSize;
environmentDotStart = systemDotEnd - 1;
environmentDotEnd = environmentDotStart - environmentDotSize;
environmentStart = environmentDotEnd - 1;
environmentEnd = 0;
}
std::vector<int> environmentSites;
environmentSites.resize(abs(environmentEnd - environmentStart) + 1);
for (int i = 0; i < abs(environmentEnd - environmentStart) + 1; ++i) *(environmentSites.begin () + i) = min(environmentStart,environmentEnd) + i;
// now initialise environment
if (useSlater) { // for FCI
StateInfo system_stateinfo = system.get_stateInfo();
StateInfo sysdot_stateinfo = systemDot.get_stateInfo();
StateInfo tmp;
TensorProduct (system_stateinfo, sysdot_stateinfo, tmp, NO_PARTICLE_SPIN_NUMBER_CONSTRAINT);
// tmp has the system+dot quantum numbers
tmp.CollectQuanta ();
// exact environment
if (dmrginp.do_fci() || environmentSites.size() == nexact) {
if ((!dot_with_sys && onedot) || !onedot) { // environment has dot
environment.set_integralIndex() = integralIndex;
environment.default_op_components(!forward, leftState==rightState);
environment.setstoragetype(DISTRIBUTED_STORAGE);
environment.BuildTensorProductBlock(environmentSites); // exact block
SpinBlock::store (true, environmentSites, environment, leftState, rightState);
}
else { // environment has no dot, so newEnv = Env
newEnvironment.set_integralIndex() = integralIndex;
newEnvironment.default_op_components(!forward, leftState==rightState);
newEnvironment.setstoragetype(DISTRIBUTED_STORAGE);
newEnvironment.BuildTensorProductBlock(environmentSites);
SpinBlock::store (true, environmentSites, newEnvironment, leftState, rightState);
}
} else if (dmrginp.warmup() == LOCAL2 || dmrginp.warmup() == LOCAL3 || dmrginp.warmup() == LOCAL4) {
int nactiveSites, ncoreSites;
if (dmrginp.warmup() == LOCAL2) {
nactiveSites = 1;
} else if (dmrginp.warmup() == LOCAL3) {
nactiveSites = 2;
} else if (dmrginp.warmup() == LOCAL4) {
nactiveSites = 3;
}
if (dot_with_sys && onedot) {
nactiveSites += 1;
}
if (nactiveSites > environmentSites.size()) {
nactiveSites = environmentSites.size();
}
ncoreSites = environmentSites.size() - nactiveSites;
// figure out what sites are in the active and core sites
int environmentActiveEnd = forward ? environmentStart + nactiveSites - 1 : environmentStart - nactiveSites + 1;
int environmentCoreStart = forward ? environmentActiveEnd + 1 : environmentActiveEnd - 1;
std::vector<int> activeSites(nactiveSites), coreSites(ncoreSites);
for (int i = 0; i < nactiveSites; ++i) {
activeSites[i] = min(environmentStart,environmentActiveEnd) + i;
}
for (int i = 0; i < ncoreSites; ++i) {
coreSites[i] = min(environmentCoreStart,environmentEnd) + i;
}
SpinBlock environmentActive, environmentCore;
if (coreSites.size() > 0) {
environmentActive.set_integralIndex() = integralIndex;
environmentCore.set_integralIndex() = integralIndex;
environmentActive.default_op_components(!forward, leftState==rightState);
environmentActive.setstoragetype(DISTRIBUTED_STORAGE);
environmentCore.default_op_components(!forward, leftState==rightState);
environmentCore.setstoragetype(DISTRIBUTED_STORAGE);
environmentActive.BuildTensorProductBlock(activeSites);
environmentCore.BuildSingleSlaterBlock(coreSites);
dmrginp.datatransfer -> start();
environmentCore.addAdditionalCompOps();
environmentActive.addAdditionalCompOps();
dmrginp.datatransfer -> stop();
if ((!dot_with_sys && onedot) || !onedot) {
environment.set_integralIndex() = integralIndex;
environment.default_op_components(!forward, leftState == rightState);
environment.setstoragetype(DISTRIBUTED_STORAGE);
environment.BuildSumBlock(constraint, environmentCore, environmentActive);
} else {
newEnvironment.set_integralIndex() = integralIndex;
newEnvironment.default_op_components(direct, environmentCore, environmentActive, haveNormops, haveCompops, leftState == rightState);
newEnvironment.setstoragetype(DISTRIBUTED_STORAGE);
newEnvironment.BuildSumBlock(constraint, environmentCore, environmentActive);
p2out << "\t\t\t NewEnvironment block " << endl << newEnvironment << endl;
newEnvironment.printOperatorSummary();
}
} else { // no core
if ((!dot_with_sys && onedot) || !onedot) {
environment.set_integralIndex() = integralIndex;
environment.default_op_components(!forward, leftState==rightState);
environment.setstoragetype(DISTRIBUTED_STORAGE);
environment.BuildTensorProductBlock(environmentSites); // exact block
} else {
newEnvironment.set_integralIndex() = integralIndex;
newEnvironment.default_op_components(!forward, leftState==rightState);
newEnvironment.setstoragetype(DISTRIBUTED_STORAGE);
newEnvironment.BuildTensorProductBlock(environmentSites);
}
}
} else { //used for warmup guess environemnt
std::vector<SpinQuantum> quantumNumbers;
std::vector<int> distribution;
std::map<SpinQuantum, int> quantaDist;
std::map<SpinQuantum, int>::iterator quantaIterator;
bool environmentComplementary = !forward;
StateInfo tmp2;
// tmp is the quantum numbers of newSystem (sys + sysdot)
if (onedot) tmp.quanta_distribution (quantumNumbers, distribution, true);
else {
StateInfo environmentdot_stateinfo = environmentDot.get_stateInfo();
TensorProduct (tmp, environmentdot_stateinfo, tmp2, constraint);
tmp2.CollectQuanta ();
tmp2.quanta_distribution (quantumNumbers, distribution, true);
}
for (int i = 0; i < distribution.size (); ++i) {
quantaIterator = quantaDist.find(quantumNumbers[i]);
if (quantaIterator != quantaDist.end()) distribution[i] += quantaIterator->second;
distribution [i] /= 4; distribution [i] += 1;
if (distribution [i] > dmrginp.nquanta()) distribution [i] = dmrginp.nquanta();
if(quantaIterator != quantaDist.end()) {
quantaIterator->second = distribution[i];
} else {
quantaDist[quantumNumbers[i]] = distribution[i];
}
}
p2out << "\t\t\t Quantum numbers and states used for warm up :: " << endl << "\t\t\t ";
quantumNumbers.clear(); quantumNumbers.reserve(distribution.size());
distribution.clear();distribution.reserve(quantumNumbers.size());
std::map<SpinQuantum, int>::iterator qit = quantaDist.begin();
for (; qit != quantaDist.end(); qit++) {
quantumNumbers.push_back( qit->first); distribution.push_back(qit->second);
p2out << quantumNumbers.back() << " = " << distribution.back() << ", ";
if (! (quantumNumbers.size() - 6) % 6) p2out << endl << "\t\t\t ";
}
p2out << endl;
if(dot_with_sys && onedot) {
newEnvironment.set_integralIndex() = integralIndex;
newEnvironment.BuildSlaterBlock (environmentSites, quantumNumbers, distribution, false, false);
} else {
environment.set_integralIndex() = integralIndex;
environment.BuildSlaterBlock (environmentSites, quantumNumbers, distribution, false, haveNormops);
}
}
} else {
p2out << "\t\t\t Restoring block of size " << environmentSites.size () << " from previous iteration" << endl;
if(dot_with_sys && onedot) {
newEnvironment.set_integralIndex() = integralIndex;
SpinBlock::restore (!forward, environmentSites, newEnvironment, leftState, rightState);
} else {
environment.set_integralIndex() = integralIndex;
SpinBlock::restore (!forward, environmentSites, environment, leftState, rightState);
}
if (dmrginp.outputlevel() > 0)
mcheck("");
}
// now initialise newEnvironment
if (!dot_with_sys || !onedot) {
dmrginp.datatransfer -> start();
environment.addAdditionalCompOps();
dmrginp.datatransfer -> stop();
newEnvironment.set_integralIndex() = integralIndex;
newEnvironment.default_op_components(direct, environment, environmentDot, haveNormops, haveCompops, leftState==rightState);
newEnvironment.setstoragetype(DISTRIBUTED_STORAGE);
newEnvironment.BuildSumBlock (constraint, environment, environmentDot);
p2out << "\t\t\t Environment block " << endl << environment << endl;
environment.printOperatorSummary();
p2out << "\t\t\t NewEnvironment block " << endl << newEnvironment << endl;
newEnvironment.printOperatorSummary();
} else {
p2out << "\t\t\t Environment block " << endl << newEnvironment << endl;
newEnvironment.printOperatorSummary();
}
}
void SpinAdapted::InitBlocks::InitNewOverlapEnvironmentBlock(SpinBlock &environment, SpinBlock& environmentDot, SpinBlock &newEnvironment,
const SpinBlock &system, SpinBlock &systemDot, int leftState, int rightState,
const int &sys_add, const int &env_add, const bool &forward, int integralIndex,
const bool &onedot, const bool& dot_with_sys, int constraint)
{
// now initialise environment Dot
int systemDotStart, systemDotEnd, environmentDotStart, environmentDotEnd, environmentStart, environmentEnd;
int systemDotSize = sys_add - 1;
int environmentDotSize = env_add - 1;
if (forward)
{
systemDotStart = dmrginp.spinAdapted() ? *system.get_sites().rbegin () + 1 : (*system.get_sites().rbegin ())/2 + 1 ;
systemDotEnd = systemDotStart + systemDotSize;
environmentDotStart = systemDotEnd + 1;
environmentDotEnd = environmentDotStart + environmentDotSize;
environmentStart = environmentDotEnd + 1;
environmentEnd = dmrginp.spinAdapted() ? dmrginp.last_site() - 1 : dmrginp.last_site()/2 - 1;
}
else
{
systemDotStart = dmrginp.spinAdapted() ? system.get_sites()[0] - 1 : (system.get_sites()[0])/2 - 1 ;
systemDotEnd = systemDotStart - systemDotSize;
environmentDotStart = systemDotEnd - 1;
environmentDotEnd = environmentDotStart - environmentDotSize;
environmentStart = environmentDotEnd - 1;
environmentEnd = 0;
}
std::vector<int> environmentSites;
environmentSites.resize(abs(environmentEnd - environmentStart) + 1);
for (int i = 0; i < abs(environmentEnd - environmentStart) + 1; ++i) *(environmentSites.begin () + i) = min(environmentStart,environmentEnd) + i;
p2out << "\t\t\t Restoring block of size " << environmentSites.size () << " from previous iteration" << endl;
if(dot_with_sys && onedot) {
newEnvironment.set_integralIndex() = integralIndex;
SpinBlock::restore (!forward, environmentSites, newEnvironment, leftState, rightState);
}
else {
environment.set_integralIndex() = integralIndex;
SpinBlock::restore (!forward, environmentSites, environment, leftState, rightState);
}
if (dmrginp.outputlevel() > 0)
mcheck("");
// now initialise newEnvironment
if (!dot_with_sys || !onedot)
{
newEnvironment.set_integralIndex() = integralIndex;
newEnvironment.initialise_op_array(OVERLAP, false);
//newEnvironment.set_op_array(OVERLAP) = boost::shared_ptr<Op_component<Overlap> >(new Op_component<Overlap>(false));
newEnvironment.setstoragetype(DISTRIBUTED_STORAGE);
newEnvironment.BuildSumBlock (constraint, environment, environmentDot);
p2out << "\t\t\t Environment block " << endl << environment << endl;
environment.printOperatorSummary();
p2out << "\t\t\t NewEnvironment block " << endl << newEnvironment << endl;
newEnvironment.printOperatorSummary();
}
else {
p2out << "\t\t\t Environment block " << endl << newEnvironment << endl;
newEnvironment.printOperatorSummary();
}
}
void SpinAdapted::InitBlocks::InitBigBlock(SpinBlock &leftBlock, SpinBlock &rightBlock, SpinBlock &big)
{
//set big block components
big.set_integralIndex() = leftBlock.get_integralIndex();
big.set_big_components();
// build the big block
if (dmrginp.hamiltonian() == BCS) {
big.BuildSumBlock(SPIN_NUMBER_CONSTRAINT, leftBlock, rightBlock);
} else {
big.BuildSumBlock(PARTICLE_SPIN_NUMBER_CONSTRAINT, leftBlock, rightBlock);
}
}