Produced using MATLAB software MATLAB Files for General CSTR Reactor Model Page 1 of 35 MATLAB Files for General CSTR Reactor Model These program comprised by these files calculates the steady state concentrations and temperatures within a CSTR at steady state for a reaction network of arbitrary complexity In addition to the files listed below this program requires the following subroutines for the input and checking of data found in the MATLAB tutorial located on the 10 34 homepage get input scalar m assert scalar m assert vector m assert matrix m assert structure m File CSTR SS F vol scan m This program calculates the steady state concentrations and temperature as a function of the volumetric flow rate through the reactor and makes the appropriate plots CSTR SS CSTR SS F vol scan m function iflag main CSTR SS F vol scan m This MATLAB program calculates the steady state concentration and temperature at steady state within a continuous stirred tank reactor in overflow mode The model is written to support an arbitarily complex reaction network First a function is called that reads in the reactor geometry and reaction data from the keyboard Then program calls the built in MATLAB nonlinear equation solver FSOLVE to solve the set of model equations for the unknown concentrations and temperature This program repeats the calculation for multiple values of the inlet flow rate and plots the results K Beers MIT ChE 10 20 2001 function iflag main CSTR SS F vol scan iflag main 0 7 16 2002 MATLAB Files for General CSTR Reactor Model Page 2 of 35 First read in the problem definition data from the keyboard or from an input file imode input input Select mode of input 0 keyboard 1 file if imode input ProbDim Reactor Inlet Physical Rxn iflag read program input if iflag 0 iflag main 1 error CSTR SS Error returned from read program input int2str iflag end else file name input Enter input file name without m s ProbDim Reactor Inlet Physical Rxn iflag feval file name end We ask the user to input the range over which to plot the solution as a function of the volumetric flowrate check real 1 check sign 2 check int 0 prompt Enter min Reactor F vol for scan F vol min get input scalar prompt check real check sign check int check real 1 check sign 2 check int 0 prompt Enter max Reactor F vol for scan F vol max get input scalar prompt check real check sign check int num grid 50 Ask user whether to use logarithmic or linear scale check real 1 check sign 2 check int 1 prompt Use linear 0 or logarithmic 1 x axis for plot i use log get input scalar prompt check real check sign check int if i use log F vol grid logspace log10 F vol min log10 F vol max num grid else F vol grid linspace F vol min F vol max num grid end We begin our simulation at the maximum volumetric flowrate 7 16 2002 MATLAB Files for General CSTR Reactor Model Page 3 of 35 because this gives the smallest conversion of product and thus the reactor concentrations and temperature are likely to be near those of the outlet This gives us a natural guess for the first simulation Guess Inlet We set the convergence parameters for the MATLAB nonlinear equation solver options optimset TolFun 1e 8 Display off LargeScale off Next we allocate space to store the results of each calculation State plot conc zeros ProbDim num species num grid State plot Temp linspace 0 0 num grid for iter 1 num grid igrid num grid iter 1 Reactor F vol F vol grid igrid We now stack the guess data into the state vector x guess stack state Guess ProbDim num species Next the MATLAB nonlinear equation solver is invoked to solve for the unknown concentrations and temperature If the calculation does not converge the user is asked to input a new guess exitflag 0 while exitflag 0 x state fval exitflag output fsolve CSTR SS calc f x guess options ProbDim Reactor Inlet Physical Rxn if exitflag 0 break end disp CSTR SS F vol scan fsolve did not converge Reactor F vol x guess x state fval ichoose input Stop 0 retry with old result 1 with new guess 2 if ichoose error CSTR SS F vol scan Stopped calculation elseif ichoose 1 x guess x state else Guess conc input Enter new guess of concentration vector Guess Temp input Enter new guess of temperature 7 16 2002 MATLAB Files for General CSTR Reactor Model Page 4 of 35 x guess stack state Guess ProbDim num species end end Unstack and store the results for later plotting list neg find x state 0 for count 1 length list neg k list neg count x state k 0 end State unstack state x state ProbDim num species State plot conc igrid State conc State plot Temp igrid State Temp Use the results of this calculation as an estimate of the solution for the next value of the flowrate Guess State end Now make plots of each concentration and temperature as a function of the volumetric flowrate through the reactor for ispecies 1 ProbDim num species figure if i use log semilogx F vol grid State plot conc ispecies else plot F vol grid State plot conc ispecies end title CSTR model Effect of F vol on conc of species int2str ispecies xlabel F vol Volumetric Flowrate ylabel c int2str ispecies end figure if i use log semilogx F vol grid State plot Temp else plot F vol grid State plot Temp end title CSTR model Effect of F vol on temperature xlabel F vol Volumetric Flowrate ylabel T 7 16 2002 MATLAB Files for General CSTR Reactor Model Page 5 of 35 Save the results to a binary output file save CSTR SS results mat iflag main 1 return 7 16 2002 MATLAB Files for General CSTR Reactor Model Page 6 of 35 File CSTR SS m This program calculates the steady state concentrations and temperature for a single simulation CSTR SS CSTR SS m function iflag main CSTR SS m This MATLAB program calculates the steady state concentration and temperature at steady state within a continuous stirred tank reactor in overflow mode The model is written to support an arbitarily complex reaction network First a function is called that reads in the reactor geometry and reaction data from the keyboard Then program calls the built in MATLAB nonlinear equation solver FSOLVE to solve the set of model equations for the unknown concentrations and temperature K Beers MIT ChE 10 20 2001 function iflag main CSTR SS iflag main 0 First read in the problem definition data from the keyboard or from an input file imode input input Select mode of input 0 keyboard 1 file if imode input ProbDim Reactor Inlet Physical Rxn iflag read program input if iflag 0 iflag main 1 error CSTR SS Error returned from read program input
View Full Document
Unlocking...