-
Notifications
You must be signed in to change notification settings - Fork 4
/
lattice.cpp
96 lines (75 loc) · 2.46 KB
/
lattice.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
/*
* 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 "lattice.hpp"
using namespace std;
Lattice::index Lattice::get_index_from_spindex( Lattice::spindex l ) const
{
assert( l < 2 * L );
return l % L;
// this is a branchless version of:
// if ( get_spindex_type( l ) == Lattice::spindex_type::down ) {
// return l - L;
// } else {
// return l;
// }
}
Lattice::spindex Lattice::get_linked_spindex( Lattice::spindex l ) const
{
assert( l < 2 * L );
return l + ( 1 - static_cast<int>( 2 * ( l / L ) ) ) * L;
// this is a branchless version of:
// if ( get_spindex_type( l ) == Lattice::spindex_type::up ) {
// return l + L;
// } else {
// return l - L;
// }
}
Lattice::spindex_type Lattice::get_spindex_type( Lattice::spindex l ) const
{
assert( l < 2 * L );
if ( l < L ) {
return Lattice::spindex_type::up;
} else {
return Lattice::spindex_type::down;
}
}
vector<Lattice::spindex> Lattice::get_Xnn( Lattice::spindex l, unsigned int X ) const
{
vector<Lattice::spindex> Xnn;
get_Xnn( l, X, &Xnn );
return Xnn;
}
Eigen::VectorXi Lattice::get_random_spindex_occ(
unsigned int Npu, unsigned int Npd, mt19937& rng ) const
{
// this is the default distribution if the lattice has no special needs:
// it will just randomly distribute Npu/Npd particles per spin direction
Eigen::VectorXi spindex_occ = Eigen::VectorXi::Zero( 2 * L );
while ( spindex_occ.head( L ).sum() < static_cast<int>( Npu ) ) {
spindex_occ[ uniform_int_distribution<Lattice::spindex>( 0, L - 1 )( rng ) ] = 1;
}
while ( spindex_occ.tail( L ).sum() < static_cast<int>( Npd ) ) {
spindex_occ[ uniform_int_distribution<Lattice::spindex>( L, 2 * L - 1 )( rng ) ] = 1;
}
return spindex_occ;
}
bool Lattice::include_r_in_ssfac( index, index ) const
{
return true;
}