Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Couple the HBModel and SWModel for use in the Split-Explicit Stepper #1268

Merged
merged 3 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
72 changes: 72 additions & 0 deletions experiments/OceanBoxGCM/refvals/ocean_gyre_refvals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ varr = [
3.78116102589123325624e-10,
1.07073256826409470244e-05,
],
[
"s_aux",
"uᵈ[1]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
[
"s_aux",
"uᵈ[2]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
[
"s_aux",
"ΔGᵘ[1]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
[
"s_aux",
"ΔGᵘ[2]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
]
parr = [
["Q", "u[1]", 12, 12, 12, 12],
Expand All @@ -115,6 +147,10 @@ parr = [
["s_aux", :w, 12, 12, 12, 12],
["s_aux", :pkin, 12, 12, 12, 12],
["s_aux", :wz0, 12, 12, 8, 12],
["s_aux", "uᵈ[1]", 12, 12, 12, 12],
["s_aux", "uᵈ[2]", 12, 12, 12, 12],
["s_aux", "ΔGᵘ[1]", 12, 12, 12, 12],
["s_aux", "ΔGᵘ[2]", 12, 12, 12, 12],
]
# END SCPRINT
# SC ====================================================================================
Expand Down Expand Up @@ -197,6 +233,38 @@ varr = [
4.05688221636862481177e-10,
1.10561449663397378925e-05,
],
[
"s_aux",
"uᵈ[1]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
[
"s_aux",
"uᵈ[2]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
[
"s_aux",
"ΔGᵘ[1]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
[
"s_aux",
"ΔGᵘ[2]",
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
0.00000000000000000000e+00,
],
]
parr = [
["Q", "u[1]", 12, 12, 12, 12],
Expand All @@ -207,6 +275,10 @@ parr = [
["s_aux", :w, 12, 12, 12, 12],
["s_aux", :pkin, 12, 12, 12, 12],
["s_aux", :wz0, 12, 12, 8, 12],
["s_aux", "uᵈ[1]", 12, 12, 12, 12],
["s_aux", "uᵈ[2]", 12, 12, 12, 12],
["s_aux", "ΔGᵘ[1]", 12, 12, 12, 12],
["s_aux", "ΔGᵘ[2]", 12, 12, 12, 12],
]
# END SCPRINT
# SC ====================================================================================
Expand Down
115 changes: 50 additions & 65 deletions src/Numerics/ODESolvers/SplitExplicitMethod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ mutable struct SplitExplicitSolver{SS, FS, RT, MSA} <: AbstractODESolver
dt::RT
"time"
t::RT
"flag to couple the models"
coupled
"storage for transfer tendency"
dQ2fast::MSA

Expand All @@ -47,20 +45,20 @@ mutable struct SplitExplicitSolver{SS, FS, RT, MSA} <: AbstractODESolver
Q = nothing;
dt = getdt(slow_solver),
t0 = slow_solver.t,
coupled = true,
) where {AT <: AbstractArray}
SS = typeof(slow_solver)
FS = typeof(fast_solver)
RT = real(eltype(slow_solver.dQ))

dQ2fast = similar(slow_solver.dQ)
dQ2fast .= -0
MSA = typeof(dQ2fast)

return new{SS, FS, RT, MSA}(
slow_solver,
fast_solver,
RT(dt),
RT(t0),
coupled,
dQ2fast,
)
end
Expand Down Expand Up @@ -95,53 +93,28 @@ function dostep!(

# Initialize fast model and tendency adjustment
# before evalution of slow mode
if split.coupled
initialize_states!(
slow_bl,
fast_bl,
slow.rhs!,
fast.rhs!,
Qslow,
Qfast,
)

# Evaluate the slow mode
# --> save tendency for the fast
slow.rhs!(dQ2fast, Qslow, param, slow_stage_time, increment = false)

# vertically integrate slow tendency to advance fast equation
# and use vertical mean for slow model (negative source)
# ---> work with dQ2fast as input
tendency_from_slow_to_fast!(
slow_bl,
fast_bl,
slow.rhs!,
fast.rhs!,
Qslow,
Qfast,
dQ2fast,
)
end
initialize_states!(slow_bl, fast_bl, slow.rhs!, fast.rhs!, Qslow, Qfast)

# Evaluate the slow mode
# --> save tendency for the fast
slow.rhs!(dQ2fast, Qslow, param, slow_stage_time, increment = false)

# vertically integrate slow tendency to advance fast equation
# and use vertical mean for slow model (negative source)
# ---> work with dQ2fast as input
tendency_from_slow_to_fast!(
slow_bl,
fast_bl,
slow.rhs!,
fast.rhs!,
Qslow,
Qfast,
dQ2fast,
)

# Compute (and RK update) slow tendency
slow.rhs!(dQslow, Qslow, param, slow_stage_time, increment = true)

# Update (RK-stage) slow state
event = Event(array_device(Qslow))
event = update!(array_device(Qslow), groupsize)(
realview(dQslow),
realview(Qslow),
slow.RKA[slow_s % length(slow.RKA) + 1],
slow.RKB[slow_s],
slow_dt,
nothing,
nothing,
nothing;
ndrange = length(realview(Qslow)),
dependencies = (event,),
)
wait(array_device(Qslow), event)

# Fractional time for slow stage
if slow_s == length(slow.RKA)
γ = 1 - slow.RKC[slow_s]
Expand All @@ -159,30 +132,42 @@ function dostep!(
for substep in 1:nsubsteps
fast_time = slow_stage_time + (substep - 1) * fast_dt
dostep!(Qfast, fast, param, fast_time)
if split.coupled
cummulate_fast_solution!(
slow_bl,
fast_bl,
fast.rhs!,
Qfast,
fast_time,
fast_dt,
substep,
)
end
end

# reconcile slow equation using fast equation
if split.coupled
reconcile_from_fast_to_slow!(
cummulate_fast_solution!(
slow_bl,
fast_bl,
slow.rhs!,
fast.rhs!,
Qslow,
Qfast,
fast_time,
fast_dt,
substep,
)
end

# Update (RK-stage) slow state
event = Event(array_device(Qslow))
event = update!(array_device(Qslow), groupsize)(
realview(dQslow),
realview(Qslow),
slow.RKA[slow_s % length(slow.RKA) + 1],
slow.RKB[slow_s],
slow_dt,
nothing,
nothing,
nothing;
ndrange = length(realview(Qslow)),
dependencies = (event,),
)
wait(array_device(Qslow), event)

# reconcile slow equation using fast equation
reconcile_from_fast_to_slow!(
slow_bl,
fast_bl,
slow.rhs!,
fast.rhs!,
Qslow,
Qfast,
)
end
updatedt!(fast, fast_dt_in)

Expand Down
Loading