Random motion, Particles, Decreasing number of particles with time

1 view (last 30 days)
Good morning,
I am modeling the brownian movement of particles in porous media with Matlab. The basis of the program is the random displacement in x and y of particles in a 500x500 matrix.
Rules are that there can be only one particle per matrix element (represented by a "1" in the matrix). A particle can move fom (i,j) to one of the 8 neighbours. Unpenetrable zones are represented by "-1" and free elements by "0"
The following code is the active part, actually moving the particles. The idea (good or bad :) ) is to:
Copy the matrix to avoid interferences
Check if there are free zones, ie "0" elements in the neighbourhood of the considered element
If there are possible movements, randomly get one of the empty elements and move the particle there.
The idea is rather simple I think but by running it a few times, I am losing particles as time passes. I have rechecked the use of randi and find commands and I can´t find where is the error in the code or logic.
Here is the code :
%%Random Motion Generator
for t=1:timeF
disp(t);
tempMat=spaceMatrix;
for i=2:size-1
for j=2:size-1
[row,col]=find(tempMat(i-1:i+1,j-1:j+1)==0); % Finding the Zero elements row and col return indice between 1 and 3
if tempMat(i,j)==1 % There is one particle
if ~isempty(row) % The particle can go at at least one other cell
a=randi(length(row)); % Generating a random indice between 1 and length(row)
spaceMatrix(i,j)=tempMat(i,j)-1; % Getting the particle out of the original cell
spaceMatrix(row(a)+i-2,col(a)+j-2)=tempMat(row(a)+i-2,col(a)+j-2)+1; % Putting the particle in the destination cell
else
spaceMatrix(i,j)=tempMat(i,j);
end
end
end
end
%if t==1||t==timeF/4||t==timeF/2||t==3*timeF/4||t==timeF
figure;
hold on
[row2,col2]=find(spaceMatrix==1);
plot(row2,col2,'r.');
[row3,col3]=find(spaceMatrix==-1);
plot(row3,col3,'.');
xlim([0 500]);
ylim([0 500]);
disp(length(row2));
%end
end
Thanks in advance for the tips and hints :)
David
  2 Comments
Jan
Jan on 25 Mar 2011
Please use a proper code formatting as described here: http://www.mathworks.com/matlabcentral/answers/help/markup . It is always a good idea to make the question as easy to read as possible.

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 25 Mar 2011
When you check (at time t) whether a particle can go to a particular location of spaceMatrix, you correctly check that the spot was empty at time t-1. But I think you fail to check whether a different particle has already moved there during time t. You need to also check whether spaceMatrix is still empty.
You'll need to devise a rule for such conflicts.

Categories

Find more on Material Sciences in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!