Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.20 KB | None | 0 0
  1. clc
  2.  
  3. clear all
  4.  
  5. %% Hard Sphere Collision Routine by Michael N. Macrossan
  6.  
  7. %function [vx,vy,vz] = HS(vx,vy,vz,plist,badd,N_in);
  8. %global sigdtvol c_in TN_in nsteps gmax % sigdtvol = sigma*dt/vol
  9. %debug = 0; if debug; dbstop if error; end
  10. %Nc = length(badd);
  11. %TN_in = TN_in + N_in; nsteps = nsteps + 1; Nbar = TN_in/nsteps;
  12. %Nsel = floor(0.5*N_in.*Nbar.*gmax*sigdtvol + rand(1,Nc)); % vectorised?
  13. %% note sigma*dt/vol constant = sigdtvol
  14. %for cell = 1:Nc
  15. %N = N_in(cell);
  16. %if N>1 % only for at least 2 particles in cell
  17. %%Nsel = floor(0.5*N*Nbar(cell)*gmax(cell)*sigma*dt/vol + rand); %
  18. %%fractional collision done randomly
  19. %if debug & Nsel(cell)<1
  20. %hs: cell,Nsel ,cell,Nsel(cell)
  21. %N,sigma*dt/vol ,N,sigdtvol
  22. %return
  23. %end
  24. %b0 = badd(cell);
  25. %gm = 0.0; % detects the largest value at each time step
  26. %Ncol = 0;
  27. %if (debug); sumg = 0.0; end
  28. %for sel = 1:Nsel(cell)
  29. %%’ sel = ’,sel
  30. %k1 = ceil(rand*N); % first collision particle
  31. %k2 = k1; while k2 == k1; k2 = ceil(rand*N); end
  32. %p1 = plist(b0 + k1); p2 = plist(b0 + k2);
  33. %gx = vx(p1) - vx(p2); % collision velocity
  34. %gy = vy(p1) - vy(p2); % = rel. velocity
  35. %gz = vz(p1) - vz(p2);
  36. %g = sqrt(gx^2 + gy^2 + gz^2);
  37. %if debug; sumg = sumg + g; end
  38. %gm = max([gm,g]);
  39. %if g/gmax(cell) > rand % accept this pair
  40. %c_in(cell) = c_in(cell) + 1.0;
  41. %if debug; Ncol = Ncol + 1; end
  42. %[vx(p1),vy(p1),vz(p1),vx(p2),vy(p2),vz(p2)] = ...
  43. %newvel(vx(p1),vy(p1),vx(p1),vx(p2),vy(p2),vz(p2),g)
  44. %end % collision
  45. %end % selection
  46. %gmax(cell) = max( [1.1*gm, 0.95*gmax(cell)] );
  47. %% use the latest largest value found, with margin for error.
  48. %% if gmax is decreasing, use smaller value 0.95 factor,
  49. %% but what if low gm found by "chance"?
  50. %end % N > 1
  51. %end % cells
  52. %return
  53.  
  54.  
  55. %% Constant quantities
  56.  
  57. N = 10000; %Number of particles
  58. dt = 1*10^(-5); %time steps (s)
  59. i = 1; % unit vector in x dir.
  60. j = 1; % unit vector in y dir.
  61. k = 1; % unit vector in z dir.
  62. M = 2.21 *10^(-27) % mass of ceasium atom in kg
  63. w = 9.2*10^(7) % angular oscillation frequency of ceasium (Hz)
  64. %B = ; % Space boundary
  65.  
  66. % Cell Parameters
  67. h = 1*10^(-6);
  68. x = h*i;
  69. y = h*j;
  70. z = h*k;
  71. Vc = h^3; %volume of space
  72. cell = x*y*z;
  73.  
  74. % Particle Information
  75. r_init = linspace(0,N,1); %position of each particle
  76. v_init = linspace(0,N,1); %velocity of each particle
  77.  
  78. for i = 0:N
  79. r_new(i) = r_init(i) + v_init(i)*dt
  80.  
  81. %% POTENTIAL
  82.  
  83. U = 0.5*M*(w_x^2 * x^2 + w_y^2 * y^2 + w_z^2 * z^2 )
  84.  
  85. for i = 1:N
  86.  
  87. v_new(i) = (1/M)*U*dt
  88.  
  89.  
  90.  
  91. %% Constant quantities
  92.  
  93. N = 10000; %Number of particles
  94. dt = 1*10^(-5); %time steps (s)
  95. i = 1; % unit vector in x dir.
  96. j = 1; % unit vector in y dir.
  97. k = 1; % unit vector in z dir.
  98. M = 2.21 *10^(-27) % mass of ceasium atom in kg
  99. w = 9.2*10^(7) % angular oscillation frequency of ceasium (Hz)
  100. %B = ; % Space boundary
  101.  
  102. % Cell Parameters
  103. h = 1*10^(-6);
  104. x = h*i;
  105. y = h*j;
  106. z = h*k;
  107. Vc = h^3; %volume of space
  108. cell = x*y*z;
  109.  
  110.  
  111. r_init = linspace(0,N,1); %position of each particle
  112. v_init = linspace(0,N,1); %velocity of each particle
  113.  
  114. for i = 1:N
  115. r_init(i) =
  116. v_init(i) =
  117.  
  118. for i = 1:N
  119. r_new(i) = r_init(i) + v_init(i)*dt
  120.  
  121.  
  122.  
  123. %% POTENTIAL
  124.  
  125. U = 0.5*M*(w_x^2 * x^2 + w_y^2 * y^2 + w_z^2 * z^2 )
  126.  
  127. for i = 1:N
  128.  
  129. v_new(i) = (1/M)*U*dt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement