The following examples use the PyScript framework.
Environment: NumPy, Matplotlib, SciPy
Beispiel 4: Fed-Batch simulation
packages = ["numpy", "matplotlib", "scipy"]
# FedBatchSimulation.py
# Python-Script zur Simulation eines Fed-Batch-Verlaufs
# import benötigter Module
import numpy as np # numpy für Vektoren, Matrizen, usw.
from scipy.integrate import odeint # scipy.integrate zum Lösen von Differentialgleichungen
import matplotlib.pyplot as plt # matplotlib.pyplot zum erstellen der Diagramme
import matplotlib
font = {'size' : 14}
matplotlib.rc('font', **font)
# Parameter
t = np.linspace(0,50,10000) # h Kultivierungsdauer 0 bis 50 h in 10000 Schritten
F_0 = 0.0 # L/h Zuflussrate zu Beginn der Kultivierung
X_0 = 0.02 # g/L Biomasse (Zelltrockenmasse) im Reaktor zu Beginn der Kultivierung
S_0 = 10 # g/L Substratkonzentration im Reaktor zu Beginn der Kultivierung
V_0 = 10 # L Mediumvolumen im Reaktor zu Beginn der Kultivierung
mu_max = 0.5 # 1/h max. biomassespezifische Wachstumsrate
k_S = 0.1 # g/L Substratsättigungskonstanten in Liste []
Yxs = 0.35 # g/g Biomasse-Substrat-Ausbeutekoeffizient
Sf = 300.0 # g/L Substratkonzentration im Feed
startwerte = [X_0, S_0, V_0] # Liste mit Anfangsbedingungen
# Simulation
def F(t): # Funktion (def) zur Berechnung der Zuflussrate F in Abhängigkeit der Kultivierungszeit t (Start nach t > 10 h)
if t>10.7:
f = 0.05
else:
f = F_0
return f
# Funktionen zur Berechnung der Reaktionsraten
def rx(X,S,k_S): # volumetrische Wachstumsrate rx der Biomasse (µ * X) in g pro Liter und Stunde
return mu_max*S/(k_S + S)*X
# Differenzialgleichungen zur Berechnung von dV/dt, dX/dt und dS/dt
def xdot(x,t):
X,S,V = x
dV = F(t)
dX = -F(t)*X/V + rx(X,S,k_S)
dS = F(t)*(Sf-S)/V - rx(X,S,k_S)/Yxs
return [dX,dS,dV]
# Lösen der Differnetialgleichungen
sol = odeint(xdot,startwerte,t)
print(type(sol))
X,S,V = sol.transpose()
# Berechung von mu
mu = S * mu_max/(k_S+ S)
# Ausgabe der Simulationsergebnisse
geometry = {'left':0.09, 'top':0.84, 'right':0.7, 'bottom':0.09, 'hspace':0.2, 'wspace':0.35}
fig, ax = plt.subplots(figsize=(12,7))
fig.subplots_adjust(**geometry)
ax.plot(t,V, '-', label="Volumen", color='gray', alpha=0.5)
ax.plot(t,S, label=r'$c_{\mathrm{S}}\;(\mathrm{g\,L}^{-1})$', color='tab:orange')
ax.set_ylabel(r'$c_{\mathrm{S}}\;(\mathrm{g\,L}^{-1})$')
ax.set_ylim(0,)
ax.set_xlim(0,50)
ax.set_xlabel(r'$t\;(\mathrm{h})$')
ax_biomasse = ax.twinx()
ax_biomasse.plot(t,X, '-', label=r'$c_{\mathrm{X}}\;(\mathrm{g\,L}^{-1})$')
ax_biomasse.set_ylabel(r'$c_{\mathrm{X}}\;(\mathrm{g\,L}^{-1})$')
ax_biomasse.set_ylim(0,)
ax_mu = ax.twinx()
ax_mu.spines.right.set_position(("axes",1.15))
ax_mu.plot(t,mu, '--', label=r'$\mu\;(\mathrm{h}^{-1})$', color='black')
ax_mu.set_ylabel(r'$\mu\;(\mathrm{h}^{-1})$')
ax_mu.set_ylim(0,)
fig.legend()
plt
<