SwissHouseRSlaTank notebook example

In this example, the usage of the model “SwissHouseRad-v0” is demonstrated.

First, we import Energym and create the simulation environment by specifying the model, a weather file and the number of simulation days.

[2]:
import energym

weather = "CH_BS_Basel"
env = energym.make("SwissHouseRSlaTank-v0", weather=weather, simulation_days=20)
the initial variables are {'uHP': 0, 'uRSla': 0}

The control inputs can be inspected using the get_inputs_names() method.

[2]:
inputs = env.get_inputs_names()
outputs = env.get_outputs_names()
print("inputs:", inputs)
print("outputs:", outputs)
inputs: ['uHP', 'uRSla']
outputs: ['TOut.T', 'heaPum.COP', 'heaPum.COPCar', 'heaPum.P', 'heaPum.QCon_flow', 'heaPum.QEva_flow', 'heaPum.TConAct', 'heaPum.TEvaAct', 'preHea.Q_flow', 'sla.QTot', 'sla.heatPortEmb[1].T', 'sla.m_flow', 'temRoo.T', 'weaBus.HDifHor', 'weaBus.HDirNor', 'weaBus.HGloHor', 'weaBus.HHorIR']
[12]:
[ p for p in env.vrs if "tem" in p]
[12]:
['tanSH.indTanHex.hAPipIns[1].temperatureDependent',
 'tanSH.indTanHex.hAPipIns[2].temperatureDependent',
 'tanSH.indTanHex.hAPipIns[3].temperatureDependent',
 'tanSH.indTanHex.hAPipIns[4].temperatureDependent',
 'tanSH.indTanHex.hAPipIns[5].temperatureDependent',
 'tanSH.indTanHex.hAPipIns[6].temperatureDependent',
 'tanSH.indTanHex.hA_temperatureDependent',
 'tanSH.indTanHex.temSenHex[1].T',
 'tanSH.indTanHex.temSenHex[1].port.Q_flow',
 'tanSH.indTanHex.temSenHex[1].port.T',
 'tanSH.indTanHex.temSenHex[2].T',
 'tanSH.indTanHex.temSenHex[2].port.Q_flow',
 'tanSH.indTanHex.temSenHex[2].port.T',
 'tanSH.indTanHex.temSenHex[3].T',
 'tanSH.indTanHex.temSenHex[3].port.Q_flow',
 'tanSH.indTanHex.temSenHex[3].port.T',
 'tanSH.indTanHex.temSenHex[4].T',
 'tanSH.indTanHex.temSenHex[4].port.Q_flow',
 'tanSH.indTanHex.temSenHex[4].port.T',
 'tanSH.indTanHex.temSenHex[5].T',
 'tanSH.indTanHex.temSenHex[5].port.Q_flow',
 'tanSH.indTanHex.temSenHex[5].port.T',
 'tanSH.indTanHex.temSenHex[6].T',
 'tanSH.indTanHex.temSenHex[6].port.Q_flow',
 'tanSH.indTanHex.temSenHex[6].port.T',
 'tanSH.indTanHex.temSenSur[1].T',
 'tanSH.indTanHex.temSenSur[1].port.Q_flow',
 'tanSH.indTanHex.temSenSur[1].port.T',
 'tanSH.indTanHex.temSenSur[2].T',
 'tanSH.indTanHex.temSenSur[2].port.Q_flow',
 'tanSH.indTanHex.temSenSur[2].port.T',
 'tanSH.indTanHex.temSenSur[3].T',
 'tanSH.indTanHex.temSenSur[3].port.Q_flow',
 'tanSH.indTanHex.temSenSur[3].port.T',
 'tanSH.indTanHex.temSenSur[4].T',
 'tanSH.indTanHex.temSenSur[4].port.Q_flow',
 'tanSH.indTanHex.temSenSur[4].port.T',
 'tanSH.indTanHex.temSenSur[5].T',
 'tanSH.indTanHex.temSenSur[5].port.Q_flow',
 'tanSH.indTanHex.temSenSur[5].port.T',
 'tanSH.indTanHex.temSenSur[6].T',
 'tanSH.indTanHex.temSenSur[6].port.Q_flow',
 'tanSH.indTanHex.temSenSur[6].port.T',
 'tanSH.indTanHex.temSenWat[1].T',
 'tanSH.indTanHex.temSenWat[1].port.Q_flow',
 'tanSH.indTanHex.temSenWat[1].port.T',
 'tanSH.indTanHex.temSenWat[2].T',
 'tanSH.indTanHex.temSenWat[2].port.Q_flow',
 'tanSH.indTanHex.temSenWat[2].port.T',
 'tanSH.indTanHex.temSenWat[3].T',
 'tanSH.indTanHex.temSenWat[3].port.Q_flow',
 'tanSH.indTanHex.temSenWat[3].port.T',
 'tanSH.indTanHex.temSenWat[4].T',
 'tanSH.indTanHex.temSenWat[4].port.Q_flow',
 'tanSH.indTanHex.temSenWat[4].port.T',
 'tanSH.indTanHex.temSenWat[5].T',
 'tanSH.indTanHex.temSenWat[5].port.Q_flow',
 'tanSH.indTanHex.temSenWat[5].port.T',
 'tanSH.indTanHex.temSenWat[6].T',
 'tanSH.indTanHex.temSenWat[6].port.Q_flow',
 'tanSH.indTanHex.temSenWat[6].port.T',
 'temHP',
 'temHP2Hex.T',
 'der(temHP2Hex.T)',
 'temHP2Hex.TAmb',
 'temHP2Hex.TMed',
 'temHP2Hex.T_a_inflow',
 'temHP2Hex.T_b_inflow',
 'temHP2Hex.T_start',
 'temHP2Hex.allowFlowReversal',
 'temHP2Hex.dynamic',
 'temHP2Hex.initType',
 'temHP2Hex.k',
 'temHP2Hex.mNor_flow',
 'temHP2Hex.m_flow_nominal',
 'temHP2Hex.m_flow_small',
 'temHP2Hex.port_a.h_outflow',
 'temHP2Hex.port_a.m_flow',
 'temHP2Hex.port_a.p',
 'temHP2Hex.port_b.h_outflow',
 'temHP2Hex.port_b.m_flow',
 'temHP2Hex.port_b.p',
 'temHP2Hex.ratTau',
 'temHP2Hex.tau',
 'temHP2Hex.tauHeaTra',
 'temHP2Hex.tauHeaTraInv',
 'temHP2Hex.tauInv',
 'temHP2Hex.transferHeat',
 'temHex2HP.T',
 'der(temHex2HP.T)',
 'temHex2HP.TAmb',
 'temHex2HP.TMed',
 'temHex2HP.T_a_inflow',
 'temHex2HP.T_b_inflow',
 'temHex2HP.T_start',
 'temHex2HP.allowFlowReversal',
 'temHex2HP.dynamic',
 'temHex2HP.initType',
 'temHex2HP.k',
 'temHex2HP.mNor_flow',
 'temHex2HP.m_flow_nominal',
 'temHex2HP.m_flow_small',
 'temHex2HP.port_a.h_outflow',
 'temHex2HP.port_a.m_flow',
 'temHex2HP.port_a.p',
 'temHex2HP.port_b.h_outflow',
 'temHex2HP.port_b.m_flow',
 'temHex2HP.port_b.p',
 'temHex2HP.ratTau',
 'temHex2HP.tau',
 'temHex2HP.tauHeaTra',
 'temHex2HP.tauHeaTraInv',
 'temHex2HP.tauInv',
 'temHex2HP.transferHeat',
 'temRoo.T',
 'temRoo.port.Q_flow',
 'temRoo.port.T',
 'temRoom',
 'temSla2Tan.T',
 'der(temSla2Tan.T)',
 'temSla2Tan.TAmb',
 'temSla2Tan.TMed',
 'temSla2Tan.T_a_inflow',
 'temSla2Tan.T_b_inflow',
 'temSla2Tan.T_start',
 'temSla2Tan.allowFlowReversal',
 'temSla2Tan.dynamic',
 'temSla2Tan.initType',
 'temSla2Tan.k',
 'temSla2Tan.mNor_flow',
 'temSla2Tan.m_flow_nominal',
 'temSla2Tan.m_flow_small',
 'temSla2Tan.port_a.h_outflow',
 'temSla2Tan.port_a.m_flow',
 'temSla2Tan.port_a.p',
 'temSla2Tan.port_b.h_outflow',
 'temSla2Tan.port_b.m_flow',
 'temSla2Tan.port_b.p',
 'temSla2Tan.ratTau',
 'temSla2Tan.tau',
 'temSla2Tan.tauHeaTra',
 'temSla2Tan.tauHeaTraInv',
 'temSla2Tan.tauInv',
 'temSla2Tan.transferHeat',
 'temTan2Sla.T',
 'der(temTan2Sla.T)',
 'temTan2Sla.TAmb',
 'temTan2Sla.TMed',
 'temTan2Sla.T_a_inflow',
 'temTan2Sla.T_b_inflow',
 'temTan2Sla.T_start',
 'temTan2Sla.allowFlowReversal',
 'temTan2Sla.dynamic',
 'temTan2Sla.initType',
 'temTan2Sla.k',
 'temTan2Sla.mNor_flow',
 'temTan2Sla.m_flow_nominal',
 'temTan2Sla.m_flow_small',
 'temTan2Sla.port_a.h_outflow',
 'temTan2Sla.port_a.m_flow',
 'temTan2Sla.port_a.p',
 'temTan2Sla.port_b.h_outflow',
 'temTan2Sla.port_b.m_flow',
 'temTan2Sla.port_b.p',
 'temTan2Sla.ratTau',
 'temTan2Sla.tau',
 'temTan2Sla.tauHeaTra',
 'temTan2Sla.tauHeaTraInv',
 'temTan2Sla.tauInv',
 'temTan2Sla.transferHeat',
 'temp_100',
 'temp_101',
 'temp_87',
 'temp_88',
 'temp_89',
 'temp_90',
 'temp_91',
 'temp_92',
 'temp_93',
 'temp_94',
 'temp_95',
 'temp_96',
 'temp_97',
 'temp_98',
 'temp_99']

