You are on page 1of 9

% This is our input file. It will be used to % request and edit information needed from the user.

% Constants and initializing variables clear, clc %hold on % default number of mesh points %________________________________________________________ % Start Prompt start_box = questdlg(['Welcome to our program! We will need' ... ' some information from you to begin. ' ... 'Click ok to continue.'], ... 'Slab Reactor Analysis', ... 'Continue','Continue'); %________________________________________________________ % Enter original Conditions for an infinite slab reactor check1 = 0; while check1 == 0; prompt = {'What is your neutron source? 1=fission, 2=point source, 3 = distri buted',... 'Point source with reflector? (1 = yes, 0 = no)'}; dlg_title = 'Source Type'; num_lines = 1; def = {'',''}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer = inputdlg(prompt,dlg_title,num_lines,def,options); type = str2double(answer(1)); reflector = str2double(answer(2)); if type == 1 prompt = {'Enter slab thickness (cm):',... % slab thickness 'Enter diffusion coefficient (cm):',... % di ffusion coefficient 'Enter macroscopic absorption cross section (cm^-1):',... % macroscopic absorption cross section 'Enter macroscopic fission cross section (cm^-1):',... 'Enter intial power guess (W/cm^2):',... 'Enter nu value :',... 'Enter k guess'}; % so urce dlg_title = 'Slab Input'; num_lines = 1; def = {'','','','','','',''};

options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer = inputdlg(prompt,dlg_title,num_lines,def,options); slab_thick = str2double(answer(1)); diff_coeff = str2double(answer(2)); abs_cross = str2double(answer(3)); fission_cross = str2double(answer(4)); guess = str2double(answer(5)); nu = str2double(answer(6)); k_guess = str2double(answer(7)); if isnan(slab_thick)==1 || isnan(diff_coeff)==1 || ... isnan(abs_cross)==1 || isnan(fission_cross)==1 ||... isnan(fission_cross) || isnan(guess) || isnan(nu)... || isnan(k_guess) error1 = errordlg('ERROR: Incorrect input. Please try again.',... 'Error1','modal'); waitfor(error1) else check1 = 1; end elseif type == 2 prompt = {'Enter slab thickness (cm):',... % slab thickness 'Enter diffusion coefficient (cm):',... % di ffusion coefficient 'Enter macroscopic absorption cross section (cm^-1):',... % macroscopic absorption cross section 'Enter source (n/cm^3*s):'}; % source dlg_title = 'Slab Input'; num_lines = 1; def = {'','','',''}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer = inputdlg(prompt,dlg_title,num_lines,def,options); slab_thick = str2double(answer(1)); diff_coeff = str2double(answer(2)); abs_cross = str2double(answer(3)); source = str2double(answer(4)); % % % % % % % % % if isnan(slab_thick)==1 || isnan(diff_coeff)==1 || ... isnan(abs_cross)==1 || isnan(fission_cross)==1 ||... isnan(fission_cross) || isnan(guess) || isnan(nu)... || isnan(k_guess) error1 = errordlg('ERROR: Incorrect input. Please try again.',... 'Error1','modal'); waitfor(error1) else check1 = 1; end elseif type == 3 prompt = {'Enter slab thickness (cm):',...

% slab thickness 'Enter diffusion coefficient (cm):',... % di ffusion coefficient 'Enter macroscopic absorption cross section (cm^-1):',... % macroscopic absorption cross section 'Enter source (n/cm^3*s):'}; % source dlg_title = 'Slab Input'; num_lines = 1; def = {'','','',''}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer = inputdlg(prompt,dlg_title,num_lines,def,options); slab_thick = str2double(answer(1)); diff_coeff = str2double(answer(2)); abs_cross = str2double(answer(3)); source = str2double(answer(4)); if isnan(slab_thick)==1 || isnan(diff_coeff)==1 || ... isnan(abs_cross)==1 || isnan(source)==1 error1 = errordlg('ERROR: Incorrect input. Please try again.',... 'Error1','modal'); waitfor(error1) else check1 = 1; end end end num_mesh = 31; %________________________________________________________ if reflector == 1 prompt = {'Enter reflector diffusion coefficient (cm):',... 'Enter reflector macroscopic absorption cross section (cm^-1):' ,... 'Enter reflector thickness (cm):',... 'Enter source of reflector (0 if no source,n/cm^3*s):'}; % source dlg_title = 'Slab Input'; num_lines = 1; def = {'','','',''}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer = inputdlg(prompt,dlg_title,num_lines,def,options); reflector_d_coeff = str2double(answer(1)); reflector_abs_cross = str2double(answer(2)); reflector_thickness = str2double(answer(3)); source_ref = str2double(answer(4)); end % Calculations from original conditions delta_x = slab_thick/(num_mesh-1); x = zeros(1,num_mesh)';

