如何在python中创建“台球"反射边界条件? [英] How to create 'billiard ball' reflection boundary condition in python?

查看:85
本文介绍了如何在python中创建“台球"反射边界条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Erwin Schrodinger(在什么是生命?)中,扩散可以完全由粒子的随机运动来解释.我想通过创建一个程序来测试这一点,该程序创建了一个封闭容器中气体分子"扩散的时间步长可视化.初始条件将有两个分区,一个是低浓度,一个是高浓度.在 t0 之后,隔板被移除并且允许气体扩散.我想使用的唯一机制是向每个分子添加位移随机向量.初始条件如下所示.

According to Erwin Schrodinger (in What is Life?), diffusion can be explained entirely by the random motion of particles. I want to test this myself by create a program the creates a time-step visualization of the diffusion of "gas molecules" in a closed container. The initial conditions would have two partitions, one with low and one with high concentration. After t0 the partition is removed and the gas is allowed to diffuse. The only mechanism I want to use is adding displacement random vectors to each molecule. The initial conditions would look like this.

我无法弄清楚的部分问题是当分子撞击边界表面时如何创建一个简单的台球类型反射.我假设简单的对称反射(角度输入 = 边界处的角度输出).我根本没有开始代码,因为我不知道如何处理这部分,而我知道如何完成其​​余部分.我知道这更像是一个数学问题,但是如何在 python 中创建这些边界条件?理想情况下,我希望自己编写此功能以便我能够理解它,而不是使用可以执行此操作的预构建包.对于任何给定的分子,这就是我正在寻找的.

The part of the problem that I con't figure out is how to create a simple billiards type reflection when the molecule hits the bounding surfaces. I am assume simple symmetrical reflections (angle in = angle out at boundaries). I haven't started the code at all because I don't know how to deal with this part, while I know how to do the rest of it. I know this is more of a math question, but how can I create these boundary conditions in python? Ideally, I would like to have to program this functionality myself so that I can understand it, rather than using a pre-built package that could do this. This is what I am looking for, for any given molecule.

最终,我真正需要的是:给定初始位置 (x1,y2)、矢量幅度 v、角度 theta 以及盒子大小和位置,分子的最终静止位置是什么 (x2,y2).

Ultimately, all I really need is this: given the initial location (x1,y2), a vector magnitude v, an angle theta, and the box size and location, what is the final resting position of the molecule (x2,y2).

推荐答案

不需要计算反射角,只需将问题分解为两种:一种用于x,一种用于y.在这两种情况下,您都需要粒子在超出边界时返回".

You don't need to calculate the reflection angle, just decompose the problem in two: one for x and one for y. In both cases, you need the particle to "go back" when it exceeds the boundary.

我之前做过一次关于流体中粒子密度的练习.最简单的方法是考虑两个方向的 (0, 1) 边界.以下代码应该这样做(提示:正确使用 abs 将创建等效的反射):

I've done this time ago for an excercise studying particle density in fluids. The easiest thing is to consider a (0, 1) boundary in both directions. The following code should do it (tip: a proper use of abs will create the equivalent of a reflection):

x0 = [.1, .9]
delta = [-0.2, 0.3]
x1 = [(1-abs(abs(xi + di)-1)) for xi, di in zip(x0, delta)]
print(x1)
# 0.1, 0.8
#or using numpy:
x1 = 1-np.abs(np.abs(np.asarray(x0) + np.asarray(delta))-1)
print(x1)
>> [0.09999999999999998, 0.8]
   array([0.1, 0.8])

我从你的问题中假设你忽略了粒子 - 粒子碰撞和粒子 - 粒子非叠加"

I'm assuming from your question that you are neglecting particle-particle collision and particle-particle "non-superposition"

这篇关于如何在python中创建“台球"反射边界条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