Composite 1D Grids

Basic Grids

NumericalEFT.CompositeGrids.SimpleGModule

Basic grids including common grids like arbitrary grids, uniform grids, log grids, and optimized grids like barycheb for interpolation and gausslegendre for integration.

source
NumericalEFT.CompositeGrids.SimpleG.ArbitraryType
struct Arbitrary{T<:AbstractFloat} <: ClosedGrid

Arbitrary grid generated from given sorted grid.

#Members:

  • bound : boundary of the grid
  • size : number of grid points
  • grid : grid points
  • weight : integration weight

#Constructor:

  • function Arbitrary{T}(grid) where {T<:AbstractFloat}
source
NumericalEFT.CompositeGrids.SimpleG.BaryChebType
struct BaryCheb{T<:AbstractFloat} <: OpenGrid

BaryCheb grid generated on [bound[1], bound[2]] with order N.

#Members:

  • bound : boundary of the grid
  • size : number of grid points
  • grid : grid points
  • weight : interpolation weight

#Constructor:

  • function BaryCheb{T}(bound, size) where {T<:AbstractFloat}
source
NumericalEFT.CompositeGrids.SimpleG.GaussLegendreType
struct GaussLegendre{T<:AbstractFloat} <: OpenGrid

GaussLegendre grid generated on [bound[1], bound[2]] with order N.

#Members:

  • bound : boundary of the grid
  • size : number of grid points
  • grid : grid points
  • weight : integration weight

#Constructor:

  • function GaussLegendre{T}(bound, size) where {T<:AbstractFloat}
source
NumericalEFT.CompositeGrids.SimpleG.LogType
struct Log{T<:AbstractFloat} <: ClosedGrid

Log grid generated on [bound[1], bound[2]] with N grid points. Minimal interval is set to be minterval. Dense to sparse if d2s, vice versa.

On [0, 1], a typical d2s Log grid looks like [0, λ^(N-1), ..., λ^2, λ, 1].

#Members:

  • bound : boundary of the grid

  • size : number of grid points

  • grid : grid points

  • weight : integration weight

  • λ : scale parameter

  • d2s : dense to sparse or not

#Constructor:

  • function Log{T}(bound, size, minterval, d2s) where {T<:AbstractFloat}
source
NumericalEFT.CompositeGrids.SimpleG.UniformType
struct Uniform{T<:AbstractFloat} <: ClosedGrid

Uniform grid generated on [bound[1], bound[2]] with N points

#Members:

  • bound : boundary of the grid
  • size : number of grid points
  • grid : grid points
  • weight : integration weight

#Constructor:

  • function Uniform{T}(bound, size) where {T<:AbstractFloat}
source
Base.floorMethod
function Base.floor(grid::AbstractGrid, x) #where {T}

use basic searchsorted function to find the index of largest grid point smaller than x.

return 1 for x<grid[1] and grid.size-1 for x>grid[end].

source
Base.floorMethod
function Base.floor(grid::Log{T}, x) where {T}

find the index of largest grid point smaller than x.

return 1 for x<grid[1] and grid.size-1 for x>grid[end].

source
Base.floorMethod
function Base.floor(grid::Uniform{T}, x) where {T}

find the index of largest grid point smaller than x.

return 1 for x<grid[1] and grid.size-1 for x>grid[end].

source
Base.showMethod
show(io::IO, grid::AbstractGrid)

Write a text representation of the AbstractGrid grid to the output stream io.

source

Composite Grids

NumericalEFT.CompositeGrids.CompositeGModule

Composite grid that has tree structure. The whole interval is first divided by a panel grid, then each interval of a panel grid is divided by a smaller grid in subgrids. Subgrid could also be composite grid.

source
NumericalEFT.CompositeGrids.CompositeG.CompositeType
struct Composite{T<:AbstractFloat,PG,SG} <: SimpleG.ClosedGrid

Composite grid generated with panel grid of type PG and subgrids of type SG. PG should always be ClosedGrid, while SG could be any grid.

#Members:

  • bound : boundary of the grid
  • size : number of grid points
  • grid : grid points
  • panel : panel grid
  • subgrids : a vector of subgrids
  • inits : index of the first grid point of a subgrid on the whole grid

#Constructor:

  • function Composite{T,PG,SG}(panel, subgrids) where {T<:AbstractFloat,PG,SG}

