Skip to content

Commit 16e85f9

Browse files
test: add tests for FMIComponent
1 parent bf79239 commit 16e85f9

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

test/extensions/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
33
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
44
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
5+
FMI = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
6+
FMIZoo = "724179cf-c260-40a9-bd27-cccc6fe2f195"
57
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
68
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
79
InfiniteOpt = "20393b10-9daf-11e9-18c9-8db751c92c57"

test/extensions/fmi.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using ModelingToolkit, FMI, FMIZoo, OrdinaryDiffEq
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
3+
import ModelingToolkit as MTK
4+
5+
@testset "Standalone pendulum model" begin
6+
@testset "v2, ME" begin
7+
fmu = loadFMU("SpringPendulum1D", "Dymola", "2022x"; type = :ME)
8+
@mtkbuild sys = MTK.FMIComponent(Val(2), Val(:ME); fmu)
9+
prob = ODEProblem{true, SciMLBase.FullSpecialize}(
10+
sys, [sys.mass__s => 0.5, sys.mass__v => 0.0], (0.0, 8.0))
11+
sol = solve(prob, Tsit5(); reltol = 1e-8, abstol = 1e-8)
12+
@test SciMLBase.successful_retcode(sol)
13+
14+
truesol = FMI.simulate(fmu, (0.0, 8.0); saveat = 0.0:0.1:8.0)
15+
@test sol(0.0:0.1:8.0).utruesol.states.u atol=1e-4
16+
# repeated solve works
17+
@test_nowarn solve(prob, Tsit5())
18+
end
19+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ end
114114

115115
if GROUP == "All" || GROUP == "Extensions"
116116
activate_extensions_env()
117+
@safetestset "FMI Extension Test" include("extensions/fmi.jl")
117118
@safetestset "HomotopyContinuation Extension Test" include("extensions/homotopy_continuation.jl")
118119
@safetestset "Auto Differentiation Test" include("extensions/ad.jl")
119120
@safetestset "LabelledArrays Test" include("labelledarrays.jl")

0 commit comments

Comments
 (0)