From 939ab6462715117715ae4b75a85504e2197428e0 Mon Sep 17 00:00:00 2001 From: imreddyTeja Date: Tue, 13 Aug 2024 11:45:24 -0700 Subject: [PATCH] Fix the method definition warning in tests The previous implementation of the Integrated LSM unit tests used a for loop to test different types. This commit moves struct definitions outside of the for loop. --- test/integrated/lsms.jl | 137 +++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 71 deletions(-) diff --git a/test/integrated/lsms.jl b/test/integrated/lsms.jl index 60943796ff..28d86b37b5 100644 --- a/test/integrated/lsms.jl +++ b/test/integrated/lsms.jl @@ -20,73 +20,67 @@ import ClimaLand: land_components using ClimaLand -for FT in (Float32, Float64) - @testset "LSM prognostic tests, FT = $FT" begin - struct DummyModel1{FT} <: ClimaLand.AbstractModel{FT} - domain::Any - end - ClimaLand.name(::DummyModel1) = :m1 - ClimaLand.prognostic_vars(::DummyModel1) = (:a,) - ClimaLand.prognostic_types(::DummyModel1{FT}) where {FT} = (FT,) - ClimaLand.prognostic_domain_names(::DummyModel1) = (:surface,) - ClimaLand.auxiliary_vars(::DummyModel1) = (:b,) - ClimaLand.auxiliary_types(::DummyModel1{FT}) where {FT} = (FT,) - ClimaLand.auxiliary_domain_names(::DummyModel1) = (:surface,) - struct DummyModel2{FT} <: ClimaLand.AbstractModel{FT} - domain::Any - end - ClimaLand.name(::DummyModel2) = :m2 - ClimaLand.prognostic_vars(::DummyModel2) = (:c, :d) - ClimaLand.prognostic_types(::DummyModel2{FT}) where {FT} = (FT, FT) - ClimaLand.prognostic_domain_names(::DummyModel2) = +@testset "LSM prognostic tests" begin + struct DummyModel1{FT} <: ClimaLand.AbstractModel{FT} + domain::Any + end + struct DummyModel2{FT} <: ClimaLand.AbstractModel{FT} + domain::Any + end + struct DummyModel{FT} <: ClimaLand.AbstractLandModel{FT} + m1::Any + m2::Any + end + for FT in (Float32, Float64) + + ClimaLand.name(::DummyModel1{FT}) = :m1 + ClimaLand.prognostic_vars(::DummyModel1{FT}) = (:a,) + ClimaLand.prognostic_types(::DummyModel1{FT}) = (FT,) + ClimaLand.prognostic_domain_names(::DummyModel1{FT}) = (:surface,) + ClimaLand.auxiliary_vars(::DummyModel1{FT}) = (:b,) + ClimaLand.auxiliary_types(::DummyModel1{FT}) = (FT,) + ClimaLand.auxiliary_domain_names(::DummyModel1{FT}) = (:surface,) + ClimaLand.name(::DummyModel2{FT}) = :m2 + ClimaLand.prognostic_vars(::DummyModel2{FT}) = (:c, :d) + ClimaLand.prognostic_types(::DummyModel2{FT}) = (FT, FT) + ClimaLand.prognostic_domain_names(::DummyModel2{FT}) = (:surface, :subsurface) - struct DummyModel{FT} <: ClimaLand.AbstractLandModel{FT} - m1::Any - m2::Any - end - ClimaLand.land_components(::DummyModel) = (:m1, :m2) - ClimaLand.lsm_aux_vars(::DummyModel) = (:i1,) - ClimaLand.lsm_aux_types(::DummyModel{FT}) where {FT} = (FT,) - ClimaLand.lsm_aux_domain_names(::DummyModel) = (:surface,) + ClimaLand.land_components(::DummyModel{FT}) = (:m1, :m2) + ClimaLand.lsm_aux_vars(::DummyModel{FT}) = (:i1,) + ClimaLand.lsm_aux_types(::DummyModel{FT}) = (FT,) + ClimaLand.lsm_aux_domain_names(::DummyModel{FT}) = (:surface,) - - - function ClimaLand.make_update_aux(::DummyModel1{FT}) where {FT} + function ClimaLand.make_update_aux(::DummyModel1{FT}) function update_aux!(p, Y, t) p.m1.b .= FT(10.0) end return update_aux! end - function ClimaLand.make_update_boundary_fluxes( - ::DummyModel{FT}, - ) where {FT} + function ClimaLand.make_update_boundary_fluxes(::DummyModel{FT}) function update_aux!(p, Y, t) p.i1 .= FT(5.0) end return update_aux! end - function ClimaLand.make_compute_exp_tendency( - ::DummyModel1{FT}, - ) where {FT} + function ClimaLand.make_compute_exp_tendency(::DummyModel1{FT}) function compute_exp_tendency!(dY, Y, p, t) dY.m1.a .= p.m1.b end return compute_exp_tendency! end - function ClimaLand.make_compute_exp_tendency( - ::DummyModel2{FT}, - ) where {FT} + function ClimaLand.make_compute_exp_tendency(::DummyModel2{FT}) function compute_exp_tendency!(dY, Y, p, t) dY.m2.c .= p.i1 dY.m2.d .= FT(-1.0) end return compute_exp_tendency! end + d = ClimaLand.Domains.Column(; zlim = (FT(-2), FT(0)), nelements = 5) m1 = DummyModel1{FT}(d) m2 = DummyModel2{FT}(d) @@ -101,38 +95,38 @@ for FT in (Float32, Float64) @test all(parent(dY.m1.a) .== FT(10)) @test all(parent(dY.m2.c) .== FT(5)) @test all(parent(dY.m2.d) .== FT(-1)) - end +end - @testset "LSM aux tests, FT = $FT" begin - struct DummyModel3{FT} <: ClimaLand.AbstractModel{FT} - domain::Any - end - ClimaLand.name(::DummyModel3) = :m1 - ClimaLand.auxiliary_vars(::DummyModel3) = (:a, :b) - ClimaLand.auxiliary_types(::DummyModel3{FT}) where {FT} = (FT, FT) - ClimaLand.auxiliary_domain_names(::DummyModel3) = (:surface, :surface) - ClimaLand.prognostic_vars(::DummyModel3) = (:c,) - ClimaLand.prognostic_types(::DummyModel3{FT}) where {FT} = (FT,) - ClimaLand.prognostic_domain_names(::DummyModel3) = (:surface,) - - struct DummyModel4{FT} <: ClimaLand.AbstractModel{FT} - domain::Any - end - - ClimaLand.name(::DummyModel4) = :m2 - ClimaLand.auxiliary_vars(::DummyModel4) = (:d, :e) - ClimaLand.auxiliary_types(::DummyModel4{FT}) where {FT} = (FT, FT) - ClimaLand.auxiliary_domain_names(::DummyModel4) = (:surface, :surface) - ClimaLand.prognostic_vars(::DummyModel4) = (:f,) - ClimaLand.prognostic_types(::DummyModel4{FT}) where {FT} = (FT,) - ClimaLand.prognostic_domain_names(::DummyModel4) = (:surface,) - - struct DummyModelB{FT} <: ClimaLand.AbstractLandModel{FT} - m1::Any - m2::Any - end - ClimaLand.land_components(::DummyModelB) = (:m1, :m2) +@testset "LSM aux tests" begin + struct DummyModel3{FT} <: ClimaLand.AbstractModel{FT} + domain::Any + end + struct DummyModel4{FT} <: ClimaLand.AbstractModel{FT} + domain::Any + end + struct DummyModelB{FT} <: ClimaLand.AbstractLandModel{FT} + m1::Any + m2::Any + end + for FT in (Float32, Float64) + ClimaLand.name(::DummyModel3{FT}) = :m1 + ClimaLand.auxiliary_vars(::DummyModel3{FT}) = (:a, :b) + ClimaLand.auxiliary_types(::DummyModel3{FT}) = (FT, FT) + ClimaLand.auxiliary_domain_names(::DummyModel3{FT}) = + (:surface, :surface) + ClimaLand.prognostic_vars(::DummyModel3{FT}) = (:c,) + ClimaLand.prognostic_types(::DummyModel3{FT}) = (FT,) + ClimaLand.prognostic_domain_names(::DummyModel3{FT}) = (:surface,) + ClimaLand.name(::DummyModel4{FT}) = :m2 + ClimaLand.auxiliary_vars(::DummyModel4{FT}) = (:d, :e) + ClimaLand.auxiliary_types(::DummyModel4{FT}) = (FT, FT) + ClimaLand.auxiliary_domain_names(::DummyModel4{FT}) = + (:surface, :surface) + ClimaLand.prognostic_vars(::DummyModel4{FT}) = (:f,) + ClimaLand.prognostic_types(::DummyModel4{FT}) = (FT,) + ClimaLand.prognostic_domain_names(::DummyModel4{FT}) = (:surface,) + ClimaLand.land_components(::DummyModelB{FT}) = (:m1, :m2) d = ClimaLand.Domains.Point(; z_sfc = FT(0.0)) m1 = DummyModel3{FT}(d) @@ -140,7 +134,8 @@ for FT in (Float32, Float64) m = DummyModelB{FT}(m1, m2) Y, p, cds = ClimaLand.initialize(m) @test propertynames(p) == (:m1, :m2) - function ClimaLand.make_update_aux(::DummyModel3{FT}) where {FT} + + function ClimaLand.make_update_aux(::DummyModel3{FT}) function update_aux!(p, Y, t) p.m1.a .= FT(2.0) p.m1.b .= FT(10.0) @@ -148,7 +143,7 @@ for FT in (Float32, Float64) return update_aux! end - function ClimaLand.make_update_aux(::DummyModel4{FT}) where {FT} + function ClimaLand.make_update_aux(::DummyModel4{FT}) function update_aux!(p, Y, t) p.m2.d .= FT(10.0) p.m2.e .= FT(10.0)