|
| 1 | +import ClimaCore: MatrixFields |
| 2 | +import LinearAlgebra: UniformScaling |
| 3 | + |
1 | 4 | ###
|
2 | 5 | ### edmfx advection test
|
3 | 6 | ###
|
4 | 7 |
|
| 8 | +# Turn off all momentum tendencies in the advection test. |
5 | 9 | function zero_velocity_tendency!(Yₜ, Y, p, t)
|
6 |
| - # turn off all monmentum tendencies in the advection test |
7 |
| - if p.atmos.advection_test |
8 |
| - FT = eltype(Y) |
9 |
| - n = n_mass_flux_subdomains(p.atmos.turbconv_model) |
| 10 | + p.atmos.advection_test || return nothing |
| 11 | + @. Yₜ.c.uₕ = C12(0, 0) |
| 12 | + @. Yₜ.f.u₃ = C3(0) |
| 13 | + if p.atmos.turbconv_model isa PrognosticEDMFX |
| 14 | + for j in 1:n_mass_flux_subdomains(p.atmos.turbconv_model) |
| 15 | + @. Yₜ.f.sgsʲs.:($$j).u₃ = C3(0) |
| 16 | + end |
| 17 | + end |
| 18 | + return nothing |
| 19 | +end |
10 | 20 |
|
11 |
| - @. Yₜ.c.uₕ = C12(FT(0), FT(0)) |
12 |
| - @. Yₜ.f.u₃ = Geometry.Covariant3Vector(FT(0)) |
| 21 | +# Turn off all momentum tendency derivatives in the advection test. |
| 22 | +function zero_velocity_jacobian!(∂Yₜ_err_∂Y, Y, p, t) |
| 23 | + p.atmos.advection_test || return nothing |
| 24 | + for ((row_name, col_name), matrix_entry) in pairs(∂Yₜ_err_∂Y) |
| 25 | + matrix_entry isa Fields.Field || continue |
| 26 | + if row_name in (MatrixFields.@name(c.uₕ), MatrixFields.@name(f.u₃)) |
| 27 | + set_identity_matrix_entry!(matrix_entry, row_name, col_name) |
| 28 | + end |
13 | 29 | if p.atmos.turbconv_model isa PrognosticEDMFX
|
14 |
| - for j in 1:n |
15 |
| - @. Yₜ.f.sgsʲs.:($$j).u₃ = Geometry.Covariant3Vector(FT(0)) |
| 30 | + for j in 1:n_mass_flux_subdomains(p.atmos.turbconv_model) |
| 31 | + if row_name == MatrixFields.FieldName(:f, :sgsʲs, j, :u₃) |
| 32 | + set_identity_matrix_entry!(matrix_entry, row_name, col_name) |
| 33 | + end |
16 | 34 | end
|
17 | 35 | end
|
18 | 36 | end
|
19 |
| - return nothing |
| 37 | +end |
| 38 | + |
| 39 | +function set_identity_matrix_entry!(matrix_entry, row_name, col_name) |
| 40 | + identity_matrix_entry_value = if row_name == col_name |
| 41 | + # TODO: Add a method for one(::Axis2Tensor) to simplify this. |
| 42 | + T = eltype(eltype(matrix_entry)) |
| 43 | + tensor_data = UniformScaling(one(eltype(T))) |
| 44 | + -DiagonalMatrixRow(Geometry.AxisTensor(axes(T), tensor_data)) |
| 45 | + else |
| 46 | + zero(eltype(matrix_entry)) |
| 47 | + end |
| 48 | + matrix_entry .= (identity_matrix_entry_value,) |
20 | 49 | end
|
0 commit comments