Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
262 commits
Select commit Hold shift + click to select a range
a130e73
correct dates
simone-silvestri Dec 5, 2024
c90b7f9
Merge remote-tracking branch 'origin/main' into ss/metadata-for-every…
simone-silvestri Dec 23, 2024
08b377f
syntax
simone-silvestri Dec 23, 2024
2eb5556
Merge remote-tracking branch 'origin/main' into ss/metadata-for-every…
simone-silvestri Feb 12, 2025
ba4bce0
more updates
simone-silvestri Feb 12, 2025
68dfdb0
all this should work?
simone-silvestri Feb 12, 2025
f212e88
clear comments
simone-silvestri Feb 12, 2025
1a68d4e
vestigial code
simone-silvestri Feb 12, 2025
c318e54
works
simone-silvestri Feb 12, 2025
79b5935
veeery much simplified
simone-silvestri Feb 12, 2025
91e1169
this part is already done
simone-silvestri Feb 12, 2025
b6fb198
back to working
simone-silvestri Feb 12, 2025
e81bdfb
works
simone-silvestri Feb 12, 2025
afbd1cc
improve show method
simone-silvestri Feb 12, 2025
8599314
change names
simone-silvestri Feb 12, 2025
bb24633
go ahead
simone-silvestri Feb 12, 2025
4f05dbb
fix it
simone-silvestri Feb 12, 2025
fe6dc72
this should work
simone-silvestri Feb 12, 2025
787ebc9
add a new constructor
simone-silvestri Mar 11, 2025
7c519a1
set with ECCOMetadatum
simone-silvestri Mar 11, 2025
78a53cd
some changes
simone-silvestri Mar 11, 2025
1e71d67
improvement to UI
simone-silvestri Mar 11, 2025
4f7fdb2
change examples
simone-silvestri Mar 11, 2025
58662d2
we don't need this
simone-silvestri Mar 11, 2025
22c8d08
chnages
simone-silvestri Mar 11, 2025
79f37eb
export ui functions
simone-silvestri Mar 11, 2025
a98669f
last date
simone-silvestri Mar 11, 2025
5405ef3
vestigial dates
simone-silvestri Mar 11, 2025
b2ff520
change docstrings
simone-silvestri Mar 11, 2025
992b4d7
better like this
simone-silvestri Mar 11, 2025
e65b0ea
add native date range
simone-silvestri Mar 12, 2025
e7a0039
Merge branch 'main' into ss/distinguish-constructor
simone-silvestri Mar 13, 2025
40a9f24
change the url
simone-silvestri Mar 13, 2025
58d5c11
fix tests
simone-silvestri Mar 13, 2025
4fc2394
fixing the tests
simone-silvestri Mar 13, 2025
385a44a
fix tests
simone-silvestri Mar 13, 2025
54e5838
it's six dates not 5
simone-silvestri Mar 14, 2025
925981d
Merge branch 'main' into ss/distinguish-constructor
simone-silvestri Mar 14, 2025
62c2f46
Merge branch 'ss/distinguish-constructor' into ss/multi-year-JRA55
simone-silvestri Mar 14, 2025
fb35d78
this works
simone-silvestri Mar 15, 2025
65ca9ba
this works
simone-silvestri Mar 15, 2025
18504c5
this should work
simone-silvestri Mar 15, 2025
f35345c
done
simone-silvestri Mar 15, 2025
97c91fd
Merge branch 'main' into ss/distinguish-constructor
navidcy Mar 16, 2025
182cbfb
use directory over folder; fix some docstrings
navidcy Mar 16, 2025
a23c423
Merge branch 'main' into ss/distinguish-constructor
simone-silvestri Mar 17, 2025
f42a187
add an ECCOMetadatum
simone-silvestri Mar 17, 2025
0a6dd9f
Merge branch 'ss/distinguish-constructor' of github.com:CliMA/ClimaOc…
simone-silvestri Mar 17, 2025
790b5e6
spacing
simone-silvestri Mar 17, 2025
1649353
add a top level constant
simone-silvestri Mar 17, 2025
739bc46
correct directory
simone-silvestri Mar 17, 2025
6ef9d7c
add a default dowbload
simone-silvestri Mar 17, 2025
58c38c7
Merge branch 'ss/distinguish-constructor' into ss/multi-year-JRA55
simone-silvestri Mar 17, 2025
4e53f82
almost there
simone-silvestri Mar 17, 2025
29d15c8
Merge branch 'main' into ss/multi-year-JRA55
simone-silvestri Mar 21, 2025
418fa99
revert test ecco
simone-silvestri Mar 21, 2025
f8cd74b
Merge branch 'ss/multi-year-JRA55' of github.com:CliMA/ClimaOcean.jl …
simone-silvestri Mar 21, 2025
4761081
Merge branch 'main' into ss/multi-year-JRA55
simone-silvestri Mar 21, 2025
93c6b6f
bugfix
simone-silvestri Mar 21, 2025
0293afd
Merge branch 'ss/multi-year-JRA55' of github.com:CliMA/ClimaOcean.jl …
simone-silvestri Mar 21, 2025
cffb7e1
Merge remote-tracking branch 'origin/main' into ss/multi-year-JRA55
simone-silvestri Mar 28, 2025
1febc0e
Merge remote-tracking branch 'origin/main' into ss/multi-year-JRA55
simone-silvestri Mar 31, 2025
ce7cbd3
start changes
simone-silvestri Mar 31, 2025
fbfe5ce
this should work
simone-silvestri Mar 31, 2025
46940e7
bugfix
simone-silvestri Mar 31, 2025
473dbd7
some bugfixing
simone-silvestri Mar 31, 2025
3ccc9f7
this works
simone-silvestri Mar 31, 2025
a35bf04
this works!
simone-silvestri Mar 31, 2025
68b3ff3
add regularization
simone-silvestri Mar 31, 2025
5f53219
bugfix
simone-silvestri Mar 31, 2025
9209bbf
add sea-ice ocean stress
simone-silvestri Apr 1, 2025
62b4629
Merge branch 'main' into ss/multi-year-JRA55
simone-silvestri Apr 1, 2025
4d963ea
fix tests
simone-silvestri Apr 1, 2025
52c91d9
Merge branch 'ss/multi-year-JRA55' of github.com:CliMA/ClimaOcean.jl …
simone-silvestri Apr 1, 2025
1ee41af
bugfix
simone-silvestri Apr 1, 2025
1d58772
Update JRA55_field_time_series.jl
simone-silvestri Apr 1, 2025
0c020d0
Update JRA55_field_time_series.jl
simone-silvestri Apr 1, 2025
bafe3c7
simplify
simone-silvestri Apr 1, 2025
350b657
add the inmemory stuff
simone-silvestri Apr 1, 2025
4a49b40
start with this
simone-silvestri Apr 3, 2025
fea1854
default to inmemory
simone-silvestri Apr 3, 2025
4441567
Merge remote-tracking branch 'origin/ss/multi-year-JRA55' into ss/omi…
simone-silvestri Apr 3, 2025
7c4aa61
go!
simone-silvestri Apr 3, 2025
24f7d93
add a failsafe + a test
simone-silvestri Apr 3, 2025
d231995
some cleanup
simone-silvestri Apr 3, 2025
ca1980c
better to write last
simone-silvestri Apr 3, 2025
f448eeb
Merge remote-tracking branch 'origin/ss/multi-year-JRA55' into ss/omi…
simone-silvestri Apr 3, 2025
fed209b
Merge branch 'main' into ss/sea-ice-momentum-stress
simone-silvestri Apr 3, 2025
aeedd2f
last index
simone-silvestri Apr 3, 2025
f954c69
Merge branch 'ss/sea-ice-momentum-stress' of github.com:CliMA/ClimaOc…
simone-silvestri Apr 3, 2025
ddee7f0
add this
simone-silvestri Apr 3, 2025
daeb12f
add a clock
simone-silvestri Apr 3, 2025
629d582
add the arctic
simone-silvestri Apr 3, 2025
54165a0
Merge branch 'ss/sea-ice-momentum-stress' into ss/omip-prototype
simone-silvestri Apr 3, 2025
35fe01d
try it out
simone-silvestri Apr 3, 2025
5548a99
correct dates
simone-silvestri Apr 3, 2025
dfb8590
Update experiments/omip_prototype/quarter_degree_omip.jl
simone-silvestri Apr 4, 2025
a049dc1
Update experiments/omip_prototype/quarter_degree_omip.jl
simone-silvestri Apr 4, 2025
d1e6faf
add stuff
simone-silvestri Apr 4, 2025
7186256
Merge branch 'main' into ss/omip-prototype
simone-silvestri Apr 7, 2025
a6d758d
going sixth degree
simone-silvestri Apr 10, 2025
0b8624e
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Apr 10, 2025
f18a772
some changes
simone-silvestri Apr 10, 2025
6679bbd
synchronize the clocks for the moment
simone-silvestri Apr 10, 2025
50a7226
Merge branch 'main' into ss/omip-prototype
simone-silvestri Apr 10, 2025
7975dd4
Update test_jra55.jl
simone-silvestri Apr 10, 2025
77e440b
bugfix
simone-silvestri Apr 10, 2025
5e3c729
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Apr 10, 2025
b05fb83
improve it quickly for now
simone-silvestri Apr 10, 2025
501b3fa
continue
simone-silvestri Apr 10, 2025
f258e29
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Apr 10, 2025
5751899
another try...
simone-silvestri Apr 14, 2025
af67adc
bugfix for the salt flux
simone-silvestri Apr 24, 2025
d008026
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri Apr 30, 2025
83f97e9
try it out
simone-silvestri Apr 30, 2025
03e7f19
correction
simone-silvestri Apr 30, 2025
1e02dd9
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri May 14, 2025
1eedc44
correct
simone-silvestri May 14, 2025
202212c
update
simone-silvestri May 22, 2025
efa566c
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri May 22, 2025
0c8d8b1
go for it
simone-silvestri May 22, 2025
0f04d0f
Update src/SeaIceSimulations.jl
simone-silvestri May 22, 2025
e28b9a4
Update SeaIceSimulations.jl
simone-silvestri May 22, 2025
0e1d4ca
Merge branch 'ss/default-sea-ice' into ss/omip-prototype
simone-silvestri May 22, 2025
2eeed4c
some.. salinity
simone-silvestri May 22, 2025
b27ac12
Merge branch 'main' into ss/omip-prototype
simone-silvestri May 29, 2025
4d09283
Merge branch 'main' into ss/omip-prototype
simone-silvestri Jun 5, 2025
1507936
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri Jun 18, 2025
702fe64
update sea ice simulation
simone-silvestri Jun 18, 2025
9664584
try like this for the moment and let it go
simone-silvestri Jun 18, 2025
8392922
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri Jul 14, 2025
d28b611
added project
simone-silvestri Jul 14, 2025
4b763ee
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Jul 14, 2025
c306b0f
retry like this
simone-silvestri Jul 14, 2025
83331f8
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Jul 14, 2025
4857647
hmmm this was explicit
simone-silvestri Jul 14, 2025
668bc53
use a fixed dt
simone-silvestri Jul 14, 2025
dcce9e2
update to new syntax
simone-silvestri Jul 14, 2025
d5288c1
go like this
simone-silvestri Jul 14, 2025
1322148
add a one-degree to test it out
simone-silvestri Jul 14, 2025
2490da2
Update one_degree_simulation.jl
simone-silvestri Jul 15, 2025
c411c71
Update one_degree_simulation.jl
simone-silvestri Jul 15, 2025
f762205
try without implicit solver
simone-silvestri Jul 17, 2025
759c1ac
Update Project.toml
simone-silvestri Jul 17, 2025
01e9f05
Update near_global_ocean_simulation.jl
simone-silvestri Jul 17, 2025
e48a2b5
Update one_degree_simulation.jl
simone-silvestri Jul 17, 2025
0765874
changes
simone-silvestri Jul 17, 2025
808e6c9
try it in both
simone-silvestri Jul 17, 2025
88bd4e8
Merge branch 'ss/adapt-to-new-oceananigans' into ss/zstar
simone-silvestri Jul 17, 2025
7cacb1d
adding the correct zstar branch
simone-silvestri Jul 17, 2025
7cb8d6b
added CUDA
simone-silvestri Jul 17, 2025
469883a
Update pipeline.yml
simone-silvestri Jul 17, 2025
86d0bce
revert CUDA
simone-silvestri Jul 17, 2025
509d6b4
enforce using a specific branch
navidcy Jul 17, 2025
308c9e3
Delete Manifest.toml
navidcy Jul 17, 2025
06d895c
Update Project.toml
navidcy Jul 17, 2025
6397010
enforce using Oceananigans#ss/fix-zstar-bc
navidcy Jul 17, 2025
ea59ebb
drop geebrish
navidcy Jul 17, 2025
352a3ef
enforce using Oceananigans#ss/fix-zstar-bc
navidcy Jul 17, 2025
2beac0e
use julia v1.10.10
navidcy Jul 17, 2025
ea86989
precompile again
navidcy Jul 17, 2025
89af369
use julia v1.10.10
navidcy Jul 17, 2025
9e2482b
first oceananigans; then develop
navidcy Jul 17, 2025
9affa64
add CUDA
navidcy Jul 17, 2025
7717533
using CUDA + record from Makie not CUDA
navidcy Jul 17, 2025
6e0be09
Update one_degree_simulation.jl
simone-silvestri Jul 18, 2025
4488c2e
some changes
simone-silvestri Jul 18, 2025
26fde07
Merge branch 'ss/zstar' of github.com:CliMA/ClimaOcean.jl into ss/zstar
simone-silvestri Jul 18, 2025
a436bed
increase a bit
simone-silvestri Jul 18, 2025
5746652
add more stuff
simone-silvestri Jul 18, 2025
5127f05
improvements
simone-silvestri Jul 18, 2025
1037980
improve
simone-silvestri Jul 18, 2025
71c82f5
add an equatorial single column
simone-silvestri Jul 21, 2025
bc33d07
possibly remove a bug?
simone-silvestri Jul 21, 2025
ed0d210
Update atmosphere_sea_ice_fluxes.jl
simone-silvestri Jul 21, 2025
5b5b747
Update atmosphere_sea_ice_fluxes.jl
simone-silvestri Jul 21, 2025
28d3e4e
adding the correct Manifest
simone-silvestri Jul 21, 2025
00a2933
Merge branch 'ss/zstar' of github.com:CliMA/ClimaOcean.jl into ss/zstar
simone-silvestri Jul 21, 2025
d7ef440
update
simone-silvestri Jul 21, 2025
b0d1fd3
Merge branch 'main' into ss/zstar
navidcy Jul 22, 2025
860ff09
Merge branch 'main' into ss/zstar
simone-silvestri Jul 22, 2025
5637600
Merge branch 'ss/zstar' of github.com:CliMA/ClimaOcean.jl into ss/zstar
simone-silvestri Jul 22, 2025
b3ab48b
remove equatorial single column
simone-silvestri Jul 22, 2025
d1c7450
remove manifest
simone-silvestri Jul 22, 2025
a1ede1f
revert
simone-silvestri Jul 22, 2025
4015bf4
token
simone-silvestri Jul 22, 2025
970ffeb
Revert "token"
simone-silvestri Jul 22, 2025
4b4f64e
Merge remote-tracking branch 'origin/ss/zstar' into ss/omip-prototype
simone-silvestri Jul 22, 2025
e6ff0d4
changed JRA55
simone-silvestri Jul 22, 2025
ef45d0c
added Project
simone-silvestri Jul 22, 2025
d96c32b
merged
simone-silvestri Jul 22, 2025
ea3ee12
bugfix
simone-silvestri Jul 22, 2025
9165bd2
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Jul 22, 2025
add5526
this should fix it
simone-silvestri Jul 22, 2025
35e2df6
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri Jul 25, 2025
92fda28
change sea ice
simone-silvestri Jul 28, 2025
ec70ca0
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri Jul 29, 2025
469bcb1
consolidate sea ice temperature
simone-silvestri Jul 30, 2025
736ac4c
adding the manifest
simone-silvestri Jul 30, 2025
6db860a
adding Manifest
simone-silvestri Aug 1, 2025
5e0997c
comment out for now
simone-silvestri Aug 1, 2025
049dacd
go for it
simone-silvestri Aug 8, 2025
cf22586
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Aug 8, 2025
17a2250
improve
simone-silvestri Aug 8, 2025
d024542
Merge remote-tracking branch 'origin/main' into ss/omip-prototype
simone-silvestri Aug 8, 2025
7d6ce58
improving the performance
simone-silvestri Aug 18, 2025
5e66a54
speed up
simone-silvestri Aug 18, 2025
9063e3e
recorrect Oceananigans
simone-silvestri Aug 18, 2025
4fb3526
Merge branch 'main' into ss/omip-prototype
simone-silvestri Aug 18, 2025
e7845a5
new Manifest
simone-silvestri Aug 18, 2025
fca5484
do not add Oceananigans
simone-silvestri Aug 18, 2025
09d22a3
Update make.jl
simone-silvestri Aug 18, 2025
3885668
one-degree-ompi for calibration
simone-silvestri Aug 20, 2025
8bbc3b8
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Aug 20, 2025
988ec77
update one degree
simone-silvestri Aug 20, 2025
3419022
use the correct value
simone-silvestri Aug 20, 2025
b1430e2
remove this for the moment
simone-silvestri Aug 20, 2025
abced34
Merge branch 'ss/omip-prototype' of github.com:CliMA/ClimaOcean.jl in…
simone-silvestri Aug 20, 2025
78de681
start with adapting
simone-silvestri Aug 20, 2025
3772b2c
fill it in
simone-silvestri Aug 21, 2025
b5befcd
remove manifest
simone-silvestri Aug 21, 2025
1a40428
remove vestigial code
simone-silvestri Aug 21, 2025
0876b41
add a simulation
simone-silvestri Aug 21, 2025
dc79dc0
add an OceananigansSimulation
simone-silvestri Aug 21, 2025
adb8393
ok this works
simone-silvestri Aug 21, 2025
ff57090
add a forced simulation
simone-silvestri Aug 21, 2025
2460b14
update
simone-silvestri Aug 21, 2025
b74450f
coupled
simone-silvestri Aug 21, 2025
7792990
some corrections
simone-silvestri Aug 21, 2025
bf23df7
back to previous stuff
simone-silvestri Aug 21, 2025
5b03a33
add veros
simone-silvestri Aug 21, 2025
5843397
add the veros experiment
simone-silvestri Aug 21, 2025
cc6ca11
dt mom not dt tracer
simone-silvestri Aug 21, 2025
267d985
Apply suggestion from @glwagner
simone-silvestri Aug 22, 2025
8602684
Apply suggestion from @glwagner
simone-silvestri Aug 22, 2025
d45906b
Update assemble_net_fluxes.jl
simone-silvestri Aug 22, 2025
29c70ca
Rename fill_up_net_fluxes! to fill_net_fluxes!
simone-silvestri Aug 22, 2025
c7ee9ad
Update ext/ClimaOceanPythonCallExt/ClimaOceanPythonCallExt.jl
simone-silvestri Aug 22, 2025
c7dbcb0
overload the set! function
simone-silvestri Aug 22, 2025
ac8d821
bugfix
simone-silvestri Aug 22, 2025
2d0c16b
bugfix
simone-silvestri Aug 22, 2025
2debe0e
bugfix
simone-silvestri Aug 22, 2025
b3c6c46
fixed it
simone-silvestri Aug 26, 2025
8cfb21d
let's go
simone-silvestri Aug 26, 2025
88e937c
add visualization
simone-silvestri Aug 26, 2025
507e81c
Merge branch 'main' into ss/adapt-veros
simone-silvestri Aug 27, 2025
3d99939
Merge branch 'main' into ss/adapt-veros
simone-silvestri Sep 1, 2025
da45c7e
Merge branch 'main' into ss/adapt-veros
simone-silvestri Sep 4, 2025
8aa6b13
Merge branch 'main' into ss/adapt-veros
simone-silvestri Oct 13, 2025
62a3cc8
Update TODO comment for fluxes BC in veros
simone-silvestri Oct 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

[pip.deps]
copernicusmarine = ">=2.0.0"
xarray = ">=2024.7.0"
numpy = ">=2.0.0"
jax = ">=0.6"
copernicusmarine = ">=2.0.0"
numpy = "==2.3.1"
tensorflow = ">=2.17"
veros = ""
113 changes: 113 additions & 0 deletions experiments/veros_forced_simulation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using ClimaOcean
using PythonCall
using Oceananigans
using Printf

#####
##### A Prognostic Python Ocean (Veros) Simulation
#####

# We import the Veros 4 degree ocean simulation setup, which consists of a near-global ocean
# with a uniform resolution of 4 degrees in both latitude and longitude and a latitude range spanning
# from 80S to 80N. The setup is defined in the `veros.setups.global_4deg` module.

# Before importing the setup, we need to ensure that the Veros module is loaded
# and that every output is removed to avoid conflicts.

VerosModule = Base.get_extension(ClimaOcean, :ClimaOceanPythonCallExt)
VerosModule.remove_outputs(:global_4deg)

# Actually loading and instantiating the Veros setup in the variable `ocean`.
# This setup uses by default a different time-step for tracers and momentum,
# so we set it to the same value (1800 seconds) for both.

ocean = VerosModule.VerosOceanSimulation("global_4deg", :GlobalFourDegreeSetup)

set!(ocean, "dt_tracer", 1800.0; path=:settings)
set!(ocean, "dt_mom", 1800.0; path=:settings)

#####
##### A Prescribed Atmosphere (JRA55)
#####

atmos = JRA55PrescribedAtmosphere(; backend = JRA55NetCDFBackend(10))

#####
##### An ice-free ocean forced by a prescribed atmosphere
#####

radiation = Radiation()
coupled_model = OceanSeaIceModel(ocean, nothing; atmosphere=atmos, radiation)
simulation = Simulation(coupled_model; Δt = 1800, stop_iteration = 100000)

#####
##### A simple progress callback
#####

# We set up a progress callback that will print the current time, iteration, and maximum velocities
# at every 5 iterations. It also collects the surface velocity fields and the net fluxes
# into the arrays `s`, `tx`, and `ty` for later visualization.

wall_time = Ref(time_ns())

s = []
tx = []
ty = []

us = coupled_model.interfaces.exchanger.exchange_ocean_state.u
vs = coupled_model.interfaces.exchanger.exchange_ocean_state.v

stmp = Field(sqrt(us^2 + vs^2))

function progress(sim)
ocean = sim.model.ocean
umax = maximum(PyArray(ocean.setup.state.variables.u))
vmax = maximum(PyArray(ocean.setup.state.variables.v))
wmax = maximum(PyArray(ocean.setup.state.variables.w))

step_time = 1e-9 * (time_ns() - wall_time[])

msg1 = @sprintf("time: %s, iteration: %d, Δt: %s, ", prettytime(sim), iteration(sim), prettytime(sim.Δt))
msg5 = @sprintf("maximum(u): (%.2f, %.2f, %.2f) m/s, ", umax, vmax, wmax)
msg6 = @sprintf("wall time: %s \n", prettytime(step_time))

@info msg1 * msg5 * msg6

wall_time[] = time_ns()

compute!(stmp)
push!(s, deepcopy(interior(stmp, :, :, 1)))
push!(tx, deepcopy(interior(coupled_model.interfaces.net_fluxes.ocean_surface.u, :, :, 1) .* 1020))
push!(ty, deepcopy(interior(coupled_model.interfaces.net_fluxes.ocean_surface.v, :, :, 1) .* 1020))

return nothing
end

add_callback!(simulation, progress, IterationInterval(5))

#####
##### Let's go!!
#####

run!(simulation)

#####
##### Visualize
#####

iter = Observable(1)
si = @lift(s[$iter])
txi = @lift(tx[$iter])
tyi = @lift(ty[$iter])

fig = Figure(resolution = (1200, 300))
ax1 = Axis(fig[1, 1]; title = "Surface speed (m/s)", xlabel = "Longitude", ylabel = "Latitude")
ax2 = Axis(fig[1, 2]; title = "Zonal wind stress (N/m²)", xlabel = "Longitude")
ax3 = Axis(fig[1, 3]; title = "Meridional wind stress (N/m²)", xlabel = "Longitude")

grid = coupled_model.interfaces.exchanger.exchange_grid
λ = λnodes(grid, Center())
φ = φnodes(grid, Center())
heatmap!(ax1, λ, φ, si, colormap = :ice, colorrange = (0, 0.15))
heatmap!(ax2, λ, φ, txi, colormap = :bwr, colorrange = (-0.2, 0.2))
heatmap!(ax3, λ, φ, tyi, colormap = :bwr, colorrange = (-0.2, 0.2))
15 changes: 15 additions & 0 deletions ext/ClimaOceanPythonCallExt/ClimaOceanPythonCallExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module ClimaOceanPythonCallExt

using ClimaOcean
using CondaPkg
using PythonCall
using Oceananigans
using Oceananigans.DistributedComputations: @root

using Dates: DateTime

include("copernicus.jl")
include("veros_ocean_simulation.jl")
include("veros_state_exchanger.jl")

end # module ClimaOceanPythonCallExt
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,3 @@ function depth_bounds_kw(z)
maximum_depth = - z[1]
return (; minimum_depth, maximum_depth)
end

end # module ClimaOceanPythonCallExt
202 changes: 202 additions & 0 deletions ext/ClimaOceanPythonCallExt/veros_ocean_simulation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
using CondaPkg

using Oceananigans.Grids: topology
using ClimaOcean.OceanSeaIceModels: reference_density, heat_capacity, SeaIceSimulation

import Oceananigans.Fields: set!
import Oceananigans.TimeSteppers: time_step!, initialize!

import ClimaOcean.OceanSeaIceModels: OceanSeaIceModel, default_nan_checker
import Oceananigans.Architectures: architecture

import Base: eltype

"""
install_veros()

Install the Veros ocean model Marine CLI using CondaPkg.
Returns a NamedTuple containing package information if successful.
"""
function install_veros()
CondaPkg.add("veros"; channel = "conda-forge")
cli = CondaPkg.which("veros")
@info "... the veros CLI has been installed at $(cli)."
return cli
end

struct VerosOceanSimulation{S}
setup :: S
end

default_nan_checker(model::OceanSeaIceModel{<:Any, <:Any, <:VerosOceanSimulation}) = nothing

initialize!(::ClimaOceanPythonCallExt.VerosOceanSimulation{Py}) = nothing
time_step!(ocean::VerosOceanSimulation, Δt) = ocean.setup.step(ocean.setup.state)
architecture(model::OceanSeaIceModel{<:Any, <:Any, <:VerosOceanSimulation}) = CPU()
eltype(model::OceanSeaIceModel{<:Any, <:Any, <:VerosOceanSimulation}) = Float64

function remove_outputs(setup::Symbol)
rm("$(setup).averages.nc", force=true)
rm("$(setup).energy.nc", force=true)
rm("$(setup).overturning.nc", force=true)
rm("$(setup).snapshot.nc", force=true)
return nothing
end

const CCField2D = Field{<:Center, <:Center, <:Nothing}
const FCField2D = Field{<:Face, <:Center, <:Nothing}
const CFField2D = Field{<:Center, <:Face, <:Nothing}

function set!(field::CCField2D, pyarray::Py, k=pyconvert(Int, pyarray.shape[2]))
array = PyArray(pyarray)
Nx, Ny, Nz = size(array)
set!(field, view(array, 3:Nx-2, 3:Ny-2, k, 1))
return field
end

function set!(field::FCField2D, pyarray::Py, k=pyconvert(Int, pyarray.shape[2]))
array = PyArray(pyarray)
Nx, Ny, Nz = size(array)
TX, TY, _ = topology(field.grid)
i_indices = TX == Periodic ? UnitRange(3, Nx-2) : UnitRange(2, Nx-2)
set!(field, view(array, i_indices, 3:Ny-2, k, 1))
return field
end

function set!(field::CFField2D, pyarray::Py, k=pyconvert(Int, pyarray.shape[2]))
array = PyArray(pyarray)
Nx, Ny, Nz = size(array)
set!(field, view(array, 3:Nx-2, 2:Ny-2, k, 1))
return field
end

"""
VerosOceanSimulation(setup, setup_name::Symbol)

Creates and initializes a preconfigured Veros ocean simulation using the
specified setup module and setup name.

Arguments
==========
- `setup::AbstractString`: The name of the Veros setup module to import (e.g., `"global_4deg"`).
- `setup_name::Symbol`: The name of the setup class or function within the module to instantiate (e.g., `:GlobalFourDegreeSetup`).
"""
function VerosOceanSimulation(setup, setup_name::Symbol)
setups = pyimport("veros.setups." * setup)
setup = @eval $setups.$setup_name()

# instantiate the setup
setup.setup()

return VerosOceanSimulation(setup)
end

"""
surface_grid(ocean::VerosOceanSimulation)

Constructs a `LatitudeLongitudeGrid` representing the surface grid of the given `VerosOceanSimulation` object.
Notes: Veros always uses a LatitudeLongitudeGrid with 2 halos in both the latitude and longitude directions.
Both latitude and longitude can be either stretched or uniform, depending on the setup, and while the meridional
direction (latitude) is always Bounded, the zonal direction (longitude) can be either Periodic or Bounded.

Arguments
==========
- `ocean::VerosOceanSimulation`: The ocean simulation object containing the grid state variables.
"""
function surface_grid(ocean::VerosOceanSimulation)

xf = Array(PyArray(ocean.setup.state.variables.xu))
yf = Array(PyArray(ocean.setup.state.variables.yu))

xc = Array(PyArray(ocean.setup.state.variables.xt))
yc = Array(PyArray(ocean.setup.state.variables.yt))

xf = xf[2:end-2]
yf = yf[2:end-2]

xc = xc[3:end-2]
yc = yc[3:end-2]

xf[1] = xf[2] - 2xc[1]
yf[1] = sign(yf[2]) * (yf[2] - 2yc[1])

TX = if xf[1] == 0 && xf[end] == 360
Periodic
else
Bounded
end

Nx = length(xc)
Ny = length(yc)

return LatitudeLongitudeGrid(size=(Nx, Ny), longitude=xf, latitude=yf, topology=(TX, Bounded, Flat), halo=(2, 2))
end

"""
set!(ocean, v, x; path = :variable)

Set the `v` variable in the `ocean` model to the value of `x`.
the path corresponds to the path inside the class where to locate the
variable `v` to set. It can be either `:variables` or `:settings`.
"""
function set!(ocean::VerosOceanSimulation, v, x; path = :variables)
setup = ocean.setup
if path == :variables
pyexec("""
with setup.state.variables.unlock():
setup.state.variables.__setattr__(y, t)
""", Main, (y=v, t=x, setup=setup))
elseif path == :settings
pyexec("""
with setup.state.settings.unlock():
setup.state.settings.__setattr__(y, t)
""", Main, (y=v, t=x, setup=setup))
else
error("path must be either :variable or :settings.")
end
end

function OceanSeaIceModel(ocean::VerosOceanSimulation, sea_ice=nothing;
atmosphere = nothing,
radiation = Radiation(),
clock = Clock(time=0),
ocean_reference_density = 1020.0,
ocean_heat_capacity = 3998.0,
sea_ice_reference_density = reference_density(sea_ice),
sea_ice_heat_capacity = heat_capacity(sea_ice),
interfaces = nothing)

if sea_ice isa SeaIceSimulation
if !isnothing(sea_ice.callbacks)
pop!(sea_ice.callbacks, :stop_time_exceeded, nothing)
pop!(sea_ice.callbacks, :stop_iteration_exceeded, nothing)
pop!(sea_ice.callbacks, :wall_time_limit_exceeded, nothing)
pop!(sea_ice.callbacks, :nan_checker, nothing)
end
end

# Contains information about flux contributions: bulk formula, prescribed fluxes, etc.
if isnothing(interfaces) && !(isnothing(atmosphere) && isnothing(sea_ice))
interfaces = ComponentInterfaces(atmosphere, ocean, sea_ice;
ocean_reference_density,
ocean_heat_capacity,
sea_ice_reference_density,
sea_ice_heat_capacity,
radiation)
end

arch = CPU()

ocean_sea_ice_model = OceanSeaIceModel(arch,
clock,
atmosphere,
sea_ice,
ocean,
interfaces)

# Make sure the initial temperature of the ocean
# is not below freezing and above melting near the surface
initialization_update_state!(ocean_sea_ice_model)

return ocean_sea_ice_model
end
Loading
Loading