-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtvector.cpp
171 lines (125 loc) · 3.93 KB
/
tvector.cpp
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
/*
* Copyright (c) 2013, Robert Rueger <[email protected]>
*
* This file is part of hVMC.
*
* hVMC 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 3 of the License, or
* (at your option) any later version.
*
* hVMC 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 hVMC. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tvector.hpp"
#if VERBOSE >= 2
# include <iostream>
#endif
#include <cmath>
#include <algorithm>
#include "macros.h"
using namespace std;
TVector::TVector(
const Lattice* lat_init,
const Jastrow& v_init,
const ParticleConfiguration& pconf_init,
double deviation_target,
unsigned int updates_until_recalc_init )
: lat( lat_init ), v( v_init ), pconf( pconf_init ),
T( lat->L ),
updates_until_recalc( updates_until_recalc_init ),
updates_since_recalc( 0 ),
devstat( FPDevStat( deviation_target ) ) { }
void TVector::init()
{
T = calc_new();
devstat.reset();
updates_since_recalc = 0;
#if VERBOSE >= 2
cout << "TVector::init() : initial T = " << endl << T.transpose() << endl;
#endif
}
const Eigen::VectorXd& TVector::get() const
{
return T;
}
void TVector::update( const ParticleHop& hop )
{
if ( updates_since_recalc >= updates_until_recalc ) {
#if VERBOSE >= 2
cout << "TVector::update() : recalculating T!" << endl;
#endif
updates_since_recalc = 0;
Eigen::VectorXd T_approx = calc_qupdated( hop );
T = calc_new();
double dev = calc_deviation( T_approx, T );
devstat.add( dev );
#if VERBOSE >= 2
cout << "TVector::update() : recalculated T "
<< "with deviation = " << dev << endl;
if ( dev > devstat.target ) {
cout << "TVector::update() : deviation goal for matrix "
<< "T not met!" << endl
<< "TVector::update() : approximate T =" << endl
<< T_approx.transpose() << endl
<< "TVector::update() : exact T =" << endl
<< T.transpose() << endl;
}
#endif
assert( dev < devstat.target );
} else {
#if VERBOSE >= 2
cout << "TVector::update() : "
<< "performing a quick update of T!" << endl;
#endif
++updates_since_recalc;
T = calc_qupdated( hop );
#ifndef NDEBUG
Eigen::VectorXd T_chk = calc_new();
double dev = calc_deviation( T, T_chk );
# if VERBOSE >= 2
cout << "TVector::update() : "
<< "[DEBUG CHECK] deviation after quick update = " << dev << endl;
if ( dev > devstat.target || !std::isfinite( dev ) ) {
cout << "TVector::update() : deviation goal for matrix "
<< "T not met!" << endl
<< "TVector::update() : quickly updated T =" << endl
<< T.transpose() << endl
<< "TVector::update() : exact T =" << endl
<< T_chk.transpose() << endl;
}
# endif
#endif
assert( dev < devstat.target );
}
}
Eigen::VectorXd TVector::calc_new() const
{
Eigen::VectorXd T_new = Eigen::VectorXd::Zero( lat->L );
for ( Lattice::index i = 0; i < lat->L; ++i ) {
for ( Lattice::index j = 0; j < lat->L; ++j ) {
T_new( i ) +=
v( i, j ) * ( pconf.get_spindex_occ()[ j ] -
pconf.get_spindex_occ()[ j + lat->L ] );
}
}
return T_new;
}
Eigen::VectorXd TVector::calc_qupdated( const ParticleHop& hop ) const
{
Eigen::VectorXd T_diff( lat->L );
for ( Lattice::index i = 0; i < lat->L; ++i ) {
T_diff( i ) = v( i, lat->get_index_from_spindex( hop.l ) )
- v( i, lat->get_index_from_spindex( hop.k ) );
}
return T + ( hop.l < lat->L ? 1.0 : -1.0 ) * T_diff;
}
FPDevStat TVector::get_devstat() const
{
return devstat;
}