-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchannel_flow.jl
More file actions
149 lines (121 loc) · 4.85 KB
/
channel_flow.jl
File metadata and controls
149 lines (121 loc) · 4.85 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# %%
using Random
using Printf
using JLD2
using CUDA
using CSV
using DataFrames
using Dierckx
using SeawaterPolynomials.TEOS10
using GibbsSeaWater
using Statistics
using NetCDF
using Glob
using Interpolations
using Adapt
using Roots
using Oceananigans
using Oceananigans.Units: minute, minutes, hour, hours, day, second, meters
using Oceananigans.TurbulenceClosures: AnisotropicMinimumDissipation, implicit_diffusion_solver
using Oceananigans.Grids: xnode, ynode, znode
using Oceananigans.BuoyancyModels: ρ′, thermal_expansionᶜᶜᶜ, haline_contractionᶜᶜᶜ, ∂z_b
using Oceananigans.Fields
using Oceananigans.Operators
using Oceananigans.Operators: ℑxᶜᵃᵃ, ℑxᶠᵃᵃ,ℑyᵃᶜᵃ, ℑyᵃᶠᵃ,ℑzᵃᵃᶜ, ℑzᵃᵃᶠ,ℑxyᶜᶜᵃ,ℑxzᶜᵃᶜ,ℑyzᵃᶜᶜ
using Oceananigans.Operators: δxᶜᵃᵃ,δxᶠᵃᵃ,δyᵃᶜᵃ,δyᵃᶠᵃ,δzᵃᵃᶜ,δzᵃᵃᶠ
using Oceananigans.Models: seawater_density
# using Oceanostics: IsotropicKineticEnergyDissipationRate, ZShearProductionRate
δ = 1
Lx = 4π*δ
Ly = 2π*δ
Lz = 2*δ
Nx = 180
Ny = 120
Nz = 192
Re_t = 180
ub = 2/3
z_faces(k) = - Lz/2 * cos(π * (k - 1) / Nz)
# z_faces(k) = Lz/2 * (k - Nz/2) / (Nz/2)
# Nz = 132
# z_faces(k) = Lz/2 * tanh((y - 96) / 90) / 0.788
# Nz = 198
# z_faces(k) = tanh((k - 100) / 40) / 0.9859328
Nh = 3
grid = RectilinearGrid(GPU(),
size = (Nx, Ny, Nz),
topology=(Oceananigans.Periodic, Oceananigans.Periodic, Bounded),
x = (0, Lx),
y = (0, Ly),
z = z_faces,
halo = (Nh, Nh, Nh),
)
@info "Build a grid:"
@show grid
# %%
# boundary conditions: inflow and outflow in y
# u_bc = OpenBoundaryCondition(1.0)
u_bcs = FieldBoundaryConditions(top = ValueBoundaryCondition(0), bottom = ValueBoundaryCondition(0))
v_bcs = FieldBoundaryConditions(top = ValueBoundaryCondition(0), bottom = ValueBoundaryCondition(0))
w_bcs = FieldBoundaryConditions(top = OpenBoundaryCondition(0) , bottom = OpenBoundaryCondition(0) )
dp_dx(x, y, z, t) = 0.00176
u_forcing = Forcing(dp_dx)
@info "Conditions required for model are done"
# %%
model = NonhydrostaticModel(; grid,
coriolis = nothing,
buoyancy = nothing,
closure = ScalarDiffusivity(ν=2.3310e-4), #, κ=1/395 #VerticallyImplicitTimeDiscretization(),
timestepper = :RungeKutta3,
advection = WENO(grid, order=5), #UpwindBiasedFifthOrder(),
# tracers = :mass,
boundary_conditions = (u=u_bcs, v=v_bcs, w=w_bcs),
forcing = (u=u_forcing, ),
)
@info "Constructed a model"
@show model
# %%
# noise(x, y, z) = 1e-2 * randn() * (-(z)^2 + 1)
# U∞(x, y, z) = 60exp(-z^20)-22.1 + noise(x, y, z)
U∞(x, y, z) = (1 + randn()/3) * ub * z * exp(-9/2 * z^2) * cos(π * y * Re_t / 100*δ) + 3 * ub * ((z+1) - 0.5 * (z+1)^2)
V∞(x, y, z) = (1 + randn()/3) * ub * z * exp(-9/2 * z^2) * sin(2π * x * Re_t / 250*δ)
# U∞(x, y, z) = (ub+0.1)*(exp(-z^20) - 0.36787944) / 0.632103306 # + noise(x, y, z)
# vᵢ(x, y, z) = noise(x, y, z)
mᵢ(x, y, z) = 1.0
set!(model, u=U∞, v=V∞, w=V∞) #, mass=mᵢ
wall_clock = time_ns()
function progress(sim)
u_max = maximum(abs, interior(model.velocities.u))
v_max = maximum(abs, interior(model.velocities.v))
w_max = maximum(abs, interior(model.velocities.w))
@info(@sprintf("Iter: %d, time: %s, Δt: %s, max|u|: %.2f, max|v|: %.5f, max|w|: %.5f, wall time: %s\n",
sim.model.clock.iteration,
prettytime(sim.model.clock.time),
prettytime(sim.Δt),
u_max, v_max, w_max,
prettytime(1e-9 * (time_ns() - wall_clock[1])), ))
return nothing
end
simulation = Simulation(model, Δt=1e-4, stop_time=1hour)
simulation.callbacks[:progress] = Callback(progress, IterationInterval(200))
wizard = TimeStepWizard(cfl=0.2, max_change=1.05, max_Δt=1, min_Δt=1e-5)
simulation.callbacks[:wizard] = Callback(wizard, IterationInterval(1))
@info "model initial conditions are Set!!"
# Output: primitive fields + computations
# u, v, w, pHY′, pNHS, mass = merge(model.velocities, model.pressures, model.tracers)
# p = Field(model.pressures.pNHS + model.pressures.pHY′)
outputs = model.velocities #merge(model.velocities, model.tracers)
simulation.output_writers[:fields] = NetCDFOutputWriter(model, outputs;
filename = joinpath(@__DIR__, "channel_flow-new.nc"),
schedule = TimeInterval(6),
overwrite_existing = true,
with_halos = true
)
# #####
# ##### Build checkpointer and output writer
# #####
simulation.output_writers[:checkpointer] = Checkpointer(model,
schedule = TimeInterval(30),
prefix = "checkpoint",
cleanup=true)
@info "Output files gererated"
run!(simulation) #, pickup=true)