-
Notifications
You must be signed in to change notification settings - Fork 22
New regional Panantarctic example #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
francispoulin
wants to merge
121
commits into
main
Choose a base branch
from
fjp/acc_regional_model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
121 commits
Select commit
Hold shift + click to select a range
aeae520
creating new example for the ACC
705f078
Update acc_regional_simulation.jl
francispoulin bc31849
Update acc_regional_simulation.jl
francispoulin 67c3eb7
Merge branch 'main' into fjp/acc_regional_model
simone-silvestri 06ab5d4
Merge branch 'main' into fjp/acc_regional_model
simone-silvestri 7741ea7
updated script
a398d0c
add different masking
simone-silvestri e377edf
updating script to get further
ef9d130
fix node problem
5e95104
fix phinodes
francispoulin 9abbc32
add grid to varphinodes
francispoulin 55f667b
fix varphinode for real
3f9dd7d
a working version on a gpu
47ec55e
change time step to 10 minutes
a6989e8
cleaning up callbacks
8cc2719
Update examples/acc_regional_simulation.jl
francispoulin 04b24e9
Merge branch 'main' into fjp/acc_regional_model
simone-silvestri c341fdc
change to the restoring rate and the outputwriter schedule
simone-silvestri 7862bf2
Merge remote-tracking branch 'origin/main' into fjp/acc_regional_model
simone-silvestri 75d909f
update example
simone-silvestri 0cb27c5
Merge branch 'main' into fjp/acc_regional_model
simone-silvestri 4462fe0
run docs
simone-silvestri 2101f85
run docs
simone-silvestri a53438e
Update examples/acc_regional_simulation.jl
simone-silvestri 9f2a04d
add a dataset
simone-silvestri bb228d1
fix restoring
simone-silvestri 291f381
jld2 writer
simone-silvestri 7a30c07
remove the interior
simone-silvestri feb1e12
correctly compute restoring on GPU
simone-silvestri 06f479f
pass it
simone-silvestri 16957c2
Update acc_regional_simulation.jl
francispoulin a3ad47e
updating file names
francispoulin 88fa6a6
try with passing the grid
simone-silvestri ad5bdb6
changing the name of the files to save
b0c23ea
modifying some names and using the visualization from near global sim…
43693b9
changing a few names and using the visualization from near global (fo…
francispoulin 2275549
change coupled_simulation to simulation
francispoulin 3f546de
remove two unnecessary lines
francispoulin 2837862
fix alignments
francispoulin 0738b8b
restore backend definition
francispoulin 1fcd5ed
returning to model
francispoulin c343d9c
changing initial time step to 2*minutes
francispoulin 5cd349c
Merge remote-tracking branch 'origin/main' into fjp/acc_regional_model
simone-silvestri 727f16e
trying the simulation from T=S=0 and no atmospheric forcing
f6f8492
adding line so it can run
759c1ac
Update Project.toml
simone-silvestri 01e9f05
Update near_global_ocean_simulation.jl
simone-silvestri e48a2b5
Update one_degree_simulation.jl
simone-silvestri 0765874
changes
simone-silvestri 3ecb067
force with salinity field
simone-silvestri 98c8166
Merge branch 'ss/adapt-to-new-oceananigans' into fjp/acc_regional_model
simone-silvestri 5cdbc05
Merge branch 'fjp/acc_regional_model' of github.com:CliMA/ClimaOcean.…
simone-silvestri dd95781
adding the Manifest
simone-silvestri 019b331
add CUDA
simone-silvestri 5453bfb
change the zfaces
simone-silvestri 11bfa0e
add CUDA to the examples
simone-silvestri bd5eb40
using CUDA
simone-silvestri 0362716
Merge branch 'fjp/acc_regional_model' of github.com:CliMA/ClimaOcean.…
simone-silvestri c5cf412
revert cuda
simone-silvestri d6339c6
specify which record function to use
francispoulin a2ed433
fixing names of the files to load
francispoulin ca71f87
Update examples/acc_regional_simulation.jl
navidcy e35fd74
Delete Manifest.toml
navidcy b310603
bump Oceananigans compat
navidcy abfcaa0
Merge branch 'main' into fjp/acc_regional_model
navidcy e2b0529
Merge branch 'main' into fjp/acc_regional_model
navidcy ed80673
Update make.jl
navidcy 9152964
a working version with non constant TKE
f36e9f9
adding a regional acc example, with TKE
ed34861
removing testing folder
francispoulin 8068ff4
Update examples/acc_regional_simulation.jl
francispoulin 2ade2a1
Changing the name of the example
francispoulin 45d434f
Merge branch 'main' of github.com:CliMA/ClimaOcean.jl into fjp/acc_re…
francispoulin 7c7c979
Merge branch 'fjp/acc_regional_model' of github.com:CliMA/ClimaOcean.…
francispoulin 33e0d6e
Update docs/make.jl
francispoulin 73d599a
Update docs/make.jl
francispoulin 861f847
Update examples/panantarctic_regional_simulation.jl
francispoulin f69d6cf
Update examples/panantarctic_regional_simulation.jl
francispoulin 32360a0
Update panantarctic_regional_simulation.jl
francispoulin 885456a
uncomment the running of the simulation
francispoulin 35c52d8
Merge branch 'main' into fjp/acc_regional_model
simone-silvestri 32f4df8
run less time
navidcy cbbd8c7
Apply suggestions from code review
navidcy 721ae2a
try ECCO2
navidcy 80ac982
Update examples/panantarctic_regional_simulation.jl
navidcy 2cc41d4
Update panantarctic_regional_simulation.jl
navidcy 0e2675f
Apply suggestions from code review
navidcy c258839
fix phrasing
navidcy ac38912
literate
navidcy 717ad8d
bring back everyone in the show
navidcy f3d6252
there is sea ice
navidcy a4941a9
dreaded missing comma
navidcy 47742f4
Merge branch 'main' into fjp/acc_regional_model
francispoulin 0109356
Update make.jl
navidcy 122e418
Update panantarctic_regional_simulation.jl
navidcy 1241a5d
Update panantarctic_regional_simulation.jl
francispoulin aebd509
Rephrase for clarity
navidcy c945e63
Update make.jl
navidcy c079625
Update make.jl
navidcy ef77e75
updating resolution for Ny
francispoulin f7d8df5
Change interpolation passes from 7 to 5
navidcy af27468
Merge branch 'main' into fjp/acc_regional_model
navidcy c5ff257
Merge branch 'main' into fjp/acc_regional_model
simone-silvestri d5291d7
Update panantarctic_regional_simulation.jl
francispoulin 8cd6585
Merge branch 'main' into fjp/acc_regional_model
navidcy 0249abe
Merge branch 'main' into fjp/acc_regional_model
navidcy 65bbc6e
Update make.jl
navidcy 6169de0
Update make.jl
navidcy 6537a21
Update make.jl
francispoulin 48c69c0
Update make.jl
francispoulin 805445f
Update make.jl
francispoulin 4fbc9d9
Update runtests.jl
francispoulin 4cf99b6
Update runtests.jl
francispoulin 2ad1653
Update docs/make.jl
francispoulin 3b716db
Update docs/make.jl
francispoulin 3ff77e8
Update docs/make.jl
glwagner e430943
Update docs/make.jl
glwagner 0bb4542
Update panantarctic_regional_simulation.jl
francispoulin 3aa53ac
Update panantarctic_regional_simulation.jl
francispoulin 5a69b1c
Merge branch 'main' into fjp/acc_regional_model
navidcy 8e4c837
Merge branch 'main' into fjp/acc_regional_model
francispoulin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,300 @@ | ||
| # # Panantarctic regional ocean simulation | ||
| # | ||
| # This example sets up and runs a regional ocean simulation for a domain around Antarctica | ||
| # using the Oceananigans.jl and ClimaOcean.jl. The simulation covers latitudes from 80°S to 20°S, | ||
| # with a horizontal resolution of 1/4 degree and 60 vertical levels. | ||
| # | ||
| # The simulation's results are visualized with the CairoMakie.jl package. | ||
| # | ||
| # The example showcases how we can use DatasetRestoring functionality to restore to a given dataset | ||
| # and also how to add custom masks on forcings. | ||
| # | ||
| # ## Initial setup with package imports | ||
| # | ||
| # We begin by importing the necessary Julia packages for visualization (CairoMakie), | ||
| # ocean modeling (Oceananigans, ClimaOcean), handling dates and times (Dates), | ||
| # and CUDA for running on CUDA-enabled GPUs. | ||
| # These packages provide the foundational tools for setting up the simulation environment, | ||
| # including grid setup, physical processes modeling, and data visualization. | ||
|
|
||
| using ClimaOcean | ||
| using ClimaOcean.ECCO | ||
| using Oceananigans | ||
| using Oceananigans.Units | ||
| using CUDA | ||
| using CairoMakie | ||
| using Dates | ||
| using Printf | ||
|
|
||
| # ### Grid and Bathymetry | ||
| # | ||
| # We start by constructing a the grid around Antarctica. | ||
|
|
||
| arch = GPU() | ||
| Nx = 1440 | ||
| Ny = 240 | ||
| Nz = 40 | ||
|
|
||
| depth = 6000meters | ||
| z = ExponentialCoordinate(Nz, -depth, 0) | ||
|
|
||
| underlying_grid = LatitudeLongitudeGrid(arch; | ||
| size = (Nx, Ny, Nz), | ||
| halo = (7, 7, 7), | ||
| z = z, | ||
| latitude = (-80, -20), | ||
| longitude = (0, 360)) | ||
|
|
||
| # ### Bathymetry and immersed boundary | ||
| # | ||
| # We add the bottom height from ETOPO1 data on our grid via `regrid_bathymetry`: | ||
|
|
||
| bottom_height = regrid_bathymetry(underlying_grid; | ||
| minimum_depth = 10meters, | ||
| interpolation_passes = 5, | ||
| major_basins = 1) | ||
|
|
||
| grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom_height); active_cells_map=true) | ||
|
|
||
| # and visualise it: | ||
|
|
||
| fig, ax, hm = heatmap(grid.immersed_boundary.bottom_height, | ||
| colormap=:deep, colorrange=(-depth, 0)) | ||
| Colorbar(fig[0, 1], hm, label="Bottom height (m)", vertical=false) | ||
| save("panantarctic_bathymetry.png", fig) | ||
| nothing #hide | ||
|
|
||
| #  | ||
|
|
||
| # ### Restoring force | ||
| # | ||
| # We need to add restoring forces (both for tracers and for velocities) at the | ||
| # northern part of the domain to mimic the effect of the part of the ocean north | ||
| # of 20°S that we are not including in our domain. | ||
| # | ||
| # First we create some mask that have the following form: | ||
| # | ||
| # ```julia | ||
| # φS φN -20 | ||
| # -------------- | ------------------ | ------------ | | ||
| # no restoring 0 linear mask 1 mask = 1 1 | ||
| # ``` | ||
|
|
||
| const φN₁ = -23 | ||
| const φN₂ = -25 | ||
| const φS₁ = -78 | ||
| const φS₂ = -75 | ||
|
|
||
| @inline northern_mask(φ) = min(max((φ - φN₂) / (φN₁ - φN₂), zero(φ)), one(φ)) | ||
| @inline southern_mask(φ, z) = ifelse(z > -20, | ||
| min(max((φ - φS₂) / (φS₁ - φS₂), zero(φ)), one(φ)), | ||
| zero(φ)) | ||
|
|
||
| @inline function tracer_mask(λ, φ, z, t) | ||
| n = northern_mask(φ) | ||
| s = southern_mask(φ, z) | ||
| return max(s, n) | ||
| end | ||
|
|
||
| # Now we are ready to construct the forcing. We relax temperature, salinity to | ||
| # data from the ECCO4 dataset at a timescale of 5 days. For the velocities at the | ||
| # northern part of the domain, we apply a sponge layer (i.e., we relax them to zero). | ||
|
|
||
| start_date = DateTime(1993, 1, 1) | ||
| end_date = DateTime(1993, 4, 1) | ||
|
|
||
| dataset = ECCO4Monthly() | ||
| T_meta = Metadata(:temperature; start_date, end_date, dataset) | ||
| S_meta = Metadata(:salinity; start_date, end_date, dataset) | ||
|
|
||
| @inline function u_sponge(i, j, k, grid, clock, fields, p) | ||
| φ = Oceananigans.Grids.φnode(i, j, k, grid, Face(), Center(), Center()) | ||
| return - p.rate * fields.u[i, j, k] * northern_mask(φ) | ||
| end | ||
|
|
||
| @inline function v_sponge(i, j, k, grid, clock, fields, p) | ||
| φ = Oceananigans.Grids.φnode(i, j, k, grid, Center(), Face(), Center()) | ||
| return - p.rate * fields.v[i, j, k] * northern_mask(φ) | ||
| end | ||
|
|
||
| rate = 1/5days | ||
| forcing = (T = DatasetRestoring(T_meta, grid; rate, mask=tracer_mask), | ||
| S = DatasetRestoring(S_meta, grid; rate, mask=tracer_mask), | ||
| u = Forcing(u_sponge; discrete_form=true, parameters=(; rate)), | ||
| v = Forcing(v_sponge; discrete_form=true, parameters=(; rate))) | ||
|
|
||
| # ### Ocean model configuration | ||
| # | ||
| # We build our ocean model using `ocean_simulation`, | ||
|
|
||
| momentum_advection = WENOVectorInvariant() | ||
| tracer_advection = WENO(order=7) | ||
|
|
||
| ocean = ocean_simulation(grid; forcing, momentum_advection, tracer_advection) | ||
|
|
||
| # We initialize the ocean model with eddy-resolving ECCO2 temperature, salinity, | ||
| # and horizontal velocities. | ||
|
|
||
| dataset = ECCO2Monthly() | ||
| T_meta = Metadatum(:temperature; date=start_date, dataset) | ||
| S_meta = Metadatum(:salinity; date=start_date, dataset) | ||
| u_meta = Metadatum(:u_velocity; date=start_date, dataset) | ||
| v_meta = Metadatum(:v_velocity; date=start_date, dataset) | ||
|
|
||
| set!(ocean.model, T=T_meta, S=S_meta, u=u_meta, v=v_meta) | ||
|
|
||
| # ### Prescribed atmosphere and radiation | ||
| # | ||
| # Next we build a prescribed atmosphere state and radiation model, | ||
| # which will drive the ocean simulation. | ||
|
|
||
| backend = JRA55NetCDFBackend(41) | ||
| atmosphere = JRA55PrescribedAtmosphere(arch; backend) | ||
| radiation = Radiation(arch) | ||
|
|
||
| # ## The coupled simulation | ||
|
|
||
| # We put all the pieces together (ocean, atmosphere, and radiation) | ||
| # into a coupled model and a coupled simulation. | ||
| # We start with a small-ish time step of 2 minutes. | ||
| # We run the simulation for 10 days with this small-ish time step. | ||
|
|
||
| coupled_model = OceanSeaIceModel(ocean; atmosphere, radiation) | ||
| simulation = Simulation(coupled_model; Δt=2minutes, stop_time = 10days) | ||
|
|
||
| # A callback function to monitor the simulation's progress is always useful. | ||
|
|
||
| wall_time = [time_ns()] | ||
|
|
||
| function progress(sim) | ||
| ocean = sim.model.ocean | ||
| u, v, w = ocean.model.velocities | ||
| T = ocean.model.tracers.T | ||
|
|
||
| Tmax, Tmin = maximum(T), minimum(T) | ||
| umax = maximum(abs, u), maximum(abs, v), maximum(abs, w) | ||
| step_time = 1e-9 * (time_ns() - wall_time[1]) | ||
|
|
||
| @info @sprintf("Time: %s, Iteration %d, Δt %s, max(vel): (%.2e, %.2e, %.2e), max(T): %.2f, min(T): %.2f, wtime: %s \n", | ||
| prettytime(ocean.model.clock.time), | ||
| ocean.model.clock.iteration, | ||
| prettytime(ocean.Δt), | ||
| umax..., Tmax, Tmin, prettytime(step_time)) | ||
|
|
||
| wall_time[1] = time_ns() | ||
| end | ||
|
|
||
| simulation.callbacks[:progress] = Callback(progress, TimeInterval(5days)) | ||
|
|
||
| # ### Output | ||
| # | ||
| # We use output writers to save the simulation data at regular intervals. | ||
|
|
||
| ocean.output_writers[:surface] = JLD2Writer(ocean.model, merge(ocean.model.tracers, ocean.model.velocities); | ||
| schedule = TimeInterval(1days), | ||
| filename = "panantarctic_surface_fields", | ||
| indices = (:, :, grid.Nz), | ||
| overwrite_existing = true, | ||
| array_type = Array{Float32}) | ||
|
|
||
| # ### Spinning up the simulation | ||
| # | ||
| # We spin up the simulation with a small time step to ensure that the interpolated initial | ||
| # conditions adapt to the model numerics and parameterization without causing instability. | ||
| # A 10-day integration with a time step of 1 minute should be sufficient to dissipate spurious | ||
| # initialization shocks. | ||
|
|
||
| run!(simulation) | ||
| nothing #hide | ||
|
|
||
| # ### Running the simulation | ||
| # | ||
| # Now that the simulation has spun up, we can run increase the timestep and run for longer; | ||
| # here we choose 60 days. | ||
|
|
||
| simulation.stop_time = 60days | ||
| simulation.Δt = 10minutes | ||
| run!(simulation) | ||
| nothing #hide | ||
|
|
||
| # ## Visualizing the results | ||
| # | ||
| # The simulation has finished, let's visualize the results. | ||
| # In this section we pull up the saved data and create visualizations using the CairoMakie.jl package. | ||
| # In particular, we generate an animation of the evolution of surface fields: | ||
| # surface speed (s), surface temperature (T), and turbulent kinetic energy (e). | ||
|
|
||
| u = FieldTimeSeries("panantarctic_surface_fields.jld2", "u"; backend = OnDisk()) | ||
| v = FieldTimeSeries("panantarctic_surface_fields.jld2", "v"; backend = OnDisk()) | ||
| T = FieldTimeSeries("panantarctic_surface_fields.jld2", "T"; backend = OnDisk()) | ||
| e = FieldTimeSeries("panantarctic_surface_fields.jld2", "e"; backend = OnDisk()) | ||
|
|
||
| times = u.times | ||
| Nt = length(times) | ||
|
|
||
| n = Observable(Nt) | ||
|
|
||
| land = interior(T.grid.immersed_boundary.bottom_height) .>= 0 | ||
|
|
||
| Tn = @lift begin | ||
| Tn = interior(T[$n]) | ||
| Tn[land] .= NaN | ||
| view(Tn, :, :, 1) | ||
| end | ||
|
|
||
| en = @lift begin | ||
| en = interior(e[$n]) | ||
| en[land] .= NaN | ||
| view(en, :, :, 1) | ||
| end | ||
|
|
||
| un = Field{Face, Center, Nothing}(u.grid) | ||
| vn = Field{Center, Face, Nothing}(v.grid) | ||
|
|
||
| s = @at (Center, Center, Nothing) sqrt(un^2 + vn^2) | ||
| s = Field(s) | ||
|
|
||
| sn = @lift begin | ||
| parent(un) .= parent(u[$n]) | ||
| parent(vn) .= parent(v[$n]) | ||
| compute!(s) | ||
| sn = interior(s) | ||
| sn[land] .= NaN | ||
| view(sn, :, :, 1) | ||
| end | ||
|
|
||
| title = @lift string("Panantarctic regional ocean simulation after ", | ||
| prettytime(times[$n] - times[1])) | ||
|
|
||
| λ, φ, _ = nodes(T) | ||
|
|
||
| fig = Figure(size = (1000, 1500)) | ||
|
|
||
| axs = Axis(fig[1, 1], xlabel="Longitude (deg)", ylabel="Latitude (deg)") | ||
| axT = Axis(fig[2, 1], xlabel="Longitude (deg)", ylabel="Latitude (deg)") | ||
| axe = Axis(fig[3, 1], xlabel="Longitude (deg)", ylabel="Latitude (deg)") | ||
|
|
||
| hm = heatmap!(axs, λ, φ, sn, colorrange = (0, 0.5), colormap = :deep, nan_color=:lightgray) | ||
| Colorbar(fig[1, 2], hm, label = "Surface Speed (m s⁻¹)") | ||
|
|
||
| hm = heatmap!(axT, λ, φ, Tn, colorrange = (-1, 30), colormap = :magma, nan_color=:lightgray) | ||
| Colorbar(fig[2, 2], hm, label = "Surface Temperature (ᵒC)") | ||
|
|
||
| hm = heatmap!(axe, λ, φ, en, colorrange = (0, 1e-3), colormap = :solar, nan_color=:lightgray) | ||
| Colorbar(fig[3, 2], hm, label = "Turbulent Kinetic Energy (m² s⁻²)") | ||
|
|
||
| Label(fig[0, :], title) | ||
|
|
||
| save("acc_snapshot.png", fig) | ||
| nothing #hide | ||
|
|
||
| #  | ||
|
|
||
| # And now we make a movie: | ||
|
|
||
| CairoMakie.record(fig, "panantarctic_regional_surface.mp4", 1:Nt, framerate = 8) do nn | ||
| n[] = nn | ||
| end | ||
| nothing #hide | ||
|
|
||
| #  |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.