-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdiffusion_1D_2procs.jl
45 lines (42 loc) · 1.47 KB
/
diffusion_1D_2procs.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Linear 1D diffusion with 2 fake mpi processes
using Plots
# enable plotting by default
if !@isdefined do_visu; do_visu = true end
@views function diffusion_1D_2procs(; do_visu=true)
# Physics
Hl = 10.0 # left H
Hr = 1.0 # right H
λ = 1.0 # diffusion coeff
nt = 200 # number of time steps
# Numerics
nx = 32 # number of local grid points
dx = 1.0 # cell size
# Derived numerics
dt = dx^2/λ/2.1
# Initial condition
HL = Hl*ones(nx)
HR = Hr*ones(nx)
H = [HL[1:end-1]; HR[2:end]]
Hg = copy(H)
# Time loop
for it = 1:nt
# Compute physics locally
HL[2:end-1] .= HL[2:end-1] .+ dt*λ*diff(diff(HL)/dx)/dx
HR[2:end-1] .= HR[2:end-1] .+ dt*λ*diff(diff(HR)/dx)/dx
# Update boundaries (MPI)
HL[end] = HR[2]
HR[1] = HL[end-1]
# Global picture
H .= [HL[1:end-1]; HR[2:end]]
# Compute physics globally (check)
Hg[2:end-1] .= Hg[2:end-1] .+ dt*λ*diff(diff(Hg)/dx)/dx
# Visualise
if do_visu
fontsize = 12
plot(Hg, legend=false, linewidth=0, markershape=:circle, markersize=5, yaxis=font(fontsize, "Courier"), xaxis=font(fontsize, "Courier"), titlefontsize=fontsize, titlefont="Courier")
display(plot!(H, legend=false, linewidth=3, framestyle=:box, xlabel="Lx", ylabel="H", title="diffusion (it=$(it))"))
end
end
return
end
diffusion_1D_2procs(; do_visu=do_visu)