1
- using FourierFlows, PyPlot, JLD2
2
-
1
+ using FourierFlows, PyPlot
3
2
import FourierFlows. TracerAdvDiff
4
3
5
4
# Numerical parameters and time-stepping parameters
6
5
nx = 128 # 2D resolution = nx^2
7
6
stepper = " RK4" # timestepper
8
7
dt = 0.02 # timestep
9
- nsubs = 200 # number of time-steps for plotting
8
+ nsubs = 200 # number of time-steps for plotting
10
9
nsteps = 4 nsubs # total number of time-steps (must be multiple of nsubs)
11
10
12
11
# Physical parameters
13
- Lx = 2 π # domain size
12
+ Lx = 2 π # domain size
14
13
kap = 0.002 # diffusivity
15
14
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
21
17
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)
30
20
31
21
# Initial condition c0 = c(x, y, t=0)
32
- amplc0, sigc0 = 0.1 , 0.1
22
+ C, dc = 0.1 , 0.1
33
23
x0, y0 = 1.2 , 0
34
- c0func (x, y) = amplc0* exp (- (x^ 2 + y^ 2 )/ (2 sigc0^ 2 ))
35
- c0 = c0func .(g. X .- x0, g. Y .- y0)
24
+ c0 (x, y) = C* exp ( - ((x- x0)^ 2 + (y- y0)^ 2 ) / (2 dc^ 2 ))
36
25
26
+ # Generate problem
27
+ prob = TracerAdvDiff. ConstDiffProblem (nx= nx, Lx= Lx, kap= kap, u= uvel, v= vvel,
28
+ dt= dt, stepper= stepper, steadyflow= true )
37
29
TracerAdvDiff. set_c! (prob, c0)
38
30
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 )
43
37
44
38
TracerAdvDiff. updatevars! (prob)
39
+ t = round (prob. state. t, digits= 2 )
45
40
41
+ sca (ax)
46
42
cla ()
47
- pcolormesh (g . X, g . Y, v . c)
43
+ pcolormesh (X, Y, prob . vars . c)
48
44
49
45
if drawcolorbar; colorbar (); end
50
46
51
- contour (g . X, g . Y, psiin , 15 , colors= " k" , linewidths= 0.7 )
47
+ contour (X, Y, psi , 15 , colors= " k" , linewidths= 0.7 )
52
48
axis (" equal" )
53
49
axis (" square" )
54
50
title (" shading: \$ c(x, y, t= $t )\$ , contours: \$\\ psi(x, y)\$ " )
@@ -58,10 +54,11 @@ function plotoutput(prob, fig, axs; drawcolorbar=false)
58
54
nothing
59
55
end
60
56
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 )
63
59
60
+ # Step problem forward
64
61
while prob. step < nsteps
65
62
stepforward! (prob, nsubs)
66
- plotoutput (prob, fig, axs )
63
+ plotoutput (prob, ax )
67
64
end
0 commit comments