Composite 1D Grids
Basic Grids
NumericalEFT.CompositeGrids.SimpleG
— ModuleBasic grids including common grids like arbitrary grids, uniform grids, log grids, and optimized grids like barycheb for interpolation and gausslegendre for integration.
NumericalEFT.CompositeGrids.SimpleG.AbstractGrid
— TypeAll Grids are derived from AbstractGrid; ClosedGrid has bound[1], bound[2] == grid[1], grid[end], while OpenGrid has bound[1]<grid[1]<grid[end]<bound[2]
NumericalEFT.CompositeGrids.SimpleG.Arbitrary
— Typestruct Arbitrary{T<:AbstractFloat} <: ClosedGrid
Arbitrary grid generated from given sorted grid.
#Members:
bound
: boundary of the gridsize
: number of grid pointsgrid
: grid pointsweight
: integration weight
#Constructor:
- function Arbitrary{T}(grid) where {T<:AbstractFloat}
NumericalEFT.CompositeGrids.SimpleG.BaryCheb
— Typestruct BaryCheb{T<:AbstractFloat} <: OpenGrid
BaryCheb grid generated on [bound[1], bound[2]] with order N.
#Members:
bound
: boundary of the gridsize
: number of grid pointsgrid
: grid pointsweight
: interpolation weight
#Constructor:
- function BaryCheb{T}(bound, size) where {T<:AbstractFloat}
NumericalEFT.CompositeGrids.SimpleG.GaussLegendre
— Typestruct GaussLegendre{T<:AbstractFloat} <: OpenGrid
GaussLegendre grid generated on [bound[1], bound[2]] with order N.
#Members:
bound
: boundary of the gridsize
: number of grid pointsgrid
: grid pointsweight
: integration weight
#Constructor:
- function GaussLegendre{T}(bound, size) where {T<:AbstractFloat}
NumericalEFT.CompositeGrids.SimpleG.Log
— Typestruct 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 gridsize
: number of grid pointsgrid
: grid pointsweight
: integration weightλ
: scale parameterd2s
: dense to sparse or not
#Constructor:
- function Log{T}(bound, size, minterval, d2s) where {T<:AbstractFloat}
NumericalEFT.CompositeGrids.SimpleG.Uniform
— Typestruct Uniform{T<:AbstractFloat} <: ClosedGrid
Uniform grid generated on [bound[1], bound[2]] with N points
#Members:
bound
: boundary of the gridsize
: number of grid pointsgrid
: grid pointsweight
: integration weight
#Constructor:
- function Uniform{T}(bound, size) where {T<:AbstractFloat}
Base.floor
— Methodfunction 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].
Base.floor
— Methodfunction 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].
Base.floor
— Methodfunction 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].
Base.show
— Methodshow(io::IO, grid::AbstractGrid)
Write a text representation of the AbstractGrid grid
to the output stream io
.
Composite Grids
NumericalEFT.CompositeGrids.CompositeG
— ModuleComposite 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.
NumericalEFT.CompositeGrids.CompositeG.Composite
— Typestruct 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 gridsize
: number of grid pointsgrid
: grid pointspanel
: panel gridsubgrids
: a vector of subgridsinits
: 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.
Base.floor
— Methodfunction 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].
NumericalEFT.CompositeGrids.CompositeG.CompositeLogGrid
— Functionfunction 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 gridN
: number of grid points of panel gridminterval
: minimum interval of panel gridd2s
: panel grid is dense to sparse or notorder
: number of grid points of subgrid
NumericalEFT.CompositeGrids.CompositeG.LogDensedGrid
— Functionfunction 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 griddense_at
: list of points that requires densed gridN
: number of grid points of panel gridminterval
: minimum interval of panel gridorder
: number of grid points of subgrid
Interpolation and Integration
NumericalEFT.CompositeGrids.Interp
— ModuleProvide interpolation and integration.
NumericalEFT.CompositeGrids.Interp.dataslice
— Methodfunction 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]
NumericalEFT.CompositeGrids.Interp.differentiate1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.findneighbor
— Methodfunction 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.
NumericalEFT.CompositeGrids.Interp.integrate1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.integrate1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.integrate1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.integrate1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.integrate1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.integrate1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.interp1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.interp1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.interp1D
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.interp1D
— Methodfunction 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()
NumericalEFT.CompositeGrids.Interp.interp1DGrid
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.interp1DGrid
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.interp1DGrid
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.interpsliced
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.linear1D
— Methodfunction linear1D(data, xgrid, x)
linear interpolation of data(x)
#Arguments:
- xgrid: one-dimensional grid of x
- data: one-dimensional array of data
- x: x
NumericalEFT.CompositeGrids.Interp.linear2D
— Methodlinear2D(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
NumericalEFT.CompositeGrids.Interp.linearND
— Methodfunction 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]
NumericalEFT.CompositeGrids.Interp.locate
— Methodfunction 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
NumericalEFT.CompositeGrids.Interp.volume
— Methodfunction 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