% Pressure transient detected at location z along beam tube
% after impulsive injection of gas at (t,z) = (0,0)
% MEZ 7/21/2012

% Q = 2e-4*.001*sqrt(28/4); % injection leak rate [torr * m^3/s]
Q = .02 * .001/30.; % injection leak rate [torr * m^3/s]
W = 30.;        % duration of injection in [s]
R = 0.6 ;       % radius of beam tube [m]
m = 4   ;       % molecular weight [AMU]
temp = 300;     % temperature [K] 
v = 1197*sqrt(temp/273)*sqrt(4/m); % mean molecular velocity [m/s]
D = (2/3)*R*v ; % diffusion constant for capillary radius R [m^2/s]
G = Q*W/(2*pi^(3/2)*R^2); % prefactor
%
%
% plot time series at various distances from injection
z= [0:20:200];    % length domain [m] 
t= [.01:.01:100];  % time domain [s]
p = zeros(length(t),length(z)); % set up array on domains
for n = 1:length(t)
    tt=t(n)  ;
    p(n,:) = (G/sqrt(D*tt)) * exp(-z.^2/(4*D*tt));
end
figure(1);
loglog(t,p(:,:)); 
ylim([1e-10  1e-6]);
legend(strcat(num2str(z(:)), ' m'), 'location','NorthEastOutside');
title(['Pressure due to ', ...
    num2str(Q*W*1000), ... 
    ' torr-liter impulsive He injection at t=0'], 'FontSize', 12);
xlabel('Time (seconds)');
ylabel('Pressure (torr)');
%
% plot pressure profile at various times
z= [0:1:100];    % length domain [m] 
t= [.001:1:10];      % time domain [s]
p = zeros(length(t),length(z)); % set up array on domains
for n = 1:length(t)
    tt=t(n)  ;
    p(n,:) = (G/sqrt(D*tt)) * exp(-z.^2/(4*D*tt));
end
figure(2);
semilogy(z(:),p(:,:));
% plot(z(:),p(:,:));
ylim([1e-9  1e-6]);
xlim([0 100]);
% legend(num2str(t(:)), 'location','NorthEastOutside');
title(['Pressure profile at 1 second intervals due to  ', ...
    num2str(Q*W*1000), ... 
    ' torr-liter injection at t=0'], 'FontSize', 12);
xlabel('Distance (m)');
ylabel('Pressure (torr)');




