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.MatsubaraFunctionType
struct MatsubaraFunction{GD, SD, DD, Q <: Number}

MatsubaraFunction type with fields:

  • grids :: NTuple{GD, AbstractMatsubaraGrid} : collection of Matsubara grids
  • shape :: NTuple{SD, Int64} : shape of tensor structure on every grid point
  • offset :: NTuple{DD, Int64} : offsets for data access
  • data :: OffsetArray{Q, DD, Array{Q, DD}} : multidimensional data array for which the axes correspond to Matsubara indices for the GD Matsubara grids
source

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!Function
function set!(
    f   :: MatsubaraFunction{GD, SD, DD, Q},
    val :: Qp,
    )   :: Nothing where {GD, SD, DD, Q <: Number, Qp <: Number}

Initialize MatsubaraFunction with val

source
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

source
function set!(
    f1 :: MatsubaraFunction,
    f2 :: MatsubaraFunction
    )  :: Nothing

Initialize MatsubaraFunction with another MatsubaraFunction (f1 = f2)

source
MatsubaraFunctions.grid_axesFunction
function grid_axes(f :: MatsubaraFunction)

Returns a tuple of valid index ranges for Matsubara grids of f

source
function grid_axes(f :: MatsubaraFunction, idx :: Int64)

Returns the range of valid indices for Matsubara grid idx of f

source
MatsubaraFunctions.LinearIndexFunction
function 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

source
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

source
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

source
MatsubaraFunctions.to_MatsubaraFunction
function 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

source
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

source
MatsubaraFunctions.upper_tail_momentsFunction
function 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.

source
MatsubaraFunctions.lower_tail_momentsFunction
function 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.

source

Getter Functions

MatsubaraFunctions.gridsFunction
function grids(
    f :: MatsubaraFunction{GD, SD, DD, Q}
    ) :: NTuple{GD, AbstractMatsubaraGrid} where {GD, SD, DD, Q <: Number}

Returns f.grids

source
function grids(
    f   :: MatsubaraFunction,
    idx :: Int64
    )   :: AbstractMatsubaraGrid

Returns f.grids[idx]

source
MatsubaraFunctions.shapeFunction
function shape(
    f :: MatsubaraFunction{GD, SD, DD, Q}
    ) :: NTuple{SD, Int64} where {GD, SD, DD, Q <: Number}

Returns f.shape

source
function shape(
    f   :: MatsubaraFunction,
    idx :: Int64
    )   :: Int64

Returns f.shape[idx]

source

Arithmetic operations

MatsubaraFunctions.addFunction
function add(
    f1 :: MatsubaraFunction, 
    f2 :: MatsubaraFunction
    )  :: MatsubaraFunction

Addition of two MatsubaraFunction, returns new MatsubaraFunction. For brevity, use f1 + f2.

source
MatsubaraFunctions.add!Function
function add!(
    f1 :: MatsubaraFunction, 
    f2 :: MatsubaraFunction
    )  :: Nothing

Inplace addition of two MatsubaraFunction (f1 += f2)

source
MatsubaraFunctions.subtractFunction
function subtract(
    f1 :: MatsubaraFunction, 
    f2 :: MatsubaraFunction
    )  :: MatsubaraFunction

Subtraction of two MatsubaraFunction, returns new MatsubaraFunction. For brevity, use f1 - f2.

source
MatsubaraFunctions.subtract!Function
function subtract!(
    f1 :: MatsubaraFunction, 
    f2 :: MatsubaraFunction
    )  :: Nothing

Inplace subtraction of two MatsubaraFunction (f1 -= f2)

source
MatsubaraFunctions.multFunction
function 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.

source
MatsubaraFunctions.mult!Function
function 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)

source

Miscellaneous utilities

Base.lengthFunction
function length(
    f :: MatsubaraFunction
    ) :: Int64

Returns length of f.data

source
MatsubaraFunctions.flattenFunction
function 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

source
MatsubaraFunctions.flatten!Function
function flatten!(
    f :: MatsubaraFunction,
    x :: AbstractVector
    ) :: Nothing

Flatten data array of MatsubaraFunction into vector

source
MatsubaraFunctions.unflatten!Function
function unflatten!(
    f :: MatsubaraFunction,
    x :: AbstractVector
    ) :: Nothing

Initialize data array of MatsubaraFunction from vector

source
Base.argmaxFunction
function 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)

source

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)