Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 1D advection-diffusion #55

Merged
merged 38 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
082752c
Add 1D advection-diffusion of passive tracer
jbisits Jun 9, 2022
acc6100
Add tests for one dimensional problem
jbisits Jun 10, 2022
787ad32
`grid.x` -> `gr.x`
jbisits Jun 10, 2022
15e73c9
Missed a comma
jbisits Jun 10, 2022
366f85e
Correct file name
jbisits Jun 10, 2022
31ae371
and in the literated part of the script
jbisits Jun 10, 2022
28cef9c
Fix file name (again) and add `Plots` to example
jbisits Jun 10, 2022
aca90c5
See if `@CUDA.allowscalar` is the fix
jbisits Jun 10, 2022
73f43dc
Was not correct, removed
jbisits Jun 10, 2022
1e01031
Add `ArrayType(dev)` to create a `CuArray`
jbisits Jun 11, 2022
f58d8ce
Try making c0 `CuArray`
jbisits Jun 11, 2022
f7b67f4
Trying another method
jbisits Jun 11, 2022
293f208
Maybe this way?
jbisits Jun 11, 2022
ff4b879
Did not seem to be the issue so changed back
jbisits Jun 11, 2022
2e42d89
`gr.x` -> `ArrayType(dev)(gr.x)`
jbisits Jun 13, 2022
5315112
Maybe this will do it
jbisits Jun 13, 2022
6277201
Update test_traceradvectiondiffusion.jl
jbisits Jun 13, 2022
fa49dda
I think this should fix it
jbisits Jun 13, 2022
a8c803d
pass `dev` to constructors
jbisits Jun 13, 2022
51f9361
`Problem(dev; parameters)` -> `Problem(dev, advecting_flow; parameters)
jbisits Jun 14, 2022
e05924e
Remove `u` and `v` from `parameters` in `celluarflow.jl`
jbisits Jun 14, 2022
6a54b9e
update compat requirements
navidcy Jun 14, 2022
0a0b859
use `x = gridpoints(::OneDGrid)`
jbisits Jun 14, 2022
6655399
Docstring update
jbisits Jun 15, 2022
0ffd42b
Another Docstring
jbisits Jun 15, 2022
6578acc
Change to using constructors for the `advecting_flow`
jbisits Jun 28, 2022
731d709
minor fiddling
navidcy Jun 29, 2022
300ec2e
bump minor release
navidcy Jun 29, 2022
d2d1537
simpler kwargs
navidcy Jun 29, 2022
9b20ebd
Change default `steadyflow` to `true`
jbisits Jun 29, 2022
d61c700
Merge branch 'add-1Dadvection-diffusion' of https://github.com/jbisit…
jbisits Jun 29, 2022
7b2622b
Change tests to match new default value for `steadyflow`
jbisits Jun 29, 2022
d08fa5c
some minor changes
navidcy Jun 29, 2022
fc3ef72
Merge branch 'add-1Dadvection-diffusion' of github.com:jbisits/Passiv…
navidcy Jun 29, 2022
0f2b4c3
homogenize some docstrings
navidcy Jun 29, 2022
af94ba2
Update examples/cellularflow.jl
jbisits Jun 29, 2022
bacae4d
update zenodo citation
navidcy Jun 29, 2022
2488c76
Merge branch 'add-1Dadvection-diffusion' of github.com:jbisits/Passiv…
navidcy Jun 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ license = "MIT"
authors = ["Navid C. Constantinou <[email protected]>", "Gregory L. Wagner <[email protected]>"]
documentation = "https://fourierflows.github.io/PassiveTracerFlowsDocumentation/dev/"
repository = "https://github.com/FourierFlows/PassiveTracerFlows.jl"
version = "0.6.1"
version = "0.7.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand All @@ -19,8 +19,8 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
CUDA = "^1.3, ^2, ^3"
DocStringExtensions = "^0.8"
FourierFlows = "^0.6.17, ^0.7, 0.8, 0.9"
DocStringExtensions = "0.8, 0.9"
FourierFlows = "0.9.2"
GeophysicalFlows = "0.14"
JLD2 = "^0.1, ^0.2, ^0.3, ^0.4"
Reexport = "^0.2, ^1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ See `examples/` for example scripts.

The code is citable via [zenodo](https://zenodo.org). Please cite as:

> Navid C. Constantinou. and Gregory L. Wagner (2022). FourierFlows/PassiveTracerFlows.jl: PassiveTracerFlows v0.6.1 (Version v0.6.1). Zenodo. [https://doi.org/10.5281/zenodo.2535983](https://doi.org/10.5281/zenodo.2535983)
> Navid C. Constantinou, Josef Bisits, and Gregory L. Wagner (2022). FourierFlows/PassiveTracerFlows.jl: PassiveTracerFlows v0.7.0 (Version v0.7.0). Zenodo. [https://doi.org/10.5281/zenodo.2535983](https://doi.org/10.5281/zenodo.2535983)

[FourierFlows.jl]: https://github.com/FourierFlows/FourierFlows.jl
2 changes: 2 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const EXAMPLES_DIR = joinpath(@__DIR__, "..", "examples")
const OUTPUT_DIR = joinpath(@__DIR__, "src/literated")

examples = [
"onedim_gaussiandiffusion.jl",
"cellularflow.jl",
"turbulent_advection-diffusion.jl"
]
Expand Down Expand Up @@ -56,6 +57,7 @@ makedocs(
"Home" => "index.md",
"Examples" => Any[
"TracerAdvectionDiffusion" => Any[
"literated/onedim_gaussiandiffusion.md",
"literated/cellularflow.md",
"literated/turbulent_advection-diffusion.md",
]
Expand Down
6 changes: 4 additions & 2 deletions examples/cellularflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ nothing # hide
# ## Set up cellular flow
# We create a two-dimensional grid to construct the cellular flow. Our cellular flow is derived
# from a streamfunction ``ψ(x, y) = ψ₀ \cos(x) \cos(y)`` as ``(u, v) = (-∂_y ψ, ∂_x ψ)``.
# The cellular flow is then passed into the `TwoDAdvectingFlow` constructor with `steadyflow = true`
# to indicate that the flow is not time dependent.
grid = TwoDGrid(n, L)

ψ₀ = 0.2
Expand All @@ -54,13 +56,13 @@ mx, my = 1, 1

uvel(x, y) = ψ₀ * my * cos(mx * x) * sin(my * y)
vvel(x, y) = -ψ₀ * mx * sin(mx * x) * cos(my * y)
advecting_flow = TwoDAdvectingFlow(; u = uvel, v = vvel, steadyflow = true)
nothing # hide


# ## Problem setup
# We initialize a `Problem` by providing a set of keyword arguments.
prob = TracerAdvectionDiffusion.Problem(dev; nx=n, Lx=L, κ=κ, steadyflow=true, u=uvel, v=vvel,
dt=dt, stepper=stepper)
prob = TracerAdvectionDiffusion.Problem(dev, advecting_flow; nx=n, Lx=L, κ, dt, stepper)
nothing # hide

# and define some shortcuts
Expand Down
130 changes: 130 additions & 0 deletions examples/onedim_gaussiandiffusion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# # Advection-diffusion of tracer in one dimension
#
# This is an example demonstrating the advection-diffusion of a passive tracer in
# one dimension.
#
# ## Install dependencies
#
# First let's make sure we have all the required packages installed

# ```julia
# using Pkg
# pkg.add(["PassiveTracerFlows", "Printf", "Plots", "JLD2"])
# ```
#
# ## Let's begin
# First load packages needed to run this example.
using PassiveTracerFlows, Plots, Printf, JLD2, LinearAlgebra

