# set up the walls
leftWall    = fromfunction(lambda   x, y: x == 0,  (nx, ny))
rightWall   = fromfunction(lambda   x, y: x == nxl,  (nx, ny))
bottomWall  = fromfunction(lambda   x, y: y == nyl,  (nx, ny))

wall    = logical_or(logical_or(leftWall, rightWall), bottomWall)

# initial velocity profile
#  < -
#   -
#  - >
vel                = zeros((2, nx, ny))
vel[0, :,  0 ]     =  uLB

# initial particle distributions
feq   = equilibrium(1.0, vel)
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
Ejemplo n.º 2
0
# velocity
print "Building vortices"
vel = zeros((2, nx, ny))
for x in range(nx):
    for y in range(ny):
        vel[:,x,y] = vel[:,x,y] \
        + rankinVortex(x-c1x, y-c1y, diameter/2.) \
        + rankinVortex(x-c2x, y-c2y, diameter/2.) \

vel = vel*uLB
print "Building vortices complete"
avgVelX = mean(vel[0,:,:])
avgVelY = mean(vel[1,:,:])

# initial particle distributions
feq   = equilibrium(1.0, vel.reshape((2,nx*ny))).reshape((9,nx,ny))
fin   = feq.copy()
fpost = feq.copy()  # post collision distributions

fluidDomain = full((nx,ny), True, dtype=bool)
clipfft = 30
fftDomain = fluidDomain[nx/2-clipfft:nx/2+clipfft, ny/2-clipfft:ny/2+clipfft]

# interactive mode (execute code while showing figures)
if ( liveUpdate | savePlot ):
    pyplot.ion()
    fig, ax = pyplot.subplots(1)
    ax.clear()
    ax.imshow(sqrt(vel[0]**2+vel[1]**2).transpose(),  cmap=cm.afmhot, vmin=0., vmax=0.05)

if analysis:
###### Setup ##################################################################

noSlipBoundary = fromfunction(lambda x, y: logical_or((y == 0), (y == ny)), (nx, ny))


# velocity inlet for schaefer turek
velIn = fromfunction(lambda d, x, y: (1-d)*4*uLB*(y-0.5)*(nyl-y-0.5)/(nyl**2),  (2, nx, ny))
rhoIn = fromfunction(lambda x,y: (1+pressureDrop) - 2*pressureDrop*x/nxl, (nx,ny))
vel = zeros((2,nx,ny));
vel[:,:,1:ny-1] = velIn[:,:,1:ny-1]*0.01

#print vel[0,0,:]

# initial particle distributions
feq   = equilibrium(rhoIn, vel)
fin   = feq.copy()
fpost = feq.copy()  # post collision distributions


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


###### Main time loop ##########################################################
for time in range(maxIterations):
    # bounce back distributions at walls
    for i in range(q):
        fin[i, noSlipBoundary] = fin[noslip[i], noSlipBoundary]
Ejemplo n.º 4
0
###### Setup ##################################################################

solidDomain = fromfunction(lambda x, y: logical_or((y == 0), (y == nyl)), (nx, ny))

fluidDomain = invert(solidDomain)

# velocity inlet for schaefer turek
velIn = fromfunction(lambda d, x, y: (1-d)*4*uLB*(y-0.5)*(nyl-y-0.5)/(nyl**2),  (2, nx, ny))

vel = zeros((2,nx,ny));
vel[:,:,1:ny-1] = velIn[:,:,1:ny-1]

#print vel[0,0,:]

# initial particle distributions
feq   = equilibrium(1.0, vel.reshape((2,nx*ny))).reshape((9,nx,ny))
fin   = feq.copy()
fpost = feq.copy()  # post collision distributions


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


###### Main time loop ##########################################################
for time in range(maxIterations):
    # bounce back distributions at walls
    finc = fin[:, solidDomain].copy()
    for i in range(9):
obstacleBounds, dragBoundStencil, liftBoundStencil, completeBoundStencil = obstacleAttack(obstacle)
nrOfDragBoundary = sum(obstacleBounds[1]) + sum(obstacleBounds[5]) + sum(obstacleBounds[8]) + \
    sum(obstacleBounds[3]) + sum(obstacleBounds[6]) + sum(obstacleBounds[7])
nrOfLiftBoundary = sum(obstacleBounds[2]) + sum(obstacleBounds[6]) + sum(obstacleBounds[5]) + \
    sum(obstacleBounds[4]) + sum(obstacleBounds[7]) + sum(obstacleBounds[8])

noSlipBoundary = fromfunction(lambda x, y: logical_or((y == 0), (y == ny)), (nx, ny))


# velocity inlet for schaefer turek
velIn = fromfunction(lambda d, x, y: (1-d)*4*uLB*y*(nyl-y)/(nyl**2),  (2, nx, ny-2))
vel = zeros((2,nx,ny));
vel[:,:,1:ny-1] = velIn

# initial particle distributions
feq   = equilibrium(1.0, vel)
fin   = feq.copy()
fpost = feq.copy()  # post collision distributions


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


###### Main time loop ##########################################################
for time in range(maxIterations):
    # bounce back distributions at obstacle
    for i in range(q):
        fin[i, obstacle] = fin[noslip[i], obstacle]