In [1]:
#Import the needed Packages
import pandas as pd
import numpy as np
import control as cn
import matplotlib.pyplot as plt
# Matplotlib inline magic
%matplotlib inline
from Algorithms import cm2in, TUBScolorscale

In [80]:
# Define a FOTD System
def FOTD(K,T,L,u,t):
    # New Array for Output
    y = np.zeros_like(u)
    for i in range(0,len(u)):
        if t[i]>=L:
            y[i] = K*(1-np.exp(-(t[i]-L)/T))*u[i]
    return y

In [125]:
plt.clf()
# Second Plot
t = np.linspace(0,1000,2000)
u = np.ones_like(t)
y1 = FOTD(5,40,100,u,t)
y1inf = 5*np.ones_like(t)
y2 = FOTD(5,80,400,u,t)
y2 = y1+y2
y2inf = 10*np.ones_like(t)
x0 = np.array([0,0])
z0 = np.array([0,10])
x1 = np.array([100,100])
z1 = np.array([0,5])
x2 = np.array([400,400])
z2 = np.array([5,10])
# Plot
fig2, ax2 = plt.subplots(figsize=(10,4))
# Outer Contour
ax2.plot(x0,z0,color="black")
ax2.plot(t,y2inf,color="black")
ax2.plot(t,y2,color="black")
ax2.plot(x1,z1,color="black")
ax2.plot(x2,z2,color="black")
# Fills
ax2.plot(t[np.where(t<400)],y1inf[np.where(t<400)], color="black")
ax2.fill_between(t[np.where(t<100)],y1inf[np.where(t<100)], y1[np.where(t<100)], facecolor=TUBScolorscale[6])
ax2.fill_between(t[np.where(t>=100)],y1inf[np.where(t>=100)], y1[np.where(t>=100)], facecolor=TUBScolorscale[2])
ax2.fill_between(t[np.where(t<400)],y1inf[np.where(t<400)], y2inf[np.where(t<400)], facecolor=TUBScolorscale[6])
ax2.fill_between(t[np.where(t>400)],y2inf[np.where(t>400)], y2[np.where(t>400)], facecolor=TUBScolorscale[2])
# Titles
plt.ylabel('Output')
plt.xlabel('Time [min]')
ax2.grid(True)
#plt.show()
#plt.gcf()
plt.rcParams['svg.fonttype'] = 'none'
plt.savefig("Testing.svg")


<matplotlib.figure.Figure at 0x12a6fca26a0>

In [20]:
# Make a Scatter Plot of the Gains

trace1 = Scatter(x = T, y = K1,
                 name ='Fan to Temperature',
                 mode = 'lines+markers', 
                 line = dict(
                     color = TUBScolorscale[0],
                     width = 1
                     #dash = 'dash'
                 ))
trace2 = Scatter(x = T, y = K2, 
                 name ='Fan to Pressure',
                 mode = 'lines+markers',
                 line = dict(
                     color = TUBScolorscale[1],
                     width = 1
                     #dash = 'dash'
                 ))
trace3 = Scatter(x = T, y = K3, 
                 name ='Valve to Temperature', 
                 mode = 'lines+markers', 
                 line = dict(
                     color = TUBScolorscale[2],
                     width = 1
                     #dash = 'dash'
                 ))
trace4 = Scatter(x = T, y = K4, name ='Valve to Pressure', mode = 'lines+markers', line = dict(
                     color = TUBScolorscale[3],
                     width = 1
                     #dash = 'dash'
                 ))

fig = dict(data=[trace1, trace2, trace3, trace4], layout=layout1)
iplot(fig)



