diff --git a/test/conservation_checker_tests.jl b/test/conservation_checker_tests.jl index b5bcf1afb1..4a8f3f51df 100644 --- a/test/conservation_checker_tests.jl +++ b/test/conservation_checker_tests.jl @@ -25,32 +25,55 @@ struct TestAtmos{I} <: Interfacer.AtmosModelSimulation i::I end name(s::TestAtmos) = "TestAtmos" +function get_field(s::TestAtmos, ::Val{:F_radiative_TOA}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(200) +end +function get_field(s::TestAtmos, ::Val{:energy}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(1e6) +end +function get_field(s::TestAtmos, ::Val{:water}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(1) +end struct TestOcean{I} <: Interfacer.SurfaceModelSimulation i::I end name(s::TestOcean) = "TestOcean" +function get_field(s::TestOcean, ::Val{:energy}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(1e6) +end +function get_field(s::TestOcean, ::Val{:water}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(0) +end +function get_field(s::TestOcean, ::Val{:area_fraction}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(0.25) +end struct TestLand{I} <: Interfacer.SurfaceModelSimulation i::I end name(s::TestLand) = "TestLand" - +function get_field(s::TestLand, ::Val{:energy}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(0) +end +function get_field(s::TestLand, ::Val{:water}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(0) +end +function get_field(s::TestLand, ::Val{:area_fraction}) + FT = Domains.float_type(Meshes.domain(s.i.space.grid.topology.mesh)) + ones(s.i.space) .* FT.(0.25) +end for FT in (Float32, Float64) - global get_field(s::TestAtmos, ::Val{:F_radiative_TOA}) = ones(s.i.space) .* FT.(200) - global get_field(s::TestAtmos, ::Val{:energy}) = ones(s.i.space) .* FT.(1e6) - global get_field(s::TestAtmos, ::Val{:water}) = ones(s.i.space) .* FT.(1) - - global get_field(s::TestOcean, ::Val{:energy}) = ones(s.i.space) .* FT.(1e6) - global get_field(s::TestOcean, ::Val{:water}) = ones(s.i.space) .* FT.(0) - global get_field(s::TestOcean, ::Val{:area_fraction}) = ones(s.i.space) .* FT.(0.25) - - global get_field(s::TestLand, ::Val{:energy}) = ones(s.i.space) .* FT.(0) - global get_field(s::TestLand, ::Val{:water}) = ones(s.i.space) .* FT.(0) - global get_field(s::TestLand, ::Val{:area_fraction}) = ones(s.i.space) .* FT.(0.25) - @testset "test check_conservation for conservation for FT=$FT" begin space = TestHelper.create_space(FT) diff --git a/test/diagnostics_tests.jl b/test/diagnostics_tests.jl index 4e0a3bd8d4..2ba04fc9c6 100644 --- a/test/diagnostics_tests.jl +++ b/test/diagnostics_tests.jl @@ -19,10 +19,9 @@ import ClimaCoupler.Diagnostics: post_save, save_time_format +get_var(cs::Interfacer.CoupledSimulation, ::Val{:x}) = float_type(cs)(1) for FT in (Float32, Float64) - global get_var(cs::Interfacer.CoupledSimulation, ::Val{:x}) = FT(1) - @testset "init_diagnostics for FT=$FT" begin names = (:x, :y) space = create_space(FT) diff --git a/test/flux_calculator_tests.jl b/test/flux_calculator_tests.jl index 0c89c1e982..d5bab403e7 100644 --- a/test/flux_calculator_tests.jl +++ b/test/flux_calculator_tests.jl @@ -110,6 +110,14 @@ function get_thermo_params(sim::TestAtmos) TP.ThermodynamicsParameters{FT}(; pairs...) end +function get_surface_params(sim::TestAtmos) + FT = sim.params.FT + toml_dict = CP.create_toml_dict(FT; dict_type = "alias") + sf_params = create_parameters(toml_dict, UF.BusingerType()) + return sf_params +end + + # ocean sim object and extensions struct TestOcean{M, Y, D, I} <: Interfacer.SurfaceModelSimulation model::M @@ -208,10 +216,6 @@ for FT in (Float32, Float64) @test_throws ErrorException calculate_surface_air_density(sim2, coupler_fields.T_sfc) end - toml_dict = CP.create_toml_dict(FT; dict_type = "alias") - sf_params = create_parameters(toml_dict, UF.BusingerType()) - global get_surface_params(::TestAtmos) = sf_params - @testset "calculate correct fluxes: dry for FT=$FT" begin surface_scheme_list = (MoninObukhovScheme(), BulkScheme()) for scheme in surface_scheme_list @@ -321,7 +325,10 @@ for FT in (Float32, Float64) end @testset "get_surface_params for FT=$FT" begin - @test get_surface_params(TestAtmos([], [], [], [])) == sf_params + toml_dict = CP.create_toml_dict(FT; dict_type = "alias") + sf_params = create_parameters(toml_dict, UF.BusingerType()) + + @test get_surface_params(TestAtmos((; FT = FT), [], [], [])) == sf_params sim = DummySimulation([], []) @test_throws ErrorException( "get_surface_params is required to be dispatched on" * Interfacer.name(sim) * ", but no method defined", diff --git a/test/interfacer_tests.jl b/test/interfacer_tests.jl index ee6a3f129c..e1f503d0c9 100644 --- a/test/interfacer_tests.jl +++ b/test/interfacer_tests.jl @@ -17,16 +17,24 @@ import ClimaCoupler.Interfacer: update_field! # test for a simple generic surface model -struct DummySimulation <: SeaIceModelSimulation end -struct DummySimulation2 <: OceanModelSimulation end -struct DummySimulation3 <: LandModelSimulation end +struct DummySimulation{S} <: SeaIceModelSimulation + space::S +end +struct DummySimulation2{S} <: OceanModelSimulation + space::S +end +struct DummySimulation3{S} <: LandModelSimulation + space::S +end -for FT in (Float32, Float64) - boundary_space = TestHelper.create_space(FT) - global get_field(::SurfaceModelSimulation, ::Val{:var}) = ones(boundary_space) - global get_field(::SurfaceModelSimulation, ::Val{:var_float}) = FT(2) - global get_field(::SurfaceModelSimulation, ::Val{:surface_temperature}) = ones(boundary_space) .* FT(300) +get_field(sim::SurfaceModelSimulation, ::Val{:var}) = ones(sim.space) +get_field(sim::SurfaceModelSimulation, ::Val{:surface_temperature}) = ones(sim.space) .* FT(300) +function get_field(sim::SurfaceModelSimulation, ::Val{:var_float}) + FT = Domains.float_type(Meshes.domain(sim.space.grid.topology.mesh)) + FT(2) +end +for FT in (Float32, Float64) @testset "test CoupledSim construction, float_type for FT=$FT" begin cs = CoupledSimulation{FT}( nothing, # comms_ctx @@ -50,7 +58,8 @@ for FT in (Float32, Float64) end @testset "get_field indexing" begin - for sim in (DummySimulation(), DummySimulation2(), DummySimulation3()) + space = TestHelper.create_space(FT) + for sim in (DummySimulation(space), DummySimulation2(space), DummySimulation3(space)) # field colidx = Fields.ColumnIndex{2}((1, 1), 73) @test parent(get_field(sim, Val(:var), colidx))[1] == FT(1) @@ -60,14 +69,14 @@ for FT in (Float32, Float64) end @testset "undefined get_field" begin - sim = DummySimulation() + space = TestHelper.create_space(FT) + sim = DummySimulation(space) val = Val(:v) @test_throws ErrorException("undefined field $val for " * name(sim)) get_field(sim, val) end # test for a simple generic surface model @testset "get_field for a SurfaceStub" begin - toml_dict = CP.create_toml_dict(FT; dict_type = "alias") aliases = string.(fieldnames(TDP.ThermodynamicsParameters)) param_pairs = CP.get_parameter_values!(toml_dict, aliases, "Thermodynamics")