From cfbc800210287fd541d0240b09b1a78d210f7de2 Mon Sep 17 00:00:00 2001 From: "Gregory L. Wagner" Date: Wed, 12 Mar 2025 20:52:18 -0700 Subject: [PATCH 1/2] Update time_step_ocean_sea_ice_model.jl --- src/OceanSeaIceModels/time_step_ocean_sea_ice_model.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OceanSeaIceModels/time_step_ocean_sea_ice_model.jl b/src/OceanSeaIceModels/time_step_ocean_sea_ice_model.jl index bea8089b..4aef6155 100644 --- a/src/OceanSeaIceModels/time_step_ocean_sea_ice_model.jl +++ b/src/OceanSeaIceModels/time_step_ocean_sea_ice_model.jl @@ -10,7 +10,7 @@ using Oceananigans.Grids: φnode using Printf -function time_step!(coupled_model::OceanSeaIceModel, Δt; callbacks=[], compute_tendencies=true, kw...) +function time_step!(coupled_model::OceanSeaIceModel, Δt; callbacks=[], compute_tendencies=true) ocean = coupled_model.ocean sea_ice = coupled_model.sea_ice atmosphere = coupled_model.atmosphere @@ -37,7 +37,7 @@ function time_step!(coupled_model::OceanSeaIceModel, Δt; callbacks=[], compute_ # TODO after ice time-step: # - Adjust ocean heat flux if the ice completely melts? - time_step!(ocean.model, Δt; kw...) + time_step!(ocean, Δt) # Time step the atmosphere time_step!(atmosphere, Δt) From e404e9e2533a53136c70efad0c196e04510d35f0 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Wed, 12 Mar 2025 21:29:52 -0700 Subject: [PATCH 2/2] Implement a simple test for callbacks --- .buildkite/pipeline.yml | 4 +- src/OceanSimulations/ocean_simulation.jl | 2 + test/runtests.jl | 5 +- ...lations.jl => test_ocean_sea_ice_model.jl} | 30 ++++++++++-- ...est_ocean_sea_ice_model_parameter_space.jl | 49 ------------------- 5 files changed, 31 insertions(+), 59 deletions(-) rename test/{test_simulations.jl => test_ocean_sea_ice_model.jl} (71%) delete mode 100644 test/test_ocean_sea_ice_model_parameter_space.jl diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index dea3c20e..cf385f44 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -134,9 +134,9 @@ steps: slurm_gpus_per_task: 1 - label: "Run simulation tests" - key: "test_simulations" + key: "test_ocean_sea_ice_model" env: - TEST_GROUP: "simulations" + TEST_GROUP: "ocean_sea_ice_model" GPU_TEST: "true" commands: - "julia --project -e 'using Pkg; Pkg.test()'" diff --git a/src/OceanSimulations/ocean_simulation.jl b/src/OceanSimulations/ocean_simulation.jl index 3206d71f..eab999df 100644 --- a/src/OceanSimulations/ocean_simulation.jl +++ b/src/OceanSimulations/ocean_simulation.jl @@ -17,6 +17,8 @@ using Statistics: mean # Some defaults default_free_surface(grid) = SplitExplicitFreeSurface(grid; cfl=0.7) +estimate_maximum_Δt(grid::RectilinearGrid) = 30minutes # ? + function estimate_maximum_Δt(grid) arch = architecture(grid) Δx = mean(xspacings(grid)) diff --git a/test/runtests.jl b/test/runtests.jl index 21e98e04..dcd16299 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -55,9 +55,8 @@ if test_group == :bathymetry || test_group == :all include("test_bathymetry.jl") end -if test_group == :simulations || test_group == :all - CUDA.set_runtime_version!(v"12.2", local_toolkit = true) # Seems to help in finding the correct CUDA dataset - include("test_simulations.jl") +if test_group == :ocean_sea_ice_model || test_group == :all + include("test_ocean_sea_ice_model.jl") include("test_diagnostics.jl") end diff --git a/test/test_simulations.jl b/test/test_ocean_sea_ice_model.jl similarity index 71% rename from test/test_simulations.jl rename to test/test_ocean_sea_ice_model.jl index a892b427..3d2395e1 100644 --- a/test/test_simulations.jl +++ b/test/test_ocean_sea_ice_model.jl @@ -11,6 +11,27 @@ using ClimaSeaIce.SeaIceThermodynamics: melting_temperature for arch in test_architectures + λ★, φ★ = 35.1, 50.1 + + grid = RectilinearGrid(arch, size = 200, x = λ★, y = φ★, + z = (-400, 0), topology = (Flat, Flat, Bounded)) + + ocean = ocean_simulation(grid) + data = Int[] + pushdata(sim) = push!(data, iteration(sim)) + add_callback!(ocean, pushdata) + backend = JRA55NetCDFBackend(4) + atmosphere = JRA55PrescribedAtmosphere(arch; backend) + radiation = Radiation(arch) + coupled_model = OceanSeaIceModel(ocean; atmosphere, radiation) + Δt = 60 + for n = 1:3 + time_step!(coupled_model, Δt) + end + @test data == [0, 1, 2, 3] + + # TODO: do the same for a SeaIceSimulation, and eventually prognostic Atmos + ##### ##### Ocean and prescribed atmosphere ##### @@ -20,11 +41,10 @@ using ClimaSeaIce.SeaIceThermodynamics: melting_temperature halo = (7, 7, 7), z = (-6000, 0)) - bottom_height = retrieve_bathymetry(grid; - minimum_depth = 10, - dir = "./", - interpolation_passes = 20, - major_basins = 1) + bottom_height = regrid_bathymetry(grid; + minimum_depth = 10, + interpolation_passes = 20, + major_basins = 1) grid = ImmersedBoundaryGrid(grid, GridFittedBottom(bottom_height); active_cells_map=true) diff --git a/test/test_ocean_sea_ice_model_parameter_space.jl b/test/test_ocean_sea_ice_model_parameter_space.jl deleted file mode 100644 index 2655dedd..00000000 --- a/test/test_ocean_sea_ice_model_parameter_space.jl +++ /dev/null @@ -1,49 +0,0 @@ -using Oceananigans -using ClimaOcean -using Oceananigans.OrthogonalSphericalShellGrids - -start_time = time_ns() -arch = GPU() -grid = TripolarGrid(arch; - size = (50, 50, 10), - halo = (7, 7, 7), - z = (-6000, 0), - first_pole_longitude = 75, - north_poles_latitude = 55) - -bottom_height = retrieve_bathymetry(grid; - minimum_depth = 10, - dir = "./", - interpolation_passes = 20, - connected_regions_allowed = 0) - -grid = ImmersedBoundaryGrid(grid, GridFittedBottom(bottom_height); active_cells_map = true) - -elapsed = 1e-9 * (time_ns() - start_time) -@info "Grid / bathymetry construction time: " * prettytime(elapsed) - -start_time = time_ns() -free_surface = SplitExplicitFreeSurface(grid; substeps = 20) -ocean = ocean_simulation(grid; free_surface) -model = ocean.model -@info "Ocean simulation construction time: " * prettytime(elapsed) - -start_time = time_ns() -backend = JRA55NetCDFBackend(4) -atmosphere = JRA55PrescribedAtmosphere(arch; backend) -radiation = Radiation(arch) - -elapsed = 1e-9 * (time_ns() - start_time) -@info "Atmosphere construction time: " * prettytime(elapsed) - -# Fluxes are computed when the model is constructed, so we just test that this works. -start_time = time_ns() -coupled_model = OceanSeaIceModel(ocean; atmosphere, radiation) - -elapsed = 1e-9 * (time_ns() - start_time) -@info "Coupled model construction time: " * prettytime(elapsed) - -start_time = time_ns() -time_step!(coupled_model, 1) -elapsed = 1e-9 * (time_ns() - start_time) -@info "One time step time: " * prettytime(elapsed)