# Use of Optimica to run generalized formulation of the bottle-neck model typical for FBA. # Follow manual 1.17 pg 60 and on # Framework import matplotlib.pyplot as plt import numpy as np from pymodelica import compile_fmu from pyjmi import transfer_optimization_problem # Transfer problem to CasADi Interface, which is used for estimation op = transfer_optimization_problem('FBA.Reactor', 'fba1b.mop') # Set optimization options and optimize opts = op.optimize_options() opts['n_e'] = 60 # Number of collocation elements opts['IPOPT_options']['mumps_mem_percent']=500 # Solve problem res_opt = op.optimize(options=opts) # Load and plot optimized profiles t = res_opt['time'] G = res_opt['G'] E = res_opt['E'] X = res_opt['X'] qGr = res_opt['qGr'] qEr = res_opt['qEr'] qO2 = res_opt['qO2'] mu = res_opt['mu'] kog = 2.3; koe = 1.6; YGr = 3.5; YEr = 1.32; MwX = 24.6; # Plot figures plt.figure() plt.subplot(2,1,1) plt.title('Batch cultivation - using Optimica to maximize cell growth') plt.plot(t,G,'b') plt.plot(t,E,'r') plt.grid() plt.legend(['G','E']) plt.ylabel('G and E [g/L]') plt.subplot(2,1,2) plt.plot(t, X,'b-') plt.grid() plt.ylabel('X [g/L]') plt.xlabel('Time [h]') plt.show() plt.figure() plt.subplot(3,1,1) plt.title('Batch cultivation - using Optimica to maximize cell growth') plt.plot(t,MwX*mu,'b') plt.plot(t,MwX*YGr*qGr,'b--') plt.plot(t,MwX*YEr*qEr,'r--') plt.grid() plt.legend(['mu','qGr','qEr']) plt.ylabel('mu') plt.subplot(3,1,2) plt.plot(t,qEr,'r') plt.grid() plt.ylabel('qEr') plt.subplot(3,1,3) plt.plot(t,qO2) plt.plot(t,kog*qGr,'b--') plt.plot(t,koe*qEr,'r--') plt.grid() plt.legend(['qO2','qGr','qEr']) plt.axis([0,10,-0.001,0.008]) plt.ylabel('qO2') plt.xlabel('Time [h]') plt.show()