CFD 7
CFD 7
CFDPython (/github/barbagroup/CFDPython/tree/master)
/ lessons (/github/barbagroup/CFDPython/tree/master/lessons)
Text provided under a Creative Commons Attribution license, CC-BY. All code is made available under the FSF-
approved BSD-3 license. (c) Lorena A. Barba, Gilbert F. Forsyth 2017. Thanks to NSF for support via CAREER award
#1149784.
@LorenaABarba (https://twitter.com/LorenaABarba)
12 steps to Navier–Stokes
You see where this is going ... we'll do 2D diffusion now and next we will combine steps 6 and 7
to solve Burgers' equation. So make sure your previous steps work well before continuing.
Step 7: 2D Diffusion
2 2
∂u ∂ u ∂ u
= ν + ν
2 2
∂t ∂x ∂y
You will recall that we came up with a method for discretizing second order derivatives in Step 3,
when investigating 1-D diffusion. We are going to use the same scheme here, with our forward
difference in time and two second-order derivatives.
n+1 n n n n n n n
u − u u − 2u + u u − 2u + u
i,j i,j i+1,j i,j i−1,j i,j+1 i,j i,j−1
= ν + ν
2 2
Δt Δx Δy
Once again, we reorganize the discretized equation and solve for ui,j n+1
n+1
ν Δt
n n n n
u = u + (u − 2u + u )
i,j i,j 2 i+1,j i,j i−1,j
Δx
ν Δt
n n n
+ (u − 2u + u )
2 i,j+1 i,j i,j−1
Δy
https://nbviewer.org/github/barbagroup/CFDPython/blob/master/lessons/09_Step_7.ipynb 1/5
12/26/24, 4:04 PM Jupyter Notebook Viewer
x = numpy.linspace(0, 2, nx)
y = numpy.linspace(0, 2, ny)
ax.set_xlim(0, 2)
ax.set_ylim(0, 2)
ax.set_zlim(1, 2.5)
ax.set_xlabel('$x$')
ax.set_ylabel('$y$');
n+1
ν Δt
n n n n
u = u + (u − 2u + u )
i,j i,j 2 i+1,j i,j i−1,j
Δx
ν Δt
n n n
+ (u − 2u + u )
2 i,j+1 i,j i,j−1
Δy
https://nbviewer.org/github/barbagroup/CFDPython/blob/master/lessons/09_Step_7.ipynb 2/5
12/26/24, 4:04 PM Jupyter Notebook Viewer
fig = pyplot.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, u[:], rstride=1, cstride=1, cmap=cm.viridis,
linewidth=0, antialiased=True)
ax.set_zlim(1, 2.5)
ax.set_xlabel('$x$')
ax.set_ylabel('$y$');
In [5]: diffuse(10)
In [6]: diffuse(14)
https://nbviewer.org/github/barbagroup/CFDPython/blob/master/lessons/09_Step_7.ipynb 3/5
12/26/24, 4:04 PM Jupyter Notebook Viewer
In [7]: diffuse(50)
Learn More
The video lesson that walks you through the details for Steps 5 to 8 is Video Lesson 6 on You
Tube:
https://nbviewer.org/github/barbagroup/CFDPython/blob/master/lessons/09_Step_7.ipynb 4/5
12/26/24, 4:04 PM Jupyter Notebook Viewer
Out[8]:
Out[9]:
https://nbviewer.org/github/barbagroup/CFDPython/blob/master/lessons/09_Step_7.ipynb 5/5