How to stop particles crossing the solid cylinder boundary
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 13 de Nov. de 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.
Respuestas (1)
Jan
el 12 de Nov. de 2021
Editada: Jan
el 12 de Nov. de 2021
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 comentarios
Walter Roberson
el 28 de Nov. de 2021
We need your full code, so that we are not busy trying to fix problems that we imagine that you might possibly have.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!