Skip to content

Commit 50c6654

Browse files
authored
Merge pull request DJ4Earth#19 from swilliamson7/main
Small edits
2 parents 6e73373 + 02783e1 commit 50c6654

File tree

7 files changed

+218
-201
lines changed

7 files changed

+218
-201
lines changed

.DS_Store

0 Bytes
Binary file not shown.

explicit_solver/advance.jl

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,61 @@
66
# RHS_terms separate from the states was no longer a good idea.
77

88

9-
function advance(u_v_eta::gyre_vector,
10-
grid::Grid,
11-
rhs::RHS_terms,
12-
params::Params,
13-
interp::Interps,
14-
grad::Derivatives,
15-
advec::Advection
16-
)
9+
# function advance(u_v_eta::gyre_vector,
10+
# grid::Grid,
11+
# rhs::RHS_terms,
12+
# params::Params,
13+
# interp::Interps,
14+
# grad::Derivatives,
15+
# advec::Advection
16+
# )
1717

18-
nx = grid.nx
19-
dt = params.dt
18+
# nx = grid.nx
19+
# dt = params.dt
2020

21-
# we now use RK4 as the timestepper, here I'm storing the coefficients needed for this
22-
rk_a = [1/6, 1/3, 1/3, 1/6]
23-
rk_b = [1/2, 1/2, 1.]
21+
# # we now use RK4 as the timestepper, here I'm storing the coefficients needed for this
22+
# rk_a = [1/6, 1/3, 1/3, 1/6]
23+
# rk_b = [1/2, 1/2, 1.]
2424

25-
rhs.umid .= u_v_eta.u
26-
rhs.vmid .= u_v_eta.v
27-
rhs.etamid .= u_v_eta.eta
25+
# rhs.umid .= u_v_eta.u
26+
# rhs.vmid .= u_v_eta.v
27+
# rhs.etamid .= u_v_eta.eta
2828

29-
rhs.u0 .= u_v_eta.u
30-
rhs.v0 .= u_v_eta.v
31-
rhs.eta0 .= u_v_eta.eta
29+
# rhs.u0 .= u_v_eta.u
30+
# rhs.v0 .= u_v_eta.v
31+
# rhs.eta0 .= u_v_eta.eta
3232

33-
rhs.u1 .= u_v_eta.u
34-
rhs.v1 .= u_v_eta.v
35-
rhs.eta1 .= u_v_eta.eta
33+
# rhs.u1 .= u_v_eta.u
34+
# rhs.v1 .= u_v_eta.v
35+
# rhs.eta1 .= u_v_eta.eta
3636

37-
for j in 1:4
37+
# @inbounds for j in 1:4
3838

39-
comp_u_v_eta_t(nx, rhs, params, interp, grad, advec)
39+
# comp_u_v_eta_t(nx, rhs, params, interp, grad, advec)
4040

41-
if j < 4
42-
rhs.u1 .= rhs.umid .+ rk_b[j] .* dt .* rhs.u_t
43-
rhs.v1 .= rhs.vmid .+ rk_b[j] .* dt .* rhs.v_t
44-
rhs.eta1 .= rhs.etamid .+ rk_b[j] .* dt .* rhs.eta_t
45-
end
41+
# if j < 4
42+
# rhs.u1 .= rhs.umid .+ rk_b[j] .* dt .* rhs.u_t
43+
# rhs.v1 .= rhs.vmid .+ rk_b[j] .* dt .* rhs.v_t
44+
# rhs.eta1 .= rhs.etamid .+ rk_b[j] .* dt .* rhs.eta_t
45+
# end
4646