# ## Choosing a device: CPU or GPU

dev = CPU() # Device (CPU/GPU)
nothing # hide


# ## Numerical parameters and time-stepping parameters

n = 128 # 2D resolution = n²
stepper = "RK4" # timestepper
dt = 0.02 # timestep
nsteps = 5000 # total number of time-steps
nothing # hide


# ## Physical parameters

L = 2π # domain size
κ = 0.01 # diffusivity
nothing # hide

# ## Flow
# We set a constant background flow and pass this to `OneDAdvectingFlow` with `steadyflow = true` to indicate the flow is not time dependent.
u(x) = 0.05
advecting_flow = OneDAdvectingFlow(; u, steadyflow = true)

# ## Problem setup
# We initialize a `Problem` by providing a set of keyword arguments.
prob = TracerAdvectionDiffusion.Problem(dev, advecting_flow; nx=n, Lx=L, κ, dt, stepper)
nothing # hide

# and define some shortcuts
sol, clock, vars, params, grid = prob.sol, prob.clock, prob.vars, prob.params, prob.grid
x = grid.x

# ## Initial condition
# We advect-diffuse a concentration field that has an initial concentration set to Gaussian.
gaussian(x, σ) = exp(-x^2 / 2σ^2)

amplitude, spread = 1, 0.15
c₀ = [amplitude * gaussian(x[i], spread) for i in 1:grid.nx]

TracerAdvectionDiffusion.set_c!(prob, c₀)
nothing #hide

# ## Saving output
# We create the saved output using the `Output` function from `FourierFlows.jl` then
# save the concentration field using the `get_concentration` function every 50 timesteps.
function get_concentration(prob)
ldiv!(prob.vars.c, prob.grid.rfftplan, deepcopy(prob.sol))

return prob.vars.c
end

output = Output(prob, "advection-diffusion1D.jld2",
(:concentration, get_concentration))

# By calling `saveproblem(output)` we save information that we will use for plotting later on.
saveproblem(output)

# ## Stepping the problem forward
# Now we step the problem forward and save output every 50 timesteps.

save_frequency = 50 # frequency at which output is saved

startwalltime = time()
while clock.step <= nsteps
if clock.step % save_frequency == 0
saveoutput(output)
log = @sprintf("Output saved, step: %04d, t: %.2f, walltime: %.2f min",
clock.step, clock.t, (time()-startwalltime) / 60)

println(log)
end

stepforward!(prob)
end

# ## Visualising the output
# We load the `.jld2` file and create a timeseries of the concentration field
file = jldopen(output.path)

iterations = parse.(Int, keys(file["snapshots/t"]))

t = [file["snapshots/t/$i"] for i ∈ iterations]
c = [file["snapshots/concentration/$i"] for i ∈ iterations]
nothing # hide

# Set up the plotting arguments and look at the initial concentration.
x, Lx = file["grid/x"], file["grid/Lx"]

plot_args = (xlabel = "x",
ylabel = "c",
framestyle = :box,
xlims = (-Lx/2, Lx/2),
ylims = (0, maximum(c[1])),
legend = :false,
color = :balance)

p = plot(x, Array(c[1]);
title = "concentration, t = " * @sprintf("%.2f", t[1]),
plot_args...)
nothing # hide

# Now, we create a movie of the tracer concentration being advected and diffused.

anim = @animate for i ∈ 1:length(t)
p[1][:title] = "concentration, t = " * @sprintf("%.2f", t[i])
p[1][1][:y] = Array(c[i])
end

mp4(anim, "1D_advection-diffusion.mp4", fps = 12)
Loading