diff_length = sqrt(diff_coeff/abs_cross); a_adj = slab_thick/2.0 + 2*diff_coeff; %________________________________________________________ % Analytical solution for i = 1:num_mesh % space vector x(i) = (-0.5*slab_thick + delta_x*(i-1)); end if type == 1 % fission source phi1 = pi*guess/(2*slab_thick*3.2e-11*fission_cross)*cos(pi*x/slab_thick); elseif type == 2 % point source phi1 = (diff_length/(2.0*diff_coeff))*(sinh((a_adj-2.0*abs(x))/... (2.0*diff_length))/(cosh(a_adj/(2.0*diff_length))))*source; elseif type == 3 % distributed source phi1 = (diff_length/(2.0*diff_coeff))*(sinh((a_adj-2.0*abs(x))/... (2.0*diff_length))/(cosh(a_adj/(2.0*diff_length))))*source; end phi_original = phi1; % set phi_original

%________________________________________________________ % Iterative Calculations for phi A = zeros(num_mesh,num_mesh); D = zeros(num_mesh,num_mesh); B = zeros(num_mesh,num_mesh); M = delta_x*delta_x*diff_coeff+abs_cross; S1 = zeros(1,num_mesh)'; S2 = zeros(1,num_mesh)'; phi2 = zeros(1,num_mesh)'; if type == 1 F = nu*fission_cross; S1 = F*phi1; k1 = k_guess; end geometry = 0; check2 = 0; num = 0; while check2 == 0 num = num + 1;

% pg 181

if type == 1

% fission source

for i = 1:num_mesh S1(i) = phi1(i)*F; phi2(i) = S1(i)./(k1*M); S2(i) = F.*phi2(i); k2 = k1*sum(S2*delta_x)/sum(S1*delta_x) ; end

compare1 = abs((S2(16)-S1(16))/S2(16)); compare2 = abs((k2-k1)/k1); % maximum = max(abs(compare)); phi1 = phi2; S1 = S2; k1 = k2; % num maximum if compare1 <= 0.00000001 && compare2 <= 0.000000001 check2 = 1; end

elseif type == 2

% point source

diff_coeff_vect = zeros(1,num_mesh)'; for i = 1:num_mesh diff_coeff_vect(i) = diff_coeff; end if reflector == 1 diff_coeff_vect(1:reflector_thickness+1) = reflector_d_coeff; diff_coeff_vect(2) = reflector_d_coeff; diff_coeff_vect(3) = reflector_d_coeff; diff_coeff_vect(4) = reflector_d_coeff; diff_coeff_vect(5) = reflector_d_coeff; diff_coeff_vect(num_mesh-reflector_thickness:num_mesh) = reflector_d diff_coeff_vect(num_mesh diff_coeff_vect(num_mesh diff_coeff_vect(num_mesh diff_coeff_vect(num_mesh end abs_cross_vect = zeros(1,num_mesh)'; for i = 1:num_mesh abs_cross_vect(i) = abs_cross; end if reflector == 1 abs_cross_vect(1:reflector_thickness+1) = reflector_abs_cross; abs_cross_vect(2) = reflector_d_coeff; abs_cross_vect(3) = reflector_d_coeff; abs_cross_vect(4) = reflector_d_coeff; abs_cross_vect(5) = reflector_d_coeff; abs_cross_vect(num_mesh-reflector_thickness:num_mesh) = reflector_ab abs_cross_vect(num_mesh abs_cross_vect(num_mesh abs_cross_vect(num_mesh abs_cross_vect(num_mesh end for i = 1:num_mesh for j = 1:num_mesh value = j - i; switch value 1) 2) 3) 4) = = = = reflector_d_coeff; reflector_d_coeff; reflector_d_coeff; reflector_d_coeff; 1) 2) 3) 4) = = = = reflector_d_coeff; reflector_d_coeff; reflector_d_coeff; reflector_d_coeff;

% % % % _coeff; % % % %

% % % % s_cross; % % % %

