Skip to content

Commit 6d18423

Browse files
committed
test(Interpolation): add tests for Interpolation inside model macro
1 parent 5a73d5e commit 6d18423

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/Blocks/sources.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,44 @@ end
500500
@test SciMLBase.successful_retcode(sol)
501501
end
502502

503+
@testset "Interpolation in model macro" begin
504+
505+
function MassSpringDamper(; name)
506+
@named input = RealInput()
507+
@variables f(t) x(t)=0 dx(t)=0 ddx(t)
508+
@parameters m=10 k=1000 d=1
509+
510+
eqs = [f ~ input.u
511+
ddx * 10 ~ k * x + d * dx + f
512+
D(x) ~ dx
513+
D(dx) ~ ddx]
514+
515+
ODESystem(eqs, t; name, systems = [input])
516+
end
517+
518+
table_data = [1.0, 2.0, 3.0]
519+
table_bkp = [0.0, 0.5, 1.0]
520+
itp = LinearInterpolation(table_data, table_bkp)
521+
522+
@mtkmodel model_with_lut begin
523+
@components begin
524+
src = Interpolation(itp)
525+
clk = ContinuousClock()
526+
model = MassSpringDamper()
527+
end
528+
@equations begin
529+
connect(src.input, clk.output)
530+
connect(src.output, model.input)
531+
end
532+
end;
533+
@mtkbuild sys = model_with_lut()
534+
535+
prob = ODEProblem(sys, [], (0.0, 1))
536+
sol = solve(prob, Tsit5())
537+
538+
@test SciMLBase.successful_retcode(sol)
539+
end
540+
503541
@testset "ParametrizedInterpolation" begin
504542
@variables y(t) = 0
505543
u = rand(15)

0 commit comments

Comments
 (0)