In [21]:
# Define the Plot Layout
layout2 = dict(autosize = False,
              width = width, # approx 20 cm
              height = height, # approx 11 cm
              font=dict(family='Nexus'), # TUBS Font
              # Change here for title etc
              yaxis = dict(
                  zeroline = False,
                  title = 'System Time Constant [s]',
                  #range = [1.2,1.35],
                  autotick = True,
                  ticks='outside',
                  #tick0 = 1.2,
                  #dtick = 0.05,
                  showgrid = True              ),
                  
              xaxis = dict(
                    zeroline = False,
                    title = 'Operating points in [K]',
                    range = [272,308],
                    autotick = False,
                    ticks='outside',
                    tick0 = 273,
                    dtick = 2,
                  showgrid = True
                          ),
              
              legend=dict(
                  x = 0,
                  y = 1.3,
        orientation = "h",
        traceorder='normal',
        font=dict(
            family='Nexus',
            size=FontSize,
            color='#000'
        )
    )
             )

In [22]:
# Make a Scatter Plot of the Time Constants

trace1 = Scatter(x = T, y = T1,
                 name ='Fan to Temperature',
                 mode = 'lines+markers', 
                 line = dict(
                     color = TUBScolorscale[0],
                     width = 1
                     #dash = 'dash'
                 ))
trace2 = Scatter(x = T, y = T2, 
                 name ='Fan to Pressure',
                 mode = 'lines+markers',
                 line = dict(
                     color = TUBScolorscale[1],
                     width = 1
                     #dash = 'dash'
                 ))
trace3 = Scatter(x = T, y = T3, 
                 name ='Valve to Temperature', 
                 mode = 'lines+markers', 
                 line = dict(
                     color = TUBScolorscale[2],
                     width = 1
                     #dash = 'dash'
                 ))
trace4 = Scatter(x = T, y = T4,
                 name ='Valve to Pressure',
                 mode = 'lines+markers', line = dict(
                     color = TUBScolorscale[3],
                     width = 1
                     #dash = 'dash'
                 ))

fig = dict(data=[trace1, trace2, trace3, trace4], layout=layout2)
iplot(fig)



In [27]:
# Define the Plot Layout
layout3 = dict(autosize = False,
              width = width,
              height = height,
              font=dict(family='Nexus', size = FontSize), # TUBS Font
              # Change here for title etc
              yaxis = dict(
                  zeroline = False,
                  title = 'System Time Delay [s]',
                  #range = [1.2,1.35],
                  autotick = True,
                  ticks='outside',
                  #tick0 = 1.2,
                  #dtick = 0.05,
                  showgrid = True              ),
                  
              xaxis = dict(
                    zeroline = False,
                    title = 'Operating points in [K]',
                    range = [272,308],
                    autotick = False,
                    ticks='outside',
                    tick0 = 273,
                    dtick = 2,
                  showgrid = True
                          ),
              
              legend=dict(
                  x = 0,
                  y = 1.3,
        orientation = "h",
        traceorder='normal',
        font=dict(
            family='Nexus',
            size=FontSize,
            color='#000'
        )
    )
             )

In [28]:
# Make a Scatter Plot of the Time Delays

trace1 = Scatter(x = T, y = L1,
                 name ='Fan to Temperature',
                 mode = 'lines+markers', 
                 line = dict(
                     color = TUBScolorscale[0],
                     width = 1
                     #dash = 'dash'
                 ))
trace2 = Scatter(x = T, y = L2, 
                 name ='Fan to Pressure',
                 mode = 'lines+markers',
                 line = dict(
                     color = TUBScolorscale[1],
                     width = 1
                     #dash = 'dash'
                 ))
trace3 = Scatter(x = T, y = L3, 
                 name ='Valve to Temperature', 
                 mode = 'lines+markers', 
                 line = dict(
                     color = TUBScolorscale[2],
                     width = 1
                     #dash = 'dash'
                 ))
trace4 = Scatter(x = T, y = L4,
                 name ='Valve to Pressure',
                 mode = 'lines+markers', line = dict(
                     color = TUBScolorscale[3],
                     width = 1
                     #dash = 'dash'
                 ))

fig = dict(data=[trace1, trace2, trace3, trace4], layout=layout3)
iplot(fig)



