Skip to content

Commit 607515c

Browse files
committed
Debugging GPU issue in saturation adjustment
1 parent 08613ca commit 607515c

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/cache/precomputed_quantities.jl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,38 @@ function add_sgs_ᶜK!(ᶜK, Y, ᶜρa⁰, ᶠu₃⁰, turbconv_model)
356356
return nothing
357357
end
358358

359+
# TODO: Remove this.
360+
@inline function PhaseEquil_ρeq_temporary_overwrite(
361+
param_set::TD.APS,
362+
ρ::FT,
363+
e_int::FT,
364+
q_tot::FT,
365+
maxiter::IT = nothing,
366+
relative_temperature_tol::TT = nothing,
367+
::Type{sat_adjust_method} = TD.RS.NewtonsMethod,
368+
T_guess::Union{FT, Nothing} = nothing,
369+
) where {FT <: Real, sat_adjust_method, IT <: TD.ITERTYPE, TT <: TD.TOLTYPE}
370+
maxiter === nothing && (maxiter = 8)
371+
relative_temperature_tol === nothing &&
372+
(relative_temperature_tol = FT(1e-4))
373+
phase_type = TD.PhaseEquil{FT}
374+
q_tot_safe = clamp(q_tot, 0, 1) # clamp(q_tot, FT(0), FT(1))
375+
T = TD.saturation_adjustment(
376+
sat_adjust_method,
377+
param_set,
378+
e_int,
379+
ρ,
380+
q_tot_safe,
381+
phase_type,
382+
maxiter,
383+
relative_temperature_tol,
384+
T_guess,
385+
)
386+
q_pt = TD.PhasePartition_equil(param_set, T, ρ, q_tot_safe, phase_type)
387+
p = TD.air_pressure(param_set, T, ρ, q_pt)
388+
return TD.PhaseEquil{FT}(ρ, p, e_int, q_tot_safe, T)
389+
end
390+
359391
function thermo_state(
360392
thermo_params;
361393
ρ = nothing,
@@ -374,7 +406,7 @@ function thermo_state(
374406
get_ts::Real, ::Nothing, ::Nothing, e_int::Real, ::Nothing, ::Nothing) =
375407
TD.PhaseDry_ρe(thermo_params, ρ, e_int)
376408
get_ts::Real, ::Nothing, ::Nothing, e_int::Real, q_tot::Real, ::Nothing) =
377-
TD.PhaseEquil_ρeq(
409+
PhaseEquil_ρeq_temporary_overwrite( # TD.PhaseEquil_ρeq(
378410
thermo_params,
379411
ρ,
380412
e_int,
@@ -490,6 +522,7 @@ NVTX.@annotate function set_implicit_precomputed_quantities!(Y, p, t)
490522
# @. ᶜK += Y.c.sgs⁰.ρatke / Y.c.ρ
491523
# TODO: We should think more about these increments before we use them.
492524
end
525+
iszero(t) && @show(eltype(Y.c.ρ)) # TODO: Remove this.
493526
@. ᶜts = ts_gs(thermo_args..., Y.c, ᶜK, ᶜΦ, Y.c.ρ)
494527
@. ᶜp = TD.air_pressure(thermo_params, ᶜts)
495528
@. ᶜh_tot = TD.total_specific_enthalpy(

0 commit comments

Comments
 (0)