Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(0.94.1) Refactor SplitExplicitFreeSurface #3894

Merged
merged 161 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 129 commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
4044e16
new bottom height
simone-silvestri Oct 9, 2024
b83a6ae
now it should work
simone-silvestri Oct 9, 2024
5ebaa84
comment
simone-silvestri Oct 9, 2024
f9ad227
comment
simone-silvestri Oct 9, 2024
cbdb713
remove circular dependency for now
simone-silvestri Oct 9, 2024
7f08768
some bugfixes
simone-silvestri Oct 9, 2024
4b7926f
change name to column_height
simone-silvestri Oct 9, 2024
6b7b27c
correct column height
simone-silvestri Oct 9, 2024
fdee366
whoops
simone-silvestri Oct 9, 2024
d1c145c
another correction
simone-silvestri Oct 9, 2024
dbb411a
some more changes
simone-silvestri Oct 9, 2024
3ec05df
another correction
simone-silvestri Oct 9, 2024
4e4d40b
couple of more bugfixes
simone-silvestri Oct 9, 2024
a6362ee
more bugfixes
simone-silvestri Oct 9, 2024
3bce6fc
this should make it work
simone-silvestri Oct 9, 2024
0fa1a67
unify the formulations
simone-silvestri Oct 9, 2024
135cac3
correct implementation
simone-silvestri Oct 9, 2024
156dada
correct implementation
simone-silvestri Oct 9, 2024
04e7170
correct partial cell bottom
simone-silvestri Oct 9, 2024
9258572
use center immersed condition for grid fitted boundary
simone-silvestri Oct 9, 2024
9df333a
use the *correct* center node
simone-silvestri Oct 9, 2024
053b26f
no h for z-values!
simone-silvestri Oct 9, 2024
61b7e7f
simplify partial cells
simone-silvestri Oct 9, 2024
1098c58
make sure we don't go out of bounds
simone-silvestri Oct 9, 2024
9e35af6
back to immersed condition
simone-silvestri Oct 9, 2024
ac7c96d
name changes
simone-silvestri Oct 10, 2024
f8d5c18
bugfix
simone-silvestri Oct 10, 2024
fd8a028
another bugfix
simone-silvestri Oct 10, 2024
f518d41
fix bugs
simone-silvestri Oct 11, 2024
983b956
some corrections
simone-silvestri Oct 11, 2024
dfada79
another bugfix
simone-silvestri Oct 11, 2024
2705b03
domain_depth
simone-silvestri Oct 11, 2024
ca935b6
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 11, 2024
cc9cd4f
some remaining `z_bottom`s
simone-silvestri Oct 11, 2024
495f6ea
Merge branch 'ss/new-bottom-height' of github.com:CliMA/Oceananigans.…
simone-silvestri Oct 11, 2024
45b5cd4
back as it was
simone-silvestri Oct 11, 2024
d381037
bugfix
simone-silvestri Oct 16, 2024
b8401cc
correct correction
simone-silvestri Oct 16, 2024
cfd5c42
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 17, 2024
3ecd318
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 21, 2024
b967754
static_column_depth
simone-silvestri Oct 21, 2024
3f36846
Merge branch 'ss/new-bottom-height' of github.com:CliMA/Oceananigans.…
simone-silvestri Oct 21, 2024
9ff305e
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 21, 2024
6046d2d
Update src/Grids/grid_utils.jl
simone-silvestri Oct 21, 2024
8106a70
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 23, 2024
a10df16
address comments
simone-silvestri Oct 23, 2024
5ee7623
new comment
simone-silvestri Oct 23, 2024
9777ee6
another name change
simone-silvestri Oct 23, 2024
1d219af
AGFBIBG istead of AGFBIB and z_bottom only in TurbulenceClosures
simone-silvestri Oct 23, 2024
238fa74
some bugfixes
simone-silvestri Oct 23, 2024
90dfa7a
better definition of bottom height
simone-silvestri Oct 23, 2024
f2402f0
fixed partial cell
simone-silvestri Oct 23, 2024
55d7432
fixed partial cells
simone-silvestri Oct 23, 2024
849c253
remove OrthogonalSphericalShellGrids while we decide what to do
simone-silvestri Oct 23, 2024
510a858
these files shouldn't go here
simone-silvestri Oct 23, 2024
926feda
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 25, 2024
aea0601
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 28, 2024
dfd0b30
Merge remote-tracking branch 'origin/main' into ss/new-bottom-height
simone-silvestri Oct 28, 2024
fe2d552
new operators
simone-silvestri Oct 28, 2024
d66baf2
Merge branch 'main' into ss/new-bottom-height
simone-silvestri Oct 30, 2024
c57a321
this was removed
simone-silvestri Oct 30, 2024
d78d659
start refactoring
simone-silvestri Oct 30, 2024
8653278
start refactoring
simone-silvestri Oct 30, 2024
4c728b3
some more refactoring
simone-silvestri Oct 30, 2024
04087ad
big overhaul
simone-silvestri Oct 30, 2024
ba7eb2f
Merge remote-tracking branch 'origin/main' into ss/refactor-split-exp…
simone-silvestri Oct 31, 2024
b9ec92b
more refactoring
simone-silvestri Oct 31, 2024
57be084
compiles
simone-silvestri Oct 31, 2024
c522ad3
more refactoring...
simone-silvestri Oct 31, 2024
dad5654
correction
simone-silvestri Nov 1, 2024
a253cc0
use a module for now
simone-silvestri Nov 1, 2024
e350d1c
make module work
simone-silvestri Nov 1, 2024
81a2c61
some more organizational stuff
simone-silvestri Nov 1, 2024
cf6d49d
some more changes
simone-silvestri Nov 1, 2024
4c844d8
it compiles
simone-silvestri Nov 1, 2024
d6d0bc7
using free_surface_displacement_field
simone-silvestri Nov 1, 2024
bb5c992
include g_Earth
simone-silvestri Nov 1, 2024
611aaec
now it should run
simone-silvestri Nov 1, 2024
aface2e
a little bit of cleanup
simone-silvestri Nov 1, 2024
811a1a6
tests should run now
simone-silvestri Nov 1, 2024
b90e4ac
Merge branch 'main' into ss/refactor-split-explicit
simone-silvestri Nov 1, 2024
df17eca
Update Project.toml
simone-silvestri Nov 1, 2024
fee6ace
conceptually this is better
simone-silvestri Nov 1, 2024
3b45d3b
fix checkpointer test
simone-silvestri Nov 1, 2024
e06226b
fix split explicit settings
simone-silvestri Nov 1, 2024
b09ce27
fixing some more tests
simone-silvestri Nov 1, 2024
dd9bd45
import with_halo
simone-silvestri Nov 1, 2024
1b15f91
back on Enzyme
simone-silvestri Nov 1, 2024
2e21d03
fix tets
simone-silvestri Nov 4, 2024
07cf9ab
some fixes
simone-silvestri Nov 4, 2024
bc3833e
these are prognostic fields
simone-silvestri Nov 4, 2024
581848b
comment
simone-silvestri Nov 4, 2024
cfcd521
Merge remote-tracking branch 'origin/main' into ss/refactor-split-exp…
simone-silvestri Nov 9, 2024
32bab5c
fix tests
simone-silvestri Nov 9, 2024
0ba3b35
move functions to correct file
simone-silvestri Nov 9, 2024
dd22f3e
apply regionally
simone-silvestri Nov 9, 2024
4e13496
Merge branch 'main' into ss/refactor-split-explicit
simone-silvestri Nov 10, 2024
0c60e28
fix tests + unify implementation
simone-silvestri Nov 10, 2024
4f811b9
remove old code
simone-silvestri Nov 10, 2024
f10d3d8
Merge branch 'ss/refactor-split-explicit' of github.com:CliMA/Oceanan…
simone-silvestri Nov 10, 2024
7e47376
fix comment
simone-silvestri Nov 10, 2024
a73d2fc
bugfix
simone-silvestri Nov 10, 2024
dcfacef
correction
simone-silvestri Nov 10, 2024
47cd4df
Merge branch 'main' into ss/refactor-split-explicit
simone-silvestri Nov 10, 2024
1302963
another bugfix
simone-silvestri Nov 10, 2024
1d26a73
Merge branch 'ss/refactor-split-explicit' of github.com:CliMA/Oceanan…
simone-silvestri Nov 10, 2024
75b22af
switch right and left connected
simone-silvestri Nov 10, 2024
011cedb
all inside apply regionally
simone-silvestri Nov 10, 2024
399c81a
revert
simone-silvestri Nov 10, 2024
c237adf
tests corrected
simone-silvestri Nov 10, 2024
e02de47
fixed tests
simone-silvestri Nov 11, 2024
06309c5
explicit free surface tendency in its own file
simone-silvestri Nov 11, 2024
70b8d49
test checkpointer
simone-silvestri Nov 11, 2024
77decf1
last bugfix
simone-silvestri Nov 11, 2024
98f6494
removed test script
simone-silvestri Nov 11, 2024
a466ae7
last bugfix?
simone-silvestri Nov 11, 2024
d598306
Merge branch 'main' into ss/refactor-split-explicit
simone-silvestri Nov 11, 2024
fff33e5
add to docs
simone-silvestri Nov 11, 2024
b85d692
Merge branch 'ss/refactor-split-explicit' of github.com:CliMA/Oceanan…
simone-silvestri Nov 11, 2024
ffc8a99
Merge branch 'main' into ss/refactor-split-explicit
simone-silvestri Nov 11, 2024
fdbd76a
thought I had already fixed this
simone-silvestri Nov 11, 2024
32f9489
bugfix
simone-silvestri Nov 12, 2024
e223912
unpacking all the fields
simone-silvestri Nov 12, 2024
252039f
last bugfix
simone-silvestri Nov 12, 2024
523b6ea
Merge branch 'main' into ss/refactor-split-explicit
simone-silvestri Nov 12, 2024
3c5930b
fix typo in docs
navidcy Nov 12, 2024
2247463
remove stray spaces
navidcy Nov 12, 2024
5adc847
empty line
navidcy Nov 12, 2024
409ca75
minor
navidcy Nov 12, 2024
89927ff
add reference
simone-silvestri Nov 13, 2024
8f274ef
split lines for math rendering
navidcy Nov 13, 2024
09b1478
better latex rendering
navidcy Nov 13, 2024
cc98fbd
math rendering
navidcy Nov 14, 2024
6f12b55
Update docs/src/appendix/library.md
simone-silvestri Nov 14, 2024
4936b53
Merge branch 'main' into ss/refactor-split-explicit
simone-silvestri Nov 14, 2024
f13b5ef
better comment for the corrector
simone-silvestri Nov 14, 2024
6caef61
Merge branch 'ss/refactor-split-explicit' of github.com:CliMA/Oceanan…
simone-silvestri Nov 14, 2024
c16b271
add comments in the docstring
simone-silvestri Nov 14, 2024
abcca51
remove kernel_parameters from the initial constructor
simone-silvestri Nov 14, 2024
ddb98e4
Update src/Models/HydrostaticFreeSurfaceModels/SplitExplicitFreeSurfa…
simone-silvestri Nov 14, 2024
4e23120
move errors inside constructors
simone-silvestri Nov 14, 2024
9a30d24
change summary strings
simone-silvestri Nov 14, 2024
350c727
store instead of advance
simone-silvestri Nov 14, 2024
4837fd6
change name to setup_free_surface!
simone-silvestri Nov 14, 2024
fb1861d
simplify ab2_step_G
simone-silvestri Nov 14, 2024
51faaad
move `compute_free_surface_tendency!` where it should go
simone-silvestri Nov 14, 2024
2fc3b68
minimize using statements
simone-silvestri Nov 14, 2024
a771810
bugfix
simone-silvestri Nov 14, 2024
0613fd5
bugfix in integrated tendencies
simone-silvestri Nov 14, 2024
85f15e3
revert quickly to see if this works
simone-silvestri Nov 14, 2024
ed1b593
compute_free_surface_tendecny! is the only problem
simone-silvestri Nov 14, 2024
f6d16cb
no need for const c and const f
simone-silvestri Nov 14, 2024
5eec283
fix errors
simone-silvestri Nov 14, 2024
c45bf12
Merge branch 'main' into ss/refactor-split-explicit
glwagner Nov 14, 2024
0e8167b
eliding NaNs + separate compute_slow_tendencies
simone-silvestri Nov 14, 2024
7229362
Merge branch 'ss/refactor-split-explicit' of github.com:CliMA/Oceanan…
simone-silvestri Nov 14, 2024
efbe3db
whoops wrong name
simone-silvestri Nov 14, 2024
6db20bb
fix in the summary
simone-silvestri Nov 14, 2024
944fd40
Update src/Models/HydrostaticFreeSurfaceModels/SplitExplicitFreeSurfa…
simone-silvestri Nov 14, 2024
7536c26
Update src/Models/HydrostaticFreeSurfaceModels/SplitExplicitFreeSurfa…
simone-silvestri Nov 14, 2024
2098d87
remove vestigial `@show`
simone-silvestri Nov 14, 2024
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Oceananigans"
uuid = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
authors = ["Climate Modeling Alliance and contributors"]
version = "0.94.0"
version = "0.94.1"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
7 changes: 7 additions & 0 deletions docs/src/appendix/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ Modules = [Oceananigans.Models.HydrostaticFreeSurfaceModels]
Private = false
```

### Split-explicit free-surface solver

```@autodocs
Modules = [Oceananigans.Models.HydrostaticFreeSurfaceModels.SplitExplicitFreeSurfaces]
Private = false
```

### Shallow-water models

```@autodocs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ fill_horizontal_velocity_halos!(args...) = nothing
free_surface_displacement_field(velocities, free_surface, grid) = ZFaceField(grid, indices = (:, :, size(grid, 3)+1))
free_surface_displacement_field(velocities, ::Nothing, grid) = nothing

