Skip to content

Commit

Permalink
unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LenkaNovak committed Sep 7, 2023
1 parent 22fcdb0 commit f5884f3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
9 changes: 5 additions & 4 deletions experiments/AMIP/modular/components/ocean/eisenman_seaice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ function solve_eisenman_model!(Y, Ya, p, thermo_params, Δt)
return Y, Ya
end

"""
∑tendencies(dY, Y, cache, _)
Calculate the tendencies for the Eisenman-Zhang sea ice model.
"""
function ∑tendencies(dY, Y, cache, _)
FT = eltype(dY)
Δt = cache.Δt
Expand Down Expand Up @@ -189,10 +194,6 @@ function eisenman_seaice_init(
# initiate prognostic variables
Y, Ya = state_init(params_ice, space)


# problem = OrdinaryDiffEq.ODEProblem(∑tendencies, Y, tspan, (; Ya = Ya, Δt = dt, params_ice = params_ice, area_fraction = area_fraction))
# integrator = OrdinaryDiffEq.init(problem, stepper, dt = dt, saveat = saveat)

ode_algo = CTS.ExplicitAlgorithm(stepper)
ode_function = CTS.ClimaODEFunction(T_exp! = ∑tendencies, dss! = weighted_dss_slab!)

Expand Down
13 changes: 12 additions & 1 deletion experiments/AMIP/modular/user_io/viz_explorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function plot_anim(cs, out_dir = ".")
combined_field = zeros(boundary_space)
sol_slab = slab_land_sim.integrator.sol

if mode_name[1:10] == "slabplanet"
if mode_name == "slabplanet"
sol_slab_ocean = slab_ocean_sim.integrator.sol
anim = Plots.@animate for (bucketu, oceanu) in zip(sol_slab.u, sol_slab_ocean.u)
land_T_sfc = get_land_temp_from_state(cs.model_sims.land_sim, bucketu)
Expand All @@ -44,6 +44,17 @@ function plot_anim(cs, out_dir = ".")
)
Plots.plot(combined_field)
end
elseif mode_name == "slabplanet_eisenman"
slab_ice_sim = slab_ice_sim.integrator.sol
anim = Plots.@animate for (bucketu, iceu) in zip(sol_slab.u, slab_ice_sim.u)
land_T_sfc = get_land_temp_from_state(cs.model_sims.land_sim, bucketu)
combine_surfaces_from_sol!(
combined_field,
cs.surface_fractions,
(; land = land_T_sfc, ocean = FT(0), ice = iceu.T_sfc),
)
Plots.plot(combined_field)
end

elseif mode_name == "amip"
sol_slab_ice = slab_ice_sim.integrator.sol
Expand Down
12 changes: 9 additions & 3 deletions src/FluxCalculator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ function surface_thermo_state(
colidx::Fields.ColumnIndex,
ΔT_sfc = 0,
)
FT = eltype(thermo_state_int)
FT = eltype(thermo_state_int[1])
@warn("Simulation " * Interfacer.name(sim) * " uses the default thermo (saturated) surface state", maxlog = 10)
T_sfc = Interfacer.get_field(sim, Val(:surface_temperature), colidx) .+ FT(ΔT_sfc) #
T_sfc = Interfacer.get_field(sim, Val(:surface_temperature), colidx) .+ FT(ΔT_sfc)
ρ_sfc = extrapolate_ρ_to_sfc.(thermo_params, thermo_state_int, T_sfc) # ideally the # calculate elsewhere, here just getter...
q_sfc = TD.q_vap_saturation_generic.(thermo_params, T_sfc, ρ_sfc, TD.Liquid()) # default: saturated liquid surface
@. TD.PhaseEquil_ρTq.(thermo_params, ρ_sfc, T_sfc, q_sfc)
Expand Down Expand Up @@ -352,7 +352,13 @@ function get_surface_fluxes_point!(inputs, surface_params::SF.Parameters.Surface
# moisture
F_turb_moisture = @. SF.evaporation(surface_params, inputs, outputs.Ch)

return F_turb_ρτxz, F_turb_ρτyz, F_shf, F_lhf, F_turb_moisture
return (;
F_turb_ρτxz = F_turb_ρτxz,
F_turb_ρτyz = F_turb_ρτyz,
F_shf = F_shf,
F_lhf = F_lhf,
F_turb_moisture = F_turb_moisture,
)
end

"""
Expand Down
5 changes: 3 additions & 2 deletions test/flux_calculator_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ end
@testset "surface_thermo_state" begin
boundary_space = TestHelper.create_space(FT)
_ones = Fields.ones(boundary_space)
sim = DummySurfaceSimulation3(
surface_sim = DummySurfaceSimulation3(
[],
[],
[],
Expand All @@ -317,5 +317,6 @@ end
thermo_params = get_thermo_params(atmos_sim)
thermo_state_int = Interfacer.get_field(atmos_sim, Val(:thermo_state_int))
colidx = Fields.ColumnIndex{2}((1, 1), 73) # arbitrary index
@test surface_thermo_state(sim, thermo_params, thermo_state_int[colidx], colidx).ρ == thermo_state_int[colidx].ρ
@test surface_thermo_state(surface_sim, thermo_params, thermo_state_int[colidx], colidx).ρ ==
thermo_state_int[colidx].ρ
end

0 comments on commit f5884f3

Please sign in to comment.