Skip to content

Commit 8f709b5

Browse files
committed
Code clarifications [ci skip]
1 parent 2f5fb0d commit 8f709b5

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed
Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,50 @@
1-
using FourierFlows, PyPlot, JLD2
2-
1+
using FourierFlows, PyPlot
32
import FourierFlows.TracerAdvDiff
43

54
# Numerical parameters and time-stepping parameters
65
nx = 128 # 2D resolution = nx^2
76
stepper = "RK4" # timestepper
87
dt = 0.02 # timestep
9-
nsubs = 200 # number of time-steps for plotting
8+
nsubs = 200 # number of time-steps for plotting
109
nsteps = 4nsubs # total number of time-steps (must be multiple of nsubs)
1110

1211
# Physical parameters
13-
Lx = 2π # domain size
12+
Lx = 2π # domain size
1413
kap = 0.002 # diffusivity
1514

16-
gr = TwoDGrid(nx, Lx)
17-
X, Y = gr.X, gr.Y
18-
19-
# streamfunction (for plotting) and (u,v) flow field
20-
psiampl = 0.2
15+
# Flow field
16+
Psi = 0.2
2117
m, n = 1, 1
22-
psiin = @. psiampl * cos(m*X) * cos(n*Y)
23-
uvel(x, y) = +psiampl * n * cos(m*x) * sin(n*y)
24-
vvel(x, y) = -psiampl * m * sin(m*x) * cos(n*y)
25-
26-
prob = TracerAdvDiff.ConstDiffProblem(; steadyflow=true,
27-
nx=nx, Lx=Lx, kap=kap, u=uvel, v=vvel, dt=dt, stepper=stepper)
28-
29-
s, v, p, g, eq, ts = prob.state, prob.vars, prob.params, prob.grid, prob.eqn, prob.ts;
18+
uvel(x, y) = +Psi * n * cos(m*x) * sin(n*y)
19+
vvel(x, y) = -Psi * m * sin(m*x) * cos(n*y)
3020

3121
# Initial condition c0 = c(x, y, t=0)
32-
amplc0, sigc0 = 0.1, 0.1
22+
C, dc = 0.1, 0.1
3323
x0, y0 = 1.2, 0
34-
c0func(x, y) = amplc0*exp(-(x^2+y^2)/(2sigc0^2))
35-
c0 = c0func.(g.X .- x0, g.Y .- y0)
24+
c0(x, y) = C*exp( -((x-x0)^2+(y-y0)^2) / (2dc^2))
3625

26+
# Generate problem
27+
prob = TracerAdvDiff.ConstDiffProblem(nx=nx, Lx=Lx, kap=kap, u=uvel, v=vvel,
28+
dt=dt, stepper=stepper, steadyflow=true)
3729
TracerAdvDiff.set_c!(prob, c0)
3830

39-
"Plot the concentration field and the (u, v) streamlines."
40-
function plotoutput(prob, fig, axs; drawcolorbar=false)
41-
s, v, p, g = prob.state, prob.vars, prob.params, prob.grid
42-
t = round(prob.state.t, digits=2)
31+
# Calculate streamfunction of flow field for plotting
32+
X, Y = prob.grid.X, prob.grid.Y
33+
psi = @. Psi * cos(m*X) * cos(n*Y)
34+
35+
"Plot the flow streamlines and tracer concentration."
36+
function plotoutput(prob, ax; drawcolorbar=false)
4337

4438
TracerAdvDiff.updatevars!(prob)
39+
t = round(prob.state.t, digits=2)
4540

41+
sca(ax)
4642
cla()
47-
pcolormesh(g.X, g.Y, v.c)
43+
pcolormesh(X, Y, prob.vars.c)
4844

4945
if drawcolorbar; colorbar(); end
5046

51-
contour(g.X, g.Y, psiin, 15, colors="k", linewidths=0.7)
47+
contour(X, Y, psi, 15, colors="k", linewidths=0.7)
5248
axis("equal")
5349
axis("square")
5450
title("shading: \$c(x, y, t= $t )\$, contours: \$\\psi(x, y)\$")
@@ -58,10 +54,11 @@ function plotoutput(prob, fig, axs; drawcolorbar=false)
5854
nothing
5955
end
6056

61-
fig, axs = subplots(ncols=1, nrows=1, figsize=(8, 8))
62-
plotoutput(prob, fig, axs; drawcolorbar=true)
57+
fig, ax = subplots(ncols=1, nrows=1, figsize=(8, 8))
58+
plotoutput(prob, ax; drawcolorbar=true)
6359

60+
# Step problem forward
6461
while prob.step < nsteps
6562
stepforward!(prob, nsubs)
66-
plotoutput(prob, fig, axs)
63+
plotoutput(prob, ax)
6764
end

0 commit comments

Comments
 (0)