The following examples use the PyScript framework.
Environment: NumPy, Matplotlib
Beispiel 3: Chemostat simulation
packages = ["numpy", "matplotlib"]
"""Python-Script for steady-state simulation of a chemostat adapted from
Chapter 16.2 "Chemostat at steady state (MATLAB)" of S.-O. Enfors (2019)
Fermentation Process Technology. Maintenance and cell death are neglected.
"""
import numpy as np
import matplotlib.pyplot as plt
# constants
mu_max = 0.8 # max. specific growth rate (1/h)
K_S = 0.1 # saturation constant (g/L)
S_i = 10 # inlet substrate concentration (g/L)
Y_xs = 0.5 # biomass-substrate yield coefficient (g/g)
# dilution rate (D) array
D = np.linspace(0.001,1,1000)
# critical dilution rate (D_crit) equals mu_max when cell death is neglected
D_crit = mu_max
# steady state (ss) equations (Enfors Chapt 11.1.3): specific growth rate (mu),
# limiting substrate (S), biomass (X), vol. biomass production rate (r_X)
def mu_ss(D):
"""Specific growth rate (mu) as a function of dilution rate (D). mu equals
D if D is less than D_crit. mu equals zero if D reaches D_crit.
"""
mu = D
if mu < D_crit:
return mu
else:
return 0
def S_ss(mu):
"""Concentration of limiting substrate (c_S) as a function of specific
growth rate (rearranged Monod equation). c_s is set to S_i when mu
approaches mu_max or if mu equals zero.
"""
c_S = mu * K_S / (mu_max - mu)
if c_S > S_i or mu == 0:
return S_i
else:
return c_S
def X_ss(c_S):
"""Concentration of biomass (c_X) as a function of c_S. The equation is
obtained from the mass balance equation of limiting substrate at steady-
state.
"""
c_X = (S_i - c_S) * Y_xs
return c_X
def r_X_ss(mu, c_X):
"""Volumetric biomass production rate (r_X) calculated as a product of
mu and c_X.
"""
r_X = mu * c_X
return r_X
# calculation of parameters at every dilution rate in D array
# with steady-state equations and list comprehension
mu = [mu_ss(i) for i in D]
c_S = [S_ss(i) for i in mu]
c_X = [X_ss(i) for i in c_S]
r_X = [r_X_ss(i,j) for i, j in zip(mu,c_X)]
# definition of matplotlib output
fig, ax = plt.subplots()
ax.set_xlabel('$D$ (h$^{-1}$)')
ax.set_ylabel('$c_\mathrm{X}$, $c_\mathrm{S}$ (g L$^{-1})$,' + '\t'
'$r_\mathrm{X}$ (g L$^{-1}$ h$^{-1}$)')
ax.plot(D, c_S, label='$c_\mathrm{S}$ (g L$^{-1})$,')
ax.plot(D, c_X, label='$c_\mathrm{X}$ (g L$^{-1})$,')
ax.plot(D, r_X, label='$r_\mathrm{X}$ (g L$^{-1}$ h$^{-1}$)')
ax.set_ylim(0,11)
ax.set_xlim(0,1)
ax_mu = ax.twinx()
ax_mu.plot(D, mu, '--', label='$\mu$ (h$^{-1}$)', color='black')
ax_mu.set_ylim(0,1.1)
ax_mu.set_ylabel('$\mu$ (h$^{-1}$)')
fig.legend(loc=(0.15,0.6))
plt
<