licenses
sequencelengths 1
3
| version
stringclasses 677
values | tree_hash
stringlengths 40
40
| path
stringclasses 1
value | type
stringclasses 2
values | size
stringlengths 2
8
| text
stringlengths 25
67.1M
| package_name
stringlengths 2
41
| repo
stringlengths 33
86
|
---|---|---|---|---|---|---|---|---|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 4458 | export read_eig, write_eig
"""
$(SIGNATURES)
Reshape a vector of eigenvalues into a matrix of eigenvalues.
Auto detect the number of bands and kpoints.
"""
@inline function _reshape_eig(
idx_b::AbstractVector, idx_k::AbstractVector, eig::AbstractVector
)
# find unique elements
n_bands = length(Set(idx_b))
n_kpts = length(Set(idx_k))
E = reshape(eig, (n_bands, n_kpts))
return map(ik -> E[:, ik], 1:n_kpts)
end
"""
$(SIGNATURES)
Check that eigenvalues are in order.
Some times there are small noises, use `digits` to set the number of digits for comparisons.
"""
@inline function _check_eig_order(eigenvalues::AbstractVector; digits=7)
round_digits(x) = round(x; digits)
for (ik, eig) in enumerate(eigenvalues)
if !issorted(eig; by=round_digits)
@warn "Eigenvalues are not sorted at " ik eig
end
end
end
"""
read_eig(filename)
read_eig(filename, ::FortranText)
read_eig(filename, ::FortranBinaryStream)
Read the wannier90 `eig` file.
# Return
- `eigenvalues`: a lenth-`n_kpts` vector, each element is a length-`n_bands` vector
The 1st version is a convenience wrapper function for the 2nd and 3rd versions.
"""
function read_eig end
function read_eig(filename::AbstractString, ::FortranText)
lines = open(filename) do io
readlines(io)
end
n_lines = length(lines)
idx_b = zeros(Int, n_lines)
idx_k = zeros(Int, n_lines)
eig = zeros(Float64, n_lines)
for i in 1:n_lines
arr = split(lines[i])
idx_b[i] = parse(Int, arr[1])
idx_k[i] = parse(Int, arr[2])
eig[i] = parse(Float64, arr[3])
end
eigenvalues = _reshape_eig(idx_b, idx_k, eig)
_check_eig_order(eigenvalues)
return eigenvalues
end
function read_eig(filename::AbstractString, ::FortranBinaryStream)
idx_b = Vector{Int}()
idx_k = Vector{Int}()
eig = Vector{Float64}()
# gfortran integer is 4 bytes
Tint = Int32
open(filename) do io
while !eof(io)
push!(idx_b, read(io, Tint))
push!(idx_k, read(io, Tint))
push!(eig, read(io, Float64))
end
end
eigenvalues = _reshape_eig(idx_b, idx_k, eig)
_check_eig_order(eigenvalues)
return eigenvalues
end
function read_eig(filename::AbstractString)
if isbinary(filename)
format = FortranBinaryStream()
else
format = FortranText()
end
eigenvalues = read_eig(filename, format)
n_kpts = length(eigenvalues)
@assert n_kpts > 0 "Empty eig file"
n_bands = length(eigenvalues[1])
@info "Reading eig file" filename n_kpts n_bands
return eigenvalues
end
"""
write_eig(filename, eigenvalues; binary=false)
write_eig(filename, eigenvalues, ::FortranText)
write_eig(filename, eigenvalues, ::FortranBinaryStream)
Write `eig` file.
# Arguments
- `eigenvalues`: a length-`n_kpts` vector, each element is a length-`n_bands` vector
# Keyword arguments
- `binary`: if true write in Fortran binary format.
"""
function write_eig end
function write_eig(filename::AbstractString, eigenvalues::AbstractVector, ::FortranText)
n_kpts = length(eigenvalues)
@assert n_kpts > 0 "Empty eigenvalues"
n_bands = length(eigenvalues[1])
open(filename, "w") do io
for ik in 1:n_kpts
for ib in 1:n_bands
@printf(io, "%5d%5d%18.12f\n", ib, ik, eigenvalues[ik][ib])
end
end
end
end
function write_eig(
filename::AbstractString, eigenvalues::AbstractVector, ::FortranBinaryStream
)
n_kpts = length(eigenvalues)
@assert n_kpts > 0 "Empty eigenvalues"
n_bands = length(eigenvalues[1])
# gfortran integer is 4 bytes
Tint = Int32
# I write in Fortran stream IO, so just plain julia `open`
open(filename, "w") do io
for ik in 1:n_kpts
for ib in 1:n_bands
write(io, Tint(ib))
write(io, Tint(ik))
write(io, Float64(eigenvalues[ik][ib]))
end
end
end
end
function write_eig(filename::AbstractString, eigenvalues::AbstractVector; binary=false)
if binary
format = FortranBinaryStream()
else
format = FortranText()
end
write_eig(filename, eigenvalues, format)
n_kpts = length(eigenvalues)
@assert n_kpts > 0 "Empty eigenvalues"
n_bands = length(eigenvalues[1])
@info "Writing eig file" filename n_kpts n_bands
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 3178 | # TODO update this file, use consistent variable names
"""
$(SIGNATURES)
Write the real space Hamiltonian to a `prefix_HH_R.dat` file.
# Arguments
- `filename`: usually `prefix_HH_R.dat`
- `H`: a `n_wann * n_wann * n_rvecs` array of Hamiltonian
- `R`: a `n_rvecs * 3` array of integers
# Keyword arguments
- `N`: a `n_rvecs` vector of integers, the degeneracy of each R vector
- `header`: a string, the header of the file
!!! note
`Wanier90` `postw90.x` has a hidden input parameter `effective_model`,
setting it to `true` and `postw90.x` will read this `HH_R.dat` to fill the
real space Hamiltonian, and do subsequent Wannier interpolation, e.g.,
in `BoltzWann`. However, the vanila `postw90.x` code does not take into
account the degeneracy of R vectors, and also does not use MDRS
interpolation. I have modified the `postw90.x` code to use MDRS, and also
changed a bit the number of digits for the Hamiltonian in `HH_R.dat`, so
that it is the same as the `prefix_tb.dat` file, i.e., from Fortran
`F12.6` to `E15.8`.
"""
function write_HH_R(
filename::AbstractString,
H::AbstractArray{T,3},
R::AbstractMatrix{IT};
N::Union{AbstractVector{IT},Nothing}=nothing,
header=default_header(),
) where {T<:Complex,IT<:Integer}
n_wann, _, n_rvecs = size(H)
size(H, 2) == n_wann || error("H must be a n_wann * n_wann * n_rvecs matrix")
size(R) == (3, n_rvecs) || error("R must be a 3 * n_rvecs matrix")
N === nothing || length(N) == n_rvecs || error("N must be a n_rvecs vector")
io = open(filename, "w")
write(io, header, "\n")
@printf(io, "%d\n", n_wann)
@printf(io, "%d\n", n_rvecs)
vec2str(v) = join([@sprintf "%5d" x for x in v], "")
for ir in 1:n_rvecs
for j in 1:n_wann
for i in 1:n_wann
h = H[i, j, ir]
# 12.6f is the wannier90 default, however, I change it to
# 15.8e so that it has the same accuracy as tb.dat file.
@printf(
io,
"%s %15.8e %15.8e\n",
vec2str([R[:, ir]..., i, j]),
real(h),
imag(h)
)
end
end
end
close(io)
@info "Written to file: $(filename)"
# the vanila wannier90 code does not read the N array (the degeneracy
# of R vector), and assume that N = 1 for all the R vectors.
# I write it, and also implement the reading of wsvec.dat as well,
# to use MDRS interpolation.
if N !== nothing
filename *= ".ndegen"
io = open(filename, "w")
# for aesthetic purpose, I write the N array in 15 columns
n_col = 15 # 15 numbers per row
for i in 0:(n_rvecs ÷ n_col - 1)
s = i * n_col + 1 # start
e = (i + 1) * n_col # end
@printf(io, "%s\n", vec2str(N[s:e]))
end
if (n_rvecs % n_col) > 0
s = n_rvecs - n_rvecs % n_col + 1 # start
e = n_rvecs # end
@printf(io, "%s\n", vec2str(N[s:e]))
end
@info "Written to file: $(filename)"
close(io)
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 2689 | export read_w90_hrdat, write_w90_hrdat
"""
$(SIGNATURES)
Read `prefix_hr.dat`.
# Return
- `Rvectors`: ``\\mathbf{R}``-vectors on which operators are defined
- `Rdegens`: degeneracies of each ``\\mathbf{R}``-vector
- `H`: Hamiltonian ``\\mathbf{H}(\\mathbf{R})``
- `header`: the first line of the file
"""
function read_w90_hrdat(filename::AbstractString)
return open(filename) do io
header = strip(readline(io))
n_wann = parse(Int, strip(readline(io)))
n_Rvecs = parse(Int, strip(readline(io)))
Rdegens = parse_vector(io, Int, n_Rvecs)
Rvectors = zeros(Vec3{Int}, n_Rvecs)
H = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
for iR in 1:n_Rvecs
for n in 1:n_wann
for m in 1:n_wann
line = split(strip(readline(io)))
Rvectors[iR] = parse.(Int, line[1:3])
@assert m == parse(Int, line[4]) line
@assert n == parse(Int, line[5]) line
H[iR][m, n] = complex(parse(Float64, line[6]), parse(Float64, line[7]))
end
end
end
@info "Reading hr.dat file" filename header n_wann n_Rvecs
return (; Rvectors, Rdegens, H, header)
end
end
"""
$(SIGNATURES)
Write `prefix_hr.dat`.
# Keyword arguments
See the return values of [`read_w90_hrdat`](@ref).
"""
function write_w90_hrdat(
filename::AbstractString;
Rvectors::AbstractVector,
Rdegens::AbstractVector,
H::AbstractVector,
header=default_header(),
)
n_Rvecs = length(H)
@assert n_Rvecs > 0 "empty H"
n_wann = size(H[1], 1)
@info "Writing hr.dat file" filename header n_wann n_Rvecs
return open(filename, "w") do io
println(io, strip(header))
@printf(io, "%d\n", n_wann)
@printf(io, "%d\n", n_Rvecs)
n_columns = 15
for (iR, degen) in enumerate(Rdegens)
@printf(io, "%5d", degen)
if mod(iR, n_columns) == 0
println(io)
end
end
if mod(n_Rvecs, n_columns) != 0
println(io)
end
for iR in 1:n_Rvecs
for n in 1:n_wann
for m in 1:n_wann
reH = real(H[iR][m, n])
imH = imag(H[iR][m, n])
@printf(
io,
" %4d %4d %4d %4d %4d %11.6f %11.6f\n",
Rvectors[iR]...,
m,
n,
reH,
imH
)
end
end
end
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 9023 | export read_mmn, write_mmn
"""
read_mmn(filename)
read_mmn(filename, ::FortranText)
read_mmn(filename, ::FortranBinaryStream)
Read wannier90 `mmn` file.
# Return
- `M`: length-`n_kpts` vector, each element is a length-`n_bvecs` vector, then
each element is a `n_bands * n_bands` matrix
- `kpb_k`: length-`n_kpts` vector, each element is a length-`n_bvecs` vector of
integers for the indices of the neighboring kpoints
- `kpb_G`: length-`n_kpts` vector, each element is a lenght-`n_bvecs` vector of
of `Vec3{Int}`, which are the translation vectors
- `header`: 1st line of the file
The translation vector `G` is defined as
`b = kpoints[kpb_k[ik][ib]] + kpb_G[ik][ib] - kpoints[ik]`,
where `b` is the `ib`-th bvector of the `ik`-th kpoint.
The 1st version is a convenience wrapper for the other two.
"""
function read_mmn end
function read_mmn(filename::AbstractString, ::FortranText)
mmn = open(filename) do io
header = strip(readline(io))
line = readline(io)
n_bands, n_kpts, n_bvecs = map(x -> parse(Int, x), split(line))
# overlap matrix
M = [[zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_bvecs] for _ in 1:n_kpts]
# for each point, list of neighbors
kpb_k = [zeros(Int, n_bvecs) for _ in 1:n_kpts]
# the translation vector G so that the true bvector
# b = kpoints[kpb_k] + kpb_G - kpoints[k]
kpb_G = [zeros(Vec3{Int}, n_bvecs) for _ in 1:n_kpts]
while !eof(io)
for ib in 1:n_bvecs
line = readline(io)
arr = split(line)
ik = parse(Int, arr[1])
kpb_k[ik][ib] = parse(Int, arr[2])
kpb_G[ik][ib] = Vec3(parse.(Int, arr[3:5]))
for n in 1:n_bands
for m in 1:n_bands
line = readline(io)
arr = split(line)
o = parse(Float64, arr[1]) + im * parse(Float64, arr[2])
M[ik][ib][m, n] = o
end
end
end
end
@assert all(Mk -> all(Mkb -> !any(isnan.(Mkb)), Mk), M)
return (; M, kpb_k, kpb_G, header)
end
return mmn
end
function read_mmn(filename::AbstractString, ::FortranBinaryStream)
# I use stream io to write mmn, so I should use plain julia `open`
mmn = open(filename) do io
header_len = 60
header = read(io, FString{header_len})
# from FString to String
header = strip(String(header))
# gfortran default integer size = 4
# https://gcc.gnu.org/onlinedocs/gfortran/KIND-Type-Parameters.html
Tint = Int32
n_bands = read(io, Tint)
n_kpts = read(io, Tint)
n_bvecs = read(io, Tint)
# overlap matrix
M = [[zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_bvecs] for _ in 1:n_kpts]
# for each point, list of neighbors, (K) representation
kpb_k = [zeros(Int, n_bvecs) for _ in 1:n_kpts]
kpb_G = [zeros(Vec3{Int}, n_bvecs) for _ in 1:n_kpts]
while !eof(io)
for ib in 1:n_bvecs
ik = read(io, Tint)
kpb_k[ik][ib] = read(io, Tint)
kpb_G[ik][ib] = Vec3{Int}(read(io, Tint), read(io, Tint), read(io, Tint))
for n in 1:n_bands
for m in 1:n_bands
r = read(io, Float64)
i = read(io, Float64)
M[ik][ib][m, n] = r + im * i
end
end
end
end
@assert all(Mk -> all(Mkb -> !any(isnan.(Mkb)), Mk), M)
return (; M, kpb_k, kpb_G, header)
end
return mmn
end
function read_mmn(filename::AbstractString)
if isbinary(filename)
format = FortranBinaryStream()
else
format = FortranText()
end
M, kpb_k, kpb_G, header = read_mmn(filename, format)
_check_dimensions_M_kpb(M, kpb_k, kpb_G)
n_kpts = length(M)
n_bvecs = length(M[1])
n_bands = size(M[1][1], 1)
@info "Reading mmn file" filename header n_kpts n_bvecs n_bands
# Not returning header since it is printed
# Note I am returning a Tuple instead of NamedTuple
return M, kpb_k, kpb_G
end
"""
write_mmn(filename; M, kpb_k, kpb_G; header=default_header(), binary=false)
write_mmn(filename; M, kpb_k, kpb_G, ::FortranText; header=default_header(), binary=false)
write_mmn(filename; M, kpb_k, kpb_G, ::FortranBinaryStream; header=default_header(), binary=false)
Write wannier90 `mmn` file.
# Arguments
- `filename`: output file name
- `M`: length-`n_kpts` vector of `n_bands * n_bands * n_bvecs` arrays
- `kpb_k`: length-`n_kpts` vector of length-`n_bvecs` vector of integers
- `kpb_G`: length-`n_kpts` vector of length-`n_bvecs` vector of `Vec3{Int}` for bvectors
# Keyword arguments
- `header`: header string
- `binary`: if true write in Fortran binary format
The 1st version is a convenience wrapper for the other two.
"""
function write_mmn end
"""
Check the dimensions between the quantities are consistent.
"""
@inline function _check_dimensions_kpb(kpb_k, kpb_G)
n_kpts = length(kpb_k)
@assert n_kpts > 0 "Empty kpb_k, n_kpts = 0"
n_bvecs = length(kpb_k[1])
@assert n_bvecs > 0 "Empty kpb_k, n_bvecs = 0"
@assert length(kpb_k) == n_kpts "kpb_k has wrong n_kpts"
@assert length(kpb_G) == n_kpts "kpb_G has wrong n_kpts"
@assert all(length.(kpb_k) .== n_bvecs) "kpb_k has different n_bvecs among kpts"
@assert all(length.(kpb_G) .== n_bvecs) "kpb_G has different n_bvecs among kpts"
@assert all(all(length.(Gk) .== 3) for Gk in kpb_G) "kpb_G[ib][ib] are not 3-vectors"
end
"""
$(SIGNATURES)
"""
@inline function _check_dimensions_M_kpb(M, kpb_k, kpb_G)
_check_dimensions_kpb(kpb_k, kpb_G)
@assert length(M) == length(kpb_k) "M and kpb_k have different n_kpts"
n_bvecs = length(kpb_k[1])
@assert all(length.(M) .== n_bvecs) "M and kpb_k have different n_bvecs"
n_bands = size(M[1][1], 1)
@assert n_bands > 0 "Empty M, n_bands = 0"
@assert all(all(size.(Mk) .== Ref((n_bands, n_bands))) for Mk in M) "M[ik][ib] are not square matrices"
end
function write_mmn(
filename::AbstractString,
M::AbstractVector,
kpb_k::AbstractVector,
kpb_G::AbstractVector,
::FortranText;
header=default_header(),
)
_check_dimensions_M_kpb(M, kpb_k, kpb_G)
n_kpts = length(M)
n_bvecs = length(M[1])
n_bands = size(M[1][1], 1)
open(filename, "w") do io
header = strip(header)
write(io, header, "\n")
@printf(io, " %d %d %d \n", n_bands, n_kpts, n_bvecs)
for ik in 1:n_kpts
for ib in 1:n_bvecs
@printf(io, "%d %d %d %d %d\n", ik, kpb_k[ik][ib], kpb_G[ik][ib]...)
for n in 1:n_bands
for m in 1:n_bands
o = M[ik][ib][m, n]
@printf(io, " %16.12f %16.12f\n", real(o), imag(o))
end
end
end
end
end
end
function write_mmn(
filename::AbstractString,
M::AbstractVector,
kpb_k::AbstractVector,
kpb_G::AbstractVector,
::FortranBinaryStream;
header=default_header(),
)
_check_dimensions_M_kpb(M, kpb_k, kpb_G)
n_kpts = length(M)
n_bvecs = length(M[1])
n_bands = size(M[1][1], 1)
# gfortran default integer size = 4
Tint = Int32
# I use stream io to write mmn, so I should use plain julia `open`
open(filename, "w") do io
header_len = 60
header = FString(header_len, String(strip(header)))
write(io, header)
write(io, Tint(n_bands))
write(io, Tint(n_kpts))
write(io, Tint(n_bvecs))
for ik in 1:n_kpts
kpb_k_ik = kpb_k[ik]
kpb_G_ik = kpb_G[ik]
for ib in 1:n_bvecs
write(io, Tint(ik))
write(io, Tint(kpb_k_ik[ib]))
write(io, Tint(kpb_G_ik[ib][1]))
write(io, Tint(kpb_G_ik[ib][2]))
write(io, Tint(kpb_G_ik[ib][3]))
for n in 1:n_bands
for m in 1:n_bands
o = M[ik][ib][m, n]
write(io, Float64(real(o)))
write(io, Float64(imag(o)))
end
end
end
end
end
end
function write_mmn(
filename::AbstractString,
M::AbstractVector,
kpb_k::AbstractVector,
kpb_G::AbstractVector;
header::AbstractString=default_header(),
binary::Bool=false,
)
_check_dimensions_M_kpb(M, kpb_k, kpb_G)
n_kpts = length(M)
n_bvecs = length(M[1])
n_bands = size(M[1][1], 1)
if binary
format = FortranBinaryStream()
else
format = FortranText()
end
write_mmn(filename, M, kpb_k, kpb_G, format; header)
@info "Writing mmn file" filename header n_kpts n_bvecs n_bands
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 9289 | export read_nnkp, write_nnkp
"""
read_nnkp(filename)
read_nnkp(filename, ::Wannier90Text)
read_nnkp(filename, ::Wannier90Toml)
Read wannier90 `nnkp` file.
# Return
- `lattice`: each column is a lattice vector
- `recip_lattice`: each column is a reciprocal lattice vector
- `kpoints`: length-`n_kpts` vector, each element is `Vec3`, in fractional coordinates
- `kpb_k`: length-`n_kpts` vector, each element is a length-`n_bvecs` vector of
integers, index of kpoints
- `kpb_G`: length-`n_kpts` vector, each element is a length-`n_bvecs` vector,
then each element is `Vec3` for translations, fractional w.r.t `recip_lattice`
Wannier90 `nnkp` file is a plain text format, the 2nd version reads `nnkp` file
in Wannier90 format. The thrid version read a TOML-format `nnkp` file, which is
defined by this package, see [`write_nnkp`](@ref).
The 1st version auto detects the format and parse it.
"""
function read_nnkp end
function read_nnkp(filename::AbstractString, ::Wannier90Text)
res = open(filename) do io
read_array(type::Type) = map(x -> parse(type, x), split(readline(io)))
lattice = zeros(Float64, 3, 3)
recip_lattice = zeros(Float64, 3, 3)
n_kpts = nothing
kpoints = nothing
kpb_k = nothing
kpb_G = nothing
while !eof(io)
line = readline(io)
if occursin("begin real_lattice", line)
for i in 1:3
lattice[:, i] = read_array(Float64)
end
line = strip(readline(io))
@assert line == "end real_lattice" "`end real_lattice` not found"
elseif occursin("begin recip_lattice", line)
for i in 1:3
recip_lattice[:, i] = read_array(Float64)
end
line = strip(readline(io))
@assert line == "end recip_lattice" "`end recip_lattice` not found"
elseif occursin("begin kpoints", line)
n_kpts = parse(Int, readline(io))
kpoints = zeros(Vec3{Float64}, n_kpts)
for i in 1:n_kpts
kpoints[i] = Vec3(read_array(Float64))
end
line = strip(readline(io))
@assert line == "end kpoints" "`end kpoints` not found"
elseif occursin("begin nnkpts", line)
@assert n_kpts !== nothing "no `kpoints` block before `nnkpts` block?"
n_bvecs = parse(Int, readline(io))
kpb_k = [zeros(Int, n_bvecs) for _ in 1:n_kpts]
kpb_G = [zeros(Vec3{Int}, n_bvecs) for _ in 1:n_kpts]
for ik in 1:n_kpts
for ib in 1:n_bvecs
arr = read_array(Int)
@assert ik == arr[1] "expected ik = $ik, got $(arr[1])"
kpb_k[ik][ib] = arr[2]
kpb_G[ik][ib] = Vec3(arr[3:end])
end
end
line = strip(readline(io))
@assert line == "end nnkpts" "`end nnkpts` not found"
end
end
@assert !iszero(lattice) "`real_lattice` not found"
@assert !iszero(recip_lattice) "`recip_lattice` not found"
@assert kpoints !== nothing "`kpoints` not found"
@assert kpb_k !== nothing "`nnkpts` not found"
@assert kpb_G !== nothing "`nnkpts` not found"
lattice = Mat3(lattice)
recip_lattice = Mat3(recip_lattice)
return (; lattice, recip_lattice, kpoints, kpb_k, kpb_G)
end
return res
end
function read_nnkp(filename::AbstractString, ::Wannier90Toml)
# I can just reuse the read_win function, without fix win inputs
nnkp = read_win(filename, Wannier90Toml(); fix_inputs=false)
# Need to set value to Any, otherwise it is Dict{Symbol,Vector},
# then I cannot assign Mat3 to it.
nnkp = Dict{Symbol,Any}(pairs(nnkp))
# Some following cleanups
# Convert to Mat3
if haskey(nnkp, :lattice) || haskey(nnkp, :recip_lattice)
for k in (:lattice, :recip_lattice)
if haskey(nnkp, k)
nnkp[k] = Mat3(nnkp[k])
end
end
end
# Convert to Vec3
if haskey(nnkp, :kpb_G)
nnkp[:kpb_G] = [[Vec3{Int}(G) for G in Gk] for Gk in nnkp[:kpb_G]]
end
# back to NamedTuple
return NamedTuple(nnkp)
end
function read_nnkp(filename::AbstractString)
format = Wannier90Text()
try
TOML.parsefile(filename)
catch err
err isa TOML.ParserError || rethrow()
else
format = Wannier90Toml()
end
nnkp = read_nnkp(filename, format)
n_kpts = length(nnkp.kpb_k)
@assert n_kpts > 0 "no kpoints found"
n_bvecs = length(nnkp.kpb_k[1])
@info "Reading nnkp file" filename n_kpts n_bvecs
return nnkp
end
"""
write_nnkp(filename; toml=false, kwargs...)
write_nnkp(filename, ::Wannier90Text; kwargs...)
write_nnkp(filename, ::Wannier90Toml; kwargs...)
Write a `nnkp` file that can be used by DFT codes, e.g., QE `pw2wannier90`.
# Keyword Arguments
- `toml`: write to a TOML file, otherwise write to a Wannier90 text file format
- `recip_lattice`: each column is a reciprocal lattice vector
- `kpoints`: length-`n_kpts` vector of `Vec3`, in fractional coordinates
- `kpb_k`: length-`n_kpts` vector, each element is a length-`n_bvecs` vector of
integers, index of kpoints
- `kpb_G`: length-`n_kpts` vector, each element is a length-`n_bvecs` vector,
then each element is a `Vec3` for translation vector, fractional w.r.t. `recip_lattice`
- `n_wann`: if given, write an `auto_projections` block
- `exclude_bands`: if given, write the specified band indices in the `exclude_bands` block
- `header`: first line of the file
!!! note
Only use `auto_projections`, the `projections` block is not supported.
"""
function write_nnkp end
function write_nnkp(
filename::AbstractString,
::Wannier90Text;
lattice::AbstractMatrix,
recip_lattice::AbstractMatrix,
kpoints::AbstractVector,
kpb_k::AbstractVector,
kpb_G::AbstractVector,
n_wann::Union{Nothing,Integer}=nothing,
exclude_bands::Union{Nothing,AbstractVector}=nothing,
header=default_header(),
)
@assert size(recip_lattice) == (3, 3) "size(recip_lattice) != (3, 3)"
_check_dimensions_kpb(kpb_k, kpb_G)
n_kpts = length(kpoints)
@assert n_kpts == length(kpb_k) "kpoints and kpb_k have different length"
n_bvecs = length(kpb_k[1])
@assert size(lattice) == (3, 3) "size(lattice) != (3, 3)"
@assert size(recip_lattice) == (3, 3) "size(recip_lattice) != (3, 3)"
open(filename, "w") do io
@printf(io, "%s\n", header)
@printf(io, "\n")
# mysterious line, seems not used in W90
@printf(io, "calc_only_A : F\n")
@printf(io, "\n")
@printf(io, "begin real_lattice\n")
for v in eachcol(lattice)
@printf(io, "%12.7f %12.7f %12.7f\n", v...)
end
@printf(io, "end real_lattice\n")
@printf(io, "\n")
@printf(io, "begin recip_lattice\n")
for v in eachcol(recip_lattice)
@printf(io, "%12.7f %12.7f %12.7f\n", v...)
end
@printf(io, "end recip_lattice\n")
@printf(io, "\n")
@printf(io, "begin kpoints\n")
@printf(io, "%d\n", n_kpts)
for kpt in kpoints
@printf(io, "%14.8f %14.8f %14.8f\n", kpt...)
end
@printf(io, "end kpoints\n")
@printf(io, "\n")
if !isnothing(n_wann)
@printf(io, "begin projections\n")
@printf(io, "%d\n", 0)
@printf(io, "end projections\n")
@printf(io, "\n")
@printf(io, "begin auto_projections\n")
@printf(io, "%d\n", n_wann)
@printf(io, "%d\n", 0)
@printf(io, "end auto_projections\n")
@printf(io, "\n")
end
@printf(io, "begin nnkpts\n")
@printf(io, "%d\n", n_bvecs)
for ik in 1:n_kpts
for ib in 1:n_bvecs
@printf(io, "%6d %6d %6d %6d %6d\n", ik, kpb_k[ik][ib], kpb_G[ik][ib]...)
end
end
@printf(io, "end nnkpts\n")
@printf(io, "\n")
@printf(io, "begin exclude_bands\n")
if exclude_bands === nothing
@printf(io, "%d\n", 0)
else
@printf(io, "%d\n", length(exclude_bands))
for b in exclude_bands
@printf(io, "%d\n", b)
end
end
@printf(io, "end exclude_bands\n")
@printf(io, "\n")
end
end
function write_nnkp(
filename::AbstractString, ::Wannier90Toml; header=default_header(), kwargs...
)
open(filename, "w") do io
println(io, header, "\n")
write_toml(io; kwargs...)
end
end
function write_nnkp(filename::AbstractString; toml=false, kwargs...)
@assert :kpb_k in keys(kwargs) "missing kpb_k"
kpb_k = kwargs[:kpb_k]
n_kpts = length(kpb_k)
@assert n_kpts > 0 "empty kpb_k"
n_bvecs = length(kpb_k[1])
@info "Writing nnkp file" filename n_kpts n_bvecs
if toml
format = Wannier90Toml()
else
format = Wannier90Text()
end
return write_nnkp(filename, format; kwargs...)
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1740 | export read_w90_rdat
"""
$(SIGNATURES)
Read `prefix_r.dat`.
# Return
- `Rvectors`: ``\\mathbf{R}``-vectors on which operators are defined
- `r_x`: ``x``-component of position operator
- `r_y`: ``y``-component of position operator
- `r_z`: ``z``-component of position operator
- `header`: the first line of the file
"""
function read_w90_rdat(filename::AbstractString)
return open(filename) do io
header = strip(readline(io))
n_wann = parse(Int, strip(readline(io)))
n_Rvecs = parse(Int, strip(readline(io)))
Rvectors = zeros(Vec3{Int}, n_Rvecs)
r_x = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
r_y = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
r_z = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
for iR in 1:n_Rvecs
for n in 1:n_wann
for m in 1:n_wann
line = split(strip(readline(io)))
Rvectors[iR] = parse.(Int, line[1:3])
@assert m == parse(Int, line[4]) line
@assert n == parse(Int, line[5]) line
r_x[iR][m, n] = complex(
parse(Float64, line[6]), parse(Float64, line[7])
)
r_y[iR][m, n] = complex(
parse(Float64, line[8]), parse(Float64, line[9])
)
r_z[iR][m, n] = complex(
parse(Float64, line[10]), parse(Float64, line[11])
)
end
end
end
@info "Reading r.dat file" filename header n_wann n_Rvecs
return (; Rvectors, r_x, r_y, r_z, header)
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 6330 |
export read_spn, write_spn
"""
read_spn(filename)
read_spn(filename, ::FortranText)
read_spn(filename, ::FortranBinary)
Read the wannier90 `spn` file.
# Return
- `Sx`: spin x, a length-`n_kpts` vector, each element is a `n_bands`-by-`n_bands` matrix
- `Sy`: spin y, a length-`n_kpts` vector, each element is a `n_bands`-by-`n_bands` matrix
- `Sz`: spin z, a length-`n_kpts` vector, each element is a `n_bands`-by-`n_bands` matrix
- `header`: 1st line of the file
"""
function read_spn end
function read_spn(filename::AbstractString, ::FortranText)
spn = open("$filename") do io
header = readline(io)
arr = split(readline(io))
n_bands, n_kpts = parse.(Int64, arr[1:2])
Sx = [zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_kpts]
Sy = [zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_kpts]
Sz = [zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_kpts]
for ik in 1:n_kpts
for m in 1:n_bands
for n in 1:m
for Si in (Sx, Sy, Sz)
line = split(readline(io))
x, y = parse.(Float64, line)
Si[ik][n, m] = x + im * y
# although each diagonal element of `S` should be real,
# actually it has a very small imaginary part,
# so we skip the conjugation on the diagonal elements.
m == n && continue
Si[ik][m, n] = x - im * y
end
end
end
end
@assert eof(io)
return (; Sx, Sy, Sz, header)
end
return spn
end
function read_spn(filename::AbstractString, ::FortranBinary)
io = FortranFile(filename)
# strip and read line
header_len = 60
header = trimstring(read(io, FString{header_len}))
# gfortran default integer is 4 bytes
Tint = Int32
n_bands, n_kpts = read(io, (Tint, 2))
Sx = [zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_kpts]
Sy = [zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_kpts]
Sz = [zeros(ComplexF64, n_bands, n_bands) for _ in 1:n_kpts]
# upper triangle part, at each kpoint
spn_tmp = zeros(ComplexF64, 3, n_bands * (n_bands + 1) ÷ 2)
for ik in 1:n_kpts
read(io, spn_tmp)
counter = 0
for m in 1:n_bands
for n in 1:m
counter += 1
for (i, Si) in enumerate((Sx, Sy, Sz))
Si[ik][n, m] = spn_tmp[i, counter]
# although each diagonal element of `S` should be real,
# actually it has a very small imaginary part,
# so we skip the conjugation on the diagonal elements.
m == n && continue
Si[ik][m, n] = conj(Si[ik][n, m])
end
end
end
end
@assert eof(io)
close(io)
return (; Sx, Sy, Sz, header)
end
function read_spn(filename::AbstractString)
if isbinary(filename)
format = FortranBinary()
else
format = FortranText()
end
Sx, Sy, Sz, header = read_spn(filename, format)
n_kpts = length(Sx)
@assert n_kpts > 0 "empty spn matrix"
n_bands = size(Sx[1], 1)
@info "Reading spn file" filename header n_kpts n_bands
return Sx, Sy, Sz
end
"""
write_spn(filename, Sx, Sy, Sz; binary=false, header)
write_spn(filename, Sx, Sy, Sz, ::FortranText; header)
write_spn(filename, Sx, Sy, Sz, ::FortranBinary; header)
Write the `spn` file.
"""
function write_spn end
"""
$(SIGNATURES)
"""
@inline function _check_dimensions_Sx_Sy_Sz(Sx, Sy, Sz)
n_kpts = length(Sx)
@assert n_kpts > 0 "empty spn matrix"
@assert n_kpts == length(Sy) == length(Sz) "Sx, Sy, Sz must have the same length"
n_bands = size(Sx[1], 1)
@assert all(size.(Sx) .== Ref((n_bands, n_bands))) "Sx[ik] must be a square matrix"
@assert all(size.(Sy) .== Ref((n_bands, n_bands))) "Sy[ik] must be a square matrix"
@assert all(size.(Sz) .== Ref((n_bands, n_bands))) "Sz[ik] must be a square matrix"
end
function write_spn(
filename::AbstractString,
Sx::AbstractVector,
Sy::AbstractVector,
Sz::AbstractVector,
::FortranText;
header=default_header(),
)
_check_dimensions_Sx_Sy_Sz(Sx, Sy, Sz)
n_kpts = length(Sx)
n_bands = size(Sx[1], 1)
open(filename, "w") do io
header = strip(header)
write(io, header, "\n")
@printf(io, "%3d %4d\n", n_bands, n_kpts)
for ik in 1:n_kpts
for m in 1:n_bands
for n in 1:m
for Si in (Sx, Sy, Sz)
s = Si[ik][n, m]
@printf(io, "%26.16e %26.16e\n", real(s), imag(s))
end
end
end
end
end
end
function write_spn(
filename::AbstractString,
Sx::AbstractVector,
Sy::AbstractVector,
Sz::AbstractVector,
::FortranBinary;
header=default_header(),
)
_check_dimensions_Sx_Sy_Sz(Sx, Sy, Sz)
n_kpts = length(Sx)
n_bands = size(Sx[1], 1)
io = FortranFile(filename, "w")
header_len = 60
write(io, FString(header_len, string(strip(header))))
# gfortran default integer is 4 bytes
Tint = Int32
write(io, Tint(n_bands), Tint(n_kpts))
# upper triangle part, at each kpoint
spn_tmp = zeros(ComplexF64, 3, n_bands * (n_bands + 1) ÷ 2)
for ik in 1:n_kpts
counter = 0
for m in 1:n_bands
for n in 1:m
counter += 1
for (i, Si) in enumerate((Sx, Sy, Sz))
spn_tmp[i, counter] = Si[ik][n, m]
end
end
end
write(io, spn_tmp)
end
close(io)
return nothing
end
function write_spn(
filename::AbstractString,
Sx::AbstractVector,
Sy::AbstractVector,
Sz::AbstractVector;
binary=false,
header=default_header(),
)
if binary
format = FortranBinary()
else
format = FortranText()
end
_check_dimensions_Sx_Sy_Sz(Sx, Sy, Sz)
n_kpts = length(Sx)
n_bands = size(Sx[1], 1)
@info "Writing spn file" filename header n_kpts n_bands
return write_spn(filename, Sx, Sy, Sz, format; header)
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 5174 | export read_w90_tbdat, write_w90_tbdat
"""
$(SIGNATURES)
Read `prefix_tb.dat`.
# Return
- `lattice`: each column is a lattice vector in Å
- `Rvectors`: ``\\mathbf{R}``-vectors on which operators are defined
- `Rdegens`: degeneracies of each ``\\mathbf{R}``-vector
- `H`: Hamiltonian ``\\mathbf{H}(\\mathbf{R})``
- `r_x`: ``x``-component of position operator
- `r_x`: ``y``-component of position operator
- `r_x`: ``z``-component of position operator
- `header`: the first line of the file
"""
function read_w90_tbdat(filename::AbstractString)
# convenice function
ssrline(io) = split(strip(readline(io)))
return open(filename) do io
header = strip(readline(io))
# Å unit
a1 = parse.(Float64, ssrline(io))
a2 = parse.(Float64, ssrline(io))
a3 = parse.(Float64, ssrline(io))
# column-major
lattice = Mat3{Float64}(hcat(a1, a2, a3))
n_wann = parse(Int, strip(readline(io)))
n_Rvecs = parse(Int, strip(readline(io)))
Rdegens = parse_vector(io, Int, n_Rvecs)
Rvectors = zeros(Vec3{Int}, n_Rvecs)
H = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
# Hamiltonian
for iR in 1:n_Rvecs
line = strip(readline(io)) # empty line
@assert line == ""
Rvectors[iR] = Vec3(parse.(Int, ssrline(io))...)
for n in 1:n_wann
for m in 1:n_wann
line = ssrline(io)
@assert m == parse(Int, line[1]) line
@assert n == parse(Int, line[2]) line
reH, imH = parse.(Float64, line[3:4])
H[iR][m, n] = reH + im * imH
end
end
end
# WF position operator
r_x = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
r_y = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
r_z = [Matrix{ComplexF64}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
for iR in 1:n_Rvecs
line = strip(readline(io)) # empty line
@assert line == ""
@assert Rvectors[iR] == Vec3(parse.(Int, ssrline(io))...)
for n in 1:n_wann
for m in 1:n_wann
line = ssrline(io)
@assert m == parse(Int, line[1])
@assert n == parse(Int, line[2])
f = parse.(Float64, line[3:8])
r_x[iR][m, n] = f[1] + im * f[2]
r_y[iR][m, n] = f[3] + im * f[4]
r_z[iR][m, n] = f[5] + im * f[6]
end
end
end
@info "Reading tb.dat file" filename header n_wann n_Rvecs
return (; lattice, Rvectors, Rdegens, H, r_x, r_y, r_z, header)
end
end
"""
$(SIGNATURES)
Write `prefix_tb.dat`.
# Keyword arguments
See the return values of [`read_w90_tbdat`](@ref).
"""
function write_w90_tbdat(
filename::AbstractString;
lattice::AbstractMatrix,
Rvectors::AbstractVector,
Rdegens::AbstractVector,
H::AbstractVector,
r_x::AbstractVector,
r_y::AbstractVector,
r_z::AbstractVector,
header=default_header(),
)
n_Rvecs = length(H)
@assert n_Rvecs > 0 "empty H"
n_wann = size(H[1], 1)
@info "Writing tb.dat file" filename header n_wann n_Rvecs
open(filename, "w") do io
println(io, strip(header))
# Å unit
@printf(io, "%21.16f %21.16f %21.16f\n", lattice[:, 1]...)
@printf(io, "%21.16f %21.16f %21.16f\n", lattice[:, 2]...)
@printf(io, "%21.16f %21.16f %21.16f\n", lattice[:, 3]...)
@printf(io, "%d\n", n_wann)
@printf(io, "%d\n", n_Rvecs)
n_columns = 15
for (iR, degen) in enumerate(Rdegens)
@printf(io, "%5d", degen)
if mod(iR, n_columns) == 0
println(io)
end
end
if mod(n_Rvecs, n_columns) != 0
println(io)
end
# Hamiltonian
for iR in 1:n_Rvecs
@printf(io, "\n%5d %5d %5d\n", Rvectors[iR]...)
for n in 1:n_wann
for m in 1:n_wann
reH = real(H[iR][m, n])
imH = imag(H[iR][m, n])
@printf(io, "%5d %5d %15.8e %15.8e\n", m, n, reH, imH)
end
end
end
# WF position operator
for iR in 1:n_Rvecs
@printf(io, "\n%5d %5d %5d\n", Rvectors[iR]...)
for n in 1:n_wann
for m in 1:n_wann
x = r_x[iR][m, n]
y = r_y[iR][m, n]
z = r_z[iR][m, n]
@printf(
io,
"%5d %5d %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e\n",
m,
n,
real(x),
imag(x),
real(y),
imag(y),
real(z),
imag(z)
)
end
end
end
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 6441 | export read_uHu, write_uHu
"""
read_uHu(filename)
read_uHu(filename, ::FortranText; transpose_band_indices=true)
read_uHu(filename, ::FortranBinary; transpose_band_indices=true)
Read the wannier90 `uHu` file.
# Keyword Arguments
- `transpose_band_indices`: QE pw2wannier90.x writes the matrix in a strange
transposed manner; if reading a QE-generated `uHu` file, this flag should
be true to restore the band indices order, so that the returned matrix
has the correct order, i.e.,
`uHu[ik][ib1, ib2][m, n]` is
``\\langle u_{m, k + b_1}| H | u_{n, k + b_2} \\rangle``
# Return
- `uHu`: a length-`n_kpts` vector, each element is a `n_bvecs * n_bvecs` matrix,
then each element is a `n_bands * n_bands` matrix
- `header`: 1st line of the file
"""
function read_uHu end
function read_uHu(filename::AbstractString, ::FortranText; transpose_band_indices=true)
return open("$filename") do io
header = readline(io)
arr = split(readline(io))
n_bands, n_kpts, n_bvecs = parse.(Int64, arr[1:3])
uHu = map(1:n_kpts) do _
map(CartesianIndices((n_bvecs, n_bvecs))) do _
zeros(ComplexF64, n_bands, n_bands)
end
end
for ik in 1:n_kpts
for ib2 in 1:n_bvecs
for ib1 in 1:n_bvecs
for n in 1:n_bands
for m in 1:n_bands
line = split(readline(io))
x, y = parse.(Float64, line)
uHu[ik][ib1, ib2][m, n] = x + im * y
end
end
if transpose_band_indices
uHu[ik][ib1, ib2] .= transpose(uHu[ik][ib1, ib2])
end
end
end
end
@assert eof(io)
return (; uHu, header)
end
end
function read_uHu(filename::AbstractString, ::FortranBinary; transpose_band_indices=true)
io = FortranFile(filename)
# strip and read line
header_len = 60
header = trimstring(read(io, FString{header_len}))
# gfortran default integer is 4 bytes
Tint = Int32
n_bands, n_kpts, n_bvecs = read(io, (Tint, 3))
uHu = map(1:n_kpts) do _
map(CartesianIndices((n_bvecs, n_bvecs))) do _
zeros(ComplexF64, n_bands, n_bands)
end
end
# upper triangle part, at each kpoint, b1, and b2
uHu_tmp = zeros(ComplexF64, n_bands^2)
for ik in 1:n_kpts
for ib2 in 1:n_bvecs
for ib1 in 1:n_bvecs
read(io, uHu_tmp)
uHu[ik][ib1, ib2] .= reshape(uHu_tmp, (n_bands, n_bands))
if transpose_band_indices
uHu[ik][ib1, ib2] .= transpose(uHu[ik][ib1, ib2])
end
end
end
end
@assert eof(io)
close(io)
return (; uHu, header)
end
function read_uHu(filename::AbstractString; kwargs...)
if isbinary(filename)
format = FortranBinary()
else
format = FortranText()
end
uHu, header = read_uHu(filename, format; kwargs...)
n_kpts = length(uHu)
@assert n_kpts > 0 "empty uHu matrix"
n_bvecs = size(uHu[1], 1)
@assert n_bvecs > 0 "empty uHu matrix"
n_bands = size(uHu[1][1, 1], 1)
@info "Reading uHu file" filename header n_kpts n_bvecs n_bands
return uHu
end
"""
write_uHu(filename, uHu; binary=false, header)
write_uHu(filename, uHu, ::FortranText; header)
write_uHu(filename, uHu, ::FortranBinary; header)
Write the `uHu` file.
# Keyword Arguments
- `transpose_band_indices`: see [`read_uHu`](@ref)
"""
function write_uHu end
function write_uHu(
filename::AbstractString,
uHu::AbstractVector,
::FortranText;
header=default_header(),
transpose_band_indices=true,
)
n_kpts = length(uHu)
@assert n_kpts > 0 "empty uHu matrix"
n_bvecs = size(uHu[1], 1)
@assert n_bvecs > 0 "empty uHu matrix"
n_bands = size(uHu[1][1, 1], 1)
open(filename, "w") do io
header = strip(header)
write(io, header, "\n")
@printf(io, "%3d %4d %4d\n", n_bands, n_kpts, n_bvecs)
for ik in 1:n_kpts
for ib2 in 1:n_bvecs
for ib1 in 1:n_bvecs
if transpose_band_indices
out_uHu = transpose(uHu[ik][ib1, ib2])
else
out_uHu = uHu[ik][ib1, ib2]
end
for n in 1:n_bands
for m in 1:n_bands
u = out_uHu[m, n]
@printf(io, "%20.10e %20.10e\n", real(u), imag(u))
end
end
end
end
end
end
end
function write_uHu(
filename::AbstractString,
uHu::AbstractVector,
::FortranBinary;
header=default_header(),
transpose_band_indices=true,
)
n_kpts = length(uHu)
@assert n_kpts > 0 "empty uHu matrix"
n_bvecs = size(uHu[1], 1)
@assert n_bvecs > 0 "empty uHu matrix"
n_bands = size(uHu[1][1, 1], 1)
io = FortranFile(filename, "w")
header_len = 60
write(io, FString(header_len, string(strip(header))))
# gfortran default integer is 4 bytes
Tint = Int32
write(io, Tint(n_bands), Tint(n_kpts), Tint(n_bvecs))
# upper triangle part, at each kpoint
uHu_tmp = zeros(ComplexF64, n_bands^2)
for ik in 1:n_kpts
for ib2 in 1:n_bvecs
for ib1 in 1:n_bvecs
if transpose_band_indices
out_uHu = transpose(uHu[ik][ib1, ib2])
else
out_uHu = uHu[ik][ib1, ib2]
end
uHu_tmp .= reshape(out_uHu, (n_bands^2,))
write(io, uHu_tmp)
end
end
end
close(io)
return nothing
end
function write_uHu(
filename::AbstractString,
uHu::AbstractVector;
binary=false,
header=default_header(),
kwargs...,
)
if binary
format = FortranBinary()
else
format = FortranText()
end
n_kpts = length(uHu)
@assert n_kpts > 0 "empty uHu matrix"
n_bvecs = size(uHu[1], 1)
@assert n_bvecs > 0 "empty uHu matrix"
n_bands = size(uHu[1][1, 1], 1)
@info "Writing uHu file" filename header n_kpts n_bands n_bvecs
return write_uHu(filename, uHu, format; header, kwargs...)
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 3127 | """
read_u_mat(filename)
Read wannier90 `prefix_u.mat` or `prefix_u_dis.mat` file.
# Arguments
- `filename`: the input file name
# Return
- `U`: `Udis` (for disentanglement) or `U` (for maximal localization) matrices
- `kpoints`: fractional kpoint coordinates
- `header`: 1st line of the file
!!! warning
The `wannier90` output `prefix_u_dis.mat` internally sorts the band indices
according to the disnentanglement window, therefore it can be different from
the original Bloch states, see the code and comments in [`get_Udis`](@ref).
"""
function read_u_mat(filename::AbstractString)
return open(filename) do io
# strip and read line
srline() = strip(readline(io))
header = String(srline())
# for u_dis.mat, nwann <= nbands
# for u.mat, nbands == nwann
nkpts, nwann, nbands = parse.(Int, split(srline()))
@info "Reading u_mat file" filename header nkpts nbands nwann
kpoints = zeros(Vec3{Float64}, nkpts)
U = [zeros(ComplexF64, nbands, nwann) for _ in 1:nkpts]
for ik in 1:nkpts
# empty line
srline()
kpoints[ik] = Vec3(parse.(Float64, split(srline()))...)
for iw in 1:nwann
for ib in 1:nbands
vals = parse.(Float64, split(srline()))
U[ik][ib, iw] = vals[1] + im * vals[2]
end
end
end
return (; U, kpoints, header)
end
end
"""
write_u_mat(filename, U, kpoints; header=default_header())
Write wannier90 `prefix_u.mat` or `prefix_u_dis.mat` file.
# Arguments
- `filename`: the input file name
- `U`: `Udis` (for disentanglement) or `U` (for maximal localization) matrices
- `kpoints`: fractional kpoint coordinates
# Keyword arguments
- `header`: 1st line of the file, optional
!!! warning
The `wannier90` output `prefix_u_dis.mat` internally sorts the band indices
according to the disnentanglement window, therefore it can be different from
the original Bloch states, see the code and comments in [`get_Udis`](@ref).
This function just writes whatever is inside the input `U` matrix, without
consider the order of disentanglement window.
"""
function write_u_mat(
filename::AbstractString,
U::AbstractVector,
kpoints::AbstractVector;
header::AbstractString=default_header(),
)
nkpts = length(U)
@assert nkpts > 0 "U is empty"
@assert nkpts == length(kpoints) "inconsistent number of kpoints"
nbands, nwann = size(U[1])
@info "Writing u_mat file" filename header nkpts nbands nwann
return open(filename, "w") do io
write(io, header, "\n")
@printf(io, "%d %d %d\n", nkpts, nwann, nbands)
for ik in 1:nkpts
# empty line
write(io, "\n")
@printf(io, " %15.10f %15.10f %15.10f\n", kpoints[ik]...)
for iw in 1:nwann
for ib in 1:nbands
u = U[ik][ib, iw]
@printf(io, " %15.10f %15.10f\n", real(u), imag(u))
end
end
end
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 4180 | export read_unk, write_unk
"""
read_unk(filename)
read_unk(filename, ::FortranText)
read_unk(filename, ::FortranBinary)
Read wannier90 `UNK` file for the periodic part of Bloch wavefunctions.
# Return
- `ik`: k-point index, start from 1
- `Ψ`: periodic part of Bloch wavefunctions in real space,
size = `(n_gx, n_gy, n_gz, n_bands, n_spin)`
"""
function read_unk end
function read_unk(filename::AbstractString, ::FortranText)
n_spin = occursin("NC", filename) ? 2 : 1
res = open(filename) do io
line = split(strip(readline(io)))
n_gx, n_gy, n_gz, ik, n_bands = parse.(Int, line)
Ψ = zeros(ComplexF64, n_gx, n_gy, n_gz, n_bands, n_spin)
for ib in 1:n_bands
for is in 1:n_spin
for iz in 1:n_gz
for iy in 1:n_gy
for ix in 1:n_gx
line = split(strip(readline(io)))
v1, v2 = parse.(Float64, line)
Ψ[ix, iy, iz, ib, is] = v1 + im * v2
end
end
end
end
end
return ik, Ψ
end
return res
end
function read_unk(filename::AbstractString, ::FortranBinary)
n_spin = occursin("NC", filename) ? 2 : 1
# unk files are not in Fortran stream io, so I need to open with FortranFile
io = FortranFile(filename)
# gfortran default integer is 4 bytes
Tint = Int32
n_gx, n_gy, n_gz, ik, n_bands = read(io, (Tint, 5))
Ψ = zeros(ComplexF64, n_gx, n_gy, n_gz, n_bands, n_spin)
for ib in 1:n_bands
for is in 1:n_spin
record = Record(io)
read!(record, view(Ψ, :, :, :, ib, is))
close(record)
end
end
close(io)
return ik, Ψ
end
function read_unk(filename::AbstractString)
if isbinary(filename)
format = FortranBinary()
else
format = FortranText()
end
ik, Ψ = read_unk(filename, format)
n_gx, n_gy, n_gz, n_bands, n_spin = size(Ψ)
@info "Reading unk file" filename ik (n_gx, n_gy, n_gz) n_bands n_spin
return ik, Ψ
end
"""
write_unk(filename, ik, Ψ; binary=false)
write_unk(filename, ik, Ψ, ::FortranText)
write_unk(filename, ik, Ψ, ::FortranBinary)
Write `UNK` file for the periodic part of Bloch wavefunctions.
# Arguments
- ik: at which kpoint? start from 1
- Ψ: Bloch wavefunctions, `size(Ψ) = (n_gx, n_gy, n_gz, n_bands, n_spin)`
# Keyword arguments
- `binary`: write as Fortran unformatted file
"""
function write_unk end
function write_unk(
filename::AbstractString, ik::Integer, Ψ::Array{<:Complex,5}, ::FortranText
)
n_gx, n_gy, n_gz, n_bands, n_spin = size(Ψ)
open(filename, "w") do io
@printf(io, " %11d %11d %11d %11d %11d\n", n_gx, n_gy, n_gz, ik, n_bands)
for ib in 1:n_bands
for is in 1:n_spin
for iz in 1:n_gz
for iy in 1:n_gy
for ix in 1:n_gx
v1 = real(Ψ[ix, iy, iz, ib, is])
v2 = imag(Ψ[ix, iy, iz, ib, is])
@printf(io, " %18.10e %18.10e\n", v1, v2)
end
end
end
end
end
end
end
function write_unk(
filename::AbstractString, ik::Integer, Ψ::Array{<:Complex,5}, ::FortranBinary
)
n_gx, n_gy, n_gz, n_bands, n_spin = size(Ψ)
# gfortran default integer is 4 bytes
Tint = Int32
# not Fortran stream IO, so using `FortranFile`
io = FortranFile(filename, "w")
write(io, Tint(n_gx), Tint(n_gy), Tint(n_gz), Tint(ik), Tint(n_bands))
for ib in 1:n_bands
for is in 1:n_spin
write(io, ComplexF64.(Ψ[:, :, :, ib, is]))
end
end
return close(io)
end
function write_unk(filename::AbstractString, ik, Ψ; binary=false)
n_gx, n_gy, n_gz, n_bands, n_spin = size(Ψ)
@info "Writing unk file" filename ik (n_gx, n_gy, n_gz) n_bands n_spin
if binary
format = FortranBinary()
else
format = FortranText()
end
return write_unk(filename, ik, Ψ, format)
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 19694 | using TOML
export read_win, write_win
"""
read_win(filename; fix_inputs=true)
read_win(filename, ::Wannier90Text; fix_inputs=true)
read_win(filename, ::Wannier90Toml; fix_inputs=true)
Read wannier90 input `win` file.
# Arguments
- `filename`: The name of the input file.
# Keyword Arguments
- `fix_inputs`: sanity check and fix the input parameters, e.g., set
`num_bands = num_wann` if `num_bands` is not specified,
convert `atoms_cart` always to `atoms_frac`, etc.
See also [`fix_win!`](@ref).
"""
function read_win end
function read_win(filename::AbstractString, ::Wannier90Text; fix_inputs::Bool=true)
params = open(filename) do io
# The win file uses "num_wann", so I keep it as is, and not using "n_wann".
keys_int = [
:num_wann,
:num_bands,
:num_iter,
:dis_num_iter,
:dis_conv_window,
:conv_window,
:num_cg_steps,
:wannier_plot_supercell,
:num_print_cycles,
:iprint,
:search_shells,
:bands_num_points,
:ws_search_size,
:num_guide_cycles,
:num_no_guide_iter,
]
keys_int3 = [:mp_grid]
keys_float = [
:kmesh_tol,
:conv_tol,
:dis_froz_min,
:dis_froz_max,
:dis_win_min,
:dis_win_max,
:dis_mix_ratio,
:dis_conv_tol,
:fermi_energy,
:fermi_energy_min,
:fermi_energy_max,
:fermi_energy_step,
:ws_distance_tol,
]
keys_bool = [
:use_ws_distance,
:wannier_plot,
:bands_plot,
:wvfn_formatted,
:spn_formatted,
:write_hr,
:write_tb,
:write_xyz,
:write_rmn,
:guiding_centres,
:gamma_only,
:spinors,
:postproc_setup,
:auto_projections,
:restart,
]
keys_indices = [:exclude_bands, :select_projections]
params = Dict{Symbol,Any}()
read_line() = strip(readline(io))
function remove_comments(line::AbstractString)
i = findfirst(r"!|#", line)
if i !== nothing
line = strip(line[1:(i.start - 1)])
end
return line
end
# handle case insensitive win files (relic of Fortran)
function read_line_until_nonempty(; lower=true, block_name=nothing)
while !eof(io)
line = read_line()
lower && (line = lowercase(line))
line = remove_comments(line)
if !isempty(line)
return line
end
end
# end of line reached
if block_name !== nothing
# in the middle of a block, raise error
error("end of file reached while parsing block `$block_name`")
end
# else, outside of blocks, should be fine reaching end of file
return nothing
end
function parse_array(line::AbstractString; T=Float64)
return map(x -> parse(T, x), split(line))
end
read_array(f::IOStream) = parse_array(readline(f))
while !eof(io)
line = read_line_until_nonempty()
line === nothing && break
# first handle special cases, e.g., blocks
if occursin(r"^begin\s+unit_cell_cart", line)
block_name = "unit_cell_cart"
unit_cell = zeros(Float64, 3, 3)
unit = read_line_until_nonempty(; block_name)
if !startswith(unit, "b") && !startswith(unit, "a")
line = unit
unit = "ang"
else
line = read_line_until_nonempty(; block_name)
end
for i in 1:3
# in win file, each line is a lattice vector, here it is stored as column vec
unit_cell[:, i] = parse_array(line)
line = read_line_until_nonempty(; block_name)
end
@assert occursin(r"^end\s+unit_cell_cart", line) "error parsing $block_name: `end $block_name` not found"
if startswith(unit, "b")
# convert to angstrom
unit_cell .*= Bohr
end
unit_cell = Mat3{Float64}(unit_cell)
push!(params, :unit_cell_cart => unit_cell)
elseif occursin(r"^begin\s+atoms_(frac|cart)", line)
iscart = occursin("cart", line)
block_name = "atoms_$(iscart ? "cart" : "frac")"
# do not lowercase due to atomic label
line = read_line_until_nonempty(; lower=false, block_name)
if iscart
unit = lowercase(line)
if !startswith(unit, "b") && !startswith(unit, "a")
unit = "ang"
else
# do not lowercase due to atomic label
line = read_line_until_nonempty(; lower=false, block_name)
end
end
# I need to read all lines and get n_atoms
lines = Vector{String}()
while !occursin(Regex("^end\\s+" * block_name), lowercase(line))
push!(lines, line)
line = read_line_until_nonempty(; lower=false, block_name)
end
n_atoms = length(lines)
atoms_frac = SymbolVec3{Float64}[]
for i in 1:n_atoms
l = split(lines[i])
symbol = Symbol(l[1])
frac = Vec3(parse_float.(l[2:end])...)
push!(atoms_frac, SymbolVec3(symbol, frac))
end
if iscart
if startswith(unit, "b")
# convert to angstrom
atoms_frac = map(atoms_frac) do (symbol, pos)
SymbolVec3(symbol, pos .* Bohr)
end
end
push!(params, :atoms_cart => atoms_frac)
else
push!(params, :atoms_frac => atoms_frac)
end
elseif occursin(r"^begin\s+projections", line)
block_name = "projections"
projections = Vector{String}()
line = read_line_until_nonempty(; lower=false, block_name)
while !occursin(r"^end\s+projections", lowercase(line))
push!(projections, line)
line = read_line_until_nonempty(; lower=false, block_name)
end
push!(params, :projections => projections)
elseif occursin(r"^begin\s+kpoints", line)
block_name = "kpoints"
line = read_line_until_nonempty(; block_name)
# I need to read all lines and get n_kpts
lines = Vector{String}()
while !occursin(r"^end\s+kpoints", line)
push!(lines, line)
line = read_line_until_nonempty(; block_name)
end
n_kpts = length(lines)
kpoints = zeros(Vec3{Float64}, n_kpts)
for i in 1:n_kpts
# There might be weight at 4th column, but we don't use it.
kpoints[i] = Vec3(parse_array(lines[i])[1:3])
end
push!(params, :kpoints => kpoints)
elseif occursin(r"^begin\s+kpoint_path", line)
block_name = "kpoint_path"
kpoint_path = Vector{Vector{SymbolVec3{Float64}}}()
# allow uppercase
line = read_line_until_nonempty(; lower=false, block_name)
while !occursin(r"^end\s+kpoint_path", lowercase(line))
l = split(line)
length(l) == 8 || error("Invalid kpoint_path line: $line")
# start kpoint
start_label = Symbol(l[1])
start_kpt = Vec3{Float64}(parse.(Float64, l[2:4]))
# end kpoint
end_label = Symbol(l[5])
end_kpt = Vec3{Float64}(parse.(Float64, l[6:8]))
# push to kpath
push!(kpoint_path, [start_label => start_kpt, end_label => end_kpt])
line = read_line_until_nonempty(; lower=false, block_name)
end
push!(params, :kpoint_path => kpoint_path)
elseif occursin(r"^begin\s+(.+)", line)
# treat all remaining unknown blocks as Vector of String
block_name = match(r"^begin\s+(.+)", line).captures[1]
block_content = Vector{String}()
# allow uppercase
line = read_line_until_nonempty(; lower=false, block_name)
while !occursin(Regex("^end\\s+" * block_name), lowercase(line))
push!(block_content, line)
line = read_line_until_nonempty(; lower=false, block_name)
end
push!(params, Symbol(block_name) => block_content)
else
# now treat remaining lines as key-value pairs
line = strip(replace(line, "=" => " ", ":" => " "))
key, value = split(line; limit=2)
value = strip(value) # remove leading whitespaces
key = Symbol(key)
if key in keys_int
value = parse(Int, value)
elseif key in keys_int3
value = strip(replace(value, "," => " "))
value = parse_array(value; T=Int)
elseif key in keys_float
value = parse_float(value)
elseif key in keys_bool
value = parse_bool(value)
elseif key in keys_indices
value = parse_indices(value)
end
push!(params, key => value)
end
end
return params
end
fix_inputs && fix_win!(params)
# convert to NamedTuple, easier to access its fields with dot notation,
# e.g., params.num_wann
params = NamedTuple(params)
return params
end
function read_win(filename::AbstractString, ::Wannier90Toml; fix_inputs::Bool=true)
win = TOML.parsefile(filename)
# I store atoms_frac and kpoint_path as Vector of SymbolVec3.
# However, TOML.print does not accept Pair (specifically, SymbolVec3),
# instead I convert SymbolVec3 to Dict in _write_win_toml.
# On reading I convert it back.
function convert_SymbolVec3(d::Dict)
# SymbolVec3 are converted to Dict of length 1 when writing
if length(d) == 1
k, v = only(d)
isa(k, String) && isa(v, Vector{<:Real}) && return SymbolVec3(k, v)
end
# Need to do the conversion recursively
for (k, v) in pairs(d)
if isa(v, Dict) || isa(v, Vector)
d[k] = convert_SymbolVec3(v)
end
end
return d
end
function convert_SymbolVec3(v::Vector)
if isa(v, Vector{<:Dict}) || isa(v, Vector{<:Vector})
return map(convert_SymbolVec3, v)
end
return v
end
win = convert_SymbolVec3(win)
# Convert keys to Symbol
win = Dict(Symbol(k) => v for (k, v) in pairs(win))
fix_inputs && fix_win!(win)
# Vector{Vector} -> Mat3
if haskey(win, :unit_cell_cart)
win[:unit_cell_cart] = Mat3(win[:unit_cell_cart])
end
# Vector{Vector} -> Vector{Vec3}
if haskey(win, :kpoints)
win[:kpoints] = [Vec3(k) for k in win[:kpoints]]
end
return NamedTuple(win)
end
function read_win(filename::AbstractString; fix_inputs=true)
format = Wannier90Text()
try
TOML.parsefile(filename)
catch err
err isa TOML.ParserError || rethrow()
else
format = Wannier90Toml()
end
win = read_win(filename, format; fix_inputs)
num_wann = win[:num_wann]
num_bands = nothing
if :num_bands in keys(win)
num_bands = win[:num_bands]
end
# I need to convert to tuple so that @info does not output its type
mp_grid = Tuple(win[:mp_grid])
@info "Reading win file" filename num_wann num_bands mp_grid
return win
end
"""
$(SIGNATURES)
Sanity check and add missing input parameters from a `win` file.
See also [`read_win`](@ref).
"""
function fix_win!(params::Dict)
!haskey(params, :num_wann) && error("num_wann not found")
params[:num_wann] > 0 || error("num_wann must be positive")
# add num_bands if not found
!haskey(params, :num_bands) && push!(params, :num_bands => params[:num_wann])
params[:num_bands] > 0 || error("num_bands must be positive")
if haskey(params, :mp_grid)
length(params[:mp_grid]) != 3 && error("mp_grid has wrong length")
any(i -> i <= 0, params[:mp_grid]) && error("mp_grid must be positive")
else
error("mp_grid not found")
end
if haskey(params, :kpoints)
n_kpts = prod(params[:mp_grid])
length(params[:kpoints]) != n_kpts && error("kpoints has wrong shape")
else
error("kpoints not found")
end
if haskey(params, :unit_cell_cart)
any(x -> ismissing(x), params[:unit_cell_cart]) && error("unit_cell_cart not found")
else
error("unit_cell_cart not found")
end
# if atoms_cart, convert to fractional
if !haskey(params, :atoms_frac)
!haskey(params, :atoms_cart) && error("both atoms_frac and atoms_cart are missing")
atoms_cart = pop!(params, :atoms_cart)
inv_cell = inv(params[:unit_cell_cart])
atoms_frac = map(atoms_cart) do (symbol, cart)
SymbolVec3{Float64}(symbol, inv_cell * cart)
end
push!(params, :atoms_frac => atoms_frac)
end
return nothing
end
"""
write_win(filename; toml=false, kwargs...)
write_win(filename, ::Wannier90Text; kwargs...)
write_win(filename, ::Wannier90Toml; kwargs...)
Write input parameters into a wannier90 `win` file.
The input parameters are keyword arguments, with key names same as that of wannier90.
# Examples
```julia
using WannierIO
write_win(
"silicon.win";
num_wann=4,
num_bands=4,
# unit_cell_cart is a matrix, its columns are the lattice vectors in angstrom
unit_cell_cart=[
0.0 2.71527 2.71527
2.71527 0.0 2.71527
2.71527 2.71527 0.0
],
# atoms_frac is a vector of pairs of atom_label and fractional coordinates
atoms_frac=[
:Si => [0.0, 0.0, 0.0],
:Si => [0.25, 0.25, 0.25],
# both `:Si` and `"Si"` are allowed
# "Si" => [0.25, 0.25, 0.25],
],
# each element in projections will be written as a line in the win file
projections=[
"random",
]
kpoint_path=[
[:G => [0.0, 0.0, 0.0], :X => [0.5, 0.0, 0.5]],
[:X => [0.5, 0.0, 0.5], :U => [0.625, 0.25, 0.625]],
],
mp_grid=[2, 2, 2],
# kpoints is a matrix, its columns are the fractional coordinates
kpoints=[
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.5],
[0.0, 0.5, 0.0],
[0.0, 0.5, 0.5],
[0.5, 0.0, 0.0],
[0.5, 0.0, 0.5],
[0.5, 0.5, 0.0],
[0.5, 0.5, 0.5],
],
# additional parameters can be passed as keyword arguments, e.g.,
num_iter=500,
)
```
"""
function write_win end
"""
$(SIGNATURES)
"""
@inline function _check_win_required_params(kwargs)
required_keys = [:num_wann, :unit_cell_cart, :atoms_frac, :mp_grid, :kpoints]
for k in required_keys
@assert haskey(kwargs, k) "Required parameter $k not found"
end
end
function write_win(
filename::AbstractString, ::Wannier90Text; header=default_header(), kwargs...
)
_check_win_required_params(kwargs)
# convert immutable kwargs to Dict
params = Dict(kwargs)
num_wann = pop!(params, :num_wann)
num_bands = pop!(params, :num_bands, nothing)
unit_cell_cart = pop!(params, :unit_cell_cart)
atoms_frac = pop!(params, :atoms_frac)
projections = pop!(params, :projections, nothing)
kpoint_path = pop!(params, :kpoint_path, nothing)
mp_grid = pop!(params, :mp_grid)
kpoints = pop!(params, :kpoints)
# if !startswith(lstrip(header), "#")
# header = "# $header"
# end
open(filename, "w") do io
println(io, "$(header)\n")
# First write most important parameters
println(io, "num_wann = $num_wann")
!isnothing(num_bands) && println(io, "num_bands = $num_bands")
# a new line to separate from the rest
println(io)
# Drop remaining parameters
for (key, value) in pairs(params)
ismissing(value) && continue
# @printf fp "%-20s = %-30s\n" string(key) value
@printf io "%s = %s\n" string(key) value
end
println(io)
# Lattice vectors are in rows in Wannier90
println(io, "begin unit_cell_cart\nangstrom")
# for floats, e.g., unit_cell, kpoints, I need to write enough digits
# to avoid rounding errors in finding bvectors
for vec in eachcol(unit_cell_cart)
@printf io "%14.8f %14.8f %14.8f\n" vec...
end
println(io, "end unit_cell_cart\n")
println(io, "begin atoms_frac")
for (element, position) in atoms_frac
if isa(element, Symbol)
element = string(element)
end
@printf io "%-3s %14.8f %14.8f %14.8f\n" element position...
end
println(io, "end atoms_frac\n")
if !isnothing(projections)
println(io, "begin projections")
for proj in projections
println(io, proj)
end
println(io, "end projections\n")
end
if !isnothing(kpoint_path)
println(io, "begin kpoint_path")
for segment in kpoint_path
line = ""
for (label, kpt) in segment
seg = @sprintf "%-3s %14.8f %14.8f %14.8f " string(label) kpt...
line *= seg
end
line = rstrip(line)
println(io, line)
end
println(io, "end kpoint_path\n")
end
@printf io "mp_grid = %d %d %d\n\n" mp_grid...
println(io, "begin kpoints")
for kpt in kpoints
@printf io "%14.8f %14.8f %14.8f\n" kpt...
end
println(io, "end kpoints")
end
end
function write_win(
filename::AbstractString, ::Wannier90Toml; header=default_header(), kwargs...
)
_check_win_required_params(kwargs)
open(filename, "w") do io
println(io, header, "\n")
write_toml(io; kwargs...)
end
end
function write_win(filename::AbstractString; toml=false, kwargs...)
if toml
format = Wannier90Toml()
else
format = Wannier90Text()
end
num_wann = get(kwargs, :num_wann, nothing)
num_bands = get(kwargs, :num_bands, nothing)
mp_grid = get(kwargs, :mp_grid, nothing)
# I need to convert to tuple so that @info does not output its type
mp_grid !== nothing && (mp_grid = Tuple(mp_grid))
@info "Writing win file" filename num_wann num_bands mp_grid
return write_win(filename, format; kwargs...)
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 5682 | export read_wout
"""
$(SIGNATURES)
Parse wannire90 `wout` file.
# Return
- `lattice`: each column is a lattice vector in Å
- `recip_lattice`: each column is a reciprocal lattice vector in Å⁻¹
- `atom_labels`: atomic symbols
- `atom_positions`: in fractional coordinates
- `centers`: final each WF centers in Å
- `spreads`: final each WF spreads in Ų
- `ΩI`, `ΩD`, `ΩOD`, `Ωtotal`: final spread (components) in Ų
"""
function read_wout(filename::AbstractString)
return open(filename) do io
start_lattice = "Lattice Vectors ("
start_recip = "Reciprocal-Space Vectors ("
start_atom = "| Site Fractional Coordinate Cartesian Coordinate"
end_atom = "*----------------------------------------------------------------------------*"
start_finalstate = "Final State"
end_finalstate = "Sum of centres and spreads"
marker_wfc = "WF centre and spread"
marker_ΩI = "Omega I ="
marker_ΩD = "Omega D ="
marker_ΩOD = "Omega OD ="
marker_Ωtotal = "Omega Total ="
ang_unit = false
lattice = nothing
recip_lattice = nothing
atom_labels = nothing
atom_positions = nothing
centers = nothing
spreads = nothing
ΩI = nothing
ΩD = nothing
ΩOD = nothing
Ωtotal = nothing
while !eof(io)
line = strip(readline(io))
if occursin(start_lattice, line)
@assert occursin("Ang", line)
ang_unit = true
lattice = zeros(Float64, 3, 3)
line = split(strip(readline(io)))
@assert line[1] == "a_1"
lattice[:, 1] = parse_float.(line[2:end])
line = split(strip(readline(io)))
@assert line[1] == "a_2"
lattice[:, 2] = parse_float.(line[2:end])
line = split(strip(readline(io)))
@assert line[1] == "a_3"
lattice[:, 3] = parse_float.(line[2:end])
continue
end
if occursin(start_recip, line)
@assert occursin("Ang^-1", line)
recip_lattice = zeros(Float64, 3, 3)
line = split(strip(readline(io)))
@assert line[1] == "b_1"
recip_lattice[:, 1] = parse_float.(line[2:end])
line = split(strip(readline(io)))
@assert line[1] == "b_2"
recip_lattice[:, 2] = parse_float.(line[2:end])
line = split(strip(readline(io)))
@assert line[1] == "b_3"
recip_lattice[:, 3] = parse_float.(line[2:end])
continue
end
if occursin(start_atom, line)
@assert occursin("Ang", line)
readline(io)
lines = Vector{String}()
line = strip(readline(io))
while line != end_atom
push!(lines, line)
line = strip(readline(io))
end
n_atom = length(lines)
atom_labels = Vector{String}()
atom_positions = zeros(Vec3{Float64}, n_atom)
for (i, line) in enumerate(lines)
line = split(line)
@assert line[1] == "|" line
push!(atom_labels, line[2])
# cartesian
# atom_positions[i] = Vec3(parse_float.(line[8:10]))
# fractional
atom_positions[i] = Vec3(parse_float.(line[4:6]))
end
continue
end
if occursin(start_finalstate, line)
lines = Vector{String}()
line = strip(readline(io))
while !occursin(end_finalstate, line)
push!(lines, line)
line = strip(readline(io))
end
n_wann = length(lines)
centers = zeros(Vec3{Float64}, n_wann)
spreads = zeros(Float64, n_wann)
for (i, line) in enumerate(lines)
@assert startswith(line, marker_wfc) line
line = split(line, r"[,()]")
idx = strip(chopprefix(line[1], marker_wfc))
idx = parse(Int, idx)
@assert i == idx "Wrong WF index at $(line[1])"
vals = map(parse_float, line[2:end])
centers[i] = Vec3(vals[1:3])
spreads[i] = vals[4]
end
continue
end
if occursin(marker_ΩI, line)
ΩI = parse_float(split(line, marker_ΩI)[2])
continue
end
if occursin(marker_ΩD, line)
ΩD = parse_float(split(line, marker_ΩD)[2])
continue
end
if occursin(marker_ΩOD, line)
ΩOD = parse_float(split(line, marker_ΩOD)[2])
continue
end
if occursin(marker_Ωtotal, line)
Ωtotal = parse_float(split(line, marker_Ωtotal)[2])
continue
end
end
@assert ang_unit "wout unit is not Angstrom, not supported yet"
lattice = Mat3(lattice)
recip_lattice = Mat3(recip_lattice)
return (;
lattice,
recip_lattice,
atom_labels,
atom_positions,
centers,
spreads,
ΩI,
ΩD,
ΩOD,
Ωtotal,
)
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 5547 | export read_w90_wsvec, write_w90_wsvec
"""
$(SIGNATURES)
Read `prefix_wsvec.dat`.
# Return
- `mdrs`: whether use MDRS interpolation, i.e. the `use_ws_distance` in the header
- `Rvectors`: the ``\\mathbf{R}``-vectors
- `Tvectors`: the ``\\mathbf{T}_{m n \\mathbf{R}}``-vectors.
Returned only `mdrs = true`.
- `Tdegens`: the degeneracies of ``\\mathbf{T}_{m n \\mathbf{R}}``-vectors.
Returned only `mdrs = true`.
- `n_wann`: number of WFs
- `header`: the first line of the file
"""
function read_w90_wsvec(filename::AbstractString)
header, mdrs, Rmn, Tvectors_flat, Tdegens_flat = open(filename) do io
header = strip(readline(io))
# check `use_ws_distance`
mdrs = false
mdrs_str = split(header)[end]
if occursin("use_ws_distance=", mdrs_str)
mdrs_str = lowercase(split(header, "use_ws_distance=")[2])
mdrs = parse_bool(mdrs_str)
end
Rmn = Vector{Vector{Int}}()
# Tvectors_flat[iRmn][iT] is Vec3 for T-vector, where iRmn is the index for the
# combination of Rvector and (m, n), iT is the index of T-vector at iRmn.
# Later on we will reorder this flattened vector, i.e., unfold the
# iRmn index into (iR, m, n).
Tvectors_flat = Vector{Vector{Vec3{Int}}}()
Tdegens_flat = Vector{Int}()
while !eof(io)
line = strip(readline(io))
# the last line is empty
if length(line) == 0
continue
end
Rx, Ry, Rz, m, n = parse.(Int, split(line))
push!(Rmn, [Rx, Ry, Rz, m, n])
n_T = parse(Int, strip(readline(io)))
push!(Tdegens_flat, n_T)
T = zeros(Vec3{Int}, n_T)
for iT in 1:n_T
line = strip(readline(io))
T[iT] = Vec3(parse.(Int, split(line))...)
end
push!(Tvectors_flat, T)
end
return header, mdrs, Rmn, Tvectors_flat, Tdegens_flat
end
# get number of WFs
n_wann = length(unique(i[end] for i in Rmn))
n_Rvecs = length(Rmn) ÷ n_wann^2
Rvectors = zeros(Vec3{Int}, n_Rvecs)
iR = 1
for rmn in Rmn
m, n = rmn[4:5]
if m == 1 && n == 1
Rvectors[iR] = Vec3(rmn[1:3])
iR += 1
end
end
if !mdrs
return (; mdrs, Rvectors, n_wann, header)
end
# Objective: reorder Tvectors_flat -> Tvectors, Tdegens_flat -> Tdegens
# such that Tvectors[iR][m, n][iT] is Vec3 for T-vector
Tvectors = [Matrix{Vector{Vec3{Int}}}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
# and Tdegens[iR][m, n] is the degeneracy of T-vector at iR-th Rvector &
# between m-th and n-th WFs
Tdegens = [Matrix{Int}(undef, n_wann, n_wann) for _ in 1:n_Rvecs]
iR = 1
for (iRmn, rmn) in enumerate(Rmn)
m, n = rmn[(end - 1):end]
Tvectors[iR][m, n] = Tvectors_flat[iRmn]
Tdegens[iR][m, n] = Tdegens_flat[iRmn]
# next Rvector
if m == n_wann && n == n_wann
iR += 1
end
end
@info "Reading wsvec.dat file" filename header mdrs n_wann n_Rvecs
return (; mdrs, Rvectors, Tvectors, Tdegens, n_wann, header)
end
"""
$(SIGNATURES)
Write `prefix_wsvec.dat`.
# Keyword Arguments
- `n_wann`: for Wigner-Seitz Rvectors, needs to provide a `n_wann` for number of
Wannier functions; for MDRS Rvectors, the `n_wann` is optional and can be
automatically determined from the `Tvectors`
- `Tvectors` and `Tdegens`: if provided, write in MDRS format; otherwise, write in
Wigner-Seitz format
Also see the return values of [`read_w90_wsvec`](@ref).
"""
function write_w90_wsvec(
filename::AbstractString;
Rvectors::AbstractVector,
n_wann::Union{Integer,Nothing}=nothing,
Tvectors::Union{AbstractVector,Nothing}=nothing,
Tdegens::Union{AbstractVector,Nothing}=nothing,
header=default_header(),
)
@assert (Tvectors !== nothing && Tdegens !== nothing) ||
(Tvectors === nothing && Tdegens === nothing) "Tvectors and Tdegens must be both nothing or both not nothing"
mdrs = Tvectors !== nothing
n_Rvecs = length(Rvectors)
@assert n_Rvecs > 0 "empty Rvectors"
if mdrs
@assert length(Tvectors) == length(Tdegens) == n_Rvecs "different n_Rvecs in Rvectors, Tvectors, and Tdegens"
if n_wann === nothing
n_wann = size(Tvectors[1], 1)
else
@assert n_wann == size(Tvectors[1], 1) "different n_wann in Tvectors and n_wann"
end
else
@assert n_wann !== nothing "n_wann must be provided for Wigner-Seitz format"
end
@info "Writing wsvec.dat file" filename header mdrs n_wann n_Rvecs
open(filename, "w") do io
if mdrs
println(io, header * " with use_ws_distance=.true.")
else
println(io, header * " with use_ws_distance=.false.")
end
for iR in 1:n_Rvecs
R = Rvectors[iR]
for m in 1:n_wann
for n in 1:n_wann
@printf(io, "%5d %5d %5d %5d %5d\n", R..., m, n)
if mdrs
@printf(io, "%5d\n", Tdegens[iR][m, n])
for T in Tvectors[iR][m, n]
@printf(io, "%5d %5d %5d\n", T...)
end
else
@printf(io, "%5d\n", 1)
@printf(io, "%5d %5d %5d\n", 0, 0, 0)
end
end
end
end
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 379 | # using Aqua
# only test ambiguities in current module, otherwise fails due to ambiguities in other packages
# https://github.com/JuliaTesting/Aqua.jl/issues/77
# disable project_extras since we don't use julia < 1.2
# Aqua.test_all(WannierIO; ambiguities=false, project_extras=false)
# Aqua.test_ambiguities(WannierIO)
using TestItemRunner
@run_package_tests verbose = true
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 758 | @testitem "read EPW mmn" begin
using LazyArtifacts
M, kpb_k, kpb_G = read_mmn(artifact"BN/BN.mmn")
n_kpts = length(M)
n_bvecs = length(M[1])
n_bands = size(M[1][1], 1)
M1 = WannierIO.read_epw_mmn(artifact"BN/reference/bn.mmn"; n_kpts, n_bvecs, n_bands)
@test M ≈ M1
end
@testitem "read/write EPW ukk" begin
using LazyArtifacts
chk = read_chk(artifact"BN/reference/bn.chk")
alat = WannierIO.read_qe_xml(artifact"BN/reference/bn.xml").alat
ukk_ref = WannierIO.Ukk(chk, alat)
ukk = WannierIO.read_epw_ukk(artifact"BN/reference/bn.ukk")
@test ukk ≈ ukk_ref
tmpfile = tempname(; cleanup=true)
WannierIO.write_epw_ukk(tmpfile, ukk)
ukk2 = WannierIO.read_epw_ukk(tmpfile)
@test ukk2 ≈ ukk
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 3708 | @testitem "read qe xml" begin
using WannierIO: Vec3
using LazyArtifacts
qe = WannierIO.read_qe_xml(artifact"Si2/reference/qe_bands.xml")
lattice = [0.0 2.715265 2.715265; 2.715265 0.0 2.715265; 2.715265 2.715265 0.0]
@test qe.lattice ≈ lattice
atom_positions = Vec3[[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]]
@test qe.atom_positions ≈ atom_positions
atom_labels = ["Si", "Si"]
@test qe.atom_labels == atom_labels
recip_lattice = [
-1.1570114348285685 1.1570114348285685 1.1570114348285685
1.1570114348285685 -1.1570114348285685 1.1570114348285685
1.1570114348285685 1.1570114348285685 -1.1570114348285685
]
@test qe.recip_lattice ≈ recip_lattice
@test length(qe.kpoints) == 511
@test qe.kpoints[1] ≈ [0.0, 0.0, 0.0]
@test qe.kpoints[end] ≈ [0.5, 0.0, 0.5]
@test length(qe.eigenvalues) == 511
eigenvalues1 = [
-5.826225550687528,
6.165602316381265,
6.165602316381265,
6.165602316381303,
8.683797578503912,
8.683797578503947,
8.683797578503983,
9.477127583014145,
13.86461804570024,
13.864618045701016,
13.87950848504097,
17.27314636025589,
17.273146360255925,
17.273146360257257,
21.254697588478756,
29.07002686142792,
]
eigenvalues511 = [
-1.6666776531834973,
-1.6666776531834973,
3.2884932258593533,
3.2884932258593533,
6.758325832996588,
6.758325832996588,
16.220036706342146,
16.220036706342146,
17.107712425166522,
17.10771242516657,
18.670405795535505,
18.67040579553565,
19.10855942754898,
19.10855942754903,
24.841843066432848,
24.841843066563083,
]
@test qe.eigenvalues[1] ≈ eigenvalues1
@test qe.eigenvalues[end] ≈ eigenvalues511
@test qe.n_electrons ≈ 8.0
@test qe.fermi_energy ≈ 6.528341904366175
@test qe.alat ≈ 3.8399645884368714
end
@testitem "read qe xml spin-polarized" begin
using WannierIO: Vec3
using LazyArtifacts
qe = WannierIO.read_qe_xml(artifact"CrI3/reference/qe_bands.xml")
lattice = [
6.8171434485254725 -3.4085717242627362 0.0
0.0 5.903819407666132 0.0
0.0 0.0 20.078373841305446
]
@test qe.lattice ≈ lattice
atom_positions = Vec3[
[0.33333333330000003, 0.6666666667000001, 0.0],
[0.6666666667, 0.3333333332999999, 0.0],
[-2.7755575615628914e-17, 0.35410773599999995, 0.0769313053],
[0.0, 0.645892264, -0.07693127530000003],
[0.354107736, 0.35410773599999995, -0.07693127530000003],
[0.645892264, 0.645892264, 0.0769313053],
[0.354107736, 0.0, 0.0769313053],
[0.645892264, 0.0, -0.07693127530000003],
]
@test qe.atom_positions ≈ atom_positions
atom_labels = ["Cr", "Cr", "I", "I", "I", "I", "I", "I"]
@test qe.atom_labels == atom_labels
recip_lattice = [
0.921674210704576 0.0 0.0
0.532128853655385 1.0642577073107704 0.0
0.0 0.0 0.31293297738354436
]
@test qe.recip_lattice ≈ recip_lattice
@test length(qe.kpoints) == 274
kpoint2 = Vec3(0.0, 0.0049999999999999975, 0.0)
@test qe.kpoints[2] ≈ kpoint2
@test length(qe.eigenvalues_up) == 274
eigenvalues_up2 = [-77.99192823029188, -77.99169805183234, -49.45736655071318]
@test qe.eigenvalues_up[2][1:3] ≈ eigenvalues_up2
@test length(qe.eigenvalues_dn) == 274
eigenvalues_dn2 = [-74.843061971795, -74.84277910814951, -46.38172392618895]
@test qe.eigenvalues_dn[2][1:3] ≈ eigenvalues_dn2
@test qe.fermi_energy ≈ -4.819375066024118
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 516 |
@testitem "isbinary file" begin
using LazyArtifacts
@test WannierIO.isbinary(artifact"Si2_valence/reference/binary/UNK00001.1")
@test !WannierIO.isbinary(artifact"Si2_valence/UNK/UNK00001.1")
end
@testitem "parse_float" begin
@test WannierIO.parse_float("1.0D-10") ≈ 1e-10
end
@testitem "parse_bool" begin
@test WannierIO.parse_bool(".true.") == true
@test WannierIO.parse_bool("T") == true
@test WannierIO.parse_bool("1") == true
@test WannierIO.parse_bool(".false") == false
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 417 | @testitem "parse_vector" begin
io = IOBuffer("""1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23""")
vec = WannierIO.parse_vector(io, Int, 23)
@test vec == collect(1:23)
close(io)
# different number of elements per line
io = IOBuffer("""1 2 3 4 5
6
7 8 9""")
vec = WannierIO.parse_vector(io, Int, 9)
@test vec == collect(1:9)
close(io)
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 893 | @testitem "read/write bxsf" begin
using LazyArtifacts
bxsf = read_bxsf(artifact"Cu/reference/Cu.bxsf")
@test bxsf.fermi_energy ≈ 16.8985
@test bxsf.origin ≈ [0.0, 0.0, 0.0]
@test bxsf.span_vectors ≈
[0.0 2.1769775 2.1769775; 2.1769775 0.0 2.1769775; 2.304768 2.304768 0.0]
@test bxsf.X ≈ range(0, 1, 31)
@test bxsf.Y ≈ bxsf.X
@test bxsf.Z ≈ bxsf.X
@test size(bxsf.E) == (7, 31, 31, 31)
E1234 = 8.26105181
@test bxsf.E[1, 2, 3, 4] ≈ E1234
tmpfile = tempname(; cleanup=true)
write_bxsf(tmpfile, bxsf.fermi_energy, bxsf.origin, bxsf.span_vectors, bxsf.E)
bxsf2 = read_bxsf(tmpfile)
@test bxsf.fermi_energy ≈ bxsf2.fermi_energy
@test bxsf.origin ≈ bxsf2.origin
@test bxsf.span_vectors ≈ bxsf2.span_vectors
@test bxsf.X ≈ bxsf2.X
@test bxsf.Y ≈ bxsf2.Y
@test bxsf.Z ≈ bxsf2.Z
@test bxsf.E ≈ bxsf2.E
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1080 | @testitem "read/write cube" begin
using LazyArtifacts
using WannierIO: Bohr
cube = read_cube(artifact"Si2_valence/reference/Si2_valence_00001.cube")
@test cube.origin ≈ [-7.10461, -9.47281, -9.47281]*Bohr
@test cube.voxel_vectors ≈
transpose([0.0 0.39470 0.39470; 0.39470 0.00000 0.39470; 0.39470 0.39470 0.00000])*Bohr
@test cube.X ≈ range(0, 19, 20)
@test cube.Y ≈ cube.X
@test cube.Z ≈ cube.X
@test size(cube.W) == (20,20,20)
@test size(cube.atom_positions) == (3,8)
@test cube.atom_positions[:,1] ≈ transpose([0.00000 -5.13111 -5.13111])*Bohr
tmpfile = tempname(; cleanup=true)
write_cube(tmpfile, cube.atom_positions, cube.atom_numbers, cube.origin, cube.voxel_vectors, cube.W)
cube2 = read_cube(tmpfile)
@test cube.atom_positions ≈ cube2.atom_positions
@test cube.atom_numbers ≈ cube2.atom_numbers
@test cube.origin ≈ cube2.origin
@test cube.voxel_vectors ≈ cube2.voxel_vectors
@test cube.X ≈ cube2.X
@test cube.Y ≈ cube2.Y
@test cube.Z ≈ cube2.Z
@test cube.W ≈ cube2.W
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1197 | @testitem "read/write amn" begin
using LazyArtifacts
A = read_amn(artifact"Si2_valence/Si2_valence.amn")
ref_A215 = ComplexF64[
0.602605803842+0.466458612517im 0.709819979644+0.096505743176im 0.602605806825+0.466458612235im 0.271333571639+0.662974997524im
-2.7652e-8+2.436e-9im -0.401551121567-0.311690904391im -1.7245e-8+1.8091e-8im -0.069156613881+0.503598920796im
-0.009606395172-0.299196334599im 0.150309036867+0.2420558235im -0.009606388763-0.299196326647im -0.134471911066+0.251199304047im
-0.392902559295+0.232501544615im 5.7803e-8-7.7606e-8im 0.39290241635-0.232501390525im 1.50756e-7-8.2322e-8im
]
@test length(A) == 216
@test size(A[1]) == (4, 4)
@test A[215] ≈ ref_A215
tmpfile = tempname(; cleanup=true)
write_amn(tmpfile, A)
A1 = read_amn(tmpfile)
@test A ≈ A1
end
@testitem "read/write amn binary" begin
using LazyArtifacts
A = read_amn(artifact"Si2_valence/Si2_valence.amn")
A1 = read_amn(artifact"Si2_valence/reference/binary/Si2_valence.amn")
@test A ≈ A1
tmpfile = tempname(; cleanup=true)
write_amn(tmpfile, A; binary=true)
A2 = read_amn(tmpfile)
@test A ≈ A2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 679 | @testitem "read/write w90 band dat" begin
using LazyArtifacts
band = read_w90_band(artifact"Si2_valence/reference/MDRS/Si2_valence")
@test length(band.kpoints) == 511
@test length(band.kpoints[1]) == 3
@test band.kpoints[511] == [0.5, 0.0, 0.5]
@test band.symm_point_indices == [1, 101, 136, 197, 303, 390, 461, 511]
@test band.symm_point_labels == ["G", "X", "U", "K", "G", "L", "W", "X"]
@test length(band.x) == 511
@test band.x[511] == 5.9004323
outdir = mktempdir(; cleanup=true)
outprefix = joinpath(outdir, "Si2_valence")
write_w90_band(outprefix; band...)
band2 = read_w90_band(outprefix)
@test band == band2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 5697 | @testitem "read chk" begin
using LazyArtifacts
chk = read_chk(artifact"Si2_valence/reference/Si2_valence.chk.fmt")
@test chk.n_wann == 4
@test chk.n_bands == 4
@test chk.n_kpts == 6^3
@test chk.n_bvecs == 8
@test length(chk.M) == 6^3
@test length(chk.M[1]) == 8
@test size(chk.M[1][1]) == (4, 4)
ref_M12 = ComplexF64[
0.9170561763002493-0.12073283760315105im 0.006084376539889745-0.0008009985221228121im 0.06241876168424332+0.02585491031881253im 0.006084587068619811-0.0008011618858289517im
0.006084880213061389-0.0008013918486074993im 0.9170555712700101-0.1207327246826146im 0.06241866709702579+0.025854802566432057im 0.006084809499489799-0.000800887926406555im
0.04089804920678168-0.005384004515382356im 0.040899090696488685-0.005384672958981166im 0.789621736965331+0.32707172642290266im 0.04089840122633419-0.005384316593360309im
0.006084658804818147-0.0008009811562424997im 0.0060846064084139105-0.0008007905091687038im 0.0624189360729618+0.02585459811803456im 0.9170558895434384-0.1207329088207673im
]
@test chk.M[1][2] ≈ ref_M12
@test length(chk.Uml) == 216
@test size(chk.Uml[1]) == (4, 4)
ref_U2 = ComplexF64[
-0.16235109810009157+0.47353334937462366im -0.3755805652160198+0.32735938468233533im -0.16235110057874652+0.4735333026272855im -0.16235112363576365+0.47353331917208363im
0.16956618931090092-0.23235535713863867im -0.7928314959724974+0.35098901875473565im 0.16956603006099888-0.23235524733459334im 0.16956607268060825-0.232355268156885im
-0.3123360136432703+0.025184486826638694im -3.782746554514418e-8+1.6862208020401383e-8im -0.10111009556353681-0.6127313622218364im 0.41344612298635436+0.587546837211439im
-0.6776552858574172-0.33054780770943226im -8.7307707370288e-8-6.01196661668837e-8im 0.30384128248067205+0.43437798438065095im 0.3738141419013159-0.10383009885606777im
]
@test chk.Uml[2] ≈ ref_U2
@test chk.Udis == Matrix{ComplexF64}[]
@test chk.checkpoint == "postwann"
@test chk.dis_bands == BitVector[]
@test chk.n_dis == Int64[]
@test chk.exclude_bands == Int64[]
@test chk.n_exclude_bands == 0
@test chk.have_disentangled == false
@test chk.header == "written on 15Jun2023 at 10:39:45"
win = read_win(artifact"Si2_valence/Si2_valence.win")
@test chk.kgrid == win.mp_grid
@test chk.kpoints == win.kpoints
# make sure we read the lattice as column-major
@test chk.lattice ≈ win.unit_cell_cart
@test chk.recip_lattice ≈ WannierIO.get_recip_lattice(chk.lattice)
ref_r = WannierIO.Vec3[
[0.6788160683908873, -0.678816205763796, -0.6788162184647731],
[-0.6788164049684758, -0.6788163321814957, 0.6788162805858188],
[-0.6788162635506181, 0.6788163021769287, -0.678816181780838],
[0.6788160891131698, 0.6788160528597309, 0.6788162387951322],
]
@test chk.r ≈ ref_r
@test chk.ΩI == -1.0
ref_ω = [1.9291789239559392, 1.9291789959111603, 1.9291788335828866, 1.9291788667547383]
@test chk.ω ≈ ref_ω
end
@testitem "read/write chk" begin
using LazyArtifacts
chk = read_chk(artifact"Si2_valence/reference/Si2_valence.chk.fmt")
tmpfile = tempname(; cleanup=true)
write_chk(tmpfile, chk)
chk2 = read_chk(tmpfile)
@test chk ≈ chk2
end
@testitem "read/write chk binary" begin
using LazyArtifacts
chk = read_chk(artifact"Si2_valence/reference/Si2_valence.chk.fmt")
chk1 = read_chk(artifact"Si2_valence/reference/binary/Si2_valence.chk")
@test chk ≈ chk1
tmpfile = tempname(; cleanup=true)
write_chk(tmpfile, chk; binary=true)
chk2 = read_chk(tmpfile)
@test chk ≈ chk2
end
@testitem "read chk disentanglement" begin
using LazyArtifacts
chk = read_chk(artifact"Si2/reference/Si2.chk.fmt")
@test chk.n_wann == 8
@test chk.n_bands == 16
@test chk.n_kpts == 9^3
@test chk.n_bvecs == 8
@test length(chk.M) == 9^3
@test length(chk.M[1]) == 8
@test size(chk.M[1][1]) == (8, 8)
@test chk.dis_bands == [trues(16) for _ in 1:(9^3)]
@test chk.n_dis == [16 for _ in 1:(9^3)]
@test chk.have_disentangled == true
end
@testitem "read/write chk disentanglement" begin
using LazyArtifacts
chk = read_chk(artifact"Si2/reference/Si2.chk.fmt")
tmpfile = tempname(; cleanup=true)
write_chk(tmpfile, chk)
chk2 = read_chk(tmpfile)
@test chk ≈ chk2
end
@testitem "read/write chk disentanglement binary" begin
using LazyArtifacts
chk = read_chk(artifact"Si2/reference/Si2.chk.fmt")
chk1 = read_chk(artifact"Si2/reference/Si2.chk")
@test chk ≈ chk1
tmpfile = tempname(; cleanup=true)
write_chk(tmpfile, chk; binary=true)
chk2 = read_chk(tmpfile)
@test chk ≈ chk2
end
@testitem "get_Udis" begin
using LazyArtifacts
chk = read_chk(artifact"Si2/reference/Si2.chk")
Udis = get_Udis(chk)
Udis_ref = read_amn(artifact"Si2/reference/Si2.chk_Udis.amn")
@test Udis ≈ Udis_ref
end
@testitem "get_U" begin
using LazyArtifacts
chk = read_chk(artifact"Si2/reference/Si2.chk")
U = get_U(chk)
U_ref = read_amn(artifact"Si2/reference/Si2.chk_U.amn")
@test U ≈ U_ref
end
# test chk lattice/recip_lattice are column-major
@testitem "read/write chk lattice" begin
using LazyArtifacts
chk = read_chk(artifact"Fe_soc/reference/Fe.chk")
wout = read_wout(artifact"Fe_soc/reference/Fe.wout")
@test all(isapprox.(chk.lattice, wout.lattice; atol=3e-7))
@test all(isapprox.(chk.recip_lattice, wout.recip_lattice; atol=3e-7))
tmpfile = tempname(; cleanup=true)
write_chk(tmpfile, chk; binary=true)
chk2 = read_chk(tmpfile)
@test chk ≈ chk2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 727 |
@testitem "read/write eig" begin
using LazyArtifacts
E = read_eig(artifact"Si2_valence/Si2_valence.eig")
@test length(E) == 216
@test length(E[1]) == 4
ref_E2 = [-5.463742712458, 3.764318343758, 5.709948162634, 5.709948162651]
@test E[2] ≈ ref_E2
tmpfile = tempname(; cleanup=true)
write_eig(tmpfile, E)
E1 = read_eig(tmpfile)
@test E ≈ E1
end
@testitem "read/write eig binary" begin
using LazyArtifacts
E = read_eig(artifact"Si2_valence/Si2_valence.eig")
E1 = read_eig(artifact"Si2_valence/reference/binary/Si2_valence.eig")
@test E ≈ E1
tmpfile = tempname(; cleanup=true)
write_eig(tmpfile, E; binary=true)
E2 = read_eig(tmpfile)
@test E ≈ E2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1388 | @testitem "read hr ws" begin
using LazyArtifacts
hrdat = read_w90_hrdat(artifact"Si2_valence/reference/WS/Si2_valence_hr.dat")
# just some simple tests
@test length(hrdat.Rvectors) == 279
@test hrdat.Rvectors[1] == [-4, 0, 2]
@test length(hrdat.H) == 279
H1 = ComplexF64[
0.000805+0.0im -0.000431-0.0im -0.000137+0.0im -0.000431+0.0im
-0.000431-0.0im 0.000805+0.0im -0.000137+0.0im -0.000431-0.0im
-0.000299+0.0im -0.000298+0.0im 0.000534+0.0im -0.000298-0.0im
-0.000431+0.0im -0.000431+0.0im -0.000137-0.0im 0.000805-0.0im
]
@test hrdat.H[1] ≈ H1
end
@testitem "read hr mdrs" begin
using LazyArtifacts
# The two files are identical
hrdat = read_w90_hrdat(artifact"Si2_valence/reference/WS/Si2_valence_hr.dat")
hrdat_ws = read_w90_hrdat(artifact"Si2_valence/reference/WS/Si2_valence_hr.dat")
for p in propertynames(hrdat)
p == :header && continue
@test hrdat_ws[p] ≈ hrdat[p]
end
end
@testitem "write hr" begin
using LazyArtifacts
hrdat = read_w90_hrdat(artifact"Si2_valence/reference/WS/Si2_valence_hr.dat")
tmpfile = tempname(; cleanup=true)
write_w90_hrdat(tmpfile; hrdat...)
hrdat2 = read_w90_hrdat(tmpfile)
@test keys(hrdat) == keys(hrdat2)
for (k, v) in pairs(hrdat)
k == :header && continue
@test hrdat2[k] == v
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1847 |
@testitem "read/write mmn" begin
using LazyArtifacts
M, kpb_k, kpb_G = read_mmn(artifact"Si2_valence/Si2_valence.mmn")
@test length(M) == 216
@test length(M[1]) == 8
@test size(M[1][1]) == (4, 4)
ref_M215_2 = ComplexF64[
0.622355772788+0.779341618658im -0.015531265051+0.027176244708im -0.003508661654-0.015077859568im 0.021680417129+0.039444115733im
-0.00654020394-0.043590860733im -0.716198599581+0.416420660955im -0.022335323703+0.073160414474im -0.011094081817+0.495937237686im
0.000395190251-0.001890191419im -0.473340195142+0.082043373917im 0.346341288525-0.454328488051im 0.219116863121-0.552770061648im
0.007094594145-0.002164553263im 0.15507683774+0.19419614694im 0.69754000164+0.104779280281im -0.363933244214+0.045670933434im
]
@test M[215][2] ≈ ref_M215_2
ref_kpb_k_3 = [2, 4, 9, 39, 46, 33, 183, 212]
@test kpb_k[3] == ref_kpb_k_3
ref_kpb_G_3 = WannierIO.Vec3[
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, -1, 0],
[-1, 0, 0],
[-1, -1, 0],
]
@test kpb_G[3] == ref_kpb_G_3
tmpfile = tempname(; cleanup=true)
write_mmn(tmpfile, M, kpb_k, kpb_G)
M2, kpb_k2, kpb_G2 = read_mmn(tmpfile)
@test M ≈ M2
@test kpb_k ≈ kpb_k2
@test kpb_G ≈ kpb_G2
end
@testitem "read/write mmn binary" begin
using LazyArtifacts
M, kpb_k, kpb_G = read_mmn(artifact"Si2_valence/Si2_valence.mmn")
M1, kpb_k1, kpb_G1 = read_mmn(artifact"Si2_valence/reference/binary/Si2_valence.mmn")
@test M ≈ M1
@test kpb_k ≈ kpb_k1
@test kpb_G ≈ kpb_G1
tmpfile = tempname(; cleanup=true)
write_mmn(tmpfile, M, kpb_k, kpb_G; binary=true)
M2, kpb_k2, kpb_G2 = read_mmn(tmpfile)
@test M ≈ M2
@test kpb_k ≈ kpb_k2
@test kpb_G ≈ kpb_G2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 998 | @testitem "read nnkp" begin
using LazyArtifacts
nnkp = read_nnkp(artifact"Si2_valence/reference/Si2_valence.nnkp")
WRITE_TOML = false
WRITE_TOML && write_nnkp("/tmp/Si2_valence.nnkp.toml"; toml=true, nnkp...)
test_data = read_nnkp(artifact"Si2_valence/reference/Si2_valence.nnkp.toml")
# make their keys unordered for comparison
@test pairs(nnkp) == pairs(test_data)
end
@testitem "read/write nnkp" begin
using LazyArtifacts
nnkp = read_nnkp(artifact"Si2_valence/reference/Si2_valence.nnkp")
tmpfile = tempname(; cleanup=true)
n_wann = 4
write_nnkp(tmpfile; nnkp..., n_wann)
nnkp2 = read_nnkp(tmpfile)
@test pairs(nnkp) == pairs(nnkp2)
end
@testitem "read/write nnkp toml" begin
using LazyArtifacts
nnkp = read_nnkp(artifact"Si2_valence/reference/Si2_valence.nnkp.toml")
tmpfile = tempname(; cleanup=true)
write_nnkp(tmpfile; toml=true, nnkp...)
nnkp2 = read_nnkp(tmpfile)
@test pairs(nnkp) == pairs(nnkp2)
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1535 | @testitem "read r WS" begin
using LazyArtifacts
rdat = read_w90_rdat(artifact"Si2_valence/reference/WS/Si2_valence_r.dat")
Rvectors1 = [-4, 0, 2]
@test rdat.Rvectors[1] == Rvectors1
r_x_end = ComplexF64[
0.0-0.0im -0.001846-0.0im 0.000296+0.0im 0.002093+0.0im
-0.000806-0.0im -0.0-0.0im -0.000149+0.0im -0.000806+0.0im
-4.4e-5-0.0im 0.00034+0.0im 0.0-0.0im -4.4e-5+0.0im
0.002093+0.0im -0.001846+0.0im 0.000296-0.0im -0.0-0.0im
]
@test rdat.r_x[end] ≈ r_x_end
r_y_end = ComplexF64[
-0.0+0.0im -0.002093-0.0im -0.000296-0.0im 0.001846-0.0im
-0.002093+0.0im -0.0-0.0im -0.000296-0.0im 0.001846+0.0im
4.4e-5-0.0im 4.4e-5+0.0im -0.0+0.0im -0.00034+0.0im
0.000806+0.0im 0.000806+0.0im 0.000149+0.0im -0.0-0.0im
]
@test rdat.r_y[end] ≈ r_y_end
r_z_end = ComplexF64[
0.0-0.0im -0.000806-0.0im -0.000149+0.0im -0.000806+0.0im
-0.001846-0.0im 0.0+0.0im 0.000296-0.0im 0.002093+0.0im
0.00034+0.0im -4.4e-5+0.0im 0.0-0.0im -4.4e-5-0.0im
-0.001846+0.0im 0.002093+0.0im 0.000296+0.0im -0.0+0.0im
]
@test rdat.r_z[end] ≈ r_z_end
end
@testitem "read r MDRS" begin
using LazyArtifacts
# The two files are identical
rdat = read_w90_rdat(artifact"Si2_valence/reference/MDRS/Si2_valence_r.dat")
rdat_ws = read_w90_rdat(artifact"Si2_valence/reference/WS/Si2_valence_r.dat")
for p in propertynames(rdat)
p == :header && continue
@test rdat_ws[p] ≈ rdat[p]
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1593 | @testitem "read/write spn" begin
using LazyArtifacts
Sx, Sy, Sz = read_spn(artifact"Fe_soc/test/Fe.spn.fmt")
ref_Sx_end = ComplexF64[
-1.045982416783206e-9+0.0im 1.8309573615290023e-9+1.8135039310434643e-9im -0.9143596596228599+0.39269798727353im 2.2580234889560057e-5+0.00012322780868176796im
1.8309573615290023e-9-1.8135039310434643e-9im 5.005565130696888e-9+0.0im -6.863936845424341e-5+0.00010788172874406267im 0.6996261651438792+0.7076597058385461im
-0.9143596596228599-0.39269798727353im -6.863936845424341e-5-0.00010788172874406267im 8.544459741957264e-9+0.0im -1.1837183322351442e-8+7.277568287854686e-10im
2.2580234889560057e-5-0.00012322780868176796im 0.6996261651438792-0.7076597058385461im -1.1837183322351442e-8-7.277568287854686e-10im -1.3997437777976164e-8+0.0im
]
@test length(Sx) == length(Sy) == length(Sz) == 8
@test size(Sx[1]) == size(Sy[1]) == size(Sz[1]) == (4, 4)
@test Sx[end] ≈ ref_Sx_end
tmpfile = tempname(; cleanup=true)
write_spn(tmpfile, Sx, Sy, Sz; binary=false)
Sx1, Sy1, Sz1 = read_spn(tmpfile)
@test Sx ≈ Sx1
@test Sy ≈ Sy1
@test Sz ≈ Sz1
end
@testitem "read/write spn binary" begin
using LazyArtifacts
Sx, Sy, Sz = read_spn(artifact"Fe_soc/test/Fe.spn")
Sx1, Sy1, Sz1 = read_spn(artifact"Fe_soc/test/Fe.spn.fmt")
@test Sx ≈ Sx1
@test Sy ≈ Sy1
@test Sz ≈ Sz1
tmpfile = tempname(; cleanup=true)
write_spn(tmpfile, Sx, Sy, Sz; binary=true)
Sx2, Sy2, Sz2 = read_spn(tmpfile)
@test Sx ≈ Sx2
@test Sy ≈ Sy2
@test Sz ≈ Sz2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 3897 | @testitem "read tb WS" begin
using LazyArtifacts
tbdat = read_w90_tbdat(artifact"Si2_valence/reference/WS/Si2_valence_tb.dat")
@test length(tbdat.Rvectors) == 279
@test tbdat.Rvectors[1] == [-4, 0, 2]
@test length(tbdat.H) == 279
H1 = ComplexF64[
0.00080451304+1.6092791e-9im -0.00043090632-8.9535509e-9im -0.00013727432+1.7830477e-10im -0.00043090075+2.7695627e-9im
-0.0004309027-2.2505901e-9im 0.00080451732+3.968764e-9im -0.00013726424+5.6728313e-9im -0.00043091084-2.4100158e-9im
-0.00029850062+3.3998938e-9im -0.00029849652+1.2885406e-9im 0.00053380915+6.5106419e-10im -0.00029849523-4.1141943e-9im
-0.00043089878+6.7332791e-9im -0.00043091377+5.6168704e-9im -0.0001372618-4.1114441e-9im 0.00080451507-6.2301744e-9im
]
@test tbdat.H[1] ≈ H1
@test length(tbdat.Rdegens) == 279
@test tbdat.Rdegens[1] == 3
@test tbdat.lattice ==
[0.0 2.715265 2.715265; 2.715265 0.0 2.715265; 2.715265 2.715265 0.0]
@test length(tbdat.r_x) == length(tbdat.r_y) == length(tbdat.r_z) == 279
r_x1 = ComplexF64[
3.6338163e-8+5.0525602e-8im -4.0150663e-5+1.506446e-8im 9.0607115e-5-5.4813038e-8im -0.0017405343-1.1882662e-8im
0.0011077989+2.2693247e-8im -6.4595459e-9+5.4150924e-9im 0.00025422758-1.6273951e-8im 0.0011078169+2.8407141e-8im
0.00012821382-2.969072e-8im 0.00013798637-2.1224108e-9im 5.4586044e-8+2.3435702e-8im 0.00012827449+8.9856419e-9im
-0.0017405579-4.523964e-8im -4.007513e-5+3.8697593e-8im 9.0627952e-5+5.942338e-8im -1.6888038e-8+2.5373747e-9im
]
r_y2 = ComplexF64[
-2.5598094e-10-3.8026624e-9im 0.00074239939-1.8853816e-8im -0.00017865222+3.344151e-8im 0.00017582479+1.5301678e-8im
0.00023456283+1.0709899e-8im -3.2666715e-8+4.7958915e-9im 0.00021987434-1.973943e-9im -1.3153397e-5+9.7076299e-9im
1.319145e-5-1.4937437e-8im -0.00021977894+3.1806597e-9im -3.5269004e-8-1.3967952e-8im -0.00023454332+3.0129073e-8im
-0.00017582461+1.1143559e-8im 0.00017861969+4.0119904e-8im -0.00074232978-1.8613896e-8im -2.2552721e-8-4.7774167e-9im
]
r_z3 = ComplexF64[
-2.7538102e-8-2.5754529e-9im 0.00017582603-4.8125766e-8im 0.00074233622-6.6380593e-9im -0.00017862626+1.7228737e-8im
-0.00017585023-1.101898e-8im 6.7641871e-10-2.4185959e-8im 0.00017860646+3.7820915e-8im -0.00074235898-3.711759e-8im
0.00023460039-2.0712049e-8im -1.318695e-5-4.598068e-9im 9.1295798e-9+4.1513854e-11im 0.00021978738+2.8018558e-8im
1.3196588e-5+3.6553635e-9im -0.00023460902+3.2222708e-8im -0.00021979792-1.031378e-8im -3.1967074e-8-2.3895402e-8im
]
@test tbdat.r_x[1] ≈ r_x1
@test tbdat.r_y[2] ≈ r_y2
@test tbdat.r_z[3] ≈ r_z3
end
@testitem "read tb MDRS" begin
using LazyArtifacts
# The two files are identical
tbdat = read_w90_tbdat(artifact"Si2_valence/reference/MDRS/Si2_valence_tb.dat")
tbdat_ws = read_w90_tbdat(artifact"Si2_valence/reference/WS/Si2_valence_tb.dat")
for p in propertynames(tbdat)
p == :header && continue
@test tbdat_ws[p] ≈ tbdat[p]
end
end
@testitem "write tb WS" begin
using LazyArtifacts
tbdat = read_w90_tbdat(artifact"Si2_valence/reference/WS/Si2_valence_tb.dat")
tmpfile = tempname(; cleanup=true)
write_w90_tbdat(tmpfile; tbdat...)
tbdat2 = read_w90_tbdat(tmpfile)
@test keys(tbdat) == keys(tbdat2)
for (k, v) in pairs(tbdat)
k == :header && continue
@test tbdat2[k] == v
end
end
@testitem "write tb MDRS" begin
using LazyArtifacts
tbdat = read_w90_tbdat(artifact"Si2_valence/reference/MDRS/Si2_valence_tb.dat")
tmpfile = tempname(; cleanup=true)
write_w90_tbdat(tmpfile; tbdat...)
tbdat2 = read_w90_tbdat(tmpfile)
@test keys(tbdat) == keys(tbdat2)
for (k, v) in pairs(tbdat)
k == :header && continue
@test tbdat2[k] == v
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1331 | @testitem "read/write uHu" begin
using LazyArtifacts
uHu = read_uHu(artifact"Fe_soc/test/Fe.uHu.fmt")
ref_uHu_end = ComplexF64[
22.832600673-6.6071280391e-16im 0.00020289010265+0.00033152537834im 0.00015694794962+0.00019375661933im -0.011251642778-0.09153385574im
0.00020289010265-0.00033152537835im 26.088879829-6.3490879221e-16im -1.0614925817+0.14032143069im -0.0063702801404-0.0029107828891im
0.00015694794962-0.00019375661933im -1.0614925817-0.14032143069im 24.575166569-1.0842021725e-19im -0.0036277162277-0.0022592847918im
-0.011251642778+0.09153385574im -0.0063702801404+0.0029107828891im -0.0036277162277+0.0022592847918im 28.464375953-1.1301723446e-15im
]
@test length(uHu) == 8
@test size(uHu[1]) == (12, 12)
@test size(uHu[1][1, 1]) == (4, 4)
@test uHu[end][end, end][1:4, 1:4] ≈ ref_uHu_end
tmpfile = tempname(; cleanup=true)
write_uHu(tmpfile, uHu; binary=false)
uHu1 = read_uHu(tmpfile)
@test uHu ≈ uHu1
end
@testitem "read/write uHu binary" begin
using LazyArtifacts
uHu = read_uHu(artifact"Fe_soc/test/Fe.uHu")
uHu1 = read_uHu(artifact"Fe_soc/test/Fe.uHu.fmt")
@test uHu ≈ uHu1
tmpfile = tempname(; cleanup=true)
write_uHu(tmpfile, uHu; binary=true)
uHu2 = read_uHu(tmpfile)
@test uHu ≈ uHu2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1080 | @testitem "read/write u.mat" begin
using LazyArtifacts
chk = read_chk(artifact"Si2/reference/Si2.chk.fmt")
Udismat = WannierIO.read_u_mat(artifact"Si2/reference/Si2_u.mat")
@assert Udismat.U ≈ chk.Uml
@assert Udismat.kpoints ≈ chk.kpoints
tmpfile = tempname(; cleanup=true)
WannierIO.write_u_mat(tmpfile, chk.Uml, chk.kpoints)
Udismat2 = WannierIO.read_u_mat(tmpfile)
@assert Udismat2.U ≈ chk.Uml
@assert Udismat2.kpoints ≈ chk.kpoints
end
@testitem "read/write u_dis.mat" begin
using LazyArtifacts
chk = read_chk(artifact"Si2/reference/Si2.chk.fmt")
Udismat = WannierIO.read_u_mat(artifact"Si2/reference/Si2_u_dis.mat")
# do not use `get_Udis` since it sorts the band indices, here we want to
# compare the raw data
@assert Udismat.U ≈ chk.Udis
@assert Udismat.kpoints ≈ chk.kpoints
tmpfile = tempname(; cleanup=true)
WannierIO.write_u_mat(tmpfile, chk.Udis, chk.kpoints)
Udismat2 = WannierIO.read_u_mat(tmpfile)
@assert Udismat2.U ≈ chk.Udis
@assert Udismat2.kpoints ≈ chk.kpoints
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 912 |
@testitem "read/write unk" begin
using LazyArtifacts
ik, ψ = read_unk(artifact"Si2_valence/UNK/UNK00001.1")
@test ik == 1
@test size(ψ) == (13, 13, 13, 4, 1)
ref_ψ234 = ComplexF64[
-0.82739368086-1.2362766865im; -1.1707908501+0.11631095198im; -0.25943725378+2.3452525646im; 1.090429898-1.8525861633im;;
]
@test ψ[2, 3, 4, :, :] == ref_ψ234
tmpfile = tempname(; cleanup=true)
write_unk(tmpfile, ik, ψ)
ik2, ψ2 = read_unk(tmpfile)
@test ik ≈ ik2
@test ψ ≈ ψ2
end
@testitem "read/write unk binary" begin
using LazyArtifacts
ik, ψ = read_unk(artifact"Si2_valence/UNK/UNK00001.1")
ik1, ψ1 = read_unk(artifact"Si2_valence/reference/binary/UNK00001.1")
@test ik == ik1
@test ψ ≈ ψ1
tmpfile = tempname(; cleanup=true)
write_unk(tmpfile, ik, ψ; binary=true)
ik2, ψ2 = read_unk(tmpfile)
@test ik == ik2
@test ψ ≈ ψ2
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 1998 | @testitem "read win" begin
using LazyArtifacts
win = read_win(artifact"Si2_valence/Si2_valence.win")
# how to generate reference data:
WRITE_TOML = false
WRITE_TOML && write_win("/tmp/Si2_valence.win.toml"; toml=true, win...)
test_data = read_win(artifact"Si2_valence/reference/Si2_valence.win.toml")
@test win == test_data
end
@testitem "read/write win" begin
using LazyArtifacts
win = read_win(artifact"Si2_valence/Si2_valence.win")
tmpfile = tempname(; cleanup=true)
write_win(tmpfile; win...)
win2 = read_win(tmpfile)
@test win == win2
end
@testitem "read/write win toml" begin
using LazyArtifacts
toml_path = artifact"Si2_valence/reference/Si2_valence.win.toml"
win = read_win(toml_path)
tmpfile = tempname(; cleanup=true)
write_win(tmpfile; win...)
win2 = read_win(tmpfile)
@test win == win2
end
@testitem "read win: special cases" begin
windir = joinpath(@__DIR__, "win_testfiles")
for win in readdir(windir)
if endswith(win, ".win")
# If it doesn't throw exceptions, it's good enough
@test read_win(joinpath(windir, win)) isa NamedTuple
end
end
end
@testitem "read win: unknown blocks" begin
windir = joinpath(@__DIR__, "win_testfiles")
win = read_win(joinpath(windir, "unknown_blocks.win"))
@test win.unknown_a == ["A1", "A2"]
@test win.unknown_b == ["B1 B2"]
end
@testitem "read win: atoms_cart bohr" begin
windir = joinpath(@__DIR__, "win_testfiles")
ref_win = read_win(joinpath(windir, "unknown_blocks.win"))
win = read_win(joinpath(windir, "atoms_cart_bohr.win"))
for ((atom1, pos1), (atom2, pos2)) in zip(win.atoms_frac, ref_win.atoms_frac)
@test atom1 == atom2
@test pos1 ≈ pos2
end
end
@testitem "read win: exclude_bands" begin
windir = joinpath(@__DIR__, "win_testfiles")
win = read_win(joinpath(windir, "exclude_bands.win"))
@test win.exclude_bands == [1, 3, 4, 5, 6]
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 3618 | @testitem "read wout" begin
using WannierIO: Vec3
using LazyArtifacts
wout = read_wout(artifact"Si2_valence/reference/Si2_valence.wout")
ref_lattice = [
0.000000 2.715265 2.715265
2.715265 0.000000 2.715265
2.715265 2.715265 0.000000
]
ref_atom_labels = ["Si", "Si"]
ref_atom_positions = Vec3[[0.00000, 0.00000, 0.00000], [0.25000, 0.25000, 0.25000]]
ref_centers = Vec3[
[0.678816, -0.678816, -0.678816],
[-0.678816, -0.678816, 0.678816],
[-0.678816, 0.678816, -0.678816],
[0.678816, 0.678816, 0.678816],
]
ref_spreads = [1.92917892, 1.92917900, 1.92917883, 1.92917887]
@test wout.lattice ≈ ref_lattice
@test wout.atom_labels == ref_atom_labels
@test wout.atom_positions ≈ ref_atom_positions
@test wout.centers ≈ ref_centers
@test wout.spreads ≈ ref_spreads
ref_ΩI = 7.153329184
ref_ΩD = 0.000000000
ref_ΩOD = 0.563386215
ref_Ωtotal = 7.716715399
@test wout.ΩI ≈ ref_ΩI
@test wout.ΩD ≈ ref_ΩD
@test wout.ΩOD ≈ ref_ΩOD
@test wout.Ωtotal ≈ ref_Ωtotal
end
# test for non-symmetric lattice, with disentanglement
@testitem "read wout disentanglement" begin
using LazyArtifacts
wout = read_wout(artifact"Fe_soc/reference/Fe.wout")
ref_lattice = [
1.434996 -1.434996 -1.434996
1.434996 1.434996 -1.434996
1.434996 1.434996 1.434996
]
ref_recip_lattice = [
2.189269 -2.189269 0.0
0.0 2.189269 -2.189269
2.189269 0.0 2.189269
]
ref_atom_labels = ["Fe"]
ref_atom_positions = [[0.00000, 0.00000, 0.00000]]
ref_centers = [
[-0.001227, 0.761822, -1.210363],
[-0.001132, 0.761153, 1.211403],
[1.43403, 0.674118, -0.223106],
[-1.436981, -0.000412, 0.95882],
[-0.002088, -1.435412, 0.479468],
[-0.001066, -0.761483, -1.210896],
[0.00033, -0.000261, 0.000357],
[8.5e-5, -0.019916, -0.01021],
[-0.000258, -0.000766, 0.000475],
[6.7e-5, -0.00072, -0.001011],
[8.2e-5, 0.020905, 0.010305],
[4.5e-5, 0.019902, -0.010005],
[-0.000815, 0.00031, -0.000449],
[0.000117, -0.020922, 0.010472],
[-0.000259, 0.000986, 0.001254],
[5.5e-5, 0.000493, -0.00047],
]
ref_spreads = [
1.11313978,
1.11389149,
1.11392684,
1.14257541,
1.14112348,
1.11318311,
0.40981481,
0.44675647,
0.48652472,
0.44072505,
0.45362382,
0.44649383,
0.4400766,
0.45389206,
0.48648695,
0.44062982,
]
@test wout.lattice ≈ ref_lattice
@test wout.recip_lattice ≈ ref_recip_lattice
@test wout.atom_labels == ref_atom_labels
@test wout.atom_positions ≈ ref_atom_positions
@test wout.centers ≈ ref_centers
@test wout.spreads ≈ ref_spreads
ref_ΩI = 10.219635550
ref_ΩD = 0.055212384
ref_ΩOD = 0.968016319
ref_Ωtotal = 11.242864254
@test wout.ΩI ≈ ref_ΩI
@test wout.ΩD ≈ ref_ΩD
@test wout.ΩOD ≈ ref_ΩOD
@test wout.Ωtotal ≈ ref_Ωtotal
end
@testitem "read wout fortran stars" begin
woutdir = joinpath(@__DIR__, "wout_testfiles")
wout = read_wout(joinpath(woutdir, "stars.wout"))
ref_centers = [
[-0.866253, 1.973841, 1.973841],
[-0.866253, 0.866253, 0.866253],
[-99.973841, 1.973841, 0.866253],
[NaN, 0.866253, 1.973841],
]
@test wout.centers[1:3] ≈ ref_centers[1:3]
@test isnan(wout.centers[end][1])
@test wout.centers[end][2:end] ≈ ref_centers[end][2:end]
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | code | 2024 | @testitem "read wsvec WS" begin
using LazyArtifacts
wsvec = read_w90_wsvec(artifact"Si2_valence/reference/WS/Si2_valence_wsvec.dat")
@assert wsvec.mdrs == false
@test length(wsvec.Rvectors) == 279
@test wsvec.Rvectors[1] == [-4, 0, 2]
@test wsvec.n_wann == 4
end
@testitem "read wsvec MDRS" begin
using WannierIO: Vec3
using LazyArtifacts
wsvec = read_w90_wsvec(artifact"Si2_valence/reference/MDRS/Si2_valence_wsvec.dat")
@assert wsvec.mdrs == true
@test length(wsvec.Rvectors) == 279
@test wsvec.Rvectors[1] == [-4, 0, 2]
@test length(wsvec.Tvectors) == 279
@test wsvec.Tvectors[1][1, 1] == Vector{Vec3}([[0, 0, 0], [6, 0, -6], [6, 0, 0]])
@test length(wsvec.Tdegens) == 279
@test wsvec.Tdegens[1] == [3 1 1 1; 1 3 1 1; 2 2 3 2; 1 1 1 3]
@test wsvec.n_wann == 4
end
@testitem "write wsvec WS" begin
using LazyArtifacts
wsvec = read_w90_wsvec(artifact"Si2_valence/reference/WS/Si2_valence_wsvec.dat")
tmpfile = tempname(; cleanup=true)
write_w90_wsvec(tmpfile; wsvec.Rvectors, wsvec.n_wann)
wsvec2 = read_w90_wsvec(tmpfile)
@test keys(wsvec) == keys(wsvec2)
for (k, v) in pairs(wsvec)
k == :header && continue
@test wsvec2[k] == v
end
end
@testitem "write wsvec MDRS" begin
using WannierIO: Vec3
using LazyArtifacts
wsvec = read_w90_wsvec(artifact"Si2_valence/reference/MDRS/Si2_valence_wsvec.dat")
tmpfile = tempname(; cleanup=true)
write_w90_wsvec(tmpfile; wsvec.Rvectors, wsvec.Tvectors, wsvec.Tdegens)
wsvec2 = read_w90_wsvec(tmpfile)
@test keys(wsvec) == keys(wsvec2)
for (k, v) in pairs(wsvec)
k == :header && continue
@test wsvec2[k] == v
end
# n_wann is optional
write_w90_wsvec(tmpfile; wsvec.Rvectors, wsvec.Tvectors, wsvec.Tdegens, wsvec.n_wann)
wsvec2 = read_w90_wsvec(tmpfile)
@test keys(wsvec) == keys(wsvec2)
for (k, v) in pairs(wsvec)
k == :header && continue
@test wsvec2[k] == v
end
end
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 1078 | # WannierIO.jl
[](https://io.wannierjl.org/stable)
[](https://io.wannierjl.org/dev)
[](https://github.com/qiaojunfeng/WannierIO.jl/actions?query=workflow%3ACI)
[](https://codecov.io/gh/qiaojunfeng/WannierIO.jl)
A Julia package for reading/writing [Wannier90](https://github.com/wannier-developers/wannier90)
file formats.
The package is designed to be minimalistic to allow easy reuse in other packages.
## Quick examples
```julia
using WannierIO
A = read_amn("silicon.amn")
write_amn("silicon_2.amn", A)
chk = read_chk("silicon.chk")
write_chk("silicon_2.chk", chk; binary=true)
```
## Related packages
- [Wannier.jl](https://github.com/qiaojunfeng/Wannier.jl): Wannierization and Wannier interpolation.
The IO part of `Wannier.jl` was isolated and moved into this package.
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 157 | # Documentation
## Writing
The documentation is written in Markdown, then processed by `Documenter.jl`.
## Build
See [`make_serve.sh`](./make_serve.sh).
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 933 | # WannierIO.jl
A Julia package for reading/writing [Wannier90](https://github.com/wannier-developers/wannier90) files.
The package is designed to be minimalistic to allow easy reuse in other packages.
This package originates from the IO part of the
[Wannier.jl](https://github.com/qiaojunfeng/Wannier.jl) package.
## Wannier90 files
Input files:
- `amn`
- `mmn`
- `eig`
- `chk`
- `UNK`
- `spn`
Also support parsing both plain text and binary formats (in Fortran language,
called `formatted` and `unformatted` IO, respectively) for some files, e.g.,
`chk` and `UNK`.
Output files:
- `*_band.dat`
- `*_tb.dat`
- `*_wsvec.dat`
- `*_hr.dat`
- `*_r.dat`
- `xsf`
- `cube`
- ...
## Quantum ESPRESSO files
To support comparing Wannier-interpolated band structures with density function
theory (DFT) bands, there are also some functions to parse Quantum ESPRESSO (QE)
output files:
- `xml`
- `bands.dat` generated by QE `bands.x`
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 4985 | # Conventions
## Units
In most cases, the units of the function arguments and returned values are in
angstrom for lattice, and fractional (w.r.t. lattice) for atomic positions, etc.
## Variables
Here are some variable conventions used throughout the code and documentation.
### Names
- `U`: unitary transformation matrices
- `A`: to differentiate between `U`, some times we use `A` specifically for
the initial projection matrix, i.e., `amn` of Wannier90
- `M`: overlap matrices between neighboring kpoints, i.e., `mmn` of Wannier90
### Dimensions
Prefixed by `n_`, indicating this is an integer specifying the length of
some quantities; then followed by a short acronym of the quantity, to avoid
typing long names repeatedly.
- `n_bands`: number of bands
- `n_wann`: number of WFs
- `n_kpts`: number of kpoints
- `n_bvecs`: number of b-vectors
- `n_atoms`: number of atoms
### Indices
Usually, the returned quantities are `Vector`s of some types (`Matrix{Float64}`,
`Vector{Float64}`, etc), and the indices follow the order of
1. kpoints
2. b-vectors (if needed)
3. bands
4. Wannier functions
For instance, the energy eigenvalues `eigenvalues` is a length-`n_kpts` vector,
with each element a length-`n_bands` vector of floats, i.e., `eigenvalues[ik][ib]`
is the `ib`-th eigenvalue at `ik`-th kpoint.
Here are some examples of indexing the vectors:
- `eigenvalues[ik][m]` for energy eigenvalues ``\varepsilon_{m \mathbf{k}}``
- `U[ik][m, n]` for the gauge matrix ``U_{mn \mathbf{k}}``
- `M[ik][ib][m, n]` for the overlap matrix ``M_{mn \mathbf{k}, \mathbf{k} + \mathbf{b}}``
where
- `ik`: index of kpoints
- `ib`: index of b-vectors
- `m`: index of bands
- `n`: index of Wannier functions
## Functions
In most cases, there are some multiple dispatches for the same function.
For instance, there are three functions for reading the `chk` file:
```julia
read_chk(filename::AbstractString)
read_chk(filename::AbstractString, ::FortranText)
read_chk(filename::AbstractString, ::FortranBinary)
```
Why do we need several functions for reading the same format? The reasons are:
- Wannier90 is a Fortran code that accepts both Fortran text format and binary
format (or called Fortran formatted and unformatted file, respectively).
To avoid introducing lots of different function names for reading text or
binary files, we use multiple dispatch to distinguish them: the type of the
2nd argument (`FortranText` or `FortranBinary`) is used to distinguish the
file type we want to read.
- However, asking the user to manually specify the file format is tedious,
therefore, we provide a high-level user-friendly function (the 1st one), which
- automatically detects the file format and calls the corresponding low-level
(2nd or 3rd) function
- prints some information of key quantities of the file, e.g., number of
kpoints, number of Wannier functions, etc., to give user a hint of what
have been parsed
- hides some irrelevant return values, e.g., the header (the 1st line) of the
file, since it has been printed in the stdout
- The low-level functions parse everything in the file, while the high-level
function aims at user ergonomics.
Thus,
- In most cases using the high-level function is enough, e.g.,
```julia-repl
julia> using WannierIO
julia> A = read_amn("si2.amn")
┌ Info: Reading amn file
│ filename = "si2.amn"
│ header = "Created on 9Sep2022 at 16:41: 5"
│ n_kpts = 8
│ n_bands = 4
└ n_wann = 4
8-element Vector{Matrix{ComplexF64}}:
[...]
```
- Use the low-level functions if you
- want to get the header of the file (or quantities not returned by high-level function)
- do not want stdout to be "polluted"
```julia-repl
julia> using WannierIO
julia> A, header = read_amn("si2.amn", WannierIO.FortranText())
julia> typeof(A)
Vector{Matrix{ComplexF64}} (alias for Array{Array{Complex{Float64}, 2}, 1})
julia> header
"Created on 9Sep2022 at 16:41: 5"
```
Note that usually the high-level function directly returns the quantities, e.g.,
a single `A` to avoid the user unpacking return values; however, often the low-level
functions return a `NamedTuple` of all the quantities, for the sake of clarity.
```julia-repl
julia> amn = read_amn("si2.amn", WannierIO.FortranText())
julia> typeof(amn)
NamedTuple{(:A, :header), Tuple{Vector{Matrix{ComplexF64}}, SubString{String}}}
```
Of course, when using low-level functions you can also directly access the
quantity without unpacking by
```julia-repl
julia> A = read_amn("si2.amn", WannierIO.FortranText()).A
```
When writing files, the user can specify whether to write in text or binary by
a keyword argument `binary` of the high-level function
```julia-repl
julia> write_amn("si2.amn", A; binary=true)
```
The `binary` keyword argument avoids the user specifying the file type
when calling the low-level functions, e.g.,
```julia-repl
julia> write_amn("si2.amn", A, WannierIO.FortranBinaryStream())
```
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 125 | # EPW files
```@meta
CurrentModule = WannierIO
```
```@autodocs
Modules = [WannierIO]
Pages = [
"misc/epw.jl",
]
```
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 72 | # Index of all functions and types
```@index
Modules = [WannierIO]
```
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 154 | # Quantum ESPRESSO files
```@meta
CurrentModule = WannierIO
```
```@autodocs
Modules = [WannierIO]
Pages = [
"qe/band.jl",
"qe/xml.jl",
]
```
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 584 | # Utility
Some simple convenience functions for development.
```@meta
CurrentModule = WannierIO
```
## Fortran related
```@autodocs
Modules = [WannierIO]
Pages = ["util/fortran.jl"]
```
## Lattice
```@autodocs
Modules = [WannierIO]
Pages = ["util/lattice.jl"]
```
## Types
```@autodocs
Modules = [WannierIO]
Pages = ["common/type.jl"]
```
## Constants
```@autodocs
Modules = [WannierIO]
Pages = ["common/const.jl"]
```
## Misc
```@autodocs
Modules = [WannierIO]
Pages = ["util/header.jl", "util/toml.jl", "util/parser.jl", "util/compare.jl", "WannierIO.jl"]
```
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 198 | # Volumetric data files
```@meta
CurrentModule = WannierIO
```
## Read/write
```@autodocs
Modules = [WannierIO]
Pages = [
"volume/xsf.jl",
"volume/bxsf.jl",
"volume/cube.jl",
]
```
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.2.6 | 3675a287430806f9b48d341eb0abf44e3074d1fa | docs | 987 | # Wannier90 files
```@meta
CurrentModule = WannierIO
```
!!! warning
Some of the functions, e.g. [`read_amn`](@ref), [`write_amn`](@ref),
[`read_chk`](@ref), [`write_chk`](@ref), etc., support reading/writing
Fortran unformatted files. However, the Fortran unformatted files are
machine and compiler dependent. Therefore, it is not guaranteed that
these functions work for all the cases.
Currently, the functions are tested on the following platforms:
- Linux + gfortran 11.2
## Public API
```@autodocs
Modules = [WannierIO]
Private = false
Pages = map(file -> joinpath("w90", file), readdir("../src/w90"))
```
## Private API
These are some lower-level types/functions that are (probably) less used, thus not exported.
Of course, you can still use them by prefixing `WannierIO.`, e.g.,
`WannierIO.read_w90_band_dat(filename)`.
```@autodocs
Modules = [WannierIO]
Public = false
Pages = map(file -> joinpath("w90", file), readdir("../src/w90"))
```
| WannierIO | https://github.com/qiaojunfeng/WannierIO.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3036 | module PFFRGSolver
# load external modules
using LinearAlgebra
using StaticArrays
using HDF5
using QuadGK
using Cubature
using LoopVectorization
using Dates
using Test
using TimerOutputs
# load source code
include("Lattice/Lattice.jl")
include("Frequency/Frequency.jl")
include("Action/Action.jl")
include("Flow/Flow.jl")
include("Observable/Observable.jl")
include("Launcher/Launcher.jl")
include("Timers/Timers.jl")
# export types, structs and functions
export
# from Lattice/unitcell.jl
Unitcell,
lattice_avail,
get_unitcell,
# from Lattice/site.jl
Site,
get_metric,
get_nbs,
# from Lattice/bond.jl
Bond,
# from Lattice/build.jl
Lattice,
get_lattice,
model_avail,
init_model!,
get_site,
get_bond,
# from Lattice/reduced.jl
Reduced_lattice,
get_trafos_orig,
get_trafos_uc,
get_reduced_lattice,
# from Lattice/disk.jl
read_lattice,
# from Lattice/test.jl
test_lattice,
# from Lattice/timers.jl
get_lattice_timers,
# from Frequency/param.jl
Param,
get_param,
# from Frequency/mesh.jl
Mesh,
get_mesh,
# from Frequency/buffer.jl
Buffer,
# from Frequency/test.jl
test_frequencies,
# from Frequency/timers.jl
get_frequency_timers,
# from Action/channel.jl
Channel,
get_abs_max,
# from Action/vertex.jl
Vertex,
# from Action/Action.jl
Action,
Action_su2,
Action_u1_dm,
read_checkpoint,
# from Action/disk.jl
read_self,
# from Action/test.jl
test_action,
# from Action/timers.jl
get_action_timers,
# from Flow/test.jl
test_flow,
# from Flow/timers.jl
get_flow_timers,
# from Observable/momentum.jl
get_momenta,
get_path,
compute_structure_factor,
# from Observable/disk.jl
read_χ_labels,
read_χ,
read_χ_all,
read_χ_flow_at_site,
compute_structure_factor_flow!,
compute_structure_factor_flow_all!,
read_structure_factor_labels,
read_structure_factor,
read_structure_factor_all,
read_structure_factor_flow_at_momentum,
read_reference_momentum,
# from Observable/fluctuations.jl
compute_fluctuations,
compute_fluctuations_flow,
# from Observable/test.jl
test_observable,
# from Observable/timers.jl
get_observable_timers,
# from Launcher/Launcher.jl
save_launcher!,
make_job!,
make_repository!,
collect_repository!,
launch!,
# from Timers/Timers.jl
get_PFFRG_timers
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 16138 | # load code
include("channel.jl")
include("vertex.jl")
abstract type Action end
# get interpolated / extrapolated self energy for general action
function get_Σ(
w :: Float64,
m :: Mesh,
a :: Action
) :: Float64
# init value
val = 0.0
# check if in bounds, otherwise extrapolate as 1 / w
if abs(w) <= m.σ[end]
p = get_param(abs(w), m.σ)
val = sign(w) * (p.lower_weight * a.Σ[p.lower_index] + p.upper_weight * a.Σ[p.upper_index])
else
val = m.σ[end] * a.Σ[end] / w
end
return val
end
# get interpolated vertex component for general action
function get_Γ_comp(
comp :: Int64,
site :: Int64,
bs :: Buffer,
bt :: Buffer,
bu :: Buffer,
r :: Reduced_lattice,
a :: Action,
apply_flags :: Function
;
ch_s :: Bool = true,
ch_t :: Bool = true,
ch_u :: Bool = true
) :: Float64
# init with bare value
val = a.Γ[comp].bare[site]
# add s channel
if ch_s
# check for site exchange
site_s = site
if bs.exchange_flag
site_s = r.exchange[site_s]
end
# apply other flags
comp_s = comp
sgn_s, comp_s = apply_flags(bs, comp_s)
# check for mapping to u channel and interpolate
if bs.map_flag
val += sgn_s * get_vertex(site_s, bs, a.Γ[comp_s], 3)
else
val += sgn_s * get_vertex(site_s, bs, a.Γ[comp_s], 1)
end
end
# add t channel
if ch_t
# check for site exchange
site_t = site
if bt.exchange_flag
site_t = r.exchange[site_t]
end
# apply other flags
comp_t = comp
sgn_t, comp_t = apply_flags(bt, comp_t)
# interpolate
val += sgn_t * get_vertex(site_t, bt, a.Γ[comp_t], 2)
end
# add u channel
if ch_u
# check for site exchange
site_u = site
if bu.exchange_flag
site_u = r.exchange[site_u]
end
# apply other flags
comp_u = comp
sgn_u, comp_u = apply_flags(bu, comp_u)
# check for mapping to s channel and interpolate
if bu.map_flag
val += sgn_u * get_vertex(site_u, bu, a.Γ[comp_u], 1)
else
val += sgn_u * get_vertex(site_u, bu, a.Γ[comp_u], 3)
end
end
return val
end
# get interpolated vertex component on all lattice sites
function get_Γ_comp_avx!(
comp :: Int64,
r :: Reduced_lattice,
bs :: Buffer,
bt :: Buffer,
bu :: Buffer,
a :: Action,
apply_flags :: Function,
temp :: SubArray{Float64, 1, Array{Float64, 3}}
;
ch_s :: Bool = true,
ch_t :: Bool = true,
ch_u :: Bool = true
) :: Nothing
# init with bare value
@turbo temp .= a.Γ[comp].bare
# add s channel
if ch_s
# apply flags
comp_s = comp
sgn_s, comp_s = apply_flags(bs, comp_s)
# check for mapping to u channel and interpolate
if bs.map_flag
get_vertex_avx!(r, bs, a.Γ[comp_s], 3, temp, bs.exchange_flag, sgn_s)
else
get_vertex_avx!(r, bs, a.Γ[comp_s], 1, temp, bs.exchange_flag, sgn_s)
end
end
# add t channel
if ch_t
# apply flags
comp_t = comp
sgn_t, comp_t = apply_flags(bt, comp_t)
# interpolate
get_vertex_avx!(r, bt, a.Γ[comp_t], 2, temp, bt.exchange_flag, sgn_t)
end
# add u channel
if ch_u
# apply flags
comp_u = comp
sgn_u, comp_u = apply_flags(bu, comp_u)
# check for mapping to s channel and interpolate
if bu.map_flag
get_vertex_avx!(r, bu, a.Γ[comp_u], 1, temp, bu.exchange_flag, sgn_u)
else
get_vertex_avx!(r, bu, a.Γ[comp_u], 3, temp, bu.exchange_flag, sgn_u)
end
end
return nothing
end
# load saving and reading for channels and vertices
include("disk.jl")
# load specialized code for different symmetries
include("action_lib/action_su2.jl") ; include("checkpoint_lib/checkpoint_su2.jl")
include("action_lib/action_u1_dm.jl"); include("checkpoint_lib/checkpoint_u1_dm.jl")
# interface function to replace action with another action (except for bare)
function replace_with!(
a1 :: Action,
a2 :: Action
) :: Nothing
# replace self energy
@turbo a1.Σ .= a2.Σ
# replace vertices
for i in eachindex(a1.Γ)
replace_with!(a1.Γ[i], a2.Γ[i])
end
return nothing
end
# interface function to replace action with another action only on the vertex level (except for bare)
function replace_with_Γ!(
a1 :: Action,
a2 :: Action
) :: Nothing
# replace vertices
for i in eachindex(a1.Γ)
replace_with!(a1.Γ[i], a2.Γ[i])
end
return nothing
end
# interface function to multiply action with factor (except for bare)
function mult_with!(
a :: Action,
fac :: Float64
) :: Nothing
# multiply self energy
@turbo a.Σ .*= fac
# multiply vertices
for i in eachindex(a.Γ)
mult_with!(a.Γ[i], fac)
end
return nothing
end
# interface function to multiply action with factor only on the vertex level (except for bare)
function mult_with_Γ!(
a :: Action,
fac :: Float64
) :: Nothing
# multiply vertices
for i in eachindex(a.Γ)
mult_with!(a.Γ[i], fac)
end
return nothing
end
# interface function to reset an action to zero (except for bare)
function reset!(
a :: Action
) :: Nothing
mult_with!(a, 0.0)
return nothing
end
# interface function to reset an action to zero only on the vertex level (except for bare)
function reset_Γ!(
a :: Action
) :: Nothing
mult_with_Γ!(a, 0.0)
return nothing
end
# interface function to multiply action with some factor and add to other action (except for bare)
function mult_with_add_to!(
a2 :: Action,
fac :: Float64,
a1 :: Action
) :: Nothing
# multiply add for the self energy
@turbo a1.Σ .+= fac .* a2.Σ
# multiply add for the vertices
for i in eachindex(a1.Γ)
mult_with_add_to!(a2.Γ[i], fac, a1.Γ[i])
end
return nothing
end
# interface function to multiply action with some factor and add to other action only on the vertex level (except for bare)
function mult_with_add_to_Γ!(
a2 :: Action,
fac :: Float64,
a1 :: Action
) :: Nothing
# multiply add for the vertices
for i in eachindex(a1.Γ)
mult_with_add_to!(a2.Γ[i], fac, a1.Γ[i])
end
return nothing
end
# interface function to add two actions (except for bare)
function add_to!(
a2 :: Action,
a1 :: Action
) :: Nothing
mult_with_add_to!(a2, 1.0, a1)
return nothing
end
# interface function to add two actions only on the vertex level (except for bare)
function add_to_Γ!(
a2 :: Action,
a1 :: Action
) :: Nothing
mult_with_add_to_Γ!(a2, 1.0, a1)
return nothing
end
# interface function to subtract two actions (except for bare)
function subtract_from!(
a2 :: Action,
a1 :: Action
) :: Nothing
mult_with_add_to!(a2, -1.0, a1)
return nothing
end
# interface function to subtract two actions only on the vertex level (except for bare)
function subtract_from_Γ!(
a2 :: Action,
a1 :: Action
) :: Nothing
mult_with_add_to_Γ!(a2, -1.0, a1)
return nothing
end
"""
get_abs_max(
a :: Action
) :: Float64
Returns maximum absolute value of an action across all vertex components.
"""
function get_abs_max(
a :: Action
) :: Float64
abs_max_Γ = zeros(Float64, length(a.Γ))
for i in eachindex(a.Γ)
abs_max_Γ[i] = get_abs_max(a.Γ[i])
end
abs_max = maximum(abs_max_Γ)
return abs_max
end
# scan cut through channel, where x is assumed to be generated by the get_mesh function with linear fraction p0
# in order to optimize the frequency mesh we use the following heuristics:
# a) the linear extent δ should be large enough to capture sharp peaks at finite frequencies, that is, δ >= 'point where channel has decayed to 10 percent of peak value'
# b) the linear extent δ should be large enough to capture sign changes at finite frequencies, that is, δ >= zero crossing
# c) the linear extent δ should be small enough to capture sharp peaks at the origin, that is, Δ should fulfill p1 < Δ < p2,
# where Δ is the relative deviation between the values at the origin and the first finite frequency
# d) the linear extent δ should be bounded to avoid overambitious shrinking or broadening of the mesh, that is, num_lin * p3 <= δ <= p4,
# where num_lin is the number of linear frequencies
function scan(
Λ :: Float64,
x :: Vector{Float64},
y :: Vector{Float64},
p0 :: Float64,
p1 :: Float64,
p2 :: Float64,
p3 :: Float64,
p4 :: Float64
) :: Float64
# determine current mesh layout
num_lin = ceil(Int64, p0 * (length(x) - 1))
# a) check for peaks at finite frequencies and set δa as 'point where channel has decayed to 10 percent of peak value'
δa = Inf
idx = argmax(abs.(y))
if idx > 1
for i in idx + 1 : length(x)
if abs(y[i] / y[idx]) <= 0.1
δa = x[i]
break
end
end
end
# b) check for sign change at finite frequencies and set δb accordingly
δb = Inf
for i in 2 : length(y)
if sign(y[i]) != sign(y[1])
δb = x[i]
break
end
end
# c) check if the value at the origin is finite. If so, set δc such that p1 < Δ < p2
δc = num_lin * x[2]
if abs(y[1]) / abs(y[idx]) > 1e-3
# compute Δ
Δ = abs(y[2] - y[1]) / max(abs(y[2]), abs(y[1]))
# adjust δc if Δ is out of required bounds
while (p1 < Δ < p2) == false
# if Δ is too large decrease δc by two percent
if Δ >= p2
δc *= 0.98
# if Δ is too small increase δc by two percent
elseif Δ <= p1
δc *= 1.02
end
# ensure δc is within required bounds
if δc < num_lin * p3
break
elseif δc > p4
break
end
# generate new reference data
xp = get_mesh(δc, x[end], length(x) - 1, p0)
yp = similar(y)
for i in eachindex(yp)
p = get_param(xp[i], x)
yp[i] = p.lower_weight * y[p.lower_index] + p.upper_weight * y[p.upper_index]
end
# recompute Δ
Δ = abs(yp[2] - yp[1]) / max(abs(yp[2]), abs(yp[1]))
end
end
# d) merge results from heuristics a), b) and c) and perform sanity checks
δ = min(max(num_lin * p3, min(δa, δb, δc)), p4)
return δ
end
# auxiliary function to scan a single channel
function scan_channel(
Λ :: Float64,
p_Ω :: NTuple{5, Float64},
p_ν :: NTuple{5, Float64},
Ω :: Vector{Float64},
ν :: Vector{Float64},
ch :: Channel
) :: NTuple{2, Float64}
# deref data
q3 = ch.q3
# determine position of the maximum
idxs = argmax(abs.(q3))
# get cuts through the maximum
q3_Ω = q3[idxs[1], :, idxs[3], idxs[4]]
q3_ν_1 = Float64[q3[idxs[1], idxs[2], x, x] - q3[idxs[1], idxs[2], end, end] for x in eachindex(ν)]
q3_ν_2 = Float64[q3[idxs[1], idxs[2], x, idxs[4]] - q3[idxs[1], idxs[2], end, idxs[4]] for x in eachindex(ν)]
q3_ν_3 = Float64[q3[idxs[1], idxs[2], idxs[3], x] - q3[idxs[1], idxs[2], idxs[3], end] for x in eachindex(ν)]
# scan bosonic cut
Ω_lin = scan(Λ, Ω, q3_Ω, p_Ω[1], p_Ω[2], p_Ω[3], p_Ω[4] * Λ, p_Ω[5] * Λ)
# scan fermionic cuts
ν_lin_1 = scan(Λ, ν, q3_ν_1, p_ν[1], p_ν[2], p_ν[3], p_ν[4] * Λ, p_ν[5] * Λ)
ν_lin_2 = scan(Λ, ν, q3_ν_2, p_ν[1], p_ν[2], p_ν[3], p_ν[4] * Λ, p_ν[5] * Λ)
ν_lin_3 = scan(Λ, ν, q3_ν_3, p_ν[1], p_ν[2], p_ν[3], p_ν[4] * Λ, p_ν[5] * Λ)
ν_lin = min(ν_lin_1, ν_lin_2, ν_lin_3)
return Ω_lin, ν_lin
end
# resample an action to new meshes via scanning and trilinear interpolation
function resample_from_to(
Λ :: Float64,
p_σ :: NTuple{2, Float64},
p_Ωs :: NTuple{5, Float64},
p_νs :: NTuple{5, Float64},
p_Ωt :: NTuple{5, Float64},
p_νt :: NTuple{5, Float64},
p_χ :: NTuple{5, Float64},
lins :: NTuple{5, Float64},
bounds :: NTuple{5, Float64},
m_old :: Mesh,
a_old :: Action,
a_new :: Action,
χ :: Vector{Matrix{Float64}}
) :: Mesh
# scale linear bounds
σ_lin = lins[2] * Λ
Ωs_lin = lins[3] * Λ
νs_lin = lins[4] * Λ
Ωt_lin = lins[3] * Λ
νt_lin = lins[4] * Λ
χ_lin = lins[5] * Λ
# adjust meshes via scanning once required scale is reached
if Λ < lins[1]
# scan self energy
σ_lin = p_σ[2] * m_old.σ[argmax(abs.(a_old.Σ))]
# scan the channels
Ωs_lins, νs_lins = zeros(Float64, length(a_old.Γ)), zeros(length(a_old.Γ))
Ωt_lins, νt_lins = zeros(Float64, length(a_old.Γ)), zeros(length(a_old.Γ))
for i in eachindex(a_old.Γ)
Ωs_lins[i], νs_lins[i] = scan_channel(Λ, p_Ωs, p_νs, m_old.Ωs, m_old.νs, a_old.Γ[i].ch_s)
Ωt_lins[i], νt_lins[i] = scan_channel(Λ, p_Ωt, p_νt, m_old.Ωt, m_old.νt, a_old.Γ[i].ch_t)
end
Ωs_lin, νs_lin = minimum(Ωs_lins), minimum(νs_lins)
Ωt_lin, νt_lin = minimum(Ωt_lins), minimum(νt_lins)
# scan the correlations
χ_lins = zeros(Float64, length(χ))
for i in eachindex(χ_lins)
χ_lins[i] = scan(Λ, m_old.χ, χ[i][argmax(abs.(χ[i]))[1], :], p_χ[1], p_χ[2], p_χ[3], p_χ[4] * Λ, p_χ[5] * Λ)
end
χ_lin = minimum(χ_lins)
end
# build new frequency meshes according to scanning results
σ = get_mesh( σ_lin, bounds[2] * max(Λ, bounds[1]), m_old.num_σ - 1, p_σ[1])
Ωs = get_mesh(Ωs_lin, bounds[3] * max(Λ, bounds[1]), m_old.num_Ω - 1, p_Ωs[1])
νs = get_mesh(νs_lin, bounds[4] * max(Λ, bounds[1]), m_old.num_ν - 1, p_νs[1])
Ωt = get_mesh(Ωt_lin, bounds[3] * max(Λ, bounds[1]), m_old.num_Ω - 1, p_Ωt[1])
νt = get_mesh(νt_lin, bounds[4] * max(Λ, bounds[1]), m_old.num_ν - 1, p_νt[1])
χ = get_mesh( χ_lin, bounds[5] * max(Λ, bounds[1]), m_old.num_χ - 1, p_χ[1])
m_new = Mesh(m_old.num_σ, m_old.num_Ω, m_old.num_ν, m_old.num_χ, σ, Ωs, νs, Ωt, νt, χ)
# resample self energy
for w in eachindex(m_new.σ)
a_new.Σ[w] = get_Σ(m_new.σ[w], m_old, a_old)
end
# resample vertices
for i in eachindex(a_new.Γ)
resample_from_to!(m_old, a_old.Γ[i], m_new, a_new.Γ[i])
end
return m_new
end
# generate action dummy
function get_action_empty(
symmetry :: String,
r :: Reduced_lattice,
m :: Mesh
;
S :: Float64 = 0.5
) :: Action
if symmetry == "su2"
return get_action_su2_empty(S, r, m)
elseif symmetry == "u1-dm"
return get_action_u1_dm_empty(r, m)
end
end
"""
read_checkpoint(
file :: HDF5.File,
Λ :: Float64
) :: Tuple{Float64, Float64, Mesh, Action}
Read checkpoint of FRG calculation from HDF5 file.
Returns cutoff Λ, ODE stepwidth dΛ, frequency meshes (wrapped in Mesh struct) and vertices (wrapped in Action struct).
"""
function read_checkpoint(
file :: HDF5.File,
Λ :: Float64
) :: Tuple{Float64, Float64, Mesh, Action}
# read symmetry group from file
symmetry = read(file, "symmetry")
if symmetry == "su2"
return read_checkpoint_su2(file, Λ)
elseif symmetry == "u1-dm"
return read_checkpoint_u1_dm(file, Λ)
end
end
# load tests and timers
include("test.jl")
include("timers.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 15086 | """
Channel
Struct containing asymptotic kernels for a channel.
* `q1 :: Matrix{Float64}` : kernel with both fermionic frequencies -> Inf
* `q2_1 :: Array{Float64, 3}` : kernel with second fermionic frequency -> Inf
* `q2_2 :: Array{Float64, 3}` : kernel with first fermionic frequency -> Inf
* `q3 :: Array{Float64, 4}` : full channel
"""
struct Channel
q1 :: Matrix{Float64}
q2_1 :: Array{Float64, 3}
q2_2 :: Array{Float64, 3}
q3 :: Array{Float64, 4}
end
# generate channel dummy
function get_channel_empty(
r :: Reduced_lattice,
m :: Mesh
) :: Channel
num_sites = length(r.sites)
# init kernels
q1 = zeros(Float64, num_sites, m.num_Ω)
q2_1 = zeros(Float64, num_sites, m.num_Ω, m.num_ν)
q2_2 = zeros(Float64, num_sites, m.num_Ω, m.num_ν)
q3 = zeros(Float64, num_sites, m.num_Ω, m.num_ν, m.num_ν)
# build channel
ch = Channel(q1, q2_1, q2_2, q3)
return ch
end
# get interpolated value of q1
function get_q1(
site :: Int64,
p :: Param,
ch :: Channel
) :: Float64
val = p.lower_weight * ch.q1[site, p.lower_index]
val += p.upper_weight * ch.q1[site, p.upper_index]
return val
end
# get interpolated value of q1 on all lattice sites
function get_q1_avx!(
r :: Reduced_lattice,
p :: Param,
ch :: Channel,
temp :: SubArray{Float64, 1, Array{Float64, 3}},
exchange :: Bool,
sgn :: Float64
) :: Nothing
# deref channel
q1 = ch.q1
# deref param
lower_index = p.lower_index
upper_index = p.upper_index
lower_weight = p.lower_weight
upper_weight = p.upper_weight
# check for site exchange
if exchange
indices = r.exchange
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight * q1[indices[i], lower_index]
val += upper_weight * q1[indices[i], upper_index]
temp[i] += sgn * val
end
else
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight * q1[i, lower_index]
val += upper_weight * q1[i, upper_index]
temp[i] += sgn * val
end
end
return nothing
end
# get interpolated value of q2_1
function get_q2_1(
site :: Int64,
p1 :: Param,
p2 :: Param,
ch :: Channel
) :: Float64
val = p1.lower_weight * p2.lower_weight * ch.q2_1[site, p1.lower_index, p2.lower_index]
val += p1.upper_weight * p2.lower_weight * ch.q2_1[site, p1.upper_index, p2.lower_index]
val += p1.lower_weight * p2.upper_weight * ch.q2_1[site, p1.lower_index, p2.upper_index]
val += p1.upper_weight * p2.upper_weight * ch.q2_1[site, p1.upper_index, p2.upper_index]
return val
end
# get interpolated value of q2_1 on all lattice sites
function get_q2_1_avx!(
r :: Reduced_lattice,
p1 :: Param,
p2 :: Param,
ch :: Channel,
temp :: SubArray{Float64, 1, Array{Float64, 3}},
exchange :: Bool,
sgn :: Float64
) :: Nothing
# deref channel
q2_1 = ch.q2_1
# deref param
lower_index1 = p1.lower_index
upper_index1 = p1.upper_index
lower_weight1 = p1.lower_weight
upper_weight1 = p1.upper_weight
lower_index2 = p2.lower_index
upper_index2 = p2.upper_index
lower_weight2 = p2.lower_weight
upper_weight2 = p2.upper_weight
# check for site exchange
if exchange
indices = r.exchange
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight1 * lower_weight2 * q2_1[indices[i], lower_index1, lower_index2]
val += upper_weight1 * lower_weight2 * q2_1[indices[i], upper_index1, lower_index2]
val += lower_weight1 * upper_weight2 * q2_1[indices[i], lower_index1, upper_index2]
val += upper_weight1 * upper_weight2 * q2_1[indices[i], upper_index1, upper_index2]
temp[i] += sgn * val
end
else
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight1 * lower_weight2 * q2_1[i, lower_index1, lower_index2]
val += upper_weight1 * lower_weight2 * q2_1[i, upper_index1, lower_index2]
val += lower_weight1 * upper_weight2 * q2_1[i, lower_index1, upper_index2]
val += upper_weight1 * upper_weight2 * q2_1[i, upper_index1, upper_index2]
temp[i] += sgn * val
end
end
return nothing
end
# get interpolated value of q2_2
function get_q2_2(
site :: Int64,
p1 :: Param,
p2 :: Param,
ch :: Channel
) :: Float64
val = p1.lower_weight * p2.lower_weight * ch.q2_2[site, p1.lower_index, p2.lower_index]
val += p1.upper_weight * p2.lower_weight * ch.q2_2[site, p1.upper_index, p2.lower_index]
val += p1.lower_weight * p2.upper_weight * ch.q2_2[site, p1.lower_index, p2.upper_index]
val += p1.upper_weight * p2.upper_weight * ch.q2_2[site, p1.upper_index, p2.upper_index]
return val
end
# get interpolated value of q2_2 on all lattice sites
function get_q2_2_avx!(
r :: Reduced_lattice,
p1 :: Param,
p2 :: Param,
ch :: Channel,
temp :: SubArray{Float64, 1, Array{Float64, 3}},
exchange :: Bool,
sgn :: Float64
) :: Nothing
# deref channel
q2_2 = ch.q2_2
# deref param
lower_index1 = p1.lower_index
upper_index1 = p1.upper_index
lower_weight1 = p1.lower_weight
upper_weight1 = p1.upper_weight
lower_index2 = p2.lower_index
upper_index2 = p2.upper_index
lower_weight2 = p2.lower_weight
upper_weight2 = p2.upper_weight
# check for site exchange
if exchange
indices = r.exchange
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight1 * lower_weight2 * q2_2[indices[i], lower_index1, lower_index2]
val += upper_weight1 * lower_weight2 * q2_2[indices[i], upper_index1, lower_index2]
val += lower_weight1 * upper_weight2 * q2_2[indices[i], lower_index1, upper_index2]
val += upper_weight1 * upper_weight2 * q2_2[indices[i], upper_index1, upper_index2]
temp[i] += sgn * val
end
else
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight1 * lower_weight2 * q2_2[i, lower_index1, lower_index2]
val += upper_weight1 * lower_weight2 * q2_2[i, upper_index1, lower_index2]
val += lower_weight1 * upper_weight2 * q2_2[i, lower_index1, upper_index2]
val += upper_weight1 * upper_weight2 * q2_2[i, upper_index1, upper_index2]
temp[i] += sgn * val
end
end
return nothing
end
# get interpolated value of q3
function get_q3(
site :: Int64,
p1 :: Param,
p2 :: Param,
p3 :: Param,
ch :: Channel
) :: Float64
val = p1.lower_weight * p2.lower_weight * p3.lower_weight * ch.q3[site, p1.lower_index, p2.lower_index, p3.lower_index]
val += p1.upper_weight * p2.lower_weight * p3.lower_weight * ch.q3[site, p1.upper_index, p2.lower_index, p3.lower_index]
val += p1.lower_weight * p2.upper_weight * p3.lower_weight * ch.q3[site, p1.lower_index, p2.upper_index, p3.lower_index]
val += p1.upper_weight * p2.upper_weight * p3.lower_weight * ch.q3[site, p1.upper_index, p2.upper_index, p3.lower_index]
val += p1.lower_weight * p2.lower_weight * p3.upper_weight * ch.q3[site, p1.lower_index, p2.lower_index, p3.upper_index]
val += p1.upper_weight * p2.lower_weight * p3.upper_weight * ch.q3[site, p1.upper_index, p2.lower_index, p3.upper_index]
val += p1.lower_weight * p2.upper_weight * p3.upper_weight * ch.q3[site, p1.lower_index, p2.upper_index, p3.upper_index]
val += p1.upper_weight * p2.upper_weight * p3.upper_weight * ch.q3[site, p1.upper_index, p2.upper_index, p3.upper_index]
return val
end
# get interpolated value of q3 on all lattice sites
function get_q3_avx!(
r :: Reduced_lattice,
p1 :: Param,
p2 :: Param,
p3 :: Param,
ch :: Channel,
temp :: SubArray{Float64, 1, Array{Float64, 3}},
exchange :: Bool,
sgn :: Float64
) :: Nothing
# deref channel
q3 = ch.q3
# deref param
lower_index1 = p1.lower_index
upper_index1 = p1.upper_index
lower_weight1 = p1.lower_weight
upper_weight1 = p1.upper_weight
lower_index2 = p2.lower_index
upper_index2 = p2.upper_index
lower_weight2 = p2.lower_weight
upper_weight2 = p2.upper_weight
lower_index3 = p3.lower_index
upper_index3 = p3.upper_index
lower_weight3 = p3.lower_weight
upper_weight3 = p3.upper_weight
# check for site exchange
if exchange
indices = r.exchange
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight1 * lower_weight2 * lower_weight3 * q3[indices[i], lower_index1, lower_index2, lower_index3]
val += upper_weight1 * lower_weight2 * lower_weight3 * q3[indices[i], upper_index1, lower_index2, lower_index3]
val += lower_weight1 * upper_weight2 * lower_weight3 * q3[indices[i], lower_index1, upper_index2, lower_index3]
val += upper_weight1 * upper_weight2 * lower_weight3 * q3[indices[i], upper_index1, upper_index2, lower_index3]
val += lower_weight1 * lower_weight2 * upper_weight3 * q3[indices[i], lower_index1, lower_index2, upper_index3]
val += upper_weight1 * lower_weight2 * upper_weight3 * q3[indices[i], upper_index1, lower_index2, upper_index3]
val += lower_weight1 * upper_weight2 * upper_weight3 * q3[indices[i], lower_index1, upper_index2, upper_index3]
val += upper_weight1 * upper_weight2 * upper_weight3 * q3[indices[i], upper_index1, upper_index2, upper_index3]
temp[i] += sgn * val
end
else
@turbo unroll = 1 for i in eachindex(temp)
val = lower_weight1 * lower_weight2 * lower_weight3 * q3[i, lower_index1, lower_index2, lower_index3]
val += upper_weight1 * lower_weight2 * lower_weight3 * q3[i, upper_index1, lower_index2, lower_index3]
val += lower_weight1 * upper_weight2 * lower_weight3 * q3[i, lower_index1, upper_index2, lower_index3]
val += upper_weight1 * upper_weight2 * lower_weight3 * q3[i, upper_index1, upper_index2, lower_index3]
val += lower_weight1 * lower_weight2 * upper_weight3 * q3[i, lower_index1, lower_index2, upper_index3]
val += upper_weight1 * lower_weight2 * upper_weight3 * q3[i, upper_index1, lower_index2, upper_index3]
val += lower_weight1 * upper_weight2 * upper_weight3 * q3[i, lower_index1, upper_index2, upper_index3]
val += upper_weight1 * upper_weight2 * upper_weight3 * q3[i, upper_index1, upper_index2, upper_index3]
temp[i] += sgn * val
end
end
return nothing
end
# get interpolated value of channel for a given frequency buffer
function get_channel(
site :: Int64,
b :: Buffer,
ch :: Channel
) :: Float64
val = 0.0
if b.kernel == 1
val = get_q1(site, b.p1, ch)
elseif b.kernel == 2
val = get_q2_1(site, b.p1, b.p2, ch)
elseif b.kernel == 3
val = get_q2_2(site, b.p1, b.p3, ch)
elseif b.kernel == 4
val = get_q3(site, b.p1, b.p2, b.p3, ch)
end
return val
end
# get interpolated value of channel for a given frequency buffer on all lattice sites
function get_channel_avx!(
r :: Reduced_lattice,
b :: Buffer,
ch :: Channel,
temp :: SubArray{Float64, 1, Array{Float64, 3}},
exchange :: Bool,
sgn :: Float64
) :: Nothing
if b.kernel == 1
get_q1_avx!(r, b.p1, ch, temp, exchange, sgn)
elseif b.kernel == 2
get_q2_1_avx!(r, b.p1, b.p2, ch, temp, exchange, sgn)
elseif b.kernel == 3
get_q2_2_avx!(r, b.p1, b.p3, ch, temp, exchange, sgn)
elseif b.kernel == 4
get_q3_avx!(r, b.p1, b.p2, b.p3, ch, temp, exchange, sgn)
end
return nothing
end
# replace channel with another channel
function replace_with!(
ch1 :: Channel,
ch2 :: Channel
) :: Nothing
@turbo ch1.q1 .= ch2.q1
@turbo ch1.q2_1 .= ch2.q2_1
@turbo ch1.q2_2 .= ch2.q2_2
@turbo ch1.q3 .= ch2.q3
return nothing
end
# multiply channel with factor
function mult_with!(
ch :: Channel,
fac :: Float64
) :: Nothing
@turbo ch.q1 .*= fac
@turbo ch.q2_1 .*= fac
@turbo ch.q2_2 .*= fac
@turbo ch.q3 .*= fac
return nothing
end
# multiply channel with factor and add to other channel
function mult_with_add_to!(
ch2 :: Channel,
fac :: Float64,
ch1 :: Channel
) :: Nothing
@turbo ch1.q1 .+= fac .* ch2.q1
@turbo ch1.q2_1 .+= fac .* ch2.q2_1
@turbo ch1.q2_2 .+= fac .* ch2.q2_2
@turbo ch1.q3 .+= fac .* ch2.q3
return nothing
end
"""
get_abs_max(
ch :: Channel
) :: Float64
Returns maximum absolute value of a channel.
"""
function get_abs_max(
ch :: Channel
) :: Float64
max_ch = maximum(abs.(ch.q3))
return max_ch
end
# resample a channel to new meshes via trilinear interpolation
function resample_from_to!(
Ω_old :: Vector{Float64},
ν_old :: Vector{Float64},
ch_old :: Channel,
Ω_new :: Vector{Float64},
ν_new :: Vector{Float64},
ch_new :: Channel
) :: Nothing
# get dimensions
num_sites = size(ch_old.q2_1, 1)
num_Ω = size(ch_old.q2_1, 2)
num_ν = size(ch_old.q2_1, 3)
# resample q1
for w in 1 : num_Ω
# get interpolation parameters
p1 = get_param(Ω_new[w], Ω_old)
for site in 1 : num_sites
ch_new.q1[site, w] = get_q1(site, p1, ch_old)
end
end
# resample q2_1 and q2_2
for v in 1 : num_ν
for w in 1 : num_Ω
# get interpolation parameters
p1 = get_param(Ω_new[w], Ω_old)
p2 = get_param(ν_new[v], ν_old)
for site in 1 : num_sites
ch_new.q2_1[site, w, v] = get_q2_1(site, p1, p2, ch_old)
ch_new.q2_2[site, w, v] = get_q2_2(site, p1, p2, ch_old)
end
end
end
# resample q3
for vp in 1 : num_ν
for v in 1 : num_ν
for w in 1 : num_Ω
# get interpolation parameters
p1 = get_param(Ω_new[w], Ω_old)
p2 = get_param(ν_new[v], ν_old)
p3 = get_param(ν_new[vp], ν_old)
for site in 1 : num_sites
ch_new.q3[site, w, v, vp] = get_q3(site, p1, p2, p3, ch_old)
end
end
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 2384 | # save channel to file
function save!(
file :: HDF5.File,
label :: String,
ch :: Channel
) :: Nothing
file[label * "/q1"] = ch.q1
file[label * "/q2_1"] = ch.q2_1
file[label * "/q2_2"] = ch.q2_2
file[label * "/q3"] = ch.q3
return nothing
end
# read channel from file
function read_channel(
file :: HDF5.File,
label :: String,
) :: Channel
# read kernels
q1 = read(file, label * "/q1")
q2_1 = read(file, label * "/q2_1")
q2_2 = read(file, label * "/q2_2")
q3 = read(file, label * "/q3")
# build channel
ch = Channel(q1, q2_1, q2_2, q3)
return ch
end
# save self energy to file
function save_self!(
file :: HDF5.File,
Λ :: Float64,
m :: Mesh,
a :: Action
) :: Nothing
# save self energy mesh to file
file["σ/$(Λ)"] = m.σ
# save self energy to file
file["Σ/$(Λ)"] = a.Σ
return nothing
end
"""
read_self(
file :: HDF5.File,
Λ :: Float64,
) :: NTuple{2, Vector{Float64}}
Read self energy mesh and values from HDF5 file at cutoff Λ.
"""
function read_self(
file :: HDF5.File,
Λ :: Float64,
) :: NTuple{2, Vector{Float64}}
# filter out nearest available cutoff
list = keys(file["σ"])
cutoffs = parse.(Float64, list)
index = argmin(abs.(cutoffs .- Λ))
println("Λ was adjusted to $(cutoffs[index]).")
# read self energy mesh
σ = read(file, "σ/$(cutoffs[index])")
# read self energy
Σ = read(file, "Σ/$(cutoffs[index])")
return σ, Σ
end
# save vertex to file
function save!(
file :: HDF5.File,
label :: String,
Γ :: Vertex
) :: Nothing
# save bare vertex
file[label * "/bare"] = Γ.bare
# save channels
save!(file, label * "/ch_s", Γ.ch_s)
save!(file, label * "/ch_t", Γ.ch_t)
save!(file, label * "/ch_u", Γ.ch_u)
return nothing
end
# read vertex from file
function read_vertex(
file :: HDF5.File,
label :: String
) :: Vertex
# read bare vertex
bare = read(file, label * "/bare")
# read channels
ch_s = read_channel(file, label * "/ch_s")
ch_t = read_channel(file, label * "/ch_t")
ch_u = read_channel(file, label * "/ch_u")
# build vertex
Γ = Vertex(bare, ch_s, ch_t, ch_u)
return Γ
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 18074 | # auxiliary function to perform tests for action
function do_action_tests!(
r :: Reduced_lattice,
m :: Mesh,
a :: Action
) :: Nothing
# init test points on mesh
w_idx = rand(1 : 31)
v_idx = rand(1 : 31)
vp_idx = rand(1 : 31)
# init test points for interpolations
ws = rand() * m.Ωs[end]
vs = rand() * m.νs[end]
vsp = rand() * m.νs[end]
wt = rand() * m.Ωt[end]
vt = rand() * m.νt[end]
vtp = rand() * m.νt[end]
wu = rand() * m.Ωs[end]
vu = rand() * m.νs[end]
vup = rand() * m.νs[end]
# fill self energy with random values
a.Σ .= rand(31)
# ensure antisymmetry
a.Σ[1] = 0.0
# generate coefficients for test function
a111 = rand(3, length(a.Γ), length(r.sites))
a110 = rand(3, length(a.Γ), length(r.sites))
a101 = rand(3, length(a.Γ), length(r.sites))
a011 = rand(3, length(a.Γ), length(r.sites))
a100 = rand(3, length(a.Γ), length(r.sites))
a010 = rand(3, length(a.Γ), length(r.sites))
a001 = rand(3, length(a.Γ), length(r.sites))
a000 = rand(3, length(a.Γ), length(r.sites))
# define testfunction (linear in all frequencies, should interpolate exactly)
f(ch, i, s, w, v, vp) = a111[ch, i, s] * w * v * vp +
a110[ch, i, s] * w * v +
a101[ch, i, s] * w * vp +
a011[ch, i, s] * v * vp +
a100[ch, i, s] * w +
a010[ch, i, s] * v +
a001[ch, i, s] * vp +
a000[ch, i, s]
# fill channels with values of testfunction
for i in eachindex(a.Γ)
for s in 1 : length(r.sites)
for iw in 1 : m.num_Ω
a.Γ[i].ch_s.q1[s, iw] = f(1, i, s, m.Ωs[iw], m.νs[end], m.νs[end])
a.Γ[i].ch_t.q1[s, iw] = f(2, i, s, m.Ωt[iw], m.νt[end], m.νt[end])
a.Γ[i].ch_u.q1[s, iw] = f(3, i, s, m.Ωs[iw], m.νs[end], m.νs[end])
for iv in 1 : m.num_ν
a.Γ[i].ch_s.q2_1[s, iw, iv] = f(1, i, s, m.Ωs[iw], m.νs[iv], m.νs[end])
a.Γ[i].ch_t.q2_1[s, iw, iv] = f(2, i, s, m.Ωt[iw], m.νt[iv], m.νt[end])
a.Γ[i].ch_u.q2_1[s, iw, iv] = f(3, i, s, m.Ωs[iw], m.νs[iv], m.νs[end])
a.Γ[i].ch_s.q2_2[s, iw, iv] = f(1, i, s, m.Ωs[iw], m.νs[end], m.νs[iv])
a.Γ[i].ch_t.q2_2[s, iw, iv] = f(2, i, s, m.Ωt[iw], m.νt[end], m.νt[iv])
a.Γ[i].ch_u.q2_2[s, iw, iv] = f(3, i, s, m.Ωs[iw], m.νs[end], m.νs[iv])
for ivp in 1 : m.num_ν
a.Γ[i].ch_s.q3[s, iw, iv, ivp] = f(1, i, s, m.Ωs[iw], m.νs[iv], m.νs[ivp])
a.Γ[i].ch_t.q3[s, iw, iv, ivp] = f(2, i, s, m.Ωt[iw], m.νt[iv], m.νt[ivp])
a.Γ[i].ch_u.q3[s, iw, iv, ivp] = f(3, i, s, m.Ωs[iw], m.νs[iv], m.νs[ivp])
end
end
end
end
end
# test self energy interpolation and extrapolation
@testset "interpolation / extrapolation Σ" begin
outer = m.σ[end] + rand()
@test get_Σ(m.σ[w_idx], m, a) ≈ a.Σ[w_idx]
@test get_Σ(outer, m, a) ≈ a.Σ[end] * m.σ[end] / outer
end
# prepare buffer for vectorized routines
temp = zeros(Float64, length(r.sites), length(a.Γ), 1)
# test interpolations in s channel
@testset "interpolations s channel" begin
@testset "on mesh" begin
# build buffers
bs_q3 = get_buffer_s(m.Ωs[w_idx], m.νs[v_idx], m.νs[vp_idx], m)
bs_q2_2 = get_buffer_s(m.Ωs[w_idx], Inf, m.νs[vp_idx], m)
bs_q2_1 = get_buffer_s(m.Ωs[w_idx], m.νs[v_idx], Inf, m)
bs_q1 = get_buffer_s(m.Ωs[w_idx], Inf, Inf, m)
bs_bare = get_buffer_s( Inf, Inf, Inf, m)
# test sequential routine
@testset "sequential" begin
idx = rand(1 : length(r.sites))
for i in eachindex(a.Γ)
@test get_vertex(idx, bs_q3, a.Γ[i], 1) ≈ a.Γ[i].ch_s.q3[idx, w_idx, v_idx, vp_idx]
@test get_vertex(idx, bs_q2_2, a.Γ[i], 1) ≈ a.Γ[i].ch_s.q2_2[idx, w_idx, vp_idx]
@test get_vertex(idx, bs_q2_1, a.Γ[i], 1) ≈ a.Γ[i].ch_s.q2_1[idx, w_idx, v_idx]
@test get_vertex(idx, bs_q1, a.Γ[i], 1) ≈ a.Γ[i].ch_s.q1[idx, w_idx]
@test get_vertex(idx, bs_bare, a.Γ[i], 1) ≈ 0.0
end
end
# test vectorized routine
@testset "vectorized" begin
for i in eachindex(a.Γ)
temp .= 0.0; get_vertex_avx!(r, bs_q3, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_s.q3[:, w_idx, v_idx, vp_idx]
temp .= 0.0; get_vertex_avx!(r, bs_q2_2, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_s.q2_2[:, w_idx, vp_idx]
temp .= 0.0; get_vertex_avx!(r, bs_q2_1, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_s.q2_1[:, w_idx, v_idx]
temp .= 0.0; get_vertex_avx!(r, bs_q1, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_s.q1[:, w_idx]
temp .= 0.0; get_vertex_avx!(r, bs_bare, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test norm(temp[:, i, 1]) ≈ 0.0
end
end
end
@testset "interpolated" begin
# build buffers
bs_q3 = get_buffer_s( ws, vs, vsp, m)
bs_q2_2 = get_buffer_s( ws, Inf, vsp, m)
bs_q2_1 = get_buffer_s( ws, vs, Inf, m)
bs_q1 = get_buffer_s( ws, Inf, Inf, m)
bs_bare = get_buffer_s(Inf, Inf, Inf, m)
# test sequential routine
@testset "sequential" begin
idx = rand(1 : length(r.sites))
for i in eachindex(a.Γ)
@test get_vertex(idx, bs_q3, a.Γ[i], 1) ≈ f(1, i, idx, ws, vs, vsp)
@test get_vertex(idx, bs_q2_2, a.Γ[i], 1) ≈ f(1, i, idx, ws, m.νs[end], vsp)
@test get_vertex(idx, bs_q2_1, a.Γ[i], 1) ≈ f(1, i, idx, ws, vs, m.νs[end])
@test get_vertex(idx, bs_q1, a.Γ[i], 1) ≈ f(1, i, idx, ws, m.νs[end], m.νs[end])
@test get_vertex(idx, bs_bare, a.Γ[i], 1) ≈ 0.0
end
end
# test vectorized routine
@testset "vectorized" begin
for i in eachindex(a.Γ)
temp .= 0.0; get_vertex_avx!(r, bs_q3, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(1, i, j, ws, vs, vsp) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bs_q2_2, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(1, i, j, ws, m.νs[end], vsp) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bs_q2_1, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(1, i, j, ws, vs, m.νs[end]) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bs_q1, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(1, i, j, ws, m.νs[end], m.νs[end]) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bs_bare, a.Γ[i], 1, view(temp, :, i, 1), false, 1.0); @test norm(temp[:, i, 1]) ≈ 0.0
end
end
end
end
# test interpolations in t channel
@testset "interpolations t channel" begin
@testset "on mesh" begin
# build buffers
bt_q3 = get_buffer_t(m.Ωt[w_idx], m.νt[v_idx], m.νt[vp_idx], m)
bt_q2_2 = get_buffer_t(m.Ωt[w_idx], Inf, m.νt[vp_idx], m)
bt_q2_1 = get_buffer_t(m.Ωt[w_idx], m.νt[v_idx], Inf, m)
bt_q1 = get_buffer_t(m.Ωt[w_idx], Inf, Inf, m)
bt_bare = get_buffer_t( Inf, Inf, Inf, m)
# test sequential routine
@testset "sequential" begin
idx = rand(1 : length(r.sites))
for i in eachindex(a.Γ)
@test get_vertex(idx, bt_q3, a.Γ[i], 2) ≈ a.Γ[i].ch_t.q3[idx, w_idx, v_idx, vp_idx]
@test get_vertex(idx, bt_q2_2, a.Γ[i], 2) ≈ a.Γ[i].ch_t.q2_2[idx, w_idx, vp_idx]
@test get_vertex(idx, bt_q2_1, a.Γ[i], 2) ≈ a.Γ[i].ch_t.q2_1[idx, w_idx, v_idx]
@test get_vertex(idx, bt_q1, a.Γ[i], 2) ≈ a.Γ[i].ch_t.q1[idx, w_idx]
@test get_vertex(idx, bt_bare, a.Γ[i], 2) ≈ 0.0
end
end
# test vectorized routine
@testset "vectorized" begin
for i in eachindex(a.Γ)
temp .= 0.0; get_vertex_avx!(r, bt_q3, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_t.q3[:, w_idx, v_idx, vp_idx]
temp .= 0.0; get_vertex_avx!(r, bt_q2_2, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_t.q2_2[:, w_idx, vp_idx]
temp .= 0.0; get_vertex_avx!(r, bt_q2_1, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_t.q2_1[:, w_idx, v_idx]
temp .= 0.0; get_vertex_avx!(r, bt_q1, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_t.q1[:, w_idx]
temp .= 0.0; get_vertex_avx!(r, bt_bare, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test norm(temp[:, i, 1]) ≈ 0.0
end
end
end
@testset "interpolated" begin
# build buffers
bt_q3 = get_buffer_t( wt, vt, vtp, m)
bt_q2_2 = get_buffer_t( wt, Inf, vtp, m)
bt_q2_1 = get_buffer_t( wt, vt, Inf, m)
bt_q1 = get_buffer_t( wt, Inf, Inf, m)
bt_bare = get_buffer_t(Inf, Inf, Inf, m)
# test sequential routine
@testset "sequential" begin
idx = rand(1 : length(r.sites))
for i in eachindex(a.Γ)
@test get_vertex(idx, bt_q3, a.Γ[i], 2) ≈ f(2, i, idx, wt, vt, vtp)
@test get_vertex(idx, bt_q2_2, a.Γ[i], 2) ≈ f(2, i, idx, wt, m.νt[end], vtp)
@test get_vertex(idx, bt_q2_1, a.Γ[i], 2) ≈ f(2, i, idx, wt, vt, m.νt[end])
@test get_vertex(idx, bt_q1, a.Γ[i], 2) ≈ f(2, i, idx, wt, m.νt[end], m.νt[end])
@test get_vertex(idx, bt_bare, a.Γ[i], 2) ≈ 0.0
end
end
# test vectorized routine
@testset "vectorized" begin
for i in eachindex(a.Γ)
temp .= 0.0; get_vertex_avx!(r, bt_q3, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(2, i, j, wt, vt, vtp) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bt_q2_2, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(2, i, j, wt, m.νt[end], vtp) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bt_q2_1, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(2, i, j, wt, vt, m.νt[end]) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bt_q1, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(2, i, j, wt, m.νt[end], m.νt[end]) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bt_bare, a.Γ[i], 2, view(temp, :, i, 1), false, 1.0); @test norm(temp[:, i, 1]) ≈ 0.0
end
end
end
end
# test interpolations in u channel
@testset "interpolations u channel" begin
@testset "on mesh" begin
# build buffers
bu_q3 = get_buffer_u(m.Ωs[w_idx], m.νs[v_idx], m.νs[vp_idx], m)
bu_q2_2 = get_buffer_u(m.Ωs[w_idx], Inf, m.νs[vp_idx], m)
bu_q2_1 = get_buffer_u(m.Ωs[w_idx], m.νs[v_idx], Inf, m)
bu_q1 = get_buffer_u(m.Ωs[w_idx], Inf, Inf, m)
bu_bare = get_buffer_u( Inf, Inf, Inf, m)
# test sequential routine
@testset "sequential" begin
idx = rand(1 : length(r.sites))
for i in eachindex(a.Γ)
@test get_vertex(idx, bu_q3, a.Γ[i], 3) ≈ a.Γ[i].ch_u.q3[idx, w_idx, v_idx, vp_idx]
@test get_vertex(idx, bu_q2_2, a.Γ[i], 3) ≈ a.Γ[i].ch_u.q2_2[idx, w_idx, vp_idx]
@test get_vertex(idx, bu_q2_1, a.Γ[i], 3) ≈ a.Γ[i].ch_u.q2_1[idx, w_idx, v_idx]
@test get_vertex(idx, bu_q1, a.Γ[i], 3) ≈ a.Γ[i].ch_u.q1[idx, w_idx]
@test get_vertex(idx, bu_bare, a.Γ[i], 3) ≈ 0.0
end
end
# test vectorized routine
@testset "vectorized" begin
for i in eachindex(a.Γ)
temp .= 0.0; get_vertex_avx!(r, bu_q3, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_u.q3[:, w_idx, v_idx, vp_idx]
temp .= 0.0; get_vertex_avx!(r, bu_q2_2, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_u.q2_2[:, w_idx, vp_idx]
temp .= 0.0; get_vertex_avx!(r, bu_q2_1, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_u.q2_1[:, w_idx, v_idx]
temp .= 0.0; get_vertex_avx!(r, bu_q1, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ a.Γ[i].ch_u.q1[:, w_idx]
temp .= 0.0; get_vertex_avx!(r, bu_bare, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test norm(temp[:, i, 1]) ≈ 0.0
end
end
end
@testset "interpolated" begin
# build buffers
bu_q3 = get_buffer_u( wu, vu, vup, m)
bu_q2_2 = get_buffer_u( wu, Inf, vup, m)
bu_q2_1 = get_buffer_u( wu, vu, Inf, m)
bu_q1 = get_buffer_u( wu, Inf, Inf, m)
bu_bare = get_buffer_u(Inf, Inf, Inf, m)
# test sequential routine
@testset "sequential" begin
idx = rand(1 : length(r.sites))
for i in eachindex(a.Γ)
@test get_vertex(idx, bu_q3, a.Γ[i], 3) ≈ f(3, i, idx, wu, vu, vup)
@test get_vertex(idx, bu_q2_2, a.Γ[i], 3) ≈ f(3, i, idx, wu, m.νs[end], vup)
@test get_vertex(idx, bu_q2_1, a.Γ[i], 3) ≈ f(3, i, idx, wu, vu, m.νs[end])
@test get_vertex(idx, bu_q1, a.Γ[i], 3) ≈ f(3, i, idx, wu, m.νs[end], m.νs[end])
@test get_vertex(idx, bu_bare, a.Γ[i], 3) ≈ 0.0
end
end
# test vectorized routine
@testset "vectorized" begin
for i in eachindex(a.Γ)
temp .= 0.0; get_vertex_avx!(r, bu_q3, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(3, i, j, wu, vu, vup) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bu_q2_2, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(3, i, j, wu, m.νs[end], vup) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bu_q2_1, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(3, i, j, wu, vu, m.νs[end]) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bu_q1, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test temp[:, i, 1] ≈ [f(3, i, j, wu, m.νs[end], m.νs[end]) for j in 1 : length(r.sites)]
temp .= 0.0; get_vertex_avx!(r, bu_bare, a.Γ[i], 3, view(temp, :, i, 1), false, 1.0); @test norm(temp[:, i, 1]) ≈ 0.0
end
end
end
end
return nothing
end
"""
test_action() :: Nothing
Run consistency checks for available action implementations by benchmarking interpolation routines.
"""
function test_action() :: Nothing
# init test dummys
list = get_mesh(rand(), 1.0, 30, 0.4)
m = Mesh(31, 31, 31, 31, list, list, list, list, list, list)
# run tests for action_su2
@testset "action su2" begin
# generate action dummy for square lattice Heisenberg model
l = get_lattice("square", 5, verbose = false)
r = get_reduced_lattice("heisenberg", [[1.0]], l, verbose = false)
a = get_action_empty("su2", r, m)
init_action!(l, r, a)
# test if bare action is correctly initialized
@testset "initialization" begin
@test norm(a.Γ[1].bare) ≈ 0.25
@test norm(a.Γ[2].bare) ≈ 0.0
end
# perform tests
do_action_tests!(r, m, a)
end
# run tests for action_u1_dm
@testset "action u1-dm" begin
# generate action dummy for triangular lattice dm-c3 model
l = get_lattice("triangular", 5, verbose = false)
r = get_reduced_lattice("triangular-dm-c3", [[1.0, 1.0, 1.0]], l, verbose = false)
a = get_action_empty("u1-dm", r, m)
init_action!(l, r, a)
# test if bare action is correctly initialized
@testset "initialization" begin
@test norm(a.Γ[1].bare) ≈ sqrt(0.125)
@test norm(a.Γ[2].bare) ≈ sqrt(0.125)
@test norm(a.Γ[3].bare) ≈ sqrt(0.125)
@test norm(a.Γ[4].bare) ≈ 0.0
@test norm(a.Γ[5].bare) ≈ 0.0
@test norm(a.Γ[6].bare) ≈ 0.0
end
# perform tests
do_action_tests!(r, m, a)
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3559 | """
get_action_timers() : Nothing
Test performance of current interpolation routines.
"""
function get_action_timers() :: Nothing
# init test dummys (taking action_su2 as an example)
list = get_mesh(rand(), 1.0, 30, 0.4)
m = Mesh(31, 31, 31, 31, list, list, list, list, list, list)
p1 = get_param(rand(), list)
p2 = get_param(rand(), list)
p3 = get_param(rand(), list)
l = get_lattice("square", 10, verbose = false)
r = get_reduced_lattice("heisenberg", [[1.0]], l, verbose = false)
a = get_action_empty("su2", r, m); init_action!(l, r, a)
temp = zeros(Float64, length(r.sites), 1, 1)
# fill self energy with random values
a.Σ .= rand(31)
# fill s channel with random values
a.Γ[1].ch_s.q3 .= rand(length(r.sites), 31, 31, 31)
# init timer
to = TimerOutput()
# time self energy interpolation and extrapolation
val = rand()
outer = m.σ[end] + val
@timeit to "=> interpolation / extrapolation Σ" begin
for rep in 1 : 10
@timeit to "-> interpolation" get_Σ(val, m, a)
@timeit to "-> extrapolation" get_Σ(outer, m, a)
end
end
# deref channel and generate temp view
ch = a.Γ[1].ch_s
vtemp = view(temp, :, 1, 1)
# time q3 interpolations
@timeit to "=> interpolation q3 kernel" begin
# time sequential routine
for rep in 1 : 10
@timeit to "-> sequential" begin
for i in 1 : size(temp, 1)
temp[i, 1, 1] = get_q3(i, p1, p2, p3, ch)
end
end
end
# time vectorized routine
for rep in 1 : 10
@timeit to "-> vectorized" begin
get_q3_avx!(r, p1, p2, p3, ch, vtemp, false, 1.0)
end
end
end
# time q2_2 interpolations
@timeit to "=> interpolation q2_2 kernel" begin
# time sequential routine
for rep in 1 : 10
@timeit to "-> sequential" begin
for i in 1 : size(temp, 1)
temp[i, 1, 1] = get_q2_2(i, p1, p3, ch)
end
end
end
# time vectorized routine
for rep in 1 : 10
@timeit to "-> vectorized" begin
get_q2_2_avx!(r, p1, p3, ch, vtemp, false, 1.0)
end
end
end
# time q2_1 interpolations
@timeit to "=> interpolation q2_1 kernel" begin
# time sequential routine
for rep in 1 : 10
@timeit to "-> sequential" begin
for i in 1 : size(temp, 1)
temp[i, 1, 1] = get_q2_1(i, p1, p2, ch)
end
end
end
# time vectorized routine
for rep in 1 : 10
@timeit to "-> vectorized" begin
get_q2_1_avx!(r, p1, p2, ch, vtemp, false, 1.0)
end
end
end
# time q1 interpolations
@timeit to "=> interpolation q1 kernel" begin
# time sequential routine
for rep in 1 : 10
@timeit to "-> sequential" begin
for i in 1 : size(temp, 1)
temp[i, 1, 1] = get_q1(i, p1, ch)
end
end
end
# time vectorized routine
for rep in 1 : 10
@timeit to "-> vectorized" begin
get_q1_avx!(r, p1, ch, vtemp, false, 1.0)
end
end
end
show(to)
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3622 | """
Vertex
Struct containing bare values of vertex component and the respective s, t and u channel.
* `bare :: Vector{Float64}` : bare couplings on irreducible lattice sites
* `ch_s :: Channel` : particle-particle (s) channel
* `ch_t :: Channel` : direct particle-hole (t) channel
* `ch_u :: Channel` : crossed particle-hole (u) channel
"""
struct Vertex
bare :: Vector{Float64}
ch_s :: Channel
ch_t :: Channel
ch_u :: Channel
end
# generate vertex dummy
function get_vertex_empty(
r :: Reduced_lattice,
m :: Mesh
) :: Vertex
# init bare
bare = zeros(Float64, length(r.sites))
# init channels
ch_s = get_channel_empty(r, m)
ch_t = get_channel_empty(r, m)
ch_u = get_channel_empty(r, m)
# build vertex
Γ = Vertex(bare, ch_s, ch_t, ch_u)
return Γ
end
# get interpolated value of vertex in certain channel for a given frequency buffer
function get_vertex(
site :: Int64,
b :: Buffer,
Γ :: Vertex,
ch :: Int64
) :: Float64
val = 0.0
if ch == 1
val = get_channel(site, b, Γ.ch_s)
elseif ch == 2
val = get_channel(site, b, Γ.ch_t)
elseif ch == 3
val = get_channel(site, b, Γ.ch_u)
end
return val
end
# get interpolated value of vertex in certain channel for a given frequency buffer on all lattice sites
function get_vertex_avx!(
r :: Reduced_lattice,
b :: Buffer,
Γ :: Vertex,
ch :: Int64,
temp :: SubArray{Float64, 1, Array{Float64, 3}},
exchange :: Bool,
sgn :: Float64
) :: Nothing
if ch == 1
get_channel_avx!(r, b, Γ.ch_s, temp, exchange, sgn)
elseif ch == 2
get_channel_avx!(r, b, Γ.ch_t, temp, exchange, sgn)
elseif ch == 3
get_channel_avx!(r, b, Γ.ch_u, temp, exchange, sgn)
end
return nothing
end
# replace vertex with another vertex (except for bare)
function replace_with!(
Γ1 :: Vertex,
Γ2 :: Vertex
) :: Nothing
replace_with!(Γ1.ch_s, Γ2.ch_s)
replace_with!(Γ1.ch_t, Γ2.ch_t)
replace_with!(Γ1.ch_u, Γ2.ch_u)
return nothing
end
# multiply vertex with factor (except for bare)
function mult_with!(
Γ :: Vertex,
fac :: Float64
) :: Nothing
mult_with!(Γ.ch_s, fac)
mult_with!(Γ.ch_t, fac)
mult_with!(Γ.ch_u, fac)
return nothing
end
# multiply vertex with some factor and add to other vertex (except for bare)
function mult_with_add_to!(
Γ2 :: Vertex,
fac :: Float64,
Γ1 :: Vertex
) :: Nothing
mult_with_add_to!(Γ2.ch_s, fac, Γ1.ch_s)
mult_with_add_to!(Γ2.ch_t, fac, Γ1.ch_t)
mult_with_add_to!(Γ2.ch_u, fac, Γ1.ch_u)
return nothing
end
"""
get_abs_max(
Γ :: Vertex
) :: Float64
Returns maximum absolute value of a vertex component across channels.
"""
function get_abs_max(
Γ :: Vertex
) :: Float64
max_s = get_abs_max(Γ.ch_s)
max_t = get_abs_max(Γ.ch_t)
max_u = get_abs_max(Γ.ch_u)
Γ_max = max(max_s, max_t, max_u)
return Γ_max
end
# resample a vertex component to new meshes via trilinear interpolation
function resample_from_to!(
m_old :: Mesh,
Γ_old :: Vertex,
m_new :: Mesh,
Γ_new :: Vertex
) :: Nothing
resample_from_to!(m_old.Ωs, m_old.νs, Γ_old.ch_s, m_new.Ωs, m_new.νs, Γ_new.ch_s)
resample_from_to!(m_old.Ωt, m_old.νt, Γ_old.ch_t, m_new.Ωt, m_new.νt, Γ_new.ch_t)
resample_from_to!(m_old.Ωs, m_old.νs, Γ_old.ch_u, m_new.Ωs, m_new.νs, Γ_new.ch_u)
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 8566 | """
Action_su2 <: Action
Struct containing self energy and vertex components for SU(2) symmetric models.
* `S :: Float64` : total spin quantum number
* `Σ :: Vector{Float64}` : negative imaginary part of the self energy
* `Γ :: Vector{Vertex}` : spin and density component of the full vertex
"""
struct Action_su2 <: Action
S :: Float64
Σ :: Vector{Float64}
Γ :: Vector{Vertex}
end
# generate action_su2 dummy
function get_action_su2_empty(
S :: Float64,
r :: Reduced_lattice,
m :: Mesh,
) :: Action_su2
# init self energy
Σ = zeros(Float64, length(m.σ))
# init vertices
Γ = Vertex[get_vertex_empty(r, m) for i in 1 : 2]
# build action
a = Action_su2(S, Σ, Γ)
return a
end
# init action for su2 symmetry
function init_action!(
l :: Lattice,
r :: Reduced_lattice,
a :: Action_su2
) :: Nothing
# init bare action for spin component
ref_int = SVector{4, Int64}(0, 0, 0, 1)
ref = Site(ref_int, get_vec(ref_int, l.uc))
for i in eachindex(r.sites)
# get bond from lattice
b = get_bond(ref, r.sites[i], l)
# set bare according to spin exchange, normalize with 2S
a.Γ[1].bare[i] = b.exchange[1, 1] / 4.0 / (2.0 * a.S)
end
return nothing
end
# set repulsion for su2 symmetry
function set_repulsion!(
A :: Float64,
a :: Action_su2
) :: Nothing
# init bare action onsite with level repulsion for spin component
a.Γ[1].bare[1] = A / 4.0 / (2.0 * a.S)
return nothing
end
# helper function to disentangle flags during interpolation for su2 models
function apply_flags_su2(
b :: Buffer,
comp :: Int64
) :: Tuple{Float64, Int64}
# clarify sign of contribution
sgn = 1.0
# -ξ(μ) = -1 for density component
if comp == 2 && b.sgn_μ
sgn *= -1.0
end
# -ξ(ν) = -1 for density component
if comp == 2 && b.sgn_ν
sgn *= -1.0
end
return sgn, comp
end
# get all interpolated vertex components for su2 models
function get_Γ(
site :: Int64,
bs :: Buffer,
bt :: Buffer,
bu :: Buffer,
r :: Reduced_lattice,
a :: Action_su2
;
ch_s :: Bool = true,
ch_t :: Bool = true,
ch_u :: Bool = true
) :: NTuple{2, Float64}
spin = get_Γ_comp(1, site, bs, bt, bu, r, a, apply_flags_su2, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
dens = get_Γ_comp(2, site, bs, bt, bu, r, a, apply_flags_su2, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
return spin, dens
end
# get all interpolated vertex components for su2 models on all lattice sites
function get_Γ_avx!(
r :: Reduced_lattice,
bs :: Buffer,
bt :: Buffer,
bu :: Buffer,
a :: Action_su2,
temp :: Array{Float64, 3},
index :: Int64
;
ch_s :: Bool = true,
ch_t :: Bool = true,
ch_u :: Bool = true
) :: Nothing
for comp in 1 : 2
get_Γ_comp_avx!(comp, r, bs, bt, bu, a, apply_flags_su2, view(temp, :, comp, index), ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
end
return nothing
end
# symmetrize full loop contribution and central part
function symmetrize!(
r :: Reduced_lattice,
a :: Action_su2
) :: Nothing
# get dimensions
num_sites = size(a.Γ[1].ch_s.q2_1, 1)
num_Ω = size(a.Γ[1].ch_s.q2_1, 2)
num_ν = size(a.Γ[1].ch_s.q2_1, 3)
# computation for q3
for v in 1 : num_ν
for vp in v + 1 : num_ν
@turbo for w in 1 : num_Ω
for i in 1 : num_sites
# get upper triangular matrix for (v, v') plane for s channel
a.Γ[1].ch_s.q3[i, w, v, vp] = a.Γ[1].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_s.q3[i, w, v, vp] = a.Γ[2].ch_s.q3[r.exchange[i], w, vp, v]
# get upper triangular matrix for (v, v') plane for t channel
a.Γ[1].ch_t.q3[i, w, v, vp] = a.Γ[1].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_t.q3[i, w, v, vp] = a.Γ[2].ch_t.q3[r.exchange[i], w, vp, v]
# get upper triangular matrix for (v, v') plane for u channel
a.Γ[1].ch_u.q3[i, w, v, vp] = a.Γ[1].ch_u.q3[i, w, vp, v]
a.Γ[2].ch_u.q3[i, w, v, vp] = a.Γ[2].ch_u.q3[i, w, vp, v]
end
end
end
end
return nothing
end
# symmetrized addition for left part (right part symmetric to left part)
function symmetrize_add_to!(
r :: Reduced_lattice,
a_l :: Action_su2,
a :: Action_su2
) :: Nothing
# get dimensions
num_sites = size(a_l.Γ[1].ch_s.q2_1, 1)
num_Ω = size(a_l.Γ[1].ch_s.q2_1, 2)
num_ν = size(a_l.Γ[1].ch_s.q2_1, 3)
# computation for q1
@turbo for w in 1 : num_Ω
for i in 1 : num_sites
# add q1 to s channel (right part from v <-> v' exchange)
a.Γ[1].ch_s.q1[i, w] += a_l.Γ[1].ch_s.q1[i, w] + a_l.Γ[1].ch_s.q1[r.exchange[i], w]
a.Γ[2].ch_s.q1[i, w] += a_l.Γ[2].ch_s.q1[i, w] + a_l.Γ[2].ch_s.q1[r.exchange[i], w]
# add q1 to t channel (right part from v <-> v' exchange)
a.Γ[1].ch_t.q1[i, w] += a_l.Γ[1].ch_t.q1[i, w] + a_l.Γ[1].ch_t.q1[r.exchange[i], w]
a.Γ[2].ch_t.q1[i, w] += a_l.Γ[2].ch_t.q1[i, w] + a_l.Γ[2].ch_t.q1[r.exchange[i], w]
# add q1 to u channel (right part from v <-> v' exchange)
a.Γ[1].ch_u.q1[i, w] += a_l.Γ[1].ch_u.q1[i, w] + a_l.Γ[1].ch_u.q1[i, w]
a.Γ[2].ch_u.q1[i, w] += a_l.Γ[2].ch_u.q1[i, w] + a_l.Γ[2].ch_u.q1[i, w]
end
end
# computation for q2_1 and q2_2
@turbo for v in 1 : num_ν
for w in 1 : num_Ω
for i in 1 : num_sites
# add q2_1 and q2_2 to s channel (right part from v <-> v' exchange)
a.Γ[1].ch_s.q2_1[i, w, v] += a_l.Γ[1].ch_s.q2_1[i, w, v] + a_l.Γ[1].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[2].ch_s.q2_1[i, w, v] += a_l.Γ[2].ch_s.q2_1[i, w, v] + a_l.Γ[2].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[1].ch_s.q2_2[i, w, v] += a_l.Γ[1].ch_s.q2_2[i, w, v] + a_l.Γ[1].ch_s.q2_1[r.exchange[i], w, v]
a.Γ[2].ch_s.q2_2[i, w, v] += a_l.Γ[2].ch_s.q2_2[i, w, v] + a_l.Γ[2].ch_s.q2_1[r.exchange[i], w, v]
# add q2_1 and q2_2 to t channel (right part from v <-> v' exchange)
a.Γ[1].ch_t.q2_1[i, w, v] += a_l.Γ[1].ch_t.q2_1[i, w, v] + a_l.Γ[1].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[2].ch_t.q2_1[i, w, v] += a_l.Γ[2].ch_t.q2_1[i, w, v] + a_l.Γ[2].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[1].ch_t.q2_2[i, w, v] += a_l.Γ[1].ch_t.q2_2[i, w, v] + a_l.Γ[1].ch_t.q2_1[r.exchange[i], w, v]
a.Γ[2].ch_t.q2_2[i, w, v] += a_l.Γ[2].ch_t.q2_2[i, w, v] + a_l.Γ[2].ch_t.q2_1[r.exchange[i], w, v]
# add q2_1 and q2_2 to u channel (right part from v <-> v' exchange)
a.Γ[1].ch_u.q2_1[i, w, v] += a_l.Γ[1].ch_u.q2_1[i, w, v] + a_l.Γ[1].ch_u.q2_2[i, w, v]
a.Γ[2].ch_u.q2_1[i, w, v] += a_l.Γ[2].ch_u.q2_1[i, w, v] + a_l.Γ[2].ch_u.q2_2[i, w, v]
a.Γ[1].ch_u.q2_2[i, w, v] += a_l.Γ[1].ch_u.q2_2[i, w, v] + a_l.Γ[1].ch_u.q2_1[i, w, v]
a.Γ[2].ch_u.q2_2[i, w, v] += a_l.Γ[2].ch_u.q2_2[i, w, v] + a_l.Γ[2].ch_u.q2_1[i, w, v]
end
end
end
# computation for q3
@turbo for vp in 1 : num_ν
for v in 1 : num_ν
for w in 1 : num_Ω
for i in 1 : num_sites
# add q3 to s channel (right part from v <-> v' exchange)
a.Γ[1].ch_s.q3[i, w, v, vp] += a_l.Γ[1].ch_s.q3[i, w, v, vp] + a_l.Γ[1].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_s.q3[i, w, v, vp] += a_l.Γ[2].ch_s.q3[i, w, v, vp] + a_l.Γ[2].ch_s.q3[r.exchange[i], w, vp, v]
# add q3 to t channel (right part from v <-> v' exchange)
a.Γ[1].ch_t.q3[i, w, v, vp] += a_l.Γ[1].ch_t.q3[i, w, v, vp] + a_l.Γ[1].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_t.q3[i, w, v, vp] += a_l.Γ[2].ch_t.q3[i, w, v, vp] + a_l.Γ[2].ch_t.q3[r.exchange[i], w, vp, v]
# add q3 to u channel (right part from v <-> v' exchange)
a.Γ[1].ch_u.q3[i, w, v, vp] += a_l.Γ[1].ch_u.q3[i, w, v, vp] + a_l.Γ[1].ch_u.q3[i, w, vp, v]
a.Γ[2].ch_u.q3[i, w, v, vp] += a_l.Γ[2].ch_u.q3[i, w, v, vp] + a_l.Γ[2].ch_u.q3[i, w, vp, v]
end
end
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 16042 | """
Action_u1_dm <: Action
Struct containing self energy and vertex components for models with U(1) symmetric Dzyaloshinskii-Moriya interaction.
* `Σ :: Vector{Float64}` : negative imaginary part of the self energy
* `Γ :: Vector{Vertex}` : Γxx, Γzz, ΓDM (i.e Γxy), Γdd, Γzd, Γdz component of the full vertex
"""
struct Action_u1_dm <: Action
Σ :: Vector{Float64}
Γ :: Vector{Vertex}
end
# generate action_u1_dm dummy
function get_action_u1_dm_empty(
r :: Reduced_lattice,
m :: Mesh,
) :: Action_u1_dm
# init self energy
Σ = zeros(Float64, length(m.σ))
# init vertices
Γ = Vertex[get_vertex_empty(r, m) for comp in 1 : 6]
# build action
a = Action_u1_dm(Σ, Γ)
return a
end
# init action for symmetric u1 models
function init_action!(
l :: Lattice,
r :: Reduced_lattice,
a :: Action_u1_dm
) :: Nothing
# init bare action for Γxx, Γzz and ΓDM component
ref_int = SVector{4, Int64}(0, 0, 0, 1)
ref = Site(ref_int, get_vec(ref_int, l.uc))
for i in eachindex(r.sites)
# get bond from lattice
b = get_bond(ref, r.sites[i], l)
# set Γxx bare according to spin exchange
a.Γ[1].bare[i] = b.exchange[1, 1] / 4.0
# set Γzz bare according to spin exchange
a.Γ[2].bare[i] = b.exchange[3, 3] / 4.0
# set ΓDM bare according to spin exchange
a.Γ[3].bare[i] = b.exchange[1, 2] / 4.0
end
return nothing
end
# set repulsion for u1-dm symmetry
function set_repulsion!(
A :: Float64,
a :: Action_u1_dm
) :: Nothing
# init bare action on-site with level repulsion for Γxx
a.Γ[1].bare[1] = A / 4.0
# init bare action on-site with level repulsion for Γzz
a.Γ[2].bare[1] = A / 4.0
return nothing
end
# helper function to disentangle flags during interpolation for u1 symmetric dm models
function apply_flags_u1_dm(
b :: Buffer,
comp :: Int64
) :: Tuple{Float64, Int64}
# clarify sign of contribution
sgn = 1.0
# ξ(μ) * ξ(ν) = -1 for Γzd & Γdz
if comp in (5, 6) && b.sgn_μν
sgn *= -1.0
end
# -ξ(μ) = -1 for Γdd & Γdz
if comp in (4, 6) && b.sgn_μ
sgn *= -1.0
end
# -ξ(ν) = -1 for Γdd & Γzd
if comp in (4, 5) && b.sgn_ν
sgn *= -1.0
end
# clarify which component to interpolate
if b.exchange_flag
# ΓDM -> -ΓDM for spin exchange (since ΓDM = Γxy = -Γyx)
if comp == 3
sgn *= -1.0
# Γzd -> Γdz for spin exchange
elseif comp == 5
comp = 6
# Γdz -> Γzd for spin exchange
elseif comp == 6
comp = 5
end
end
return sgn, comp
end
# get all interpolated vertex components for u1 symmetric dm models
function get_Γ(
site :: Int64,
bs :: Buffer,
bt :: Buffer,
bu :: Buffer,
r :: Reduced_lattice,
a :: Action_u1_dm
;
ch_s :: Bool = true,
ch_t :: Bool = true,
ch_u :: Bool = true
) :: NTuple{6, Float64}
Γxx = get_Γ_comp(1, site, bs, bt, bu, r, a, apply_flags_u1_dm, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
Γzz = get_Γ_comp(2, site, bs, bt, bu, r, a, apply_flags_u1_dm, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
ΓDM = get_Γ_comp(3, site, bs, bt, bu, r, a, apply_flags_u1_dm, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
Γdd = get_Γ_comp(4, site, bs, bt, bu, r, a, apply_flags_u1_dm, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
Γzd = get_Γ_comp(5, site, bs, bt, bu, r, a, apply_flags_u1_dm, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
Γdz = get_Γ_comp(6, site, bs, bt, bu, r, a, apply_flags_u1_dm, ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
return Γxx, Γzz, ΓDM, Γdd, Γzd, Γdz
end
# get all interpolated vertex components for u1 symmetric dm models on all lattice sites
function get_Γ_avx!(
r :: Reduced_lattice,
bs :: Buffer,
bt :: Buffer,
bu :: Buffer,
a :: Action_u1_dm,
temp :: Array{Float64, 3},
index :: Int64
;
ch_s :: Bool = true,
ch_t :: Bool = true,
ch_u :: Bool = true
) :: Nothing
for comp in 1 : 6
get_Γ_comp_avx!(comp, r, bs, bt, bu, a, apply_flags_u1_dm, view(temp, :, comp, index), ch_s = ch_s, ch_t = ch_t, ch_u = ch_u)
end
return nothing
end
# symmetrize full loop contribution and central part
function symmetrize!(
r :: Reduced_lattice,
a :: Action_u1_dm
) :: Nothing
# get dimensions
num_sites = size(a.Γ[1].ch_s.q2_1, 1)
num_Ω = size(a.Γ[1].ch_s.q2_1, 2)
num_ν = size(a.Γ[1].ch_s.q2_1, 3)
# computation for q3
for v in 1 : num_ν
for vp in v + 1 : num_ν
@turbo for w in 1 : num_Ω
for i in 1 : num_sites
# get upper triangular matrix for (v, v') plane for s channel
a.Γ[1].ch_s.q3[i, w, v, vp] = a.Γ[1].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_s.q3[i, w, v, vp] = a.Γ[2].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[3].ch_s.q3[i, w, v, vp] = -a.Γ[3].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[4].ch_s.q3[i, w, v, vp] = a.Γ[4].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[5].ch_s.q3[i, w, v, vp] = -a.Γ[6].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[6].ch_s.q3[i, w, v, vp] = -a.Γ[5].ch_s.q3[r.exchange[i], w, vp, v]
# get upper triangular matrix for (v, v') plane for t channel
a.Γ[1].ch_t.q3[i, w, v, vp] = a.Γ[1].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_t.q3[i, w, v, vp] = a.Γ[2].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[3].ch_t.q3[i, w, v, vp] = -a.Γ[3].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[4].ch_t.q3[i, w, v, vp] = a.Γ[4].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[5].ch_t.q3[i, w, v, vp] = -a.Γ[6].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[6].ch_t.q3[i, w, v, vp] = -a.Γ[5].ch_t.q3[r.exchange[i], w, vp, v]
# get upper triangular matrix for (v, v') plane for u channel
a.Γ[1].ch_u.q3[i, w, v, vp] = a.Γ[1].ch_u.q3[i, w, vp, v]
a.Γ[2].ch_u.q3[i, w, v, vp] = a.Γ[2].ch_u.q3[i, w, vp, v]
a.Γ[3].ch_u.q3[i, w, v, vp] = a.Γ[3].ch_u.q3[i, w, vp, v]
a.Γ[4].ch_u.q3[i, w, v, vp] = a.Γ[4].ch_u.q3[i, w, vp, v]
a.Γ[5].ch_u.q3[i, w, v, vp] = -a.Γ[5].ch_u.q3[i, w, vp, v]
a.Γ[6].ch_u.q3[i, w, v, vp] = -a.Γ[6].ch_u.q3[i, w, vp, v]
end
end
end
end
return nothing
end
# symmetrized addition for left part (right part symmetric to left part)
function symmetrize_add_to!(
r :: Reduced_lattice,
a_l :: Action_u1_dm,
a :: Action_u1_dm
) :: Nothing
# get dimensions
num_sites = size(a_l.Γ[1].ch_s.q2_1, 1)
num_Ω = size(a_l.Γ[1].ch_s.q2_1, 2)
num_ν = size(a_l.Γ[1].ch_s.q2_1, 3)
# computation for q1
@turbo for w in 1 : num_Ω
for i in 1 : num_sites
# add q1 to s channel (right part from v <-> v' exchange)
a.Γ[1].ch_s.q1[i, w] += a_l.Γ[1].ch_s.q1[i, w] + a_l.Γ[1].ch_s.q1[r.exchange[i], w]
a.Γ[2].ch_s.q1[i, w] += a_l.Γ[2].ch_s.q1[i, w] + a_l.Γ[2].ch_s.q1[r.exchange[i], w]
a.Γ[3].ch_s.q1[i, w] += a_l.Γ[3].ch_s.q1[i, w] - a_l.Γ[3].ch_s.q1[r.exchange[i], w]
a.Γ[4].ch_s.q1[i, w] += a_l.Γ[4].ch_s.q1[i, w] + a_l.Γ[4].ch_s.q1[r.exchange[i], w]
a.Γ[5].ch_s.q1[i, w] += a_l.Γ[5].ch_s.q1[i, w] - a_l.Γ[6].ch_s.q1[r.exchange[i], w]
a.Γ[6].ch_s.q1[i, w] += a_l.Γ[6].ch_s.q1[i, w] - a_l.Γ[5].ch_s.q1[r.exchange[i], w]
# add q1 to t channel (right part from v <-> v' exchange)
a.Γ[1].ch_t.q1[i, w] += a_l.Γ[1].ch_t.q1[i, w] + a_l.Γ[1].ch_t.q1[r.exchange[i], w]
a.Γ[2].ch_t.q1[i, w] += a_l.Γ[2].ch_t.q1[i, w] + a_l.Γ[2].ch_t.q1[r.exchange[i], w]
a.Γ[3].ch_t.q1[i, w] += a_l.Γ[3].ch_t.q1[i, w] - a_l.Γ[3].ch_t.q1[r.exchange[i], w]
a.Γ[4].ch_t.q1[i, w] += a_l.Γ[4].ch_t.q1[i, w] + a_l.Γ[4].ch_t.q1[r.exchange[i], w]
a.Γ[5].ch_t.q1[i, w] += a_l.Γ[5].ch_t.q1[i, w] - a_l.Γ[6].ch_t.q1[r.exchange[i], w]
a.Γ[6].ch_t.q1[i, w] += a_l.Γ[6].ch_t.q1[i, w] - a_l.Γ[5].ch_t.q1[r.exchange[i], w]
# add q1 to u channel (right part from v <-> v' exchange)
a.Γ[1].ch_u.q1[i, w] += a_l.Γ[1].ch_u.q1[i, w] + a_l.Γ[1].ch_u.q1[i, w]
a.Γ[2].ch_u.q1[i, w] += a_l.Γ[2].ch_u.q1[i, w] + a_l.Γ[2].ch_u.q1[i, w]
a.Γ[3].ch_u.q1[i, w] += a_l.Γ[3].ch_u.q1[i, w] + a_l.Γ[3].ch_u.q1[i, w]
a.Γ[4].ch_u.q1[i, w] += a_l.Γ[4].ch_u.q1[i, w] + a_l.Γ[4].ch_u.q1[i, w]
a.Γ[5].ch_u.q1[i, w] += a_l.Γ[5].ch_u.q1[i, w] - a_l.Γ[5].ch_u.q1[i, w]
a.Γ[6].ch_u.q1[i, w] += a_l.Γ[6].ch_u.q1[i, w] - a_l.Γ[6].ch_u.q1[i, w]
end
end
# computation for q2_1 and q2_2
@turbo for v in 1 : num_ν
for w in 1 : num_Ω
for i in 1 : num_sites
# add q2_1 and q2_2 to s channel (right part from v <-> v' exchange)
a.Γ[1].ch_s.q2_1[i, w, v] += a_l.Γ[1].ch_s.q2_1[i, w, v] + a_l.Γ[1].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[2].ch_s.q2_1[i, w, v] += a_l.Γ[2].ch_s.q2_1[i, w, v] + a_l.Γ[2].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[3].ch_s.q2_1[i, w, v] += a_l.Γ[3].ch_s.q2_1[i, w, v] - a_l.Γ[3].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[4].ch_s.q2_1[i, w, v] += a_l.Γ[4].ch_s.q2_1[i, w, v] + a_l.Γ[4].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[5].ch_s.q2_1[i, w, v] += a_l.Γ[5].ch_s.q2_1[i, w, v] - a_l.Γ[6].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[6].ch_s.q2_1[i, w, v] += a_l.Γ[6].ch_s.q2_1[i, w, v] - a_l.Γ[5].ch_s.q2_2[r.exchange[i], w, v]
a.Γ[1].ch_s.q2_2[i, w, v] += a_l.Γ[1].ch_s.q2_2[i, w, v] + a_l.Γ[1].ch_s.q2_1[r.exchange[i], w, v]
a.Γ[2].ch_s.q2_2[i, w, v] += a_l.Γ[2].ch_s.q2_2[i, w, v] + a_l.Γ[2].ch_s.q2_1[r.exchange[i], w, v]
a.Γ[3].ch_s.q2_2[i, w, v] += a_l.Γ[3].ch_s.q2_2[i, w, v] - a_l.Γ[3].ch_s.q2_1[r.exchange[i], w, v]
a.Γ[4].ch_s.q2_2[i, w, v] += a_l.Γ[4].ch_s.q2_2[i, w, v] + a_l.Γ[4].ch_s.q2_1[r.exchange[i], w, v]
a.Γ[5].ch_s.q2_2[i, w, v] += a_l.Γ[5].ch_s.q2_2[i, w, v] - a_l.Γ[6].ch_s.q2_1[r.exchange[i], w, v]
a.Γ[6].ch_s.q2_2[i, w, v] += a_l.Γ[6].ch_s.q2_2[i, w, v] - a_l.Γ[5].ch_s.q2_1[r.exchange[i], w, v]
# add q2_1 and q2_2 to t channel (right part from v <-> v' exchange)
a.Γ[1].ch_t.q2_1[i, w, v] += a_l.Γ[1].ch_t.q2_1[i, w, v] + a_l.Γ[1].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[2].ch_t.q2_1[i, w, v] += a_l.Γ[2].ch_t.q2_1[i, w, v] + a_l.Γ[2].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[3].ch_t.q2_1[i, w, v] += a_l.Γ[3].ch_t.q2_1[i, w, v] - a_l.Γ[3].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[4].ch_t.q2_1[i, w, v] += a_l.Γ[4].ch_t.q2_1[i, w, v] + a_l.Γ[4].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[5].ch_t.q2_1[i, w, v] += a_l.Γ[5].ch_t.q2_1[i, w, v] - a_l.Γ[6].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[6].ch_t.q2_1[i, w, v] += a_l.Γ[6].ch_t.q2_1[i, w, v] - a_l.Γ[5].ch_t.q2_2[r.exchange[i], w, v]
a.Γ[1].ch_t.q2_2[i, w, v] += a_l.Γ[1].ch_t.q2_2[i, w, v] + a_l.Γ[1].ch_t.q2_1[r.exchange[i], w, v]
a.Γ[2].ch_t.q2_2[i, w, v] += a_l.Γ[2].ch_t.q2_2[i, w, v] + a_l.Γ[2].ch_t.q2_1[r.exchange[i], w, v]
a.Γ[3].ch_t.q2_2[i, w, v] += a_l.Γ[3].ch_t.q2_2[i, w, v] - a_l.Γ[3].ch_t.q2_1[r.exchange[i], w, v]
a.Γ[4].ch_t.q2_2[i, w, v] += a_l.Γ[4].ch_t.q2_2[i, w, v] + a_l.Γ[4].ch_t.q2_1[r.exchange[i], w, v]
a.Γ[5].ch_t.q2_2[i, w, v] += a_l.Γ[5].ch_t.q2_2[i, w, v] - a_l.Γ[6].ch_t.q2_1[r.exchange[i], w, v]
a.Γ[6].ch_t.q2_2[i, w, v] += a_l.Γ[6].ch_t.q2_2[i, w, v] - a_l.Γ[5].ch_t.q2_1[r.exchange[i], w, v]
# add q2_1 and q2_2 to u channel (right part from v <-> v' exchange)
a.Γ[1].ch_u.q2_1[i, w, v] += a_l.Γ[1].ch_u.q2_1[i, w, v] + a_l.Γ[1].ch_u.q2_2[i, w, v]
a.Γ[2].ch_u.q2_1[i, w, v] += a_l.Γ[2].ch_u.q2_1[i, w, v] + a_l.Γ[2].ch_u.q2_2[i, w, v]
a.Γ[3].ch_u.q2_1[i, w, v] += a_l.Γ[3].ch_u.q2_1[i, w, v] + a_l.Γ[3].ch_u.q2_2[i, w, v]
a.Γ[4].ch_u.q2_1[i, w, v] += a_l.Γ[4].ch_u.q2_1[i, w, v] + a_l.Γ[4].ch_u.q2_2[i, w, v]
a.Γ[5].ch_u.q2_1[i, w, v] += a_l.Γ[5].ch_u.q2_1[i, w, v] - a_l.Γ[5].ch_u.q2_2[i, w, v]
a.Γ[6].ch_u.q2_1[i, w, v] += a_l.Γ[6].ch_u.q2_1[i, w, v] - a_l.Γ[6].ch_u.q2_2[i, w, v]
a.Γ[1].ch_u.q2_2[i, w, v] += a_l.Γ[1].ch_u.q2_2[i, w, v] + a_l.Γ[1].ch_u.q2_1[i, w, v]
a.Γ[2].ch_u.q2_2[i, w, v] += a_l.Γ[2].ch_u.q2_2[i, w, v] + a_l.Γ[2].ch_u.q2_1[i, w, v]
a.Γ[3].ch_u.q2_2[i, w, v] += a_l.Γ[3].ch_u.q2_2[i, w, v] + a_l.Γ[3].ch_u.q2_1[i, w, v]
a.Γ[4].ch_u.q2_2[i, w, v] += a_l.Γ[4].ch_u.q2_2[i, w, v] + a_l.Γ[4].ch_u.q2_1[i, w, v]
a.Γ[5].ch_u.q2_2[i, w, v] += a_l.Γ[5].ch_u.q2_2[i, w, v] - a_l.Γ[5].ch_u.q2_1[i, w, v]
a.Γ[6].ch_u.q2_2[i, w, v] += a_l.Γ[6].ch_u.q2_2[i, w, v] - a_l.Γ[6].ch_u.q2_1[i, w, v]
end
end
end
# computation for q3
@turbo for vp in 1 : num_ν
for v in 1 : num_ν
for w in 1 : num_Ω
for i in 1 : num_sites
# add q3 to s channel (right part from v <-> v' exchange)
a.Γ[1].ch_s.q3[i, w, v, vp] += a_l.Γ[1].ch_s.q3[i, w, v, vp] + a_l.Γ[1].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_s.q3[i, w, v, vp] += a_l.Γ[2].ch_s.q3[i, w, v, vp] + a_l.Γ[2].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[3].ch_s.q3[i, w, v, vp] += a_l.Γ[3].ch_s.q3[i, w, v, vp] - a_l.Γ[3].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[4].ch_s.q3[i, w, v, vp] += a_l.Γ[4].ch_s.q3[i, w, v, vp] + a_l.Γ[4].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[5].ch_s.q3[i, w, v, vp] += a_l.Γ[5].ch_s.q3[i, w, v, vp] - a_l.Γ[6].ch_s.q3[r.exchange[i], w, vp, v]
a.Γ[6].ch_s.q3[i, w, v, vp] += a_l.Γ[6].ch_s.q3[i, w, v, vp] - a_l.Γ[5].ch_s.q3[r.exchange[i], w, vp, v]
# add q3 to t channel (right part from v <-> v' exchange)
a.Γ[1].ch_t.q3[i, w, v, vp] += a_l.Γ[1].ch_t.q3[i, w, v, vp] + a_l.Γ[1].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[2].ch_t.q3[i, w, v, vp] += a_l.Γ[2].ch_t.q3[i, w, v, vp] + a_l.Γ[2].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[3].ch_t.q3[i, w, v, vp] += a_l.Γ[3].ch_t.q3[i, w, v, vp] - a_l.Γ[3].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[4].ch_t.q3[i, w, v, vp] += a_l.Γ[4].ch_t.q3[i, w, v, vp] + a_l.Γ[4].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[5].ch_t.q3[i, w, v, vp] += a_l.Γ[5].ch_t.q3[i, w, v, vp] - a_l.Γ[6].ch_t.q3[r.exchange[i], w, vp, v]
a.Γ[6].ch_t.q3[i, w, v, vp] += a_l.Γ[6].ch_t.q3[i, w, v, vp] - a_l.Γ[5].ch_t.q3[r.exchange[i], w, vp, v]
# add q3 to u channel (right part from v <-> v' exchange)
a.Γ[1].ch_u.q3[i, w, v, vp] += a_l.Γ[1].ch_u.q3[i, w, v, vp] + a_l.Γ[1].ch_u.q3[i, w, vp, v]
a.Γ[2].ch_u.q3[i, w, v, vp] += a_l.Γ[2].ch_u.q3[i, w, v, vp] + a_l.Γ[2].ch_u.q3[i, w, vp, v]
a.Γ[3].ch_u.q3[i, w, v, vp] += a_l.Γ[3].ch_u.q3[i, w, v, vp] + a_l.Γ[3].ch_u.q3[i, w, vp, v]
a.Γ[4].ch_u.q3[i, w, v, vp] += a_l.Γ[4].ch_u.q3[i, w, v, vp] + a_l.Γ[4].ch_u.q3[i, w, vp, v]
a.Γ[5].ch_u.q3[i, w, v, vp] += a_l.Γ[5].ch_u.q3[i, w, v, vp] - a_l.Γ[5].ch_u.q3[i, w, vp, v]
a.Γ[6].ch_u.q3[i, w, v, vp] += a_l.Γ[6].ch_u.q3[i, w, v, vp] - a_l.Γ[6].ch_u.q3[i, w, vp, v]
end
end
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1938 | # save current status to file
function checkpoint!(
file :: HDF5.File,
Λ :: Float64,
dΛ :: Float64,
m :: Mesh,
a :: Action_su2
) :: Nothing
# save step size
file["dΛ/$(Λ)"] = dΛ
# save frequency meshes
file["σ/$(Λ)"] = m.σ
file["Ωs/$(Λ)"] = m.Ωs
file["νs/$(Λ)"] = m.νs
file["Ωt/$(Λ)"] = m.Ωt
file["νt/$(Λ)"] = m.νt
file["χ/$(Λ)"] = m.χ
# save spin length
if haskey(file, "S") == false
file["S"] = a.S
end
# save symmetry group
if haskey(file, "symmetry") == false
file["symmetry"] = "su2"
end
# save self energy
file["a/$(Λ)/Σ"] = a.Σ
# save vertex
save!(file, "a/$(Λ)/Γ/spin", a.Γ[1])
save!(file, "a/$(Λ)/Γ/dens", a.Γ[2])
return nothing
end
# read checkpoint from file
function read_checkpoint_su2(
file :: HDF5.File,
Λ :: Float64
) :: Tuple{Float64, Float64, Mesh, Action_su2}
# filter out nearest available cutoff
list = keys(file["σ"])
cutoffs = parse.(Float64, list)
index = argmin(abs.(cutoffs .- Λ))
println("Λ was adjusted to $(cutoffs[index]).")
# read step size
dΛ = read(file, "dΛ/$(cutoffs[index])")
# read frequency meshes
σ = read(file, "σ/$(cutoffs[index])")
Ωs = read(file, "Ωs/$(cutoffs[index])")
νs = read(file, "νs/$(cutoffs[index])")
Ωt = read(file, "Ωt/$(cutoffs[index])")
νt = read(file, "νt/$(cutoffs[index])")
χ = read(file, "χ/$(cutoffs[index])")
m = Mesh(length(σ), length(Ωs), length(νs), length(χ), σ, Ωs, νs, Ωt, νt, χ)
# read spin length
S = read(file, "S")
# read self energy
Σ = read(file, "a/$(cutoffs[index])/Σ")
# read vertex
Γ = Vertex[read_vertex(file, "a/$(cutoffs[index])/Γ/spin"),
read_vertex(file, "a/$(cutoffs[index])/Γ/dens")]
# build action
a = Action_su2(S, Σ, Γ)
return cutoffs[index], dΛ, m, a
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 2214 | # save current status to file
function checkpoint!(
file :: HDF5.File,
Λ :: Float64,
dΛ :: Float64,
m :: Mesh,
a :: Action_u1_dm
) :: Nothing
# save step size
file["dΛ/$(Λ)"] = dΛ
# save frequency meshes
file["σ/$(Λ)"] = m.σ
file["Ωs/$(Λ)"] = m.Ωs
file["νs/$(Λ)"] = m.νs
file["Ωt/$(Λ)"] = m.Ωt
file["νt/$(Λ)"] = m.νt
file["χ/$(Λ)"] = m.χ
# save symmetry group
if haskey(file, "symmetry") == false
file["symmetry"] = "u1-dm"
end
# save self energy
file["a/$(Λ)/Σ"] = a.Σ
# save vertex
save!(file, "a/$(Λ)/Γ/Γxx", a.Γ[1])
save!(file, "a/$(Λ)/Γ/Γzz", a.Γ[2])
save!(file, "a/$(Λ)/Γ/ΓDM", a.Γ[3])
save!(file, "a/$(Λ)/Γ/Γdd", a.Γ[4])
save!(file, "a/$(Λ)/Γ/Γzd", a.Γ[5])
save!(file, "a/$(Λ)/Γ/Γdz", a.Γ[6])
return nothing
end
# read checkpoint from file
function read_checkpoint_u1_dm(
file :: HDF5.File,
Λ :: Float64
) :: Tuple{Float64, Float64, Mesh, Action_u1_dm}
# filter out nearest available cutoff
list = keys(file["σ"])
cutoffs = parse.(Float64, list)
index = argmin(abs.(cutoffs .- Λ))
println("Λ was adjusted to $(cutoffs[index]).")
# read step size
dΛ = read(file, "dΛ/$(cutoffs[index])")
# read frequency meshes
σ = read(file, "σ/$(cutoffs[index])")
Ωs = read(file, "Ωs/$(cutoffs[index])")
νs = read(file, "νs/$(cutoffs[index])")
Ωt = read(file, "Ωt/$(cutoffs[index])")
νt = read(file, "νt/$(cutoffs[index])")
χ = read(file, "χ/$(cutoffs[index])")
m = Mesh(length(σ), length(Ωs), length(νs), length(χ), σ, Ωs, νs, Ωt, νt, χ)
# read self energy
Σ = read(file, "a/$(cutoffs[index])/Σ")
# read vertex
Γ = Vertex[read_vertex(file, "a/$(cutoffs[index])/Γ/Γxx"),
read_vertex(file, "a/$(cutoffs[index])/Γ/Γzz"),
read_vertex(file, "a/$(cutoffs[index])/Γ/ΓDM"),
read_vertex(file, "a/$(cutoffs[index])/Γ/Γdd"),
read_vertex(file, "a/$(cutoffs[index])/Γ/Γzd"),
read_vertex(file, "a/$(cutoffs[index])/Γ/Γdz")]
# build action
a = Action_u1_dm(Σ, Γ)
return cutoffs[index], dΛ, m, a
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1889 | # compute the BSE in the s channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_s_BSE!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action,
a2 :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
s, vs, vsp = get_kernel_args(1, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_s_BSE!(Λ, b, v, dv, s, vs, vsp, r, m, a1, temp)
# compute integrals
ref = Λ + 0.5 * s
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 1, w1])
integrand!(tbuff[1], val, corrs[2, 1, w1])
# parse result
for i in eachindex(a2.Γ)
if kernel == 1
@turbo a2.Γ[i].ch_s.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo a2.Γ[i].ch_s.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo a2.Γ[i].ch_s.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo a2.Γ[i].ch_s.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1888 | # compute the BSE in the t channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_t_BSE!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action,
a2 :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
t, vt, vtp = get_kernel_args(2, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_t_BSE!(Λ, b, v, dv, t, vt, vtp, r, m, a1, temp)
# compute integral
ref = Λ + 0.5 * t
val = m.Ωt[end] + m.νt[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 2, w1])
integrand!(tbuff[1], val, corrs[2, 2, w1])
# parse result
for i in eachindex(a2.Γ)
if kernel == 1
@turbo a2.Γ[i].ch_t.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo a2.Γ[i].ch_t.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo a2.Γ[i].ch_t.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo a2.Γ[i].ch_t.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1888 | # compute the BSE in the u channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_u_BSE!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action,
a2 :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
u, vu, vup = get_kernel_args(3, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_u_BSE!(Λ, b, v, dv, u, vu, vup, r, m, a1, temp)
# compute integral
ref = Λ + 0.5 * u
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 3, w1])
integrand!(tbuff[1], val, corrs[2, 3, w1])
# parse result
for i in eachindex(a2.Γ)
if kernel == 1
@turbo a2.Γ[i].ch_u.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo a2.Γ[i].ch_u.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo a2.Γ[i].ch_u.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo a2.Γ[i].ch_u.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 941 | # load propagator bubbles
include("bubbles.jl")
# load parquet equations for different symmetries
include("parquet_lib/parquet_su2/parquet_su2.jl")
include("parquet_lib/parquet_u1_dm/parquet_u1_dm.jl")
# load flow equations for different symmetries
include("flow_lib/flow_su2/flow_su2.jl")
include("flow_lib/flow_u1_dm/flow_u1_dm.jl")
# load quadrature rule for vertex integration
include("quadrature.jl")
# load SDE computation
include("SDE.jl")
# load BSE computation of channels for frequency tuples (w1, w2, w3) and kernels k
include("BSE_s.jl")
include("BSE_t.jl")
include("BSE_u.jl")
# load self energy derivative calculation
include("flow_self.jl")
# load flow computation of channels for frequency tuples (w1, w2, w3) and kernels k
include("flow_s.jl")
include("flow_t.jl")
include("flow_u.jl")
# load full BSE and flow computation
include("compute.jl")
# load tests and timers
include("test.jl")
include("timers.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3029 | # compute reduced s bubble
function compute_channel_s_reduced!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action,
a2 :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
s, vsp = 0.0, 0.0
if kernel == 1
s, vsp = m.Ωs[w1], Inf
else
s, vsp = m.Ωs[w1], m.νs[w3]
end
# define integrand
integrand!(b, v, dv) = compute_s_reduced!(Λ, b, v, dv, s, vsp, r, m, a1, temp)
# compute integrals
ref = Λ + 0.5 * s
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 1, w1])
integrand!(tbuff[1], val, corrs[2, 1, w1])
# parse result
for i in eachindex(a2.Γ)
if kernel == 1
@turbo a2.Γ[i].ch_s.q1[:, w1] .= view(tbuff[1], i, :)
else
@turbo a2.Γ[i].ch_s.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end
# compute self energy from SDE
function compute_Σ!(
Λ :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action,
a2 :: Action,
tbuffs :: Vector{NTuple{3, Matrix{Float64}}},
temps :: Vector{Array{Float64, 3}},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64},
Σ_tol :: NTuple{2, Float64}
) :: Nothing
# compute boundary corrections
compute_corrs!(Λ, m, a1, corrs, Γ_tol)
# compute reduced s bubble in q1 and q2_2
@sync begin
for w1 in 1 : m.num_Ω
# compute q1
Threads.@spawn compute_channel_s_reduced!(Λ, 1, w1, -1, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
for w3 in 1 : m.num_ν
# compute q2_2
Threads.@spawn compute_channel_s_reduced!(Λ, 3, w1, w3, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
end
end
# compute self energy for all frequencies
@sync for i in 2 : length(m.σ)
Threads.@spawn begin
integrand = v -> compute_Σ_kernel(Λ, m.σ[i], v, r, m, a1, a2)
a2.Σ[i] = quadgk(integrand, -Inf, -2.0 * Λ, 0.0, 2.0 * Λ, Inf, atol = Σ_tol[1], rtol = Σ_tol[2])[1]
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 6677 | # get bare propagator
function get_G_bare(
Λ :: Float64,
w :: Float64
) :: Float64
val = 0.0
if abs(w) > 1e-8
val = -expm1(-w^2 / Λ^2) / w
end
return val
end
# get dressed propagator
function get_G(
Λ :: Float64,
w :: Float64,
m :: Mesh,
a :: Action
) :: Float64
val = 0.0
if abs(w) > 1e-8
Σ = get_Σ(w, m, a)
G0 = get_G_bare(Λ, w)
denom = 0.0
# ensure causality
if w * Σ >= 0.0
denom = 1.0 / G0 + Σ
else
denom = 1.0 / G0
end
val = 1.0 / denom
end
return val
end
# get single scale propagator
function get_S(
Λ :: Float64,
w :: Float64,
m :: Mesh,
a :: Action
) :: Float64
val = 0.0
if abs(w) > 1e-8
G = get_G(Λ, w, m, a)
G0 = get_G_bare(Λ, w)
val = (G / G0)^2 * exp(-w^2 / Λ^2) * 2.0 * w / Λ^3
end
return val
end
# get differentiated propagator bubble
function get_propagator_kat(
Λ :: Float64,
w1 :: Float64,
w2 :: Float64,
m :: Mesh,
a :: Action,
da :: Action
) :: Float64
dΣ = get_Σ(w1, m, da)
S1 = get_S(Λ, w1, m, a)
G1 = get_G(Λ, w1, m, a)
G2 = get_G(Λ, w2, m, a)
val = (S1 + G1^2 * dΣ) * G2 / (2.0 * pi)
return val
end
# get undifferentiated propagator bubble
function get_propagator(
Λ :: Float64,
w1 :: Float64,
w2 :: Float64,
m :: Mesh,
a :: Action
) :: Float64
G1 = get_G(Λ, w1, m, a)
G2 = get_G(Λ, w2, m, a)
val = G1 * G2 / (2.0 * pi)
return val
end
# compute boundary corrections for vertex integrals
function compute_corrs_kat!(
Λ :: Float64,
m :: Mesh,
a :: Action,
da :: Action,
corrs :: Array{Float64, 3},
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
@turbo corrs .= 0.0
# compute boundary corrections
@sync for i in size(corrs, 3)
Threads.@spawn begin
# compute boundary corrections for s channel
s_propagator = v -> get_propagator_kat(Λ, v + 0.5 * m.Ωs[i], 0.5 * m.Ωs[i] - v, m, a, da) + get_propagator_kat(Λ, 0.5 * m.Ωs[i] - v, v + 0.5 * m.Ωs[i], m, a, da)
s_val = m.Ωs[end] + m.νs[end]
s_bound_minus = s_propagator(-s_val)
s_bound_plus = s_propagator( s_val)
if abs(s_bound_minus) > 1e-8
corrs[1, 1, i] = quadgk(s_propagator, Inf, -s_val, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / s_bound_minus
end
if abs(s_bound_plus) > 1e-8
corrs[2, 1, i] = quadgk(s_propagator, s_val, Inf, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / s_bound_plus
end
# compute boundary corrections for t channel
t_propagator = v -> get_propagator_kat(Λ, v + 0.5 * m.Ωt[i], v - 0.5 * m.Ωt[i], m, a, da) + get_propagator_kat(Λ, v - 0.5 * m.Ωt[i], v + 0.5 * m.Ωt[i], m, a, da)
t_val = m.Ωt[end] + m.νt[end]
t_bound_minus = t_propagator(-t_val)
t_bound_plus = t_propagator( t_val)
if abs(t_bound_minus) > 1e-8
corrs[1, 2, i] = quadgk(t_propagator, -Inf, -t_val, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / t_bound_minus
end
if abs(t_bound_plus) > 1e-8
corrs[2, 2, i] = quadgk(t_propagator, t_val, Inf, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / t_bound_plus
end
# compute boundary corrections for u channel
u_propagator = v -> get_propagator_kat(Λ, v - 0.5 * m.Ωs[i], v + 0.5 * m.Ωs[i], m, a, da) + get_propagator_kat(Λ, v + 0.5 * m.Ωs[i], v - 0.5 * m.Ωs[i], m, a, da)
u_val = m.Ωs[end] + m.νs[end]
u_bound_minus = u_propagator(-u_val)
u_bound_plus = u_propagator( u_val)
if abs(u_bound_minus) > 1e-8
corrs[1, 3, i] = quadgk(u_propagator, -Inf, -u_val, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / u_bound_minus
end
if abs(u_bound_plus) > 1e-8
corrs[2, 3, i] = quadgk(u_propagator, u_val, Inf, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / u_bound_plus
end
end
end
return nothing
end
# compute boundary corrections for vertex integrals
function compute_corrs!(
Λ :: Float64,
m :: Mesh,
a :: Action,
corrs :: Array{Float64, 3},
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
@turbo corrs .= 0.0
# compute boundary corrections
@sync for i in size(corrs, 3)
Threads.@spawn begin
# compute boundary corrections for s channel
s_propagator = v -> -get_propagator(Λ, v + 0.5 * m.Ωs[i], 0.5 * m.Ωs[i] - v, m, a)
s_val = m.Ωs[end] + m.νs[end]
s_bound_minus = s_propagator(-s_val)
s_bound_plus = s_propagator( s_val)
if abs(s_bound_minus) > 1e-8
corrs[1, 1, i] = quadgk(s_propagator, -Inf, -s_val, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / s_bound_minus
end
if abs(s_bound_plus) > 1e-8
corrs[2, 1, i] = quadgk(s_propagator, s_val, Inf, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / s_bound_plus
end
# compute boundary corrections for t channel
t_propagator = v -> -get_propagator(Λ, v + 0.5 * m.Ωt[i], v - 0.5 * m.Ωt[i], m, a)
t_val = m.Ωt[end] + m.νt[end]
t_bound_minus = t_propagator(-t_val)
t_bound_plus = t_propagator( t_val)
if abs(t_bound_minus) > 1e-8
corrs[1, 2, i] = quadgk(t_propagator, -Inf, -t_val, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / t_bound_minus
end
if abs(t_bound_plus) > 1e-8
corrs[2, 2, i] = quadgk(t_propagator, t_val, Inf, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / t_bound_plus
end
# compute boundary corrections for u channel
u_propagator = v -> -get_propagator(Λ, v - 0.5 * m.Ωs[i], v + 0.5 * m.Ωs[i], m, a)
u_val = m.Ωs[end] + m.νs[end]
u_bound_minus = u_propagator(-u_val)
u_bound_plus = u_propagator( u_val)
if abs(u_bound_minus) > 1e-8
corrs[1, 3, i] = quadgk(u_propagator, -Inf, -u_val, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / u_bound_minus
end
if abs(u_bound_plus) > 1e-8
corrs[2, 3, i] = quadgk(u_propagator, u_val, Inf, atol = Γ_tol[1], rtol = Γ_tol[2])[1] / u_bound_plus
end
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 15109 | # compute the full right side of the BSEs for all channels
function compute_Γ!(
Λ :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action,
a2 :: Action,
tbuffs :: Vector{NTuple{3, Matrix{Float64}}},
temps :: Vector{Array{Float64, 3}},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
@sync begin
for w1 in 1 : m.num_Ω
# compute q1
Threads.@spawn begin
compute_channel_s_BSE!(Λ, 1, w1, -1, -1, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_BSE!(Λ, 1, w1, -1, -1, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_BSE!(Λ, 1, w1, -1, -1, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w3 in 1 : m.num_ν
# compute q2_1
Threads.@spawn begin
compute_channel_s_BSE!(Λ, 2, w1, w3, -1, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_BSE!(Λ, 2, w1, w3, -1, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_BSE!(Λ, 2, w1, w3, -1, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
# compute q2_2
Threads.@spawn begin
compute_channel_s_BSE!(Λ, 3, w1, -1, w3, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_BSE!(Λ, 3, w1, -1, w3, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_BSE!(Λ, 3, w1, -1, w3, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w2 in w3 : m.num_ν
# compute q3
Threads.@spawn begin
compute_channel_s_BSE!(Λ, 4, w1, w2, w3, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_BSE!(Λ, 4, w1, w2, w3, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_BSE!(Λ, 4, w1, w2, w3, r, m, a1, a2, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
end
end
end
end
symmetrize!(r, a2)
return nothing
end
# compute the full right side of the Katanin truncated flow equations for all channels
function compute_dΓ_1l!(
Λ :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
tbuffs :: Vector{NTuple{3, Matrix{Float64}}},
temps :: Vector{Array{Float64, 3}},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# compute boundary corrections
compute_corrs_kat!(Λ, m, a, da, corrs, Γ_tol)
@sync begin
for w1 in 1 : m.num_Ω
# compute q1
Threads.@spawn begin
compute_channel_s_kat!(Λ, 1, w1, -1, -1, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_kat!(Λ, 1, w1, -1, -1, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_kat!(Λ, 1, w1, -1, -1, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w3 in 1 : m.num_ν
# compute q2_1
Threads.@spawn begin
compute_channel_s_kat!(Λ, 2, w1, w3, -1, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_kat!(Λ, 2, w1, w3, -1, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_kat!(Λ, 2, w1, w3, -1, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
# compute q2_2
Threads.@spawn begin
compute_channel_s_kat!(Λ, 3, w1, -1, w3, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_kat!(Λ, 3, w1, -1, w3, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_kat!(Λ, 3, w1, -1, w3, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w2 in w3 : m.num_ν
# compute q3
Threads.@spawn begin
compute_channel_s_kat!(Λ, 4, w1, w2, w3, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_kat!(Λ, 4, w1, w2, w3, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_kat!(Λ, 4, w1, w2, w3, r, m, a, da, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
end
end
end
end
symmetrize!(r, da)
return nothing
end
# compute the full right side of the two loop truncated flow equations for all channels
function compute_dΓ_2l!(
Λ :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
da_l :: Action,
tbuffs :: Vector{NTuple{3, Matrix{Float64}}},
temps :: Vector{Array{Float64, 3}},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# compute one loop
compute_dΓ_1l!(Λ, r, m, a, da, tbuffs, temps, corrs, eval, Γ_tol)
# compute boundary corrections
compute_corrs!(Λ, m, a, corrs, Γ_tol)
@sync begin
for w1 in 1 : m.num_Ω
# compute q1
Threads.@spawn begin
compute_channel_s_left!(Λ, 1, w1, -1, -1, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 1, w1, -1, -1, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 1, w1, -1, -1, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w3 in 1 : m.num_ν
# compute q2_1
Threads.@spawn begin
compute_channel_s_left!(Λ, 2, w1, w3, -1, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 2, w1, w3, -1, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 2, w1, w3, -1, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
# compute q2_2
Threads.@spawn begin
compute_channel_s_left!(Λ, 3, w1, -1, w3, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 3, w1, -1, w3, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 3, w1, -1, w3, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w2 in 1 : m.num_ν
# compute q3
Threads.@spawn begin
compute_channel_s_left!(Λ, 4, w1, w2, w3, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 4, w1, w2, w3, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 4, w1, w2, w3, r, m, a, da, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
end
end
end
end
symmetrize_add_to!(r, da_l, da)
return nothing
end
# compute the full right side of the multiloop truncated flow equations for all channels
function compute_dΓ_ml!(
Λ :: Float64,
r :: Reduced_lattice,
m :: Mesh,
loops :: Int64,
a :: Action,
da :: Action,
da_l :: Action,
da_c :: Action,
da_temp :: Action,
da_Σ :: Action,
tbuffs :: Vector{NTuple{3, Matrix{Float64}}},
temps :: Vector{Array{Float64, 3}},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# compute two loop
compute_dΓ_2l!(Λ, r, m, a, da, da_l, tbuffs, temps, corrs, eval, Γ_tol)
# update temporary buffer and reset terms for self energy corrections
reset_Γ!(da_temp)
reset_Γ!(da_Σ)
symmetrize_add_to!(r, da_l, da_temp)
for loop in 3 : loops
@sync begin
for w1 in 1 : m.num_Ω
# compute q1
Threads.@spawn begin
compute_channel_s_central!(Λ, 1, w1, -1, -1, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_central!(Λ, 1, w1, -1, -1, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_central!(Λ, 1, w1, -1, -1, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w3 in 1 : m.num_ν
# compute q2_1
Threads.@spawn begin
compute_channel_s_central!(Λ, 2, w1, w3, -1, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_central!(Λ, 2, w1, w3, -1, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_central!(Λ, 2, w1, w3, -1, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
# compute q2_2
Threads.@spawn begin
compute_channel_s_central!(Λ, 3, w1, -1, w3, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_central!(Λ, 3, w1, -1, w3, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_central!(Λ, 3, w1, -1, w3, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w2 in w3 : m.num_ν
# compute q3
Threads.@spawn begin
compute_channel_s_central!(Λ, 4, w1, w2, w3, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_central!(Λ, 4, w1, w2, w3, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_central!(Λ, 4, w1, w2, w3, r, m, a, da_l, da_c, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
end
end
end
end
@sync begin
for w1 in 1 : m.num_Ω
# compute q1
Threads.@spawn begin
compute_channel_s_left!(Λ, 1, w1, -1, -1, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 1, w1, -1, -1, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 1, w1, -1, -1, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
for w3 in 1 : m.num_ν
# compute q2_1
Threads.@spawn begin
compute_channel_s_left!(Λ, 2, w1, w3, -1, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 2, w1, w3, -1, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 2, w1, w3, -1, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
# compute q2_2
Threads.@spawn begin
compute_channel_s_left!(Λ, 3, w1, -1, w3, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 3, w1, -1, w3, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 3, w1, -1, w3, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
# compute q3
for w2 in 1 : m.num_ν
Threads.@spawn begin
compute_channel_s_left!(Λ, 4, w1, w2, w3, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_t_left!(Λ, 4, w1, w2, w3, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
compute_channel_u_left!(Λ, 4, w1, w2, w3, r, m, a, da_temp, da_l, tbuffs[Threads.threadid()], temps[Threads.threadid()], corrs, eval, Γ_tol)
end
end
end
end
end
# update temporary buffer
symmetrize!(r, da_c)
replace_with_Γ!(da_temp, da_c)
symmetrize_add_to!(r, da_l, da_temp)
# update self energy corrections and flow
add_to_Γ!(da_c, da_Σ)
add_to_Γ!(da_temp, da)
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 5852 | # compute the Katanin truncated flow equations in the s channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_s_kat!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
s, vs, vsp = get_kernel_args(1, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_s_kat!(Λ, b, v, dv, s, vs, vsp, r, m, a, da, temp)
# compute integrals
ref = Λ + 0.5 * s
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 1, w1])
integrand!(tbuff[1], val, corrs[2, 1, w1])
# parse result
for i in eachindex(da.Γ)
if kernel == 1
@turbo da.Γ[i].ch_s.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da.Γ[i].ch_s.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da.Γ[i].ch_s.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da.Γ[i].ch_s.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end
# compute the left part of the flow equations in the s channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_s_left!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
da_l :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
s, vs, vsp = get_kernel_args(1, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_s_left!(Λ, b, v, dv, s, vs, vsp, r, m, a, da, temp)
# compute integrals
ref = Λ + 0.5 * s
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 1, w1])
integrand!(tbuff[1], val, corrs[2, 1, w1])
# parse result
for i in eachindex(da_l.Γ)
if kernel == 1
@turbo da_l.Γ[i].ch_s.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da_l.Γ[i].ch_s.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da_l.Γ[i].ch_s.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da_l.Γ[i].ch_s.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end
# compute the central part of the flow equations in the s channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_s_central!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da_l :: Action,
da_c :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
s, vs, vsp = get_kernel_args(1, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_s_central!(Λ, b, v, dv, s, vs, vsp, r, m, a, da_l, temp)
# compute integrals
ref = Λ + 0.5 * s
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 1, w1])
integrand!(tbuff[1], val, corrs[2, 1, w1])
# parse result
for i in eachindex(da_c.Γ)
if kernel == 1
@turbo da_c.Γ[i].ch_s.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da_c.Γ[i].ch_s.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da_c.Γ[i].ch_s.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da_c.Γ[i].ch_s.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1535 | # compute self energy derivative
function compute_dΣ!(
Λ :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
Σ_tol :: NTuple{2, Float64}
) :: Nothing
# compute self energy derivative for all frequencies
@sync for i in 2 : length(m.σ)
Threads.@spawn begin
integrand = v -> compute_dΣ_kernel(Λ, m.σ[i], v, r, m, a)
da.Σ[i] = quadgk(integrand, -Inf, -2.0 * Λ, 0.0, 2.0 * Λ, Inf, atol = Σ_tol[1], rtol = Σ_tol[2])[1]
end
end
return nothing
end
# compute corrections to self energy derivative
function compute_dΣ_corr!(
Λ :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
da_Σ :: Action,
Σ_tol :: NTuple{2, Float64}
) :: Nothing
# compute first correction
@sync for i in 2 : length(m.σ)
Threads.@spawn begin
integrand = v -> compute_dΣ_kernel_corr1(Λ, m.σ[i], v, r, m, a, da_Σ)
da_Σ.Σ[i] = quadgk(integrand, -Inf, -2.0 * Λ, 0.0, 2.0 * Λ, Inf, atol = Σ_tol[1], rtol = Σ_tol[2])[1]
end
end
# compute second correction and parse to da
@sync for i in 2 : length(m.σ)
Threads.@spawn begin
integrand = v -> compute_dΣ_kernel_corr2(Λ, m.σ[i], v, r, m, a, da_Σ)
da.Σ[i] += da_Σ.Σ[i]
da.Σ[i] += quadgk(integrand, -Inf, -2.0 * Λ, 0.0, 2.0 * Λ, Inf, atol = Σ_tol[1], rtol = Σ_tol[2])[1]
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 5849 | # compute the Katanin truncated flow equations in the t channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_t_kat!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
t, vt, vtp = get_kernel_args(2, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_t_kat!(Λ, b, v, dv, t, vt, vtp, r, m, a, da, temp)
# compute integral
ref = Λ + 0.5 * t
val = m.Ωt[end] + m.νt[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 2, w1])
integrand!(tbuff[1], val, corrs[2, 2, w1])
# parse result
for i in eachindex(da.Γ)
if kernel == 1
@turbo da.Γ[i].ch_t.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da.Γ[i].ch_t.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da.Γ[i].ch_t.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da.Γ[i].ch_t.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end
# compute the left part of the flow equations in the t channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_t_left!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
da_l :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
t, vt, vtp = get_kernel_args(2, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_t_left!(Λ, b, v, dv, t, vt, vtp, r, m, a, da, temp)
# compute integral
ref = Λ + 0.5 * t
val = m.Ωt[end] + m.νt[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 2, w1])
integrand!(tbuff[1], val, corrs[2, 2, w1])
# parse result
for i in eachindex(da_l.Γ)
if kernel == 1
@turbo da_l.Γ[i].ch_t.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da_l.Γ[i].ch_t.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da_l.Γ[i].ch_t.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da_l.Γ[i].ch_t.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end
# compute the central part of the flow equations in the t channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_t_central!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da_l :: Action,
da_c :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
t, vt, vtp = get_kernel_args(2, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_t_central!(Λ, b, v, dv, t, vt, vtp, r, m, a, da_l, temp)
# compute integral
ref = Λ + 0.5 * t
val = m.Ωt[end] + m.νt[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 2, w1])
integrand!(tbuff[1], val, corrs[2, 2, w1])
# parse result
for i in eachindex(da_c.Γ)
if kernel == 1
@turbo da_c.Γ[i].ch_t.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da_c.Γ[i].ch_t.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da_c.Γ[i].ch_t.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da_c.Γ[i].ch_t.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 5849 | # compute the Katanin truncated flow equations in the u channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_u_kat!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
u, vu, vup = get_kernel_args(3, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_u_kat!(Λ, b, v, dv, u, vu, vup, r, m, a, da, temp)
# compute integral
ref = Λ + 0.5 * u
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 3, w1])
integrand!(tbuff[1], val, corrs[2, 3, w1])
# parse result
for i in eachindex(da.Γ)
if kernel == 1
@turbo da.Γ[i].ch_u.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da.Γ[i].ch_u.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da.Γ[i].ch_u.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da.Γ[i].ch_u.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end
# compute the left part of the flow equations in the u channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_u_left!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da :: Action,
da_l :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
u, vu, vup = get_kernel_args(3, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_u_left!(Λ, b, v, dv, u, vu, vup, r, m, a, da, temp)
# compute integral
ref = Λ + 0.5 * u
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 3, w1])
integrand!(tbuff[1], val, corrs[2, 3, w1])
# parse result
for i in eachindex(da_l.Γ)
if kernel == 1
@turbo da_l.Γ[i].ch_u.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da_l.Γ[i].ch_u.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da_l.Γ[i].ch_u.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da_l.Γ[i].ch_u.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end
# compute the central part of the flow equations in the u channel for a frequency tuple (w1, w2, w3) and a given kernel on all lattice sites
function compute_channel_u_central!(
Λ :: Float64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
da_l :: Action,
da_c :: Action,
tbuff :: NTuple{3, Matrix{Float64}},
temp :: Array{Float64, 3},
corrs :: Array{Float64, 3},
eval :: Int64,
Γ_tol :: NTuple{2, Float64}
) :: Nothing
# reset buffer
tbuff[1] .= 0.0
# get frequency arguments
u, vu, vup = get_kernel_args(3, kernel, w1, w2, w3, m)
# define integrand
integrand!(b, v, dv) = compute_u_central!(Λ, b, v, dv, u, vu, vup, r, m, a, da_l, temp)
# compute integral
ref = Λ + 0.5 * u
val = m.Ωs[end] + m.νs[end]
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2], sgn = -1.0)
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, -2.0 * ref, 0.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_lin!((b, v, dv) -> integrand!(b, v, dv), tbuff, 0.0 * ref, 2.0 * ref, eval, Γ_tol[1], Γ_tol[2])
integrate_log!((b, v, dv) -> integrand!(b, v, dv), tbuff, 2.0 * ref, 1.0 * val, eval, Γ_tol[1], Γ_tol[2])
# correct boundaries
integrand!(tbuff[1], -val, corrs[1, 3, w1])
integrand!(tbuff[1], val, corrs[2, 3, w1])
# parse result
for i in eachindex(da_c.Γ)
if kernel == 1
@turbo da_c.Γ[i].ch_u.q1[:, w1] .= view(tbuff[1], i, :)
elseif kernel == 2
@turbo da_c.Γ[i].ch_u.q2_1[:, w1, w2] .= view(tbuff[1], i, :)
elseif kernel == 3
@turbo da_c.Γ[i].ch_u.q2_2[:, w1, w3] .= view(tbuff[1], i, :)
else
@turbo da_c.Γ[i].ch_u.q3[:, w1, w2, w3] .= view(tbuff[1], i, :)
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 4225 | # auxiliary function to compute necessary contributions for refined Simpson rule
function residual!(
f! :: Function,
buff :: Matrix{Float64},
a :: Float64,
b :: Float64,
n :: Int64
) :: Nothing
# compute refined step size
h = 0.5 * (b - a) / n
# compute integral contributions for new nodes
for i in 1 : n
f!(buff, a + (2.0 * i - 1.0) * h, +4.0 * h / 3.0)
end
# compute integral contributions for reweighted nodes
for i in 1 : n ÷ 2
f!(buff, a + (4.0 * i - 2.0) * h, -2.0 * h / 3.0)
end
return nothing
end
# integrate inplace function over an interval [a, b], with b >= a, using an adaptive Simpson rule with Richardson extrapolation on the converged result
function simps!(
f! :: Function,
buff1 :: Matrix{Float64},
buff2 :: Matrix{Float64},
a :: Float64,
b :: Float64,
atol :: Float64,
rtol :: Float64
) :: Nothing
# reset result buffer
@turbo buff1 .= 0.0
# compute initial approximation
m = 0.5 * (a + b)
f!(buff1, a, 1.0 * (b - a) / 6.0)
f!(buff1, m, 2.0 * (b - a) / 3.0)
f!(buff1, b, 1.0 * (b - a) / 6.0)
# compute improved approximation
@turbo buff2 .= 0.5 .* buff1
residual!((b, x, dx) -> f!(b, x, dx), buff2, a, b, 2)
n = 4
# continue improving the integral approximation until convergence is reached
while true
# perform Richardson extrapolation
@turbo buff1 .*= -1.0 / 15.0
@turbo buff1 .+= 16.0 / 15.0 .* buff2
# compute errors
norm1 = norm(buff1)
norm2 = norm(buff2)
@turbo buff1 .-= buff2
adiff = norm(buff1)
rdiff = adiff / max(norm1, norm2)
# if result has converged or maximum depth (= 20) is reached, terminate
if adiff < atol || rdiff < rtol || n > 2^20
@turbo buff1 .+= buff2
break
end
# update current solution
@turbo buff1 .= buff2
# compute improved approximation
@turbo buff2 .= 0.5 .* buff1
residual!((b, x, dx) -> f!(b, x, dx), buff2, a, b, n)
n *= 2
end
return nothing
end
# integrate inplace function over an interval [a, b], with b >= a, by pre-discretizing the integration domain linearly and applying an adaptive Simpson rule to each subdomain
# note: tbuff[1] is not reset for convenience in flow integration
function integrate_lin!(
f! :: Function,
tbuff :: NTuple{3, Matrix{Float64}},
a :: Float64,
b :: Float64,
eval :: Int64,
atol :: Float64,
rtol :: Float64
) :: Nothing
@assert b >= a "Upper integration bound must be larger than or equal to lower bound."
if b > a
# split integration domain in subdomains of equal length
h = (b - a) / eval
# iterate over subdomains and apply adaptive Simpson rule
for i in 1 : eval
simps!((b, x, dx) -> f!(b, x, dx), tbuff[2], tbuff[3], a + (i - 1) * h, a + i * h, atol, rtol)
tbuff[1] .+= tbuff[2]
end
end
return nothing
end
# integrate inplace function over an interval [a, b], with b >= a and a > 0, by pre-discretizing the integration domain logarithmically and applying an adaptive Simpson rule to each subdomain
# note: tbuff[1] is not reset for convenience in flow integration
# note: the sgn keyword can be usend to map [a, b] -> [-b, -a]
function integrate_log!(
f! :: Function,
tbuff :: NTuple{3, Matrix{Float64}},
a :: Float64,
b :: Float64,
eval :: Int64,
atol :: Float64,
rtol :: Float64
;
sgn :: Float64 = 1.0
) :: Nothing
@assert b >= a "Upper integration bound must be larger than or equal to lower bound."
@assert a > 0.0 "Lower bound must be larger zero."
if b > a
# determine logarithmic factor
ξ = (b / a)^(1.0 / eval)
# iterate over subdomains and apply adaptive Simpson rule
for i in 1 : eval
simps!((b, x, dx) -> f!(b, sgn * x, dx), tbuff[2], tbuff[3], ξ^(i - 1) * a, ξ^i * a, atol, rtol)
tbuff[1] .+= tbuff[2]
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1475 | # define test kernel
function test_kernel!(
b :: Matrix{Float64},
x :: Float64,
dx :: Float64
) :: Nothing
for i in eachindex(b)
b[i] += dx * x^i * exp(-x^2) * sin(2.0 * pi * x)
end
return nothing
end
# define benchmark kernel
function bench_kernel!(
b :: Matrix{Float64},
x :: Float64
) :: Nothing
for i in eachindex(b)
b[i] = x^i * exp(-x^2) * sin(2.0 * pi * x)
end
return nothing
end
"""
test_flow() :: Nothing
Run consistency checks for flow equations by testing integrators.
"""
function test_flow() :: Nothing
# benchmark handcrafted integrators against QuadGK
test_integrators()
return nothing
end
"""
test_integrators() :: Nothing
Run consistency checks for integrators by computing test integrals and comparing to QuadGK.
"""
function test_integrators() :: Nothing
# init test dummys
b1 = zeros(Float64, 10, 10)
b2 = (copy(b1), copy(b1), copy(b1))
b3 = (copy(b1), copy(b1), copy(b1))
@testset "quadrature" begin
# compute integral with QuadGK
quadgk!((b, x) -> bench_kernel!(b, x), b1, 1.0, 5.0, atol = 1e-8, rtol = 1e-8)
# compute integral with simps!
integrate_lin!((b, x, dx) -> test_kernel!(b, x, dx), b2, 1.0, 5.0, 100, 1e-8, 1e-8)
integrate_log!((b, x, dx) -> test_kernel!(b, x, dx), b3, 1.0, 5.0, 100, 1e-8, 1e-8)
@test b1 ≈ b2[1]
@test b1 ≈ b3[1]
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 5620 | # auxiliary function to perform timings for action
function time_kernels!(
to :: TimerOutput,
r :: Reduced_lattice,
m :: Mesh,
a :: Action,
ap :: Action
) :: Nothing
# get timer parameters
Λ = rand()
v = rand()
dv = rand()
wc = rand()
vc = rand()
vcp = rand()
# init buffers for evaluation of rhs
buff = zeros(Float64, length(a.Γ), length(r.sites))
temp = zeros(Float64, length(r.sites), length(a.Γ), 2)
# fill self energy with random values
a.Σ .= rand(31)
ap.Σ .= rand(31)
# fill channels with random values
for i in eachindex(a.Γ)
a.Γ[i].ch_s.q1 .= rand(length(r.sites), 31)
a.Γ[i].ch_t.q1 .= rand(length(r.sites), 31)
a.Γ[i].ch_u.q1 .= rand(length(r.sites), 31)
a.Γ[i].ch_s.q2_1 .= rand(length(r.sites), 31, 31)
a.Γ[i].ch_t.q2_1 .= rand(length(r.sites), 31, 31)
a.Γ[i].ch_u.q2_1 .= rand(length(r.sites), 31, 31)
a.Γ[i].ch_s.q2_2 .= rand(length(r.sites), 31, 31)
a.Γ[i].ch_t.q2_2 .= rand(length(r.sites), 31, 31)
a.Γ[i].ch_u.q2_2 .= rand(length(r.sites), 31, 31)
a.Γ[i].ch_s.q3 .= rand(length(r.sites), 31, 31, 31)
a.Γ[i].ch_t.q3 .= rand(length(r.sites), 31, 31, 31)
a.Γ[i].ch_u.q3 .= rand(length(r.sites), 31, 31, 31)
ap.Γ[i].ch_s.q1 .= rand(length(r.sites), 31)
ap.Γ[i].ch_t.q1 .= rand(length(r.sites), 31)
ap.Γ[i].ch_u.q1 .= rand(length(r.sites), 31)
ap.Γ[i].ch_s.q2_1 .= rand(length(r.sites), 31, 31)
ap.Γ[i].ch_t.q2_1 .= rand(length(r.sites), 31, 31)
ap.Γ[i].ch_u.q2_1 .= rand(length(r.sites), 31, 31)
ap.Γ[i].ch_s.q2_2 .= rand(length(r.sites), 31, 31)
ap.Γ[i].ch_t.q2_2 .= rand(length(r.sites), 31, 31)
ap.Γ[i].ch_u.q2_2 .= rand(length(r.sites), 31, 31)
ap.Γ[i].ch_s.q3 .= rand(length(r.sites), 31, 31, 31)
ap.Γ[i].ch_t.q3 .= rand(length(r.sites), 31, 31, 31)
ap.Γ[i].ch_u.q3 .= rand(length(r.sites), 31, 31, 31)
end
for rep in 1 : 10
# time parquet equations
@timeit to "=> parquet" begin
# time SDE
@timeit to "-> SDE" compute_Σ_kernel(Λ, v, wc, r, m, a, ap)
# time BSE in all channels
@timeit to "-> BSE s channel" compute_s_BSE!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, temp)
@timeit to "-> BSE t channel" compute_t_BSE!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, temp)
@timeit to "-> BSE u channel" compute_u_BSE!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, temp)
end
# time flow equations
@timeit to "=> FRG" begin
# time self energy
@timeit to "-> Σ one loop" compute_dΣ_kernel(Λ, v, wc, r, m, a)
@timeit to "-> Σ corr 1" compute_dΣ_kernel_corr1(Λ, v, wc, r, m, a, ap)
@timeit to "-> Σ corr 2" compute_dΣ_kernel_corr2(Λ, v, wc, r, m, a, ap)
# time Katanin part in all channels
@timeit to "-> Katanin s channel" compute_s_kat!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
@timeit to "-> Katanin t channel" compute_t_kat!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
@timeit to "-> Katanin u channel" compute_u_kat!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
# time left part in all channels
@timeit to "-> left s channel" compute_s_left!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
@timeit to "-> left t channel" compute_t_left!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
@timeit to "-> left u channel" compute_u_left!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
# time central part in all channels
@timeit to "-> central s channel" compute_s_central!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
@timeit to "-> central t channel" compute_t_central!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
@timeit to "-> central u channel" compute_u_central!(Λ, buff, v, dv, wc, vc, vcp, r, m, a, ap, temp)
end
end
return nothing
end
"""
get_flow_timers() :: Nothing
Time current implementation of flow equations by running the different integration kernels.
"""
function get_flow_timers() :: Nothing
println("NOTE: TIMERS BETWEEN DIFFERENT SYMMETRIES SHALL NOT BE COMPARED (RESULTS ARE MODEL DEPENDENT).")
println()
# init test dummys
list = get_mesh(rand(), 1.0, 30, 0.4)
m = Mesh(31, 31, 31, 31, list, list, list, list, list, list)
# init timer
to = TimerOutput()
# time evals of integration kernels for action_su2
@timeit to "=> action_su2" begin
# generate action dummy for square lattice Heisenberg model
l = get_lattice("square", 5, verbose = false)
r = get_reduced_lattice("heisenberg", [[1.0]], l, verbose = false)
a = get_action_empty("su2", r, m); init_action!(l, r, a)
ap = get_action_empty("su2", r, m)
# time integration kernels
time_kernels!(to, r, m, a, ap)
end
# time evals of integration kernels for action_u1_dm
@timeit to "=> action_u1_dm" begin
# generate action dummy for triangular lattice dm-c3 model
l = get_lattice("triangular", 5, verbose = false)
r = get_reduced_lattice("triangular-dm-c3", [[1.0, 1.0, 1.0]], l, verbose = false)
a = get_action_empty("u1-dm", r, m); init_action!(l, r, a)
ap = get_action_empty("u1-dm", r, m)
# time integration kernels
time_kernels!(to, r, m, a, ap)
end
show(to)
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 114 | # load code
include("flow_su2_self.jl")
include("flow_su2_s.jl")
include("flow_su2_t.jl")
include("flow_su2_u.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 4723 | # Katanin kernel
function compute_s_kat!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = get_propagator_kat(Λ, v + 0.5 * s, 0.5 * s - v, m, a, da) + get_propagator_kat(Λ, 0.5 * s - v, v + 0.5 * s, m, a, da)
# get buffers for left vertex
bs1 = get_buffer_s(s, vs, -v, m)
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * ( 3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end
# left kernel (right part obtained by symmetries)
function compute_s_left!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for left vertex
bs1 = get_buffer_empty()
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, da, temp, 1, ch_s = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * ( 3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end
# central kernel
function compute_s_central!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da_l :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(s, vs, -v, m)
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_empty()
bu2 = get_buffer_empty()
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, da_l, temp, 2, ch_t = false, ch_u = false)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * ( 3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3447 | # integration kernel for loop function
function compute_dΣ_kernel(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s( v + w, 0.5 * (-v + w), 0.5 * (v - w), m)
b1t = get_buffer_t(0.0, w, v, m)
b1u = get_buffer_u(-v + w, 0.5 * ( v + w), 0.5 * (v + w), m)
# get buffers for local vertex
b2s = get_buffer_s(v + w, 0.5 * (-v + w), 0.5 * (-v + w), m)
b2t = get_buffer_t(v - w, 0.5 * ( v + w), 0.5 * ( v + w), m)
b2u = get_buffer_u(0.0, w, v, m)
# compute local contributions
val = 3.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, a, apply_flags_su2) + get_Γ_comp(2, 1, b2s, b2t, b2u, r, a, apply_flags_su2)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * (2.0 * a.S) * get_Γ_comp(2, j, b1s, b1t, b1u, r, a, apply_flags_su2)
end
# multiply with single scale propagator
val *= get_S(Λ, v, m, a) / (2.0 * pi)
return val
end
# first integration kernel for loop function for self energy corrections
function compute_dΣ_kernel_corr1(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da_Σ :: Action_su2
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s( v + w, 0.5 * (-v + w), 0.5 * (v - w), m)
b1t = get_buffer_t(0.0, w, v, m)
b1u = get_buffer_u(-v + w, 0.5 * ( v + w), 0.5 * (v + w), m)
# get buffers for local vertex
b2s = get_buffer_s(v + w, 0.5 * (-v + w), 0.5 * (-v + w), m)
b2t = get_buffer_t(v - w, 0.5 * ( v + w), 0.5 * ( v + w), m)
b2u = get_buffer_u(0.0, w, v, m)
# compute local contributions
val = 3.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, da_Σ, apply_flags_su2, ch_u = false) + get_Γ_comp(2, 1, b2s, b2t, b2u, r, da_Σ, apply_flags_su2, ch_u = false)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * (2.0 * a.S) * get_Γ_comp(2, j, b1s, b1t, b1u, r, da_Σ, apply_flags_su2, ch_t = false)
end
# multiply with full propagator
val *= -get_G(Λ, v, m, a) / (2.0 * pi)
return val
end
# second integration kernel for loop function for self energy corrections
function compute_dΣ_kernel_corr2(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da_Σ :: Action_su2
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s( v + w, 0.5 * (-v + w), 0.5 * (v - w), m)
b1t = get_buffer_t(0.0, w, v, m)
b1u = get_buffer_u(-v + w, 0.5 * ( v + w), 0.5 * (v + w), m)
# get buffers for local vertex
b2s = get_buffer_s(v + w, 0.5 * (-v + w), 0.5 * (-v + w), m)
b2t = get_buffer_t(v - w, 0.5 * ( v + w), 0.5 * ( v + w), m)
b2u = get_buffer_u(0.0, w, v, m)
# compute local contributions
val = 3.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, a, apply_flags_su2) + get_Γ_comp(2, 1, b2s, b2t, b2u, r, a, apply_flags_su2)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * (2.0 * a.S) * get_Γ_comp(2, j, b1s, b1t, b1u, r, a, apply_flags_su2)
end
# multiply with full propagator
val *= get_G(Λ, v, m, a)^2 * get_Σ(v, m, da_Σ) / (2.0 * pi)
return val
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 8649 | # Katanin kernel
function compute_t_kat!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = get_propagator_kat(Λ, v + 0.5 * t, v - 0.5 * t, m, a, da) + get_propagator_kat(Λ, v - 0.5 * t, v + 0.5 * t, m, a, da)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_t(t, vt, v, m)
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_s(v + vtp, 0.5 * (-t + v - vtp), 0.5 * (-t - v + vtp), m)
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_u(v - vtp, 0.5 * (-t + v + vtp), 0.5 * ( t + v + vtp), m)
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_u(t, v, vt, m)
# get buffers for local right vertex
bs4 = get_buffer_s(v + vtp, 0.5 * (t - v + vtp), 0.5 * (-t - v + vtp), m)
bt4 = get_buffer_t(v - vtp, 0.5 * (t + v + vtp), 0.5 * (-t + v + vtp), m)
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3s, v3d = get_Γ(1, bs3, bt3, bu3, r, a)
v4s, v4d = get_Γ(1, bs4, bt4, bu4, r, a)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-1.0 * v1s * v4s + v1s * v4d - 1.0 * v3s * v2s + v3d * v2s)
Γd = -p * ( 3.0 * v1d * v4s + v1d * v4d + 3.0 * v3s * v2d + v3d * v2d)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1s = temp[overlap_i[j, 1], 1, 1]; v1d = temp[overlap_i[j, 1], 2, 1]
v2s = temp[overlap_i[j, 2], 1, 2]; v2d = temp[overlap_i[j, 2], 2, 2]
# compute contribution at inner site
Γs += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1s * v2s
Γd += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1d * v2d
end
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end
# left kernel (right part obtained by symmetries)
function compute_t_left!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = -get_propagator(Λ, v + 0.5 * t, v - 0.5 * t, m, a)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_empty()
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_s(v + vtp, 0.5 * (-t + v - vtp), 0.5 * (-t - v + vtp), m)
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_u(v - vtp, 0.5 * (-t + v + vtp), 0.5 * ( t + v + vtp), m)
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_empty()
# get buffers for local right vertex
bs4 = get_buffer_s(v + vtp, 0.5 * (t - v + vtp), 0.5 * (-t - v + vtp), m)
bt4 = get_buffer_t(v - vtp, 0.5 * (t + v + vtp), 0.5 * (-t + v + vtp), m)
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3s, v3d = get_Γ(1, bs3, bt3, bu3, r, da, ch_u = false)
v4s, v4d = get_Γ(1, bs4, bt4, bu4, r, a)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, da, temp, 1, ch_t = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-1.0 * v1s * v4s + v1s * v4d - 1.0 * v3s * v2s + v3d * v2s)
Γd = -p * ( 3.0 * v1d * v4s + v1d * v4d + 3.0 * v3s * v2d + v3d * v2d)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1s = temp[overlap_i[j, 1], 1, 1]; v1d = temp[overlap_i[j, 1], 2, 1]
v2s = temp[overlap_i[j, 2], 1, 2]; v2d = temp[overlap_i[j, 2], 2, 2]
# compute contribution at inner site
Γs += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1s * v2s
Γd += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1d * v2d
end
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end
# central kernel
function compute_t_central!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da_l :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = -get_propagator(Λ, v + 0.5 * t, v - 0.5 * t, m, a)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_t(t, vt, v, m)
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_empty()
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_empty()
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_u(t, v, vt, m)
# get buffers for local right vertex
bs4 = get_buffer_empty()
bt4 = get_buffer_empty()
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3s, v3d = get_Γ(1, bs3, bt3, bu3, r, a)
v4s, v4d = get_Γ(1, bs4, bt4, bu4, r, da_l, ch_s = false, ch_t = false)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, da_l, temp, 2, ch_s = false, ch_u = false)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-1.0 * v1s * v4s + v1s * v4d - 1.0 * v3s * v2s + v3d * v2s)
Γd = -p * ( 3.0 * v1d * v4s + v1d * v4d + 3.0 * v3s * v2d + v3d * v2d)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1s = temp[overlap_i[j, 1], 1, 1]; v1d = temp[overlap_i[j, 1], 2, 1]
v2s = temp[overlap_i[j, 2], 1, 2]; v2d = temp[overlap_i[j, 2], 2, 2]
# compute contribution at inner site
Γs += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1s * v2s
Γd += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1d * v2d
end
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 4725 | # Katanin kernel
function compute_u_kat!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = get_propagator_kat(Λ, v - 0.5 * u, v + 0.5 * u, m, a, da) + get_propagator_kat(Λ, v + 0.5 * u, v - 0.5 * u, m, a, da)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_u(u, vu, v, m)
# get buffers for right vertex
bs2 = get_buffer_s( v + vup, 0.5 * (u + v - vup), 0.5 * (-u + v - vup), m)
bt2 = get_buffer_t(-v + vup, 0.5 * (u + v + vup), 0.5 * (-u + v + vup), m)
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * (3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end
# left kernel (right part obtained by symmetries)
function compute_u_left!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v - 0.5 * u, v + 0.5 * u, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_empty()
# get buffers for right vertex
bs2 = get_buffer_s( v + vup, 0.5 * (u + v - vup), 0.5 * (-u + v - vup), m)
bt2 = get_buffer_t(-v + vup, 0.5 * (u + v + vup), 0.5 * (-u + v + vup), m)
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, da, temp, 1, ch_u = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * (3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end
# central kernel
function compute_u_central!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
da_l :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v - 0.5 * u, v + 0.5 * u, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_u(u, vu, v, m)
# get buffers for right vertex
bs2 = get_buffer_empty()
bt2 = get_buffer_empty()
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, da_l, temp, 2, ch_s = false, ch_t = false)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * (3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 122 | # load code
include("flow_u1_dm_self.jl")
include("flow_u1_dm_s.jl")
include("flow_u1_dm_t.jl")
include("flow_u1_dm_u.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 7726 | # Katanin kernel
function compute_s_kat!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = get_propagator_kat(Λ, v + 0.5 * s, 0.5 * s - v, m, a, da) + get_propagator_kat(Λ, 0.5 * s - v, v + 0.5 * s, m, a, da)
# get buffers for left vertex
bs1 = get_buffer_s(s, vs, -v, m)
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx - v1xx * v2zz - v1dz * v2DM + v1zd * v2DM - v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd - 2.0 * v1xx * v2xx - 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx - v1xx * v2dz - v1zz * v2DM + v1xx * v2zd - v1DM * v2zz + v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd + 2.0 * v1DM * v2xx + v1dz * v2dd - 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end
# left kernel (right part obtained by symmetries)
function compute_s_left!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for left vertex
bs1 = get_buffer_empty()
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, da, temp, 1, ch_s = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx - v1xx * v2zz - v1dz * v2DM + v1zd * v2DM - v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd - 2.0 * v1xx * v2xx - 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx - v1xx * v2dz - v1zz * v2DM + v1xx * v2zd - v1DM * v2zz + v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd + 2.0 * v1DM * v2xx + v1dz * v2dd - 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end
# central kernel
function compute_s_central!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da_l :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(s, vs, -v, m)
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_empty()
bu2 = get_buffer_empty()
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, da_l, temp, 2, ch_t = false, ch_u = false)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx - v1xx * v2zz - v1dz * v2DM + v1zd * v2DM - v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd - 2.0 * v1xx * v2xx - 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx - v1xx * v2dz - v1zz * v2DM + v1xx * v2zd - v1DM * v2zz + v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd + 2.0 * v1DM * v2xx + v1dz * v2dd - 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3725 | # integration kernel for loop function
function compute_dΣ_kernel(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s( v + w, 0.5 * (-v + w), 0.5 * (v - w), m)
b1t = get_buffer_t(0.0, w, v, m)
b1u = get_buffer_u(-v + w, 0.5 * ( v + w), 0.5 * (v + w), m)
# get buffers for local vertex
b2s = get_buffer_s(v + w, 0.5 * (-v + w), 0.5 * (-v + w), m)
b2t = get_buffer_t(v - w, 0.5 * ( v + w), 0.5 * ( v + w), m)
b2u = get_buffer_u(0.0, w, v, m)
# compute local contributions
val = 2.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, a, apply_flags_u1_dm) +
get_Γ_comp(2, 1, b2s, b2t, b2u, r, a, apply_flags_u1_dm) +
get_Γ_comp(4, 1, b2s, b2t, b2u, r, a, apply_flags_u1_dm)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * get_Γ_comp(4, j, b1s, b1t, b1u, r, a, apply_flags_u1_dm)
end
# multiply with single scale propagator
val *= get_S(Λ, v, m, a) / (2.0 * pi)
return val
end
# first integration kernel for loop function for self energy corrections
function compute_dΣ_kernel_corr1(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da_Σ :: Action_u1_dm
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s( v + w, 0.5 * (-v + w), 0.5 * (v - w), m)
b1t = get_buffer_t(0.0, w, v, m)
b1u = get_buffer_u(-v + w, 0.5 * ( v + w), 0.5 * (v + w), m)
# get buffers for local vertex
b2s = get_buffer_s(v + w, 0.5 * (-v + w), 0.5 * (-v + w), m)
b2t = get_buffer_t(v - w, 0.5 * ( v + w), 0.5 * ( v + w), m)
b2u = get_buffer_u(0.0, w, v, m)
# compute local contributions
val = 2.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, da_Σ, apply_flags_u1_dm, ch_u = false) +
get_Γ_comp(2, 1, b2s, b2t, b2u, r, da_Σ, apply_flags_u1_dm, ch_u = false) +
get_Γ_comp(4, 1, b2s, b2t, b2u, r, da_Σ, apply_flags_u1_dm, ch_u = false)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * get_Γ_comp(4, j, b1s, b1t, b1u, r, da_Σ, apply_flags_u1_dm, ch_t = false)
end
# multiply with full propagator
val *= -get_G(Λ, v, m, a) / (2.0 * pi)
return val
end
# second integration kernel for loop function for self energy corrections
function compute_dΣ_kernel_corr2(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da_Σ :: Action_u1_dm
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s( v + w, 0.5 * (-v + w), 0.5 * (v - w), m)
b1t = get_buffer_t(0.0, w, v, m)
b1u = get_buffer_u(-v + w, 0.5 * ( v + w), 0.5 * (v + w), m)
# get buffers for local vertex
b2s = get_buffer_s(v + w, 0.5 * (-v + w), 0.5 * (-v + w), m)
b2t = get_buffer_t(v - w, 0.5 * ( v + w), 0.5 * ( v + w), m)
b2u = get_buffer_u(0.0, w, v, m)
# compute local contributions
val = 2.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, a, apply_flags_u1_dm) +
get_Γ_comp(2, 1, b2s, b2t, b2u, r, a, apply_flags_u1_dm) +
get_Γ_comp(4, 1, b2s, b2t, b2u, r, a, apply_flags_u1_dm)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * get_Γ_comp(4, j, b1s, b1t, b1u, r, a, apply_flags_u1_dm)
end
# multiply with full propagator
val *= get_G(Λ, v, m, a)^2 * get_Σ(v, m, da_Σ) / (2.0 * pi)
return val
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 15396 | # Katanin kernel
function compute_t_kat!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = get_propagator_kat(Λ, v + 0.5 * t, v - 0.5 * t, m, a, da) + get_propagator_kat(Λ, v - 0.5 * t, v + 0.5 * t, m, a, da)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_t(t, vt, v, m)
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_s(v + vtp, 0.5 * (-t + v - vtp), 0.5 * (-t - v + vtp), m)
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_u(v - vtp, 0.5 * (-t + v + vtp), 0.5 * ( t + v + vtp), m)
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_u(t, v, vt, m)
# get buffers for local right vertex
bs4 = get_buffer_s(v + vtp, 0.5 * (t - v + vtp), 0.5 * (-t - v + vtp), m)
bt4 = get_buffer_t(v - vtp, 0.5 * (t + v + vtp), 0.5 * (-t + v + vtp), m)
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3xx, v3zz, v3DM, v3dd, v3zd, v3dz = get_Γ(1, bs3, bt3, bu3, r, a)
v4xx, v4zz, v4DM, v4dd, v4zd, v4dz = get_Γ(1, bs4, bt4, bu4, r, a)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v4dz - v1DM * v4zd + v1xx * v4dd - v1xx * v4zz +
v3dd * v2xx + v3dz * v2DM - v3zd * v2DM - v3zz * v2xx)
Γzz = -p * (v1zz * v4dd + 2.0 * v1zd * v4DM - v1zd * v4zd + v1zz * v4zz - 2.0 * v1zz * v4xx - v1zd * v4dz -
2.0 * v3DM * v2dz - v3dz * v2dz + v3dd * v2zz - 2.0 * v3xx * v2zz + v3zz * v2zz - v3zd * v2dz)
ΓDM = -p * (v1DM * v4dd - v1xx * v4dz + v1xx * v4zd - v1DM * v4zz -
v3dz * v2xx + v3dd * v2DM + v3zd * v2xx - v3zz * v2DM)
Γdd = -p * (-v1dz * v4dz + 2.0 * v1dd * v4xx + v1dd * v4zz - v1dz * v4zd - 2.0 * v1dz * v4DM + v1dd * v4dd +
2.0 * v3DM * v2zd + 2.0 * v3xx * v2dd + v3zz * v2dd - v3dz * v2zd + v3dd * v2dd - v3zd * v2zd)
Γzd = -p * (v1zd * v4zz + v1zd * v4dd + 2.0 * v1zd * v4xx + v1zz * v4zd + 2.0 * v1zz * v4DM + v1zz * v4dz +
v3zd * v2dd + 2.0 * v3DM * v2dd + v3dd * v2zd + v3zz * v2zd - 2.0 * v3xx * v2zd + v3dz * v2dd)
Γdz = -p * (-2.0 * v1dd * v4DM + v1dd * v4zd + v1dd * v4dz + v1dz * v4zz + v1dz * v4dd - 2.0 * v1dz * v4xx +
v3zd * v2zz + 2.0 * v3xx * v2dz + v3dd * v2dz + v3dz * v2zz - 2.0 * v3DM * v2zz + v3zz * v2dz)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1xx = temp[overlap_i[j, 1], 1, 1]
v1zz = temp[overlap_i[j, 1], 2, 1]
v1DM = temp[overlap_i[j, 1], 3, 1]
v1dd = temp[overlap_i[j, 1], 4, 1]
v1zd = temp[overlap_i[j, 1], 5, 1]
v1dz = temp[overlap_i[j, 1], 6, 1]
v2xx = temp[overlap_i[j, 2], 1, 2]
v2zz = temp[overlap_i[j, 2], 2, 2]
v2DM = temp[overlap_i[j, 2], 3, 2]
v2dd = temp[overlap_i[j, 2], 4, 2]
v2zd = temp[overlap_i[j, 2], 5, 2]
v2dz = temp[overlap_i[j, 2], 6, 2]
# compute contribution at inner site
Γxx += -p * (-2.0) * overlap_i[j, 3] * (v1xx * v2xx - v1DM * v2DM)
Γzz += -p * (-2.0) * overlap_i[j, 3] * (v1zz * v2zz - v1zd * v2dz)
ΓDM += -p * (-2.0) * overlap_i[j, 3] * (v1DM * v2xx + v1xx * v2DM)
Γdd += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dd - v1dz * v2zd)
Γzd += -p * (-2.0) * overlap_i[j, 3] * (v1zd * v2dd + v1zz * v2zd)
Γdz += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dz + v1dz * v2zz)
end
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end
# left kernel (right part obtained by symmetries)
function compute_t_left!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = -get_propagator(Λ, v + 0.5 * t, v - 0.5 * t, m, a)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_empty()
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_s(v + vtp, 0.5 * (-t + v - vtp), 0.5 * (-t - v + vtp), m)
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_u(v - vtp, 0.5 * (-t + v + vtp), 0.5 * ( t + v + vtp), m)
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_empty()
# get buffers for local right vertex
bs4 = get_buffer_s(v + vtp, 0.5 * (t - v + vtp), 0.5 * (-t - v + vtp), m)
bt4 = get_buffer_t(v - vtp, 0.5 * (t + v + vtp), 0.5 * (-t + v + vtp), m)
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3xx, v3zz, v3DM, v3dd, v3zd, v3dz = get_Γ(1, bs3, bt3, bu3, r, da, ch_u = false)
v4xx, v4zz, v4DM, v4dd, v4zd, v4dz = get_Γ(1, bs4, bt4, bu4, r, a)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, da, temp, 1, ch_t = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v4dz - v1DM * v4zd + v1xx * v4dd - v1xx * v4zz +
v3dd * v2xx + v3dz * v2DM - v3zd * v2DM - v3zz * v2xx)
Γzz = -p * (v1zz * v4dd + 2.0 * v1zd * v4DM - v1zd * v4zd + v1zz * v4zz - 2.0 * v1zz * v4xx - v1zd * v4dz -
2.0 * v3DM * v2dz - v3dz * v2dz + v3dd * v2zz - 2.0 * v3xx * v2zz + v3zz * v2zz - v3zd * v2dz)
ΓDM = -p * (v1DM * v4dd - v1xx * v4dz + v1xx * v4zd - v1DM * v4zz -
v3dz * v2xx + v3dd * v2DM + v3zd * v2xx - v3zz * v2DM)
Γdd = -p * (-v1dz * v4dz + 2.0 * v1dd * v4xx + v1dd * v4zz - v1dz * v4zd - 2.0 * v1dz * v4DM + v1dd * v4dd +
2.0 * v3DM * v2zd + 2.0 * v3xx * v2dd + v3zz * v2dd - v3dz * v2zd + v3dd * v2dd - v3zd * v2zd)
Γzd = -p * (v1zd * v4zz + v1zd * v4dd + 2.0 * v1zd * v4xx + v1zz * v4zd + 2.0 * v1zz * v4DM + v1zz * v4dz +
v3zd * v2dd + 2.0 * v3DM * v2dd + v3dd * v2zd + v3zz * v2zd - 2.0 * v3xx * v2zd + v3dz * v2dd)
Γdz = -p * (-2.0 * v1dd * v4DM + v1dd * v4zd + v1dd * v4dz + v1dz * v4zz + v1dz * v4dd - 2.0 * v1dz * v4xx +
v3zd * v2zz + 2.0 * v3xx * v2dz + v3dd * v2dz + v3dz * v2zz - 2.0 * v3DM * v2zz + v3zz * v2dz)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1xx = temp[overlap_i[j, 1], 1, 1]
v1zz = temp[overlap_i[j, 1], 2, 1]
v1DM = temp[overlap_i[j, 1], 3, 1]
v1dd = temp[overlap_i[j, 1], 4, 1]
v1zd = temp[overlap_i[j, 1], 5, 1]
v1dz = temp[overlap_i[j, 1], 6, 1]
v2xx = temp[overlap_i[j, 2], 1, 2]
v2zz = temp[overlap_i[j, 2], 2, 2]
v2DM = temp[overlap_i[j, 2], 3, 2]
v2dd = temp[overlap_i[j, 2], 4, 2]
v2zd = temp[overlap_i[j, 2], 5, 2]
v2dz = temp[overlap_i[j, 2], 6, 2]
# compute contribution at inner site
Γxx += -p * (-2.0) * overlap_i[j, 3] * (v1xx * v2xx - v1DM * v2DM)
Γzz += -p * (-2.0) * overlap_i[j, 3] * (v1zz * v2zz - v1zd * v2dz)
ΓDM += -p * (-2.0) * overlap_i[j, 3] * (v1DM * v2xx + v1xx * v2DM)
Γdd += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dd - v1dz * v2zd)
Γzd += -p * (-2.0) * overlap_i[j, 3] * (v1zd * v2dd + v1zz * v2zd)
Γdz += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dz + v1dz * v2zz)
end
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end
# central kernel
function compute_t_central!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da_l :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = -get_propagator(Λ, v + 0.5 * t, v - 0.5 * t, m, a)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_t(t, vt, v, m)
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_empty()
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_empty()
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_u(t, v, vt, m)
# get buffers for local right vertex
bs4 = get_buffer_empty()
bt4 = get_buffer_empty()
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3xx, v3zz, v3DM, v3dd, v3zd, v3dz = get_Γ(1, bs3, bt3, bu3, r, a)
v4xx, v4zz, v4DM, v4dd, v4zd, v4dz = get_Γ(1, bs4, bt4, bu4, r, da_l, ch_s = false, ch_t = false)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, da_l, temp, 2, ch_s = false, ch_u = false)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v4dz - v1DM * v4zd + v1xx * v4dd - v1xx * v4zz +
v3dd * v2xx + v3dz * v2DM - v3zd * v2DM - v3zz * v2xx)
Γzz = -p * (v1zz * v4dd + 2.0 * v1zd * v4DM - v1zd * v4zd + v1zz * v4zz - 2.0 * v1zz * v4xx - v1zd * v4dz -
2.0 * v3DM * v2dz - v3dz * v2dz + v3dd * v2zz - 2.0 * v3xx * v2zz + v3zz * v2zz - v3zd * v2dz)
ΓDM = -p * (v1DM * v4dd - v1xx * v4dz + v1xx * v4zd - v1DM * v4zz -
v3dz * v2xx + v3dd * v2DM + v3zd * v2xx - v3zz * v2DM)
Γdd = -p * (-v1dz * v4dz + 2.0 * v1dd * v4xx + v1dd * v4zz - v1dz * v4zd - 2.0 * v1dz * v4DM + v1dd * v4dd +
2.0 * v3DM * v2zd + 2.0 * v3xx * v2dd + v3zz * v2dd - v3dz * v2zd + v3dd * v2dd - v3zd * v2zd)
Γzd = -p * (v1zd * v4zz + v1zd * v4dd + 2.0 * v1zd * v4xx + v1zz * v4zd + 2.0 * v1zz * v4DM + v1zz * v4dz +
v3zd * v2dd + 2.0 * v3DM * v2dd + v3dd * v2zd + v3zz * v2zd - 2.0 * v3xx * v2zd + v3dz * v2dd)
Γdz = -p * (-2.0 * v1dd * v4DM + v1dd * v4zd + v1dd * v4dz + v1dz * v4zz + v1dz * v4dd - 2.0 * v1dz * v4xx +
v3zd * v2zz + 2.0 * v3xx * v2dz + v3dd * v2dz + v3dz * v2zz - 2.0 * v3DM * v2zz + v3zz * v2dz)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1xx = temp[overlap_i[j, 1], 1, 1]
v1zz = temp[overlap_i[j, 1], 2, 1]
v1DM = temp[overlap_i[j, 1], 3, 1]
v1dd = temp[overlap_i[j, 1], 4, 1]
v1zd = temp[overlap_i[j, 1], 5, 1]
v1dz = temp[overlap_i[j, 1], 6, 1]
v2xx = temp[overlap_i[j, 2], 1, 2]
v2zz = temp[overlap_i[j, 2], 2, 2]
v2DM = temp[overlap_i[j, 2], 3, 2]
v2dd = temp[overlap_i[j, 2], 4, 2]
v2zd = temp[overlap_i[j, 2], 5, 2]
v2dz = temp[overlap_i[j, 2], 6, 2]
# compute contribution at inner site
Γxx += -p * (-2.0) * overlap_i[j, 3] * (v1xx * v2xx - v1DM * v2DM)
Γzz += -p * (-2.0) * overlap_i[j, 3] * (v1zz * v2zz - v1zd * v2dz)
ΓDM += -p * (-2.0) * overlap_i[j, 3] * (v1DM * v2xx + v1xx * v2DM)
Γdd += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dd - v1dz * v2zd)
Γzd += -p * (-2.0) * overlap_i[j, 3] * (v1zd * v2dd + v1zz * v2zd)
Γdz += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dz + v1dz * v2zz)
end
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 7716 | # Katanin kernel
function compute_u_kat!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = get_propagator_kat(Λ, v - 0.5 * u, v + 0.5 * u, m, a, da) + get_propagator_kat(Λ, v + 0.5 * u, v - 0.5 * u, m, a, da)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_u(u, vu, v, m)
# get buffers for right vertex
bs2 = get_buffer_s( v + vup, 0.5 * (u + v - vup), 0.5 * (-u + v - vup), m)
bt2 = get_buffer_t(-v + vup, 0.5 * (u + v + vup), 0.5 * (-u + v + vup), m)
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (-v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx + v1xx * v2zz + v1dz * v2DM + v1zd * v2DM + v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd + 2.0 * v1xx * v2xx + 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx + v1xx * v2dz + v1zz * v2DM + v1xx * v2zd + v1DM * v2zz - v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd - 2.0 * v1DM * v2xx + v1dz * v2dd + 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end
# left kernel (right part obtained by symmetries)
function compute_u_left!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v - 0.5 * u, v + 0.5 * u, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_empty()
# get buffers for right vertex
bs2 = get_buffer_s( v + vup, 0.5 * (u + v - vup), 0.5 * (-u + v - vup), m)
bt2 = get_buffer_t(-v + vup, 0.5 * (u + v + vup), 0.5 * (-u + v + vup), m)
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, da, temp, 1, ch_u = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (-v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx + v1xx * v2zz + v1dz * v2DM + v1zd * v2DM + v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd + 2.0 * v1xx * v2xx + 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx + v1xx * v2dz + v1zz * v2DM + v1xx * v2zd + v1DM * v2zz - v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd - 2.0 * v1DM * v2xx + v1dz * v2dd + 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end
# central kernel
function compute_u_central!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
da_l :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v - 0.5 * u, v + 0.5 * u, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_u(u, vu, v, m)
# get buffers for right vertex
bs2 = get_buffer_empty()
bt2 = get_buffer_empty()
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1)
get_Γ_avx!(r, bs2, bt2, bu2, da_l, temp, 2, ch_s = false, ch_t = false)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (-v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx + v1xx * v2zz + v1dz * v2DM + v1zd * v2DM + v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd + 2.0 * v1xx * v2xx + 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx + v1xx * v2dz + v1zz * v2DM + v1xx * v2zd + v1DM * v2zz - v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd - 2.0 * v1DM * v2xx + v1dz * v2dd + 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1550 | # BSE kernel for the s channel
function compute_s_BSE!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for left vertex
bs1 = get_buffer_empty()
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1, ch_s = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * ( 3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 2885 | # BSE kernel for the t channel
function compute_t_BSE!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = -get_propagator(Λ, v + 0.5 * t, v - 0.5 * t, m, a)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_empty()
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_s(v + vtp, 0.5 * (-t + v - vtp), 0.5 * (-t - v + vtp), m)
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_u(v - vtp, 0.5 * (-t + v + vtp), 0.5 * ( t + v + vtp), m)
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_empty()
# get buffers for local right vertex
bs4 = get_buffer_s(v + vtp, 0.5 * (t - v + vtp), 0.5 * (-t - v + vtp), m)
bt4 = get_buffer_t(v - vtp, 0.5 * (t + v + vtp), 0.5 * (-t + v + vtp), m)
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3s, v3d = get_Γ(1, bs3, bt3, bu3, r, a, ch_u = false)
v4s, v4d = get_Γ(1, bs4, bt4, bu4, r, a)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1, ch_t = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-1.0 * v1s * v4s + v1s * v4d - 1.0 * v3s * v2s + v3d * v2s)
Γd = -p * ( 3.0 * v1d * v4s + v1d * v4d + 3.0 * v3s * v2d + v3d * v2d)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1s = temp[overlap_i[j, 1], 1, 1]; v1d = temp[overlap_i[j, 1], 2, 1]
v2s = temp[overlap_i[j, 2], 1, 2]; v2d = temp[overlap_i[j, 2], 2, 2]
# compute contribution at inner site
Γs += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1s * v2s
Γd += -p * (-2.0) * overlap_i[j, 3] * (2.0 * a.S) * v1d * v2d
end
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1552 | # BSE kernel for the u channel
function compute_u_BSE!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v - 0.5 * u, v + 0.5 * u, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_empty()
# get buffers for right vertex
bs2 = get_buffer_s( v + vup, 0.5 * (u + v - vup), 0.5 * (-u + v - vup), m)
bt2 = get_buffer_t(-v + vup, 0.5 * (u + v + vup), 0.5 * (-u + v + vup), m)
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1, ch_u = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = temp[i, 1, 1]; v1d = temp[i, 2, 1]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * (3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 2389 | # reduced kernel for the s channel
function compute_s_reduced!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_su2,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for right vertex (left vertex is given by bare)
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1s = a.Γ[1].bare[i]; v1d = a.Γ[2].bare[i]
v2s = temp[i, 1, 2]; v2d = temp[i, 2, 2]
# compute contribution at site i
Γs = -p * (-2.0 * v1s * v2s + v1s * v2d + v1d * v2s)
Γd = -p * ( 3.0 * v1s * v2s + v1d * v2d)
# parse result to output buffer
buff[1, i] += dv * Γs
buff[2, i] += dv * Γd
end
return nothing
end
# integration kernel for loop function
function compute_Σ_kernel(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action_su2,
a2 :: Action_su2
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s(v + w, Inf, 0.5 * (v - w), m)
b1t = get_buffer_empty()
b1u = get_buffer_empty()
# get buffers for local vertex
b2s = get_buffer_s(v + w, Inf, 0.5 * (-v + w), m)
b2t = get_buffer_empty()
b2u = get_buffer_empty()
# compute local contributions
val = 3.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, a2, apply_flags_su2, ch_t = false, ch_u = false) +
get_Γ_comp(2, 1, b2s, b2t, b2u, r, a2, apply_flags_su2, ch_t = false, ch_u = false)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * (2.0 * a2.S) * get_Γ_comp(2, j, b1s, b1t, b1u, r, a2, apply_flags_su2, ch_t = false, ch_u = false)
end
# multiply with full propagator
val *= -get_G(Λ, v, m, a1) / (2.0 * pi)
return val
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 105 | # load code
include("SDE_su2.jl")
include("BSE_su2_s.jl")
include("BSE_su2_t.jl")
include("BSE_su2_u.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 2549 | # BSE kernel for the s channel
function compute_s_BSE!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vs :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for left vertex
bs1 = get_buffer_empty()
bt1 = get_buffer_t(v - vs, 0.5 * (s + v + vs), 0.5 * (s - v - vs), m)
bu1 = get_buffer_u(v + vs, 0.5 * (s - v + vs), 0.5 * (s + v - vs), m)
# get buffers for right vertex
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1, ch_s = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx - v1xx * v2zz - v1dz * v2DM + v1zd * v2DM - v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd - 2.0 * v1xx * v2xx - 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx - v1xx * v2dz - v1zz * v2DM + v1xx * v2zd - v1DM * v2zz + v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd + 2.0 * v1DM * v2xx + v1dz * v2dd - 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 5132 | # BSE kernel for the t channel
function compute_t_BSE!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
t :: Float64,
vt :: Float64,
vtp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator and overlap
p = -get_propagator(Λ, v + 0.5 * t, v - 0.5 * t, m, a)
overlap = r.overlap
# get buffers for left non-local vertex
bs1 = get_buffer_s( v + vt, 0.5 * (-t - v + vt), 0.5 * (-t + v - vt), m)
bt1 = get_buffer_empty()
bu1 = get_buffer_u(-v + vt, 0.5 * (-t + v + vt), 0.5 * ( t + v + vt), m)
# get buffers for right non-local vertex
bs2 = get_buffer_s(v + vtp, 0.5 * (-t + v - vtp), 0.5 * (-t - v + vtp), m)
bt2 = get_buffer_t(t, v, vtp, m)
bu2 = get_buffer_u(v - vtp, 0.5 * (-t + v + vtp), 0.5 * ( t + v + vtp), m)
# get buffers for local left vertex
bs3 = get_buffer_s( v + vt, 0.5 * (t + v - vt), 0.5 * (-t + v - vt), m)
bt3 = get_buffer_t(-v + vt, 0.5 * (t + v + vt), 0.5 * (-t + v + vt), m)
bu3 = get_buffer_empty()
# get buffers for local right vertex
bs4 = get_buffer_s(v + vtp, 0.5 * (t - v + vtp), 0.5 * (-t - v + vtp), m)
bt4 = get_buffer_t(v - vtp, 0.5 * (t + v + vtp), 0.5 * (-t + v + vtp), m)
bu4 = get_buffer_u(t, vtp, v, m)
# cache local vertex values
v3xx, v3zz, v3DM, v3dd, v3zd, v3dz = get_Γ(1, bs3, bt3, bu3, r, a, ch_u = false)
v4xx, v4zz, v4DM, v4dd, v4zd, v4dz = get_Γ(1, bs4, bt4, bu4, r, a)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1, ch_t = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v4dz - v1DM * v4zd + v1xx * v4dd - v1xx * v4zz +
v3dd * v2xx + v3dz * v2DM - v3zd * v2DM - v3zz * v2xx)
Γzz = -p * (v1zz * v4dd + 2.0 * v1zd * v4DM - v1zd * v4zd + v1zz * v4zz - 2.0 * v1zz * v4xx - v1zd * v4dz -
2.0 * v3DM * v2dz - v3dz * v2dz + v3dd * v2zz - 2.0 * v3xx * v2zz + v3zz * v2zz - v3zd * v2dz)
ΓDM = -p * (v1DM * v4dd - v1xx * v4dz + v1xx * v4zd - v1DM * v4zz -
v3dz * v2xx + v3dd * v2DM + v3zd * v2xx - v3zz * v2DM)
Γdd = -p * (-v1dz * v4dz + 2.0 * v1dd * v4xx + v1dd * v4zz - v1dz * v4zd - 2.0 * v1dz * v4DM + v1dd * v4dd +
2.0 * v3DM * v2zd + 2.0 * v3xx * v2dd + v3zz * v2dd - v3dz * v2zd + v3dd * v2dd - v3zd * v2zd)
Γzd = -p * (v1zd * v4zz + v1zd * v4dd + 2.0 * v1zd * v4xx + v1zz * v4zd + 2.0 * v1zz * v4DM + v1zz * v4dz +
v3zd * v2dd + 2.0 * v3DM * v2dd + v3dd * v2zd + v3zz * v2zd - 2.0 * v3xx * v2zd + v3dz * v2dd)
Γdz = -p * (-2.0 * v1dd * v4DM + v1dd * v4zd + v1dd * v4dz + v1dz * v4zz + v1dz * v4dd - 2.0 * v1dz * v4xx +
v3zd * v2zz + 2.0 * v3xx * v2dz + v3dd * v2dz + v3dz * v2zz - 2.0 * v3DM * v2zz + v3zz * v2dz)
# determine overlap for site i
overlap_i = overlap[i]
# determine range for inner sum
Range = size(overlap_i, 1)
# compute inner sum
@turbo unroll = 1 for j in 1 : Range
# read cached values for inner site
v1xx = temp[overlap_i[j, 1], 1, 1]
v1zz = temp[overlap_i[j, 1], 2, 1]
v1DM = temp[overlap_i[j, 1], 3, 1]
v1dd = temp[overlap_i[j, 1], 4, 1]
v1zd = temp[overlap_i[j, 1], 5, 1]
v1dz = temp[overlap_i[j, 1], 6, 1]
v2xx = temp[overlap_i[j, 2], 1, 2]
v2zz = temp[overlap_i[j, 2], 2, 2]
v2DM = temp[overlap_i[j, 2], 3, 2]
v2dd = temp[overlap_i[j, 2], 4, 2]
v2zd = temp[overlap_i[j, 2], 5, 2]
v2dz = temp[overlap_i[j, 2], 6, 2]
# compute contribution at inner site
Γxx += -p * (-2.0) * overlap_i[j, 3] * (v1xx * v2xx - v1DM * v2DM)
Γzz += -p * (-2.0) * overlap_i[j, 3] * (v1zz * v2zz - v1zd * v2dz)
ΓDM += -p * (-2.0) * overlap_i[j, 3] * (v1DM * v2xx + v1xx * v2DM)
Γdd += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dd - v1dz * v2zd)
Γzd += -p * (-2.0) * overlap_i[j, 3] * (v1zd * v2dd + v1zz * v2zd)
Γdz += -p * (-2.0) * overlap_i[j, 3] * (v1dd * v2dz + v1dz * v2zz)
end
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 2547 | # BSE kernel for the u channel
function compute_u_BSE!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
u :: Float64,
vu :: Float64,
vup :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v - 0.5 * u, v + 0.5 * u, m, a)
# get buffers for left vertex
bs1 = get_buffer_s(v + vu, 0.5 * (u - v + vu), 0.5 * (-u - v + vu), m)
bt1 = get_buffer_t(v - vu, 0.5 * (u + v + vu), 0.5 * (-u + v + vu), m)
bu1 = get_buffer_empty()
# get buffers for right vertex
bs2 = get_buffer_s( v + vup, 0.5 * (u + v - vup), 0.5 * (-u + v - vup), m)
bt2 = get_buffer_t(-v + vup, 0.5 * (u + v + vup), 0.5 * (-u + v + vup), m)
bu2 = get_buffer_u(u, v, vup, m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs1, bt1, bu1, a, temp, 1, ch_u = false)
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = temp[i, 1, 1]
v1zz = temp[i, 2, 1]
v1DM = temp[i, 3, 1]
v1dd = temp[i, 4, 1]
v1zd = temp[i, 5, 1]
v1dz = temp[i, 6, 1]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (-v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx + v1xx * v2zz + v1dz * v2DM + v1zd * v2DM + v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd + 2.0 * v1xx * v2xx + 2.0 * v1DM * v2DM - v1zd * v2dz)
ΓDM = -p * (v1dd * v2DM + v1DM * v2dd - v1zd * v2xx + v1xx * v2dz + v1zz * v2DM + v1xx * v2zd + v1DM * v2zz - v1dz * v2xx)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
Γzd = -p * (v1zd * v2dd + v1dd * v2zd - 2.0 * v1DM * v2xx + v1dz * v2zz + v1zz * v2dz + 2.0 * v1xx * v2DM)
Γdz = -p * (v1zd * v2zz + v1dd * v2dz + v1zz * v2zd - 2.0 * v1DM * v2xx + v1dz * v2dd + 2.0 * v1xx * v2DM)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[3, i] += dv * ΓDM
buff[4, i] += dv * Γdd
buff[5, i] += dv * Γzd
buff[6, i] += dv * Γdz
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3038 | # reduced kernel for the s channel
function compute_s_reduced!(
Λ :: Float64,
buff :: Matrix{Float64},
v :: Float64,
dv :: Float64,
s :: Float64,
vsp :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a :: Action_u1_dm,
temp :: Array{Float64, 3}
) :: Nothing
# get propagator
p = -get_propagator(Λ, v + 0.5 * s, 0.5 * s - v, m, a)
# get buffers for right vertex (left vertex is given by bare)
bs2 = get_buffer_s(s, v, vsp, m)
bt2 = get_buffer_t(-v - vsp, 0.5 * (s + v - vsp), 0.5 * (s - v + vsp), m)
bu2 = get_buffer_u( v - vsp, 0.5 * (s + v + vsp), 0.5 * (s - v - vsp), m)
# cache vertex values for all lattice sites in temporary buffer
get_Γ_avx!(r, bs2, bt2, bu2, a, temp, 2)
# compute contributions for all lattice sites
@turbo unroll = 1 for i in eachindex(r.sites)
# read cached values for site i
v1xx = a.Γ[1].bare[i]
v1zz = a.Γ[2].bare[i]
v1DM = a.Γ[3].bare[i]
v1dd = a.Γ[4].bare[i]
v1zd = a.Γ[5].bare[i]
v1dz = a.Γ[6].bare[i]
v2xx = temp[i, 1, 2]
v2zz = temp[i, 2, 2]
v2DM = temp[i, 3, 2]
v2dd = temp[i, 4, 2]
v2zd = temp[i, 5, 2]
v2dz = temp[i, 6, 2]
# compute contribution at site i
Γxx = -p * (v1DM * v2dz - v1DM * v2zd + v1xx * v2dd + v1dd * v2xx - v1xx * v2zz - v1dz * v2DM + v1zd * v2DM - v1zz * v2xx)
Γzz = -p * (v1zz * v2dd + v1dd * v2zz - v1dz * v2zd - 2.0 * v1xx * v2xx - 2.0 * v1DM * v2DM - v1zd * v2dz)
Γdd = -p * (-v1dz * v2dz + 2.0 * v1xx * v2xx + v1dd * v2dd + 2.0 * v1DM * v2DM - v1zd * v2zd + v1zz * v2zz)
# parse result to output buffer
buff[1, i] += dv * Γxx
buff[2, i] += dv * Γzz
buff[4, i] += dv * Γdd
end
return nothing
end
# integration kernel for loop function
function compute_Σ_kernel(
Λ :: Float64,
w :: Float64,
v :: Float64,
r :: Reduced_lattice,
m :: Mesh,
a1 :: Action_u1_dm,
a2 :: Action_u1_dm,
) :: Float64
# get buffers for non-local vertex
b1s = get_buffer_s(v + w, Inf, 0.5 * (v - w), m)
b1t = get_buffer_empty()
b1u = get_buffer_empty()
# get buffers for local vertex
b2s = get_buffer_s(v + w, Inf, 0.5 * (-v + w), m)
b2t = get_buffer_empty()
b2u = get_buffer_empty()
# compute local contributions
val = 2.0 * get_Γ_comp(1, 1, b2s, b2t, b2u, r, a2, apply_flags_u1_dm, ch_t = false, ch_u = false) +
get_Γ_comp(2, 1, b2s, b2t, b2u, r, a2, apply_flags_u1_dm, ch_t = false, ch_u = false) +
get_Γ_comp(4, 1, b2s, b2t, b2u, r, a2, apply_flags_u1_dm, ch_t = false, ch_u = false)
# compute contributions for all lattice sites
for j in eachindex(r.sites)
val -= 2.0 * r.mult[j] * get_Γ_comp(4, j, b1s, b1t, b1u, r, a2, apply_flags_u1_dm, ch_t = false, ch_u = false)
end
# multiply with full propagator
val *= -get_G(Λ, v, m, a1) / (2.0 * pi)
return val
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 113 | # load code
include("SDE_u1_dm.jl")
include("BSE_u1_dm_s.jl")
include("BSE_u1_dm_t.jl")
include("BSE_u1_dm_u.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 112 | # load code
include("param.jl")
include("mesh.jl")
include("buffer.jl")
include("test.jl")
include("timers.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 5400 | """
Buffer
Struct used for reading out vertices from Action struct.
Contains symmetry related flags, (asymptotic) kernel specification and interpolation parameters.
* `exchange_flag :: Bool` : flag for site [(i0, j) <-> (j, i0)] and spin [(μ, ν) <-> (ν, μ)] exchange
* `map_flag :: Bool` : flag for channel mapping s <-> u
* `sgn_μν :: Bool` : sign function for combined spin indices
* `sgn_μ :: Bool` : sign function for first spin index
* `sgn_ν :: Bool` : sign function for second spin index
* `kernel :: Int64` : specification of asymptotic kernel to be interpolated
* `p1 :: Param` : interpolation parameters for bosonic frequency argument
* `p2 :: Param` : interpolation parameters for first fermionic frequency argument
* `p3 :: Param` : interpolation parameters for second fermionic frequency argument
"""
struct Buffer
exchange_flag :: Bool
map_flag :: Bool
sgn_μν :: Bool
sgn_μ :: Bool
sgn_ν :: Bool
kernel :: Int64
p1 :: Param
p2 :: Param
p3 :: Param
end
# function to invert flag
function set_flag(
flag :: Bool
) :: Bool
if flag
flag = false
else
flag = true
end
return flag
end
# generate buffer dummy
function get_buffer_empty() :: Buffer
b = Buffer(false, false, false, false, false, 0, get_param_empty(), get_param_empty(), get_param_empty())
return b
end
# generate generic access buffer for Action struct given flags
function get_buffer(
w :: Float64,
v :: Float64,
vp :: Float64,
Ω :: Vector{Float64},
ν :: Vector{Float64},
exchange_flag :: Bool,
map_flag :: Bool,
sgn_μν :: Bool,
sgn_μ :: Bool,
sgn_ν :: Bool
) :: Buffer
if Ω[end] < abs(w)
return get_buffer_empty()
else
if ν[end] < abs(v)
if ν[end] < abs(vp)
# interpolation for q1
return Buffer(exchange_flag, map_flag, sgn_μν, sgn_μ, sgn_ν, 1, get_param(w, Ω), get_param_empty(), get_param_empty())
else
# interpolation for q2_2
return Buffer(exchange_flag, map_flag, sgn_μν, sgn_μ, sgn_ν, 3, get_param(w, Ω), get_param_empty(), get_param(vp, ν))
end
else
if ν[end] < abs(vp)
# interpolation for q2_1
return Buffer(exchange_flag, map_flag, sgn_μν, sgn_μ, sgn_ν, 2, get_param(w, Ω), get_param(v, ν), get_param_empty())
else
# interpolation for q3
return Buffer(exchange_flag, map_flag, sgn_μν, sgn_μ, sgn_ν, 4, get_param(w, Ω), get_param(v, ν), get_param(vp, ν))
end
end
end
end
# generate access buffer for s channel of Action struct
function get_buffer_s(
w :: Float64,
v :: Float64,
vp :: Float64,
m :: Mesh
) :: Buffer
# init flags
exchange_flag = false
map_flag = false
sgn_μν = false
sgn_μ = false
sgn_ν = false
# do -w -> w
if w < 0.0
w *= -1.0
exchange_flag = set_flag(exchange_flag)
end
# do -v -> v
if v < 0.0
v *= -1.0
exchange_flag = set_flag(exchange_flag)
map_flag = set_flag(map_flag)
sgn_μ = set_flag(sgn_μ)
end
# do -vp -> vp
if vp < 0.0
vp *= -1.0
map_flag = set_flag(map_flag)
sgn_ν = set_flag(sgn_ν)
end
return get_buffer(w, v, vp, m.Ωs, m.νs, exchange_flag, map_flag, sgn_μν, sgn_μ, sgn_ν)
end
# generate access buffer for t channel of Action struct
function get_buffer_t(
w :: Float64,
v :: Float64,
vp :: Float64,
m :: Mesh
) :: Buffer
# init flags
exchange_flag = false
map_flag = false
sgn_μν = false
sgn_μ = false
sgn_ν = false
# do -w -> w
if w < 0.0
w *= -1.0
sgn_μν = set_flag(sgn_μν)
end
# do -v -> v
if v < 0.0
v *= -1.0
sgn_μ = set_flag(sgn_μ)
end
# do -vp -> vp
if vp < 0.0
vp *= -1.0
sgn_ν = set_flag(sgn_ν)
end
return get_buffer(w, v, vp, m.Ωt, m.νt, exchange_flag, map_flag, sgn_μν, sgn_μ, sgn_ν)
end
# generate access buffer for u channel of Action struct
function get_buffer_u(
w :: Float64,
v :: Float64,
vp :: Float64,
m :: Mesh
) :: Buffer
# init flags
exchange_flag = false
map_flag = false
sgn_μν = false
sgn_μ = false
sgn_ν = false
# do -w -> w
if w < 0.0
w *= -1.0
exchange_flag = set_flag(exchange_flag)
sgn_μν = set_flag(sgn_μν)
end
# do -v -> v
if v < 0.0
v *= -1.0
exchange_flag = set_flag(exchange_flag)
map_flag = set_flag(map_flag)
sgn_ν = set_flag(sgn_ν)
end
# do -vp -> vp
if vp < 0.0
vp *= -1.0
map_flag = set_flag(map_flag)
sgn_ν = set_flag(sgn_ν)
end
return get_buffer(w, v, vp, m.Ωs, m.νs, exchange_flag, map_flag, sgn_μν, sgn_μ, sgn_ν)
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 3666 | """
Mesh
Struct containing frequency meshes for the self energy, vertices and correlations.
* `num_σ :: Int64` : total number of frequencies in the self energy mesh
* `num_Ω :: Int64` : total number of frequencies in the bosonic meshes
* `num_ν :: Int64` : total number of frequencies in the fermionic meshes
* `num_χ :: Int64` : total number of frequencies in the correlation mesh
* `σ :: Vector{Float64}` : self energy mesh
* `Ωs :: Vector{Float64}` : bosonic mesh for the s (u) channel
* `νs :: Vector{Float64}` : fermionic mesh for the s (u) channel
* `Ωt :: Vector{Float64}` : bosonic mesh for the t channel
* `νt :: Vector{Float64}` : fermionic mesh for the t channel
* `χ :: Vector{Float64}` : correlation mesh
"""
struct Mesh
num_σ :: Int64
num_Ω :: Int64
num_ν :: Int64
num_χ :: Int64
σ :: Vector{Float64}
Ωs :: Vector{Float64}
νs :: Vector{Float64}
Ωt :: Vector{Float64}
νt :: Vector{Float64}
χ :: Vector{Float64}
end
# auxiliary function to fetch frequency arguments for a specific channel and kernel
function get_kernel_args(
ch :: Int64,
kernel :: Int64,
w1 :: Int64,
w2 :: Int64,
w3 :: Int64,
m :: Mesh
) :: NTuple{3, Float64}
# fetch arguments for s channel
if ch == 1
if kernel == 1
return m.Ωs[w1], Inf, Inf
elseif kernel == 2
return m.Ωs[w1], m.νs[w2], Inf
elseif kernel == 3
return m.Ωs[w1], Inf, m.νs[w3]
else
return m.Ωs[w1], m.νs[w2], m.νs[w3]
end
# fetch arguments for t channel
elseif ch == 2
if kernel == 1
return m.Ωt[w1], Inf, Inf
elseif kernel == 2
return m.Ωt[w1], m.νt[w2], Inf
elseif kernel == 3
return m.Ωt[w1], Inf, m.νt[w3]
else
return m.Ωt[w1], m.νt[w2], m.νt[w3]
end
# fetch arguments for u channel
else
if kernel == 1
return m.Ωs[w1], Inf, Inf
elseif kernel == 2
return m.Ωs[w1], m.νs[w2], Inf
elseif kernel == 3
return m.Ωs[w1], Inf, m.νs[w3]
else
return m.Ωs[w1], m.νs[w2], m.νs[w3]
end
end
end
"""
get_mesh(
linear :: Float64,
upper :: Float64,
num :: Int64,
p :: Float64
) :: Vector{Float64}
Generate a mesh of (num + 1) linearly (0.0 to linear) and logarithmically (linear to upper) spaced frequencies.
Thereby linear and upper are explicitly included and p * num frequencies of the grid are devoted to the linear part.
"""
function get_mesh(
linear :: Float64,
upper :: Float64,
num :: Int64,
p :: Float64
) :: Vector{Float64}
# sanity checks
@assert linear > 0.0 "Linear bound must be larger than zero."
@assert upper > 0.0 "Upper bound must be larger than zero."
@assert linear < upper "Linear bound must be smaller than upper bound."
# compute number of linear and logarithmic points
num_lin = ceil(Int64, p * num)
num_log = num - num_lin
# sanity check
@assert num_log > 0 "Number of frequencies is too small."
# determine linear width and logarithmic factor
h = linear / num_lin
ξ = (upper / linear)^(1.0 / num_log)
# allocate list
mesh = zeros(Float64, num + 1)
# compute frequencies
for i in 1 : num_lin
mesh[i + 1] = i * h
end
for i in 1 : num_log
mesh[num_lin + 1 + i] = ξ^i * linear
end
return mesh
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 2277 | """
Param
Struct containing interpolation parameters for a single point in a mesh.
* `lower_index :: Int64` : index of nearest neighbor in mesh with smaller value
* `upper_index :: Int64` : index of nearest neighbor in mesh with larger value
* `lower_weight :: Float64` : interpolation weight for mesh[lower_index]
* `upper_weight :: Float64` : interpolation weight for mesh[upper_index]
"""
struct Param
lower_index :: Int64
upper_index :: Int64
lower_weight :: Float64
upper_weight :: Float64
end
# generate param dummy
function get_param_empty() :: Param
p = Param(0, 0, 0.0, 0.0)
return p
end
# find nearest neighbor (lower and upper) indices in sorted list including zero
function get_indices(
val :: Float64,
list :: Vector{Float64}
) :: NTuple{2, Int64}
# init indices
lower_index = 0
upper_index = 0
# check if in bounds otherwise search list
if val >= list[end]
lower_index, upper_index = length(list), length(list)
else
# iterate over list until upper_index is found (lower_index is then also determined)
index_current = 1
while val > list[index_current]
index_current += 1
end
lower_index = index_current
upper_index = index_current
if val < list[index_current]
lower_index -= 1
end
end
return lower_index, upper_index
end
"""
get_param(
val :: Float64,
list :: Vector{Float64}
) :: Param
Compute interpolation parameters of val in a set of discrete points (list) and buffer result in Param struct.
"""
function get_param(
val :: Float64,
list :: Vector{Float64}
) :: Param
# get neighbors and init weights
lower_index, upper_index = get_indices(val, list)
lower_weight, upper_weight = 0.0, 0.0
# compute weights
if lower_index < upper_index
d = 1.0 / (list[upper_index] - list[lower_index])
lower_weight = d * (list[upper_index] - val)
upper_weight = d * (val - list[lower_index])
else
lower_weight = 1.0
end
# build param
p = Param(lower_index, upper_index, lower_weight, upper_weight)
return p
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1774 | """
test_frequencies() :: Nothing
Run consistency checks for current frequency implementation for meshes with 30 positive frequencies.
"""
function test_frequencies() :: Nothing
# init test dummys
list = get_mesh(rand(), 1.0, 30, 0.4)
m = Mesh(31, 31, 31, 31, list, list, list, list, list, list)
w = rand()
v = rand()
vp = rand()
# test list bounds
@testset "list bounds" begin
@test list[1] ≈ 0.0
@test list[end] ≈ 1.0
end
# test frequency buffers
@testset "buffers" begin
@testset "s channel" begin
b = get_buffer_s(w, v, vp, m); @test b.kernel == 4
b = get_buffer_s(w, Inf, vp, m); @test b.kernel == 3
b = get_buffer_s(w, v, Inf, m); @test b.kernel == 2
b = get_buffer_s(w, Inf, Inf, m); @test b.kernel == 1
b = get_buffer_s(Inf, Inf, Inf, m); @test b.kernel == 0
end
@testset "t channel" begin
b = get_buffer_t(w, v, vp, m); @test b.kernel == 4
b = get_buffer_t(w, Inf, vp, m); @test b.kernel == 3
b = get_buffer_t(w, v, Inf, m); @test b.kernel == 2
b = get_buffer_t(w, Inf, Inf, m); @test b.kernel == 1
b = get_buffer_t(Inf, Inf, Inf, m); @test b.kernel == 0
end
@testset "u channel" begin
b = get_buffer_u(w, v, vp, m); @test b.kernel == 4
b = get_buffer_u(w, Inf, vp, m); @test b.kernel == 3
b = get_buffer_u(w, v, Inf, m); @test b.kernel == 2
b = get_buffer_u(w, Inf, Inf, m); @test b.kernel == 1
b = get_buffer_u(Inf, Inf, Inf, m); @test b.kernel == 0
end
end
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 1014 | """
get_frequency_timers() :: Nothing
Test performance of current frequency implementation for meshes with 30 positive frequencies.
"""
function get_frequency_timers() :: Nothing
# init test dummys
list = get_mesh(rand(), 1.0, 30, 0.4)
m = Mesh(31, 31, 31, 31, list, list, list, list, list, list)
w = rand()
v = rand()
vp = rand()
# init timer
to = TimerOutput()
# time single interpolation
@timeit to "=> single interpolation" begin
for rep in 1 : 10
@timeit to "-> index search" get_indices(w, list)
@timeit to "-> param build" get_param(w, list)
end
end
# time buffer building
@timeit to "=> buffer building" begin
for rep in 1 : 10
@timeit to "-> s channel" get_buffer_s(w, v, vp, m)
@timeit to "-> t channel" get_buffer_t(w, v, vp, m)
@timeit to "-> u channel" get_buffer_u(w, v, vp, m)
end
end
show(to)
return nothing
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 173 | # load code
include("unitcell.jl")
include("site.jl")
include("bond.jl")
include("build.jl")
include("reduced.jl")
include("disk.jl")
include("test.jl")
include("timers.jl") | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
|
[
"MIT"
] | 0.5.0 | 5e2cd6b758e228080cdb43b0e0c469683fcd68b2 | code | 856 | """
Bond
Struct encapsulating the interactions between two lattice sites in matrix form.
* `sites :: Tuple{Int64, Int64}` : indices of interacting lattice sites
* `exchange :: Matrix{Float64}` : interaction matrix
"""
struct Bond
sites :: Tuple{Int64, Int64}
exchange :: Matrix{Float64}
end
# generate a bond with vanishing interactions
function get_bond_empty(
i :: Int64,
j :: Int64
) :: Bond
b = Bond((i, j), zeros(Float64, 3, 3))
return b
end
# modify bond matrix in place
function add_bond!(
J :: Float64,
b :: Bond,
μ :: Int64,
ν :: Int64
) :: Nothing
b.exchange[μ, ν] += J
return nothing
end
# check if bonds are equal
function are_equal(
b1 :: Bond,
b2 :: Bond
) :: Bool
equal = norm(b1.exchange .- b2.exchange) <= 1e-8
return equal
end | PFFRGSolver | https://github.com/dominikkiese/PFFRGSolver.jl.git |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.