Skip to content

Commit be7e91f

Browse files
committed
JModelica scripts for folder BuildingSystems\Technologies\Chillers\Examples added
1 parent 270f00d commit be7e91f

File tree

9 files changed

+127
-2
lines changed

9 files changed

+127
-2
lines changed

BuildingSystems/Resources/Scripts/Dymola/Technologies/Chillers/Examples/CompressionChiller.mos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
simulateModel("BuildingSystems.Technologies.Chillers.Examples.CompressionChiller", stopTime=7200, method="dassl", resultFile="CompressionChiller");
1+
simulateModel("BuildingSystems.Technologies.Chillers.Examples.CompressionChiller", stopTime=7200, method="cvode", resultFile="CompressionChiller");
22
removePlots();
33
createPlot(
44
id = 1,

BuildingSystems/Resources/Scripts/Dymola/Technologies/Chillers/Examples/CompressionChillerWithStorage.mos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
simulateModel("BuildingSystems.Technologies.Chillers.Examples.CompressionChillerWithStorage", stopTime=7200, method="dassl", resultFile="CompressionChillerWithStorage");
1+
simulateModel("BuildingSystems.Technologies.Chillers.Examples.CompressionChillerWithStorage", stopTime=7200, method="cvode", resultFile="CompressionChillerWithStorage");
22
removePlots();
33
createPlot(
44
id = 1,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.Technologies.Chillers.Examples.CompressionChiller'
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'] = 120
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, final_time=7200.0, options=opts)
38+
39+
# <codecell> plotting of the results
40+
import pylab as P
41+
fig = P.figure(1)
42+
P.clf()
43+
# temperatures chiller
44+
y1 = res['senTemEvaIn.T']
45+
y2 = res['senTemEvaOut.T']
46+
y3 = res['senTemConIn.T']
47+
y4 = res['senTemConOut.T']
48+
t = res['time']
49+
P.subplot(2,1,1)
50+
P.plot(t, y1, t, y2, t, y3, t, y4)
51+
P.legend(['senTemEvaIn.T','senTemEvaOut.T','senTemConIn.T','senTemConOut'])
52+
P.ylabel('Temperature (K)')
53+
P.xlabel('Time (s)')
54+
# COP chiller
55+
y1 = res['chiller.COP']
56+
P.subplot(2,1,2)
57+
P.plot(t, y1)
58+
P.legend(['chiller.COP'])
59+
P.ylabel('COP (1)')
60+
P.xlabel('Time (s)')
61+
P.show()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.Technologies.Chillers.Examples.CompressionChillerWithStorage'
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'] = 120
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, final_time=7200, options=opts)
38+
39+
# <codecell> plotting of the results
40+
import pylab as P
41+
fig = P.figure(1)
42+
P.clf()
43+
# temperatures chiller
44+
y1 = res['senTemEvaIn.T']
45+
y2 = res['senTemEvaOut.T']
46+
y3 = res['senTemConIn.T']
47+
y4 = res['senTemConOut.T']
48+
t = res['time']
49+
P.subplot(2,1,1)
50+
P.plot(t, y1, t, y2, t, y3, t, y4)
51+
P.legend(['senTemEvaIn.T','senTemEvaOut.T','senTemConIn.T','senTemConOut'])
52+
P.ylabel('Temperature (K)')
53+
P.xlabel('Time (s)')
54+
# temperatures storage
55+
y1 = res['storage.T[1]']
56+
y2 = res['storage.T[2]']
57+
y3 = res['storage.T[3]']
58+
y4 = res['storage.T[3]']
59+
P.subplot(2,1,2)
60+
P.plot(t, y1, t, y2, t, y3, t, y4)
61+
P.legend(['storage.T[1]','storage.T[2]','storage.T[3]','storage.T[4]'])
62+
P.ylabel('Temperature (K)')
63+
P.xlabel('Time (s)')
64+
P.show()

0 commit comments

Comments
 (0)