@@ -10,6 +10,10 @@ using ClimaOcean.OceanSeaIceModels.CrossRealmFluxes:
10
10
using Thermodynamics
11
11
using CUDA
12
12
using KernelAbstractions: @kernel , @index
13
+ using Oceananigans. TimeSteppers: update_state!
14
+ using Oceananigans. Units: hours, days
15
+
16
+ using Statistics: mean, std
13
17
14
18
import ClimaOcean. OceanSeaIceModels. CrossRealmFluxes: water_saturation_specific_humidity
15
19
@@ -196,4 +200,76 @@ _fractional_indices(at_node, grid, ::Nothing, ::Nothing, ::Nothing) = (nothing,
196
200
end
197
201
end
198
202
203
+ @testset " Fluxes regression" begin
204
+ for arch in test_architectures
205
+ @info " Testing fluxes regression..."
206
+
207
+ grid = LatitudeLongitudeGrid (arch;
208
+ size = (20 , 20 , 20 ),
209
+ latitude = (- 60 , 60 ),
210
+ longitude = (0 , 360 ),
211
+ z = (- 5000 , 0 ))
212
+
213
+ # Speed up compilation by removing all the unnecessary stuff
214
+ momentum_advection = nothing
215
+ tracer_advection = nothing
216
+ tracers = (:T , :S )
217
+ buoyancy = nothing
218
+ closure = nothing
219
+ coriolis = nothing
220
+
221
+ ocean = ocean_simulation (grid; momentum_advection, tracer_advection, closure, tracers, coriolis)
222
+
223
+ T_metadata = ECCOMetadata (:temperature )
224
+ S_metadata = ECCOMetadata (:salinity )
225
+
226
+ set! (ocean. model; T= T_metadata, S= S_metadata)
227
+
228
+ atmosphere = JRA55_prescribed_atmosphere (1 : 10 ; grid, architecture = arch, backend = InMemory ())
229
+ radiation = Radiation (ocean_albedo= 0.1 , ocean_emissivity= 1.0 )
230
+ sea_ice = nothing
231
+
232
+ coupled_model = OceanSeaIceModel (ocean, sea_ice; atmosphere, radiation)
233
+
234
+ times = 0 : 1 hours: 1 days
235
+ Ntimes = length (times)
236
+
237
+ # average the fluxes over one day
238
+ Jᵀ = interior (ocean. model. tracers. T. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
239
+ Jˢ = interior (ocean. model. tracers. S. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
240
+ τˣ = interior (ocean. model. velocities. u. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
241
+ τʸ = interior (ocean. model. velocities. v. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
242
+
243
+ for time in times[2 : end ]
244
+ coupled_model. clock. time = time
245
+ update_state! (coupled_model)
246
+ Jᵀ .+ = interior (ocean. model. tracers. T. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
247
+ Jˢ .+ = interior (ocean. model. tracers. S. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
248
+ τˣ .+ = interior (ocean. model. velocities. u. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
249
+ τʸ .+ = interior (ocean. model. velocities. v. boundary_conditions. top. condition, :, :, 1 ) ./ Ntimes
250
+ end
251
+
252
+ Jᵀ_mean = mean (Jᵀ)
253
+ Jˢ_mean = mean (Jˢ)
254
+ τˣ_mean = mean (τˣ)
255
+ τʸ_mean = mean (τʸ)
256
+
257
+ Jᵀ_std = std (Jᵀ)
258
+ Jˢ_std = std (Jˢ)
259
+ τˣ_std = std (τˣ)
260
+ τʸ_std = std (τʸ)
261
+
262
+ # Regression test
263
+ @test Jᵀ_mean ≈ - 3.526464713488678e-5
264
+ @test Jˢ_mean ≈ 1.1470078542716042e-6
265
+ @test τˣ_mean ≈ - 1.0881334225579832e-5
266
+ @test τʸ_mean ≈ 5.653281786086694e-6
267
+
268
+ @test Jᵀ_std ≈ 7.477575901188957e-5
269
+ @test Jˢ_std ≈ 3.7416720607945508e-6
270
+ @test τˣ_std ≈ 0.00011349625113971719
271
+ @test τʸ_std ≈ 7.627885224680635e-5
272
+ end
273
+ end
274
+
199
275
0 commit comments