class Water( Drawable ) : NONE_T , LBM_T , SPH_T = range(3) def __init__( self ) : self.sph = SPH() self.lbm = LBM() self.water = self.sph def set( self , water_type ) : if water_type == self.NONE_T : self.water = None elif water_type == self.SPH_T : self.water = self.sph elif water_type == self.LBM_T : self.water = self.lbm def set_borders( self , b ) : self.sph.set_borders( b ) self.lbm.set_borders( b ) def draw( self ) : self.water.draw() def gfx_init( self ) : self.sph.gfx_init() self.lbm.gfx_init() def wave( self , dt ) : self.water.wave( dt )
from sph import SPH import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation sph = SPH(1 << 8, 0.1) fig, axs = plt.subplots(1) scatter = axs.scatter(sph.pos[:,0], sph.pos[:,1]) def update(time): global sph, scatter sph.update() scatter.set_offsets(sph.pos) print("frame: ", time) animation = FuncAnimation(fig, update, frames=range(100), interval=10, repeat=False) plt.show()
def __init__( self ) : self.sph = SPH() self.lbm = LBM() self.water = self.sph
def __init__(self, *args, **kwargs): #mouse handling for transforming scene self.mouse_down = False self.mouse_old = Vec([0., 0.]) self.rotate = Vec([0., 0., 0.]) self.translate = Vec([0., 0., 0.]) #self.initrans = Vec([0., 0., -2.]) self.init_persp_trans = Vec([-.5, -0.5, -2.5]) self.init_ortho_trans = Vec([0., 0., 0.]) self.init_persp_rotate = Vec([0., 0., 0.]) #self.init_ortho_rotate = Vec([90., -90., 0.]) self.init_ortho_rotate = Vec([0., 0., 0.]) self.ortho = True self.dt = dt self.width = 640 self.height = 480 glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(self.width, self.height) glutInitWindowPosition(0, 0) self.win = glutCreateWindow("SPH: Python") #gets called by GLUT every frame glutDisplayFunc(self.draw) #handle user input glutKeyboardFunc(self.on_key) glutMouseFunc(self.on_click) glutMotionFunc(self.on_mouse_motion) #this will call draw every 30 ms glutTimerFunc(30, self.timer, 30) glViewport(0, 0, self.width, self.height) #setup OpenGL scene self.glprojection() ######################################################################### #max_num = 16384 max_num = 8192 #max_num = 2**12 #4096 #max_num = 2**10 #1024 #max_num = 2**8 #256 #max_num = 2**7 #128 dmin = Vec([0, 0, 0]) dmax = Vec([1, 1, 1]) self.domain = Domain(dmin, dmax) self.system = SPH(max_num, self.domain) self.ghost_domain = Domain(dmin, dmax) self.ghost = SPH(max_num * 36, self.ghost_domain) ipos = addRect(512, Vec([0.1, 0.1, 0., 0.]), Vec([1., 1., 0., 0.]), self.system) gpos = addRect(8192, Vec([0.1, 0.1, 0., 0.]), Vec([1., 1., 0., 0.]), self.ghost) #print ipos, "LEN", len(ipos) #print gpos, "LEN", len(gpos) self.clghost_system = clsph.CLSPH(dt, self.ghost, is_ghost=True) self.clsystem = clsph.CLSPH(dt, self.system) #ipos = sph.addRect3D(50, Vec([1.2, 1.2, .2,0.]), Vec([2.,2.,1.,0.]), self.system) self.clghost_system.push_particles(gpos, None, None) #self.clghost_system.update() self.clsystem.push_particles(ipos, None, None) color = [1., 0., 0., 1.] self.clsystem.set_color(color) color = [.75, 0.75, 0.75, 1.] self.clghost_system.set_color(color) ######################################################################### print "about to start main loop" glutMainLoop()