Updated files to work correctly.

This commit is contained in:
Anne de Jong 2018-12-16 13:40:05 +01:00
parent f0ec52f51f
commit 73493854ef
3 changed files with 38 additions and 25 deletions

View File

@ -1 +1,6 @@
Solve the boundary layer velocity profile using a finite difference method. Directly animate the result. # Blflow
This code solves the boundary layer velocity profile that occurs due to an
acoustic wave in the vicinity of a wall. In a small layer (the viscous boundary
layer thickness ($\delta_\nu$)), the presence of the wall affects the velocity
field which would otherwise be a "plug" flow.

14
blflow.py Normal file → Executable file
View File

@ -46,15 +46,13 @@ def u_np1(un, tn, dt):
un0 = np.zeros(n, float) un0 = np.zeros(n, float)
t = 0 t = 0
un = un0 un = un0
# un.append(un0)
# Make the plot
# plt.ioff()
f = plt.figure(1, figsize=(12, 6)) f = plt.figure(1, figsize=(12, 6))
linefd, = plt.plot(un0, y) linefd, = plt.plot(un0, y)
linee, = plt.plot(un0, y) linee, = plt.plot(un0, y)
plt.legend(('Finite difference', 'Periodic exact')) plt.legend(('Finite difference', 'Periodic exact'),
loc='lower right')
plt.ylim(0, 1) plt.ylim(0, 1)
plt.xlim(-1.5, 1.5) plt.xlim(-1.5, 1.5)
plt.ylabel('Distance from wall [m]') plt.ylabel('Distance from wall [m]')
@ -69,13 +67,13 @@ try:
t += dt t += dt
uold = un uold = un
un = u_np1(uold, t, dt) un = u_np1(uold, t, dt)
if(i % 100 == 0): if(i % 25 == 0):
linefd.set_xdata(un) linefd.set_xdata(un)
linee.set_xdata(u_ex(t)) linee.set_xdata(u_ex(t))
f.canvas.draw_idle() f.canvas.draw_idle()
plt.pause(.00001) plt.pause(.000005)
if not plt.fignum_exists(1): if not plt.fignum_exists(1):
break break
i += 1 i += 1
except Exception: except Exception:
pass pass

42
parplateflow.py Normal file → Executable file
View File

@ -41,26 +41,36 @@ def u_np1(un, tn, dt):
un0 = zeros(n, float) un0 = zeros(n, float)
t = 0 t = 0
un = un0 un = un0
# un.append(un0)
# Make the plot f = plt.figure(1, figsize=(12, 6))
linefd, = plt.plot(un0, y) linefd, = plt.plot(un0, y)
linee, = plt.plot(un0, y) linee, = plt.plot(un0, y)
plt.legend(('Finite difference', 'Periodic exact')) plt.legend(('Finite difference', 'Periodic exact'),
loc='lower right')
plt.ylim(-1, 1) plt.ylim(-1, 1)
plt.xlim(-1.5, 1.5) plt.xlim(-1.5, 1.5)
plt.ylabel('y') plt.ylabel('y [m]')
plt.xlabel('u') plt.xlabel('Velocity [m/s]')
plt.grid('on') plt.grid(True)
plt.show(block=False)
i = 0 i = 0
uold = un uold = un
while(True):
t += dt
uold = un try:
un = u_np1(uold, t, dt) while(True):
if(i % 100 == 0): t += dt
linefd.set_xdata(un) uold = un
linee.set_xdata(u_ex(t)) un = u_np1(uold, t, dt)
plt.draw() if(i % 25 == 0):
# print("Time:",t) linefd.set_xdata(un)
i += 1 linee.set_xdata(u_ex(t))
f.canvas.draw_idle()
plt.pause(.000005)
if not plt.fignum_exists(1):
break
i += 1
except Exception:
pass
exit(0)