Skip to content

Commit

Permalink
run for HybridBox
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Apr 12, 2024
1 parent 80e1a5a commit 627e577
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
3 changes: 0 additions & 3 deletions src/shared_utilities/Domains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,8 @@ corresponding to the surface, with values equal to the topmost level.
"""
function top_center_to_surface(center_field::ClimaCore.Fields.Field)
center_space = axes(center_field)
# face_space = obtain_face_space(center_space)
# N = ClimaCore.Spaces.nlevels(face_space)
N_minus_half = ClimaCore.Spaces.nlevels(center_space)
surface_space = obtain_surface_space(center_space)
# level = ClimaCore.Fields.level(center_field, ClimaCore.Spaces.nlevels(center_space))
return ClimaCore.Fields.Field(
ClimaCore.Fields.field_values(
ClimaCore.Fields.level(center_field, N_minus_half),
Expand Down
11 changes: 8 additions & 3 deletions src/standalone/Soil/boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,18 @@ function ClimaLand.set_dfluxBCdY!(
θ_rN = Domains.top_center_to_surface(θ_r)
S_sN = Domains.top_center_to_surface(S_s)

# Extract the local geometry of the top face space
local_geometryN = Fields.local_geometry_field(KN)

# Get the local geometry of the face space, then extract the top level
levels = ClimaCore.Spaces.nlevels(Domains.obtain_face_space(axes(p.soil.K)))
local_geometry_faceN = ClimaCore.Fields.level(
Fields.local_geometry_field(Domains.obtain_face_space(axes(p.soil.K))),
levels - ClimaCore.Utilities.half,
)

# Update dfluxBCdY at the top boundary in place
# Calculate the value and convert it to a Covariant3Vector
@. p.soil.dfluxBCdY =
covariant3_unit_vector(local_geometryN) *
covariant3_unit_vector(local_geometry_faceN) *
(KN * dψdϑ(hydrology_cmN, ϑ_lN, νN, θ_rN, S_sN) / Δz)
return nothing
end
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ end
end

# Standalone Bucket model tests
@safetestset "Bucket albedo types tests" begin
include("standalone/Bucket/albedo_types.jl")
end
# @safetestset "Bucket albedo types tests" begin
# include("standalone/Bucket/albedo_types.jl")
# end
@safetestset "Bucket snow tests" begin
include("standalone/Bucket/snow_bucket_tests.jl")
end
Expand Down
41 changes: 22 additions & 19 deletions test/shared_utilities/implicit_timestepping/richards_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ for FT in (Float32, Float64)
@test Array(parent(jac_ϑ_l.entries.:3))[end] == FT(0)
@test all(
Array(parent(jac_ϑ_l.entries.:1))[2:end] .≈
K_ic / dz^2 * dψdϑ_ic,
dtγ * (K_ic / dz^2 * dψdϑ_ic),
)
# Check values on main diagonal: note jac_ϑ_l is I-γJ
@test Array(parent(jac_ϑ_l.entries.:2))[1] .≈
Expand Down Expand Up @@ -111,7 +111,7 @@ for FT in (Float32, Float64)
)
@test all(
Array(parent(jac_ϑ_l.entries.:1))[2:end, :, 1, 1, 1] .≈
K_ic / dz^2 * dψdϑ_ic,
dtγ * (K_ic / dz^2 * dψdϑ_ic),
)
# Check values on main diagonal: note jac_ϑ_l is I-γJ
@test all(
Expand All @@ -127,11 +127,12 @@ for FT in (Float32, Float64)
1,
] .≈ dtγ * (-2 * K_ic / dz^2 * dψdϑ_ic) - I,
)
# TODO these fail
# @test all(
# Array(parent(jac_ϑ_l.entries.:2))[end, :, 1, 1, 1] .≈
# dtγ * (-K_ic / dz^2 * dψdϑ_ic - K_ic / (dz * dz / 2) * dψdϑ_ic) - I,
# )
@test all(
Array(parent(jac_ϑ_l.entries.:2))[end, :, 1, 1, 1] .≈
dtγ *
(-K_ic / dz^2 * dψdϑ_ic - K_ic / (dz * dz / 2) * dψdϑ_ic) -
I,
)
end

end
Expand Down Expand Up @@ -188,16 +189,19 @@ for FT in (Float32, Float64)
)
dz = FT(0.01)
dψdϑ_ic = dψdϑ(hcm, FT(0.24), ν, θ_r, S_s)
jac_ϑ_l = jacobian.matrix[
MatrixFields.@name(soil.ϑ_l),
MatrixFields.@name(soil.ϑ_l)
]
if typeof(domain) <: Column
@test Array(parent(jac_ϑ_l.entries.:2))[1] .≈
dtγ * (-K_ic / dz^2 * dψdϑ_ic) - I
# TODO these fail
# @test all(
# Array(parent(jac_ϑ_l.entries.:2))[2:(end - 1)] .≈
# dtγ * (-2 * K_ic / dz^2 * dψdϑ_ic) - I,
# )
# @test Array(parent(jac_ϑ_l.entries.:2))[end] .≈
# dtγ * (-K_ic / dz^2 * dψdϑ_ic) - I
@test all(
Array(parent(jac_ϑ_l.entries.:2))[2:(end - 1)] .≈
dtγ * (-2 * K_ic / dz^2 * dψdϑ_ic) - I,
)
@test Array(parent(jac_ϑ_l.entries.:2))[end] .≈
dtγ * (-K_ic / dz^2 * dψdϑ_ic) - I
elseif typeof(domain) <: HybridBox
@test all(
Array(parent(jac_ϑ_l.entries.:2))[1, :, 1, 1, 1] .≈
Expand All @@ -212,11 +216,10 @@ for FT in (Float32, Float64)
1,
] .≈ dtγ * (-2 * K_ic / dz^2 * dψdϑ_ic) - I,
)
# TODO these fail
# @test all(
# Array(parent(jac_ϑ_l.entries.:2))[end, :, 1, 1, 1] .≈
# dtγ * (-K_ic / dz^2 * dψdϑ_ic - K_ic / (dz * dz / 2) * dψdϑ_ic) - I,
# )
@test all(
Array(parent(jac_ϑ_l.entries.:2))[end, :, 1, 1, 1] .≈
dtγ * (-K_ic / dz^2 * dψdϑ_ic) - I,
)
end
end
end
Expand Down

0 comments on commit 627e577

Please sign in to comment.