Skip to content

Commit 78655b3

Browse files
committed
add debug plots; step one dt
1 parent 6f60497 commit 78655b3

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

experiments/AMIP/coupler_driver.jl

+19-3
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ include("cli_options.jl")
9898
parsed_args = parse_commandline(argparse_settings())
9999

100100
## modify parsed args for fast testing from REPL #hide
101+
include("user_io/debug_plots.jl")
102+
pkg_dir = pkgdir(ClimaCoupler)
101103
if isinteractive()
102-
include("user_io/debug_plots.jl")
103104
parsed_args["config_file"] =
104105
isnothing(parsed_args["config_file"]) ? joinpath(pkg_dir, "config/model_configs/interactive_debug.yml") :
105106
parsed_args["config_file"]
@@ -122,10 +123,11 @@ run_name = config_dict["run_name"]
122123
energy_check = config_dict["energy_check"]
123124
const FT = config_dict["FLOAT_TYPE"] == "Float64" ? Float64 : Float32
124125
land_sim_name = "bucket"
125-
t_end = Float64(time_to_seconds(config_dict["t_end"]))
126+
# t_end = Float64(time_to_seconds(config_dict["t_end"]))
126127
t_start = 0.0
127-
tspan = (t_start, t_end)
128128
Δt_cpl = Float64(config_dict["dt_cpl"])
129+
t_end = Δt_cpl
130+
tspan = (t_start, t_end)
129131
saveat = Float64(time_to_seconds(config_dict["dt_save_to_sol"]))
130132
date0 = date = DateTime(config_dict["start_date"], dateformat"yyyymmdd")
131133
mono_surface = config_dict["mono_surface"]
@@ -173,6 +175,10 @@ The data files are downloaded from the `ClimaCoupler` artifacts directory. If th
173175
original sources.
174176
=#
175177

178+
debug_dir = joinpath(COUPLER_ARTIFACTS_DIR, "debug_output/")
179+
isdir(debug_dir) ? nothing : mkpath(debug_dir)
180+
181+
# get the paths to the necessary data files: land-sea mask, sst map, sea ice concentration
176182
include(joinpath(pkgdir(ClimaCoupler), "artifacts", "artifact_funcs.jl"))
177183
sst_data = joinpath(sst_dataset_path(), "sst.nc")
178184
sic_data = joinpath(sic_dataset_path(), "sic.nc")
@@ -551,6 +557,8 @@ cs = CoupledSimulation{FT}(
551557
dir_paths,
552558
);
553559

560+
debug(cs, debug_dir * "0_initialized_cs")
561+
554562
#=
555563
## Restart component model states if specified
556564
If a restart directory is specified and contains output files from the `checkpoint_cb` callback, the component model states are restarted from those files. The restart directory
@@ -585,18 +593,21 @@ end
585593

586594
# 2.coupler updates surface model area fractions
587595
update_surface_fractions!(cs)
596+
debug(cs, "debug_output/2_surface_fraction_update")
588597

589598
# 3.surface density (`ρ_sfc`): calculated by the coupler by adiabatically extrapolating atmospheric thermal state to the surface.
590599
# For this, we need to import surface and atmospheric fields. The model sims are then updated with the new surface density.
591600
import_combined_surface_fields!(cs.fields, cs.model_sims, cs.boundary_space, turbulent_fluxes)
592601
import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, turbulent_fluxes)
593602
update_model_sims!(cs.model_sims, cs.fields, turbulent_fluxes)
603+
debug(cs, "debug_output/3_update_sims")
594604

595605
# 4.surface vapor specific humidity (`q_sfc`): step surface models with the new surface density to calculate their respective `q_sfc` internally
596606
## TODO: the q_sfc calculation follows the design of the bucket q_sfc, but it would be neater to abstract this from step! (#331)
597607
step!(land_sim, Δt_cpl)
598608
step!(ocean_sim, Δt_cpl)
599609
step!(ice_sim, Δt_cpl)
610+
debug(cs, "debug_output/4_step_surface_models")
600611

601612
# 5.turbulent fluxes: now we have all information needed for calculating the initial turbulent surface fluxes using the combined state
602613
# or the partitioned state method
@@ -615,9 +626,11 @@ elseif turbulent_fluxes isa PartitionedStateFluxes
615626
CA.SurfaceConditions.update_surface_conditions!(atmos_sim.integrator.u, new_p, atmos_sim.integrator.t) ## sets T_sfc (but SF calculation not necessary - requires split functionality in CA)
616627
atmos_sim.integrator.p.precomputed.sfc_conditions .= new_p.precomputed.sfc_conditions
617628
end
629+
debug(cs, "debug_output/5_after_turb_fluxes")
618630

619631
# 6.reinitialize models + radiative flux: prognostic states and time are set to their initial conditions. For atmos, this also triggers the callbacks and sets a nonzero radiation flux (given the new sfc_conditions)
620632
reinit_model_sims!(cs.model_sims)
633+
debug(cs, "debug_output/6_after_reinit")
621634

622635
# 7.update all fluxes: coupler re-imports updated atmos fluxes (radiative fluxes for both `turbulent_fluxes` types
623636
# and also turbulent fluxes if `turbulent_fluxes isa CombinedStateFluxes`,
@@ -626,6 +639,8 @@ reinit_model_sims!(cs.model_sims)
626639
import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, turbulent_fluxes)
627640
update_model_sims!(cs.model_sims, cs.fields, turbulent_fluxes)
628641

642+
debug(cs, "debug_output/7_import_atmos_fluxes")
643+
629644
#=
630645
## Coupling Loop
631646
@@ -755,6 +770,7 @@ end #hide
755770
## run the coupled simulation
756771
solve_coupler!(cs);
757772

773+
debug(cs, "debug_output/6_after_solve")
758774
#=
759775
## Postprocessing
760776
Currently all postprocessing is performed using the root process only.

experiments/AMIP/user_io/debug_plots.jl

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ function debug(cs_fields::NamedTuple, dir, cs_fields_ref = nothing)
4545
for field_name in field_names
4646
field = getproperty(cs_fields, field_name)
4747
push!(all_plots, Plots.plot(field, title = string(field_name) * print_extrema(field)))
48+
if (field_name == :T_S) && (@isdefined debug_csf0)
49+
push!(
50+
all_plots,
51+
Plots.plot(
52+
field .- debug_csf0.T_S,
53+
title = string(field_name) * "_anom" * print_extrema(field),
54+
color = :viridis,
55+
),
56+
)
57+
end
4858
end
4959
Plots.plot(all_plots..., size = (1500, 800))
5060
Plots.png(joinpath(dir, "debug_coupler"))

0 commit comments

Comments
 (0)