-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleLoop_simresults.jl
More file actions
81 lines (64 loc) · 1.93 KB
/
SimpleLoop_simresults.jl
File metadata and controls
81 lines (64 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using DrWatson
@quickactivate "SimpleLoop"
using NonLinearSystemNeuralNetworkFMU
using Revise
using DataFrames
using CSV
using CairoMakie
# Model and plot parameters
b = -0.5
Ns = [100, 500, 750, 1000]
FH_Colors = ["#009BBB",
"#E98300",
"#C50084",
"#722EA5",
"#A2AD00"]
# Simulate fmus
sol = DataFrame[]
for N in Ns
local workingDir = datadir("sims", "fmus")
local fmu = datadir(workingDir, "$(modelName).onnx_N$(N).fmu")
resultFile = "simpleLoop_onnx_res_N$(N).csv"
logFile = joinpath(workingDir, modelName*"_OMSimulator_N$(N).log")
cmd = `OMSimulator --resultFile=$resultFile --stopTime=2 "$(fmu)"`
redirect_stdio(stdout=logFile, stderr=logFile) do
run(Cmd(cmd, dir=workingDir))
end
push!(sol, CSV.read(joinpath(workingDir, resultFile), DataFrame; ntasks=1))
end
# Plot results
function plotSolution(dfs::Array{DataFrame}, Ns::Array{Int})
fig = Figure(fontsize = 21,
resolution = (1600, 800))
axis = Axis(fig[1,1],
title = "SimpleLoop Simulation Result",
xlabel = "time t",
ylabel = "y(t)")
lines!(axis, dfs[1].time, dfs[1].y_ref, color=:black)
for (i,df) in enumerate(dfs)
lines!(axis, df.time, df.y, color=FH_Colors[i+1], linestyle = :dash)
end
l1 = LineElement(color = :black)
l2 = LineElement(color = :black, linestyle = :dash)
Legend(fig[1,1],
[l1, l2],
["Ground truth", "Surroage"],
tellheight = false,
tellwidth = false,
margin = (50, 50, 50, 50),
halign = :left, valign = :top,
labelsize = 21)
groupN = [LineElement(color = FH_Colors[i+1], linestyle=:dash) for (i,_) in enumerate(dfs)]
Legend(fig[1,2],
groupN,
string.(Ns),
"N",
labelsize = 21)
return fig
end
fig = plotSolution(sol, Ns)
display(fig)
if !isdir(plotsdir())
mkpath(plotsdir())
end
save(plotsdir("SimpleLoop_simresults_y.svg"), fig)