-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun.jl
199 lines (177 loc) · 5.33 KB
/
run.jl
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#= This file is used to run some predefined examples =#
#=
Simple test file
=#
using Revise
using OM
#= This import is needed =#
import OMBackend
import OMFrontend
function flatten(models)
for model in models
@time OM.flatten(model, "test/$(model).mo")
end
end
"""
Like flatten but tries to flatten several model in for instance a package
"""
function flatten(models, file)
local scode = OM.translateToSCode("test/$(file).mo")
local res
for model in models
@time res = OM.OMFrontend.instantiateSCodeToDAE(model, scode)
end
return res
end
function flattenFM(models, file)
local scode = OM.translateToSCode("test/$(file).mo")
local res
for model in models
@time res = OMFrontend.instantiateSCodeToFM(model, scode)
end
return res
end
function runModels(models)
for model in models
@info "Running : $model"
@time OM.runModelDAE(model, "test/$(model).mo")
end
end
function runModelsMTK(models)
for model in models
@info "Running : $model"
@time OM.runModelDAE(model, "test/$(model).mo", mode = OMBackend.MTK_MODE)
end
end
function runModelsMTK(models, file)
for model in models
@info "Running : $model"
@time OM.runModelDAE(model, "test/$(file).mo", mode = OMBackend.MTK_MODE)
end
end
function dumpModelsMTK(models, file)
local res
#= Get the simulation code =#
local scode = OM.translateToSCode("test/$(file).mo")
for model in models
@info "Dumping : $model"
res = OM.OMFrontend.instantiateSCodeToDAE(model, scode)
OMBackend.printInitialSystem(res[1])
end
end
simpleModelsNoSorting = ["HelloWorld", "LotkaVolterra", "VanDerPol"]
systemsWithoutDifferentials = ["HelloWorldWithoutDer"]
simpleModelsSorting = ["SimpleMechanicalSystem"]
simpleHybridModels = ["BouncingBallReals",
"IfEquationDer",
"BouncingBallsReal"
#=, "ManyEvents5" Currently issues with sundials=#
]
#modelsJustForFlattenTests = ["Influenza", "ElectricalComponentTest"]
#@info "Models that we flatten but are still unable to simulate"
#flatten(modelsJustForFlattenTests)
#= Simple Hybrid DAE systems. No hybrid-discrete behaviour=#
function flattenSimpleModels()
@info "Running flatten test:"
@info "Models that require no sorting"
flatten(simpleModelsNoSorting)
end
function flattenHybridSystems()
flatten(simpleHybridModels)
end
function flattenCompoundModels()
@info "Trying to flatten models in a package (Here we have inheritance)"
compoundModels = ["Models.ManyEvents", "Models.ManyEventsManyConditions"]
flatten(compoundModels, "ManyEventsPackage")
end
function runOriginalBackend()
runModels(systemsWithoutDifferentials)
@info "Simulating Simple Hybrid-DAE systems. No hybrid-discrete behavior:"
runModels(simpleModelsNoSorting)
runModels(simpleModelsSorting)
@info "Simulating Systems with hybrid behaviour:"
runModels(simpleHybridModels)
end
#= Simple hybrid systems =#
# @info "Running simple hybrid systems"
# #@time OM.runModel("BouncingBallReals", "test/BouncingBallReals.mo", stopTime = 5)
# #using Plots How to plot for instancehanicalSystem.mo"))
simpleHybridModels = ["BouncingBallReals",
"BouncingBallsReal",
"ManyEvents5"]
function runMTKBackend()
#= Running MTK tests=#
@info "Testing MTK backend.."
@info "Running the simple models with MTK"
runModelsMTK(simpleModelsNoSorting)
@info "Running more advanced models with MTK"
runModelsMTK(simpleModelsSorting)
@info "Testing hybrid systems with MTK"
runModelsMTK(simpleHybridModels)
end
function flattenAdvancedModelsC()
tst = ["ElectricalComponentTest.Resistor0", "ElectricalComponentTest.Resistor1", "ElectricalComponentTest.SimpleCircuit"]
F = "ElectricalComponentTest"
#tst = ["HelloWorld"#=, "ElectricalComponentTest.SimpleCircuit"=#]
# F = "HelloWorld"
for _ in 1:100
newRes = flatten(tst, F);
res = newRes
if res == newRes
println("No error!")
res = flatten(tst, F);
else
println("we have an error")
end
end
# @info oldRes
# OMBackend.turnOnLogging()
# runModelsMTK(tst, F)
0
end
function flattenFlatSimpleCircuit()
local tst = ["SimpleCircuit"]
local F = "FlattenSimpleCircuit"
#tst = ["HelloWorld"#=, "ElectricalComponentTest.SimpleCircuit"=#]
# F = "HelloWorld"
# @info oldRes
@info "Flatten"
oldRes = flatten(tst, F)
@info "Dumping the models"
dumpModelsMTK(tst, F)
#=lets try to run=#
runModelsMTK(tst, F)
0
end
function flattenAdvancedModels()
local tst = ["ElectricalComponentTest.ResistorCircuit0",
"ElectricalComponentTest.ResistorCircuit1",
"ElectricalComponentTest.SimpleCircuit"]
local F = "ElectricalComponentTest"
#tst = ["HelloWorld"#=, "ElectricalComponentTest.SimpleCircuit"=#]
# F = "HelloWorld"
# @info oldRes
@info "Flatten"
oldRes = flatten(tst, F)
dumpModelsMTK(tst, F)
#=lets try to run=#
runModelsMTK(tst, F)
0
end
function flattenConnectTest()
local tst = ["Connect5"]
local F = "Connect5"
#tst = ["HelloWorld"#=, "ElectricalComponentTest.SimpleCircuit"=#]
# F = "HelloWorld"
# @info oldRes
@info "Flatten"
local oldRes = flattenFM(tst, F)[1]
@info "Dumping the models"
res =OMFrontend.toString(oldRes)
@info "Dumping the model:"
println(res)
# dumpModelsMTK(tst, F)
#=lets try to run=#
# runModelsMTK(tst, F)
0
end