# free surface initialization functions
initialize_free_surface!(free_surface, grid, velocities) = nothing
setup_free_surface!(model, free_surface, χ) = nothing

include("compute_w_from_continuity.jl")
include("rigid_lid.jl")

# No free surface
include("nothing_free_surface.jl")

# Explicit free-surface solver functionality
include("explicit_free_surface.jl")
Expand All @@ -46,9 +52,9 @@ include("matrix_implicit_free_surface_solver.jl")
include("implicit_free_surface.jl")

# Split-Explicit free-surface solver functionality
include("split_explicit_free_surface.jl")
include("distributed_split_explicit_free_surface.jl")
include("split_explicit_free_surface_kernels.jl")
include("SplitExplicitFreeSurfaces/SplitExplicitFreeSurfaces.jl")

using .SplitExplicitFreeSurfaces

include("hydrostatic_free_surface_field_tuples.jl")
include("hydrostatic_free_surface_model.jl")
Expand Down Expand Up @@ -85,6 +91,13 @@ Return a flattened `NamedTuple` of the prognostic fields associated with `Hydros
η = free_surface.η),
tracers)

@inline hydrostatic_prognostic_fields(velocities, free_surface::SplitExplicitFreeSurface, tracers) = merge((u = velocities.u,
v = velocities.v,
η = free_surface.η,
U = free_surface.barotropic_velocities.U,
V = free_surface.barotropic_velocities.V),
tracers)

@inline hydrostatic_prognostic_fields(velocities, ::Nothing, tracers) = merge((u = velocities.u,
v = velocities.v),
tracers)
Expand All @@ -95,6 +108,14 @@ Return a flattened `NamedTuple` of the prognostic fields associated with `Hydros
tracers,
(; η = free_surface.η))

