Figure 6.27:

Phase portrait of conversion versus temperature for several initial conditions; \tau =35~min.

Figure 6.27

Code for Figure 6.27

Text of the GNU GPL.

main.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Converted from phase_portrait.m - Phase portrait for theta=35 CSTR (5 trajectories)
import numpy as np
from scipy.integrate import solve_ivp
from misc import save_ascii

p = dict(
    k_m      = 0.004,
    T_m      = 298.,
    E        = 15000.,
    c_Af     = 2.,
    C_p      = 4.,
    rho      = 1000.,
    T_f      = 298.,
    T_a      = 298.,
    DeltaH_R = -2.2e5,
    U        = 340.,
    theta    = 35.,
    T_set    = 321.53,
    c_set    = 0.48995,
    T_fs     = 298.,
    Kc       = 0.,
)
p['C_ps'] = p['C_p'] * p['rho']

def rhs(t, x, p):
    c_A = x[0]; T = x[1]
    k   = p['k_m'] * np.exp(-p['E'] * (1./T - 1./p['T_m']))
    T_f = p['T_fs'] + p['Kc'] * (T - p['T_set'])
    return [
        (p['c_Af'] - c_A)/p['theta'] - k*c_A,
        p['U']/p['C_ps']*(p['T_a']-T) + (T_f-T)/p['theta'] - k*c_A*p['DeltaH_R']/p['C_ps']
    ]

ics = [
    [p['c_Af'], p['T_f']],
    [0., p['T_f']],
    [0.3980, 321.39],
    [0.8*p['c_Af'], 310.],  # x=0.8 => c_A=0.4
    [0.4*p['c_Af'], 315.],  # x=0.6 => c_A=0.8 -- but Octave has x=0.6,c_Af=2 → c_A=(1-0.6)*2=0.8
]

# Note: Octave source uses x0=[.8,310] and x0=[.6,315] as c_A directly (not conversion)
ics = [
    [p['c_Af'], p['T_f']],
    [0., p['T_f']],
    [0.3980, 321.39],
    [0.8, 310.],
    [0.6, 315.],
]

tfinal = 5. * p['theta']
ntimes = 200
table  = None

for x0_i in ics:
    tout = np.linspace(0., tfinal, ntimes)
    sol  = solve_ivp(lambda t, x: rhs(t, x, p), [0., tfinal], x0_i,
                     method='Radau', t_eval=tout,
                     rtol=np.sqrt(np.finfo(float).eps),
                     atol=np.sqrt(np.finfo(float).eps))
    x    = sol.y.T
    conv = (p['c_Af'] - x[:, 0]) / p['c_Af']
    block = np.column_stack([conv, x[:, 1]])
    if table is None:
        table = block
    else:
        table = np.column_stack([table, block])

save_ascii('phase_portrait.dat', table)