## This file simulates cell growth in a CSTR on a single limiting substrate.
## Specific growth rate is represented as a function of substrate concentration.
## Starting with initial conditions, it displays the transient system dynamics.
## Variables
var('mu Y K_m mu_max X_in S_in V_in V_out X_0 S_0')
(X,S,t) = var('X,S,t')
## Adjustable Parameters
mu_max = 0.05
Y = 0.5
K_m = 2
X_in = 0
S_in = 10
V_in = 0.01
V_out = 0.01
X_0 = 0.1
S_0 = 10
## Calculation Parameters
end_points = 250
stepsize = 1
steps = end_points/stepsize
ics = [0,X_0,S_0]
## Equations
mu = (mu_max*S)/(K_m+S)
cells = (diff(X,t) == mu*X+X_in*V_in-X*V_out)
substrate = (diff(S,t) == -(1/Y)*mu*X+S_in*V_in-S*V_out)
## Take the right-hand side of each equation and the calc parameters
## Find the solution to the initial-value problem
des = [cells.rhs(), substrate.rhs()] ##takes the right-hand side of each equation
sol = desolve_system_rk4(des, [X,S], ics, ivar=t, end_points=end_points,step=stepsize)