generating random particles in a cylinder

2 Ansichten (letzte 30 Tage)
hamed
hamed am 11 Jun. 2015
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 Kommentare
hamed
hamed am 14 Jun. 2015
I'm still not getting appropriate answer. I think the problem is due to random number rejection by overlapping check which results in predictable random numbers. However, I have revised the previous code due to mapping like this and becomes faster;
%Initial random position of particles (Normal distribution)
vol_frac=0.400831;
%no. of particles
rng shuffle
% Npart=1100;
R=0.003;
Npart=round(6*0.08^3*vol_frac/4/0.006^3);
x=zeros(1,Npart);y=zeros(1,Npart);z=zeros(1,Npart);
lz=0.04;
lx=lz;ly=lx;
teta=2*pi*rand;
ri=(lz-R)*sqrt(rand);
x(1)=ri*cos(teta);
y(1)=ri*sin(teta);
z(1)=(2*lz-2*R)*rand-lz+R;
for i=2:Npart;
teta=2*pi*rand;
ri=(lz-R)*sqrt(rand);
x(i)=ri*cos(teta);
y(i)=ri*sin(teta);
z(i)=(2*lz-2*R)*rand-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
teta=2*pi*rand;
ri=(lz-R)*sqrt(rand);
x(i)=ri*cos(teta);
y(i)=ri*sin(teta);
z(i)=(2*lz-2*R)*rand-lz+R;
k=i-1;
else
k=k-1;
end
end
end
Denisse Campos Muñoz
Denisse Campos Muñoz am 17 Feb. 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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by