InterpolationExtrapolationTest ​
Tests interpolation with extrapolation by applying linear interpolation with constant extrapolation.
This component creates an interpolation object configured with linear interpolation and constant extrapolation on a dataset containing time values from 0 to 1 and their corresponding squared values. The simulation runs beyond the data range to verify that extrapolation works correctly, extending the boundary values for inputs outside the dataset range.
Usage ​
BlockComponents.InterpolationExtrapolationTest()
Parameters: ​
| Name | Description | Units | Default value |
|---|---|---|---|
dataset | Dataset containing time values from 0 to 1 and their squares, with 'ts' as independent variable and 'data' as dependent variable | – | DyadTimeseries(hcat(0:0.1:1, square(0:0.1:1)), dependent_vars=["data"], independent_var="ts") |
Variables ​
| Name | Description | Units |
|---|---|---|
y | Output variable that receives the interpolated value | – |
Behavior ​
Behavior of this component cannot be rendered because it includes path variables.
Source ​
dyad
"""
Tests interpolation with extrapolation by applying linear interpolation with constant extrapolation.
This component creates an interpolation object configured with linear interpolation and constant
extrapolation on a dataset containing time values from 0 to 1 and their corresponding squared values.
The simulation runs beyond the data range to verify that extrapolation works correctly, extending
the boundary values for inputs outside the dataset range.
"""
test component InterpolationExtrapolationTest
"Interpolation object that performs linear interpolation with constant extrapolation"
interp = Interpolation(interpolation_type = InterpolationType.LinearInterpolation(), extrapolation_type = ExtrapolationType.Constant(), dataset = dataset) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 170, "y1": 70, "x2": 270, "y2": 170, "rot": 0}
}
}
}
"Dataset containing time values from 0 to 1 and their squares, with 'ts' as independent variable and 'data' as dependent variable"
structural parameter dataset::DyadData.DyadTimeseries = DyadTimeseries(hcat(0:0.1:1, square(0:0.1:1)), dependent_vars = ["data"], independent_var = "ts")
"Output variable that receives the interpolated value"
variable y::Real
relations
interp.u = time
interp.y = y
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 1.5, "expect": {"signals": ["y"]}}},
"doc": {"behavior": false}
}
}
endFlattened Source
dyad
"""
Tests interpolation with extrapolation by applying linear interpolation with constant extrapolation.
This component creates an interpolation object configured with linear interpolation and constant
extrapolation on a dataset containing time values from 0 to 1 and their corresponding squared values.
The simulation runs beyond the data range to verify that extrapolation works correctly, extending
the boundary values for inputs outside the dataset range.
"""
test component InterpolationExtrapolationTest
"Interpolation object that performs linear interpolation with constant extrapolation"
interp = Interpolation(interpolation_type = InterpolationType.LinearInterpolation(), extrapolation_type = ExtrapolationType.Constant(), dataset = dataset) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 170, "y1": 70, "x2": 270, "y2": 170, "rot": 0}
}
}
}
"Dataset containing time values from 0 to 1 and their squares, with 'ts' as independent variable and 'data' as dependent variable"
structural parameter dataset::DyadData.DyadTimeseries = DyadTimeseries(hcat(0:0.1:1, square(0:0.1:1)), dependent_vars = ["data"], independent_var = "ts")
"Output variable that receives the interpolated value"
variable y::Real
relations
interp.u = time
interp.y = y
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 1.5, "expect": {"signals": ["y"]}}},
"doc": {"behavior": false}
}
}
endTest Cases ​
julia
using BlockComponents
using DyadInterface: TransientAnalysis, rebuild_sol, ODEAlg
using ModelingToolkit: toggle_namespacing, get_initial_conditions, @named
using CSV, DataFrames, Plots
snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")<< @setup-block not executed in draft mode >>Test Case case1 ​
julia
@named model_case1 = BlockComponents.InterpolationExtrapolationTest()
model_case1 = toggle_namespacing(model_case1, false)
model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = ODEAlg.Auto(), start = 0e+0, stop = 1.5e+0, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)<< @setup-block not executed in draft mode >>julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.y])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "BlockComponents.InterpolationExtrapolationTest_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.y], width=2, label="Actual value of y")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of y")
end<< @setup-block not executed in draft mode >>julia
plt<< @example-block not executed in draft mode >>Related ​
Examples
Experiments
Analyses
Tests