Skip to content

Commit

Permalink
Fix the method definition warning in tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
imreddyTeja authored and treddy0205@gmail.com committed Aug 14, 2024
1 parent 89b329c commit 7ea7461
Showing 1 changed file with 66 additions and 71 deletions.
137 changes: 66 additions & 71 deletions test/integrated/lsms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -101,54 +95,55 @@ 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)
m2 = DummyModel4{FT}(d)
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)
end
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)
Expand Down

0 comments on commit 7ea7461

Please sign in to comment.