【问题标题】:How to stop particles crossing the solid cylinder boundary?如何阻止粒子穿过实心圆柱体边界?
【发布时间】:2021-12-25 12:07:51
【问题描述】:

我正在做一个随机游走粒子跟踪模拟。在我的问题中,我必须在圆柱体上实现反射边界。在这段代码中,检查意味着如果粒子进入圆柱体,它们之前的位置不应该改变。我的意思是,如果一个粒子越过实体边界,这样的移动就会被拒绝,并且在当前迭代期间,示踪剂会停留在其先前的位置。为澄清起见,我附上了一张图片,您可以在其中看到粒子坐在圆圈中。 但是,颗粒仍然进入气缸。下面是我的代码。

%% 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
                                            % u -> x-velocity component 
  y_ out = y_previous + v.dt + sqrt(2Ddt);  % y_out--> current position
                                            % y_previous--> previous position
                                            % v -> y-velocity component
    
  %% Check whether particle is inside the cylinder obstacle 
  % x_c and y_c is the center location for cylinder (obstacle) in the flow
  Incircle = sqrt((x_out - x_c).^2 + (y_out - y_c).^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(kk1) = x_previous(kk1);             % Do not update location
    y_out(kk1) = y_previous(kk1);
  end        
    x_previous = x_out;
    y_previous = y_out;

end

任何修改/更正都会有所帮助 谢谢

【问题讨论】:

标签: matlab indexing simulation particles random-walk


【解决方案1】:

由于舍入误差,比较floatdouble时,使用

a-b > tol  % tol = some error tolerance, say, 1e-10

而不是

a > b

另外,sqrt 会引入一些数值误差,比较平方距离更准确。

尝试将代码中的这些行更改为

Incircle = (x_out - x_c).^2 + (y_out - y_c).^2;  
Particle_enter  = find (abs(Incircle - D^2/4) < tol);

如果你随机生成粒子的初始位置,首先要确保它们不在障碍物内。

最后,如果一个粒子碰到一个反射边界,它不应该被反射,而不是回到原来的位置吗?

【讨论】:

  • 您好,有多种方法可以实现无通量边界条件。您建议的示踪剂的反射就是其中之一。你能在我的代码中解释一下如何实现这个条件吗?
  • 先计算碰撞点。然后在碰撞点反转垂直于障碍物表面的速度,这涉及到表面的单位法向量的计算。但是在你添加任何新东西之前,不幸的是,很可能在你的代码中引入新问题之前,最好关注当前的穿越障碍问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-20
  • 1970-01-01
  • 2017-08-22
  • 2015-03-26
相关资源
最近更新 更多