diff --git a/.gitignore b/.gitignore index 4105c32..639799a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,26 @@ -*.jl.*.cov +# Files generated by invoking Julia with --code-coverage *.jl.cov -*.jl.mem +*.jl.*.cov *.jld2 -/docs/build/ + +# Files generated by invoking Julia with --track-allocation +*.jl.mem + +# System-specific files and directories generated by the BinaryProvider and BinDeps packages +# They contain absolute paths specific to the host computer, and so should not be committed +deps/deps.jl +deps/build.log +deps/downloads/ +deps/usr/ +deps/src/ + +# Build artifacts for creating documentation generated by the Documenter package +docs/build/ +docs/site/ +/run/ + +# File generated by Pkg, the package manager, based on a corresponding Project.toml +# It records a fixed state of all packages used by the project. As such, it should not be +# committed for packages, but should be committed for applications that require a static +# environment. +Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index ea79e7b..0000000 --- a/Manifest.toml +++ /dev/null @@ -1,290 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[ArgTools]] -uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" - -[[Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[ChainRulesCore]] -deps = ["Compat", "LinearAlgebra", "SparseArrays"] -git-tree-sha1 = "d711603452231bad418bd5e0c91f1abd650cba71" -uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" -version = "1.11.3" - -[[ChangesOfVariables]] -deps = ["ChainRulesCore", "LinearAlgebra", "Test"] -git-tree-sha1 = "bf98fa45a0a4cee295de98d4c1462be26345b9a1" -uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" -version = "0.1.2" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "44c37b4636bc54afac5c574d2d02b625349d6582" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.41.0" - -[[CompilerSupportLibraries_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" - -[[CompositeGrids]] -deps = ["DelimitedFiles", "FastGaussQuadrature", "FileIO", "JLD2", "LinearAlgebra", "Printf", "Quadmath", "Random", "StaticArrays", "Statistics"] -git-tree-sha1 = "7ccfda7b5bbb6989dde6d9b3824b532007d594cb" -uuid = "b5136c89-beeb-4521-9139-60d2cac8be56" -version = "0.0.3" - -[[DataStructures]] -deps = ["Compat", "InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.18.11" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[DocStringExtensions]] -deps = ["LibGit2"] -git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b" -uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.8.6" - -[[Downloads]] -deps = ["ArgTools", "LibCURL", "NetworkOptions"] -uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" - -[[FastGaussQuadrature]] -deps = ["LinearAlgebra", "SpecialFunctions", "StaticArrays"] -git-tree-sha1 = "58d83dd5a78a36205bdfddb82b1bb67682e64487" -uuid = "442a2c76-b920-505d-bb47-c5924d526838" -version = "0.4.9" - -[[FileIO]] -deps = ["Pkg", "Requires", "UUIDs"] -git-tree-sha1 = "2db648b6712831ecb333eae76dbfd1c156ca13bb" -uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" -version = "1.11.2" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[InverseFunctions]] -deps = ["Test"] -git-tree-sha1 = "a7254c0acd8e62f1ac75ad24d5db43f5f19f3c65" -uuid = "3587e190-3f89-42d0-90ee-14403ec27112" -version = "0.1.2" - -[[IrrationalConstants]] -git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151" -uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" -version = "0.1.1" - -[[JLD2]] -deps = ["DataStructures", "FileIO", "MacroTools", "Mmap", "Pkg", "Printf", "Reexport", "TranscodingStreams", "UUIDs"] -git-tree-sha1 = "09ef0c32a26f80b465d808a1ba1e85775a282c97" -uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" -version = "0.4.17" - -[[JLLWrappers]] -deps = ["Preferences"] -git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e" -uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" -version = "1.3.0" - -[[Lehmann]] -deps = ["DelimitedFiles", "FastGaussQuadrature", "LinearAlgebra", "Printf", "Quadmath", "StaticArrays"] -git-tree-sha1 = "011264d58bceeb682fdf285c3c12c1b56bba07fc" -uuid = "95bf888a-8996-4655-9f35-1c0506bdfefe" -version = "0.2.0" - -[[LibCURL]] -deps = ["LibCURL_jll", "MozillaCACerts_jll"] -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" - -[[LibCURL_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] -uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" - -[[LibGit2]] -deps = ["Base64", "NetworkOptions", "Printf", "SHA"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[LibSSH2_jll]] -deps = ["Artifacts", "Libdl", "MbedTLS_jll"] -uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[LogExpFunctions]] -deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] -git-tree-sha1 = "e5718a00af0ab9756305a0392832c8952c7426c1" -uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" -version = "0.3.6" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[MacroTools]] -deps = ["Markdown", "Random"] -git-tree-sha1 = "3d3e902b31198a27340d0bf00d6ac452866021cf" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.9" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" - -[[NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" - -[[OpenLibm_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "05823500-19ac-5b8b-9628-191a04bc5112" - -[[OpenSpecFun_jll]] -deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" -uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" -version = "0.5.5+0" - -[[OrderedCollections]] -git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.4.1" - -[[Pkg]] -deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[Preferences]] -deps = ["TOML"] -git-tree-sha1 = "2cf929d64681236a2e074ffafb8d568733d2e6af" -uuid = "21216c6a-2e73-6563-6e65-726566657250" -version = "1.2.3" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[Quadmath]] -deps = ["Printf", "Random", "Requires"] -git-tree-sha1 = "5a8f74af8eae654086a1d058b4ec94ff192e3de0" -uuid = "be4d8f0f-7fa4-5f49-b795-2f01399ab2dd" -version = "0.5.5" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[Reexport]] -git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "1.2.2" - -[[Requires]] -deps = ["UUIDs"] -git-tree-sha1 = "8f82019e525f4d5c669692772a6f4b0a58b06a6a" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "1.2.0" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[SpecialFunctions]] -deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] -git-tree-sha1 = "e08890d19787ec25029113e88c34ec20cac1c91e" -uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "2.0.0" - -[[StaticArrays]] -deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "3c76dde64d03699e074ac02eb2e8ba8254d428da" -uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.2.13" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" - -[[Tar]] -deps = ["ArgTools", "SHA"] -uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" - -[[Test]] -deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[TranscodingStreams]] -deps = ["Random", "Test"] -git-tree-sha1 = "216b95ea110b5972db65aa90f88d8d89dcb8851c" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.9.6" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" - -[[nghttp2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" - -[[p7zip_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" diff --git a/src/GreenFunc.jl b/src/GreenFunc.jl index fe0f8e4..de4f1a1 100644 --- a/src/GreenFunc.jl +++ b/src/GreenFunc.jl @@ -2,20 +2,9 @@ module GreenFunc using StaticArrays, Lehmann, CompositeGrids # Write your package code here. -abstract type TimeDomain end -abstract type ImTime <: TimeDomain end -abstract type ReTime <: TimeDomain end -abstract type ImFreq <: TimeDomain end -abstract type ReFreq <: TimeDomain end -abstract type DLRFreq <: TimeDomain end - -struct DLRInterp <: CompositeGrids.Interp.InterpStyle end - -export TimeDomain, ImTime, ReTime, ImFreq, ReFreq, DLRFreq include("green/Green.jl") -export Green2DLR, toTau, toMatFreq, toDLR, getDynamic, getInstant - - +export TimeDomain, ImTime, ReTime, ImFreq, ReFreq, DLRFreq +export Green2DLR, toTau, toMatFreq, toDLR, dynamic, instant end diff --git a/src/green/Green.jl b/src/green/Green.jl index bcd5869..1b4278c 100644 --- a/src/green/Green.jl +++ b/src/green/Green.jl @@ -2,70 +2,43 @@ General Green's function. """ - -# """ -# Green's function with two external legs. The structure saves a function G( τ, q, σ) -# and corresponding grids of τ, q and σ. - -# #Members: -# - 'timeType': Whether the Green's function is in time/frequency/dlr space -# - 'spaceType': Whether the Green's function is in coordinate space or momentum space -# - 'color': Indices of species of Green's function (such as different spin values) -# - 'isFermi': Particle is fermi or boson -# - 'timeSymmetry': Whether the Green's function has particle-hole symmetry, anti-particle-hole symmetry or none of them -# - 'spaceSymmetry': Symmetry of lattice -# - 'timeGrid': Time or Frequency grid -# - 'β':Inverse temperature -# - 'spaceGrid': Coordinate or momentum grid -# - 'instant': Instantaneous part of Green's function that is δ(τ) in τ space. -# - 'dynamic': Dynamic part of Green's function -# """ -# mutable struct Green2{T<:AbstractFloat,TGT,SGT,CT} -# timeType::Symbol -# spaceType::Symbol -# isFermi::Bool -# timeSymmetry::Symbol -# spaceSymmetry::Any -# β::Float64 -# color::CT -# timeGrid::TGT -# spaceGrid::SGT -# instant::AbstractArray{T,3} -# dynamic::AbstractArray{T,4} - - -# """ -# function GreenTwo{T,TGT,SGT,CT}(ttype,stype,color_n,tgrid,sgrid)where{T<:AbstractFloat,TGT,SGT,CT} - -# create two-leg Green's function on tgrid, sgrid and color_n. -# The value of Green's function is initialized with zero. -# """ -# function Green2{T}(timeType,spaceType,isFermi, β,timeGrid::TGT, spaceGrid::SGT; color::CT=nothing,timeSymmetry=:none, spaceSymmetry=nothing,error=nothing)where{T<:Number,TGT,SGT,CT} -# ct = CT -# if(color == nothing) -# color = [1] -# ct = typeof(color) -# end -# static_val = zeros(T, (length(color),length(color),length(spaceGrid))) -# dynamic_val = zeros(T, (length(color), length(color), length(spaceGrid),length(timeGrid))) -# instant = static_val -# dynamic = dynamic_val -# return new{T,TGT,SGT,ct}(timeType,spaceType,isFermi,timeSymmetry,spaceSymmetry, β,color,timeGrid,spaceGrid,instant,dynamic, error) -# end -# end - +abstract type TimeDomain end +struct ImTime <: TimeDomain end +struct ReTime <: TimeDomain end +struct ImFreq <: TimeDomain end +struct ReFreq <: TimeDomain end +struct DLRFreq <: TimeDomain end +const IMTIME = ImTime() +const RETIME = ReTime() +const IMFREQ = ImFreq() +const REFREQ = ReFreq() +const DLRFREQ = DLRFreq() + +abstract type InterpMethod end +struct DefaultInterp <: InterpMethod end +struct LinearInterp <: InterpMethod end +struct DLRInterp <: InterpMethod end +const DEFAULTINTERP = DefaultInterp() +const LINEARINTERP = LinearInterp() +const DLRINTERP = DLRInterp() + + +InterpMethod(GT::Type{<:CompositeGrids.AbstractGrid}, MT::Type{<:LinearInterp}) = CompositeGrids.Interp.LinearInterp() +InterpMethod(GT::Type{<:CompositeGrids.AbstractGrid}, MT::Type{<:DefaultInterp}) = CompositeGrids.Interp.InterpStyle(GT) +InterpMethod(GT, MT::Type{<:DLRInterp}) = DLRInterp() """ Green's function with two external legs that has in-built Discrete Lehmann Representation. +#Parameters: +- 'T': type of data +- 'TType': type of time domain, TType<:TimeDomain +- 'TGT': type of time grid +- 'SGT': type of space grid #Members: - 'name': Name of green's function -- 'isFermi': Particle is fermi or boson -- 'β': Inverse temperature - 'color': Number of different species of Green's function (such as different spin values) - 'dlrGrid': In-built Discrete Lehmann Representation -- 'timeType': Whether the Green's function is in time/frequency/dlr space -- 'timeSymmetry': Whether the Green's function has particle-hole symmetry, anti-particle-hole symmetry or none of them - 'timeGrid': Time or Frequency grid - 'spaceType': Whether the Green's function is in coordinate space/momentum space - 'spaceGrid': Coordinate or momentum grid @@ -76,15 +49,15 @@ Green's function with two external legs that has in-built Discrete Lehmann Repre """ mutable struct Green2DLR{T<:Number,Type<:TimeDomain,TGT,SGT} name::Symbol - isFermi::Bool - β::Float64 + # isFermi::Bool + # β::Float64 color::Int dlrGrid::DLRGrid ######### Mesh ############## - timeType::DataType - timeSymmetry::Symbol + # timeType::DataType + # timeSymmetry::Symbol timeGrid::TGT spaceType::Symbol @@ -99,12 +72,15 @@ mutable struct Green2DLR{T<:Number,Type<:TimeDomain,TGT,SGT} dynamicError::Array{T,4} """ - function Green2DLR{T,TimeType}(name::Symbol, β, isFermi::Bool, Euv, spaceGrid, color::Int = 1; + function Green2DLR{T}(name::Symbol, timeType::TT, β, isFermi::Bool, Euv, spaceGrid, color::Int = 1; timeSymmetry::Symbol = :none, rtol = 1e-8, kwargs... - ) where {T<:Number,TimeType<:TimeDomain} + ) where {T<:Number, TT<:TimeDomain} + Create two-leg Green's function on timeGrid, spaceGrid and color, with in-built DLR. + #Arguements - - 'name': Name of green's function. + - 'name': Name of green's function. + - 'timeType': type of time domain, TT<:TimeDomain - 'β': Inverse temperature - 'isFermi': Particle is fermi or boson - 'Euv': the UV energy scale of the spectral density @@ -119,9 +95,9 @@ mutable struct Green2DLR{T<:Number,Type<:TimeDomain,TGT,SGT} - 'instantError': Error of instantaneous part. Default: 0 everywhere - 'dynamicError': Error of dynamic part. Default: 0 everywhere """ - function Green2DLR{T,TimeType}(name::Symbol, β, isFermi::Bool, Euv, spaceGrid, color::Int = 1; + function Green2DLR{T}(name::Symbol, timeType::TT, β, isFermi::Bool, Euv, spaceGrid, color::Int = 1; timeSymmetry::Symbol = :none, rtol = 1e-8, kwargs... - ) where {T<:Number,TimeType<:TimeDomain} + ) where {T<:Number, TT<:TimeDomain} # @assert spaceType == :k || spaceType == :x @assert timeSymmetry == :ph || timeSymmetry == :pha || timeSymmetry == :none @@ -132,52 +108,71 @@ mutable struct Green2DLR{T<:Number,Type<:TimeDomain,TGT,SGT} println(keys(kwargs)) if :timeGrid in keys(kwargs) - timeGrid = kwargs[:timeGrid] + givenTimeGrid = kwargs[:timeGrid] + if givenTimeGrid isa AbstractVector + timeGrid = CompositeGrids.SimpleG.Arbitrary{eltype(givenTimeGrid)}(givenTimeGrid) + elseif givenTimeGrid isa CompositeGrids.AbstractGrid + timeGrid = givenTimeGrid + else + error("Input timeGrid has to be Vector or Composite grid") + end else - if TimeType == ImFreq - timeGrid = dlrGrid.n - elseif TimeType == ImTime - timeGrid = dlrGrid.τ - elseif TimeType == DLRFreq - timeGrid = dlrGrid.ω + if TT == ImFreq + bareTimeGrid = dlrGrid.n + elseif TT == ImTime + bareTimeGrid = dlrGrid.τ + elseif TT == DLRFreq + bareTimeGrid = dlrGrid.ω else error("$TimeType is not supported!") end + timeGrid = CompositeGrids.SimpleG.Arbitrary{eltype(bareTimeGrid)}(bareTimeGrid) end #if timeGrid is nothing, then set it to be the DLR grid, which is a vector of Integer or Float64 - if timeGrid isa AbstractVector - timeGrid = CompositeGrids.SimpleG.Arbitrary{eltype(timeGrid)}(timeGrid) - end - @assert timeGrid isa AbstractGrid "Input timeGrid has to be Vector or Composite grid" - if TimeType == DLRFreq - @assert length(timeGrid.grid) == dlrGrid.size "The size of the DLR grid should match the DLR rank = $(dlrGrid.size)." - elseif TimeType == ImFreq + + if TT == DLRFreq + #@assert length(timeGrid.grid) == dlrGrid.size "The size of the DLR grid should match the DLR rank = $(dlrGrid.size)." + elseif TT == ImFreq @assert eltype(timeGrid.grid) <: Int "Matsubara frequency grid is expected to be integers!" end - # println(TGT) - if spaceGrid isa AbstractVector - spaceGrid = CompositeGrids.SimpleG.Arbitrary{eltype(spaceGrid)}(spaceGrid) + compSpaceGrid = CompositeGrids.SimpleG.Arbitrary{eltype(spaceGrid)}(spaceGrid) + elseif spaceGrid isa CompositeGrids.AbstractGrid + compSpaceGrid = spaceGrid + else + error("Input spaceGrid has to be Vector or Composite grid") end - @assert spaceGrid isa AbstractGrid "Input spaceGrid has to be Vector or Composite grid" instant = Array{T,3}(undef, 0, 0, 0) dynamic = Array{T,4}(undef, 0, 0, 0, 0) instantError = Array{T,3}(undef, 0, 0, 0) dynamicError = Array{T,4}(undef, 0, 0, 0, 0) - gnew = new{T,TimeType,typeof(timeGrid),typeof(spaceGrid)}( - name, isFermi, β, color, dlrGrid, - TimeType, timeSymmetry, timeGrid, - spaceType, spaceGrid, + gnew = new{T,TT,typeof(timeGrid),typeof(compSpaceGrid)}( + name, color, dlrGrid, + timeGrid, + spaceType, compSpaceGrid, instant, dynamic, instantError, dynamicError) - return set!(gnew; kwargs...) end end +function Base.getproperty(obj::Green2DLR{T,TT,TGT,SGT}, sym::Symbol) where {T,TT,TGT,SGT} + if sym === :isFermi + return obj.dlrGrid.isFermi + elseif sym === :β + return obj.dlrGrid.β + elseif sym === :timeType + return TT + elseif sym === :timeSymmetry + return obj.dlrGrid.symmetry + else # fallback to getfield + return getfield(obj, sym) + end +end + function Base.size(green::Green2DLR) return (green.color, green.color, size(green.spaceGrid), size(green.timeGrid)) end @@ -202,11 +197,12 @@ end """ function toTau(green::Green2DLR, targetGrid = green.dlrGrid.τ) - Convert Green's function to τ space by Fourier transform. - If green is already in τ space then it will be interpolated to the new grid. - #Arguements - - 'green': Original Green's function - - 'targetGrid': Grid of outcome Green's function. Default: DLR τ grid +Convert Green's function to τ space by Fourier transform. +If green is already in τ space then it will be interpolated to the new grid. + +#Arguements +- 'green': Original Green's function +- 'targetGrid': Grid of outcome Green's function. Default: DLR τ grid """ function toTau(green::Green2DLR, targetGrid = green.dlrGrid.τ) @@ -231,20 +227,20 @@ function toTau(green::Green2DLR, targetGrid = green.dlrGrid.τ) dynamic = dlr2tau(green.dlrGrid, green.dynamic, targetGrid.grid; axis = 4) end - return Green2DLR{eltype(dynamic),ImTime}( - green.name, green.β, green.isFermi, green.dlrGrid.Euv, green.spaceGrid, green.color; + return Green2DLR{eltype(dynamic)}( + green.name, IMTIME,green.β, green.isFermi, green.dlrGrid.Euv, green.spaceGrid, green.color; timeSymmetry = green.timeSymmetry, timeGrid = targetGrid, rtol = green.dlrGrid.rtol, dynamic = dynamic, instant = green.instant) - end """ - function toTau(green::Green2DLR, targetGrid = green.dlrGrid.τ) - Convert Green's function to τ space by Fourier transform. - If green is already in τ space then it will be interpolated to the new grid. - #Arguements - - 'green': Original Green's function - - 'targetGrid': Grid of outcome Green's function. Default: DLR τ grid + function toMatFreq(green::Green2DLR, targetGrid = green.dlrGrid.n) +Convert Green's function to matfreq space by Fourier transform. +If green is already in matfreq space then it will be interpolated to the new grid. + +#Arguements +- 'green': Original Green's function +- 'targetGrid': Grid of outcome Green's function. Default: DLR n grid """ function toMatFreq(green::Green2DLR, targetGrid = green.dlrGrid.n) @@ -269,29 +265,24 @@ function toMatFreq(green::Green2DLR, targetGrid = green.dlrGrid.n) dynamic = dlr2matfreq(green.dlrGrid, green.dynamic, targetGrid.grid; axis = 4) end - return Green2DLR{eltype(dynamic),ImFreq}( - green.name, green.β, green.isFermi, green.dlrGrid.Euv, green.spaceGrid, green.color; + return Green2DLR{eltype(dynamic)}( + green.name, IMFREQ, green.β, green.isFermi, green.dlrGrid.Euv, green.spaceGrid, green.color; timeSymmetry = green.timeSymmetry, timeGrid = targetGrid, rtol = green.dlrGrid.rtol, dynamic = dynamic, instant = green.instant) end """ - function toTau(green::Green2DLR, targetGrid = green.dlrGrid.τ) - Convert Green's function to τ space by Fourier transform. - If green is already in τ space then it will be interpolated to the new grid. - #Arguements - - 'green': Original Green's function - - 'targetGrid': Grid of outcome Green's function. Default: DLR τ grid + function toDLR(green::Green2DLR) +Convert Green's function to dlr space. + +#Arguements +- 'green': Original Green's function """ function toDLR(green::Green2DLR) - - targetGrid = CompositeGrids.SimpleG.Arbitrary{eltype(green.dlrGrid.ω)}(green.dlrGrid.ω) - - # do nothing if the domain and the grid remain the same - if green.timeType == ImFreq + if green.timeType == DLRFreq return green end if isempty(green.dynamic) # if dynamic data has not yet been initialized, there is nothing to do @@ -300,145 +291,109 @@ function toDLR(green::Green2DLR) if (green.timeType == ImTime) - dynamic = dlr2tau(green.dlrGrid, green.dynamic, targetGrid.grid; axis = 4) + dynamic = tau2dlr(green.dlrGrid, green.dynamic, green.timeGrid.grid; axis = 4) elseif (green.timeType == ImFreq) - dynamic = dlr2matfreq(green.dlrGrid, green.dynamic, targetGrid.grid; axis = 4) + dynamic = matfreq2dlr(green.dlrGrid, green.dynamic, green.timeGrid.grid; axis = 4) end - return Green2DLR{eltype(dynamic),DLRFreq}( - green.name, green.β, green.isFermi, green.dlrGrid.Euv, green.spaceGrid, green.color; - timeSymmetry = green.timeSymmetry, timeGrid = targetGrid, rtol = green.dlrGrid.rtol, + return Green2DLR{eltype(dynamic)}( + green.name,DLRFREQ, green.β, green.isFermi, green.dlrGrid.Euv, green.spaceGrid, green.color; + timeSymmetry = green.timeSymmetry, timeGrid = green.dlrGrid.ω, rtol = green.dlrGrid.rtol, dynamic = dynamic, instant = green.instant) end -# """ -# function toMatFreq(green::Green2DLR, targetGrid = green.dlrGrid.τ) -# Convert Green's function to ωn space by Fourier transform. -# If green is already in ωn space then it will be interpolated to the new grid. -# #Arguements -# - 'green': Original Green's function -# - 'targetGrid': Grid of outcome Green's function. Default: DLR n grid -# """ -# function toMatFreq(green::Green2DLR, targetGrid = green.dlrGrid.n) -# if green.hasError -# #error = green.dynamicError -# error = nothing -# else -# error = nothing -# end -# if (typeof(targetGrid) <: AbstractVector{}) -# targetGrid = CompositeGrids.SimpleG.Arbitrary{eltype(targetGrid)}(targetGrid) -# end -# if (green.timeType == :n) -# dynamic = matfreq2matfreq(green.dlrGrid, green.dynamic, targetGrid.grid, green.timeGrid.grid; error, axis = 4) -# elseif (green.timeType == :τ) -# dynamic = tau2matfreq(green.dlrGrid, green.dynamic, targetGrid.grid, green.timeGrid.grid; error, axis = 4) -# elseif (green.timeType == :ω) -# dynamic = dlr2matfreq(green.dlrGrid, green.dynamic, targetGrid.grid; axis = 4) -# end -# green_new = Green2DLR{eltype(dynamic)}(green.isFermi, green.dlrGrid.Euv, green.dlrGrid.rtol, green.spaceType, green.spaceGrid, green.β, :n; timeSymmetry = green.timeSymmetry, timeGrid = targetGrid, color = green.color, spaceSymmetry = green.spaceSymmetry) -# green_new.dynamic = dynamic -# green_new.instant = green.instant -# if green.hasError -# green_new.instantError = green.instantError -# green_new.dynamicError = green_new.dynamic -# # Need future implementation -# end -# return green_new -# end - -# """ -# function toTau(green::Green2DLR) -# Convert Green's function to its DLR coefficents. -# Return a copy of green If it is already in dlr space. -# #Arguements -# - 'green': Original Green's function -# """ -# function toDLR(green::Green2DLR) -# if green.hasError -# #error = green.dynamicError -# error = nothing -# else -# error = nothing -# end -# targetGrid = CompositeGrids.SimpleG.Arbitrary{eltype(green.dlrGrid.ω)}(green.dlrGrid.ω) -# if (green.timeType == :ω) -# green_new = deepcopy(green) -# return green_new -# elseif (green.timeType == :n) -# dynamic = matfreq2dlr(green.dlrGrid, green.dynamic, green.timeGrid.grid; error, axis = 4) -# elseif (green.timeType == :τ) -# dynamic = tau2dlr(green.dlrGrid, green.dynamic, green.timeGrid.grid; error, axis = 4) -# end -# green_new = Green2DLR{eltype(dynamic)}(green.isFermi, green.dlrGrid.Euv, green.dlrGrid.rtol, green.spaceType, green.spaceGrid, green.β, :ω; timeSymmetry = green.timeSymmetry, timeGrid = targetGrid, color = green.color, spaceSymmetry = green.spaceSymmetry) -# green_new.dynamic = dynamic -# green_new.instant = green.instant -# if green.hasError -# green_new.instantError = green.instantError -# green_new.dynamicError = green_new.dynamic -# # Need future implementation -# end -# return green_new -# end +""" + function instant(green::Green2DLR{DT,TT,TGT,SGT}, space, color1::Int, color2::Int=color1; spaceMethod::SM = DEFAULTINTERP) where {DT,TT,TGT,SGT,SM} +Find value of Green's function's instant part at given color and k/x by interpolation. +Interpolation method is by default depending on the grid, but could also be chosen to be linear. + +#Argument +- 'green': Green's function +- 'space': Target k/x point +- 'color1': Target color1 +- 'color2': Target color2 +- 'spaceMethod': Method of interpolation for space. +""" +function instant(green::Green2DLR{DT,TT,TGT,SGT}, space, color1::Int, color2::Int=color1; spaceMethod::SM = DEFAULTINTERP) where {DT,TT,TGT,SGT,SM} + if isempty(green.instant) + error("Instant Green's function can not be empty!") + else + IM = InterpMethod(SGT,SM) + nei = CompositeGrids.Interp.findneighbor(IM, green.spaceGrid,space) + instant_x = view(green.instant, color1, color2, nei.index) + return CompositeGrids.Interp.interpsliced(nei,instant_x) + end +end """ - function get(green::Green2DLR, time, space; color=nothing, timeMethod = :default, spaceMethod=:default) + function dynamic(green::Green2DLR{DT,TT,TGT,SGT}, time, space, color1::Int, color2::Int, timeMethod::TM , spaceMethod::SM) where {DT,TT,TGT<:CompositeGrids.AbstractGrid,SGT<:CompositeGrids.AbstractGrid,TM,SM} + +Find value of Green's function's dynamic part at given color and k/x by interpolation. +Interpolation method is by default depending on the grid, but could also be chosen to be linear. -Find value of Green's function at given color, τ/ωn and k/x by interpolation. -Interpolation in τ/ωn use DLR method #Argument - 'green': Green's function -- 'time': Target τ/ωn point +- 'time': Target τ/ω_n point - 'space': Target k/x point -- 'colorvalue': Target color -- 'timeMethod':Method of interpolation in ωn/τ -- 'spacemethod': Method of interpolation in k/x +- 'color1': Target color1 +- 'color2': Target color2 +- 'timeMethod': Method of interpolation for time +- 'spaceMethod': Method of interpolation for space """ -function getDynamic(green::Green2DLR, time, space; colorIndex = 1, timeMethod = CompositeGrids.Interp.LinearInterp(), spaceMethod = CompositeGrids.Interp.LinearInterp()) - #@assert green.timeType == :n || green.timeType == :τ - if !(typeof(spaceMethod)<:CompositeGrids.Interp.InterpStyle) - error("Space Interpolation method not implemented!") - end +function dynamic(green::Green2DLR{DT,TT,TGT,SGT}, time, space, color1::Int, color2::Int, timeMethod::TM , spaceMethod::SM) where {DT,TT,TGT<:CompositeGrids.AbstractGrid,SGT<:CompositeGrids.AbstractGrid,TM,SM} + # for double composite if isempty(green.dynamic) error("Dynamic Green's function can not be empty!") else - dynamic_τx = green.dynamic[colorIndex, colorIndex, :, :] - spaceNeighbor = CompositeGrids.Interp.findneighbor(spaceMethod, green.spaceGrid, space) - dynamic_x_slice = CompositeGrids.Interp.dataslice(dynamic_τx, 1, spaceNeighbor.index) - if timeMethod == DLRInterp() - dynamic_τ = CompositeGrids.Interp.interpsliced(spaceNeighbor, dynamic_x_slice, axis = 1) - if green.timeType == ImFreq - dynamic = (matfreq2matfreq(green.dlrGrid, dynamic_τ, [time,], green.timeGrid.grid))[1] - elseif green.timeType == ImTime - dynamic = (tau2tau(green.dlrGrid, dynamic_τ, [time,], green.timeGrid.grid))[1] - end - elseif typeof(timeMethod)<:CompositeGrids.Interp.InterpStyle - timeNeighbor = CompositeGrids.Interp.findneighbor(timeMethod, green.timeGrid, time) - dynamic_τx_slice = CompositeGrids.Interp.dataslice(dynamic_x_slice, 2, timeNeighbor.index) - dynamic_τ = CompositeGrids.Interp.interpsliced(spaceNeighbor, dynamic_τx_slice, axis = 1) - dynamic = CompositeGrids.Interp.interpsliced(timeNeighbor, dynamic_τ, axis = 1) - else - error("Time interpolation method not implemented!") - end - end + TIM = InterpMethod(TGT,SM) + SIM = InterpMethod(SGT,SM) + + spaceNeighbor = CompositeGrids.Interp.findneighbor(SIM, green.spaceGrid, space) + timeNeighbor = CompositeGrids.Interp.findneighbor(TIM, green.timeGrid, time) + dynamic_slice = view(green.dynamic, color1, color2, spaceNeighbor.index, timeNeighbor.index) + dynamic_slice_xint = CompositeGrids.Interp.interpsliced(spaceNeighbor,dynamic_slice, axis=1) + result = CompositeGrids.Interp.interpsliced(timeNeighbor,dynamic_slice_xint, axis=1) + end + return result +end - return dynamic +function dynamic( + green::Green2DLR{DT,TT,TGT,SGT}, time, space, color1::Int, color2::Int, + timeMethod::LinearInterp = LINEARINTERP , spaceMethod::LinearInterp = LINEARINTERP + ) where {DT,TT,TGT<:CompositeGrids.AbstractGrid,SGT<:CompositeGrids.AbstractGrid} + # for double composite and double linear + if isempty(green.dynamic) + error("Dynamic Green's function can not be empty!") + else + dynamic_slice = view(green.dynamic, color1, color2, :,:) + result = CompositeGrids.Interp.linear2D(dynamic_slice, green.spaceGrid,green.timeGrid,space,time) + end + return result end -function getInstant(green::Green2DLR, space; colorIndex = 1, spaceMethod = CompositeGrids.Interp.LinearInterp()) - if isempty(green.instant) - error("Instant Green's function can not be empty!") - elseif typeof(spaceMethod)<:CompositeGrids.Interp.InterpStyle - instant_x = green.instant[colorIndex, colorIndex, :] - spaceNeighbor = CompositeGrids.Interp.findneighbor(spaceMethod, green.spaceGrid, space) - instant_x_slice = CompositeGrids.Interp.dataslice(instant_x, spaceNeighbor.index) - instant = CompositeGrids.Interp.interpsliced(spaceNeighbor, instant_x_slice) +function dynamic(green::Green2DLR{DT,TT,TGT,SGT}, time, space, color1::Int, color2::Int, timeMethod::DLRInterp , spaceMethod::SM) where {DT,TT,TGT<:CompositeGrids.AbstractGrid,SGT<:CompositeGrids.AbstractGrid,SM} + # for composite space and dlr time + if isempty(green.dynamic) + error("Dynamic Green's function can not be empty!") else - error("Space Interpolation method not implemented!") + SIM = InterpMethod(SGT,SM) + spaceNeighbor = CompositeGrids.Interp.findneighbor(SIM, green.spaceGrid, space) + dynamic_slice = view(green.dynamic, color1, color2, spaceNeighbor.index,:) + + dynamic_slice_xint = CompositeGrids.Interp.interpsliced(spaceNeighbor,dynamic_slice, axis=1) + if green.timeType == ImFreq + result = (matfreq2matfreq(green.dlrGrid, dynamic_slice_xint, [time,], green.timeGrid.grid))[1] + elseif green.timeType == ImTime + result = (tau2tau(green.dlrGrid, dynamic_slice_xint, [time,], green.timeGrid.grid))[1] + end end - return instant + return result end + + + + diff --git a/test/test_Green.jl b/test/test_Green.jl index e692895..f106584 100644 --- a/test/test_Green.jl +++ b/test/test_Green.jl @@ -1,4 +1,5 @@ -SemiCircle(dlr, grid, type) = Sample.SemiCircle(dlr.Euv, dlr.β, dlr.isFermi, dlr.symmetry, grid, type, dlr.rtol, 24, true) +SemiCircle(dlr, grid, type) = Sample.SemiCircle(dlr.Euv, dlr.β, dlr.isFermi, grid, type, dlr.symmetry; rtol = dlr.rtol, degree = 24, regularized = true) + @testset "GreenFunc" begin # @testset "Green2" begin # tgrid = [0.0,1.0] @@ -16,10 +17,11 @@ SemiCircle(dlr, grid, type) = Sample.SemiCircle(dlr.Euv, dlr.β, dlr.isFermi, dl isFermi = true Euv = 1000.0 - green_freq = Green2DLR{ComplexF64,ImFreq}(:green, β, isFermi, Euv, sgrid) + green_freq = Green2DLR{ComplexF64}(:green, GreenFunc.IMFREQ ,β, isFermi, Euv, sgrid) rtol = green_freq.dlrGrid.rtol + println(green_freq.timeType) Gτ = SemiCircle(green_freq.dlrGrid, green_freq.dlrGrid.τ, :τ) - Gn = SemiCircle(green_freq.dlrGrid, green_freq.dlrGrid.n, :ωn) + Gn = SemiCircle(green_freq.dlrGrid, green_freq.dlrGrid.n, :n) green_dum = zeros(ComplexF64, (green_freq.color, green_freq.color, green_freq.spaceGrid.size, green_freq.timeGrid.size)) for (ti, t) in enumerate(green_freq.timeGrid) for (qi, q) in enumerate(green_freq.spaceGrid) @@ -63,7 +65,7 @@ SemiCircle(dlr, grid, type) = Sample.SemiCircle(dlr.Euv, dlr.β, dlr.isFermi, dl isFermi = true Euv = 1000.0 - green_linear = Green2DLR{Float64,ImTime}(:green, β, isFermi, Euv, sgrid) + green_linear = Green2DLR{Float64}(:green, GreenFunc.IMTIME,β, isFermi, Euv, sgrid) rtol = green_linear.dlrGrid.rtol green_dum = zeros(Float64, (green_linear.color, green_linear.color, green_linear.spaceGrid.size, green_linear.timeGrid.size)) for (ti, t) in enumerate(green_linear.timeGrid) @@ -90,9 +92,13 @@ SemiCircle(dlr, grid, type) = Sample.SemiCircle(dlr.Euv, dlr.β, dlr.isFermi, dl τ = 0.5 x = 0.3 - interp_dym = getDynamic(green_linear, τ, x) + interp_dym = dynamic(green_linear, τ, x, 1,1) @test interp_dym - τ * x < 1e-8 - interp_ins = getInstant(green_linear, x) + interp_ins = instant(green_linear, x,1,1) + @test interp_ins - x < 1e-8 + interp_ins = dynamic(green_linear, τ, x,1,1,GreenFunc.DEFAULTINTERP,GreenFunc.DEFAULTINTERP) + @test interp_ins - x < 1e-8 + interp_ins = dynamic(green_linear, τ, x,1,1,GreenFunc.DLRINTERP,GreenFunc.DEFAULTINTERP) @test interp_ins - x < 1e-8 end end