1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
from OpenGL.GL import *
from OpenGL.GLUT import *
import numpy as np
from boltzgas import HardSphereSetup, HardSphereSimulation
from boltzgas.initial_condition import grid_of_random_velocity_particles
from boltzgas.visual import View, VelocityHistogram, Tracer, ColoredBox
glutInit()
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowPosition(0, 0)
glutCreateWindow("BoltzGas")
grid_width = 32
radius = 0.004
char_u = 1120
position, velocity = grid_of_random_velocity_particles(grid_width, radius, char_u)
velocity[:,:] = 0
velocity[0,0] = 10*char_u
velocity[0,1] = 4*char_u
config = HardSphereSetup(radius, char_u, position, velocity)
gas = HardSphereSimulation(config, opengl = True, t_scale = 0.1)
tracer = Tracer(gas, 4)
histogram = VelocityHistogram(gas, [1.1,0], [1,1])
histogram.setup()
view = View(gas, [ ColoredBox([0,0], [1,1], (0.2,0.2,0.2)), tracer ], [ histogram ])
active = False
def on_display():
if active:
for i in range(0,5):
gas.evolve()
tracer.update()
histogram.update()
view.display()
def on_reshape(width, height):
view.reshape(width, height)
def on_timer(t):
glutTimerFunc(t, on_timer, t)
glutPostRedisplay()
def on_keyboard(key, x, y):
global active
active = not active
def on_close():
histogram.pool.shutdown()
glutDisplayFunc(on_display)
glutReshapeFunc(on_reshape)
glutTimerFunc(10, on_timer, 10)
glutKeyboardFunc(on_keyboard)
glutCloseFunc(on_close)
if __name__ == "__main__":
glutMainLoop()
|