Skip to content

Commit 492b911

Browse files
test: test v3 FMUs as subcomponents
1 parent c542dbb commit 492b911

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test/extensions/fmi.jl

+33-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using ModelingToolkit, FMI, FMIZoo, OrdinaryDiffEq
22
using ModelingToolkit: t_nounits as t, D_nounits as D
33
import ModelingToolkit as MTK
44

5+
const FMU_DIR = joinpath(@__DIR__, "fmus")
6+
57
@testset "Standalone pendulum model" begin
68
fmu = loadFMU("SpringPendulum1D", "Dymola", "2022x"; type = :ME)
79
truesol = FMI.simulate(
@@ -71,7 +73,7 @@ end
7173

7274
@testset "IO Model" begin
7375
@testset "v2, ME" begin
74-
fmu = loadFMU("../../omc-fmus/SimpleAdder.fmu"; type = :ME)
76+
fmu = loadFMU(joinpath(FMU_DIR, "SimpleAdder.fmu"); type = :ME)
7577
@named adder = MTK.FMIComponent(Val(2); fmu, type = :ME)
7678
@variables a(t) b(t) c(t) [guess = 1.0]
7779
@mtkbuild sys = ODESystem(
@@ -87,7 +89,7 @@ end
8789
@test SciMLBase.successful_retcode(sol)
8890
end
8991
@testset "v2, CS" begin
90-
fmu = loadFMU("../../omc-fmus/SimpleAdder.fmu"; type = :CS)
92+
fmu = loadFMU(joinpath(FMU_DIR, "SimpleAdder.fmu"); type = :CS)
9193
@named adder = MTK.FMIComponent(
9294
Val(2); fmu, type = :CS, communication_step_size = 0.001)
9395
@variables a(t) b(t) c(t) [guess = 1.0]
@@ -104,4 +106,33 @@ end
104106
sol = solve(prob, Rodas5P(autodiff = false))
105107
@test SciMLBase.successful_retcode(sol)
106108
end
109+
110+
@testset "v3, ME" begin
111+
fmu = loadFMU(joinpath(FMU_DIR, "StateSpace.fmu"); type = :ME)
112+
@named sspace = MTK.FMIComponent(Val(3); fmu, type = :ME)
113+
@variables u(t)=1.0 x(t)=1.0 y(t) [guess = 1.0]
114+
@mtkbuild sys = ODESystem(
115+
[sspace.u ~ u, D(u) ~ t, D(x) ~ sspace.x + sspace.y, y^2 ~ sspace.y + x], t;
116+
systems = [sspace]
117+
)
118+
119+
prob = ODEProblem(sys, [sys.sspace.x => 1.0], (0.0, 1.0); use_scc = false)
120+
sol = solve(prob, Rodas5P(autodiff = false))
121+
@test SciMLBase.successful_retcode(sol)
122+
end
123+
124+
@testset "v3, CS" begin
125+
fmu = loadFMU(joinpath(FMU_DIR, "StateSpace.fmu"); type = :CS)
126+
@named sspace = MTK.FMIComponent(
127+
Val(3); fmu, communication_step_size = 1e-3, type = :CS)
128+
@variables u(t)=1.0 x(t)=1.0 y(t) [guess = 1.0]
129+
@mtkbuild sys = ODESystem(
130+
[sspace.u ~ u, D(u) ~ t, D(x) ~ sspace.x + sspace.y, y^2 ~ sspace.y + x], t;
131+
systems = [sspace]
132+
)
133+
134+
prob = ODEProblem(sys, [sys.sspace.x => 1.0], (0.0, 1.0); use_scc = false)
135+
sol = solve(prob, Rodas5P(autodiff = false))
136+
@test SciMLBase.successful_retcode(sol)
137+
end
107138
end

test/extensions/fmus/StateSpace.fmu

33.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)