From 9d06f777a0c9fe35e0b8c41227f333bf48f33d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez=20Panadero?= Date: Tue, 21 Nov 2023 14:00:31 +0000 Subject: [PATCH] Master --- src/Dirac/Dirac.jl | 30 ++++++++++---- src/Groups/AlgebraU2.jl | 20 ++++++++++ src/Groups/FundamentalSU2.jl | 72 ++++++++++++++++++++++++++++++++++ src/Groups/Groups.jl | 7 +++- src/Groups/SU2Types.jl | 10 +++++ src/LatticeGPU.jl | 2 +- test/dirac/test_fp_fa.jl | 4 +- test/dirac/test_solver_plw.jl | 2 +- test/dirac/test_solver_rand.jl | 2 +- 9 files changed, 135 insertions(+), 14 deletions(-) create mode 100644 src/Groups/AlgebraU2.jl create mode 100644 src/Groups/FundamentalSU2.jl diff --git a/src/Dirac/Dirac.jl b/src/Dirac/Dirac.jl index 53e22d3..2d78098 100644 --- a/src/Dirac/Dirac.jl +++ b/src/Dirac/Dirac.jl @@ -54,15 +54,31 @@ struct DiracWorkspace{T} function DiracWorkspace(::Type{G}, ::Type{T}, lp::SpaceParm{4,6,B,D}) where {G,T <: AbstractFloat, B,D} - sr = scalar_field(Spinor{4,G}, lp) - sp = scalar_field(Spinor{4,G}, lp) - sAp = scalar_field(Spinor{4,G}, lp) - st = scalar_field(Spinor{4,G}, lp) + @timeit "Allocating DiracWorkspace" begin + if G == SU3fund + sr = scalar_field(Spinor{4,SU3fund{T}}, lp) + sp = scalar_field(Spinor{4,SU3fund{T}}, lp) + sAp = scalar_field(Spinor{4,SU3fund{T}}, lp) + st = scalar_field(Spinor{4,SU3fund{T}}, lp) + csw = tensor_field(U3alg{T},lp) + elseif G == SU2fund + sr = scalar_field(Spinor{4,SU2fund{T}}, lp) + sp = scalar_field(Spinor{4,SU2fund{T}}, lp) + sAp = scalar_field(Spinor{4,SU2fund{T}}, lp) + st = scalar_field(Spinor{4,SU2fund{T}}, lp) + csw = tensor_field(U2alg{T},lp) + else + sr = scalar_field(Spinor{4,G}, lp) + sp = scalar_field(Spinor{4,G}, lp) + sAp = scalar_field(Spinor{4,G}, lp) + st = scalar_field(Spinor{4,G}, lp) + csw = nothing + end + end - csw = tensor_field(U3alg{T},lp) + return new{T}(sr,sp,sAp,st,csw) + end - return new{T}(sr,sp,sAp,st,csw,cs) - end end export DiracWorkspace, DiracParam diff --git a/src/Groups/AlgebraU2.jl b/src/Groups/AlgebraU2.jl new file mode 100644 index 0000000..4e88638 --- /dev/null +++ b/src/Groups/AlgebraU2.jl @@ -0,0 +1,20 @@ + + + +struct U2alg{T} <: Algebra + u11::T + u22::T + u12::Complex{T} +end + +function antsym(a::SU2{T}) where T <: AbstractFloat + return U2alg{T}(2.0*imag(a.t1),-2.0*imag(a.t1),2.0*a.t2) +end + +Base.:*(a::U2alg{T},b::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(im*a.u11*b.t1 + a.u12*b.t2, + -conj(a.u12)*b.t1 + im*a.u22*b.t2) + +Base.:+(a::U2alg{T},b::U2alg{T}) where T <: AbstractFloat = U2alg{T}(a.u11 + b.u11, a.u22 + b.u22, a.u12 + b.u12) + +Base.:*(r::Number, a::U2alg{T}) where T <: AbstractFloat = U2alg{T}(r*a.u11, r*a.u22, r*a.u12) + diff --git a/src/Groups/FundamentalSU2.jl b/src/Groups/FundamentalSU2.jl new file mode 100644 index 0000000..c44a4d5 --- /dev/null +++ b/src/Groups/FundamentalSU2.jl @@ -0,0 +1,72 @@ + + + +SU2fund(a::T, b::T) where T <: AbstractFloat = SU2fund{T}(complex(a), complex(b)) + +""" + dag(a::SU2fund{T}) + +Returns the conjugate of a fundamental element. +""" +dag(a::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(conj(a.t1), conj(a.t2)) + +""" + norm(a::SU2fund{T}) + +Returns the norm of a fundamental element. Same result as dot(a,a). +""" +norm(a::SU2fund{T}) where T <: AbstractFloat = sqrt((abs2(a.t1) + abs2(a.t2))) + +""" + norm(a::SU2fund{T}) + +Returns the norm of a fundamental element. Same result as sqrt(dot(a,a)). +""" +norm2(a::SU2fund{T}) where T <: AbstractFloat = (abs2(a.t1) + abs2(a.t2)) + +""" + dot(a::SU2fund{T},b::SU2fund{T}) + +Returns the scalar product of two fundamental elements. The convention is for the product to the linear in the second argument, and anti-linear in the first argument. +""" +dot(g1::SU2fund{T},g2::SU2fund{T}) where T <: AbstractFloat = conj(g1.t1)*g2.t1+conj(g1.t2)*g2.t2 + +""" + *(g::SU2{T},b::SU2fund{T}) + +Returns ga +""" +Base.:*(g::SU2{T},b::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(g.t1*b.t1 + g.t2*b.t2,-conj(g.t2)*b.t1 + conj(g.t1)*b.t2) + +""" + \\(g::SU2{T},b::SU2fund{T}) + +Returns g^dag b +""" +Base.:\(g::SU2{T},b::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(conj(g.t1)*b.t1 - g.t2 * b.t2,conj(g.t2)*b.t1 + g.t1 * b.t2) + +""" + *(a::SU2alg{T},b::SU2fund{T}) + +Returns a*b +""" + +Base.:*(a::SU2alg{T},b::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(complex(0.0, a.t3)*b.t1/2 + complex(a.t2,a.t1)*b.t2/2, + complex(-a.t2,a.t1)*b.t1/2 + complex(0.0, -a.t3)*b.t1/2) + +Base.:+(a::SU2fund{T},b::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(a.t1+b.t1,a.t2+b.t2) +Base.:-(a::SU2fund{T},b::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(a.t1-b.t1,a.t2-b.t2) +Base.:+(a::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(a.t1,a.t2) +Base.:-(a::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(-a.t1,-a.t2) +imm(a::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(complex(-imag(a.t1),real(a.t1)), + complex(-imag(a.t2),real(a.t2))) +mimm(a::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(complex(imag(a.t1),-real(a.t1)), + complex(imag(a.t2),-real(a.t2))) + +# Operations with numbers +Base.:*(a::SU2fund{T},b::Number) where T <: AbstractFloat = SU2fund{T}(b*a.t1,b*a.t2) +Base.:*(b::Number,a::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(b*a.t1,b*a.t2) +Base.:/(a::SU2fund{T},b::Number) where T <: AbstractFloat = SU2fund{T}(a.t1/b,a.t2/b) + +Base.:*(a::M2x2{T},b::SU2fund{T}) where T <: AbstractFloat = SU2fund{T}(a.u11*b.t1 + a.u12*b.t2, + a.u21*b.t1 + a.u22*b.t2) \ No newline at end of file diff --git a/src/Groups/Groups.jl b/src/Groups/Groups.jl index 3ed40ca..c6380b5 100644 --- a/src/Groups/Groups.jl +++ b/src/Groups/Groups.jl @@ -54,11 +54,12 @@ export Group, Algebra, GMatrix # SU(2) and 2x2 matrix operations ## include("SU2Types.jl") -export SU2, SU2alg, M2x2 +export SU2, SU2alg, M2x2, SU2fund include("GroupSU2.jl") include("M2x2.jl") include("AlgebraSU2.jl") +include("FundamentalSU2.jl") ## END SU(2) ## @@ -74,8 +75,10 @@ include("FundamentalSU3.jl") export imm, mimm ## END SU(3) + +include("AlgebraU2.jl") include("AlgebraU3.jl") -export U3alg +export U2alg, U3alg include("GroupU1.jl") export U1, U1alg diff --git a/src/Groups/SU2Types.jl b/src/Groups/SU2Types.jl index 4a6a0f7..7525743 100644 --- a/src/Groups/SU2Types.jl +++ b/src/Groups/SU2Types.jl @@ -53,3 +53,13 @@ Base.convert(::Type{M2x2{T}}, a::SU2{T}) where T = M2x2{T}(a.t1,a.t2,-conj(a.t2) Random.rand(rng::AbstractRNG, ::Random.SamplerType{SU2alg{T}}) where T <: AbstractFloat = SU2alg{T}(randn(rng,T),randn(rng,T),randn(rng,T)) Random.rand(rng::AbstractRNG, ::Random.SamplerType{SU2{T}}) where T <: AbstractFloat = exp(SU2alg{T}(randn(rng,T),randn(rng,T),randn(rng,T))) + + +struct SU2fund{T} + t1::Complex{T} + t2::Complex{T} +end + +Base.zero(::Type{SU2fund{T}}) where T <: AbstractFloat = SU2fund{T}(zero(T),zero(T),zero(T)) +Random.rand(rng::AbstractRNG, ::Random.SamplerType{SU2fund{T}}) where T <: AbstractFloat = SU2fund{T}(complex(randn(rng,T),randn(rng,T)), + complex(randn(rng,T),randn(rng,T))) \ No newline at end of file diff --git a/src/LatticeGPU.jl b/src/LatticeGPU.jl index bb640f2..6eccf5c 100644 --- a/src/LatticeGPU.jl +++ b/src/LatticeGPU.jl @@ -16,7 +16,7 @@ include("Groups/Groups.jl") using .Groups export Group, Algebra, GMatrix -export SU2, SU2alg, SU3, SU3alg, M3x3, M2x2, U1, U1alg, SU3fund, U3alg +export SU2, SU2alg, SU3, SU3alg, M3x3, M2x2, U1, U1alg, SU3fund, U3alg, SU2fund, U2alg export dot, expm, exp, dag, unitarize, inverse, tr, projalg, norm, norm2, isgroup, alg2mat, dev_one, antsym include("Space/Space.jl") diff --git a/test/dirac/test_fp_fa.jl b/test/dirac/test_fp_fa.jl index ee931ae..6610bb4 100644 --- a/test/dirac/test_fp_fa.jl +++ b/test/dirac/test_fp_fa.jl @@ -14,7 +14,7 @@ lp = SpaceParm{4}(size,(4,4,4,4),1,(0,0,0,0,0,0)); exptheta = exp.(im.*theta./lp.iL); dpar = DiracParam{Float64}(SU3fund,m,0.0,exptheta,1.0); -dws = DiracWorkspace(SU3fund{Float64},Float64,lp); +dws = DiracWorkspace(SU3fund,Float64,lp); U = fill!(vector_field(SU3{Float64},lp),one(SU3{Float64})); psi = scalar_field(Spinor{4,SU3fund{Float64}},lp); @@ -66,7 +66,7 @@ function fA_test(;theta = (0.5,0.7,1.0,0.0), m = 1.3, size = (8,8,8,16),prec = 1 exptheta = exp.(im.*theta./lp.iL); dpar = DiracParam{Float64}(SU3fund,m,0.0,exptheta,1.0); - dws = DiracWorkspace(SU3fund{Float64},Float64,lp); + dws = DiracWorkspace(SU3fund,Float64,lp); U = fill!(vector_field(SU3{Float64},lp),one(SU3{Float64})); psi = scalar_field(Spinor{4,SU3fund{Float64}},lp); diff --git a/test/dirac/test_solver_plw.jl b/test/dirac/test_solver_plw.jl index 14100d0..195a1a3 100644 --- a/test/dirac/test_solver_plw.jl +++ b/test/dirac/test_solver_plw.jl @@ -8,7 +8,7 @@ function Dwpw_test(;p=0,s=1,c=1) lp = SpaceParm{4}((16,16,16,16), (4,4,4,4), 0, (0,0,0,0,0,0)) gp = GaugeParm{Float64}(SU3{Float64}, 6.0, 1.0) dpar = DiracParam{Float64}(SU3fund,1.3,0.0,(1.0,1.0,1.0,1.0),0.0) -dws = DiracWorkspace(SU3fund{Float64},Float64,lp); +dws = DiracWorkspace(SU3fund,Float64,lp); p==0 ? p = Int.(round.(lp.iL.*rand(4),RoundUp)) : nothing U = fill!(vector_field(SU3{Float64},lp),one(SU3{Float64})) diff --git a/test/dirac/test_solver_rand.jl b/test/dirac/test_solver_rand.jl index 91a477d..c06de0a 100644 --- a/test/dirac/test_solver_rand.jl +++ b/test/dirac/test_solver_rand.jl @@ -10,7 +10,7 @@ using CUDA, LatticeGPU, TimerOutputs gp = GaugeParm{Float64}(SU3{Float64}, 6.0, 1.0) ymws = YMworkspace(SU3, Float64, lp) dpar = DiracParam{Float64}(SU3fund,2.3,0.0,(1.0,1.0,1.0,1.0),0.0) - dws = DiracWorkspace(SU3fund{Float64},Float64,lp); + dws = DiracWorkspace(SU3fund,Float64,lp); randomize!(ymws.mom, lp, ymws) U = exp.(ymws.mom)