generating random particles in a cylinder
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Denisse Campos Muñoz
2016-2-17
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?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!