Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for leaky tests #2220

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/hybrid/implicit_equation_jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import LinearAlgebra: ldiv!
using ClimaCore: Spaces, Fields, Operators
using ClimaCore.Utilities: half
using ClimaCore.MatrixFields
import ClimaCore.MatrixFields: ⋆
using ClimaCore.MatrixFields: @name

"""
Expand Down
62 changes: 31 additions & 31 deletions examples/hybrid/staggered_nonhydrostatic_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# norm_sqr(C123(ᶜuₕ) + C123(ᶜinterp(ᶠw))) / 2 =
# ACT12(ᶜuₕ) * ᶜuₕ / 2 + ACT3(ᶜinterp(ᶠw)) * ᶜinterp(ᶠw) / 2
# ∂(ᶜK)/∂(ᶠw) = ACT3(ᶜinterp(ᶠw)) * ᶜinterp_matrix()
@. ∂ᶜK∂ᶠw = DiagonalMatrixRow(adjoint(CT3(ᶜinterp(ᶠw)))) ᶜinterp_matrix()
@. ∂ᶜK∂ᶠw = DiagonalMatrixRow(adjoint(CT3(ᶜinterp(ᶠw)))) ᶜinterp_matrix()

# ᶜρₜ = -ᶜdivᵥ(ᶠinterp(ᶜρ) * ᶠw)
# ∂(ᶜρₜ)/∂(ᶠw) = -ᶜdivᵥ_matrix() * ᶠinterp(ᶜρ) * ᶠg³³
@. ∂ᶜρₜ∂ᶠ𝕄 = -(ᶜdivᵥ_matrix()) DiagonalMatrixRow(ᶠinterp(ᶜρ) * g³³(ᶠgⁱʲ))
@. ∂ᶜρₜ∂ᶠ𝕄 = -(ᶜdivᵥ_matrix()) DiagonalMatrixRow(ᶠinterp(ᶜρ) * g³³(ᶠgⁱʲ))

if :ρθ in propertynames(Y.c)
ᶜρθ = Y.c.ρθ
Expand All @@ -349,14 +349,14 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ᶜρθₜ = -ᶜdivᵥ(ᶠinterp(ᶜρθ) * ᶠw)
# ∂(ᶜρθₜ)/∂(ᶠw) = -ᶜdivᵥ_matrix() * ᶠinterp(ᶜρθ) * ᶠg³³
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(ᶠinterp(ᶜρθ) * g³³(ᶠgⁱʲ))
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(ᶠinterp(ᶜρθ) * g³³(ᶠgⁱʲ))
else
# ᶜρθₜ = -ᶜdivᵥ(ᶠinterp(ᶜρ) * ᶠupwind_product(ᶠw, ᶜρθ / ᶜρ))
# ∂(ᶜρθₜ)/∂(ᶠw) =
# -ᶜdivᵥ_matrix() * ᶠinterp(ᶜρ) *
# ∂(ᶠupwind_product(ᶠw, ᶜρθ / ᶜρ))/∂(ᶠw)
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(
ᶠinterp(ᶜρ) *
vec_data(ᶠno_flux(ᶠupwind_product(ᶠw + εw, ᶜρθ / ᶜρ))) /
vec_data(CT3(ᶠw + εw)) * g³³(ᶠgⁱʲ),
Expand All @@ -381,10 +381,10 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶜp)/∂(ᶠw) = ∂(ᶜp)/∂(ᶜK) * ∂(ᶜK)/∂(ᶠw)
# ∂(ᶜp)/∂(ᶜK) = -ᶜρ * R_d / cv_d
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix()) (
-(ᶜdivᵥ_matrix()) (
DiagonalMatrixRow(ᶠinterp(ᶜρe + ᶜp) * g³³(ᶠgⁱʲ)) +
DiagonalMatrixRow(CT3(ᶠw)) ᶠinterp_matrix()
DiagonalMatrixRow(-(ᶜρ * R_d / cv_d)) ∂ᶜK∂ᶠw
DiagonalMatrixRow(CT3(ᶠw)) ᶠinterp_matrix()
DiagonalMatrixRow(-(ᶜρ * R_d / cv_d)) ∂ᶜK∂ᶠw
)
else
# ᶜρeₜ =
Expand All @@ -397,15 +397,15 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶜp)/∂(ᶠw) = ∂(ᶜp)/∂(ᶜK) * ∂(ᶜK)/∂(ᶠw)
# ∂(ᶜp)/∂(ᶜK) = -ᶜρ * R_d / cv_d
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(ᶠinterp(ᶜρ)) (
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(ᶠinterp(ᶜρ)) (
DiagonalMatrixRow(
vec_data(
ᶠno_flux(
ᶠupwind_product(ᶠw + εw, (ᶜρe + ᶜp) / ᶜρ),
),
) / vec_data(CT3(ᶠw + εw)) * g³³(ᶠgⁱʲ),
) +
ᶠno_flux_row(ᶠupwind_product_matrix(ᶠw))
ᶠno_flux_row(ᶠupwind_product_matrix(ᶠw))
(-R_d / cv_d * ∂ᶜK∂ᶠw)
)
end
Expand All @@ -414,11 +414,11 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂ᶜ𝔼ₜ∂ᶠ𝕄 has 3 diagonals instead of 5
if isnothing(ᶠupwind_product)
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix())
-(ᶜdivᵥ_matrix())
DiagonalMatrixRow(ᶠinterp(ᶜρe + ᶜp) * g³³(ᶠgⁱʲ))
else
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(
ᶠinterp(ᶜρ) * vec_data(
ᶠno_flux(ᶠupwind_product(ᶠw + εw, (ᶜρe + ᶜp) / ᶜρ)),
) / vec_data(CT3(ᶠw + εw)) * g³³(ᶠgⁱʲ),
Expand All @@ -443,9 +443,9 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# -ᶜdivᵥ_matrix() * ᶠinterp(ᶜρe_int + ᶜp) * ᶠg³³ +
# ᶜinterp_matrix() * adjoint(ᶠgradᵥ(ᶜp)) * ᶠg³³
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix())
-(ᶜdivᵥ_matrix())
DiagonalMatrixRow(ᶠinterp(ᶜρe_int + ᶜp) * g³³(ᶠgⁱʲ)) +
ᶜinterp_matrix()
ᶜinterp_matrix()
DiagonalMatrixRow(adjoint(ᶠgradᵥ(ᶜp)) * g³³(ᶠgⁱʲ))
else
# ᶜρe_intₜ =
Expand All @@ -456,12 +456,12 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶠupwind_product(ᶠw, (ᶜρe_int + ᶜp) / ᶜρ))/∂(ᶠw) +
# ᶜinterp_matrix() * adjoint(ᶠgradᵥ(ᶜp)) * ᶠg³³
@. ∂ᶜ𝔼ₜ∂ᶠ𝕄 =
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(
-(ᶜdivᵥ_matrix()) DiagonalMatrixRow(
ᶠinterp(ᶜρ) * vec_data(
ᶠno_flux(ᶠupwind_product(ᶠw + εw, (ᶜρe_int + ᶜp) / ᶜρ)),
) / vec_data(CT3(ᶠw + εw)) * g³³(ᶠgⁱʲ),
) +
ᶜinterp_matrix()
ᶜinterp_matrix()
DiagonalMatrixRow(adjoint(ᶠgradᵥ(ᶜp)) * g³³(ᶠgⁱʲ))
end
end
Expand All @@ -480,7 +480,7 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶠgradᵥ(ᶜp))/∂(ᶜρθ) =
# ᶠgradᵥ_matrix() * γ * R_d * (ᶜρθ * R_d / p_0)^(γ - 1)
@. ∂ᶠ𝕄ₜ∂ᶜ𝔼 =
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
DiagonalMatrixRow(γ * R_d * (ᶜρθ * R_d / p_0)^(γ - 1))

if flags.∂ᶠ𝕄ₜ∂ᶜρ_mode == :exact
Expand All @@ -489,20 +489,20 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶠwₜ)/∂(ᶠinterp(ᶜρ)) = ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2
# ∂(ᶠinterp(ᶜρ))/∂(ᶜρ) = ᶠinterp_matrix()
@. ∂ᶠ𝕄ₜ∂ᶜρ =
DiagonalMatrixRow(ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2) ᶠinterp_matrix()
DiagonalMatrixRow(ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2) ᶠinterp_matrix()
elseif flags.∂ᶠ𝕄ₜ∂ᶜρ_mode == :hydrostatic_balance
# same as above, but we assume that ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ) =
# -ᶠgradᵥ(ᶜΦ)
@. ∂ᶠ𝕄ₜ∂ᶜρ =
-DiagonalMatrixRow(ᶠgradᵥ(ᶜΦ) / ᶠinterp(ᶜρ)) ᶠinterp_matrix()
-DiagonalMatrixRow(ᶠgradᵥ(ᶜΦ) / ᶠinterp(ᶜρ)) ᶠinterp_matrix()
end
elseif :ρe in propertynames(Y.c)
# ᶠwₜ = -ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ) - ᶠgradᵥ(ᶜK + ᶜΦ)
# ∂(ᶠwₜ)/∂(ᶜρe) = ∂(ᶠwₜ)/∂(ᶠgradᵥ(ᶜp)) * ∂(ᶠgradᵥ(ᶜp))/∂(ᶜρe)
# ∂(ᶠwₜ)/∂(ᶠgradᵥ(ᶜp)) = -1 / ᶠinterp(ᶜρ)
# ∂(ᶠgradᵥ(ᶜp))/∂(ᶜρe) = ᶠgradᵥ_matrix() * R_d / cv_d
@. ∂ᶠ𝕄ₜ∂ᶜ𝔼 =
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) (ᶠgradᵥ_matrix() * R_d / cv_d)
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) (ᶠgradᵥ_matrix() * R_d / cv_d)

if flags.∂ᶠ𝕄ₜ∂ᶜρ_mode == :exact
# ᶠwₜ = -ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ) - ᶠgradᵥ(ᶜK + ᶜΦ)
Expand All @@ -515,24 +515,24 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶠwₜ)/∂(ᶠinterp(ᶜρ)) = ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2
# ∂(ᶠinterp(ᶜρ))/∂(ᶜρ) = ᶠinterp_matrix()
@. ∂ᶠ𝕄ₜ∂ᶜρ =
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
DiagonalMatrixRow(R_d * (-(ᶜK + ᶜΦ) / cv_d + T_tri)) +
DiagonalMatrixRow(ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2) ᶠinterp_matrix()
DiagonalMatrixRow(ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2) ᶠinterp_matrix()
elseif flags.∂ᶠ𝕄ₜ∂ᶜρ_mode == :hydrostatic_balance
# same as above, but we assume that ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ) =
# -ᶠgradᵥ(ᶜΦ) and that ᶜK is negligible compared ot ᶜΦ
@. ∂ᶠ𝕄ₜ∂ᶜρ =
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
DiagonalMatrixRow(R_d * (-(ᶜΦ) / cv_d + T_tri)) -
DiagonalMatrixRow(ᶠgradᵥ(ᶜΦ) / ᶠinterp(ᶜρ)) ᶠinterp_matrix()
DiagonalMatrixRow(ᶠgradᵥ(ᶜΦ) / ᶠinterp(ᶜρ)) ᶠinterp_matrix()
end
elseif :ρe_int in propertynames(Y.c)
# ᶠwₜ = -ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ) - ᶠgradᵥ(ᶜK + ᶜΦ)
# ∂(ᶠwₜ)/∂(ᶜρe_int) = ∂(ᶠwₜ)/∂(ᶠgradᵥ(ᶜp)) * ∂(ᶠgradᵥ(ᶜp))/∂(ᶜρe_int)
# ∂(ᶠwₜ)/∂(ᶠgradᵥ(ᶜp)) = -1 / ᶠinterp(ᶜρ)
# ∂(ᶠgradᵥ(ᶜp))/∂(ᶜρe_int) = ᶠgradᵥ_matrix() * R_d / cv_d
@. ∂ᶠ𝕄ₜ∂ᶜ𝔼 =
DiagonalMatrixRow(-1 / ᶠinterp(ᶜρ)) (ᶠgradᵥ_matrix() * R_d / cv_d)
DiagonalMatrixRow(-1 / ᶠinterp(ᶜρ)) (ᶠgradᵥ_matrix() * R_d / cv_d)

if flags.∂ᶠ𝕄ₜ∂ᶜρ_mode == :exact
# ᶠwₜ = -ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ) - ᶠgradᵥ(ᶜK + ᶜΦ)
Expand All @@ -544,16 +544,16 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶠwₜ)/∂(ᶠinterp(ᶜρ)) = ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2
# ∂(ᶠinterp(ᶜρ))/∂(ᶜρ) = ᶠinterp_matrix()
@. ∂ᶠ𝕄ₜ∂ᶜρ =
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ))
-DiagonalMatrixRow(1 / ᶠinterp(ᶜρ))
(ᶠgradᵥ_matrix() * R_d * T_tri) +
DiagonalMatrixRow(ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2) ᶠinterp_matrix()
DiagonalMatrixRow(ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ)^2) ᶠinterp_matrix()
elseif flags.∂ᶠ𝕄ₜ∂ᶜρ_mode == :hydrostatic_balance
# same as above, but we assume that ᶠgradᵥ(ᶜp) / ᶠinterp(ᶜρ) =
# -ᶠgradᵥ(ᶜΦ)
@. ∂ᶠ𝕄ₜ∂ᶜρ =
DiagonalMatrixRow(-1 / ᶠinterp(ᶜρ))
DiagonalMatrixRow(-1 / ᶠinterp(ᶜρ))
(ᶠgradᵥ_matrix() * R_d * T_tri) -
DiagonalMatrixRow(ᶠgradᵥ(ᶜΦ) / ᶠinterp(ᶜρ)) ᶠinterp_matrix()
DiagonalMatrixRow(ᶠgradᵥ(ᶜΦ) / ᶠinterp(ᶜρ)) ᶠinterp_matrix()
end
end

Expand All @@ -571,13 +571,13 @@ function implicit_equation_jacobian!(j, Y, p, δtγ, t)
# ∂(ᶠwₜ)/∂(ᶠgradᵥ(ᶜK + ᶜΦ)) = -1
# ∂(ᶠgradᵥ(ᶜK + ᶜΦ))/∂(ᶜK) = ᶠgradᵥ_matrix()
if :ρθ in propertynames(Y.c) || :ρe_int in propertynames(Y.c)
@. ∂ᶠ𝕄ₜ∂ᶠ𝕄 = -(ᶠgradᵥ_matrix()) ∂ᶜK∂ᶠw
@. ∂ᶠ𝕄ₜ∂ᶠ𝕄 = -(ᶠgradᵥ_matrix()) ∂ᶜK∂ᶠw
elseif :ρe in propertynames(Y.c)
@. ∂ᶠ𝕄ₜ∂ᶠ𝕄 =
-(
DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
DiagonalMatrixRow(1 / ᶠinterp(ᶜρ)) ᶠgradᵥ_matrix()
DiagonalMatrixRow(-(ᶜρ * R_d / cv_d)) + ᶠgradᵥ_matrix()
) ∂ᶜK∂ᶠw
) ∂ᶜK∂ᶠw
end

I = one(∂R∂Y)
Expand Down
2 changes: 1 addition & 1 deletion src/MatrixFields/MatrixFields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export DiagonalMatrixRow,
QuaddiagonalMatrixRow,
PentadiagonalMatrixRow
export FieldVectorKeys, FieldMatrixKeys, FieldVectorView, FieldMatrix
export FieldMatrixWithSolver, ⋅
export FieldMatrixWithSolver

include("band_matrix_row.jl")

Expand Down
1 change: 1 addition & 0 deletions src/MatrixFields/matrix_multiplication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ This means that we can express the bounds on the interior values of ``i`` as
"""
struct MultiplyColumnwiseBandMatrixField <: Operators.FiniteDifferenceOperator end
const ⋅ = MultiplyColumnwiseBandMatrixField()
const ⋆ = MultiplyColumnwiseBandMatrixField()

