@@ -816,45 +816,58 @@ function (f::CachedInterpolation{T})(u, x, args) where T
816816 return interp
817817end
818818
819+ # function Symbolics.derivative(::typeof(CachedInterpolation), args::NTuple{2, Any}, ::Val{2})
820+ # Symbolics.derivative(args[1], (args[2],), Val(1))
821+ # end
822+
819823Base. nameof (:: CachedInterpolation ) = :CachedInterpolation
820824
821825@register_symbolic (f:: CachedInterpolation )(u:: AbstractArray , x:: AbstractArray , args:: Tuple )
822826
823827"""
824- ParametrizedInterpolation (interp_type, u, x, args...; name)
828+ ParametrizedInterpolationBlock (interp_type, u, x, args...; name, t = ModelingToolkit.t_nounits )
825829
826- Represent function interpolation symbolically as a block component. By default interpolation types
827- from [`DataInterpolations.jl`](https://github.com/SciML/DataInterpolations.jl) are supported.
830+ Represent function interpolation symbolically as a block component, with the interpolation data represented parametrically.
831+ By default interpolation types from [`DataInterpolations.jl`](https://github.com/SciML/DataInterpolations.jl) are supported,
832+ but in general any callable type that builds the interpolation object via `itp = interpolation_type(u, x, args...)` and calls
833+ the interpolation with `itp(t)` should work. This does not need to represent an interpolation, it can be any type that satisfies
834+ the interface, such as lookup tables.
828835# Arguments:
829836 - `interp_type`: the type of the interpolation. For `DataInterpolations`,
830837these would be any of [the available interpolations](https://github.com/SciML/DataInterpolations.jl?tab=readme-ov-file#available-interpolations),
831838such as `LinearInterpolation`, `ConstantInterpolation` or `CubicSpline`.
832839 - `u`: the data used for interpolation. For `DataInterpolations` this will be an `AbstractVector`
833840 - `x`: the values that each data points correspond to, usually the times corresponding to each value in `u`.
834841 - `args`: any other arguments beeded to build the interpolation
842+ # Keyword arguments:
843+ - `name`: the name of the component
844+ - `t`: the interpolation parameter, this is the time (`ModelingToolkit.t_nounits`) by default
835845
836846# Parameters:
837847 - `data`: the symbolic representation of the data passed at construction time via `u`.
838848 - `ts`: the symbolic representation of times corresponding to the data passed at construction time via `x`.
849+ - `t`: the parameter used for interpolation
839850
840851# Connectors:
841852 - `output`: a [`RealOutput`](@ref) connector corresponding to the interpolated value
842853"""
843- function ParametrizedInterpolation (
844- interp_type:: T , u:: AbstractVector , x:: AbstractVector , args... ; name) where T
854+ function ParametrizedInterpolationBlock (
855+ interp_type:: T , u:: AbstractVector , x:: AbstractVector , args... ;
856+ name, t = ModelingToolkit. t_nounits) where {T}
857+
858+ build_interpolation = CachedInterpolation (interp_type, u, x, args)
845859
846860 @parameters data[1 : length (x)] = u
847861 @parameters ts[1 : length (x)] = x
848862 @parameters interpolation_type:: T = interp_type [tunable = false ]
849- build_interpolation = CachedInterpolation (interp_type, u, x, args)
850863 @parameters (interpolator:: interp_type )(.. ):: eltype (u)
851864
852865 @named output = RealOutput ()
853866
854867 eqs = [output. u ~ interpolator (t)]
855868
856- ODESystem (eqs, t , [],
857- [data, ts, interpolation_type, interpolator];
869+ ODESystem (eqs, ModelingToolkit . t_nounits , [],
870+ [data, ts, interpolation_type, interpolator, t ];
858871 parameter_dependencies = [
859872 interpolator ~ build_interpolation (data, ts, args)
860873 ],
0 commit comments