Skip to content

Commit

Permalink
Factor out implicit and wfact pcq calls
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Sep 30, 2023
1 parent 8519aa6 commit 68889f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/prognostic_equations/implicit/implicit_tendency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ClimaCore: Fields, Geometry
NVTX.@annotate function implicit_tendency!(Yₜ, Y, p, t)
fill_with_nans!(p)
Yₜ .= zero(eltype(Yₜ))
set_precomputed_quantities!(Y, p, t)
Fields.bycolumn(axes(Y.c)) do colidx
implicit_vertical_advection_tendency!(Yₜ, Y, p, t, colidx)
if p.turbconv_model isa TurbulenceConvection.EDMFModel
Expand Down
1 change: 0 additions & 1 deletion src/prognostic_equations/implicit/wfact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ end

NVTX.@annotate function Wfact!(W, Y, p, dtγ, t)
fill_with_nans!(p)
set_precomputed_quantities!(Y, p, t)
Fields.bycolumn(axes(Y.c)) do colidx
Wfact!(W, Y, p, dtγ, t, colidx)
end
Expand Down
3 changes: 3 additions & 0 deletions src/time_stepper/hc_ars343.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function CTS.step_u!(
jacobian = newtons_method_cache.j
if (!isnothing(jacobian)) &&
CTS.needs_update!(newtons_method.update_j, CTS.NewTimeStep(t))
post_implicit!(u, p, t)
T_imp!.Wfact(jacobian, u, p, dt * γ, t)
end
end
Expand Down Expand Up @@ -45,11 +46,13 @@ function CTS.step_u!(
t_imp = t + dt * c_imp[i]
implicit_equation_residual! =
(residual, Ui) -> begin
post_implicit!(Ui, p, t_imp)
T_imp!(residual, Ui, p, t_imp)
@. residual = temp + dt * a_imp[i, i] * residual - Ui
end
implicit_equation_jacobian! =
(jacobian, Ui) -> begin
post_implicit!(Ui, p, t_imp)
T_imp!.Wfact(jacobian, Ui, p, dt * a_imp[i, i], t_imp)
end
call_post_implicit! = Ui -> begin
Expand Down
7 changes: 6 additions & 1 deletion src/time_stepper/imex_ark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function CTS.step_u!(
if γ isa Nothing
sdirk_error(name)
else
post_implicit!(u, p, t)
T_imp!.Wfact(jacobian, u, p, dt * γ, t)
end
end
Expand Down Expand Up @@ -56,13 +57,16 @@ function CTS.step_u!(
# TODO: can/should we remove these closures?
implicit_equation_residual! =
(residual, Ui) -> begin
post_implicit!(Ui, p, t_imp)
T_imp!(residual, Ui, p, t_imp)
@. residual =
temp + dt * a_imp[i, i] * residual - Ui
end
implicit_equation_jacobian! =
(jacobian, Ui) ->
(jacobian, Ui) -> begin
post_implicit!(Ui, p, t_imp)
T_imp!.Wfact(jacobian, Ui, p, dt * a_imp[i, i], t_imp)
end

CTS.solve_newton!(
newtons_method,
Expand All @@ -81,6 +85,7 @@ function CTS.step_u!(
if iszero(a_imp[i, i])
# If its coefficient is 0, T_imp[i] is effectively being
# treated explicitly.
post_implicit!(Ui, p, t_imp)
T_imp!(T_imp[i], U, p, t_imp)
else
# If T_imp[i] is being treated implicitly, ensure that it
Expand Down
7 changes: 6 additions & 1 deletion src/time_stepper/imex_ssprk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function CTS.step_u!(
if γ isa Nothing
sdirk_error(name)
else
post_implicit!(u, p, t)
T_imp!.Wfact(jacobian, u, p, dt * γ, t)
end
end
Expand Down Expand Up @@ -56,12 +57,15 @@ function CTS.step_u!(
# TODO: can/should we remove these closures?
implicit_equation_residual! =
(residual, Ui) -> begin
post_implicit!(Ui, p, t_imp)
T_imp!(residual, Ui, p, t_imp)
@. residual = temp + dt * a_imp[i, i] * residual - Ui
end
implicit_equation_jacobian! =
(jacobian, Ui) ->
(jacobian, Ui) -> begin
post_implicit!(Ui, p, t_imp)
T_imp!.Wfact(jacobian, Ui, p, dt * a_imp[i, i], t_imp)
end
CTS.solve_newton!(
newtons_method,
newtons_method_cache,
Expand All @@ -79,6 +83,7 @@ function CTS.step_u!(
if iszero(a_imp[i, i])
# If its coefficient is 0, T_imp[i] is effectively being
# treated explicitly.
post_implicit!(U, p, t_imp)
T_imp!(T_imp[i], U, p, t_imp)
else
# If T_imp[i] is being treated implicitly, ensure that it
Expand Down

0 comments on commit 68889f5

Please sign in to comment.