Skip to content

Commit cbb3cc7

Browse files
committed
add debug plots; step one dt
1 parent 45d0bf6 commit cbb3cc7

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

experiments/AMIP/coupler_driver.jl

+20-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ parsed_args = parse_commandline(argparse_settings())
140140

141141
## setup coupler and model configurations
142142
# modify parsed args for fast testing from REPL #hide
143+
include("user_io/debug_plots.jl")
143144
pkg_dir = pkgdir(ClimaCoupler)
144145
if isinteractive()
145-
include("user_io/debug_plots.jl")
146146
parsed_args["config_file"] =
147147
isnothing(parsed_args["config_file"]) ? joinpath(pkg_dir, "config/model_configs/interactive_debug.yml") :
148148
parsed_args["config_file"]
@@ -165,10 +165,11 @@ run_name = config_dict["run_name"]
165165
energy_check = config_dict["energy_check"]
166166
const FT = config_dict["FLOAT_TYPE"] == "Float64" ? Float64 : Float32
167167
land_sim_name = "bucket"
168-
t_end = Float64(time_to_seconds(config_dict["t_end"]))
168+
# t_end = Float64(time_to_seconds(config_dict["t_end"]))
169169
t_start = 0.0
170-
tspan = (t_start, t_end)
171170
Δt_cpl = Float64(config_dict["dt_cpl"])
171+
t_end = Δt_cpl
172+
tspan = (t_start, t_end)
172173
saveat = Float64(time_to_seconds(config_dict["dt_save_to_sol"]))
173174
date0 = date = DateTime(config_dict["start_date"], dateformat"yyyymmdd")
174175
mono_surface = config_dict["mono_surface"]
@@ -194,6 +195,9 @@ isdir(COUPLER_ARTIFACTS_DIR) ? nothing : mkpath(COUPLER_ARTIFACTS_DIR)
194195
@info COUPLER_OUTPUT_DIR
195196
config_dict["print_config_dict"] ? @info(config_dict) : nothing
196197

198+
debug_dir = joinpath(COUPLER_ARTIFACTS_DIR, "debug_output/")
199+
isdir(debug_dir) ? nothing : mkpath(debug_dir)
200+
197201
# get the paths to the necessary data files: land-sea mask, sst map, sea ice concentration
198202
include(joinpath(pkgdir(ClimaCoupler), "artifacts", "artifact_funcs.jl"))
199203
sst_data = joinpath(sst_dataset_path(), "sst.nc")
@@ -534,6 +538,8 @@ cs = CoupledSimulation{FT}(
534538
dir_paths,
535539
);
536540

541+
debug(cs, debug_dir * "0_initialized_cs")
542+
537543
#=
538544
## Restart component model states if specified
539545
=#
@@ -563,12 +569,16 @@ import_combined_surface_fields!(cs.fields, cs.model_sims, cs.boundary_space, tur
563569
import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, turbulent_fluxes)
564570
update_model_sims!(cs.model_sims, cs.fields, turbulent_fluxes)
565571

572+
debug(cs, "debug_output/1_init_exchange_cs")
573+
566574
# 2) each surface component model calculates its own vapor specific humidity (q_sfc)
567575
# TODO: the q_sfc calculation follows the design of the bucket q_sfc, but it would be neater to abstract this from step!
568576
step!(land_sim, Δt_cpl)
569577
step!(ocean_sim, Δt_cpl)
570578
step!(ice_sim, Δt_cpl)
571579

580+
debug(cs, "debug_output/2_step_sfc_models")
581+
572582
# 3) coupler re-imports updated surface fields and calculates turbulent fluxes, while updating atmos sfc_conditions
573583
if turbulent_fluxes isa CombinedStateFluxes
574584
# calculate fluxes using combined surface states on the atmos grid
@@ -585,16 +595,22 @@ elseif turbulent_fluxes isa PartitionedStateFluxes
585595
atmos_sim.integrator.p.precomputed.sfc_conditions .= new_p.precomputed.sfc_conditions
586596
end
587597

598+
debug(cs, "debug_output/3_init_flux_calc")
599+
588600
# 4) given the new sfc_conditions, atmos calls the radiative flux callback
589601
reinit_model_sims!(cs.model_sims) # NB: for atmos this sets a nonzero radiation flux
590602

603+
debug(cs, "debug_output/4_reinit")
604+
591605
# 5) coupler re-imports updated atmos fluxes (radiative fluxes for both `turbulent_fluxes` types
592606
# and also turbulent fluxes if `turbulent_fluxes isa CombinedStateFluxes`,
593607
# and sends them to the surface component models. If `turbulent_fluxes isa PartitionedStateFluxes`
594608
# atmos receives the turbulent fluxes from the coupler.
595609
import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, turbulent_fluxes)
596610
update_model_sims!(cs.model_sims, cs.fields, turbulent_fluxes)
597611

612+
debug(cs, "debug_output/5_import_atmos_fluxes")
613+
598614
#=
599615
## Coupling Loop
600616
=#
@@ -720,6 +736,7 @@ end #hide
720736
## run the coupled simulation
721737
solve_coupler!(cs);
722738

739+
debug(cs, "debug_output/6_after_solve")
723740
#=
724741
## Postprocessing
725742
Currently all postprocessing is performed using the root process only.

experiments/AMIP/user_io/debug_plots.jl

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,21 @@ end
2424
Plot useful coupler fields (in `field_names`) and save plots to a directory.
2525
"""
2626
function debug(cs_fields::NamedTuple, dir)
27-
field_names = (:F_turb_energy, :F_turb_moisture, :P_liq, :T_S, :ρ_sfc, :q_sfc)
27+
field_names = (:albedo, :F_radiative, :F_turb_energy, :F_turb_moisture, :P_liq, :T_S, :ρ_sfc, :q_sfc, :beta, :z0b_S, :z0m_S)
2828
all_plots = []
2929
for field_name in field_names
3030
field = getproperty(cs_fields, field_name)
3131
push!(all_plots, Plots.plot(field, title = string(field_name) * print_extrema(field)))
32+
if (field_name == :T_S) && (@isdefined debug_csf0)
33+
push!(
34+
all_plots,
35+
Plots.plot(
36+
field .- debug_csf0.T_S,
37+
title = string(field_name) * "_anom" * print_extrema(field),
38+
color = :viridis,
39+
),
40+
)
41+
end
3242
end
3343
fig = Plots.plot(all_plots..., size = (1500, 800))
3444
Plots.png(joinpath(dir, "debug_coupler"))

0 commit comments

Comments
 (0)