# -*- coding: utf-8 -*-
# 3.0
#
import chemengdstool
#FUNCTIONS
# chemengdstool(functions='dx1/dt=q*(1-x1)-x1*exp(x3/(1+x3/27.85))*0.06,dx2...(x4-x3),dx4/dt=10*(qc*(-1-x4)+0.78*0.952*(x4-x3))',\
# parameters='qc=0.6,q=3.9', initialvalues='x1=0,x2=0.11,x3=65.66,x4=346', freeparameter='q', steps=370, \
# display_x='q', display_y='x2', stepsize=0.10000000000000001, minstepsize=0.01, maxstepsize=1, showstability=False,\
# xlabel='q', ylabel='x2', title='x2-q', direction='forward', locbiftype='All', exportMatlabData=False)
# The chemengdstool is the tool for analysis dynamic system by analying the differential equations.
# Here the chemengdstool use A-B-C CSTR reactor as default study system.
#
# chemengdstool(functions,parametervalues,initialvalues,freeparameter,steps,display_x,display_y,
# stepsize, minstepsize, maxstepsize, showstability, xlabel, ylabel, title,
# direction, locbiftype, exportMatlabData)
# functions: the differential equation of dynamic system
# parametervalues: the parameter values
# initialvalues: the initial values of state variables
# freeparameter: the free parameter that varis when system is studying
# steps: steps of calulations, usually is the number of points
# display_x: the variable in figure of x axis
# display_y: the variable in figure of y axis
#
# Default parameters as follow:
#
# l_functions='dx1/dt=q*(1-x1)-x1*exp(x3/(1+x3/27.85))*0.06,dx2/dt=q*(0-x2)+x1*exp(x3/(1+x3/27.85))*0.06-\
# x2*0.06*exp(0.32*x3/(1+x3/27.85))*1.015,dx3/dt=q*(0-x3)+8*0.06*(x1*exp(x3/(1+x3/27.85))+\
# 0.19*x2*1.015* exp(0.32*x3/(1+x3/27.85)))+0.78*(x4-x3),dx4/dt=10*(qc*(-1-x4)+0.78*0.952*(x4-x3))'
# l_parameters='qc=0.6,q=3.9'
# l_initialvalues='x1=0,x2=0.11,x3=65.66,x4=346'
# l_freeparameters='q'
# l_steps=370
# l_display_x='q'
# l_display_y='x2'
#
# chemengdstool(functions=l_functions,parameters=l_parameters,initialvalues=l_initialvalues,
# freeparameter=l_freeparameters,steps=l_steps,display_x=l_display_x,display_y=l_display_y,
# stepsize=0.1,minstepsize=0.01,maxstepsize=1,showstability=False,
# xlabel=l_display_x,ylabel=l_display_y,title=l_display_y+'-'+l_display_x,direction='forward',locbiftype='All',exportMatlabData=False):
chemengdstool.chemengdstool()
#
import chemengdstool
#The code of of the Anaerobic Fermentor system
functions='dx/dt=x*(y/(y+0.00014)*(1-y)*(1-z)-d),dy/dt=d*(y0-y)-x*0.1306*(0.0286+2.3929*y/(y+0.00014)*(1-y)*(1-z)+y/(y+0.01)),dz/dt=x*0.8955*(0.0083+0.5583*y/(y+0.00014)*(1-y)*(1-z)+y/(y+0.025))-z*d'
parameters='d=0.6,y0=0.0104'
initialvalues='x=0.03158,y=0.00022,z=0.01659'
freeparameter='y0'
display_y='z'
display_x='y0'
steps=174
chemengdstool.chemengdstool(functions,parameters,initialvalues,freeparameter,steps,display_x,display_y,1e-3,1e-4,1e-2,True,'Dimensionless substrate feed concentration y0','Dimensionless product concentration z','d=0.6')
#
import chemengdstool
#The Code of the MMA Polymerization Reactor
functions='dCm/dt=-0.3531044406e4*(0.177e10*exp(-0.2199061823e4/T)+0.10067e16*exp(-0.8958142892e4/T))*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))+0.1e2*F*(0.64678e1-Cm),dCI/dt=-0.3792e19*CI*exp(-0.1548833293e5/T)+0.80e2*FI-0.1e2*F*CI,dT/dt=0.2085721876e15*exp(-0.2199061823e4/T)*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))-0.8314087760e1*T+0.8314087760e1*Tj+0.1e2*F*(Tin-T),dD0/dt=0.4160432571e19*CI*exp(-0.1548833293e5/T)+0.3554702404e19*exp(-0.8958142892e4/T)*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))-0.1e2*F*D0,dD1/dt=0.3535281659e6*(0.177e10*exp(-0.2199061823e4/T)+0.10067e16*exp(-0.8958142892e4/T))*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))-0.1e2*F*D1,dTj/dt=0.5000000000e2*Fcw*(0.2932e3-Tj)+0.1714285714e2*T-0.1714285714e2*Tj'
parameters = 'F=1.0,FI=0.0032,Fcw=0.1588,Tin=350'
initialvalues='Cm=6.44280,CI=0.00041,T=338.825,D0=0.00003,D1=2.50255,Tj=324.382'
freeparameter='FI'
display_x='FI'
display_y='T'
stepsize=1
minstepsize=0.1
maxstepsize=10
steps=74
chemengdstool.chemengdstool(functions,parameters,initialvalues,freeparameter,steps,display_x,display_y,stepsize,minstepsize,maxstepsize,True,'Initiator volumetric flowrate FI (m3/h)','Temperature T (K)','Fcw=0.1588')
#
import chemengdstool
#The Code of the MMA Polymerization Reactor
functions='dCm/dt=-0.3531044406e4*(0.177e10*exp(-0.2199061823e4/T)+0.10067e16*exp(-0.8958142892e4/T))*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))+0.1e2*F*(0.64678e1-Cm),dCI/dt=-0.3792e19*CI*exp(-0.1548833293e5/T)+0.80e2*FI-0.1e2*F*CI,dT/dt=0.2085721876e15*exp(-0.2199061823e4/T)*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))-0.8314087760e1*T+0.8314087760e1*Tj+0.1e2*F*(Tin-T),dD0/dt=0.4160432571e19*CI*exp(-0.1548833293e5/T)+0.3554702404e19*exp(-0.8958142892e4/T)*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))-0.1e2*F*D0,dD1/dt=0.3535281659e6*(0.177e10*exp(-0.2199061823e4/T)+0.10067e16*exp(-0.8958142892e4/T))*Cm*sqrt(CI*exp(-0.1548833293e5/T)/exp(-0.3541255713e3/T))-0.1e2*F*D1,dTj/dt=0.5000000000e2*Fcw*(0.2932e3-Tj)+0.1714285714e2*T-0.1714285714e2*Tj'
#4.534351 0.003321 399.647745 0.058087 193.576934 365.951620 2.113005
parameters = 'F=0.0085,FI=0.0032,Fcw=0.1588,Tin=350'
initialvalues='Cm=3.7358,CI=3.0046,T=297.8348,D0=0.004,D1=273.5261,Tj=296.3677'
#parameters = 'F=1.0,FI=0.0001,Fcw=0.1588,Tin=350'
#initialvalues='Cm=6.44280,CI=0.00041,T=338.825,D0=0.00003,D1=2.50255,Tj=324.382'
freeparameter='F'
display_x='F'
display_y='T'
stepsize=1
minstepsize=0.1
maxstepsize=5
steps=269
chemengdstool.chemengdstool(functions,parameters,initialvalues,freeparameter,steps,display_x,display_y,stepsize,minstepsize,maxstepsize,True,'Initiator volumetric flowrate FI (m3/h)','Temperature T (K)','Fcw=0.1588',direction='backward',locbiftype='LP')
#
import chemengdstool
functions='dT1/dt=0.1000000000e1*F0*(0.3000e3-T1)+0.1000000000e1*Fr*(T2-T1)+0.6493506495e9*exp(-0.6013952369e4/T1)*CA1+0.1376623377e9*exp(-0.9057012268e4/T1)*CA1,dCA1/dt=0.1000000000e1*F0*(CA0-CA1)+0.1000000000e1*Fr*(CA2-CA1)-0.30e7*exp(-0.6013952369e4/T1)*CA1-0.60e6*exp(-0.9057012268e4/T1)*CA1,dCB1/dt=0.1000000000e1*F0*(CB0-CB1)+0.1000000000e1*Fr*(CB2-CB1)+0.30e7*exp(-0.6013952369e4/T1)*CA1,dT2/dt=0.3333333333e0*(F0+Fr)*(T1-T2)+0.3333333333e0*F3*(0.3000e3-T2)+0.6493506495e9*exp(-0.6013952369e4/T2)*CA2+0.1376623377e9*exp(-0.9057012268e4/T2)*CA2,dCA2/dt=0.3333333333e0*(F0+Fr)*(CA1-CA2)+0.3333333333e0*F3*(CA03-CA2)-0.30e7*exp(-0.6013952369e4/T2)*CA2-0.60e6*exp(-0.9057012268e4/T2)*CA2,dCB2/dt=0.3333333333e0*(F0+Fr)*(CB1-CB2)+0.3333333333e0*F3*(CB03-CB2)+0.30e7*exp(-0.6013952369e4/T2)*CA2'
#parameters= 'F0=4.998,F3=30,Fr=34.998,CA0=4,CA03=2'
#initialvalues= 'T1=839,CA1=0.0086,T2=792,CA2=0.013'
#label = H , x = ( 1166.554837 0.000000 3.941944 1166.554837 0.000000 3.941944 0.000000 )
#parameters= 'F0=0.01,F3=0,Fr=40,CA0=4,CA03=2,CB0=0,CB03=0'
#initialvalues= 'T1=1166.554837,CA1=0.01,CB1=3.9,T2=1166.554837,CA2=0.01,CB2=3.9'
#label = H , x = ( 1382.881351 -0.996416 4.888148 1116.703583 0.232372 3.675260 -7901.930268 )
#parameters= 'F0=-7901.930268,F3=0,Fr=0,CA0=4,CA03=2,CB0=0,CB03=0'
#initialvalues= 'T1=1382.881351,CA1=-0.996416,CB1=4.888148,T2=1116.703583,CA2=0.232372,CB2=3.675260'
parameters='F0=15.6464,F3=0,Fr=0,CA0=4,CA03=2,CB0=0,CB03=0'
initialvalues= 'T1=1165.7795,CA1=0.0036,CB1=3.9385,T2=1166.5533,CA2=0,CB2=3.942'
display_x='F0'
display_y='CB2'
steps=400
freeparameter='F0'
chemengdstool.chemengdstool(functions,parameters,initialvalues,freeparameter,steps,display_x,display_y,0.1,0.0000001,10,True,'F0','CB2','F3=0,Fr=0,CA0=4,CA03=2','forward','LP')
#