@inline hydrostatic_fields(velocities, free_surface::SplitExplicitFreeSurface, tracers) = merge((u = velocities.u,
v = velocities.v,
w = velocities.w,
η = free_surface.η,
U = free_surface.barotropic_velocities.U,
V = free_surface.barotropic_velocities.V),
tracers)

@inline hydrostatic_fields(velocities, ::Nothing, tracers) = merge((u = velocities.u,
v = velocities.v,
w = velocities.w),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module SplitExplicitFreeSurfaces

export SplitExplicitFreeSurface, ForwardBackwardScheme, AdamsBashforth3Scheme
export FixedSubstepNumber, FixedTimeStepSize

using Oceananigans
using Oceananigans.Architectures
using Oceananigans.Fields
using Oceananigans.Utils
using Oceananigans.Grids
using Oceananigans.Operators
using Oceananigans.Grids: AbstractGrid
using Oceananigans.Models.HydrostaticFreeSurfaceModels: AbstractFreeSurface,
free_surface_displacement_field

using Adapt
using Base
using KernelAbstractions: @index, @kernel

import Oceananigans.Models.HydrostaticFreeSurfaceModels: initialize_free_surface!,
setup_free_surface!,
materialize_free_surface,
ab2_step_free_surface!,
explicit_barotropic_pressure_x_gradient,
explicit_barotropic_pressure_y_gradient

include("split_explicit_timesteppers.jl")
include("split_explicit_free_surface.jl")
include("distributed_split_explicit_free_surface.jl")
include("setup_split_explicit.jl")
include("step_split_explicit_free_surface.jl")
include("barotropic_correction.jl")

# extend
@inline explicit_barotropic_pressure_x_gradient(i, j, k, grid, ::SplitExplicitFreeSurface) = zero(grid)
@inline explicit_barotropic_pressure_y_gradient(i, j, k, grid, ::SplitExplicitFreeSurface) = zero(grid)

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Kernels to compute the vertical integral of the velocities
@kernel function _barotropic_mode_kernel!(U, V, grid, ::Nothing, u, v)
i, j = @index(Global, NTuple)
barotropic_mode_kernel!(U, V, i, j, grid, u, v)
end

@kernel function _barotropic_mode_kernel!(U, V, grid, active_cells_map, u, v)
idx = @index(Global, Linear)
i, j = active_linear_index_to_tuple(idx, active_cells_map)
barotropic_mode_kernel!(U, V, i, j, grid, u, v)
end

@inline function barotropic_mode_kernel!(U, V, i, j, grid, u, v)
@inbounds U[i, j, 1] = Δzᶠᶜᶜ(i, j, 1, grid) * u[i, j, 1]
@inbounds V[i, j, 1] = Δzᶜᶠᶜ(i, j, 1, grid) * v[i, j, 1]

for k in 2:grid.Nz
@inbounds U[i, j, 1] += Δzᶠᶜᶜ(i, j, k, grid) * u[i, j, k]
@inbounds V[i, j, 1] += Δzᶜᶠᶜ(i, j, k, grid) * v[i, j, k]
end

return nothing
end

@inline function compute_barotropic_mode!(U, V, grid, u, v)
active_cells_map = retrieve_surface_active_cells_map(grid)
launch!(architecture(grid), grid, :xy, _barotropic_mode_kernel!, U, V, grid, active_cells_map, u, v; active_cells_map)
return nothing
end

@kernel function _barotropic_split_explicit_corrector!(u, v, U, V, U̅, V̅, grid)
i, j, k = @index(Global, NTuple)

@inbounds begin
Hᶠᶜ = static_column_depthᶠᶜᵃ(i, j, grid)
Hᶜᶠ = static_column_depthᶜᶠᵃ(i, j, grid)

u[i, j, k] = u[i, j, k] + (U[i, j, 1] - U̅[i, j, 1]) / Hᶠᶜ
v[i, j, k] = v[i, j, k] + (V[i, j, 1] - V̅[i, j, 1]) / Hᶜᶠ
end
end

function barotropic_split_explicit_corrector!(u, v, free_surface, grid)
state = free_surface.filtered_state
U, V = free_surface.barotropic_velocities
U̅, V̅ = state.U, state.V
arch = architecture(grid)

# take out "bad" barotropic mode,
# !!!! reusing U̅ and V̅ for U and V have already been restarted
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does "restarted" mean here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the comment to make it more clear. In practice and have exhausted their scope because we copied the filtered values in U and V, to initialize them for the new subcycling step, so and are used here as "work arrays" to store the vertical integral of u and v

compute_barotropic_mode!(U̅, V̅, grid, u, v)

# add in "good" barotropic mode
launch!(arch, grid, :xyz, _barotropic_split_explicit_corrector!,
u, v, U, V, U̅, V̅, grid)

return nothing
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Oceananigans.Grids: with_halo
using Oceananigans.AbstractOperations: GridMetricOperation, Δz
using Oceananigans.DistributedComputations: DistributedGrid, DistributedField
using Oceananigans.DistributedComputations: SynchronizedDistributed, synchronize_communication!

const DistributedSplitExplicit = SplitExplicitFreeSurface{<:DistributedField}

wait_free_surface_communication!(free_surface, model, arch) = nothing
wait_free_surface_communication!(::DistributedSplitExplicit, model, ::SynchronizedDistributed) = nothing

function wait_free_surface_communication!(free_surface::DistributedSplitExplicit, model, arch)

barotropic_velocities = free_surface.barotropic_velocities

for field in (barotropic_velocities.U, barotropic_velocities.V)
synchronize_communication!(field)
end

Gᵁ = model.timestepper.Gⁿ.U
Gⱽ = model.timestepper.Gⁿ.V

for field in (Gᵁ, Gⱽ)
synchronize_communication!(field)
end

return nothing
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# `initialize_free_surface!` is called at the beginning of the simulation to initialize the free surface state
# from the initial velocity conditions.
function initialize_free_surface!(sefs::SplitExplicitFreeSurface, grid, velocities)
barotropic_velocities = sefs.barotropic_velocities
@apply_regionally compute_barotropic_mode!(barotropic_velocities.U, barotropic_velocities.V, grid, velocities.u, velocities.v)
fill_halo_regions!((barotropic_velocities.U, barotropic_velocities.V))
return nothing
end

# `initialize_free_surface_state!` is called at the beginning of the substepping to
# reset the filtered state to zero and reinitialize the state from the filtered state.
function initialize_free_surface_state!(filtered_state, η, velocities, timestepper)

initialize_free_surface_timestepper!(timestepper, η, velocities)

fill!(filtered_state.η, 0)
fill!(filtered_state.U, 0)
fill!(filtered_state.V, 0)

return nothing
end

# Calculate RHS for the barotropic time step.
@kernel function _compute_integrated_ab2_tendencies!(Gᵁ, Gⱽ, grid, ::Nothing, Gu⁻, Gv⁻, Guⁿ, Gvⁿ, χ)
i, j = @index(Global, NTuple)

@inbounds Gᵁ[i, j, 1] = Δzᶠᶜᶜ(i, j, 1, grid) * ab2_step_Gu(i, j, 1, grid, Gu⁻, Guⁿ, χ)
@inbounds Gⱽ[i, j, 1] = Δzᶜᶠᶜ(i, j, 1, grid) * ab2_step_Gv(i, j, 1, grid, Gv⁻, Gvⁿ, χ)

for k in 2:grid.Nz
@inbounds Gᵁ[i, j, 1] += Δzᶠᶜᶜ(i, j, k, grid) * ab2_step_Gu(i, j, k, grid, Gu⁻, Guⁿ, χ)
@inbounds Gⱽ[i, j, 1] += Δzᶜᶠᶜ(i, j, k, grid) * ab2_step_Gv(i, j, k, grid, Gv⁻, Gvⁿ, χ)
end
end

# Calculate RHS for the barotropic time step.q
@kernel function _compute_integrated_ab2_tendencies!(Gᵁ, Gⱽ, grid, active_cells_map, Gu⁻, Gv⁻, Guⁿ, Gvⁿ, χ)
idx = @index(Global, Linear)
i, j = active_linear_index_to_tuple(idx, active_cells_map)

@inbounds Gᵁ[i, j, 1] = Δzᶠᶜᶜ(i, j, 1, grid) * ab2_step_Gu(i, j, 1, grid, Gu⁻, Guⁿ, χ)
@inbounds Gⱽ[i, j, 1] = Δzᶜᶠᶜ(i, j, 1, grid) * ab2_step_Gv(i, j, 1, grid, Gv⁻, Gvⁿ, χ)

for k in 2:grid.Nz
@inbounds Gᵁ[i, j, 1] += Δzᶠᶜᶜ(i, j, k, grid) * ab2_step_Gu(i, j, k, grid, Gu⁻, Guⁿ, χ)
@inbounds Gⱽ[i, j, 1] += Δzᶜᶠᶜ(i, j, k, grid) * ab2_step_Gv(i, j, k, grid, Gv⁻, Gvⁿ, χ)
end
end

@inline ab2_step_Gu(i, j, k, grid, G⁻, Gⁿ, χ::FT) where FT =
@inbounds ifelse(peripheral_node(i, j, k, grid, f, c, c), zero(grid), (convert(FT, 1.5) + χ) * Gⁿ[i, j, k] - G⁻[i, j, k] * (convert(FT, 0.5) + χ))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these fail when G⁻ has NaNs, even if χ = -0.5. I thought there was another PR that fixed this, but it is either reverted here or that other PR has not been merged (I can't find it...)

Also this function contains 5 or 6 computations on one line. It should be split into multiple lines.


@inline ab2_step_Gv(i, j, k, grid, G⁻, Gⁿ, χ::FT) where FT =
@inbounds ifelse(peripheral_node(i, j, k, grid, c, f, c), zero(grid), (convert(FT, 1.5) + χ) * Gⁿ[i, j, k] - G⁻[i, j, k] * (convert(FT, 0.5) + χ))

# Setting up the RHS for the barotropic step (tendencies of the barotropic velocity components)
# This function is called after `calculate_tendency` and before `ab2_step_velocities!`
function setup_free_surface!(model, ::SplitExplicitFreeSurface, χ)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"setup" may be easy to confuse with "regularize" and "materialize" (that's what I first thought when I saw this).

Maybe "initialize" is better.

Copy link
Collaborator Author

@simone-silvestri simone-silvestri Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In light of this comment I have made an additional change. The setup_free_surface! is basically just calculating the slow tendencies for U and V, so it makes sense to unify it to the compute_free_surface_tendency! that we already have for the ExplicitFreeSurface. However, since we need to do it after the apply_flux_bc! (we need to integrate upwards also the BCs) I have moved the compute_free_surface_tendency! after we apply the BCs to the three-dimensional tendencies


# we start the time integration of η from the average ηⁿ
Gu⁻ = model.timestepper.G⁻.u
Gv⁻ = model.timestepper.G⁻.v
Guⁿ = model.timestepper.Gⁿ.u
Gvⁿ = model.timestepper.Gⁿ.v

GUⁿ = model.timestepper.Gⁿ.U
GVⁿ = model.timestepper.Gⁿ.V

@apply_regionally setup_split_explicit_tendency!(GUⁿ, GVⁿ, model.grid, Gu⁻, Gv⁻, Guⁿ, Gvⁿ, χ)

fields_to_fill = (GUⁿ, GVⁿ)
fill_halo_regions!(fields_to_fill; async = true)

return nothing
end

@inline function setup_split_explicit_tendency!(GUⁿ, GVⁿ, grid, Gu⁻, Gv⁻, Guⁿ, Gvⁿ, χ)
active_cells_map = retrieve_surface_active_cells_map(grid)

launch!(architecture(grid), grid, :xy, _compute_integrated_ab2_tendencies!, GUⁿ, GVⁿ, grid,
active_cells_map, Gu⁻, Gv⁻, Guⁿ, Gvⁿ, χ; active_cells_map)

return nothing
end
Loading