示例#1
0
v += 0.05*np.random.uniform(-1, 1, (n, n))

sy, sx = V.shape
grd = Grid(sx=sx, sy=sy, resx=sx, resy=sy)
grd.lineWidth(0).wireframe(False).lighting(ambient=0.5)
formula = r'(u,v)=(D_u\cdot\Delta u -u v v+F(1-u), D_v\cdot\Delta v +u v v -(F+k)v)'
ltx = Latex(formula, s=15, pos=(0,-sy/1.9,0))
print('Du, Dv, F, k, name =', Du, Dv, F, k, name)
settings.useDepthPeeling = False

for step in range(Nsteps):
    for i in range(25):
        Lu = (                  U[0:-2, 1:-1] +
              U[1:-1, 0:-2] - 4*U[1:-1, 1:-1] + U[1:-1, 2:] +
                                U[2:  , 1:-1])
        Lv = (                  V[0:-2, 1:-1] +
              V[1:-1, 0:-2] - 4*V[1:-1, 1:-1] + V[1:-1, 2:] +
                                V[2:  , 1:-1])
        uvv = u*v*v
        u += Du*Lu - uvv + F*(1-u)
        v += Dv*Lv + uvv - (F+k)*v

    grd.cmap('ocean_r', V.ravel(), on='cells', arrayName="escals")
    grd.mapCellsToPoints()
    newpts = grd.points()
    newpts[:,2] = grd.getPointArray('escals')*25 # assign z
    grd.points(newpts) # set the new points
    plt = show(ltx, grd, zoom=1.25, elevation=-.15, bg='linen', interactive=False)
    if plt.escaped: break  # if ESC is hit during loop

interactive().close()
示例#2
0
grd = Grid(sx=sx, sy=sy, resx=sx, resy=sy)
grd.lineWidth(0).wireframe(False).lighting(ambient=0.5)
formula = r'(u,v)=(D_u\cdot\Delta u -u v v+F(1-u), D_v\cdot\Delta v +u v v -(F+k)v)'
ltx = Latex(formula, s=15, pos=(0, -sy / 1.9, 0))
print('Du, Dv, F, k, name =', Du, Dv, F, k, name)
settings.useDepthPeeling = False

for step in range(Nsteps):
    for i in range(25):
        Lu = (U[0:-2, 1:-1] + U[1:-1, 0:-2] - 4 * U[1:-1, 1:-1] + U[1:-1, 2:] +
              U[2:, 1:-1])
        Lv = (V[0:-2, 1:-1] + V[1:-1, 0:-2] - 4 * V[1:-1, 1:-1] + V[1:-1, 2:] +
              V[2:, 1:-1])
        uvv = u * v * v
        u += Du * Lu - uvv + F * (1 - u)
        v += Dv * Lv + uvv - (F + k) * v

    grd.cmap('ocean_r', V.ravel(), on='cells', arrayName="escals")
    grd.mapCellsToPoints()  # interpolate cell data to point data
    newpts = grd.points()
    newpts[:, 2] = grd.pointdata['escals'] * 25  # assign z elevation
    grd.points(newpts)  # set the new points
    plt = show(ltx,
               grd,
               zoom=1.25,
               elevation=-.15,
               bg='linen',
               interactive=False)
    if plt.escaped: break  # if ESC is hit during loop

# interactive().close()