Skip to content

Commit d3dd216

Browse files
committed
Clean up notations and tests
1 parent b525674 commit d3dd216

2 files changed

Lines changed: 36 additions & 49 deletions

File tree

src/models/ising.jl

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ If `Jx == Jy`, this returns the isotropic critical point `ising_βc`.
7878
"""
7979
function ising_anisotropic_βc(Jx::Real, Jy::Real)
8080
if Jx == Jy
81-
return Float64(ising_βc)
81+
return Float64(ising_βc) / Jx
8282
end
8383
f(β) = sinh(2β * Jx) * sinh(2β * Jy) - 1.0
8484
β_max = Float64(ising_βc) / min(Jx, Jy) * 5.0
@@ -100,14 +100,14 @@ with anisotropic couplings `Jx`, `Jy` is
100100
where `Kx = β Jx`, `Ky = β Jy`.
101101
"""
102102
function f_onsager_anisotropic::Real, Jx::Real, Jy::Real)
103-
K1 = Float64* Jx)
104-
K2 = Float64* Jy)
105-
if Jx == Jy && abs(K1 - Float64(ising_βc)) < 1.0e-14
103+
Kx, Ky = Float64* Jx), Float64* Jy)
104+
# Only use the high-precision constant at the isotropic critical point with J=1
105+
if Jx == 1 && Jy == 1 && abs(Kx - Float64(ising_βc)) < 1.0e-14
106106
return Float64(f_onsager)
107107
end
108108

109-
c1, s1 = cosh(2K1), sinh(2K1)
110-
c2, s2 = cosh(2K2), sinh(2K2)
109+
c1, s1 = cosh(2Kx), sinh(2Kx)
110+
c2, s2 = cosh(2Ky), sinh(2Ky)
111111
s2_sq = s2^2
112112

