Skip to content

Commit c7dbcb0

Browse files
overload the set! function
1 parent c7ee9ad commit c7dbcb0

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

experiments/veros_forced_simulation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ VerosModule.remove_outputs(:global_4deg)
2323

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

26-
VerosModule.veros_settings_set!(ocean, "dt_tracer", 1800.0)
27-
VerosModule.veros_settings_set!(ocean, "dt_mom", 1800.0)
26+
set!(ocean.setup.settings, "dt_tracer", 1800.0)
27+
set!(ocean.setup.settings, "dt_mom", 1800.0)
2828

2929
#####
3030
##### A Prescribed Atmosphere (JRA55)

ext/ClimaOceanPythonCallExt/veros_ocean_simulation.jl

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,30 +133,15 @@ function surface_grid(ocean::VerosOceanSimulation)
133133
end
134134

135135
"""
136-
veros_set!(ocean, v, x)
136+
set!(class::Py, v, x)
137137
138-
Set the `v` variable in the `ocean` model to the value of `x`.
138+
Set the `s` property of a Python `class` to the value of `x`.
139139
"""
140-
function veros_set!(ocean::VerosOceanSimulation, v, x)
141-
setup = ocean.setup
140+
function set!(class::Py, s, x)
142141
pyexec("""
143-
with setup.state.variables.unlock():
144-
setup.state.variables.__setattr__(y, t)
145-
""", Main, (y=v, t=x, setup=setup))
146-
end
147-
148-
149-
"""
150-
veros_settings_set!(ocean, v, x)
151-
152-
Set the `s` setting in the `ocean` model to the value of `x`.
153-
"""
154-
function veros_settings_set!(ocean::VerosOceanSimulation, s, x)
155-
setup = ocean.setup
156-
pyexec("""
157-
with setup.state.settings.unlock():
158-
setup.state.settings.__setattr__(y, t)
159-
""", Main, (y=s, t=x, setup=setup))
142+
with class.unlock():
143+
class.__setattr__(y, t)
144+
""", Main, (y=s, t=x, class=class))
160145
end
161146

162147
function OceanSeaIceModel(ocean::VerosOceanSimulation, sea_ice=nothing;

ext/ClimaOceanPythonCallExt/veros_state_exchanger.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ClimaOcean.OceanSeaIceModels.InterfaceComputations:
1313
get_ocean_state,
1414
ocean_surface_fluxes,
1515
get_radiative_forcing,
16-
fill_up_net_fluxes!
16+
fill_net_fluxes!
1717

1818
mutable struct VerosStateExchanger{G, OST, AST, AEX}
1919
exchange_grid :: G
@@ -97,8 +97,8 @@ function fill_net_fluxes!(ocean::VerosOceanSimulation, net_ocean_fluxes)
9797
tb[:, :, t] .= t2
9898
end
9999

100-
veros_set!(ocean, "taux", ta)
101-
veros_set!(ocean, "tauy", tb)
100+
set!(ocean.state.variables, "taux", ta)
101+
set!(ocean.state.variables, "tauy", tb)
102102

103103
# TODO: Add heat flux and salinity flux when they
104104
# fix veros to be able to force with prescribed boundary
@@ -107,8 +107,8 @@ function fill_net_fluxes!(ocean::VerosOceanSimulation, net_ocean_fluxes)
107107
# t1 = view(parent(net_ocean_fluxes.T), 1:nx, 2:ny+1, 1)
108108
# t2 = view(parent(net_ocean_fluxes.S), 1:nx, 2:ny+1, 1)
109109

110-
# veros_set!(ocean, "temp_flux", t1)
111-
# veros_set!(ocean, "salt_flux", t2)
110+
# set!(ocean, "temp_flux", t1)
111+
# set!(ocean, "salt_flux", t2)
112112

113113
return nothing
114114
end

0 commit comments

Comments
 (0)