Skip to content

Commit 31ffc5c

Browse files
authored
Merge pull request #79 from FourierFlows/FixTracerAdvDiff
Fix TracerAdvDiff module
2 parents 509f86a + 3654231 commit 31ffc5c

File tree

7 files changed

+426
-140
lines changed

7 files changed

+426
-140
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111

1212
docs/build/
1313
docs/site/
14+
coverage/

docs/src/modules/traceradvdiff.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33
### Basic Equations
44

55
This module solves the advection diffusion equation for a passive tracer
6-
concentration $c(x,y,t)$ in two-dimensions:
6+
concentration $c(x, y, t)$ in two-dimensions:
77

8-
$$\partial_t c + \boldsymbol{u} \boldsymbol{\cdot} \boldsymbol{\nabla} c = \kappa \nabla^2 c\ ,$$
8+
$$\partial_t c + \boldsymbol{u} \boldsymbol{\cdot} \boldsymbol{\nabla} c = \underbrace{\eta \partial_x^2 c + \kappa \partial_y^2 c}_{\textrm{diffusivity}} + \underbrace{\kappa_h (-1)^{n_{h}} \nabla^{2n_{h}}c}_{\textrm{hyper-diffusivity}}\ ,$$
9+
10+
where $\boldsymbol{u} = (u,v)$ is the two-dimensional advecting flow, $\eta$ the $x$-diffusivity and $\kappa$ is the $y$-diffusivity. If $\eta$ is not defined then the code uses isotropic diffusivity, i.e., $\eta \partial_x^2 c + \kappa \partial_y^2 c\mapsto\kappa\nabla^2$. The advecting flow could be either compressible or incompressible.
911

10-
where $\mathbf{u} = (u,v)$ is the two-dimensional advecting velocity and $\kappa$
11-
is the diffusivity.
1212

1313
### Implementation
1414

15-
Coming soon.
15+
The equation is time-stepped forward in Fourier space:
16+
17+
$$\partial_t \widehat{c} = - \widehat{\boldsymbol{u} \boldsymbol{\cdot} \boldsymbol{\nabla} c} - \left[ (\eta k_x^2 + \kappa k_y^2) +\kappa_h k^{2\nu_h} \right]\widehat{c}\ .$$
18+
19+
Thus:
20+
21+
```math
22+
\begin{align*}
23+
\mathcal{L} &= -\eta k_x^2 - \kappa k_y^2 - \kappa_h k^{2\nu_h}\ , \\
24+
\mathcal{N}(\widehat{c}) &= - \mathrm{FFT}(u \partial_x c + \upsilon \partial_y c)\ .
25+
\end{align*}
26+
```

examples/cudaexamples/cu_randomdecay.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TwoDTurb.set_q!(prob, q0)
1515
fig = figure(); tic()
1616
for i = 1:10
1717
stepforward!(prob, nt)
18-
TwoDTurb.updatevars!(prob)
18+
TwoDTurb.updatevars!(prob)
1919

2020
cfl = maximum(prob.vars.U)*prob.grid.dx/prob.ts.dt
2121
@printf("step: %04d, t: %6.1f, cfl: %.2f, ", prob.step, prob.t, cfl)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using FourierFlows, PyPlot, JLD2
2+
3+
import FourierFlows.TracerAdvDiff
4+
5+
# Numerical parameters and time-stepping parameters
6+
nx = 128 # 2D resolution = nx^2
7+
stepper = "RK4" # timestepper
8+
dt = 0.02 # timestep
9+
nsubs = 200 # number of time-steps for plotting
10+
nsteps = 4nsubs # total number of time-steps (must be multiple of nsubs)
11+
12+
# Physical parameters
13+
Lx = 2π # domain size
14+
kap = 0.002 # diffusivity
15+
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
21+
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;
30+
31+
# Initial condition c0 = c(x, y, t=0)
32+
amplc0, sigc0 = 0.1, 0.1
33+
c0func(x, y) = amplc0*exp(-(x^2+y^2)/(2sigc0^2))
34+
c0 = c0func.(g.X-1.2, g.Y)
35+
36+
TracerAdvDiff.set_c!(prob, c0)
37+
38+
"Plot the concentration field and the (u, v) streamlines."
39+
function plotoutput(prob, fig, axs; drawcolorbar=false)
40+
s, v, p, g = prob.state, prob.vars, prob.params, prob.grid
41+
t = round(prob.state.t, 2)
42+
43+
TracerAdvDiff.updatevars!(prob)
44+
45+
cla()
46+
pcolormesh(g.X, g.Y, v.c)
47+
48+
if drawcolorbar; colorbar(); end
49+
50+
contour(g.X, g.Y, psiin, 15, colors="k", linewidths=0.7)
51+
axis("equal")
52+
axis("square")
53+
title("shading: \$c(x, y, t= $t )\$, contours: \$\\psi(x, y)\$")
54+
55+
pause(0.001)
56+
57+
nothing
58+
end
59+
60+
fig, axs = subplots(ncols=1, nrows=1, figsize=(8, 8))
61+
plotoutput(prob, fig, axs; drawcolorbar=true)
62+
63+
while prob.step < nsteps
64+
stepforward!(prob, nsubs)
65+
plotoutput(prob, fig, axs)
66+
end

0 commit comments

Comments
 (0)