@@ -10,7 +10,7 @@ import ClimaCore.Geometry as Geometry
10
10
horizontal_dynamics_tendency!(Yₜ, Y, p, t)
11
11
12
12
Computes tendencies due to horizontal advection for prognostic variables of the
13
- grid mean and EDMFX subdomains, and also applies horizontal pressure gradient and
13
+ grid mean and EDMFX subdomains, and also applies horizontal pressure gradient and
14
14
gravitational acceleration terms for horizontal momentum.
15
15
16
16
Specifically, this function calculates:
@@ -344,7 +344,6 @@ function edmfx_sgs_vertical_advection_tendency!(
344
344
turbconv_params = CAP. turbconv_params (params)
345
345
α_b = CAP. pressure_normalmode_buoy_coeff1 (turbconv_params)
346
346
ᶠz = Fields. coordinate_field (Y. f). z
347
- ᶜa_scalar = p. scratch. ᶜtemp_scalar
348
347
ᶜu₃ʲ = p. scratch. ᶜtemp_C3
349
348
ᶜKᵥʲ = p. scratch. ᶜtemp_scalar_2
350
349
for j in 1 : n
@@ -370,58 +369,127 @@ function edmfx_sgs_vertical_advection_tendency!(
370
369
end
371
370
372
371
for j in 1 : n
373
- @. ᶜa_scalar = draft_area (Y. c. sgsʲs.:($$ j). ρa, ᶜρʲs.:($$ j))
374
- vtt = vertical_transport (
375
- ᶜρʲs.:($ j),
376
- ᶠu³ʲs.:($ j),
377
- ᶜa_scalar,
378
- dt,
379
- edmfx_upwinding,
380
- )
372
+ ᶜa = (@. lazy (draft_area (Y. c. sgsʲs.:($$ j). ρa, ᶜρʲs.:($$ j))))
373
+ edmf_upwnd = edmfx_upwinding
374
+
375
+ # Flux form vertical advection of area farction with the grid mean velocity
376
+ vtt = vertical_transport (ᶜρʲs.:($ j), ᶠu³ʲs.:($ j), ᶜa, dt, edmf_upwnd)
381
377
@. Yₜ. c. sgsʲs.:($$ j). ρa += vtt
382
378
383
- va = vertical_advection (
384
- ᶠu³ʲs.:($ j),
385
- Y. c. sgsʲs.:($ j). mse,
386
- edmfx_upwinding,
387
- )
388
- @. Yₜ. c. sgsʲs.:($$ j). mse += va
379
+ # Advective form advection of mse and q_tot with the grid mean velocity
380
+ # TODO - make it work for multiple updrafts
381
+ if j > 1
382
+ error (" Below code doesn't work for multiple updrafts" )
383
+ end
384
+ sgs_q_tot_mse = (@name (c. sgsʲs.:(1 ). mse), @name (c. sgsʲs.:(1 ). q_tot))
385
+ MatrixFields. unrolled_foreach (sgs_q_tot_mse) do χʲ_name
386
+ MatrixFields. has_field (Y, χʲ_name) || return
387
+ ᶜχʲ = MatrixFields. get_field (Y, χʲ_name)
388
+ ᶜχʲₜ = MatrixFields. get_field (Yₜ, χʲ_name)
389
+
390
+ va = vertical_advection (ᶠu³ʲs.:($ j), ᶜχʲ, edmf_upwnd)
391
+ @. ᶜχʲₜ += va
392
+ end
389
393
390
- va = vertical_advection (
391
- ᶠu³ʲs.:($ j),
392
- Y. c. sgsʲs.:($ j). q_tot,
393
- edmfx_upwinding,
394
- )
395
- @. Yₜ. c. sgsʲs.:($$ j). q_tot += va
396
394
if p. atmos. moisture_model isa NonEquilMoistModel &&
397
395
p. atmos. microphysics_model isa Microphysics1Moment
398
- # TODO - add precipitation terminal velocity
399
- # TODO - add cloud sedimentation velocity
400
- # TODO - add their contributions to mean energy and mass
401
- va = vertical_advection (
402
- ᶠu³ʲs.:($ j),
403
- Y. c. sgsʲs.:($ j). q_liq,
404
- edmfx_upwinding,
405
- )
406
- @. Yₜ. c. sgsʲs.:($$ j). q_liq += va
407
- va = vertical_advection (
408
- ᶠu³ʲs.:($ j),
409
- Y. c. sgsʲs.:($ j). q_ice,
410
- edmfx_upwinding,
411
- )
412
- @. Yₜ. c. sgsʲs.:($$ j). q_ice += va
413
- va = vertical_advection (
414
- ᶠu³ʲs.:($ j),
415
- Y. c. sgsʲs.:($ j). q_rai,
416
- edmfx_upwinding,
396
+ # TODO - add contibutions to sgs mass flux from tracer sedimentation
397
+ # TODO - add precipitation and cloud sedimentation in implicit solver/tendency with if/else
398
+
399
+ FT = eltype (params)
400
+ thp = CAP. thermodynamics_params (params)
401
+ (; ᶜΦ) = p. core
402
+ (; ᶜtsʲs) = p. precomputed
403
+
404
+ # Sedimentation velocities for microphysics tracers
405
+ # TODO - lazify ᶜwₗʲs computation. No need to cache it.
406
+ sgs_microphysics_tracers = (
407
+ (@name (c. sgsʲs.:(1 ). q_liq), @name (q_liq), @name (ᶜwₗʲs.:(1 ))),
408
+ (@name (c. sgsʲs.:(1 ). q_ice), @name (q_ice), @name (ᶜwᵢʲs.:(1 ))),
409
+ (@name (c. sgsʲs.:(1 ). q_rai), @name (q_rai), @name (ᶜwᵣʲs.:(1 ))),
410
+ (@name (c. sgsʲs.:(1 ). q_sno), @name (q_sno), @name (ᶜwₛʲs.:(1 ))),
417
411
)
418
- @. Yₜ. c. sgsʲs.:($$ j). q_rai += va
419
- va = vertical_advection (
420
- ᶠu³ʲs.:($ j),
421
- Y. c. sgsʲs.:($ j). q_sno,
422
- edmfx_upwinding,
423
- )
424
- @. Yₜ. c. sgsʲs.:($$ j). q_sno += va
412
+
413
+ MatrixFields. unrolled_foreach (
414
+ sgs_microphysics_tracers,
415
+ ) do (qʲ_name, name, wʲ_name)
416
+ MatrixFields. has_field (Y, qʲ_name) || return
417
+
418
+ ᶜqʲ = MatrixFields. get_field (Y, qʲ_name)
419
+ ᶜqʲₜ = MatrixFields. get_field (Yₜ, qʲ_name)
420
+ ᶜwʲ = MatrixFields. get_field (p. precomputed, wʲ_name)
421
+ ᶠw³ʲ = (@. lazy (CT3 (ᶠinterp (Geometry. WVector (- 1 * ᶜwʲ)))))
422
+ ᶜw³ʲ = (@. lazy (CT3 (Geometry. WVector (- 1 * ᶜwʲ))))
423
+ ᶜaqʲ = (@. lazy (ᶜa * ᶜqʲ))
424
+
425
+ # Flux form vertical advection of rho * area with sedimentation velocities
426
+ # Eq (4) term (3) in the writeup
427
+ vtt = vertical_transport (ᶜρʲs.:($ j), ᶠw³ʲ, ᶜaqʲ, dt, edmf_upwnd)
428
+ @. Yₜ. c. sgsʲs.:($$ j). ρa += vtt
429
+
430
+ # Advective form advection of moisture tracers with the grid mean velocity
431
+ # Eq (2) term (1) in the writeup
432
+ va = vertical_advection (ᶠu³ʲs.:($ j), ᶜqʲ, edmf_upwnd)
433
+ @. ᶜqʲₜ += va
434
+
435
+ # Advective form advection of q_tot and moisture tracers with sedimentation velocities
436
+ # Eq (1-2) term (2)
437
+ va = vertical_advection (ᶠw³ʲ, ᶜqʲ, edmf_upwnd)
438
+ @. Yₜ. c. sgsʲs.:($$ j). q_tot += (1 - Y. c. sgsʲs.:($$ j). q_tot) * va
439
+ @. ᶜqʲₜ += va
440
+ # Advective form advection of mse with sedimentation velocity
441
+ # Eq (3) term (2)
442
+ if name in (@name (q_liq), @name (q_rai))
443
+ ᶜmse_li = (@. lazy (
444
+ TD. internal_energy_liquid (thp, ᶜtsʲs.:($$ j)) + ᶜΦ,
445
+ ))
446
+ elseif name in (@name (q_ice), @name (q_sno))
447
+ ᶜmse_li = (@. lazy (
448
+ TD. internal_energy_ice (thp, ᶜtsʲs.:($$ j)) + ᶜΦ,
449
+ ))
450
+ else
451
+ error (" Unsupported moisture tracer variable" )
452
+ end
453
+ va = vertical_advection (ᶠw³ʲ, ᶜqʲ .* ᶜmse_li, edmf_upwnd)
454
+ @. Yₜ. c. sgsʲs.:($$ j). mse += va
455
+ va = vertical_advection (ᶠw³ʲ, ᶜqʲ, edmf_upwnd)
456
+ @. Yₜ. c. sgsʲs.:($$ j). mse -= Y. c. sgsʲs.:($$ j). mse * va
457
+
458
+ # mse, q_tot and moisture tracers terms proportional to 1/ρ̂ ∂zρ̂
459
+ # Eq (1-3) term (3)
460
+ ᶜinv_ρ̂ = (@. lazy (
461
+ specific (
462
+ FT (1 ),
463
+ Y. c. sgsʲs.:($$ j). ρa,
464
+ FT (0 ),
465
+ Y. c. ρ,
466
+ turbconv_model,
467
+ ),
468
+ ))
469
+ ᶜ∂ρ̂∂z = (@. lazy (
470
+ upwind_biased_grad (
471
+ - 1 * Geometry. WVector (ᶜwʲ),
472
+ Y. c. sgsʲs.:($$ j). ρa,
473
+ ),
474
+ ))
475
+ @. Yₜ. c. sgsʲs.:($$ j). mse -=
476
+ dot (ᶜinv_ρ̂ * ᶜ∂ρ̂∂z, ᶜw³ʲ) *
477
+ ᶜqʲ *
478
+ (ᶜmse_li - Y. c. sgsʲs.:($$ j). mse)
479
+ @. Yₜ. c. sgsʲs.:($$ j). q_tot -=
480
+ dot (ᶜinv_ρ̂ * ᶜ∂ρ̂∂z, ᶜw³ʲ) *
481
+ ᶜqʲ *
482
+ (1 - Y. c. sgsʲs.:($$ j). q_tot)
483
+ @. ᶜqʲₜ -= dot (ᶜinv_ρ̂ * ᶜ∂ρ̂∂z, ᶜw³ʲ) * ᶜqʲ
484
+
485
+ # mse, q_tot and moisture tracer terms proportional to velocity gradients
486
+ # Eq (1-3) term (4)
487
+ @. Yₜ. c. sgsʲs.:($$ j). mse -=
488
+ ᶜdivᵥ (ᶠw³ʲ) * ᶜqʲ * (ᶜmse_li - Y. c. sgsʲs.:($$ j). mse)
489
+ @. Yₜ. c. sgsʲs.:($$ j). q_tot -=
490
+ ᶜdivᵥ (ᶠw³ʲ) * ᶜqʲ * (1 - Y. c. sgsʲs.:($$ j). q_tot)
491
+ @. ᶜqʲₜ -= ᶜdivᵥ (ᶠw³ʲ) * ᶜqʲ
492
+ end
425
493
end
426
494
end
427
495
end
0 commit comments