-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operators.jl
129 lines (79 loc) · 3.84 KB
/
Operators.jl
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
using LinearAlgebra
using Parameters
"""
The important idea is to create the Operator_one/two_site object which acts like an operator as we would use in text book.
fields :
operator_name -> locates the corresponding operator function.
indices -> set of indices where the operator acts.
This way we can create any kind of interaction among two sites by manually creating interaction between two spins of arbritrary kind.
Furthermore, we can also add another field in this struct (or just add another element in the indices field) that will give the coupling
constant corresponding to the given operator and indices. This way we can create any kind of spin hamiltonian upto two spin interaction.
"""
@with_kw struct Operator_two_site
operator_name::AbstractString
operator_type::AbstractString = "SpinHalf"
indices::Vector{Tuple{Int64, Int64}}
end
@with_kw struct Operator_one_site
operator_name::AbstractString
operator_type::AbstractString = "SpinHalf"
indices::Vector{Int64}
end
function Two_site_matrix(operator::Operator_two_site,hilbert_space::Union{basis1,basis2},N::Int64)
Ham = zeros(length(hilbert_space.configs),length(hilbert_space.configs))
count = 0
oprt = eval(Symbol(operator.operator_name))
oprt_typ = operator.operator_type
if nfields(hilbert_space) == 1
for conf in hilbert_space.configs
count += 1
for indx in operator.indices
coeff, new_conf = oprt(conf,indx[1],indx[2],N,oprt_typ)
Ham[bisection_checkstate(hilbert_space,new_conf),count] += coeff
end
end
return Ham
elseif nfields(hilbert_space) == 3
for conf in hilbert_space.configs
count += 1
for indx in operator.indices
coeff, new_conf = oprt(conf,indx[1],indx[2],N,oprt_typ)
represent, l = representative(new_conf,N)
b = bisection_checkstate(hilbert_space,represent)
if b >= 0
Ham[b,count] += coeff_trans_inv(hilbert_space.periodicity[count],hilbert_space.periodicity[b],coeff,hilbert_space.k,l,N)
end
end
end
return Ham
end
end
function One_site_matrix(operator::Operator_one_site,hilbert_space::Union{basis1,basis2},N::Int64)
Ham = zeros(length(hilbert_space.configs),length(hilbert_space.configs))
count = 0
oprt = eval(Symbol(operator.operator_name))
oprt_typ = operator.operator_type
if nfields(hilbert_space) == 1
for conf in hilbert_space.configs
count += 1
for indx in operator.indices
coeff, new_conf = oprt(conf,indx,N,oprt_typ)
Ham[bisection_checkstate(hilbert_space,new_conf),count] += coeff
end
end
return Ham
elseif nfields(hilbert_space) == 3
for conf in hilbert_space.configs
count += 1
for indx in operator.indices
coeff, new_conf = oprt(conf,indx,N,oprt_typ)
represent, l = representative(new_conf,N)
b = bisection_checkstate(hilbert_space,represent)
if b >= 0
Ham[b,count] += coeff_trans_inv(hilbert_space.periodicity[count],hilbert_space.periodicity[b],coeff,hilbert_space.k,l,N)
end
end
end
return Ham
end
end