Some refactoring

This commit is contained in:
madmaurice 2016-02-17 11:43:19 +01:00
parent ed32bba8c6
commit 828a841606

View file

@ -3,6 +3,11 @@
from game import *
class WaterSim(Game):
alpha = 100000
u = lambda Cm1,C,C1,dx: WaterSim.alpha * (Cm1+C1-2*C) * 0.5 * dx
v = lambda u,v,d,dt: ( v + (u - d * v) * dt )
w = lambda w,v,dt: w + v * dt
def __init__(self,N):
self.N = N
self.init_data(N//2)
@ -26,19 +31,27 @@ class WaterSim(Game):
def on_update(self, dtime):
C2 = [0] * self.N
C2[0] = 100 * (self.C[1] - self.C[0]) * 100/self.N
C2[-1] = 100 * (self.C[-2] - self.C[-1]) * 100/self.N
C2[0] = WaterSim.u(self.C[1] , self.C[0] , self.C[1] , 1.0/self.N)
C2[-1] = WaterSim.u(self.C[-2] , self.C[-1] , self.C[-2] , 1.0/self.N)
#C2[0] = 100 * (self.C[1] - self.C[0]) * 100/self.N
#C2[-1] = 100 * (self.C[-2] - self.C[-1]) * 100/self.N
for i in range(1,self.N-1):
C2[i] = 1000 * (self.C[i+1] + self.C[i-1] - 2*self.C[i]) * 0.5 * 100 /(self.N)
C2[i] = WaterSim.u(self.C[i-1],self.C[i], self.C[i+1], 1.0/self.N)
#C2[i] = 1000 * (self.C[i+1] + self.C[i-1] - 2*self.C[i]) * 0.5 * 100 /(self.N)
for i in range(0,self.N):
self.C1[i] = (self.C1[i] + C2[i] * dtime)
if i == 0 or i == self.N-1:
self.C1[i] *= 0.98
d = 10
#d = 0.95
else:
self.C1[i] *= 0.9999
self.C[i] = ( self.C[i] + self.C1[i] * dtime )
d = 0.1
#d = 0.9999
#self.C1[i] = d * (self.C1[i] + C2[i] * dtime)
self.C1[i] = WaterSim.v(C2[i], self.C1[i], d, dtime)
#self.C[i] = ( self.C[i] + self.C1[i] * dtime )
self.C[i] = WaterSim.w(self.C[i], self.C1[i], dtime)
if self.C[i] < 0:
self.C[i] = 0