In [1]:
    
%matplotlib inline
import dympy
import matplotlib.pyplot as plt
    
In [2]:
    
dir(dympy)
    
    Out[2]:
In [3]:
    
# initialize dymola connection
dymola = dympy.Dymola()
dymola.clear()
    
In [4]:
    
dymola.openModel('example.mo')
    
In [5]:
    
dymola.compile('example')
    
In [6]:
    
dymola.write_dsu({'time':[0,43200,86400],'Q_flow_hp':[1000,5000,2000],'T_amb':[273.15,278.15,273.15]})
dymola.set_parameters({'C_in.C':5e6,'C_em.C':10e6,'UA_em_in.G':1600,'UA_in_amb.G':200})
dymola.set_parameters({'C_em.T':300})
    
In [7]:
    
dymola.simulate(StopTime=86400)
    
In [8]:
    
res = dymola.get_result()
    
In [9]:
    
res.keys()
    
    Out[9]:
In [10]:
    
dymola.get_res('UA_em_in')
    
    Out[10]:
In [11]:
    
plt.figure(figsize=(10,8))
ax = plt.subplot(211)
ax.plot(res['time']/3600,res['Q_flow_hp'],'r',label='hp')
ax.plot(res['time']/3600,res['Q_flow_sol'],'g',label='sol')
ax.set_ylabel('$\dot{Q}$ (W)')
plt.legend()
ax = plt.subplot(212)
ax.plot(res['time']/3600,res['C_in.T'],'r',label='in')
ax.plot(res['time']/3600,res['C_em.T'],'b',label='em')
ax.plot(res['time']/3600,res['T_amb'],'g',label='amb')
ax.set_ylabel('$T$ ($^\circ$C)')
ax.set_xlabel('time (h)')
plt.legend()
    
    Out[11]:
    
In [12]:
    
dymola.dsfinal2dsin()
    
In [13]:
    
dymola.simulate(StartTime=86400,StopTime=2*86400)
    
In [14]:
    
res2 = dymola.get_result()
    
In [15]:
    
plt.figure(figsize=(10,8))
ax = plt.subplot(211)
ax.plot(res2['time']/3600,res2['Q_flow_hp'],'r',label='hp')
ax.plot(res2['time']/3600,res2['Q_flow_sol'],'g',label='sol')
ax.set_ylabel('$\dot{Q}$ (W)')
plt.legend()
ax = plt.subplot(212)
ax.plot(res2['time']/3600,res2['C_in.T'],'r',label='in')
ax.plot(res2['time']/3600,res2['C_em.T'],'b',label='em')
ax.plot(res2['time']/3600,res2['T_amb'],'g',label='amb')
ax.set_ylabel('$T$ ($^\circ$C)')
ax.set_xlabel('time (h)')
plt.legend()
    
    Out[15]: