4848@inline get_possibly_zero_flux (fluxes, name) = getfield (fluxes, name)
4949@inline get_possibly_zero_flux (:: Nothing , name) = ZeroField ()
5050
51-
5251mutable struct ComponentInterfaces{AO, ASI, SIO, C, AP, OP, SIP, EX, P}
5352 atmosphere_ocean_interface :: AO
5453 atmosphere_sea_ice_interface :: ASI
@@ -61,100 +60,6 @@ mutable struct ComponentInterfaces{AO, ASI, SIO, C, AP, OP, SIP, EX, P}
6160 properties :: P
6261end
6362
64- mutable struct StateExchanger{G, AST, AEX}
65- exchange_grid :: G
66- exchange_atmosphere_state :: AST
67- atmosphere_exchanger :: AEX
68- end
69-
70- mutable struct ExchangeAtmosphereState{F}
71- u :: F
72- v :: F
73- T :: F
74- q :: F
75- p :: F
76- Qs :: F
77- Qℓ :: F
78- Mp :: F
79- end
80-
81- ExchangeAtmosphereState (grid) = ExchangeAtmosphereState (Field {Center, Center, Nothing} (grid),
82- Field {Center, Center, Nothing} (grid),
83- Field {Center, Center, Nothing} (grid),
84- Field {Center, Center, Nothing} (grid),
85- Field {Center, Center, Nothing} (grid),
86- Field {Center, Center, Nothing} (grid),
87- Field {Center, Center, Nothing} (grid),
88- Field {Center, Center, Nothing} (grid))
89-
90- # Note that Field location can also affect fractional index type.
91- # Here we assume that we know the location of Fields that will be interpolated.
92- fractional_index_type (FT, Topo) = FT
93- fractional_index_type (FT, :: Flat ) = Nothing
94-
95- StateExchanger (ocean:: Simulation , :: Nothing ) = nothing
96-
97- function StateExchanger (ocean:: Simulation , atmosphere)
98- # TODO : generalize this
99- exchange_grid = ocean. model. grid
100- exchange_atmosphere_state = ExchangeAtmosphereState (exchange_grid)
101- exchanger = atmosphere_exchanger (atmosphere, exchange_grid, exchange_atmosphere_state)
102-
103- return StateExchanger (ocean. model. grid, exchange_atmosphere_state, exchanger)
104- end
105-
106- function atmosphere_exchanger (atmosphere:: PrescribedAtmosphere , exchange_grid, exchange_atmosphere_state)
107- atmos_grid = atmosphere. grid
108- arch = architecture (exchange_grid)
109- Nx, Ny, Nz = size (exchange_grid)
110-
111- # Make a NamedTuple of fractional indices
112- # Note: we could use an array of FractionalIndices. Instead, for compatbility
113- # with Reactant we construct FractionalIndices on the fly in `interpolate_atmospheric_state`.
114- FT = eltype (atmos_grid)
115- TX, TY, TZ = topology (exchange_grid)
116- fi = TX () isa Flat ? nothing : Field {Center, Center, Nothing} (exchange_grid, FT)
117- fj = TY () isa Flat ? nothing : Field {Center, Center, Nothing} (exchange_grid, FT)
118- frac_indices = (i= fi, j= fj) # no k needed, only horizontal interpolation
119-
120- return frac_indices
121- end
122-
123- initialize! (exchanger:: StateExchanger , :: Nothing ) = nothing
124-
125- function initialize! (exchanger:: StateExchanger , atmosphere:: PrescribedAtmosphere )
126- atmos_grid = atmosphere. grid
127- exchange_grid = exchanger. exchange_grid
128- arch = architecture (exchange_grid)
129- frac_indices = exchanger. atmosphere_exchanger
130- kernel_parameters = interface_kernel_parameters (exchange_grid)
131- launch! (arch, exchange_grid, kernel_parameters,
132- _compute_fractional_indices!, frac_indices, exchange_grid, atmos_grid)
133- return nothing
134- end
135-
136- @kernel function _compute_fractional_indices! (indices_tuple, exchange_grid, atmos_grid)
137- i, j = @index (Global, NTuple)
138- kᴺ = size (exchange_grid, 3 ) # index of the top ocean cell
139- X = _node (i, j, kᴺ + 1 , exchange_grid, c, c, f)
140- if topology (atmos_grid) == (Flat, Flat, Flat)
141- fractional_indices_ij = FractionalIndices (nothing , nothing , nothing )
142- else
143- fractional_indices_ij = FractionalIndices (X, atmos_grid, c, c, c)
144- end
145- fi = indices_tuple. i
146- fj = indices_tuple. j
147- @inbounds begin
148- if ! isnothing (fi)
149- fi[i, j, 1 ] = fractional_indices_ij. i
150- end
151-
152- if ! isnothing (fj)
153- fj[i, j, 1 ] = fractional_indices_ij. j
154- end
155- end
156- end
157-
15863# Possible units for temperature and salinity
15964struct DegreesCelsius end
16065struct DegreesKelvin end
0 commit comments