create Composite grid from panel and subgrids. if the boundary grid point of two neighbor subgrids are too close, they will be combined in the whole grid.

source
Base.floorMethod
function Base.floor(grid::Composite{T,PG,SG}, x) where {T,PG,SG}

first find the corresponding subgrid by flooring on panel grid, then floor on subgrid and collect result. give the floor result on the whole grid. if floor on panel grid is needed, simply call floor(grid.panel, x).

return 1 for x<grid[1] and grid.size-1 for x>grid[end].

source
NumericalEFT.CompositeGrids.CompositeG.CompositeLogGridFunction
function CompositeLogGrid(type, bound, N, minterval, d2s, order, T=Float64)

create a composite grid with a Log grid as panel and subgrids of selected type.

#Members:

  • type : type of the subgrids, currently in [:cheb, :gauss, :uniform]
  • bound : boundary of the grid
  • N : number of grid points of panel grid
  • minterval : minimum interval of panel grid
  • d2s : panel grid is dense to sparse or not
  • order : number of grid points of subgrid
source
NumericalEFT.CompositeGrids.CompositeG.LogDensedGridFunction
function LogDensedGrid(type, bound, dense_at, N, minterval, order, T=Float64)

create a composite grid of CompositeLogGrid as subgrids. the grid is densed at selected points in dense_at, which in the real situation could be [kF,] for fermi k grid and [0, 2kF] for bose k grid, etc. if two densed point is too close to each other, they will be combined.

#Members:

  • type : type of the subgrid of subgrid, currently in [:cheb, :gauss, :uniform]
  • bound : boundary of the grid
  • dense_at : list of points that requires densed grid
  • N : number of grid points of panel grid
  • minterval : minimum interval of panel grid
  • order : number of grid points of subgrid
source

Interpolation and Integration

NumericalEFT.CompositeGrids.Interp.datasliceMethod
function dataslice(data, axes, indices)

Return a view of data sliced on given axes with given indices. Works like view(data, (:, ..., :, i1:f1, :, ..., in:fn, :, ..., :)). Type unstable unless slice dims are constant.

#Members:

  • data: data to be sliced.
  • axes: axes to be sliced. accept Int or NTuple{DIM, Int} for single or multiple axes. when omitted, assume all axes.
  • indices: indices of slicing. accept UnitRange{Int} or Vector of UnitRange{Int} like 2:8 or [2:8, 3:7]
source
NumericalEFT.CompositeGrids.Interp.differentiate1DMethod
function differentiate1D(data, xgrid, x; axis=1)

calculate integration of data[i] on xgrid. For 1D data, return a number; for multiple dimension, reduce the given axis.

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • x: point to differentiate
  • axis: axis to be differentiated in data
source
NumericalEFT.CompositeGrids.Interp.findneighborMethod
function findneighbor(xgrid::T, x; method=:default) where {T}

Find neighbor grid points and related information for extrapolating the value of x on xgrid.

#Members:

  • xgrid: grid to be interpolated
  • x: value to be interpolated
  • method: :default use optimized method, :linear use linear interp.
source
NumericalEFT.CompositeGrids.Interp.integrate1DMethod
function integrate1D(::ChebIntegrate, data, xgrid)

calculate integration of data[i] on xgrid works for grids that have integration weight stored

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
source
NumericalEFT.CompositeGrids.Interp.integrate1DMethod
function integrate1D(::CompositeIntegrate, data, xgrid)

calculate integration of data[i] on xgrid call integrate1D for each subgrid and return the sum.

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
source
NumericalEFT.CompositeGrids.Interp.integrate1DMethod
function integrate1D(::NoIntegrate, data, xgrid)

calculate integration of data[i] on xgrid works for grids that do not have integration weight stored

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
source
NumericalEFT.CompositeGrids.Interp.integrate1DMethod
function integrate1D(::WeightIntegrate, data, xgrid)

calculate integration of data[i] on xgrid works for grids that have integration weight stored

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
source
NumericalEFT.CompositeGrids.Interp.integrate1DMethod
function integrate1D(data, xgrid, range; axis=1)

calculate integration of data[i] on xgrid. For 1D data, return a number; for multiple dimension, reduce the given axis.

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • range: range of integration, [init, fin] within bound of xgrid.
  • axis: axis to be integrated in data