113113
# The 2D Onsager integral reduces to 1D after integrating out θ₂ analytically
@@ -143,27 +143,12 @@ Defaults to the isotropic case `Jx = Jy = 1.0`.
143143
### Examples
144144
```julia
145145
classical_ising() # default: ℤ₂ symmetric, isotropic at βc
146-
classical_ising(Trivial, 0.5; h = 1.0) # no symmetry, with magnetic field
147-
classical_ising(1.0; Jx = 1.0, Jy = 0.5) # anisotropic: Jx=1, Jy=0.5
146+
classical_ising(Trivial, 0.5; h = 1.0) # no symmetry, with magnetic field
147+
classical_ising(1.0; Jx = 1.0, Jy = 0.5) # anisotropic: Jx=1, Jy=0.5
148148
classical_ising(Trivial, 0.5; Jy = 0.8) # anisotropic without symmetry
149149
150150
!!! info
151-
When studying this model with impurities, the tensor without symmetry should be constructed,
152-
as the impurity breaks the ℤ₂ symmetry.
153-
154-
!!! note "Leg convention"
155-
The tensor follows the standard TNRKit convention:
156-
157-
```
158-
3 (up, vertical, Jy)
159-
|
160-
1 ←--+--← 4 (right, horizontal, Jx)
161-
|
162-
2 (down, vertical, Jy)
163-
```
164-
165-
Legs 1 and 4 are **horizontal** bonds (coupling `Jx`),
166-
legs 2 and 3 are **vertical** bonds (coupling `Jy`).
151+
When studying this model with impurities, the tensor without symmetry should be constructed, as the impurity breaks the ℤ₂ symmetry.
167152
168153
See also: [`classical_ising_3D`](@ref), [`ising_anisotropic_βc`](@ref).
169154
"""
@@ -173,28 +158,24 @@ end
173158
classical_ising(; kwargs...) = classical_ising(ising_βc; kwargs...)
174159
classical_ising(::Type{Trivial}; kwargs...) = classical_ising(Trivial, ising_βc; kwargs...)
175160
function classical_ising(::Type{Trivial}, β::Real; T::Type{<:Number} = Float64, h = 0.0, Jx = 1.0, Jy = 1.0)
176-
Kx = β * Jx
177-
Ky = β * Jy
161+
Kx, Ky = β * Jx, β * Jy
178162
init = zeros(T, 2, 2, 2, 2)
179163
for (i, j, k, l) in Iterators.product([1:2 for _ in 1:4]...)
180164
init[i, j, k, l] = mod(i + j + k + l, 2) == 0 ? cosh(h * β) : sinh(h * β)
181165
end
182166
init = TensorMap(init, ℂ^2 ^2 ^2 ^2)
183167

184-
bond_tensor_x = ising_bond_tensor(Kx, T) # horizontal bonds (legs 1, 4)
185-
bond_tensor_y = ising_bond_tensor(Ky, T) # vertical bonds (legs 2, 3)
186-
168+
bond_tensor_x = ising_bond_tensor(Kx, T)
169+
bond_tensor_y = ising_bond_tensor(Ky, T)
187170
@tensor T[-1 -2; -3 -4] := 2 * init[1 2; 3 4] * bond_tensor_x[-1; 1] * bond_tensor_y[-2; 2] * bond_tensor_y[3; -3] * bond_tensor_x[4; -4]
188171
return T
189172
end
190173
function classical_ising(::Type{Z2Irrep}, β::Real; T::Type{<:Number} = Float64, h = 0.0, Jx = 1.0, Jy = 1.0)
191174
@assert h == 0.0 "External magnetic field is not compatible with ℤ₂ symmetry"
192-
Kx = β * Jx
193-
Ky = β * Jy
194-
195-
xh, yh = cosh(Kx), sinh(Kx) # horizontal bonds (legs 1, 4)
196-
xv, yv = cosh(Ky), sinh(Ky) # vertical bonds (legs 2, 3)
197-
w = sqrt(xh * yh * xv * yv) # off-diagonal coupling √(cosh Kx sinh Kx cosh Ky sinh Ky)
175+
Kx, Ky = β * Jx, β * Jy
176+
xh, yh = cosh(Kx), sinh(Kx)
177+
xv, yv = cosh(Ky), sinh(Ky)
178+
w = sqrt(xh * yh * xv * yv)
198179

199180
S = ℤ₂Space(0 => 1, 1 => 1)
200181
t = zeros(T, S S S S)
@@ -213,9 +194,9 @@ with a magnetisation impurity. Compatible with no symmetry on each of its spaces
213194
214195
### Examples
215196
```julia
216-
classical_ising_impurity() # default: isotropic at βc
217-
classical_ising_impurity(0.5; h = 1.0) # with magnetic field
218-
classical_ising_impurity(0.5; Jx = 1.0, Jy = 0.5) # anisotropic couplings
197+
classical_ising_impurity() # default: isotropic at βc
198+
classical_ising_impurity(0.5; h = 1.0) # with magnetic field
199+
classical_ising_impurity(0.5; Jx = 1.0, Jy = 0.5) # anisotropic couplings
219200
```
220201
!!! info
221202
When calculating the free energy with `free_energy()`, set the `initial_size` keyword argument to `2.0`.
@@ -228,16 +209,15 @@ function classical_ising_impurity(β::Real; kwargs...)
228209
end
229210
classical_ising_impurity(; kwargs...) = classical_ising_impurity(ising_βc; kwargs...)
230211
function classical_ising_impurity(::Type{Trivial}, β::Real; T::Type{<:Number} = Float64, h = 0.0, Jx = 1.0, Jy = 1.0)
231-
Kx = β * Jx
232-
Ky = β * Jy
212+
Kx, Ky = β * Jx, β * Jy
233213
init = zeros(T, 2, 2, 2, 2)
234214
for (i, j, k, l) in Iterators.product([1:2 for _ in 1:4]...)
235215
init[i, j, k, l] = mod(i + j + k + l, 2) == 0 ? sinh(h * β) : cosh(h * β)
236216
end
237217
init = TensorMap(init, ℂ^2 ^2 ^2 ^2)
238218

239-
bond_tensor_x = ising_bond_tensor(Kx, T) # horizontal bonds (legs 1, 4)
240-
bond_tensor_y = ising_bond_tensor(Ky, T) # vertical bonds (legs 2, 3)
219+
bond_tensor_x = ising_bond_tensor(Kx, T)
220+
bond_tensor_y = ising_bond_tensor(Ky, T)
241221

242222
@tensor t[-1 -2; -3 -4] := 2 * init[1 2; 3 4] * bond_tensor_x[-1; 1] * bond_tensor_y[-2; 2] * bond_tensor_y[3; -3] * bond_tensor_x[4; -4]
243223
return t

test/models/models.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,24 @@ end
9090

9191
# Tests for anisotropic Ising helper functions
9292
@testset "Anisotropic Ising helpers" begin
93-
# Critical condition: sinh(2βc Jx) * sinh(2βc Jy) = 1
94-
for (Jx, Jy) in [(1.0, 1.0), (1.0, 0.5), (1.0, 0.3)]
93+
# Critical condition: sinh(2βc Jx) · sinh(2βc Jy) = 1, and βc scaling
94+
for (Jx, Jy) in [(1.0, 1.0), (1.0, 0.5), (1.0, 0.3), (2.0, 2.0)]
9595
βc = ising_anisotropic_βc(Jx, Jy)
9696
@test sinh(2 * Float64(βc) * Jx) * sinh(2 * Float64(βc) * Jy) 1.0 rtol = 1.0e-14
97+
if Jx == Jy
98+
@test Float64(βc) Float64(ising_βc) / Jx # βc scales as 1/J
99+
end
97100
end
98101

99-
# Jx=Jy reduces to the isotropic critical point
100-
@test Float64(ising_anisotropic_βc(1.0, 1.0)) Float64(ising_βc) rtol = 1.0e-14
101-
102-
# f_onsager_anisotropic at Jx=Jy=1, βc matches f_onsager
103-
@test f_onsager_anisotropic(ising_βc, 1.0, 1.0) Float64(f_onsager) rtol = 1.0e-14
102+
# Free energy scaling: f(β, J, J) = J · f_iso(β·J)
103+
for (β, J) in [(Float64(ising_βc), 1.0), (0.5, 2.0), (0.3, 1.5)]
104+
βc = ising_anisotropic_βc(J, J)
105+
f_J = f_onsager_anisotropic(β, J, J)
106+
f_Jc = f_onsager_anisotropic(βc, J, J)
107+
f_1 = f_onsager_anisotropic* J, 1.0, 1.0)
108+
@test f_J J * f_1 rtol = 1.0e-6
109+
@test f_Jc J * Float64(f_onsager) rtol = 1.0e-6
110+
end
104111

105112
# Jy→0 limit: f should approach the 1D Ising result
106113
β = 0.5

0 commit comments

Comments
 (0)