Skip to content

Commit

Permalink
Clean up tests, remove hardcoded param constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Jan 19, 2024
1 parent 8fd165b commit d225fba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 51 deletions.
65 changes: 15 additions & 50 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion test/test_profiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit d225fba

Please sign in to comment.