DOC PREVIEW
MIT 10 34 - Lecture Notes

This preview shows page 1-2-16-17-18-34-35 out of 35 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

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/2002MATLAB 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/2002MATLAB 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/2002MATLAB 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/2002MATLAB 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/2002MATLAB 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


View Full Document

MIT 10 34 - Lecture Notes

Documents in this Course
Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?