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

Momentum dynamics validation on the CubedSphere #3306

Open
wants to merge 179 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 162 commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
53f7fb5
first try for momentum dynamics on cubedsphere
navidcy Oct 4, 2023
c9aa1b3
some cleanup
navidcy Oct 4, 2023
58e0145
second halo pass
simone-silvestri Oct 4, 2023
5d964b2
change name
simone-silvestri Oct 4, 2023
b282ca3
weno momentum advection
navidcy Oct 4, 2023
2bdf043
remove passes = 1:2 from fill_halo_regions!
navidcy Oct 4, 2023
dd35637
add second_fill_halo_pass
navidcy Oct 4, 2023
d8b83c5
fix second_halo_pass! call
navidcy Oct 4, 2023
b3f5e24
more verbose name
navidcy Oct 4, 2023
aeb39ed
Addded steady-state test case from PR #3302
siddharthabishnu Oct 5, 2023
4b22581
fix momentum advection scheme
navidcy Oct 5, 2023
7eec30c
add script to visualize vorticity
navidcy Oct 5, 2023
a1784b4
add vertical scheme in momentum advection
navidcy Oct 5, 2023
4c6f9ee
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
glwagner Oct 7, 2023
c4ca9e9
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
navidcy Oct 11, 2023
cced0d3
visualize vorticity
navidcy Oct 11, 2023
20ed9c4
code cleanup
navidcy Oct 12, 2023
74cc1d3
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
navidcy Oct 12, 2023
99c1e78
Fixed vorticity computation on cubed sphere panel corners
siddharthabishnu Oct 12, 2023
4701920
second_fill_halo_regions_pass -> second_pass_of_fill_halo_regions
navidcy Oct 12, 2023
e5dd568
update vorticity calculation
navidcy Oct 12, 2023
d171972
add vorticity output
navidcy Oct 12, 2023
bb2e248
merge
navidcy Oct 12, 2023
4292835
correct import
navidcy Oct 12, 2023
fde5e2e
back to previous
navidcy Oct 12, 2023
ad15c0e
plot movies
navidcy Oct 12, 2023
746532f
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
navidcy Oct 15, 2023
ae15f9c
attempt to fill correctly the corner halo regions
navidcy Oct 16, 2023
87a5d45
Merge branch 'ncc-glw/cubed-sphere-dynamics' of github.com:CliMA/Ocea…
navidcy Oct 16, 2023
4646a5c
Commented out unnecessary lines of code
siddharthabishnu Oct 16, 2023
0454188
Fixed lower limit of halo indices, compacted code
siddharthabishnu Oct 17, 2023
581fdb9
Filled north-east corner halos
siddharthabishnu Oct 18, 2023
bb28847
Filled south-west corner halos
siddharthabishnu Oct 18, 2023
e6f0d68
Fixed a bug and filled more halos
siddharthabishnu Oct 18, 2023
e3cb76d
Filled remaining halos
siddharthabishnu Oct 19, 2023
51a7d96
Set ζ values to NaN for non-essential halo indices
siddharthabishnu Oct 19, 2023
bb47cf8
Imported change from cubed-sphere-corner-vorticity
siddharthabishnu Oct 19, 2023
8b962b3
don't use short-circuit but ensure operator presedence is taken care of
navidcy Oct 19, 2023
9408a01
add return
navidcy Oct 19, 2023
49ef46f
use solid-body rotation about NP + other tests
navidcy Oct 19, 2023
ff5f208
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
navidcy Oct 19, 2023
689f769
bit of cleanup
navidcy Oct 19, 2023
bea55d6
fix docstrings + more verbose naming
navidcy Oct 20, 2023
ea1b27a
Filled halos in x direction of odd panel corners
siddharthabishnu Oct 24, 2023
355587a
Merge branch 'ncc-glw/cubed-sphere-dynamics' of github.com:CliMA/Ocea…
siddharthabishnu Oct 24, 2023
cf3f03e
Filled halos in x direction of even panel corners
siddharthabishnu Oct 24, 2023
1496f43
alignment
navidcy Oct 24, 2023
5d669bb
remove duplicate
navidcy Oct 24, 2023
b7483e8
adds test u,v
navidcy Oct 24, 2023
e7ac069
Merge branch 'ncc-glw/cubed-sphere-dynamics' of github.com:CliMA/Ocea…
navidcy Oct 24, 2023
a6792f6
sid's changes
navidcy Oct 24, 2023
b481e98
Saved both vorticity and Coriolis parameter
siddharthabishnu Oct 25, 2023
ea9e71f
Fixed minor bug: missing "=" sign
siddharthabishnu Oct 25, 2023
a173d58
Overwrote vorticity computation
siddharthabishnu Oct 26, 2023
e07552a
Some cleanup
siddharthabishnu Oct 26, 2023
21d8520
declutter a bit
navidcy Oct 26, 2023
ed2cd84
sw/nw -> se/ne
navidcy Oct 26, 2023
66222dc
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
simone-silvestri Oct 26, 2023
b4afa0d
attempt to incorporate corner fixes in vorticity calc
navidcy Oct 27, 2023
092f215
some more debugging to figure out what's wrong
navidcy Oct 27, 2023
71ebad3
attempt to fix NE corners of odd panels
navidcy Oct 30, 2023
77354c2
Comparison with MITgcm
siddharthabishnu Nov 2, 2023
0c236de
Plot u, v and Δu, Δv w.r.t. MITgcm
siddharthabishnu Nov 2, 2023
49f90a2
Understand relation between two cubed sphere grids
siddharthabishnu Nov 6, 2023
abb577f
Same grid -> closer MITgcm & Oceananigans outputs
siddharthabishnu Nov 6, 2023
837067d
updates mitgcm comparison script
navidcy Nov 6, 2023
9435af1
add comment about longitude values at the poles
navidcy Nov 6, 2023
b6d833d
Minor changes
siddharthabishnu Nov 6, 2023
842189d
Merge branch 'ncc-glw/cubed-sphere-dynamics' of github.com:CliMA/Ocea…
siddharthabishnu Nov 6, 2023
d064b1f
Compared Azᶜᶜᵃ between MITgcm and Oceananigans
siddharthabishnu Nov 7, 2023
75c3f28
fill velocity halos in update state
navidcy Nov 7, 2023
ac68144
Merge branch 'ncc-glw/cubed-sphere-dynamics' of github.com:CliMA/Ocea…
navidcy Nov 7, 2023
c1fe98d
Added a visualization script for the cubed sphere
siddharthabishnu Nov 14, 2023
f4b9896
Removed 4/3 factor in corner vorticity computation
siddharthabishnu Nov 14, 2023
121e109
Added solid body rotation test case of MITgcm
siddharthabishnu Nov 14, 2023
b910398
Fixed velocity computations in corner halo regions
siddharthabishnu Nov 17, 2023
e25151d
Improved cubed sphere visualization script
siddharthabishnu Nov 17, 2023
9e561b6
Enhanced solid body rotation test case of MITgcm
siddharthabishnu Nov 17, 2023
0bc4142
Imported changes from ss-sb/implicit-free-surface
siddharthabishnu Nov 20, 2023
e358091
Fixed color range bug and renamed functions
siddharthabishnu Nov 22, 2023
0c34873
Filled velocity halos in corner regions
siddharthabishnu Nov 22, 2023
9b50474
Plotted the initial state of additional fields
siddharthabishnu Nov 22, 2023
8bc5508
Commented out debugging code
siddharthabishnu Nov 22, 2023
dbcce8f
Refined vorticity computation script
siddharthabishnu Nov 29, 2023
f73dfd2
Observed NANs on halos, high ζ₀ on boundaries
siddharthabishnu Nov 29, 2023
896fab0
δxᶠᵃᵃ --> δxᶠᶜᶜ and δyᵃᶠᵃ --> δyᶜᶠᶜ
siddharthabishnu Nov 30, 2023
8479281
Simplified vorticity and removed halo fills
siddharthabishnu Dec 7, 2023
fddef06
Reinstated fill halos for the streamfunction
siddharthabishnu Dec 8, 2023
6fe1308
Vorticity at interior points seems reasonable!
siddharthabishnu Dec 12, 2023
cd7e66c
Improved visualization and plotted initial ssh
siddharthabishnu Dec 12, 2023
50d41be
Ran simulation and it still blows up!
siddharthabishnu Dec 12, 2023
b8481e6
Using smaller mesh, constant velocities to debug
siddharthabishnu Dec 15, 2023
ef01019
Considered the option of only one layer of halo
siddharthabishnu Dec 15, 2023
b58b12f
First Implementation of Rossby-Haurwitz Test Case
siddharthabishnu Dec 15, 2023
605f18b
Commented out unnecessary lines, used simpler u, v
siddharthabishnu Dec 15, 2023
fb34b28
Fixed potential error in velocity halo fillings
siddharthabishnu Dec 16, 2023
5c6b2c5
Fixed Δxᶠᶜᵃ and plotted relevant grid metrics
siddharthabishnu Dec 18, 2023
a15b0aa
Fixed metric Δxᶠᶜᵃ[0,Ny+1:Ny+Hy] for even panels
siddharthabishnu Dec 19, 2023
3029997
Grid metric changes in Rossby-Haurwitz test case
siddharthabishnu Dec 19, 2023
693e12d
Ran the Rossby-Haurwitz simulation
siddharthabishnu Dec 19, 2023
0122a10
Reinstated 4/3 factor in ζ computation at corners
siddharthabishnu Dec 20, 2023
3ee51f6
Added option to load cubed_sphere_32_grid.jld2
siddharthabishnu Dec 20, 2023
deb0d8b
Compared metrics Δxᶠᶜᵃ, Δyᶜᶠᵃ, Azᶠᶠᵃ with v0.82.0
siddharthabishnu Dec 21, 2023
9d16534
Fixed a bug in overwriting grid metrics
siddharthabishnu Dec 22, 2023
78da645
Overwrote additional grid metrics with v0.82.0
siddharthabishnu Dec 25, 2023
8dd1417
Overwrote grid metrics from JMC's output file
siddharthabishnu Jan 6, 2024
00cd2b8
First attempt at forward-backward time integrator
siddharthabishnu Jan 9, 2024
dac8db2
Plotted relative difference of grid metrics
siddharthabishnu Jan 10, 2024
f604c6c
Fixed a bug in cubed sphere visualization script
siddharthabishnu Jan 13, 2024
3d5ea90
Customized Rossby-Haurwitz visualization options
siddharthabishnu Jan 13, 2024
42436d7
Added simplified initial velocity for debugging
siddharthabishnu Jan 17, 2024
769e357
FWB with AB2 for velocity FW for free surface
simone-silvestri Jan 17, 2024
96e4241
Added tests to verify halo vorticity computation
siddharthabishnu Jan 17, 2024
2c1e39a
replace "fill_velocity_halos" with simple code
jm-c Jan 18, 2024
7935d43
Fixed bug associated with AB2-FB time integrator
siddharthabishnu Jan 19, 2024
212fc16
Add Coriolis
jm-c Jan 20, 2024
dc6b4ac
Overwrote lat-lon values from JMC's output file
siddharthabishnu Jan 23, 2024
50d4381
Added new test function for cubed sphere
siddharthabishnu Jan 24, 2024
6a000e5
Updated Rossby-Haurwitz simulation script
siddharthabishnu Jan 26, 2024
54ba43d
fix typo
jm-c Jan 31, 2024
f7cd926
tweaks fill_velocity_halos for high-order scheme
jm-c Jan 31, 2024
cff9e5e
fix previous commit for case Hx > 2
jm-c Jan 31, 2024
4fbd188
Needed just for the hacked FB+AB2 to work
jm-c Feb 2, 2024
1bba4ec
Deeper ocean + remove global-mean from initial Eta
jm-c Feb 2, 2024
499ffd3
Changes to get consistent initial velocity
jm-c Feb 2, 2024
35ec029
Same function to fill halos for u, v, grid metrics
siddharthabishnu Feb 7, 2024
bee9fcd
Disabled option to employ MITgcm's grid metrics
siddharthabishnu Feb 9, 2024
8351eec
Refactored function and variable names
siddharthabishnu Feb 9, 2024
eb990ac
horizontal_closure = nothing for Rossby-Haurwitz
siddharthabishnu Feb 9, 2024
4c32749
Fixed a major bug and cleaned up code
siddharthabishnu Feb 9, 2024
9b50d93
Bickley jet simulation on the cubed sphere
siddharthabishnu Feb 10, 2024
9c099ee
Minor modification
siddharthabishnu Feb 10, 2024
187e631
Initial condition: f(λ,φ,z) instead of f(x,y,z)
siddharthabishnu Feb 11, 2024
bbede50
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
navidcy Feb 11, 2024
391789a
Fixed bugs and enhanced Bickley jet test case
siddharthabishnu Feb 13, 2024
16ba6e4
remove unneded DataDeps
navidcy Feb 13, 2024
558d93f
nHalo -> Nhalo
navidcy Feb 13, 2024
d85a2d2
Clean code with better Bickley jet initialization
siddharthabishnu Feb 13, 2024
6993302
Refined the script multi_region_cubed_sphere.jl
siddharthabishnu Feb 16, 2024
b478a1d
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
navidcy Feb 28, 2024
3e19e8a
Renamed files and added information on Imaginocean
siddharthabishnu Feb 28, 2024
e4420c2
Added a function to plot fields on the sphere
siddharthabishnu Feb 28, 2024
35d1a69
Enhanced Rossby-Haurwitz wave validation script
siddharthabishnu Feb 28, 2024
010d4ab
Merge branch 'main' into ncc-glw/cubed-sphere-dynamics
navidcy Feb 29, 2024
9897096
Enhanced Bickley jet validation script
siddharthabishnu Feb 29, 2024
941260f
Improved cubed sphere visualization and bug fix
siddharthabishnu Mar 1, 2024
f86278e
Saved output to file, η w.r.t. surface, fixed bugs
siddharthabishnu Mar 4, 2024
930b915
Default comparison of old and new metrics disabled
siddharthabishnu Mar 5, 2024
b05b709
Printed MITgcm grid metrics to jld2 file
siddharthabishnu Mar 7, 2024
532df46
Inserted single EOL at the end of files
siddharthabishnu Mar 7, 2024
9ec9f54
Exported Δxᶜᶜᵃ, Δyᶜᶜᵃ, Δxᶠᶠᵃ, Δyᶠᶠᵃ to jld2 file
siddharthabishnu Mar 8, 2024
1f27841
Exported metrics of 4x4x1 cs grid to jld2 file
siddharthabishnu Mar 13, 2024
b9197c8
Made minor modifications suggested by Navid
siddharthabishnu Mar 19, 2024
2f29cca
Merge remote-tracking branch 'origin/main' into cubed-sphere-dynamics
siddharthabishnu Apr 4, 2024
01a1afc
Replace scripts with main branch equivalents
siddharthabishnu Apr 4, 2024
5b8fc15
Redefine "view" to take ssh into consideration
siddharthabishnu Apr 6, 2024
07fa4ef
Update validation scripts
siddharthabishnu Apr 6, 2024
67e212d
Fix error in accessing size of a multiregion field
siddharthabishnu Apr 13, 2024
5161be1
Loop only over interior z points to fill halos
siddharthabishnu Apr 13, 2024
37e66e2
Fix major bug
siddharthabishnu Apr 16, 2024
1b1ec0a
Fill cubed sphere velocity halos only once
siddharthabishnu Apr 17, 2024
f3d2a5d
add comment
navidcy Apr 17, 2024
22d5a37
Apply suggestions from code review
navidcy Apr 17, 2024
c24a936
Print initial condition and Azᶠᶠᵃ to output file
siddharthabishnu Apr 17, 2024
42c37cf
Apply suggestions from code review
navidcy Apr 18, 2024
43e970a
Set g = 10, H = 1000, r = 6370e3 for Bickley jet
siddharthabishnu Apr 21, 2024
2ea3bbd
Delete cs validation scripts no longer used
siddharthabishnu Apr 22, 2024
1f99f74
Delete replace_horizontal_vector_halos!
siddharthabishnu Apr 22, 2024
2406d2c
Revert modifications in validation/bickley_jet
siddharthabishnu Apr 22, 2024
03bdefc
Refine cubed sphere Bickley jet validation script
siddharthabishnu Apr 22, 2024
8c9ca4e
Further modify cubed sphere Bickley jet test case
siddharthabishnu Apr 24, 2024
cdd742d
Improve visualization of cs validation test cases
siddharthabishnu Apr 25, 2024
0447313
Remove MITgcm data visualization functions
siddharthabishnu Apr 29, 2024
fa1868c
Refine Bickley jet validation script
siddharthabishnu Apr 29, 2024
6868203
Compact multiple cubed sphere validation scripts
siddharthabishnu Apr 30, 2024
f66153b
Rename cs solid body rotation validation script
siddharthabishnu Apr 30, 2024
204933f
Remove commented-out deprecated code
siddharthabishnu Apr 30, 2024
5e1d5a9
Fix Rossby-Haurwitz wave initial streamfunction
siddharthabishnu May 2, 2024
659b1b2
Compact cubed sphere validation scripts
siddharthabishnu May 2, 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
4 changes: 4 additions & 0 deletions src/Fields/field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ function offset_windowed_data(data, Loc, grid, indices)
windowed_parent = parent(data)
else
parent_indices = map(parent_index_range, indices, loc, topo, halo)
if size(data)[3] == 1 && first.(axes(data))[3] == grid.Nz + 1 # take ssh into consideration
parent_indices = collect(parent_indices)
parent_indices[3] = 1:1
end
Comment on lines +248 to +251
Copy link
Collaborator Author

