From d225fba0619a278c7a92c48a757e40244f538b20 Mon Sep 17 00:00:00 2001 From: nefrathenrici Date: Fri, 19 Jan 2024 10:12:33 -0800 Subject: [PATCH] Clean up tests, remove hardcoded param constructor --- test/runtests.jl | 65 ++++++++++--------------------------------- test/test_profiles.jl | 2 +- 2 files changed, 16 insertions(+), 51 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index bf333e8d..a523a3e3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,29 +1,28 @@ +using Test + import Random Random.seed!(1234) -using Test -import Thermodynamics +import KernelAbstractions: CPU + +import Thermodynamics as TD using SurfaceFluxes import SurfaceFluxes as SF import SurfaceFluxes.UniversalFunctions as UF import SurfaceFluxes.Parameters as SFP import SurfaceFluxes.UniversalFunctions.BusingerParams -import KernelAbstractions: CPU - import CLIMAParameters as CP -FloatType = Float32 -param_set = SFP.SurfaceFluxesParameters(FloatType, BusingerParams) -thermo_params = param_set.thermo_params -uft = UF.BusingerType() - -const TD = Thermodynamics device(::T) where {T <: Array} = CPU() ArrayType = Array @info "CPU Tests" @info ArrayType +FloatType = Float32 @testset "SurfaceFluxes - Recovery Profiles" begin + param_set = SFP.SurfaceFluxesParameters(FloatType, BusingerParams) + thermo_params = param_set.thermo_params + uft = UF.universal_func_type(typeof(param_set.ufp)) ρ_sfc = FloatType(1.15) ρ_in = FloatType(1.13) qt_sfc = FloatType(0.01) @@ -86,51 +85,16 @@ ArrayType = Array end end -# Parameter set generated in ClimaAtmos GCM run -const sf_params = SurfaceFluxes.Parameters.SurfaceFluxesParameters{ - FloatType, - SurfaceFluxes.UniversalFunctions.BusingerParams{FloatType}, - Thermodynamics.Parameters.ThermodynamicsParameters{FloatType}, -}( - 0.4f0, - SurfaceFluxes.UniversalFunctions.BusingerParams{FloatType}(0.74f0, 4.7f0, 4.7f0, 2.5f0, 4.45f0), - Thermodynamics.Parameters.ThermodynamicsParameters{FloatType}( - 273.16f0, - 100000.0f0, - 100000.0f0, - 1859.0f0, - 4181.0f0, - 2100.0f0, - 2.5008f6, - 2.8344f6, - 611.657f0, - 273.16f0, - 273.15f0, - 150.0f0, - 1000.0f0, - 298.15f0, - 6864.8f0, - 10513.6f0, - 0.2857143f0, - 8.31446f0, - 0.02897f0, - 0.01801528f0, - 290.0f0, - 220.0f0, - 9.80616f0, - 233.0f0, - 1.0f0, - ), -) @testset "Near-zero Obukhov length (Floating Point Consistency)" begin FloatTypes = (Float32, Float64) z_levels = [1, 5, 10, 20, 40, 80, 160, 320, 640] # [m] level of first interior grid point for (i, FloatType) in enumerate(FloatTypes) + sf_params = SFP.SurfaceFluxesParameters(FloatType, BusingerParams) for (jj, z_int) in enumerate(z_levels) - ts_int_test = Thermodynamics.PhaseEquil{FloatType}(1.1751807f0, 97086.64f0, 10541.609f0, 0.0f0, 287.85202f0) + ts_int_test = TD.PhaseEquil{FloatType}(1.1751807f0, 97086.64f0, 10541.609f0, 0.0f0, 287.85202f0) ts_sfc_test = - Thermodynamics.PhaseEquil{FloatType}(1.2176297f0, 102852.51f0, 45087.812f0, 0.013232904f0, 291.96683f0) + TD.PhaseEquil{FloatType}(1.2176297f0, 102852.51f0, 45087.812f0, 0.013232904f0, 291.96683f0) sc = SF.ValuesOnly( SF.StateValues(FloatType(z_int), (FloatType(0), FloatType(0)), ts_int_test), SF.StateValues(FloatType(0), (FloatType(0), FloatType(0)), ts_sfc_test), @@ -155,14 +119,15 @@ end z0_b = [1e-5, 1e-4, 1e-3] # roughness length [heat] sol_mat = Array{Any, 4}(undef, 2, length(z_levels), length(z0_m), length(z0_b)) for (ii, FloatType) in enumerate(FloatTypes) + sf_params = SFP.SurfaceFluxesParameters(FloatType, BusingerParams) for (jj, z_int) in enumerate(z_levels) for (kk, z0m) in enumerate(z0_m) for (ll, z0b) in enumerate(z0_b) # Test case with identical interior and surface states ts_int_test = - Thermodynamics.PhaseEquil{FloatType}(1.1751807f0, 97086.64f0, 10541.609f0, 0.0f0, 287.85202f0) + TD.PhaseEquil{FloatType}(1.1751807f0, 97086.64f0, 10541.609f0, 0.0f0, 287.85202f0) ts_sfc_test = - Thermodynamics.PhaseEquil{FloatType}(1.1751807f0, 97086.64f0, 10541.609f0, 0.0f0, 287.85202f0) + TD.PhaseEquil{FloatType}(1.1751807f0, 97086.64f0, 10541.609f0, 0.0f0, 287.85202f0) sc = SF.ValuesOnly( SF.StateValues(FloatType(z_int), (FloatType(0), FloatType(0)), ts_int_test), SF.StateValues(FloatType(0), (FloatType(0), FloatType(0)), ts_sfc_test), diff --git a/test/test_profiles.jl b/test/test_profiles.jl index 77d64df8..38a5d3f7 100644 --- a/test/test_profiles.jl +++ b/test/test_profiles.jl @@ -8,7 +8,7 @@ const AW = ArtifactWrappers const TD = Thermodynamics FT = Float32 -param_set = SFP.SurfaceFluxesParameters(FloatType, BusingerParams) +param_set = SFP.SurfaceFluxesParameters(FT, BusingerParams) thermo_params = param_set.thermo_params uft = UF.BusingerType()