47-
rhs.u0 .= rhs.u0 .+ rk_a[j] .* dt .* rhs.u_t
48-
rhs.v0 .= rhs.v0 .+ rk_a[j] .* dt .* rhs.v_t
49-
rhs.eta0 .= rhs.eta0 .+ rk_a[j] .* dt .* rhs.eta_t
47+
# rhs.u0 .= rhs.u0 .+ rk_a[j] .* dt .* rhs.u_t
48+
# rhs.v0 .= rhs.v0 .+ rk_a[j] .* dt .* rhs.v_t
49+
# rhs.eta0 .= rhs.eta0 .+ rk_a[j] .* dt .* rhs.eta_t
5050

51-
end
51+
# end
5252

53-
@assert all(x -> x < 7.0, rhs.u0)
54-
@assert all(x -> x < 7.0, rhs.v0)
55-
@assert all(x -> x < 7.0, rhs.eta0)
53+
# @assert all(x -> x < 7.0, rhs.u0)
54+
# @assert all(x -> x < 7.0, rhs.v0)
55+
# @assert all(x -> x < 7.0, rhs.eta0)
5656

57-
copyto!(u_v_eta.u, rhs.u0)
58-
copyto!(u_v_eta.v, rhs.v0)
59-
copyto!(u_v_eta.eta, rhs.eta0)
57+
# copyto!(u_v_eta.u, rhs.u0)
58+
# copyto!(u_v_eta.v, rhs.v0)
59+
# copyto!(u_v_eta.eta, rhs.eta0)
6060

61-
return nothing
61+
# return nothing
6262

63-
end
63+
# end
6464

