MatsubaraFunction
Constructor
A MatsubaraFunction
is a collection of MatsubaraGrid
instances together with an associated tensor structure $G_{i_1...i_n}$ for each point $(\omega_1, ..., \omega_m)$ in the cartesian product of the grids.
MatsubaraFunctions.MatsubaraFunction
— Typestruct MatsubaraFunction{GD, SD, DD, Q <: Number}
MatsubaraFunction type with fields:
grids :: NTuple{GD, AbstractMatsubaraGrid}
: collection of Matsubara gridsshape :: NTuple{SD, Int64}
: shape of tensor structure on every grid pointoffset :: NTuple{DD, Int64}
: offsets for data accessdata :: OffsetArray{Q, DD, Array{Q, DD}}
: multidimensional data array for which the axes correspond to Matsubara indices for the GD Matsubara grids
Some possible constructors are
T = 1.0
N = 128
g = MatsubaraGrid(T, N, Fermion)
# 1D grid, rank 1 tensor with index dimension 1 (scalar valued)
f1_complex = MatsubaraFunction(g, 1)
f1_real = MatsubaraFunction(g, 1; data_t=Float64)
# 1D grid, rank 1 tensor with index dimension 5 (vector valued)
f2_complex = MatsubaraFunction(g, 5)
f2_real = MatsubaraFunction(g, 5; data_t=Float64)
# 1D grid, rank 2 tensor with index dimension 5 (matrix valued)
f3_complex = MatsubaraFunction(g, 5, 5)
f3_real = MatsubaraFunction(g, 5, 5; data_t=Float64)
# 2D grid, rank 2 tensor with index dimension 5 (matrix valued)
f4_complex = MatsubaraFunction((g, g), 5, 5)
f4_real = MatsubaraFunction((g, g), 5, 5; data_t=Float64)
Indexing and assignment
There are two possible ways to access the data of a MatsubaraFunction
, using either the bracket []
or the parenthesis ()
operator. The former can be used together with a set of linear indices or with a combination of MatsubaraFrequency
objects and linear indices (for the tensor structure). It will return the value of the function precisely for the given arguments. ()
also allows to substitute Float64
for the frequency arguments, in which case a multilinear interpolation is performed. In addition, ()
is well defined even for out of bounds access, since it makes use of either polynomial or constant extrapolation in this case.
ξ = 0.5
T = 1.0
N = 128
g = MatsubaraGrid(T, N, Fermion)
f = MatsubaraFunction(g)
for v in g
f[v] = 1.0 / (im * value(v) - ξ)
end
# access MatsubaraFunction data
v = g[rand(eachindex(g))]
println(f[v]) # fast data access, throws error if v is out of bounds
println(f(v)) # fast data access, defined even if v is out of bounds
println(f(value(v))) # slow data access, uses interpolation
# polynomial extrapolation in 1D, constant term set to 1 (default is 0)
vp = MatsubaraFrequency(T, 256, Fermion)
println(f(vp; extrp = ComplexF64(1.0)))
MatsubaraFunctions.set!
— Functionfunction set!(
f :: MatsubaraFunction{GD, SD, DD, Q},
val :: Qp,
) :: Nothing where {GD, SD, DD, Q <: Number, Qp <: Number}
Initialize MatsubaraFunction with val
function set!(
f :: MatsubaraFunction{GD, SD, DD, Q},
arr :: Array{Qp, DD},
) :: Nothing where {GD, SD, DD, Q <: Number, Qp <: Number}
Initialize MatsubaraFunction with arr
function set!(
f1 :: MatsubaraFunction,
f2 :: MatsubaraFunction
) :: Nothing
Initialize MatsubaraFunction with another MatsubaraFunction (f1 = f2
)
MatsubaraFunctions.grid_axes
— Functionfunction grid_axes(f :: MatsubaraFunction)
Returns a tuple of valid index ranges for Matsubara grids of f
function grid_axes(f :: MatsubaraFunction, idx :: Int64)
Returns the range of valid indices for Matsubara grid idx
of f
MatsubaraFunctions.LinearIndex
— Functionfunction LinearIndex(
f :: MatsubaraFunction{GD, SD, DD, Q},
w :: NTuple{GD, AbstractMatsubaraFrequency},
x :: Vararg{Int64, SD}
) :: Int64 where {GD, SD, DD, Q <: Number}
Returns linear index for access to f.data
function LinearIndex(
f :: MatsubaraFunction{GD, SD, DD, Q},
cidx :: CartesianIndex{DD}
) :: Int64 where {GD, SD, DD, Q <: Number}
Returns linear index for access to f.data
function LinearIndex(
f :: MatsubaraFunction{GD, SD, DD, Q},
x :: Vararg{Int64, DD}
) :: Int64 where {GD, SD, DD, Q <: Number}
Returns linear index for access to f.data
MatsubaraFunctions.to_Matsubara
— Functionfunction to_Matsubara(
f :: MatsubaraFunction{GD, SD, DD, Q},
cidx :: CartesianIndex{DD}
) :: Tuple{NTuple{GD, MatsubaraFrequency}, NTuple{SD, Int64}} where {GD, SD, DD, Q <: Number}
Returns coordinates in grids and index of tensor structure
function to_Matsubara(
f :: MatsubaraFunction{GD, SD, DD, Q},
idx :: Int64
) :: Tuple{NTuple{GD, MatsubaraFrequency}, NTuple{SD, Int64}} where {GD, SD, DD, Q <: Number}
Returns coordinates in grids and index of tensor structure
MatsubaraFunctions.upper_tail_moments
— Functionfunction upper_tail_moments(
f :: MatsubaraFunction{1, SD, DD, Q},
α0 :: Q,
x :: Vararg{Int64, SD}
) :: Tuple{Q, Q} where {SD, DD, Q <: Number}
Returns high frequency moments for quadratic model using upper grid bound. Here, α0 is the asymptotic limit for large positive frequencies.
MatsubaraFunctions.lower_tail_moments
— Functionfunction lower_tail_moments(
f :: MatsubaraFunction{1, SD, DD, Q},
α0 :: Q,
x :: Vararg{Int64, SD}
) :: Tuple{Q, Q} where {SD, DD, Q <: Number}
Returns high frequency moments for quadratic model using lower grid bound. Here, α0 is the asymptotic limit for large negative frequencies.
Getter Functions
MatsubaraFunctions.grids
— Functionfunction grids(
f :: MatsubaraFunction{GD, SD, DD, Q}
) :: NTuple{GD, AbstractMatsubaraGrid} where {GD, SD, DD, Q <: Number}
Returns f.grids
function grids(
f :: MatsubaraFunction,
idx :: Int64
) :: AbstractMatsubaraGrid
Returns f.grids[idx]
MatsubaraFunctions.shape
— Functionfunction shape(
f :: MatsubaraFunction{GD, SD, DD, Q}
) :: NTuple{SD, Int64} where {GD, SD, DD, Q <: Number}
Returns f.shape
function shape(
f :: MatsubaraFunction,
idx :: Int64
) :: Int64
Returns f.shape[idx]
Arithmetic operations
MatsubaraFunctions.add
— Functionfunction add(
f1 :: MatsubaraFunction,
f2 :: MatsubaraFunction
) :: MatsubaraFunction
Addition of two MatsubaraFunction, returns new MatsubaraFunction. For brevity, use f1 + f2.
MatsubaraFunctions.add!
— Functionfunction add!(
f1 :: MatsubaraFunction,
f2 :: MatsubaraFunction
) :: Nothing
Inplace addition of two MatsubaraFunction (f1 += f2
)
MatsubaraFunctions.subtract
— Functionfunction subtract(
f1 :: MatsubaraFunction,
f2 :: MatsubaraFunction
) :: MatsubaraFunction
Subtraction of two MatsubaraFunction, returns new MatsubaraFunction. For brevity, use f1 - f2.
MatsubaraFunctions.subtract!
— Functionfunction subtract!(
f1 :: MatsubaraFunction,
f2 :: MatsubaraFunction
) :: Nothing
Inplace subtraction of two MatsubaraFunction (f1 -= f2
)
MatsubaraFunctions.mult
— Functionfunction mult(
f :: MatsubaraFunction{GD, SD, DD, Q},
val :: Qp
) :: MatsubaraFunction{GD, SD, DD, Q} where {GD, SD, DD, Q <: Number, Qp <: Number}
Multiplication of MatsubaraFunction with scalar, returns new MatsubaraFunction. For brevity, use val * f or f * val.
MatsubaraFunctions.mult!
— Functionfunction mult!(
f :: MatsubaraFunction{GD, SD, DD, Q},
val :: Qp
) :: Nothing where {GD, SD, DD, Q <: Number, Qp <: Number}
Inplace multiplication of MatsubaraFunction with scalar (f *= val
)
Miscellaneous utilities
Base.length
— Functionfunction length(
f :: MatsubaraFunction
) :: Int64
Returns length of f.data
MatsubaraFunctions.flatten
— Functionfunction flatten(
f :: MatsubaraFunction{GD, SD, DD, Q}
) :: Vector{Q} where {GD, SD, DD, Q <: Number}
Flatten data array of MatsubaraFunction and return vector of the corresponding data type
MatsubaraFunctions.flatten!
— Functionfunction flatten!(
f :: MatsubaraFunction,
x :: AbstractVector
) :: Nothing
Flatten data array of MatsubaraFunction into vector
MatsubaraFunctions.unflatten!
— Functionfunction unflatten!(
f :: MatsubaraFunction,
x :: AbstractVector
) :: Nothing
Initialize data array of MatsubaraFunction from vector
MatsubaraFunctions.absmax
— Functionfunction absmax(
f :: MatsubaraFunction
) :: Float64
Returns largest element of f.data
(in absolute terms)
Base.argmax
— Functionfunction argmax(
f :: MatsubaraFunction{GD, SD, DD, Q}
) :: CartesianIndex{DD} where {GD, SD, DD, Q <: Number}
Returns position of largest element of f.data
(in absolute terms)
I/O to HDF5 files
MatsubaraFunction
objects can be saved in HDF5 file format as
using MatsubaraFunctions
using HDF5
file = h5open("test.h5", "w")
T = 1.0
N = 128
g = MatsubaraGrid(T, N, Fermion)
f = MatsubaraFunction(g, 1)
save_matsubara_function!(file, "func", f)
fp = load_matsubara_function(file, "func")
close(file)
MatsubaraFunctions.save_matsubara_function!
— Functionfunction save_matsubara_function!(
h :: HDF5.File,
l :: String,
f :: MatsubaraFunction
) :: Nothing
Save MatsubaraFunction f
with label l
to file h
MatsubaraFunctions.load_matsubara_function
— Functionfunction load_matsubara_function(
h :: HDF5.File,
l :: String
) :: MatsubaraFunction
Load MatsubaraFunction with label l
from file h