-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmiscellaneous.h
More file actions
131 lines (109 loc) · 2.77 KB
/
miscellaneous.h
File metadata and controls
131 lines (109 loc) · 2.77 KB
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
//
// miscellaneous.h
// ED_solver
//
// Created by Bin Xu on 12/19/14.
// Copyright (c) 2014 Bin Xu. All rights reserved.
//
#ifndef ED_solver_miscellaneous_h
#define ED_solver_miscellaneous_h
#include <bitset>
#include <complex>
#include "constants.h"
using namespace std;
struct Pxy
{
int px, py;
bool operator== (const Pxy &rhs) const
{ return px == rhs.px && py == rhs.py; }
Pxy operator+ (const Pxy &rhs) const
{ Pxy temp(px + rhs.px, py + rhs.py); return temp; }
Pxy(){}
Pxy(int o_px, int o_py){ px = o_px, py = o_py; }
};
struct Orbital
{
char spin; //In spin 1/2 case, one sets 1 for up spin and 2 for down spin.
// k is the real momentum (kx, ky) : double; p is the nominal momentum (I, J) : int
Pxy p;
pair<double, double> k; //The real, rescaled momentum
double fac;
double radius2;
bool operator== (const Orbital &rhs) const
{
return p == rhs.p && spin == rhs.spin;
}
Orbital operator+ (const Orbital &rhs) const
{
Orbital temp(p.px+rhs.p.px, p.py+rhs.p.py, spin+rhs.spin);
return temp;
}
Orbital(){fac = 0; radius2 = 0;}
Orbital(int px, int py, char spin)
{
p.px = px, p.py = py, this->spin = spin;
fac = 0;
radius2 = 0;
}
};
struct OrbPair
{
Orbital orb1, orb2;
char spin;
Pxy p;
OrbPair(){}
OrbPair(const Orbital& orba, const Orbital& orbb)
{
orb1 = orba, orb2 = orbb; p = orb1.p + orb2.p;
spin = orb1.spin + orb2.spin;
}
};
struct OrbTriplet
{
Orbital orb1, orb2, orb3;
char spins;
Pxy p;
OrbTriplet(){}
OrbTriplet(const Orbital& orba, const Orbital& orbb, const Orbital& orbc)
: orb1(orba), orb2(orbb), orb3(orbc)
{
spins = orb1.spin + orb2.spin + orb3.spin;
}
};
typedef bitset<MaxOrbital> CompactState;
struct State
{
CompactState cstate;
unsigned state_id;
State(CompactState &o_cstate): cstate(o_cstate), state_id(0){}
State(): state_id(0){}
};
////////////////////////////////////////////////////////////////////////////////
// Hashers
////////////////////////////////////////////////////////////////////////////////
struct Pxy_hasher
{
size_t operator()(const Pxy& p) const
{
return (hash<int>()(p.px) ^ (hash<int>()(p.py) << 1));
}
};
struct Orbital_hasher
{
size_t operator()(const Orbital& orb) const
{
return (hash<char>()(orb.spin)^((hash<int>()(orb.p.px) ^ \
(hash<int>()(orb.p.py) << 1))<<1));
}
};
struct MatEle
{
unsigned bra, ket;
complex<double> amplitude;
MatEle()
{
bra = 0, ket = 0, amplitude = 0;
}
MatEle(int b, int k, complex<double> amp) : bra(b), ket(k), amplitude(amp) {}
};
#endif