Skip to content

Commit 9cbae31

Browse files
refactor: add inputs to the interpolation components
Co-authored-by: Fredrik Bagge Carlson <[email protected]>
1 parent 6a97072 commit 9cbae31

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/Blocks/sources.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -752,24 +752,25 @@ such as `LinearInterpolation`, `ConstantInterpolation` or `CubicSpline`.
752752
753753
# Parameters:
754754
- `interpolator`: the symbolic
755-
- `t`: the parameter used for interpolation
756755
757756
# Connectors:
757+
- `input`: a [`RealInput`](@ref) connector corresponding to the independent variable
758758
- `output`: a [`RealOutput`](@ref) connector corresponding to the interpolated value
759759
"""
760760
function Interpolation(interp_type, u, x, args...; name)
761761
itp = interp_type(u, x, args...)
762-
InterpolationBlock(itp; name, t)
762+
Interpolation(itp; name)
763763
end
764764

765765
function Interpolation(itp; name)
766766
@parameters (interpolator::typeof(itp))(..) = itp
767-
767+
@named input = RealInput()
768768
@named output = RealOutput()
769769

770-
eqs = [output.u ~ interpolator(t)]
770+
eqs = [output.u ~ interpolator(input.u)]
771771

772-
ODESystem(eqs, ModelingToolkit.t_nounits, [], [interpolator, t]; name, systems = [output])
772+
ODESystem(
773+
eqs, t, [], [interpolator]; name, systems = [input, output])
773774
end
774775

775776
struct CachedInterpolation{T,I,U,X,C}
@@ -840,36 +841,35 @@ such as `LinearInterpolation`, `ConstantInterpolation` or `CubicSpline`.
840841
- `args`: any other arguments beeded to build the interpolation
841842
# Keyword arguments:
842843
- `name`: the name of the component
843-
- `t`: the interpolation parameter, this is the time (`ModelingToolkit.t_nounits`) by default
844844
845845
# Parameters:
846846
- `data`: the symbolic representation of the data passed at construction time via `u`.
847847
- `ts`: the symbolic representation of times corresponding to the data passed at construction time via `x`.
848-
- `t`: the parameter used for interpolation
849848
850849
# Connectors:
850+
- `input`: a [`RealInput`](@ref) connector corresponding to the independent variable
851851
- `output`: a [`RealOutput`](@ref) connector corresponding to the interpolated value
852852
"""
853853
function ParametrizedInterpolation(
854854
interp_type::T, u::AbstractVector, x::AbstractVector, args...;
855-
name, t = ModelingToolkit.t_nounits) where {T}
856-
855+
name) where {T}
857856
build_interpolation = CachedInterpolation(interp_type, u, x, args)
858857

859858
@parameters data[1:length(x)] = u
860859
@parameters ts[1:length(x)] = x
861860
@parameters interpolation_type::T=interp_type [tunable = false]
862861
@parameters (interpolator::interp_type)(..)::eltype(u)
863862

863+
@named input = RealInput()
864864
@named output = RealOutput()
865865

866-
eqs = [output.u ~ interpolator(t)]
866+
eqs = [output.u ~ interpolator(input.u)]
867867

868868
ODESystem(eqs, ModelingToolkit.t_nounits, [],
869-
[data, ts, interpolation_type, interpolator, t];
869+
[data, ts, interpolation_type, interpolator];
870870
parameter_dependencies = [
871871
interpolator ~ build_interpolation(data, ts, args)
872872
],
873-
systems = [output],
873+
systems = [input, output],
874874
name)
875875
end

test/Blocks/sources.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ end
488488
x = 0:14.0
489489

490490
@named i = Interpolation(LinearInterpolation, u, x)
491-
eqs = [D(y) ~ i.output.u]
491+
eqs = [i.input.u ~ t, D(y) ~ i.output.u]
492492

493493
@named model = ODESystem(eqs, t, systems = [i])
494494
sys = structural_simplify(model)
@@ -506,7 +506,7 @@ end
506506

507507
@testset "LinearInterpolation" begin
508508
@named i = ParametrizedInterpolation(LinearInterpolation, u, x)
509-
eqs = [D(y) ~ i.output.u]
509+
eqs = [i.input.u ~ t, D(y) ~ i.output.u]
510510

511511
@named model = ODESystem(eqs, t, systems = [i])
512512
sys = structural_simplify(model)
@@ -556,7 +556,7 @@ end
556556
@testset "BSplineInterpolation" begin
557557
@named i = ParametrizedInterpolationBlock(
558558
BSplineInterpolation, u, x, 3, :Uniform, :Uniform)
559-
eqs = [D(y) ~ i.output.u]
559+
eqs = [i.input.u ~ t, D(y) ~ i.output.u]
560560

561561
@named model = ODESystem(eqs, t, systems = [i])
562562
sys = structural_simplify(model)

0 commit comments

Comments
 (0)