To run the simulation, a number of steps is specified (here 288 steps per day for 10 days), a control input is specified and passed to the simulation model with the step() method. To generate some plots later on, we save all the outputs in lists.

[3]:
from scipy import signal

steps = 288*5
out_list = []
outputs = env.get_output()
controls = []
hour = 0
for i in range(steps):
    control = {}
    control['uHP'] = [0.5*(signal.square(0.1*i)+1.0)]
    control['uRSla'] = [0.5*(math.sin(0.01*i)+1.0)]
    controls +=[ {p:control[p][0] for p in control} ]
    outputs = env.step(control)
    _,hour,_,_ = env.get_date()
    out_list.append(outputs)
[OK] %s
[WARNING] %s
[WARNING] %s

Since the outputs are given as dictionaries and are collected in lists, we can simply load them as a pandas.DataFrame.

[4]:
import pandas as pd
out_df = pd.DataFrame(out_list)
[5]:
out_df
[5]:
TOut.T heaPum.COP heaPum.COPCar heaPum.P heaPum.QCon_flow heaPum.QEva_flow heaPum.TConAct heaPum.TEvaAct preHea.Q_flow sla.QTot sla.heatPortEmb[1].T sla.m_flow temRoo.T weaBus.HDifHor weaBus.HDirNor weaBus.HGloHor weaBus.HHorIR time
0 273.040697 2.936312 9.333496 1000.0 2.936312e+03 -1.936312e+03 298.244740 266.290503 0.0 491.136760 293.259915 1.0 293.137130 0.0 0.0 0.0 198.356554 300.0
1 273.050842 2.926178 9.301283 1000.0 2.926178e+03 -1.926178e+03 298.419801 266.336076 0.0 863.146962 293.343195 1.0 293.127409 0.0 0.0 0.0 198.314931 600.0
2 273.060017 2.917537 9.273817 1000.0 2.917537e+03 -1.917537e+03 298.570454 266.375464 0.0 1179.949544 293.415200 1.0 293.120212 0.0 0.0 0.0 198.276953 900.0
3 273.067805 2.909959 9.249729 1000.0 2.909959e+03 -1.909959e+03 298.702920 266.409766 0.0 1455.690932 293.479116 1.0 293.115194 0.0 0.0 0.0 198.244444 1200.0
4 273.073788 2.903212 9.228283 1000.0 2.903212e+03 -1.903212e+03 298.820295 266.439374 0.0 1697.535518 293.536461 1.0 293.112077 0.0 0.0 0.0 198.219227 1500.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1435 278.738889 4.229040 13.442619 0.0 1.925930e-34 -1.925930e-34 301.141021 278.739062 0.0 427.618111 296.405626 1.0 296.298722 0.0 0.0 0.0 298.691478 430800.0
1436 278.737656 4.228762 13.441736 0.0 1.925930e-34 -1.925930e-34 301.141021 278.737589 0.0 403.327543 296.389726 1.0 296.288894 0.0 0.0 0.0 298.764373 431100.0
1437 278.743194 4.229753 13.444886 0.0 1.925930e-34 -1.925930e-34 301.141021 278.742838 0.0 381.896320 296.374382 1.0 296.278908 0.0 0.0 0.0 298.817684 431400.0
1438 278.756858 4.232269 13.452885 0.0 1.925930e-34 -1.925930e-34 301.141021 278.756156 0.0 362.985865 296.359535 1.0 296.268789 0.0 0.0 0.0 298.847523 431700.0
1439 278.780000 4.236575 13.466570 0.0 1.925930e-34 -1.925930e-34 301.141021 278.778904 0.0 346.280830 296.345130 1.0 296.258560 0.0 0.0 0.0 298.850000 432000.0

1440 rows × 18 columns

To generate plots, we can directly get the data from the DataFrames, by using the key names. Displayed are the room temperature, the supply temperature and the return temperature, as well as the external temperature, and the heat pump energy.

[14]:
import matplotlib.pyplot as plt
%matplotlib notebook

f, (ax1,ax2,ax3) = plt.subplots(3,figsize=(10,15))#


ax1.plot(out_df['temRoo.T']-273.15, 'r')
ax1.plot(out_df['sla.heatPortEmb[1].T']-273.15, 'b--')
ax1.plot(out_df['heaPum.TEvaAct']-273.15, 'orange')
ax1.set_ylabel('Temp')
ax1.set_xlabel('Steps')

ax2.plot(out_df['TOut.T']-273.15, 'r')
ax2.set_ylabel('Temp')
ax2.set_xlabel('Steps')

ax3.plot(out_df['heaPum.QCon_flow'], 'g')
ax3.set_ylabel('Energy')
ax3.set_xlabel('Steps')

plt.subplots_adjust(hspace=0.4)

plt.show()

To end the simulation, the close() method is called. It deletes files that were produced during the simulation and stores some information about the simulation in the energym_runs folder.

[ ]:
env.close()
[ ]: