11import Oceananigans as OC
22import ClimaOcean as CO
33import ClimaCoupler: Checkpointer, FieldExchanger, FluxCalculator, Interfacer, Utilities
4- import Interfacer: remap, remap!, get_field
4+ import ClimaCoupler . Interfacer: remap, remap!, get_field
55import ClimaComms
66import ClimaCore as CC
77import Thermodynamics as TD
88import ClimaParams as CP
99import ClimaOcean. EN4: download_dataset
1010using KernelAbstractions: @kernel , @index , @inbounds
11- import ConservativeRemapping as CR
11+ import ConservativeRegridding as CR
1212
1313include (" climaocean_helpers.jl" )
1414
@@ -76,7 +76,7 @@ function OceananigansSimulation(
7676 bottom_height = CO. regrid_bathymetry (
7777 underlying_grid;
7878 minimum_depth = 30 ,
79- interpolation_passes = 20 ,
79+ interpolation_passes = 1 ,
8080 major_basins = 1 ,
8181 )
8282 grid = OC. ImmersedBoundaryGrid (
@@ -183,7 +183,7 @@ To regrid from ClimaCore to Oceananigans, use `CR.regrid!(dest_vector, transpose
183183"""
184184function construct_remappers (grid_oc, boundary_space)
185185 # Get the vector of polygons for Oceananigans and ClimaCore spaces
186- vertices_oc = compute_cell_matrix (grid_oc)
186+ vertices_oc = compute_cell_matrix (grid_oc. underlying_grid )
187187 vertices_cc = CC. Remapping. get_element_vertices (boundary_space)
188188
189189 remapper_oc_to_cc = CR. Regridder (vertices_cc, vertices_oc)
@@ -210,12 +210,15 @@ end
210210
211211# Non-allocating ClimaCore -> Oceananigans remap
212212function Interfacer. remap! (dst_field:: OC.Field , src_field:: CC.Fields.Field , remapping)
213- value_per_element_cc =
214- CC. Remappping. get_value_per_element (src_field, remapping. field_ones_cc)
213+ CC. Remapping. get_value_per_element! (
214+ remapping. value_per_element_cc,
215+ src_field,
216+ remapping. field_ones_cc,
217+ )
215218 CR. regrid! (
216- vec (interior (dst_field)),
219+ vec (OC . interior (dst_field, :, :, 1 )),
217220 transpose (remapping. remapper_oc_to_cc),
218- value_per_element_cc,
221+ remapping . value_per_element_cc,
219222 )
220223 return nothing
221224end
@@ -235,13 +238,18 @@ function Interfacer.remap!(dst_field::CC.Fields.Field, src_field::OC.Field, rema
235238 CR. regrid! (
236239 remapping. value_per_element_cc,
237240 remapping. remapper_oc_to_cc,
238- vec (interior (src_field)),
241+ vec (OC . interior (src_field, :, :, 1 )),
239242 )
240243
241244 # Convert the vector of remapped values to a ClimaCore Field with one value per element
242245 CC. Remapping. set_value_per_element! (dst_field, remapping. value_per_element_cc)
243246 return nothing
244247end
248+ # Handle the case of remapping the area fraction field, which is a ClimaCore Field
249+ Interfacer. remap! (dst_field:: CC.Fields.Field , src_field:: CC.Fields.Field , remapping) =
250+ Interfacer. remap! (dst_field, src_field)
251+ Interfacer. remap! (dst_field:: CC.Fields.Field , src_field:: Number , remapping) =
252+ Interfacer. remap! (dst_field, src_field)
245253# Allocating Oceananigans -> ClimaCore remap
246254function Interfacer. remap (
247255 src_field:: OC.Field ,
@@ -253,10 +261,22 @@ function Interfacer.remap(
253261 return dst_field
254262end
255263
264+ # Handle the case of remapping a scalar number to a ClimaCore space
265+ Interfacer. remap (num:: Number , remapping, target_space:: CC.Spaces.AbstractSpace ) =
266+ Interfacer. remap (num, target_space)
267+
256268# Extend Interfacer.get_field to allow automatic remapping to the target space
257269# TODO see if we can remove this
258- function Interfacer. get_field (sim, quantity, target_space)
259- return remap (Interfacer. get_field (sim, quantity), sim. remapping, target_space)
270+ function Interfacer. get_field (sim:: OceananigansSimulation , quantity, target_space)
271+ return Interfacer. remap (
272+ Interfacer. get_field (sim, quantity),
273+ sim. remapping,
274+ target_space,
275+ )
276+ end
277+ function Interfacer. get_field! (target_field, sim:: OceananigansSimulation , quantity)
278+ Interfacer. remap! (target_field, Interfacer. get_field (sim, quantity), sim. remapping)
279+ return nothing
260280end
261281
262282"""
@@ -363,21 +383,23 @@ function FluxCalculator.update_turbulent_fluxes!(sim::OceananigansSimulation, fi
363383 Interfacer. remap! (sim. remapping. scratch_field_oc2, F_turb_ρτyz, sim. remapping) # meridional momentum flux
364384
365385 # Rename for clarity; these are now Center, Center Oceananigans fields
366- F_turb_ρτxz_oc = OC . interior ( sim. remapping. scratch_field_oc1, :, :, 1 )
367- F_turb_ρτyz_oc = OC . interior ( sim. remapping. scratch_field_oc2, :, :, 1 )
386+ oc_F_turb_ρτxz = sim. remapping. scratch_field_oc1
387+ oc_F_turb_ρτyz = sim. remapping. scratch_field_oc2
368388
369389 # Weight by (1 - sea ice concentration)
370- OC. interior (F_turb_ρτxz_oc, :, :, 1 ) .= F_turb_ρτxz_oc .* (1.0 .- ice_concentration)
371- OC. interior (F_turb_ρτyz_oc, :, :, 1 ) .= F_turb_ρτyz_oc .* (1.0 .- ice_concentration)
390+ OC. interior (oc_F_turb_ρτxz, :, :, 1 ) .=
391+ OC. interior (oc_F_turb_ρτxz, :, :, 1 ) .* (1.0 .- ice_concentration)
392+ OC. interior (oc_F_turb_ρτyz, :, :, 1 ) .=
393+ OC. interior (oc_F_turb_ρτyz, :, :, 1 ) .* (1.0 .- ice_concentration)
372394
373395 # Set the momentum flux BCs at the correct locations using the remapped scratch fields
374396 oc_flux_u = surface_flux (sim. ocean. model. velocities. u)
375397 oc_flux_v = surface_flux (sim. ocean. model. velocities. v)
376398 set_from_extrinsic_vector! (
377399 (; u = oc_flux_u, v = oc_flux_v),
378400 grid,
379- F_turb_ρτxz_cc ,
380- F_turb_ρτyz_cc ,
401+ oc_F_turb_ρτxz ,
402+ oc_F_turb_ρτyz ,
381403 )
382404
383405 (; reference_density, heat_capacity, fresh_water_density) = sim. ocean_properties
0 commit comments