How to stop particles crossing the solid cylinder boundary
Show older comments
Hello,
I am doing random walk particle tracking simulation. In my problem, I have to implement reflected boundary on the cylinder. In this code, the check implies that if particles enter into the cylinder, its previous position should not change.
However, particles still entering into the cylinder. Below is my code.
%% loop starts
for i = 1:T % T is the total computation time of simulation
t = i*dt; % dt is the time step
%% Particle tracking starts
x_ out = x_previous + u.dt + sqrt(2Ddt); % x_out--> current position, x_previous--> previous position of
% particle, u is the x-velocity component
y_ out = y_previous + v.dt + sqrt(2Ddt); % y_out--> current position, y_in--> previous position of #
% particle, v is the y-velocity velocity component
%% Check whether particle reflects from cylinder obstacle
% x_c and y_c is the center location for cylinder (obstacle) in the flow
Incircle = sqrt((x_out - x_c(j)).^2 + (y_out - y_c(j)).^2);
Particle_enter = find (Incircle < D/2); % Particle entered in obstacle having diameter (D)
%% if particle cross cylinder boundary, do not update its position
If ismember(Particle_enter,1)
kk1 = find(ismember(isIncircle, 1) == 1);
x_out = x_previous(kk1); % Do not update location
y_out = y_previous(kk1);
end
x_previous = x_out;
y_previous = y_out;
end
Any suggestion/modification in the code will be helpful
Thanks
5 Comments
Jan
on 12 Nov 2021
I do not understand this sentence: "if particles enter into the cylinder, its previous position should not change".
K_A
on 12 Nov 2021
Image Analyst
on 12 Nov 2021
Try inpolygon(). Wouldn't it be more accurate to have the particle bounce/reflect off the surface rather than stop dead in its tracks?
K_A
on 12 Nov 2021
Image Analyst
on 13 Nov 2021
Yes of course -- that would be the wrong formula unless the particle was aiming directly at the center. If it's a "glancing blow" then you need to take the slope of the cylinder at the point of impact into account. You need to have another array, slope, where the elements are the arctangent of y_c over x_c. Then it's just simple geometry/algebra/trigonometry to reflect a line off of a plane at that slope.
Answers (1)
What about:
Outcircle = ((x_out - x_c(j)).^2 + (y_out - y_c(j)).^2) >= (D/2)^2;
x_out(Outcircle) = x_previous(Outcircle);
y_out(Outcircle) = y_previous(Outcircle);
Note: sqrt() is expensive. Squaring the radius is much cheaper.
4 Comments
K_A
on 13 Nov 2021
Edited: Walter Roberson
on 28 Nov 2021
Jan
on 13 Nov 2021
"Particles seems to freeze and they are not moving after applying this check."
Yes, of course. This is what you have asked for:
"if particles enter into the cylinder, its previous position should not change."
Please use the tools for format code in the forum. I've done this in your question and in your comment for you. In both cases you see immediately, that there is a strange space:
x_ out = x_previous + u.dt + sqrt(2Ddt);
% ^
y_ out = y_previous + v.dt + sqrt(2Ddt);
% ^
This seems to be a typo, but if x_ and y_ are not defined before, it should stop with an error message. So how do you create the output?
In this code you add some fixed values to the x and y positions. Are you sure that you want to access the field dt of the structs u and v? Motion simulations usually have a term like velocity_x * dt to determine the motion of a partical.
Please take into account that "does not work" is not useful to explain a poblem. Do you get an error message? If so, which one? Or do the results differ from your expectations? Then explain both - remember that the readers do not know, what you expect.
Walter Roberson
on 28 Nov 2021
We need your full code, so that we are not busy trying to fix problems that we imagine that you might possibly have.
Categories
Find more on Programming 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!