Oct-10-2018, 07:20 PM
Hi all!
I wrote a -primitive- diffusion simulator, although it works there is one problem: It is damn slow. (30000 diffusion-step took almost a day
)
How it's look like:
There is a 1000*1000*1000 box with 50000 particles. The x and y koordinats are homogeneously distributed (and random of course), BUT the z coordinates are not. Let's cut the box "horizontally" in 1000 plane (so each plane has a single z-coordinate). The planes on the top are very populated, while the planes with low z-coordinate are barely populated. (The population of each horizontal plane can be described with a 2-degree polynom, but it is not important.)
The particles can move only along the x,y or z axis. I don't want to allow the particles to leave the box. Therefore, if a particle's z-coordinate equals 1000/or equals null, it's movement is restricted (it cannot go upwards/ or downwards).
X and Y koordinates are restricted to, I was lazy to make too much if condition, so i used the np.remainder-trick (but only for x and y coordinates). That means if one of my particles can "teleport back" to the other side of my box.
Now let's see the the important part of the code: (I didn't paste here, how the matrix of the original coordinates (k numpy-matrix) was made. It is long and unimportant...)
Obviously a for cycle inside an other for cycle is not good for speed. As you can see, the particles are moving one-by one.
It would be faster, if i could create a big L-matrix (stepping-matrix) with the shape of 50000*3, so all the particles could move at once.
Like this way: L=np.matrix([random.choice(svv) for _in range(50000)])
But in that case, I cannot restrict the z-koordinates, and the particles would escape on the top and the bottom of the box.
I wrote a -primitive- diffusion simulator, although it works there is one problem: It is damn slow. (30000 diffusion-step took almost a day

How it's look like:
There is a 1000*1000*1000 box with 50000 particles. The x and y koordinats are homogeneously distributed (and random of course), BUT the z coordinates are not. Let's cut the box "horizontally" in 1000 plane (so each plane has a single z-coordinate). The planes on the top are very populated, while the planes with low z-coordinate are barely populated. (The population of each horizontal plane can be described with a 2-degree polynom, but it is not important.)
The particles can move only along the x,y or z axis. I don't want to allow the particles to leave the box. Therefore, if a particle's z-coordinate equals 1000/or equals null, it's movement is restricted (it cannot go upwards/ or downwards).
X and Y koordinates are restricted to, I was lazy to make too much if condition, so i used the np.remainder-trick (but only for x and y coordinates). That means if one of my particles can "teleport back" to the other side of my box.
Now let's see the the important part of the code: (I didn't paste here, how the matrix of the original coordinates (k numpy-matrix) was made. It is long and unimportant...)
svv=[[0, 0, 1], [0, 0, -1], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]] felsvv=[[0, 0, 1], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]] lesvv=[[0, 0, -1], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]] lista=[] o=np.matrix([1000, 1000, 1001]) for j in range(30000): for i in range(50000): if k[i,2]==0: l=np.matrix([random.choice(felsvv)]) elif k[i,2]==1000: l=np.matrix([random.choice(lesvv)]) else: l=np.matrix([random.choice(svv)]) ujsor=k[i,:]+l lista.append(ujsor) k=np.remainder(np.matrix(np.array(lista)), o) lista=[] print(k)
Obviously a for cycle inside an other for cycle is not good for speed. As you can see, the particles are moving one-by one.
It would be faster, if i could create a big L-matrix (stepping-matrix) with the shape of 50000*3, so all the particles could move at once.
Like this way: L=np.matrix([random.choice(svv) for _in range(50000)])
But in that case, I cannot restrict the z-koordinates, and the particles would escape on the top and the bottom of the box.