generating random particles in a cylinder
Mostrar comentarios más antiguos
I am trying to generate random particles in a cylinder corresponds to a finite volume fraction. Therefore, each volume fraction results in different number of particles. But, as volume fraction increases, say number of particles increases, the simulation time increases dramatically. For example, for 1100 particles (about volume fraction equal to 0.3) it takes just a minute to generate them in a way that they maintain within the cylinder boundaries and also do not overlap. However, if I want 1400 particles corresponds to volume fraction 0.4 it took about 24 hours and still not finished. Any suggestion is appreciated. The code is as below;
vol_frac=0.400831;
lz=0.04;
lx=lz;ly=lx;
x(1)=(2*lz-2*R)*rand(1)-lz+R;
y(1)=(2*sqrt(lz^2-x(1)^2)-2*R)*rand(1)-sqrt(lz^2-x(1)^2)+R;
z(1)=(2*lz-2*R)*rand(1)-lz+R;
%no. of particles
Npart=round(6*0.08^3*vol_frac/4/0.006^3);
%Npart=1100;
for i=2:Npart;
x(i)=(2*lz-2*R)*rand(1)-lz+R;
y(i)=(2*sqrt(lz^2-x(i)^2)-2*R)*rand(1)-sqrt(lz^2-x(i)^2)+R;
z(i)=(2*lz-2*R)*rand(1)-lz+R;
k=i-1;
while k>=1;
c=((y(k)-y(i))^2+(x(k)-x(i))^2+(z(k)-z(i))^2)^0.5;
if c<=2*R
x(i)=(2*lz-2*R)*rand(1)-lz+R;
y(i)=(2*sqrt(lz^2-x(i)^2)-2*R)*rand(1)-sqrt(lz^2-x(i)^2)+R;
z(i)=(2*lz-2*R)*rand(1)-lz+R;
k=i-1;
else
k=k-1;
end
end
end
7 comentarios
Image Analyst
el 11 de Jun. de 2015
What is R, and is it a constant? Please add comments. Also you should know that typing control-i in the MATLAB editor will fix up the indenting so that when you paste it in here, it does not look all messed up like it does now.
hamed
el 11 de Jun. de 2015
Guillaume
el 12 de Jun. de 2015
The issue is not with rand which does generate uniformly distributed numbers but most likely with your mapping from a cube (which is what is generated by rand) to a cylinder.
Can you comment your code? Explain each equation and particularly the purpose of the while loop. Also which direction is the axis of the cylinder?
I would hope that x, y and z have been predeclared with zero. Otherwise, the resizing / copying with each iteration of the for loop would be a reason for slowdowns.
hamed
el 14 de Jun. de 2015
Denisse Campos Muñoz
el 17 de Feb. de 2016
I used your code to generating particles in cylindrical coordinates and that these follow uniform distribution using random ('unif', ..., ...) and would like to know how to graph the particles.
How I can plot the distributed along the center of each particle?
Respuestas (0)
Categorías
Más información sobre Probability Distributions and Hypothesis Tests en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