@navidcy navidcy Apr 17, 2024

Choose a reason for hiding this comment

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

this reads like a hack..

also, what's "ssh" mentioned in the comment?

what if size(data)[2] == 1... then nothing needs to happen?

Copy link
Contributor

@siddharthabishnu siddharthabishnu May 1, 2024

Choose a reason for hiding this comment

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

Yes, it is a temporary hack. I have outlined the issue arising in the absence of this hack in issue #3572 and created PR #3573 to resolve it. In the comment, ssh refers to fields like ssh defined on the xy plane, for which the parent array takes the z-halo into consideration even though it does not exist. In case of a field like the meridional average of a scalar quantity which is defined on the xz plane, the same issue arises without an equivalent hack.

windowed_parent = view(parent(data), parent_indices...)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ const ExplicitFreeSurfaceHFSM = HFSM{<:Any, <:Any, <:Any, <:ExplicitFreeSur
const ImplicitFreeSurfaceHFSM = HFSM{<:Any, <:Any, <:Any, <:ImplicitFreeSurface}
const SplitExplicitFreeSurfaceHFSM = HFSM{<:Any, <:Any, <:Any, <:SplitExplicitFreeSurface}

#=
pressure_correct_velocities!(model::ExplicitFreeSurfaceHFSM, Δt; kwargs...) = nothing
=#

#####
##### Barotropic pressure correction for models with a free surface
#####

function pressure_correct_velocities!(model::ImplicitFreeSurfaceHFSM, Δt)

function pressure_correct_velocities!(model::Union{ImplicitFreeSurfaceHFSM, ExplicitFreeSurfaceHFSM}, Δt)
launch!(model.architecture, model.grid, :xyz,
_barotropic_pressure_correction,
model.velocities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ explicit_ab2_step_free_surface!(free_surface, model, Δt, χ) =
i, j = @index(Global, NTuple)

@inbounds begin
η[i, j, Nz+1] += Δt * ((FT(1.5) + χ) * Gηⁿ[i, j, Nz+1] - (FT(0.5) + χ) * Gη⁻[i, j, Nz+1])
# AB2 for η
# η[i, j, Nz+1] += Δt * ((FT(1.5) + χ) * Gηⁿ[i, j, Nz+1] - (FT(0.5) + χ) * Gη⁻[i, j, Nz+1])
# FW for η
η[i, j, Nz+1] += Δt * Gηⁿ[i, j, Nz+1]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ implicitly during time-stepping.
model_fields = merge(hydrostatic_fields(velocities, free_surface, tracers), auxiliary_fields)

return ( - U_dot_∇u(i, j, k, grid, advection, velocities)
#=
- explicit_barotropic_pressure_x_gradient(i, j, k, grid, free_surface)
=#
- x_f_cross_U(i, j, k, grid, coriolis, velocities)
- ∂xᶠᶜᶜ(i, j, k, grid, hydrostatic_pressure_anomaly)
- ∂ⱼ_τ₁ⱼ(i, j, k, grid, closure, diffusivities, clock, model_fields, buoyancy)
Expand Down Expand Up @@ -83,7 +85,9 @@ implicitly during time-stepping.
model_fields = merge(hydrostatic_fields(velocities, free_surface, tracers), auxiliary_fields)

return ( - U_dot_∇v(i, j, k, grid, advection, velocities)
#=
- explicit_barotropic_pressure_y_gradient(i, j, k, grid, free_surface)
=#
- y_f_cross_U(i, j, k, grid, coriolis, velocities)
- ∂yᶜᶠᶜ(i, j, k, grid, hydrostatic_pressure_anomaly)
- ∂ⱼ_τ₂ⱼ(i, j, k, grid, closure, diffusivities, clock, model_fields, buoyancy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ using Oceananigans.Architectures
using Oceananigans.Grids: with_halo, isrectilinear, halo_size
using Oceananigans.Architectures: device

import Oceananigans.Solvers: solve!, precondition!
using Oceananigans.Fields: replace_horizontal_vector_halos!

import Oceananigans.Solvers: solve!, precondition!, auxiliary_actions!
import Oceananigans.Architectures: architecture
navidcy marked this conversation as resolved.
Show resolved Hide resolved

"""
Expand Down Expand Up @@ -50,7 +52,14 @@ function PCGImplicitFreeSurfaceSolver(grid::AbstractGrid, settings, gravitationa
vertically_integrated_lateral_areas = (xᶠᶜᶜ = ∫ᶻ_Axᶠᶜᶜ, yᶜᶠᶜ = ∫ᶻ_Ayᶜᶠᶜ)

@apply_regionally compute_vertically_integrated_lateral_areas!(vertically_integrated_lateral_areas)
fill_halo_regions!(vertically_integrated_lateral_areas)

u = vertically_integrated_lateral_areas.xᶠᶜᶜ
v = vertically_integrated_lateral_areas.yᶜᶠᶜ

for _ in 1:3
fill_halo_regions!(vertically_integrated_lateral_areas)
@apply_regionally replace_horizontal_vector_halos!((; u, v, w = nothing), grid, signed = false)
end

# Set some defaults
settings = Dict{Symbol, Any}(settings)
Expand Down Expand Up @@ -136,14 +145,17 @@ function implicit_free_surface_linear_operation!(L_ηⁿ⁺¹, ηⁿ⁺¹, ∫

# Note: because of `fill_halo_regions!` below, we cannot use `PCGImplicitFreeSurface` on a
# multi-region grid; `fill_halo_regions!` cannot be used within `@apply_regionally`
fill_halo_regions!(ηⁿ⁺¹)

launch!(arch, grid, :xy, _implicit_free_surface_linear_operation!,
L_ηⁿ⁺¹, grid, ηⁿ⁺¹, ∫ᶻ_Axᶠᶜᶜ, ∫ᶻ_Ayᶜᶠᶜ, g, Δt)

return nothing
end

ImplicitFreeSurfaceOperation = typeof(implicit_free_surface_linear_operation!)

auxiliary_actions!(::ImplicitFreeSurfaceOperation, L_ηⁿ⁺¹, ηⁿ⁺¹, args...) = fill_halo_regions!(ηⁿ⁺¹)

# Kernels that act on vertically integrated / surface quantities
@inline ∫ᶻ_Ax_∂x_ηᶠᶜᶜ(i, j, k, grid, ∫ᶻ_Axᶠᶜᶜ, η) = @inbounds ∫ᶻ_Axᶠᶜᶜ[i, j, k] * ∂xᶠᶜᶠ(i, j, k, grid, η)
@inline ∫ᶻ_Ay_∂y_ηᶜᶠᶜ(i, j, k, grid, ∫ᶻ_Ayᶜᶠᶜ, η) = @inbounds ∫ᶻ_Ayᶜᶠᶜ[i, j, k] * ∂yᶜᶠᶠ(i, j, k, grid, η)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function update_state!(model::HydrostaticFreeSurfaceModel, grid, callbacks; comp
@apply_regionally update_model_field_time_series!(model, model.clock)

fill_halo_regions!(prognostic_fields(model), model.clock, fields(model); async = true)
#=
@apply_regionally replace_horizontal_vector_halos!(model.velocities, model.grid)
=#
grid isa ConformalCubedSphereGrid ? fill_halo_regions!((model.velocities.u, model.velocities.v)) : nothing
@apply_regionally compute_auxiliaries!(model)

fill_halo_regions!(model.diffusivity_fields; only_local_halos = true)
Expand Down
44 changes: 28 additions & 16 deletions src/MultiRegion/cubed_sphere_boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
function fill_halo_regions!(field::CubedSphereField{<:Center, <:Center})
grid = field.grid

Nx, Ny, Nz = size(grid)
Nx, Ny, Nz = size(field)
Hx, Hy, Hz = halo_size(grid)

Nx == Ny || error("horizontal grid size Nx and Ny must be the same")
Expand All @@ -32,14 +32,20 @@ function fill_halo_regions!(field::CubedSphereField{<:Center, <:Center})
Hx == Hy || error("horizontal halo size Hx and Hy must be the same")
Hc = Hx

if size(field[1].data)[3] == 1 && first.(axes(field[1].data))[3] == grid.Nz + 1 # take ssh into consideration
k_min, k_max = Nz+1, Nz+1
else
k_min, k_max = 1, Nz
end

#-- one pass: only use interior-point values:
for region in 1:6

region_E, region_N, region_W, region_S = find_neighboring_panels(grid, region)

if isodd(region)
#- odd face number (1, 3, 5):
for k in -Hz+1:Nz+Hz
for k in k_min:k_max
#- E + W Halo for field:
field[region][Nc+1:Nc+Hc, 1:Nc, k] .= field[region_E][1:Hc, 1:Nc, k]
field[region][1-Hc:0, 1:Nc, k] .= reverse(field[region_W][1:Nc, Nc+1-Hc:Nc, k], dims=1)'
Expand All @@ -49,7 +55,7 @@ function fill_halo_regions!(field::CubedSphereField{<:Center, <:Center})
end
elseif iseven(region)
#- even face number (2, 4, 6):
for k in -Hz+1:Nz+Hz
for k in k_min:k_max
#- E + W Halo for field:
field[region][Nc+1:Nc+Hc, 1:Nc, k] .= reverse(field[region_E][1:Nc, 1:Hc, k], dims=1)'
field[region][1-Hc:0, 1:Nc, k] .= field[region_W][Nc+1-Hc:Nc, 1:Nc, k]
Expand All @@ -63,10 +69,16 @@ function fill_halo_regions!(field::CubedSphereField{<:Center, <:Center})
return nothing
end

# Halos have to be filled concurrently for pairs of XFaced and YFaced Fields, like `u` and `v`.
# Therefore, e.g., fill_halo_regions!(u) should do nothing and the halos for `u` and `v` are filed
# via fill_halo_regions!((u, v))
fill_halo_regions!(field::CubedSphereField{<:Face, <:Center}) = nothing
fill_halo_regions!(field::CubedSphereField{<:Center, <:Face}) = nothing

function fill_halo_regions!(field::CubedSphereField{<:Face, <:Face})
grid = field.grid

Nx, Ny, Nz = size(grid)
Nx, Ny, Nz = size(field)
Hx, Hy, Hz = halo_size(grid)

Nx == Ny || error("horizontal grid size Nx and Ny must be the same")
Expand All @@ -82,7 +94,7 @@ function fill_halo_regions!(field::CubedSphereField{<:Face, <:Face})

if isodd(region)
#- odd face number (1, 3, 5):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E + W Halo for field:
field[region][Nc+1:Nc+Hc, 1:Nc, k] .= field[region_E][1:Hc, 1:Nc, k]
field[region][1-Hc:0, 2:Nc+1, k] .= reverse(field[region_W][1:Nc, Nc+1-Hc:Nc, k], dims=1)'
Expand All @@ -99,7 +111,7 @@ function fill_halo_regions!(field::CubedSphereField{<:Face, <:Face})
end
elseif iseven(region)
#- even face number (2, 4, 6):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E + W Halo for field:
field[region][Nc+1:Nc+Hc, 2:Nc, k] .= reverse(field[region_E][2:Nc, 1:Hc, k], dims=1)'
if Hc > 1
Expand Down Expand Up @@ -128,7 +140,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Center, <:Center},
field_1.grid == field_2.grid || error("fields must be on the same grid")
grid = field_1.grid

Nx, Ny, Nz = size(grid)
Nx, Ny, Nz = size(field_1)
Hx, Hy, Hz = halo_size(grid)
signed ? plmn = -1 : plmn = 1

Expand All @@ -145,7 +157,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Center, <:Center},

if isodd(region)
#- odd face number (1, 3, 5):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E Halo:
field_1[region][Nc+1:Nc+Hc, 1:Nc, k] .= field_1[region_E][1:Hc, 1:Nc, k]
field_2[region][Nc+1:Nc+Hc, 1:Nc, k] .= field_2[region_E][1:Hc, 1:Nc, k]
Expand All @@ -161,7 +173,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Center, <:Center},
end
elseif iseven(region)
#- even face number (2, 4, 6):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E Halo:
field_1[region][Nc+1:Nc+Hc, 1:Nc, k] .= reverse(field_2[region_E][1:Nc, 1:Hc, k], dims=1)'
field_2[region][Nc+1:Nc+Hc, 1:Nc, k] .= reverse(field_1[region_E][1:Nc, 1:Hc, k], dims=1)' * plmn
Expand All @@ -187,7 +199,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Face, <:Center},
field_1.grid == field_2.grid || error("fields must be on the same grid")
grid = field_1.grid

Nx, Ny, Nz = size(grid)
Nx, Ny, Nz = size(field_1)
Hx, Hy, Hz = halo_size(grid)
signed ? plmn = -1 : plmn = 1

Expand All @@ -204,7 +216,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Face, <:Center},

if isodd(region)
#- odd face number (1, 3, 5):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E + W Halo for field_1:
field_1[region][Nc+1:Nc+Hc, 1:Nc, k] .= field_1[region_E][1:Hc, 1:Nc, k]
field_1[region][1-Hc:0, 1:Nc, k] .= reverse(field_2[region_W][1:Nc, Nc+1-Hc:Nc, k], dims=1)'
Expand All @@ -224,7 +236,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Face, <:Center},
end
elseif iseven(region)
#- even face number (2, 4, 6):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E + W Halo for field_1:
field_1[region][Nc+1:Nc+Hc, 1:Nc, k] .= reverse(field_2[region_E][1:Nc, 1:Hc, k], dims=1)'
field_1[region][1-Hc:0, 1:Nc, k] .= field_1[region_W][Nc+1-Hc:Nc, 1:Nc, k]
Expand All @@ -249,7 +261,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Face, <:Center},
# (e.g., vort3(0,1) & (1,0)).
if Hc > 1
for region in 1:6
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- SW corner:
field_1[region][1-Hc:0, 0, k] .= field_2[region][1, 1-Hc:0, k]
field_2[region][0, 1-Hc:0, k] .= field_1[region][1-Hc:0, 1, k]'
Expand All @@ -275,7 +287,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Face, <:Face},
field_1.grid == field_2.grid || error("fields must be on the same grid")
grid = field_1.grid

Nx, Ny, Nz = size(grid)
Nx, Ny, Nz = size(field_1)
Hx, Hy, Hz = halo_size(grid)
signed ? plmn = -1 : plmn = 1

Expand All @@ -292,7 +304,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Face, <:Face},

if isodd(region)
#- odd face number (1, 3, 5):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E Halo:
field_1[region][Nc+1:Nc+Hc, 1:Nc, k] .= field_1[region_E][1:Hc, 1:Nc, k]
field_2[region][Nc+1:Nc+Hc, 1:Nc, k] .= field_2[region_E][1:Hc, 1:Nc, k]
Expand All @@ -318,7 +330,7 @@ function fill_halo_regions!(field_1::CubedSphereField{<:Face, <:Face},
end
else
#- even face number (2, 4, 6):
for k in -Hz+1:Nz+Hz
for k in 1:Nz
#- E Halo:
field_1[region][Nc+1:Nc+Hc, 2:Nc, k] .= reverse(field_2[region_E][2:Nc, 1:Hc, k], dims=1)'
field_2[region][Nc+1:Nc+Hc, 2:Nc+1, k] .= reverse(field_1[region_E][1:Nc, 1:Hc, k], dims=1)' * plmn
Expand Down
2 changes: 1 addition & 1 deletion src/MultiRegion/multi_region_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const GriddedMultiRegionFieldTuple{N, T} = NTuple{N, T} where {N, T<:GriddedMult
const GriddedMultiRegionFieldNamedTuple{S, N} = NamedTuple{S, N} where {S, N<:GriddedMultiRegionFieldTuple}

# Utils
Base.size(f::GriddedMultiRegionField) = size(getregion(f.grid, 1))
Base.size(f::GriddedMultiRegionField) = size(getregion(f, 1))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice catch


@inline isregional(f::GriddedMultiRegionField) = true
@inline devices(f::GriddedMultiRegionField) = devices(f.grid)
Expand Down
2 changes: 2 additions & 0 deletions src/MultiRegion/unified_implicit_free_surface_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ build_implicit_step_solver(::Val{:PreconditionedConjugateGradient}, grid::MultiR
throw(ArgumentError("Cannot use PCG solver with Multi-region grids!! Select :Default or :HeptadiagonalIterativeSolver as solver_method"))
build_implicit_step_solver(::Val{:Default}, grid::ConformalCubedSphereGrid, settings, gravitational_acceleration) =
PCGImplicitFreeSurfaceSolver(grid, settings, gravitational_acceleration)
build_implicit_step_solver(::Val{:PreconditionedConjugateGradient}, grid::ConformalCubedSphereGrid, settings, gravitational_acceleration) =
PCGImplicitFreeSurfaceSolver(grid, settings, gravitational_acceleration)
build_implicit_step_solver(::Val{:HeptadiagonalIterativeSolver}, grid::ConformalCubedSphereGrid, settings, gravitational_acceleration) =
throw(ArgumentError("Cannot use Matrix solvers with ConformalCubedSphereGrid!! Select :Default or :PreconditionedConjugateGradient as solver_method"))

Expand Down
58 changes: 36 additions & 22 deletions src/Operators/vorticity_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
ζ₃ᶠᶠᶜ(i, j, k, grid, u, v)

The vertical vorticity associated with horizontal velocities ``u`` and ``v``.
navidcy marked this conversation as resolved.
Show resolved Hide resolved
"""
"""
@inline ζ₃ᶠᶠᶜ(i, j, k, grid, u, v) = Γᶠᶠᶜ(i, j, k, grid, u, v) / Azᶠᶠᶜ(i, j, k, grid)

@inline function ζ₃ᶠᶠᶜ(i, j, k, grid::OrthogonalSphericalShellGrid{FT}, u, v) where FT
scaling = ifelse(on_corner(i, j, grid), convert(FT, 1), 1)
return scaling * Γᶠᶠᶜ(i, j, k, grid, u, v) / Azᶠᶠᶜ(i, j, k, grid)
end

# Corner
@inline on_corner(i, j, grid) = on_south_west_corner(i, j, grid) | on_south_east_corner(i, j, grid) | on_north_west_corner(i, j, grid) | on_north_east_corner(i, j, grid)

# South-west, south-east, north-west, north-east corners
@inline on_south_west_corner(i, j, grid) = (i == 1 && j == 1)
@inline on_south_east_corner(i, j, grid) = (i == grid.Nx+1 && j == 1)
@inline on_north_east_corner(i, j, grid) = (i == grid.Nx+1 && j == grid.Ny+1)
@inline on_north_west_corner(i, j, grid) = (i == 1 && j == grid.Ny+1)

#####
##### Vertical circulation at the corners of the cubed sphere needs to treated in a special manner.
##### See: https://github.com/CliMA/Oceananigans.jl/issues/1584
Expand All @@ -17,26 +31,26 @@
Γᶠᶠᶜ(i, j, k, grid, u, v)

The vertical circulation associated with horizontal velocities ``u`` and ``v``.
navidcy marked this conversation as resolved.
Show resolved Hide resolved
"""
@inline function Γᶠᶠᶜ(i, j, k, grid::OrthogonalSphericalShellGrid, u, v)
# South-west corner
if i == 1 && j == 1
return Δy_qᶜᶠᶜ(i, j, k, grid, v) - Δx_qᶠᶜᶜ(i, j, k, grid, u) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u)

# South-east corner
elseif i == grid.Nx+1 && j == 1
return - Δy_qᶜᶠᶜ(i-1, j, k, grid, v) - Δx_qᶠᶜᶜ(i, j, k, grid, u) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u)

# North-west corner
elseif i == 1 && j == grid.Ny+1
return Δy_qᶜᶠᶜ(i, j, k, grid, v) - Δx_qᶠᶜᶜ(i, j, k, grid, u) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u)

# North-east corner
elseif i == grid.Nx+1 && j == grid.Ny+1
return - Δy_qᶜᶠᶜ(i-1, j, k, grid, v) - Δx_qᶠᶜᶜ(i, j, k, grid, u) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u)

# Not a corner
"""
#=
@inline Γᶠᶠᶜ(i, j, k, grid::OrthogonalSphericalShellGrid, u, v) =
ifelse(on_south_west_corner(i, j, grid) | on_north_west_corner(i, j, grid),
Δy_qᶜᶠᶜ(i, j, k, grid, v) - Δx_qᶠᶜᶜ(i, j, k, grid, u) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u),
ifelse(on_south_east_corner(i, j, grid) | on_north_east_corner(i, j, grid),
- Δy_qᶜᶠᶜ(i-1, j, k, grid, v) - Δx_qᶠᶜᶜ(i, j, k, grid, u) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u),
δxᶠᶜᶜ(i, j, k, grid, Δy_qᶜᶠᶜ, v) - δyᶜᶠᶜ(i, j, k, grid, Δx_qᶠᶜᶜ, u)))
=#

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is this old/deprecated code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. I will delete it.

function Γᶠᶠᶜ(i, j, k, grid::OrthogonalSphericalShellGrid, u, v)
Hx, Hy = grid.Hx, grid.Hy
if i == 1 - Hx || j == 1 - Hy
Γ = NaN
elseif on_south_west_corner(i, j, grid) || on_north_west_corner(i, j, grid)
Γ = Δy_qᶜᶠᶜ(i, j, k, grid, v) - Δx_qᶠᶜᶜ(i, j, k, grid, u) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u)
elseif on_south_east_corner(i, j, grid) || on_north_east_corner(i, j, grid)
Γ = - Δy_qᶜᶠᶜ(i-1, j, k, grid, v) + Δx_qᶠᶜᶜ(i, j-1, k, grid, u) - Δx_qᶠᶜᶜ(i, j, k, grid, u)
else
return δxᶠᵃᵃ(i, j, k, grid, Δy_qᶜᶠᶜ, v) - δyᵃᶠᵃ(i, j, k, grid, Δx_qᶠᶜᶜ, u)
Γ = δxᶠᶠᶜ(i, j, k, grid, Δy_qᶜᶠᶜ, v) - δyᶠᶠᶜ(i, j, k, grid, Δx_qᶠᶜᶜ, u)
end
end
return Γ
end
navidcy marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions src/Solvers/preconditioned_conjugate_gradient_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ function iterate!(x, solver, b, args...)

@apply_regionally perform_iteration!(q, p, ρ, z, solver, args...)

auxiliary_actions!(solver.linear_operation!, q, p, args...)

@apply_regionally solver.linear_operation!(q, p, args...)

α = ρ / dot(p, q)

@debug "PreconditionedConjugateGradientSolver $(solver.iteration), |q|: $(norm(q))"
Expand All @@ -208,6 +212,8 @@ function iterate!(x, solver, b, args...)
return nothing
end

auxiliary_actions!(args...) = nothing

""" first iteration of the PCG """
function initialize_solution!(q, x, b, solver, args...)
solver.linear_operation!(q, x, args...)
Expand Down
Loading