Operators.strip_space(op::MultiplyColumnwiseBandMatrixField, _) = op

Expand Down
15 changes: 4 additions & 11 deletions test/Fields/benchmark_fieldvectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ if ClimaComms.device() isa ClimaComms.CUDADevice
else
device_name = "CPU"
end
if !(@isdefined(TU))
include(
joinpath(
pkgdir(ClimaCore),
"test",
"TestUtilities",
"TestUtilities.jl",
),
)
import .TestUtilities as TU
end
@isdefined(TU) || include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
);
import .TestUtilities as TU

include(joinpath(pkgdir(ClimaCore), "benchmarks/scripts/benchmark_utils.jl"))

Expand Down
4 changes: 2 additions & 2 deletions test/Fields/convergence_field_integrals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ using LinearAlgebra: norm
using Statistics: mean
using ForwardDiff

include(
@isdefined(TU) || include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
)
);
import .TestUtilities as TU

"""
Expand Down
4 changes: 2 additions & 2 deletions test/Fields/field_opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ using LinearAlgebra: norm
using Statistics: mean
using ForwardDiff

include(
@isdefined(TU) || include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
)
);
import .TestUtilities as TU

# https://github.com/CliMA/ClimaCore.jl/issues/946
Expand Down
4 changes: 2 additions & 2 deletions test/Fields/unit_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ using LinearAlgebra: norm
using Statistics: mean
using ForwardDiff

include(
@isdefined(TU) || include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
)
);
import .TestUtilities as TU

function spectral_space_2D(; n1 = 1, n2 = 1, Nij = 4)
Expand Down
15 changes: 4 additions & 11 deletions test/Fields/utils_field_multi_broadcast_fusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ using LinearAlgebra: norm
using Statistics: mean
using ForwardDiff

if !(@isdefined(TU))
include(
joinpath(
pkgdir(ClimaCore),
"test",
"TestUtilities",
"TestUtilities.jl",
),
)
import .TestUtilities as TU
end
@isdefined(TU) || include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
);
import .TestUtilities as TU

@show ClimaComms.device()

Expand Down
6 changes: 3 additions & 3 deletions test/InputOutput/unit_read_type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import ClimaCore
import ClimaCore: Fields, InputOutput
using ClimaComms
ClimaComms.@import_required_backends
include(
@isdefined(TU) || include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
)
import .TestUtilities as TU
);
import .TestUtilities as TU;

compare_read_type(x) = InputOutput.read_type(string(eltype(x))) == eltype(x)
@testset "Read field element types" begin
Expand Down
15 changes: 9 additions & 6 deletions test/MatrixFields/field_names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import ClimaCore.MatrixFields: @name, is_subset_that_covers_set

include("matrix_field_test_utils.jl")

struct Foo{T}
struct FieldNameFoo{T}
_value::T
end
Base.propertynames(::Foo) = (:value,)
Base.getproperty(foo::Foo, s::Symbol) =
Base.propertynames(::FieldNameFoo) = (:value,)
Base.getproperty(foo::FieldNameFoo, s::Symbol) =
s == :value ? getfield(foo, :_value) : error("Invalid property name")
Base.convert(::Type{Foo{T}}, foo::Foo) where {T} = Foo{T}(foo.value)
Base.zero(::Type{Foo{T}}) where {T} = Foo(zero(T))
Base.convert(::Type{FieldNameFoo{T}}, foo::FieldNameFoo) where {T} = FieldNameFoo{T}(foo.value)
Base.zero(::Type{FieldNameFoo{T}}) where {T} = FieldNameFoo(zero(T))

const x = (; foo = Foo(0), a = (; b = 1, c = ((; d = 2), (;), (3, ()))))
get_x() = (; foo = FieldNameFoo(0), a = (; b = 1, c = ((; d = 2), (;), (3, ()))))

@testset "FieldName Unit Tests" begin
x = get_x()
@test_all @name() == MatrixFields.FieldName()
@test_all @name(a.c.:(1).d) == MatrixFields.FieldName(:a, :c, 1, :d)
@test_all @name(a.c.:(3).:(1)) == MatrixFields.FieldName(:a, :c, 3, 1)
Expand Down Expand Up @@ -81,6 +82,7 @@ const x = (; foo = Foo(0), a = (; b = 1, c = ((; d = 2), (;), (3, ()))))
end

@testset "FieldNameTree Unit Tests" begin
x = get_x()
name_tree = MatrixFields.FieldNameTree(x)

@test_all MatrixFields.FieldNameTree(x) == name_tree
Expand Down Expand Up @@ -110,6 +112,7 @@ end
end

@testset "FieldNameSet Unit Tests" begin
x = get_x()
name_tree = MatrixFields.FieldNameTree(x)

vector_keys(names...) = MatrixFields.FieldVectorKeys(names, name_tree)
Expand Down
7 changes: 4 additions & 3 deletions test/MatrixFields/flat_spaces.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import ClimaCore
include(
@isdefined(TU) || include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
)
);
import .TestUtilities as TU

include("matrix_field_test_utils.jl")
import ClimaCore.MatrixFields: @name, ⋅
import ClimaCore.MatrixFields: @name
import ClimaCore.MatrixFields: ⋆

@testset "Matrix Fields with Spectral Element and Point Spaces" begin
get_j_field(space, FT) = fill(MatrixFields.DiagonalMatrixRow(FT(1)), space)
Expand Down
Loading
Loading