@@ -411,20 +411,31 @@ end
411411
412412"""
413413 set_implicit_precomputed_quantities!(Y, p, t)
414+ set_implicit_precomputed_quantities_part1!(Y, p, t)
415+ set_implicit_precomputed_quantities_part2!(Y, p, t)
414416
415- Updates the precomputed quantities that are handled implicitly based on the
416- current state `Y`. This is called before each evaluation of either
417- `implicit_tendency!` or `remaining_tendency!`, and it includes quantities used
417+ Update the precomputed quantities that are handled implicitly based on the
418+ current state `Y`. These are called before each evaluation of either
419+ `implicit_tendency!` or `remaining_tendency!`, and they include quantities used
418420in both tedencies.
419421
420- This function also applies a "filter" to `Y` in order to ensure that `ᶠu³` is 0
422+ These functions also apply a "filter" to `Y` in order to ensure that `ᶠu³` is 0
421423at the surface (i.e., to enforce the impenetrable boundary condition). If the
422424`turbconv_model` is EDMFX, the filter also ensures that `ᶠu³⁰` and `ᶠu³ʲs` are 0
423425at the surface. In the future, we will probably want to move this filtering
424426elsewhere, but doing it here ensures that it occurs whenever the precomputed
425427quantities are updated.
428+
429+ These functions are split into two parts so that the first stage of the implicit
430+ and explicit calculations can be executed in sequence before completing the
431+ remaining steps. This ordering is required to correctly compute variables at
432+ the environment boundary after applying the boundary conditions.
426433"""
427434NVTX. @annotate function set_implicit_precomputed_quantities! (Y, p, t)
435+ set_implicit_precomputed_quantities_part1! (Y, p, t)
436+ set_implicit_precomputed_quantities_part2! (Y, p, t)
437+ end
438+ NVTX. @annotate function set_implicit_precomputed_quantities_part1! (Y, p, t)
428439 (; turbconv_model, moisture_model, microphysics_model) = p. atmos
429440 (; ᶜΦ) = p. core
430441 (; ᶜu, ᶠu³, ᶠu, ᶜK, ᶜts, ᶜp) = p. precomputed
@@ -463,6 +474,16 @@ NVTX.@annotate function set_implicit_precomputed_quantities!(Y, p, t)
463474
464475 if turbconv_model isa PrognosticEDMFX
465476 set_prognostic_edmf_precomputed_quantities_draft! (Y, p, ᶠuₕ³, t)
477+ elseif ! (isnothing (turbconv_model))
478+ # Do nothing for other turbconv models for now
479+ end
480+ end
481+ NVTX. @annotate function set_implicit_precomputed_quantities_part2! (Y, p, t)
482+ (; turbconv_model) = p. atmos
483+ ᶠuₕ³ = p. scratch. ᶠtemp_CT3
484+ @. ᶠuₕ³ = $ compute_ᶠuₕ³ (Y. c. uₕ, Y. c. ρ)
485+
486+ if turbconv_model isa PrognosticEDMFX
466487 set_prognostic_edmf_precomputed_quantities_environment! (Y, p, ᶠuₕ³, t)
467488 set_prognostic_edmf_precomputed_quantities_implicit_closures! (Y, p, t)
468489 elseif ! (isnothing (turbconv_model))
@@ -471,20 +492,22 @@ NVTX.@annotate function set_implicit_precomputed_quantities!(Y, p, t)
471492end
472493
473494"""
474- set_explicit_precomputed_quantities!(Y, p, t)
495+ set_explicit_precomputed_quantities_part1!(Y, p, t)
496+ set_explicit_precomputed_quantities_part2!(Y, p, t)
475497
476- Updates the precomputed quantities that are handled explicitly based on the
477- current state `Y`. This is only called before each evaluation of
478- `remaining_tendency!`, though it includes quantities used in both
498+ Update the precomputed quantities that are handled explicitly based on the
499+ current state `Y`. These are only called before each evaluation of
500+ `remaining_tendency!`, though they include quantities used in both
479501`implicit_tendency!` and `remaining_tendency!`.
502+
503+ These functions are split into two parts so that the first stage of the implicit
504+ and explicit calculations can be executed in sequence before completing the
505+ remaining steps. This ordering is required to correctly compute variables at
506+ the environment boundary after applying the boundary conditions.
480507"""
481- NVTX. @annotate function set_explicit_precomputed_quantities! (Y, p, t)
482- (; turbconv_model, moisture_model, microphysics_model, cloud_model) =
483- p. atmos
484- (; vertical_diffusion, call_cloud_diagnostics_per_stage) = p. atmos
485- (; ᶜΦ) = p. core
486- (; ᶜu, ᶜts, ᶜp) = p. precomputed
487- ᶠuₕ³ = p. scratch. ᶠtemp_CT3 # updated in set_implicit_precomputed_quantities!
508+ NVTX. @annotate function set_explicit_precomputed_quantities_part1! (Y, p, t)
509+ (; turbconv_model) = p. atmos
510+ (; ᶜts) = p. precomputed
488511 thermo_params = CAP. thermodynamics_params (p. params)
489512
490513 if ! isnothing (p. sfc_setup)
@@ -502,6 +525,19 @@ NVTX.@annotate function set_explicit_precomputed_quantities!(Y, p, t)
502525
503526 if turbconv_model isa PrognosticEDMFX
504527 set_prognostic_edmf_precomputed_quantities_bottom_bc! (Y, p, t)
528+ elseif turbconv_model isa DiagnosticEDMFX
529+ set_diagnostic_edmf_precomputed_quantities_bottom_bc! (Y, p, t)
530+ elseif ! (isnothing (turbconv_model))
531+ # Do nothing for other turbconv models for now
532+ end
533+
534+ return nothing
535+ end
536+ NVTX. @annotate function set_explicit_precomputed_quantities_part2! (Y, p, t)
537+ (; turbconv_model, moisture_model, cloud_model) = p. atmos
538+ (; call_cloud_diagnostics_per_stage) = p. atmos
539+
540+ if turbconv_model isa PrognosticEDMFX
505541 set_prognostic_edmf_precomputed_quantities_explicit_closures! (Y, p, t)
506542 set_prognostic_edmf_precomputed_quantities_precipitation! (
507543 Y,
@@ -510,7 +546,6 @@ NVTX.@annotate function set_explicit_precomputed_quantities!(Y, p, t)
510546 )
511547 end
512548 if turbconv_model isa DiagnosticEDMFX
513- set_diagnostic_edmf_precomputed_quantities_bottom_bc! (Y, p, t)
514549 set_diagnostic_edmf_precomputed_quantities_do_integral! (Y, p, t)
515550 set_diagnostic_edmf_precomputed_quantities_top_bc! (Y, p, t)
516551 set_diagnostic_edmf_precomputed_quantities_env_closures! (Y, p, t)
560595Updates all precomputed quantities based on the current state `Y`.
561596"""
562597function set_precomputed_quantities! (Y, p, t)
563- set_implicit_precomputed_quantities! (Y, p, t)
564- set_explicit_precomputed_quantities! (Y, p, t)
598+ set_implicit_precomputed_quantities_part1! (Y, p, t)
599+ set_explicit_precomputed_quantities_part1! (Y, p, t)
600+ set_implicit_precomputed_quantities_part2! (Y, p, t)
601+ set_explicit_precomputed_quantities_part2! (Y, p, t)
565602end
0 commit comments