FunctionTabulations.compute_SHA
— Methodcompute_SHA(func)
Utility function to compute the SHA of a function.
FunctionTabulations.create_tabulation_1D
— Methodcreate_tabulation_1D(
func::Function[,
args...];
xmin::T,
xmax::T,
npoints::Int[,
x_scale::Symbol = :linear,
f_scale = :linear,
jld_base_path = nothing,
custom_name = nothing,
interpolation_type = :linear,
extrapolation_bc = Throw,
check_SHA = true,
check_SHA_mode = :warn,
metadata=nothing,
metadata_validation_fn=nothing,
kwargs...]
) where {T<:Union{Real,Quantity}}
Computes or loads the tabulation for a given function of the kind f(x)
.
Arguments
func::Function
: the function which should be tabulated. Must be of the kindf(x)
xmin::Union{Real,Quantity}
: the minimumx
for the range which will be covered by the tabulationxmax::Union{Real,Quantity}
: the maximumx
for the range which will be covered by the tabulationnpoints::Int
: the number of points for whichf(x)
will be computedx_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, thex
points will be evenly spaced. If:log10
is chosen, the points will be logarithmically spaced. Defaults to:linear
f_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, thef(x)
points will not be alterated. If:log10
is chosen, log10 will be applied to thef(x)
points before interpolating. Defaults to:linear
jld_base_path::String
: path to the folder where the tabulation should be saved. Defaults to the current foldercustom_name::String
: custom name for the tabulation file, to which_data.jld2
will be appended. Defaults to the name of the function to be tabulatedinterpolation_type::Symbol
: Type of the spline to be used for interpolation. Can either be :linear (1st order spline) or :cubic (3rd order spline)extrapolation_bc
: behaviour of the tabulation outside of the boundaries defined by[xmin, xmax]
. Possible behaviours are handled by Interpolations.jl and includeThrow
(throws and eror if a value out of bounds is acessed) or
Line(extrapolate linearly). Defaults to
Throw`check_SHA::Bool
: Whether to check the SHA of the tabulated function. If the SHA of the tabulated function does not match the SHA stored inside the tabulation file, it might be necessary to recompute the tabulation, since it's likely that the definition of the tabulated function has changed.check_SHA_mode::Symbol
: Describes the behaviour of this function if the SHA of the tabulated function does not match the SHA stored inside the tabulation file. Defaults to :warn (print a warning but load the tabulation all the same). Other options include :throw (throw an error to suggest manual deletion of the old tabulation) and :none (don't do anything).metadata::Dict{String,Any}
: an optionalDict{String, Any}
which contains additional metadata to be stored in the tabulation achive.metadata_validation_fn::Function
: a function of the kindmetadata_validation_fn(metadata1::Dict{String, Any}, metadata2::Dict{String, Any})
to chech whether two metadata dictionaries contain the same data.args..., kwargs...
: additionalargs
andkwargs
will be passed to the function which is to be tabulated
Examples
julia> func_1d(x) = sin(x)
julia> itp_1d_1 = create_tabulation_1D(
func_1d,
xmin = 0.0,
xmax = 3.0,
npoints = 100,
x_scale = :linear,
f_scale = :linear
)
julia> isapprox(itp_1d_1(2.0), func_1d(2.0), rtol = 1e-3)
true
Measurement units are supported too:
julia> using Unitful
julia> func_1d(x) = x^2
julia> itp_1d_1 = create_tabulation_1D(
func_1d,
xmin = 0.0u"m",
xmax = 3.0u"m",
npoints = 100,
x_scale = :linear,
f_scale = :linear
)
julia> isapprox(itp_1d_1(2.0u"m"), func_1d(2.0u"m"), rtol = 1e-3)
true
FunctionTabulations.create_tabulation_1D
— Methodcreate_tabulation_1D(
func::Function,
x::Vector{T},
args...;
jld_base_path = nothing,
custom_name = nothing,
x_scale::Symbol = :linear,
f_scale = :linear,
interpolation_type = :linear,
extrapolation_bc = Throw,
check_SHA = true,
check_SHA_mode = :warn,
metadata=nothing,
metadata_validation_fn=nothing,
kwargs...
) where {T<:Union{Real,Quantity}}
Provides an interface for create_tabulation_1D
where the tabulation points are defined by the Vector x
. Only linear_interpolation
is supported.`
FunctionTabulations.create_tabulation_2D
— Methodcreate_tabulation_2D(
func::Function[,
args...];
xmin::T,
xmax::T,
ymin::V,
ymax::V,
npoints_x::Int,
npoints_y::Int[,
x_scale::Symbol = :linear,
y_scale::Symbol = :linear,
f_scale = :linear,
jld_base_path = nothing,
custom_name = nothing,
interpolation_type = :linear,
extrapolation_bc = Throw,
check_SHA = true,
check_SHA_mode = :warn,
metadata=nothing,
metadata_validation_fn=nothing,
kwargs...]
) where {T<:Union{Real,Quantity},V<:Union{Real,Quantity}}
Computes or loads the tabulation for a given function of the kind f(x, y)
.
Arguments
func::Function
: the function which should be tabulated. Must be of the kindf(x, y)
xmin::Union{Real,Quantity}
: the minimumx
for the range which will be covered by the tabulationxmax::Union{Real,Quantity}
: the maximumx
for the range which will be covered by the tabulationymin::Union{Real,Quantity}
: the minimumy
for the range which will be covered by the tabulationymax::Union{Real,Quantity}
: the maximumy
for the range which will be covered by the tabulationnpoints_x::Int
: the number of points along thex
axis for whichf(x,y)
will be computednpoints_y::Int
: the number of points along they
axis for whichf(x,y)
will be computedx_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, thex
points will be evenly spaced. If:log10
is chosen, the points will be logarithmically spaced. Defaults to:linear
y_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, they
points will be evenly spaced. If:log10
is chosen, the points will be logarithmically spaced. Defaults to:linear
f_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, thef(x)
points will not be alterated. If:log10
is chosen, log10 will be applied to thef(x)
points before interpolating. Defaults to:linear
jld_base_path
: path to the folder where the tabulation should be saved. Defaults to the current foldercustom_name
: custom name for the tabulation file, to which_data.jld2
will be appended. Defaults to the name of the function to be tabulatedinterpolation_type
: Type of the spline to be used for interpolation. Can either be :linear (1st order spline) or :cubic (3rd order spline)extrapolation_bc
: behaviour of the tabulation outside of the boundaries defined by[xmin, xmax]
. Possible behaviours are handled by Interpolations.jl and includeThrow
(throws and eror if a value out of bounds is acessed) or
Line(extrapolate linearly). Defaults to
Throw`check_SHA::Bool
: Whether to check the SHA of the tabulated function. If the SHA of the tabulated function does not match the SHA stored inside the tabulation file, it might be necessary to recompute the tabulation, since it's likely that the definition of the tabulated function has changed.check_SHA_mode::Symbol
: Describes the behaviour of this function if the SHA of the tabulated function does not match the SHA stored inside the tabulation file. Defaults to :warn (print a warning but load the tabulation all the same). Other options include :throw (throw an error to suggest manual deletion of the old tabulation) and :none (don't do anything).metadata::Dict{String,Any}
: an optionalDict{String, Any}
which contains additional metadata to be stored in the tabulation achive.metadata_validation_fn::Function
: a function of the kindmetadata_validation_fn(metadata1::Dict{String, Any}, metadata2::Dict{String, Any})
to chech whether two metadata dictionaries contain the same data.args..., kwargs...
: additionalargs
andkwargs
will be passed to the function which is to be tabulated
Examples
julia> func_2d(x, y) = sin(x) * sin(y)
julia> itp_2d_1 = create_tabulation_2D(
func_2d,
xmin = 0.0,
xmax = 1.0,
ymin = 0.0,
ymax = 2.0,
npoints_x = 100,
npoints_y = 100,
)
julia> isapprox(itp_2d_1(1.0, 1.3), func_2d(1.0, 1.3), rtol = 1e-3)
true
Measurement units are supported too:
julia> using Unitful
julia> func_2d(x, y) = x^2 + y
julia> itp_2d_1 = create_tabulation_2D(
func_2d,
xmin = 0.0u"m",
xmax = 1.0u"m",
ymin = 0.0u"m^2",
ymax = 2.0u"m^2",
npoints_x = 100,
npoints_y = 100,
)
julia> isapprox(itp_2d_1(1.0u"m", 1.3u"m^2"), func_2d(1.0u"m", 1.3u"m^2"), rtol = 1e-3)
true
FunctionTabulations.create_tabulation_2D
— Methodfunction create_tabulation_2D(
func::Function,
x::Vector{T},
y::Vector{V},
args...;
jld_base_path = nothing,
custom_name = nothing,
x_scale::Symbol = :linear,
y_scale::Symbol = :linear,
f_scale = :linear,
interpolation_type = :linear,
extrapolation_bc = Throw,
check_SHA = true,
check_SHA_mode = :warn,
metadata=nothing,
metadata_validation_fn=nothing,
kwargs...
) where {T<:Union{Real,Quantity},V<:Union{Real,Quantity}}
Provides an interface for create_tabulation_2D
where the tabulation points are defined by the Vectors x
and y
. Only linear_interpolation
is supported.`
FunctionTabulations.create_tabulation_3D
— Methodcreate_tabulation_3D(
func::Function[,
args...];
xmin::T,
xmax::T,
ymin::V,
ymax::V,
zmin::W,
zmax::W,
npoints_x::Int,
npoints_y::Int,
npoints_z::Int[,
x_scale::Symbol = :linear,
y_scale::Symbol = :linear,
z_scale::Symbol = :linear,
f_scale = :linear,
jld_base_path = nothing,
custom_name = nothing,
interpolation_type = :linear,
extrapolation_bc = Throw,
check_SHA = true,
check_SHA_mode = :warn,
metadata=nothing,
metadata_validation_fn=nothing,
kwargs...]
) where {T<:Union{Real,Quantity},V<:Union{Real,Quantity},W<:Union{Real,Quantity}}
Computes or loads the tabulation for a given function of the kind f(x, y, z)
.
Arguments
func::Function
: the function which should be tabulated. Must be of the kindf(x, y)
xmin::Union{Real,Quantity}
: the minimumx
for the range which will be covered by the tabulationxmax::Union{Real,Quantity}
: the maximumx
for the range which will be covered by the tabulationymin::Union{Real,Quantity}
: the minimumy
for the range which will be covered by the tabulationymax::Union{Real,Quantity}
: the maximumy
for the range which will be covered by the tabulationzmin::Union{Real,Quantity}
: the minimumz
for the range which will be covered by the tabulationzmax::Union{Real,Quantity}
: the maximumz
for the range which will be covered by the tabulationnpoints_x::Int
: the number of points along thex
axis for whichf(x,y,z)
will be computednpoints_y::Int
: the number of points along they
axis for whichf(x,y,z)
will be computednpoints_z::Int
: the number of points along thez
axis for whichf(x,y,z)
will be computedx_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, thex
points will be evenly spaced. If:log10
is chosen, the points will be logarithmically spaced. Defaults to:linear
y_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, they
points will be evenly spaced. If:log10
is chosen, the points will be logarithmically spaced. Defaults to:linear
z_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, thez
points will be evenly spaced. If:log10
is chosen, the points will be logarithmically spaced. Defaults to:linear
f_scale::Symbol
: the scale which will be used for tabulation. If:linear
is choosen, thef(x)
points will not be alterated. If:log10
is chosen, log10 will be applied to thef(x)
points before interpolating. Defaults to:linear
jld_base_path
: path to the folder where the tabulation should be saved. Defaults to the current foldercustom_name
: custom name for the tabulation file, to which_data.jld2
will be appended. Defaults to the name of the function to be tabulatedinterpolation_type
: Type of the spline to be used for interpolation. Can either be :linear (1st order spline) or :cubic (3rd order spline)extrapolation_bc
: behaviour of the tabulation outside of the boundaries defined by[xmin, xmax]
. Possible behaviours are handled by Interpolations.jl and includeThrow
(throws and eror if a value out of bounds is acessed) or
Line(extrapolate linearly). Defaults to
Throw`check_SHA::Bool
: Whether to check the SHA of the tabulated function. If the SHA of the tabulated function does not match the SHA stored inside the tabulation file, it might be necessary to recompute the tabulation, since it's likely that the definition of the tabulated function has changed.check_SHA_mode::Symbol
: Describes the behaviour of this function if the SHA of the tabulated function does not match the SHA stored inside the tabulation file. Defaults to :warn (print a warning but load the tabulation all the same). Other options include :throw (throw an error to suggest manual deletion of the old tabulation) and :none (don't do anything).metadata::Dict{String,Any}
: an optionalDict{String, Any}
which contains additional metadata to be stored in the tabulation achive.metadata_validation_fn::Function
: a function of the kindmetadata_validation_fn(metadata1::Dict{String, Any}, metadata2::Dict{String, Any})
to chech whether two metadata dictionaries contain the same data.args..., kwargs...
: additionalargs
andkwargs
will be passed to the function which is to be tabulated
Examples
julia> func_3d(x, y, z) = x * y + z
julia> itp_3d_1 = create_tabulation_3D(
func_3d,
xmin = 0.0,
xmax = 1.0,
ymin = 0.0,
ymax = 2.0,
zmin = 0.0,
zmax = 3.0,
npoints_x = 100,
npoints_y = 100,
npoints_z = 100,
)
julia> isapprox(itp_3d_1(1.0, 1.3, 2.5), func_3d(1.0, 1.3, 2.5), rtol = 1e-3)
true
Measurement units are supported too:
julia> using Unitful
julia> func_3d(x, y, z) = x * y + z
julia> itp_3d_1 = create_tabulation_3D(
func_3d,
xmin = 0.0u"m",
xmax = 1.0u"m",
ymin = 0.0"s^-1",
ymax = 2.0"s^-1",
zmin = 0.0u"m/s",
zmax = 3.0u"m/s",
npoints_x = 100,
npoints_y = 100,
npoints_z = 100,
)
julia> isapprox(itp_3d_1(1.0u"m", 1.3u"s^-1", 2.5u"m/s"), func_3d(1.0u"m", 1.3u"s^-1", 2.5u"m/s"), rtol = 1e-3)
true
FunctionTabulations.create_tabulation_3D
— Methodfunction create_tabulation_3D(
func::Function,
x::Vector{T},
y::Vector{V},
z::Vector{W},
args...;
jld_base_path = nothing,
custom_name = nothing,
x_scale::Symbol = :linear,
y_scale::Symbol = :linear,
z_scale::Symbol = :linear,
f_scale = :linear,
interpolation_type = :linear,
extrapolation_bc = Throw,
check_SHA = true,
check_SHA_mode = :warn,
metadata=nothing,
metadata_validation_fn=nothing,
kwargs...
) where {T<:Union{Real,Quantity},V<:Union{Real,Quantity},W<:Union{Real,Quantity}}
Provides an interface for create_tabulation_3D
where the tabulation points are defined by the Vectors x
, y
and z
. Only linear_interpolation
is supported.`
FunctionTabulations.scaler
— Methodscaler(x::Real, scale::Symbol)
Utility function to scale a variable, accepts :linear and :log10 scale
FunctionTabulations.test_sha
— Methodtest_sha(func, sha[; mode = :warn])
Compares the SHA of the func
funtion with the provided SHA.
FunctionTabulations.un_scaler
— Methodun_scaler(x::Real, scale::Symbol)
Utility function to un_scale a variable, accepts :linear and :log10 scale
FunctionTabulations.wrap_function_1D_add_units
— Methodwrapfunction1Daddunits(func, xunits, funits[, args...; kwargs...])
Add units back to a 1D function.
FunctionTabulations.wrap_function_1D_remove_units
— Methodwrapfunction1Dremoveunits(func, xunits, funits[, args...; kwargs...])
Remove units from a 1D function.
FunctionTabulations.wrap_function_2D_add_units
— Methodwrapfunction2Daddunits(func, xunits, yunits, f_units[, args...; kwargs...])
Add units back to a 2D function.
FunctionTabulations.wrap_function_2D_remove_units
— Methodwrapfunction2Dremoveunits(func, xunits, yunits, f_units[, args...; kwargs...])
Remove units from a 2D function.
FunctionTabulations.wrap_function_3D_add_units
— Methodwrapfunction3Daddunits(func, xunits, yunits, zunits, funits[, args...; kwargs...])
Add units back to a 3D function.
FunctionTabulations.wrap_function_3D_remove_units
— Methodwrapfunction3Dremoveunits(func, xunits, yunits, zunits, funits[, args...; kwargs...])
Remove units from a 3D function.