|
| 1 | +# 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 | +# compile model to fmu |
| 18 | +from pymodelica import compile_fmu |
| 19 | +model_name = 'BuildingSystems.Buildings.Constructions.Examples.WallThermal1DNodes' |
| 20 | +my_fmu = compile_fmu(model_name, moLibs) |
| 21 | + |
| 22 | +# 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 | +# plotting of the results |
| 40 | +import pylab as P |
| 41 | +fig = P.figure(1) |
| 42 | +P.clf() |
| 43 | +# wall |
| 44 | +# temperatures |
| 45 | +y1 = res['ambient.TAirRef'] |
| 46 | +y2 = res['wall.construction.layer[1].T[1]'] |
| 47 | +y3 = res['wall.construction.layer[1].T[2]'] |
| 48 | +y4 = res['wall.construction.layer[2].T[1]'] |
| 49 | +y5 = res['wall.construction.layer[2].T[2]'] |
| 50 | +t = res['time'] |
| 51 | +P.subplot(2,1,1) |
| 52 | +P.plot(t, y1, t, y2, t, y3, t, y4, t, y5) |
| 53 | +P.legend(['ambient.TAirRef','wall.construction.layer[1].T[1]','wall.construction.layer[1].T[2]','wall.construction.layer[2].T[1]','wall.construction.layer[2].T[2]']) |
| 54 | +P.ylabel('Temperature (K)') |
| 55 | +P.xlabel('Time (s)') |
| 56 | +# wall |
| 57 | +# heat flows |
| 58 | +y1 = res['wall.construction.heatPort_x1.Q_flow'] |
| 59 | +y2 = res['wall.construction.heatPort_x1.Q_flow'] |
| 60 | +P.subplot(2,1,2) |
| 61 | +P.plot(t, y1, t, y2) |
| 62 | +P.legend(['wall.construction.heatPort_x1.Q_flow','wall.construction.heatPort_x1.Q_flow']) |
| 63 | +P.ylabel('Heat flow (W)') |
| 64 | +P.xlabel('Time (s)') |
| 65 | +P.show() |
0 commit comments