6565
function advance(states_rhs::SWM_pde,
6666
grid::Grid,
@@ -70,12 +70,8 @@ function advance(states_rhs::SWM_pde,
7070
advec::Advection
7171
)
7272

73-
nx = grid.nx
74-
dt = params.dt
75-
76-
# we now use RK4 as the timestepper, here I'm storing the coefficients needed for this
77-
rk_a = [1/6, 1/3, 1/3, 1/6]
78-
rk_b = [1/2, 1/2, 1.]
73+
@unpack nx = grid
74+
@unpack dt, rk_a, rk_b = params
7975

8076
states_rhs.umid .= states_rhs.u
8177
states_rhs.vmid .= states_rhs.v
@@ -89,9 +85,9 @@ function advance(states_rhs::SWM_pde,
8985
states_rhs.v1 .= states_rhs.v
9086
states_rhs.eta1 .= states_rhs.eta
9187

92-
for j in 1:4
88+
@inbounds for j in 1:4
9389

94-
comp_u_v_eta_t!(nx, states_rhs, params, interp, grad, advec)
90+
comp_u_v_eta_t(nx, states_rhs, params, interp, grad, advec)
9591

9692
if j < 4
9793
states_rhs.u1 .= states_rhs.umid .+ rk_b[j] .* dt .* states_rhs.u_t
@@ -145,7 +141,7 @@ function integrate(days, nx, ny; Lx = 3840e3, Ly = 3840e3)
145141
)
146142

147143
@time for t in 1:T
148-
advance!(states_rhs, grid, params, interp, grad, advec)
144+
advance(states_rhs, grid, params, interp, grad, advec)
149145
copyto!(states_rhs.u, states_rhs.u0)
150146
copyto!(states_rhs.v, states_rhs.v0)
151147
copyto!(states_rhs.eta, states_rhs.eta0)

explicit_solver/build_grid.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,24 @@ end
4848

4949
# This function will just serve to take the vectors containing state information
5050
# and transform them to matrices
51-
function vec_to_mat(u, v, eta, grid)
51+
function vec_to_mat(states, grid)
5252

5353
state_matrices = gyre_matrix(
54-
reshape(u, grid.nx-1, grid.ny)',
55-
reshape(v, grid.nx, grid.ny-1)',
56-
reshape(eta, grid.nx, grid.ny)'
54+
reshape(states.u, grid.nx-1, grid.ny)',
55+
reshape(states.v, grid.nx, grid.ny-1)',
56+
reshape(states.eta, grid.nx, grid.ny)'
5757
)
5858

5959
return state_matrices
6060

6161
end
6262

63-
function mat_to_vec(um, vm, etam, grid)
63+
function mat_to_vec(states_mat, grid)
6464

6565
state_vectors = gyre_vector(
66-
reshape(um', grid.Nu),
67-
reshape(vm', grid.Nv),
68-
reshape(etam', grid.NT)
66+
reshape(states_mat.u', grid.Nu),
67+
reshape(states_mat.v', grid.Nv),
68+
reshape(states_mat.eta', grid.NT)
6969
)
7070

7171
return state_vectors

explicit_solver/compute_time_deriv.jl

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,57 @@
22
# computes the advection term (needed for the time derivatives). Two versions of each function
33
# are defined, each just depends on what type of structure I'm passing for RHS
44

5-
function comp_u_v_eta_t!(
6-
nx::Int,
7-
rhs::RHS_terms,
8-
params::Params,
9-
interp::Interps,
10-
grad::Derivatives,
11-
advec::Advection
12-
)
13-
14-
rhs.h .= rhs.eta1 .+ params.H
15-
16-
rhs.h_u .= interp.ITu * rhs.h
17-
rhs.h_v .= interp.ITv * rhs.h
18-
rhs.h_q .= interp.ITq * rhs.h
19-
20-
rhs.U .= rhs.u1 .* rhs.h_u
21-
rhs.V .= rhs.v1 .* rhs.h_v
22-
23-
rhs.kinetic .= interp.IuT * (rhs.u1.^2) .+ interp.IvT * (rhs.v1.^2)
24-
25-
# Kloewer defined new terms q and p corresponding to potential vorticity and
26-
# Bernoulli potential respectively. To avoid errors in my mimic I'm following
27-
# along and doing the same
28-
rhs.q .= (params.coriolis .+ grad.Gvx * rhs.v1 .- grad.Guy * rhs.u1) ./ rhs.h_q
29-
rhs.p .= 0.5 .* rhs.kinetic .+ params.g .* rhs.h
30-
31-
# bottom friction
32-
rhs.kinetic_sq .= sqrt.(rhs.kinetic)
33-
rhs.bfric_u .= params.bottom_drag .* ((interp.ITu * rhs.kinetic_sq) .* rhs.u1) ./ rhs.h_u
34-
rhs.bfric_v .= params.bottom_drag .* ((interp.ITv * rhs.kinetic_sq) .* rhs.v1) ./ rhs.h_v
35-
36-
# deal with the advection term
37-
comp_advection(nx, rhs, advec)
38-
39-
# rhs.Mu .= params.A_h .* (grad.LLu * rhs.u1)
40-
# rhs.Mv .= params.A_h .* (grad.LLv * rhs.v1)
5+
# function comp_u_v_eta_t(
6+
# nx::Int,
7+
# rhs::RHS_terms,
8+
# params::Params,
9+
# interp::Interps,
10+
# grad::Derivatives,
11+
# advec::Advection
12+
# )
13+
14+
# rhs.h .= rhs.eta1 .+ params.H
15+
16+
# rhs.h_u .= interp.ITu * rhs.h
17+
# rhs.h_v .= interp.ITv * rhs.h
18+
# rhs.h_q .= interp.ITq * rhs.h
19+
20+
# rhs.U .= rhs.u1 .* rhs.h_u
21+
# rhs.V .= rhs.v1 .* rhs.h_v
22+
23+
# rhs.kinetic .= interp.IuT * (rhs.u1.^2) .+ interp.IvT * (rhs.v1.^2)
24+
25+
# # Kloewer defined new terms q and p corresponding to potential vorticity and
26+
# # Bernoulli potential respectively. To avoid errors in my mimic I'm following
27+
# # along and doing the same
28+
# rhs.q .= (params.coriolis .+ grad.Gvx * rhs.v1 .- grad.Guy * rhs.u1) ./ rhs.h_q
29+
# rhs.p .= 0.5 .* rhs.kinetic .+ params.g .* rhs.h
30+
31+
# # bottom friction
32+
# rhs.kinetic_sq .= sqrt.(rhs.kinetic)
33+
# rhs.bfric_u .= params.bottom_drag .* ((interp.ITu * rhs.kinetic_sq) .* rhs.u1) ./ rhs.h_u
34+
# rhs.bfric_v .= params.bottom_drag .* ((interp.ITv * rhs.kinetic_sq) .* rhs.v1) ./ rhs.h_v
35+
36+
# # deal with the advection term
37+
# comp_advection(nx, rhs, advec)
38+
39+
# # rhs.Mu .= params.A_h .* (grad.LLu * rhs.u1)
40+
# # rhs.Mv .= params.A_h .* (grad.LLv * rhs.v1)
4141

42-
rhs.Mu .= (interp.ITu * params.nu) .* (grad.LLu * rhs.u1)
43-
rhs.Mv .= (interp.ITv * params.nu) .* (grad.LLv * rhs.v1)
42+
# rhs.Mu .= (interp.ITu * params.nu) .* (grad.LLu * rhs.u1)
43+
# rhs.Mv .= (interp.ITv * params.nu) .* (grad.LLv * rhs.v1)
4444

45-
rhs.u_t .= rhs.adv_u .- grad.GTx * rhs.p .+ params.wind_stress ./ rhs.h_u .- rhs.Mu .- rhs.bfric_u
45+
# rhs.u_t .= rhs.adv_u .- grad.GTx * rhs.p .+ params.wind_stress ./ rhs.h_u .- rhs.Mu .- rhs.bfric_u
4646

47-
rhs.v_t .= rhs.adv_v .- grad.GTy * rhs.p .- rhs.Mv .- rhs.bfric_v
47+
# rhs.v_t .= rhs.adv_v .- grad.GTy * rhs.p .- rhs.Mv .- rhs.bfric_v
4848

49-
rhs.eta_t .= - (grad.Gux * rhs.U .+ grad.Gvy * rhs.V)
49+
# rhs.eta_t .= - (grad.Gux * rhs.U .+ grad.Gvy * rhs.V)
5050

51-
return nothing
51+
# return nothing
5252

53-
end
53+
# end
5454

55-
function comp_u_v_eta_t!(nx::Int,
55+
function comp_u_v_eta_t(nx::Int,
5656
rhs::SWM_pde,
5757
params::Params,
5858
interp::Interps,
@@ -83,25 +83,25 @@ function comp_u_v_eta_t!(nx::Int,
8383
rhs.bfric_v .= params.bottom_drag .* ((interp.ITv * rhs.kinetic_sq) .* rhs.v1) ./ rhs.h_v
8484

8585
# deal with the advection term
86-
comp_advection!(nx, rhs, advec)
86+
comp_advection(nx, rhs, advec)
8787

8888
# rhs.Mu .= params.A_h .* (grad.LLu * rhs.u1)
8989
# rhs.Mv .= params.A_h .* (grad.LLv * rhs.v1)
9090

91+
### Important: Need to apply Laplacian to nu for when nu varies spatially ##################
9192
rhs.Mu .= (interp.ITu * params.nu) .* (grad.LLu * rhs.u1)
9293
rhs.Mv .= (interp.ITv * params.nu) .* (grad.LLv * rhs.v1)
9394

9495
rhs.u_t .= rhs.adv_u .- grad.GTx * rhs.p .+ params.wind_stress ./ rhs.h_u .- rhs.Mu .- rhs.bfric_u
95-
9696
rhs.v_t .= rhs.adv_v .- grad.GTy * rhs.p .- rhs.Mv .- rhs.bfric_v
97-
9897
rhs.eta_t .= - (grad.Gux * rhs.U .+ grad.Gvy * rhs.V)
9998

10099
return nothing
101100

102101
end
103102

104-
function comp_advection!(
103+
# Arakawa and Lamb advection scheme
104+
function comp_advection(
105105
nx::Int,
106106
rhs::SWM_pde,
107107
advec::Advection
@@ -132,29 +132,29 @@ function comp_advection!(
132132

133133
end
134134

135-
function comp_advection(nx::Int, rhs::RHS_terms, advec::Advection)
135+
# function comp_advection(nx::Int, rhs::RHS_terms, advec::Advection)
136136

137-
rhs.AL1q .= advec.AL1 * rhs.q
138-
rhs.AL2q .= advec.AL2 * rhs.q
137+
# rhs.AL1q .= advec.AL1 * rhs.q
138+
# rhs.AL2q .= advec.AL2 * rhs.q
139139

140-
AL1q_au = @view rhs.AL1q[1:end-nx]
141-
AL2q_bu = @view rhs.AL2q[nx+1:end]
142-
AL2q_cu = @view rhs.AL2q[1:end-nx]
143-
AL1q_du = @view rhs.AL1q[nx+1:end]
140+
# AL1q_au = @view rhs.AL1q[1:end-nx]
141+
# AL2q_bu = @view rhs.AL2q[nx+1:end]
142+
# AL2q_cu = @view rhs.AL2q[1:end-nx]
143+
# AL1q_du = @view rhs.AL1q[nx+1:end]
144144

145-
AL1q_av = @view rhs.AL1q[advec.index_av]
146-
AL2q_bv = @view rhs.AL2q[advec.index_bv]
147-
AL2q_cv = @view rhs.AL2q[advec.index_cv]
148-
AL1q_dv = @view rhs.AL1q[advec.index_dv]
145+
# AL1q_av = @view rhs.AL1q[advec.index_av]
146+
# AL2q_bv = @view rhs.AL2q[advec.index_bv]
147+
# AL2q_cv = @view rhs.AL2q[advec.index_cv]
148+
# AL1q_dv = @view rhs.AL1q[advec.index_dv]
149149

150-
rhs.adv_u .= advec.Seur * (advec.ALeur * rhs.q .* rhs.U) .+ advec.Seul * (advec.ALeul * rhs.q .* rhs.U) .+
151-
advec.Sau * (AL1q_au .* rhs.V) .+ advec.Sbu * (AL2q_bu .* rhs.V) .+
152-
advec.Scu * (AL2q_cu .* rhs.V) .+ advec.Sdu * (AL1q_du .* rhs.V)
150+
# rhs.adv_u .= advec.Seur * (advec.ALeur * rhs.q .* rhs.U) .+ advec.Seul * (advec.ALeul * rhs.q .* rhs.U) .+
151+
# advec.Sau * (AL1q_au .* rhs.V) .+ advec.Sbu * (AL2q_bu .* rhs.V) .+
152+
# advec.Scu * (AL2q_cu .* rhs.V) .+ advec.Sdu * (AL1q_du .* rhs.V)
153153

154-
rhs.adv_v .= advec.Spvu * ((advec.ALpvu * rhs.q) .* rhs.V) .+ advec.Spvd * ((advec.ALpvd * rhs.q) .* rhs.V) .-
155-
advec.Sav * (AL1q_av .* rhs.U) .- advec.Sbv * (AL2q_bv .* rhs.U) .-
156-
advec.Scv * (AL2q_cv .* rhs.U) .- advec.Sdv * (AL1q_dv .* rhs.U)
154+
# rhs.adv_v .= advec.Spvu * ((advec.ALpvu * rhs.q) .* rhs.V) .+ advec.Spvd * ((advec.ALpvd * rhs.q) .* rhs.V) .-
155+
# advec.Sav * (AL1q_av .* rhs.U) .- advec.Sbv * (AL2q_bv .* rhs.U) .-
156+
# advec.Scv * (AL2q_cv .* rhs.U) .- advec.Sdv * (AL1q_dv .* rhs.U)
157157

158-
return nothing
158+
# return nothing
159159

160-
end
160+
# end

0 commit comments

Comments
 (0)