case -1 A(i,j) = (1.0*diff_coeff_vect(i)./(delta_x^2))*(1 - ... % geometry = 0, 1, 2 (slab, cylinder, sphere) (geometry/(2.0*i - 1))); case 0 A(i,j) = 2.0*diff_coeff_vect(i)./(delta_x^2) + abs_cross _vect(i); case 1 A(i,j) = (1.0*diff_coeff_vect(i)./(delta_x^2))*(1 + ... (geometry/(2.0*i - 1))); otherwise A(i,j) = 0; end end end D = zeros(num_mesh,num_mesh); B = zeros(num_mesh,num_mesh); for i = 1:num_mesh for j = 1:num_mesh; D(i,i) = A(i,i); if i == j B(i,j)=0; else B(i,j) = A(i,j); end end end D_inv = inv(D); % % % % % % % % % S = zeros(1,num_mesh)'; zero_spot = (num_mesh+1)/2; S(zero_spot) = source; for i = 1:num_mesh S(i) = source./1.0; end % source

S(6) = source; S(11) = source; S(16) = source; S(21) = source; S(26) = source; if reflector == 1 S(1:reflector_thickness+1) = source_ref; S(num_mesh-reflector_thickness:num_mesh) = source_ref; end phi2 = D_inv*B*phi1 + D_inv*S; % phi2 calc compare = phi2 - phi1; maximum = max(abs(compare)); num = num + 1; num maximum if maximum <= 0.000000000001*phi2(16) check2 = 1; end phi1 = phi2;

elseif type == 3

% distributed source

diff_coeff_vect = zeros(1,num_mesh)'; for i = 1:num_mesh diff_coeff_vect(i) = diff_coeff; end if reflector == 1 diff_coeff_vect(1:reflector_thickness+1) = reflector_d_coeff; diff_coeff_vect(2) = reflector_d_coeff; diff_coeff_vect(3) = reflector_d_coeff; diff_coeff_vect(4) = reflector_d_coeff; diff_coeff_vect(5) = reflector_d_coeff; diff_coeff_vect(num_mesh-reflector_thickness:num_mesh) = reflector_d diff_coeff_vect(num_mesh diff_coeff_vect(num_mesh diff_coeff_vect(num_mesh diff_coeff_vect(num_mesh end abs_cross_vect = zeros(1,num_mesh)'; for i = 1:num_mesh abs_cross_vect(i) = abs_cross; end if reflector == 1 abs_cross_vect(1:reflector_thickness+1) = reflector_abs_cross; abs_cross_vect(2) = reflector_d_coeff; abs_cross_vect(3) = reflector_d_coeff; abs_cross_vect(4) = reflector_d_coeff; abs_cross_vect(5) = reflector_d_coeff; abs_cross_vect(num_mesh-reflector_thickness:num_mesh) = reflector_ab abs_cross_vect(num_mesh abs_cross_vect(num_mesh abs_cross_vect(num_mesh abs_cross_vect(num_mesh end for i = 1:num_mesh for j = 1:num_mesh value = j - i; switch value case -1 A(i,j) = (1.0*diff_coeff/(delta_x^2))*(1 - ... % geometr y = 0, 1, 2 (slab, cylinder, sphere) (geometry/(2.0*i - 1))); case 0 A(i,j) = 2.0*diff_coeff/(delta_x^2) + abs_cross; case 1 A(i,j) = (1.0*diff_coeff/(delta_x^2))*(1 + ... (geometry/(2.0*i - 1))); otherwise A(i,j) = 0; end end end 1) 2) 3) 4) = = = = reflector_d_coeff; reflector_d_coeff; reflector_d_coeff; reflector_d_coeff; 1) 2) 3) 4) = = = = reflector_d_coeff; reflector_d_coeff; reflector_d_coeff; reflector_d_coeff;

% % % % _coeff; % % % %

% % % % s_cross; % % % %

for i = 1:num_mesh for j = 1:num_mesh; D(i,i) = A(i,i); if i == j B(i,j)=0; else B(i,j) = A(i,j); end end end D_inv = inv(D); S = zeros(1,num_mesh)'; zero_spot = (num_mesh+1)/2; S(zero_spot) = source; for i = 1:num_mesh S(i) = source./1.0; end % source

% %

if reflector == 1 S(1:reflector_thickness+1) = source_ref; S(num_mesh-reflector_thickness:num_mesh) = source_ref; end

phi2 = D_inv*B*phi1 + D_inv*S; compare = phi2 - phi1; maximum = max(abs(compare)); num = num + 1; num maximum if maximum <= 0.001*phi2(16) check2 = 1; end phi1 = phi2; end end % plot(x,phi_original) % hold on plot(x,phi2,'-.b*')

% phi2 calc

if type == 1 start_box = questdlg(['The k effective was calculated to be: ', num2str(k2)] , ... 'k Effective', ... 'Continue','Continue'); end %________________________________________________________

% Calculate k %________________________________________________________

% intergral for k 1 % %________________________________________________________

You might also like