fin   = feq.copy()
fpost = feq.copy()

# interactive mode (execute code while showing figures)
if ( liveUpdate | savePlot ):
    pyplot.ion()
    fig, ax = pyplot.subplots(1)

os.chdir(outputFolder)


###### Main time loop ##########################################################
for time in range(maxIterations):

    # Calculate macroscopic density and velocity
    (rho, u) = getMacroValues(fin)

    feq = equilibrium(rho, u)

    # Collision step.
    fpost = BGKCollide(fin, feq, omega)
    #fpost = cumulantCollide_min(fin, rho, u, omega)

    # Streaming step
    fin[0, :, :] = fpost[0, :, :]

    fin[1, 1:nxl,   :]     = fpost[1, 0:nxl-1,  :]
    fin[2,   :,   0:nyl-1] = fpost[2,   :,    1:nyl]
    fin[3, 0:nxl-1, :]     = fpost[3, 1:nxl,    :]
    fin[4,   :,   1:nyl]   = fpost[4,   :,    0:nyl-1]
# interactive mode (execute code while showing figures)
if ( liveUpdate ):
    pyplot.ion()
    fig, ax = pyplot.subplots(1)

os.chdir(outputFolder)

plottingData = (plotEveryN, skipFirstN, liveUpdate, saveVTK, savePlot, ax, fig, grid, prefix)

checkTransformation(fin)

###### Main time loop ##########################################################
for time in range(maxIterations):

    # Calculate macroscopic density and velocity
    (rho, u) = getMacroValues(fin)

    predensity = sum(rho)
    preVelX = sum(u[0,:,:])
    preVelY = sum(u[1,:,:])

    print amin(rho)
    feq = equilibrium(rho, u)

    # Collision step.
    #fpost = BGKCollide(fin, feq, omega)
    fpost = cumulantCollide(fin, rho, u, omega)
    #fpost = cumulantCollideAll(fin, rho, u, omega, omega, omega, omega)
    #fpost = centralMomentSRT(fin, feq, u, omega)

    (rho, u) = getMacroValues(fpost)