@@ -382,160 +382,13 @@ function edmfx_sgs_diffusive_flux_tendency!(
382382 Y,
383383 p,
384384 t,
385- turbconv_model:: PrognosticEDMFX ,
385+ turbconv_model:: Union{EDOnlyEDMFX, DiagnosticEDMFX, PrognosticEDMFX} ,
386386)
387- FT = Spaces. undertype (axes (Y. c))
388- (; dt, params) = p
389- thermo_params = CAP. thermodynamics_params (params)
390- turbconv_params = CAP. turbconv_params (params)
391- c_d = CAP. tke_diss_coeff (turbconv_params)
392- (; ᶜK, ᶜu⁰, ᶜK⁰, ᶜlinear_buoygrad, ᶜstrain_rate_norm, ᶜρʲs, ᶜts, ᶜts⁰) = p. precomputed
393- (; ρatke_flux) = p. precomputed
394- ᶠgradᵥ = Operators. GradientC2F ()
395- ᶜρa⁰ = @. lazy (ρa⁰ (Y. c. ρ, Y. c. sgsʲs, turbconv_model))
396- ᶜtke⁰ = @. lazy (specific (Y. c. sgs⁰. ρatke, Y. c. ρ))
397-
398- if p. atmos. edmfx_model. sgs_diffusive_flux isa Val{true }
399-
400- (; ᶜlinear_buoygrad, ᶜstrain_rate_norm) = p. precomputed
401- # scratch to prevent GPU Kernel parameter memory error
402- ᶜmixing_length_field = p. scratch. ᶜtemp_scalar_2
403- ᶜmixing_length_field .= ᶜmixing_length (Y, p)
404- ᶜK_u = @. lazy (
405- eddy_viscosity (turbconv_params, ᶜtke⁰, ᶜmixing_length_field),
406- )
407- ᶜprandtl_nvec = @. lazy (
408- turbulent_prandtl_number (
409- params,
410- ᶜlinear_buoygrad,
411- ᶜstrain_rate_norm,
412- ),
413- )
414- ᶜK_h = @. lazy (eddy_diffusivity (ᶜK_u, ᶜprandtl_nvec))
415- ᶠρaK_h = p. scratch. ᶠtemp_scalar
416- @. ᶠρaK_h = ᶠinterp (Y. c. ρ) * ᶠinterp (ᶜK_h)
417- ᶠρaK_u = p. scratch. ᶠtemp_scalar_2
418- @. ᶠρaK_u = ᶠinterp (Y. c. ρ) * ᶠinterp (ᶜK_u)
419387
420- # Total enthalpy diffusion
421- ᶜdivᵥ_ρe_tot = Operators. DivergenceF2C (
422- top = Operators. SetValue (C3 (FT (0 ))),
423- bottom = Operators. SetValue (C3 (FT (0 ))),
424- )
425-
426- ᶜh_tot = @. lazy (
427- TD. total_specific_enthalpy (
428- thermo_params,
429- ᶜts,
430- specific (Y. c. ρe_tot, Y. c. ρ),
431- ),
432- )
433- @. Yₜ. c. ρe_tot -= ᶜdivᵥ_ρe_tot (- (ᶠρaK_h * ᶠgradᵥ (ᶜh_tot)))
434- if use_prognostic_tke (turbconv_model)
435- # Turbulent TKE transport (diffusion)
436- ᶜdivᵥ_ρatke = Operators. DivergenceF2C (
437- top = Operators. SetValue (C3 (FT (0 ))),
438- bottom = Operators. SetValue (ρatke_flux),
439- )
440- # Add flux divergence and dissipation term, relaxing TKE to zero
441- # in one time step if tke < 0
442- @. Yₜ. c. sgs⁰. ρatke -=
443- ᶜdivᵥ_ρatke (- (ᶠρaK_u * ᶠgradᵥ (ᶜtke⁰))) + ifelse (
444- ᶜtke⁰ >= FT (0 ),
445- tke_dissipation (
446- turbconv_params,
447- Y. c. sgs⁰. ρatke,
448- ᶜtke⁰,
449- ᶜmixing_length_field,
450- ),
451- Y. c. sgs⁰. ρatke / dt,
452- )
453- end
454- if ! (p. atmos. moisture_model isa DryModel)
455- # Specific humidity diffusion
456- ᶜρχₜ_diffusion = p. scratch. ᶜtemp_scalar
457- ᶜdivᵥ_ρq_tot = Operators. DivergenceF2C (
458- top = Operators. SetValue (C3 (FT (0 ))),
459- bottom = Operators. SetValue (C3 (FT (0 ))),
460- )
461- @. ᶜρχₜ_diffusion =
462- ᶜdivᵥ_ρq_tot (- (ᶠρaK_h * ᶠgradᵥ (specific (Y. c. ρq_tot, Y. c. ρ))))
463- @. Yₜ. c. ρq_tot -= ᶜρχₜ_diffusion
464- @. Yₜ. c. ρ -= ᶜρχₜ_diffusion # Effect of moisture diffusion on (moist) air mass
465- end
466-
467- if p. atmos. moisture_model isa NonEquilMoistModel && (
468- p. atmos. microphysics_model isa Microphysics1Moment ||
469- p. atmos. microphysics_model isa Microphysics2Moment
470- )
471- α_precip = CAP. α_vert_diff_tracer (params)
472- ᶜρχₜ_diffusion = p. scratch. ᶜtemp_scalar
473- ᶜdivᵥ_ρq = Operators. DivergenceF2C (
474- top = Operators. SetValue (C3 (FT (0 ))),
475- bottom = Operators. SetValue (C3 (FT (0 ))),
476- )
477- ᶜρʲ = ᶜρʲs.:(1 )
478- ᶜρ⁰ = @. lazy (TD. air_density (thermo_params, ᶜts⁰))
479-
480- microphysics_tracers = (
481- (@name (c. ρq_liq), @name (c. sgsʲs.:(1 ). q_liq), @name (q_liq), FT (1 )),
482- (@name (c. ρq_ice), @name (c. sgsʲs.:(1 ). q_ice), @name (q_ice), FT (1 )),
483- (@name (c. ρq_rai), @name (c. sgsʲs.:(1 ). q_rai), @name (q_rai), α_precip),
484- (@name (c. ρq_sno), @name (c. sgsʲs.:(1 ). q_sno), @name (q_sno), α_precip),
485- (@name (c. ρn_liq), @name (c. sgsʲs.:(1 ). n_liq), @name (n_liq), FT (1 )),
486- (@name (c. ρn_rai), @name (c. sgsʲs.:(1 ). n_rai), @name (n_rai), α_precip),
487- )
488-
489- MatrixFields. unrolled_foreach (
490- microphysics_tracers,
491- ) do (ρχ_name, χʲ_name, χ_name, α)
492- MatrixFields. has_field (Y, ρχ_name) || return
493-
494- ᶜρχₜ = MatrixFields. get_field (Yₜ, ρχ_name)
495- ᶜχʲ = MatrixFields. get_field (Y, χʲ_name)
496- ᶜχ⁰ = ᶜspecific_env_value (χ_name, Y, p)
497-
498- # add updraft diffusion
499- @. ᶜρχₜ_diffusion =
500- draft_area (Y. c. sgsʲs.:(1 ). ρa, ᶜρʲ) *
501- ᶜdivᵥ_ρq (
502- - (ᶠinterp (ᶜρʲ) * ᶠinterp (ᶜK_h) * α * ᶠgradᵥ (ᶜχʲ)),
503- )
504- @. ᶜρχₜ -= ᶜρχₜ_diffusion
505-
506- # add environment diffusion
507- @. ᶜρχₜ_diffusion =
508- draft_area (ᶜρa⁰, ᶜρ⁰) *
509- ᶜdivᵥ_ρq (
510- - (ᶠinterp (ᶜρ⁰) * ᶠinterp (ᶜK_h) * α * ᶠgradᵥ (ᶜχ⁰)),
511- )
512- @. ᶜρχₜ -= ᶜρχₜ_diffusion
513- end
514- end
515-
516- # Momentum diffusion
517- ᶠstrain_rate = compute_strain_rate_face_vertical (ᶜu⁰)
518- @. Yₜ. c. uₕ -= C12 (ᶜdivᵥ (- (2 * ᶠρaK_u * ᶠstrain_rate)) / Y. c. ρ)
519- end
520- return nothing
521- end
522-
523- function edmfx_sgs_diffusive_flux_tendency! (
524- Yₜ,
525- Y,
526- p,
527- t,
528- turbconv_model:: Union{EDOnlyEDMFX, DiagnosticEDMFX} ,
529- )
530-
531- # Assumes envinronmental area fraction is 1 (so draft area fraction is negligible)
532- # TODO : Relax this assumption and construct diagnostic EDMF fluxes in parallel to
533- # prognostic fluxes
534388 FT = Spaces. undertype (axes (Y. c))
535389 (; dt, params) = p
536390 turbconv_params = CAP. turbconv_params (params)
537391 thermo_params = CAP. thermodynamics_params (params)
538- c_d = CAP. tke_diss_coeff (turbconv_params)
539392 (; ᶜu, ᶜts) = p. precomputed
540393 (; ρatke_flux) = p. precomputed
541394 ᶠgradᵥ = Operators. GradientC2F ()
@@ -609,27 +462,24 @@ function edmfx_sgs_diffusive_flux_tendency!(
609462 @. ᶜρχₜ_diffusion =
610463 ᶜdivᵥ_ρq_tot (- (ᶠρaK_h * ᶠgradᵥ (specific (Y. c. ρq_tot, Y. c. ρ))))
611464 @. Yₜ. c. ρq_tot -= ᶜρχₜ_diffusion
612- @. Yₜ. c. ρ -= ᶜρχₜ_diffusion
465+ @. Yₜ. c. ρ -= ᶜρχₜ_diffusion # Effect of moisture diffusion on (moist) air mass
613466 end
614467
615- cloud_tracers = (@name (c. ρq_liq), @name (c. ρq_ice), @name (c. ρn_liq))
616- precip_tracers = (@name (c. ρq_rai), @name (c. ρq_sno), @name (c. ρn_rai))
617-
618- α = CAP. α_vert_diff_tracer (params)
468+ α_precip = CAP. α_vert_diff_tracer (params)
619469 ᶜρχₜ_diffusion = p. scratch. ᶜtemp_scalar
620470 ᶜdivᵥ_ρq = Operators. DivergenceF2C (
621471 top = Operators. SetValue (C3 (FT (0 ))),
622472 bottom = Operators. SetValue (C3 (FT (0 ))),
623473 )
624- MatrixFields . unrolled_foreach (cloud_tracers) do ρχ_name
625- MatrixFields . has_field (Y, ρχ_name) || return
626- ᶜρχ = MatrixFields . get_field (Y, ρχ_name)
627- ᶜχ = ( @. lazy ( specific (ᶜρχ, Y . c . ρ)))
628- @. ᶜρχₜ_diffusion = ᶜdivᵥ_ρq ( - (ᶠρaK_h * ᶠgradᵥ (ᶜχ)))
629- ᶜρχₜ = MatrixFields . get_field (Yₜ, ρχ_name)
630- @. ᶜρχₜ -= ᶜρχₜ_diffusion
631- end
632- MatrixFields. unrolled_foreach (precip_tracers ) do ρχ_name
474+ microphysics_tracers = (
475+ ( @name (c . ρq_liq), FT ( 1 )),
476+ ( @name (c . ρq_ice), FT ( 1 )),
477+ ( @name (c . ρq_rai), α_precip),
478+ ( @name (c . ρq_sno), α_precip),
479+ ( @name (c . ρn_liq), FT ( 1 )),
480+ ( @name (c . ρn_rai), α_precip),
481+ )
482+ MatrixFields. unrolled_foreach (microphysics_tracers ) do ( ρχ_name, α)
633483 MatrixFields. has_field (Y, ρχ_name) || return
634484 ᶜρχ = MatrixFields. get_field (Y, ρχ_name)
635485 ᶜχ = (@. lazy (specific (ᶜρχ, Y. c. ρ)))
0 commit comments