Produced using MATLAB software CSTR ODE CSTR ODE Page 1 of 52 CSTR ODE CSTR ODE m function iflag main CSTR ODE This MATLAB program calculates the dynanamic concentration and temperature profiles within a continuous stirred tank reactor This program models a CSTR in overflow mode no volume change or if the flow rate is set to zero the model simulates a batch reactor At the moment semi batch reactors with a volume that changes with time is not supported This program uses the MATLAB ODE IVP solver ode15s a multistep method that works well for stiff systems K Beers MIT ChE 10 28 2001 function iflag main CSTR ODE 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 StateInit iflag read program input if iflag 0 iflag main 1 error CSTR ODE 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 StateInit iflag feval file name end We now stack the initial state data into the state vector 7 16 2002 CSTR ODE CSTR ODE Page 2 of 52 x init stack state StateInit ProbDim num species Reactor nonisothermal Then the options for the MATLAB ODE IVP solver are set options odeset RelTol 1e 4 AbsTol 1e 6 Refine 10 Stats on The user is now asked to the length of the time period to be simulated time final prompt Enter final simulation time check real 1 check sign 1 check int 0 time final get input scalar prompt check real check sign check int Now the ODE IVP solver is called t x traj ode15s CSTR ODE calc f 0 time final x init options ProbDim Reactor Inlet Physical Rxn Plot the simulation results for ispecies 1 ProbDim num species figure plot t x traj ispecies title Concentration of species int2str ispecies xlabel time ylabel c int2str ispecies end if Reactor nonisothermal figure plot t x traj ProbDim num species 1 title Reactor Temperature xlabel time ylabel T end Save the results to a binary output file save CSTR ODE results mat iflag main 1 return 7 16 2002 CSTR ODE CSTR ODE Page 3 of 52 CSTR ODE read program input m function ProbDim Reactor Inlet Physical Rxn StateInit iflag read program input This procedure reads in the simulation parameters that are required to define a single CSTR dynamic simulation Kenneth Beers Massachusetts Institute of Technology Department of Chemical Engineering 10 28 2001 Version as of 10 28 2001 function ProbDim Reactor Inlet Physical Rxn StateInit iflag read program input func name read program input iflag 0 disp disp disp Input the system parameters disp The parameters are input in real units where disp L unit of length disp M unit of mass disp t unit of time disp E unit of energy disp T unit of temperature REACTOR DATA PDL Input first the reactor volume and heat transfer data disp disp disp Input the reactor data disp Perform assertion that a real scalar positive number has been entered This is performed by a function assert scalar 7 16 2002 CSTR ODE CSTR ODE Page 4 of 52 that gives first the value and name of the variable the name of the function that is making the assertion and values of 1 for the three flags that tell the assertion routine to make sure the value is real positive and not to check that it is an integer disp disp Reactor size information Reactor volume check real 1 check sign 1 check int 0 prompt Input the volume of the reactor L 3 Reactor volume get input scalar prompt check real check sign check int Reactor F vol check real 1 check sign 1 check int 0 prompt Input volumetric flowrate through reactor L 3 t Reactor F vol get input scalar prompt check real check sign check int Now the user selects whether to perform a non isothermal calculation or to keep the temperature constant at the value of Temp cool Reactor nonisothermal check real 1 check sign 1 check int 2 prompt Simulate isothermal 0 or non isothermal 1 reactor Reactor nonisothermal get input scalar prompt check real check sign check int If operate in isothermal mode only input set temperature if Reactor nonisothermal Reactor Temp cool check real 1 check sign 1 check int 0 prompt Enter the constant reactor temperature Reactor Temp cool get input scalar prompt check real check sign check int We now set the other non needed coolant information to dummy values Reactor F cool 1 Reactor U HT 1 Reactor A HT 1 Reactor Cp cool 1 otherwise if simulating non isothermal reactor input 7 16 2002 CSTR ODE CSTR ODE Page 5 of 52 the data for the coolant jacket else disp disp Reactor coolant information Reactor F cool check real 1 check sign 1 check int 0 prompt Input the coolant flowrate L 3 t Reactor F cool get input scalar prompt check real check sign check int Reactor Temp cool check real 1 check sign 1 check int 0 prompt Input the coolant inlet temperature T Reactor T cool get input scalar prompt check real check sign check int Reactor U HT check real 1 check sign 1 check int 0 prompt Input the jacket heat transfer coefficient E t L 2 T Reactor U HT get input scalar prompt check real check sign check int Reactor A HT check real 1 check sign 1 check int 0 prompt Input the jacket heat transfer area L 2 Reactor A HT get input scalar prompt check real check sign check int Reactor Cp cool check real 1 check sign 1 check int 0 prompt Input the reactor coolant heat capacity E mol T Reactor Cp cool get input scalar prompt check real check sign check int end PDL Input number of species ProbDim num species disp disp ProbDim num species check real 1 check sign 1 check int 1 prompt Input the number of species ProbDim num species get input scalar prompt check real check sign check int 7 16 2002 CSTR ODE CSTR ODE Page 6 of 52 PDL Input inlet properties Inlet conc Inlet Temp and the initial concentrations and temperature within the reactor disp disp disp Input the inlet and initial reactor concentrations mol L 3 and temperature T disp Inlet conc linspace 0 0 ProbDim num species StateInit conc Inlet conc StateInit Temp 0 for ispecies 1 ProbDim num species Inlet conc in ispecies if Reactor F vol check real 1 check sign 2 check int 0 prompt Enter inlet concentration of species int2str ispecies Inlet conc ispecies get input scalar prompt check real check sign check int else Inlet conc ispecies 0 end StateInit conc ispecies check real 1 check sign 2 check int 0 prompt Enter initial reactor concentration of species int2str ispecies StateInit conc ispecies get input scalar prompt check real
View Full Document
Unlocking...