In [29]:
# Define the Plot Layout
layout4 = dict(autosize = False,
              width = width,
              height = height,
              font=dict(family='Nexus'), # TUBS Font
              # Change here for title etc
              yaxis = dict(
                  zeroline = False,
                  title = 'System Coupling',
                  #range = [1.2,1.35],
                  autotick = True,
                  ticks='outside',
                  #tick0 = 1.2,
                  #dtick = 0.05,
                  showgrid = True              ),
                  
              xaxis = dict(
                    zeroline = False,
                    title = 'Operating points in [K]',
                    range = [272,308],
                    autotick = False,
                    ticks='outside',
                    tick0 = 273,
                    dtick = 2,
                  showgrid = True
                          ),
              
              legend=dict(
                  x = 0,
                  y = 1.3,
        orientation = "h",
        traceorder='normal',
        font=dict(
            family='Nexus',
            size=12,
            color='#000'
        )
    )
             )

In [41]:
# Make a Scatter Plot of the Couplings

trace1 = Scatter(x = T, y = K2*(L1+T1-L2-T2),
                 line = dict(
                     color = TUBScolorscale[0],
                     width = 1
                     #dash = 'dash'
                 ),
                 name ='Valve to Temperature',
                 mode = 'lines+markers')
trace2 = Scatter(x = T, y = K3*(L4+T4-L3-T3),
                 line = dict(
                     color = TUBScolorscale[1],
                     width = 1
                     #dash = 'dash'
                 ),
                 name ='Fan to Pressure',
                 mode = 'lines+markers')


fig = dict(data=[trace1, trace2], layout=layout4)
iplot(fig)



In [33]:
# Make a Scatter Plot of the Couplings - Aström

trace1 = Scatter(x = T, y = (K1*K2/(K1*K4-K2*K3))*(L1+T1-L2-T2), name ='Valve to Temperature', mode = 'lines+markers')
trace2 = Scatter(x = T, y = (K3*K4/(K1*K4-K2*K3))*(L4+T4-L3-T3), name ='Fan to Pressure', mode = 'lines+markers')


fig = dict(data=[trace1, trace2], layout=layout4)
iplot(fig)



In [34]:
# Define the Plot Layout
layout5 = dict(autosize = False,
              width = width,
              height = height,
              font=dict(family='Nexus'), # TUBS Font
              # Change here for title etc
              yaxis = dict(
                  zeroline = False,
                  title = 'Controller Gain',
                  #range = [1.2,1.35],
                  autotick = True,
                  ticks='outside',
                  #tick0 = 1.2,
                  #dtick = 0.05,
                  showgrid = True              ),
                  
              xaxis = dict(
                    zeroline = False,
                    title = 'Operating points in [K]',
                    range = [272,308],
                    autotick = False,
                    ticks='outside',
                    tick0 = 273,
                    dtick = 2,
                  showgrid = True
                          ),
              
              legend=dict(
                  x = 0,
                  y = 1.3,
        orientation = "h",
        traceorder='normal',
        font=dict(
            family='Nexus',
            size=12,
            color='#000'
        )
    )
             )

In [35]:
# Define the controller proportional and integral gain

P1 = 0.15/K1 + (0.35 - (L1*T1)/(L1+T1)**2)*T1/K1/L1
P2 = 0.15/K4 + (0.35 - (L4*T4)/(L4+T4)**2)*T4/K4/L4
I1 = 0.35*L1+13*L1*T1**2/(T1**2+12*L1*T1+7*L1**2)
I2 = 0.35*L4+13*L4*T4**2/(T4**2+12*L4*T4+7*L4**2)

In [36]:
# Make a scatter plot of the controller variables

trace1 = Scatter(x = T, y = P1, name ='Valve Controller', mode = 'lines+markers')
trace2 = Scatter(x = T, y = P2, name ='Fan Controller', mode = 'lines+markers')


fig = dict(data=[trace1, trace2], layout=layout5)
iplot(fig)



In [37]:
# Make a Scatter Plot of the Couplings - Aström

trace1 = Scatter(x = T, y = I1, name ='Valve Controller', mode = 'lines+markers')
trace2 = Scatter(x = T, y = I2, name ='Fan Controller', mode = 'lines+markers')


fig = dict(data=[trace1, trace2], layout=layout5)
iplot(fig)



In [42]:
len(T)


Out[42]:
35

In [ ]: