Skip to content

Commit 86b6d42

Browse files
committed
JModelica scripts for example BuildingSystems\Applications\SolarThermalSytems\SolarThermalSystem1 added
1 parent db2f546 commit 86b6d42

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

BuildingSystems/Resources/Scripts/Dymola/Applications/SolarThermalSystems/SolarThermalSystem1.mos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
simulateModel("BuildingSystems.Applications.SolarThermalSystems.SolarThermalSystem1", stopTime=864000, method="dassl", tolerance = 1e-5, resultFile="SolarThermalSystem1");
1+
simulateModel("BuildingSystems.Applications.SolarThermalSystems.SolarThermalSystem1", stopTime=864000, method="dassl", resultFile="SolarThermalSystem1");
22
removePlots();
33
createPlot(
44
id = 1,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# <codecell> paths and info
2+
import os, sys
3+
homeDir = os.environ['HOMEPATH']
4+
jmodDir = os.environ['JMODELICA_HOME']
5+
workDir = "Desktop" # has to be adapted by the user !!!
6+
moLiDir = os.path.join(homeDir, workDir, "BuildingSystems")
7+
8+
# give the path to directory where package.mo is stored
9+
moLibs = [os.path.join(jmodDir, "ThirdParty\MSL\Modelica"),
10+
os.path.join(moLiDir,"BuildingSystems"),
11+
]
12+
13+
print(sys.version)
14+
print(all(os.path.isfile(os.path.join(moLib, "package.mo")) for moLib in moLibs))
15+
print(os.getcwd())
16+
17+
# <codecell> compile model to fmu
18+
from pymodelica import compile_fmu
19+
model_name = 'BuildingSystems.Applications.SolarThermalSystems.SolarThermalSystem1'
20+
my_fmu = compile_fmu(model_name, moLibs)
21+
22+
# <codecell> simulate the fmu and store results
23+
from pyfmi import load_fmu
24+
25+
myModel = load_fmu(my_fmu)
26+
27+
opts = myModel.simulate_options()
28+
opts['solver'] = "CVode"
29+
opts['ncp'] = 240
30+
opts['result_handling']="file"
31+
opts["CVode_options"]['discr'] = 'BDF'
32+
opts['CVode_options']['iter'] = 'Newton'
33+
opts['CVode_options']['maxord'] = 5
34+
opts['CVode_options']['atol'] = 1e-5
35+
opts['CVode_options']['rtol'] = 1e-5
36+
37+
res = myModel.simulate(start_time=0.0, final_time=864000, options=opts)
38+
39+
# <codecell> plotting of the results
40+
import pylab as P
41+
fig = P.figure(1)
42+
P.clf()
43+
# collector
44+
# radiation
45+
y1 = res['collector.radiationPort.IrrDir']
46+
y2 = res['collector.radiationPort.IrrDir']
47+
t = res['time']
48+
P.subplot(4,1,1)
49+
P.plot(t, y1, t, y2)
50+
P.legend(['collector.radiationPort.IrrDir','collector.radiationPort.IrrDir'])
51+
P.ylabel('Power (W/m2)')
52+
P.xlabel('Time (s)')
53+
# collector and storage temperatures
54+
y1 = res['collector.vol[10].T']
55+
y2 = res['storage.T[1]']
56+
y3 = res['storage.T[10]']
57+
t = res['time']
58+
P.subplot(4,1,2)
59+
P.plot(t, y1, t, y2, t, y3)
60+
P.legend(['collector.vol[10].T','storage.T[1]','storage.T[10]'])
61+
P.ylabel('Temperature (K)')
62+
P.xlabel('Time (s)')
63+
# control signal pump
64+
y1 = res['control.y']
65+
t = res['time']
66+
P.subplot(4,1,3)
67+
P.plot(t, y1)
68+
P.legend(['control.y'])
69+
P.ylabel('signal (1)')
70+
P.xlabel('Time (s)')
71+
# back up heater
72+
y1 = res['hea.Q_flow']
73+
t = res['time']
74+
P.subplot(4,1,4)
75+
P.plot(t, y1)
76+
P.legend(['hea.Q_flow'])
77+
P.ylabel('Power (W)')
78+
P.xlabel('Time (s)')
79+
P.show()

0 commit comments

Comments
 (0)