source
NumericalEFT.CompositeGrids.Interp.integrate1DMethod
function integrate1D(data, xgrid; axis=1)

calculate integration of data[i] on xgrid. For 1D data, return a number; for multiple dimension, reduce the given axis.

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • axis: axis to be integrated in data
source
NumericalEFT.CompositeGrids.Interp.interp1DMethod
function interp1D(::ChebInterp, data, xgrid, x)

linear interpolation of data(x), barycheb for BaryCheb grid

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • x: x
source
NumericalEFT.CompositeGrids.Interp.interp1DMethod
function interp1D(::CompositeInterp,data, xgrid, x)

linear interpolation of data(x), first floor on panel to find subgrid, then call interp1D on subgrid

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • x: x
source
NumericalEFT.CompositeGrids.Interp.interp1DMethod
function interp1D(::LinearInterp,data, xgrid, x)

linear interpolation of data(x), use floor and linear1D

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • x: x
source
NumericalEFT.CompositeGrids.Interp.interp1DMethod
function interp1D(data, xgrid, x; axis=1, method=InterpStyle(T))

linear interpolation of data(x) with single or multiple dimension. For 1D data, return a number; for multiple dimension, reduce the given axis.

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • x: x
  • axis: axis to be interpolated in data
  • method: by default use optimized method; use linear interp if Interp.LinearInterp()
source
NumericalEFT.CompositeGrids.Interp.interp1DGridMethod
function interp1DGrid(::CompositeInterp, data, xgrid, grid)

linear interpolation of data(grid[1:end]), return a Vector grid should be sorted.

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • grid: points to be interpolated on
source
NumericalEFT.CompositeGrids.Interp.interp1DGridMethod
function interp1DGrid(::Union{LinearInterp,ChebInterp}, data, xgrid, grid)

linear interpolation of data(grid[1:end]), return a Vector simply call interp1D on each points

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • grid: points to be interpolated on
source
NumericalEFT.CompositeGrids.Interp.interp1DGridMethod
function interp1DGrid(data, xgrid, grid; axis=1, method=InterpStyle(T))

For 1D data, do interpolation of data(grid[1:end]), return a Vector. For ND data, do interpolation of data(grid[1:end]) at given axis, return data of same dimension.

#Arguments:

  • xgrid: one-dimensional grid of x
  • data: one-dimensional array of data
  • grid: points to be interpolated on
  • axis: axis to be interpolated in data
  • method: by default use optimized method; use linear interp if :linear
source
NumericalEFT.CompositeGrids.Interp.interpslicedMethod
function interpsliced(neighbor, data; axis=1)

Interpolate with given neighbor and sliced data. Assume data already sliced on given axis.

#Members:

  • neighbor: neighbor from findneighbor()
  • data: sliced data
  • axis: axis sliced and to be interpolated
source
NumericalEFT.CompositeGrids.Interp.linear2DMethod

linear2D(data, xgrid, ygrid, x, y)

linear interpolation of data(x, y)

#Arguments:

  • xgrid: one-dimensional grid of x
  • ygrid: one-dimensional grid of y
  • data: two-dimensional array of data
  • x: x
  • y: y
source
NumericalEFT.CompositeGrids.Interp.linearNDMethod
function linearND(data, xgrids, xs)

linear interpolation of data(xs)

#Arguments:

  • xgrids: n-dimensional grids, xgrids[i] is a 1D grid
  • data: n-dimensional array of data
  • xs: list of x, x[i] corresponds to xgrids[i]
source
NumericalEFT.CompositeGrids.Interp.locateMethod
function locate(grid, x)

return the index of grid point closest to x. Useful for Monte Carlo algorithm when variable x is continuous while histogram is stored on grid.

#Arguments:

  • grid: one-dimensional grid of x
  • x: point to locate
source
NumericalEFT.CompositeGrids.Interp.volumeMethod
function volume(grid, i)

return the volume of grid point i. The volume is defined as the length/area/volume/... of histogram bar represented by grid point i. In 1D grids of this package, it is defined as the length of interval between (grid[i-1]+grid[i])/2 and (grid[i]+grid[i+1])/2, and for edge points one side is replaced by boundary points. When index i is omitted, the length of the whole grid is returned. It is guaranteed that volume(grid)==sum(volume(grid, i) for i in 1:length(grid)).

#Arguments:

  • grid: one-dimensional grid
  • i: index of grid point
source