-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
module KadanoffBaym | ||
|
||
import OrdinaryDiffEq | ||
using LinearAlgebra | ||
using QuadGK | ||
using AbstractFFTs | ||
|
||
export GreenFunction, Symmetrical, SkewHermitian | ||
export kbsolve! | ||
export wigner_transform | ||
import OrdinaryDiffEq | ||
|
||
include("utils.jl") | ||
|
||
include("gf.jl") | ||
export GreenFunction, Symmetrical, SkewHermitian | ||
|
||
include("vie.jl") | ||
include("vcabm.jl") | ||
include("kb.jl") | ||
export kbsolve! | ||
|
||
include("wigner.jl") | ||
export wigner_transform | ||
|
||
include("langreth.jl") | ||
export TimeOrderedGreenFunction, TimeOrderedConvolution, conv | ||
export greater, lesser, advanced, retarded | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
abstract type AbstractTimeOrderedGreenFunction end | ||
|
||
""" | ||
""" | ||
struct TimeOrderedGreenFunction <: AbstractTimeOrderedGreenFunction | ||
L # Lesser | ||
G # Greater | ||
|
||
TimeOrderedGreenFunction(L, G) = new(L, G) | ||
end | ||
|
||
Base.:*(a::Number, g::TimeOrderedGreenFunction) = TimeOrderedGreenFunction(a * lesser(g), a * greater(g)) | ||
Base.:+(g1::TimeOrderedGreenFunction, g2::TimeOrderedGreenFunction) = TimeOrderedGreenFunction(lesser(g1) + lesser(g2), greater(g1) + greater(g2)) | ||
|
||
""" | ||
""" | ||
struct TimeOrderedConvolution{TA<:AbstractTimeOrderedGreenFunction, TB<:AbstractTimeOrderedGreenFunction} <: AbstractTimeOrderedGreenFunction | ||
A::TA | ||
B::TB | ||
dts::UpperTriangular | ||
end | ||
|
||
""" | ||
""" | ||
function conv(A::AbstractTimeOrderedGreenFunction, B::AbstractTimeOrderedGreenFunction, dts) | ||
c = TimeOrderedConvolution(A, B, dts) | ||
return TimeOrderedGreenFunction(lesser(c), greater(c)) | ||
end | ||
|
||
# Langreth's rules | ||
greater(g::TimeOrderedGreenFunction) = g.G | ||
lesser(g::TimeOrderedGreenFunction) = g.L | ||
advanced(g::TimeOrderedGreenFunction) = UpperTriangular(lesser(g) - greater(g)) | ||
retarded(g::TimeOrderedGreenFunction) = adjoint(advanced(g)) | ||
|
||
greater(g::TimeOrderedConvolution) = (retarded(g.A) .* adjoint(g.dts)) * greater(g.B) + greater(g.A) * (g.dts .* advanced(g.B)) |> skew_hermitify! | ||
lesser(g::TimeOrderedConvolution) = (retarded(g.A) .* adjoint(g.dts)) * lesser(g.B) + lesser(g.A) * (g.dts .* advanced(g.B)) |> skew_hermitify! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function integrate(x::AbstractVector, y::AbstractVector) | ||
if isone(length(y)) | ||
return zero(first(y)) | ||
end | ||
@inbounds retval = (x[2] - x[1]) * (y[1] + y[2]) | ||
@inbounds @fastmath @simd for i in 2:(length(y)-1) | ||
retval += (x[i+1] - x[i]) * (y[i] + y[i+1]) | ||
end | ||
return 1 // 2 * retval | ||
end | ||
|
||
function compute(A, B, ts) | ||
l = zero(lesser(A)) | ||
for i in 1:size(l, 1) | ||
for j in 1:i | ||
l[i,j] += integrate(ts, greater(A)[i, 1:i] .* lesser(B)[1:i, j]) | ||
l[i,j] -= integrate(ts, lesser(A)[i, 1:j] .* greater(B)[1:j, j]) | ||
l[i,j] -= integrate(ts[j:i], lesser(A)[i, j:i] .* lesser(B)[j:i, j]) | ||
|
||
l[j,i] = -conj(l[i,j]) | ||
end | ||
l[i,i] = eltype(l) <: Real ? 0.0 : im * imag(l[i,i]) | ||
end | ||
|
||
g = zero(greater(A)) | ||
for i in 1:size(g, 1) | ||
for j in 1:i | ||
g[i,j] -= integrate(ts, lesser(A)[i, 1:i] .* greater(B)[1:i, j]) | ||
g[i,j] += integrate(ts, greater(A)[i, 1:j] .* lesser(B)[1:j, j]) | ||
g[i,j] += integrate(ts[j:i], greater(A)[i, j:i] .* greater(B)[j:i, j]) | ||
|
||
g[j,i] = -conj(g[i,j]) | ||
end | ||
g[i,i] = eltype(g) <: Real ? 0.0 : im * imag(g[i,i]) | ||
end | ||
|
||
TimeOrderedGreenFunction(l, g) | ||
end | ||
|
||
N = 100 | ||
|
||
# Suppose a non-equidistant time-grid | ||
ts = sort(N*rand(N)); | ||
|
||
# And 2 time-ordered GFs defined on that grid | ||
a = let | ||
x = rand(ComplexF64,N,N) | ||
y = rand(ComplexF64,N,N) | ||
TimeOrderedGreenFunction(x - x', y - y') # Skew-symmetric L and G components | ||
end | ||
b = let | ||
x = rand(ComplexF64,N,N) | ||
y = rand(ComplexF64,N,N) | ||
TimeOrderedGreenFunction(x - x', y - y') # Skew-symmetric L and G components | ||
end | ||
|
||
dts = reduce(hcat, ([KadanoffBaym.calculate_weights(ts[1:i], ones(Int64, i-1), 1e-8, 1e-3); zeros(length(ts)-i)] for i in eachindex(ts))) |> UpperTriangular | ||
|
||
⋆(a, b) = conv(a, b, dts) | ||
|
||
@testset "Langreth's rules" begin | ||
@test greater(a ⋆ b) ≈ greater(compute(a, b, ts)) | ||
@test lesser(a ⋆ b) ≈ lesser(compute(a, b, ts)) | ||
@test retarded(a ⋆ b) ≈ retarded(compute(a, b, ts)) | ||
@test greater(a ⋆ b ⋆ a) ≈ greater(compute(compute(a, b, ts), a, ts)) | ||
@test retarded(a ⋆ b ⋆ a) ≈ retarded(compute(compute(a, b, ts), a, ts)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a6ca086
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
a6ca086
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/74803
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
Also, note the warning: Version 1.2.0 skips over 1.1.0
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.
a6ca086
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
a6ca086
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request updated: JuliaRegistries/General/74803
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: