Skip to content

Commit b74450f

Browse files
coupled
1 parent 2460b14 commit b74450f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

ext/ClimaOceanPythonCallExt/veros_ocean_simulation.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CondaPkg
22

3+
using Oceananigans.Grids: topology
34
using ClimaOcean.OceanSeaIceModels: reference_density, heat_capacity, SeaIceSimulation
45

56
import Oceananigans.Fields: set!
@@ -43,10 +44,10 @@ function remove_outputs(setup::Symbol)
4344
end
4445

4546
const CCField2D = Field{<:Center, <:Center, <:Nothing}
46-
const FCField2D = Field{<:Face, <:Center, <:Nothing}
47+
const FCField2D = Field{<:Face, <:Center, <:Nothing}
4748
const CFField2D = Field{<:Center, <:Face, <:Nothing}
4849

49-
function set!(field::CCField2D, pyarray::Py, k=pyconvert(Int, pyarray.shape[2]))
50+
function set!(field::Field2D, pyarray::Py, k=pyconvert(Int, pyarray.shape[2]))
5051
array = PyArray(pyarray)
5152
Nx, Ny, Nz = size(array)
5253
set!(field, view(array, 3:Nx-2, 3:Ny-2, k, 1))
@@ -56,7 +57,9 @@ end
5657
function set!(field::FCField2D, pyarray::Py, k=pyconvert(Int, pyarray.shape[2]))
5758
array = PyArray(pyarray)
5859
Nx, Ny, Nz = size(array)
59-
set!(field, view(array, 3:Nx-2, 3:Ny-2, k, 1))
60+
TX, TY, _ = topology(field.grid)
61+
i_indices = TX == Periodic ? UnitRange(3, Nx-2) : UnitRange(2, Nx-2)
62+
set!(field, view(array, i_indices, 3:Ny-2, k, 1))
6063
return field
6164
end
6265

ext/ClimaOceanPythonCallExt/veros_state_exchanger.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ end
8383
@inline get_radiative_forcing(ocean::VerosOceanSimulation) = nothing
8484

8585
function fill_up_net_fluxes!(ocean::VerosOceanSimulation, net_ocean_fluxes)
86-
nx = pyconvert(Int, ocean.setup.state.settings.nx)
87-
ny = pyconvert(Int, ocean.setup.state.settings.ny)
88-
t1 = parent(net_ocean_fluxes.u)[:, 1:44, 1]
89-
t2 = parent(net_ocean_fluxes.v)[:, 1:44, 1]
86+
nx = pyconvert(Int, ocean.setup.state.settings.nx) + 4
87+
ny = pyconvert(Int, ocean.setup.state.settings.ny) + 4
88+
t1 = view(parent(net_ocean_fluxes.u), 1:nx, 1:ny, 1)
89+
t2 = view(parent(net_ocean_fluxes.v), 1:nx, 1:ny, 1)
9090

91+
# TODO: Remove this when they fix veros to
92+
# be able to force with an array instead of Climatology
9193
ta = zeros(size(t1)..., 12)
9294
tb = zeros(size(t2)..., 12)
9395
for t in 1:12
@@ -97,5 +99,16 @@ function fill_up_net_fluxes!(ocean::VerosOceanSimulation, net_ocean_fluxes)
9799

98100
veros_set!(ocean, "taux", ta)
99101
veros_set!(ocean, "tauy", tb)
102+
103+
# TODO: Add heat flux and salinity flux when they
104+
# fix veros to be able to force with prescribed boundary
105+
# conditions rather than restoring
106+
107+
# t1 = view(parent(net_ocean_fluxes.T), 1:nx, 2:ny+1, 1)
108+
# t2 = view(parent(net_ocean_fluxes.S), 1:nx, 2:ny+1, 1)
109+
110+
# veros_set!(ocean, "temp_flux", t1)
111+
# veros_set!(ocean, "salt_flux", t2)
112+
100113
return nothing
101114
end

0 commit comments

Comments
 (0)