Skip to content

Commit 3122a33

Browse files
Insert updates from PRs #4724, #4743 and #4744
1 parent 15f7f2d commit 3122a33

File tree

6 files changed

+559
-628
lines changed

6 files changed

+559
-628
lines changed

src/Grids/grid_utils.jl

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -329,81 +329,6 @@ coordinate_summary(topo, Δ::Union{AbstractVector, AbstractMatrix}, name) =
329329
@inline column_depthᶜᶠᵃ(i, j, k, grid, η) = static_column_depthᶜᶠᵃ(i, j, grid)
330330
@inline column_depthᶠᶠᵃ(i, j, k, grid, η) = static_column_depthᶠᶠᵃ(i, j, grid)
331331

332-
#####
333-
##### Spherical geometry
334-
#####
335-
336-
"""
337-
spherical_area_triangle(a::Number, b::Number, c::Number)
338-
339-
Return the area of a spherical triangle on the unit sphere with sides `a`, `b`, and `c`.
340-
341-
The area of a spherical triangle on the unit sphere is ``E = A + B + C - π``, where ``A``, ``B``, and ``C``
342-
are the triangle's inner angles.
343-
344-
It has been known since the time of Euler and Lagrange that
345-
``\\tan(E/2) = P / (1 + \\cos a + \\cos b + \\cos c)``, where
346-
``P = (1 - \\cos²a - \\cos²b - \\cos²c + 2 \\cos a \\cos b \\cos c)^{1/2}``.
347-
348-
References
349-
==========
350-
351-
* Euler, L. (1778) De mensura angulorum solidorum, Opera omnia, 26, 204-233 (Orig. in Acta adac. sc. Petrop. 1778)
352-
* Lagrange, J.-L. (1798) Solutions de quilquies problèmes relatifs au triangles sphéruques, Oeuvres, 7, 331-359.
353-
"""
354-
function spherical_area_triangle(a::Number, b::Number, c::Number)
355-
cosa = cos(a)
356-
cosb = cos(b)
357-
cosc = cos(c)
358-
359-
tan½E = sqrt(1 - cosa^2 - cosb^2 - cosc^2 + 2cosa * cosb * cosc)
360-
tan½E /= 1 + cosa + cosb + cosc
361-
362-
return 2atan(tan½E)
363-
end
364-
365-
"""
366-
spherical_area_triangle(a::AbstractVector, b::AbstractVector, c::AbstractVector)
367-
368-
Return the area of a spherical triangle on the unit sphere with vertices given by the 3-vectors
369-
`a`, `b`, and `c` whose origin is the the center of the sphere. The formula was first given by
370-
Eriksson (1990).
371-
372-
If we denote with ``A``, ``B``, and ``C`` the inner angles of the spherical triangle and with
373-
``a``, ``b``, and ``c`` the side of the triangle then, it has been known since Euler and Lagrange
374-
that ``\\tan(E/2) = P / (1 + \\cos a + \\cos b + \\cos c)``, where ``E = A + B + C - π`` is the
375-
triangle's excess and ``P = (1 - \\cos²a - \\cos²b - \\cos²c + 2 \\cos a \\cos b \\cos c)^{1/2}``.
376-
On the unit sphere, ``E`` is precisely the area of the spherical triangle. Erikkson (1990) showed
377-
that ``P`` above is the same as the volume defined by the vectors `a`, `b`, and `c`, that is
378-
``P = |𝐚 \\cdot (𝐛 \\times 𝐜)|``.
379-
380-
References
381-
==========
382-
383-
* Eriksson, F. (1990) On the measure of solid angles, Mathematics Magazine, 63 (3), 184-187, doi:10.1080/0025570X.1990.11977515
384-
"""
385-
function spherical_area_triangle(a₁::AbstractVector, a₂::AbstractVector, a₃::AbstractVector)
386-
(sum(a₁.^2) 1 && sum(a₂.^2) 1 && sum(a₃.^2) 1) || error("a₁, a₂, a₃ must be unit vectors")
387-
388-
tan½E = abs(dot(a₁, cross(a₂, a₃)))
389-
tan½E /= 1 + dot(a₁, a₂) + dot(a₂, a₃) + dot(a₁, a₃)
390-
391-
return 2atan(tan½E)
392-
end
393-
394-
"""
395-
spherical_area_quadrilateral(a₁, a₂, a₃, a₄)
396-
397-
Return the area of a spherical quadrilateral on the unit sphere whose points are given by 3-vectors,
398-
`a`, `b`, `c`, and `d`. The area of the quadrilateral is given as the sum of the ares of the two
399-
non-overlapping triangles. To avoid having to pick the triangles appropriately ensuring they are not
400-
overlapping, we compute the area of the quadrilateral as the half the sum of the areas of all four potential
401-
triangles formed by `a₁`, `a₂`, `a₃`, and `a₄`.
402-
"""
403-
spherical_area_quadrilateral(a::AbstractVector, b::AbstractVector, c::AbstractVector, d::AbstractVector) =
404-
1/2 * (spherical_area_triangle(a, b, c) + spherical_area_triangle(a, b, d) +
405-
spherical_area_triangle(a, c, d) + spherical_area_triangle(b, c, d))
406-
407332
"""
408333
add_halos(data, loc, topo, sz, halo_sz; warnings=true)
409334

src/MultiRegion/multi_region_field.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using Base: @propagate_inbounds
99
import Oceananigans.DistributedComputations: reconstruct_global_field, CommunicationBuffers
1010
import Oceananigans.BoundaryConditions: regularize_field_boundary_conditions
1111
import Oceananigans.Grids: xnodes, ynodes
12-
import Oceananigans.Fields: set!, compute!, compute_at!, validate_field_data, validate_boundary_conditions
12+
import Oceananigans.Fields: set!, compute!, compute_at!, interior, validate_field_data, validate_boundary_conditions
1313
import Oceananigans.Fields: validate_indices, communication_buffers
1414
import Oceananigans.Diagnostics: hasnan
1515

@@ -140,6 +140,16 @@ function compute!(comp::MultiRegionComputedField, time=nothing)
140140
return comp
141141
end
142142

143+
function interior(mrf::MultiRegionField)
144+
@apply_regionally interior_mrf = interior(mrf)
145+
return interior_mrf
146+
end
147+
148+
function interior(mrf::MultiRegionField, I...)
149+
@apply_regionally interior_mrf = interior(mrf, I...)
150+
return interior_mrf
151+
end
152+
143153
@inline hasnan(field::MultiRegionField) = (&)(construct_regionally(hasnan, field).regional_objects...)
144154

145155
validate_indices(indices, loc, mrg::MultiRegionGrids) =

src/MultiRegion/multi_region_grid.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ const MultiRegionGrids{FT, TX, TY, TZ} = Union{MultiRegionGrid{FT, TX, TY, TZ},
3939
@inline Base.lastindex(mrg::MultiRegionGrids) = length(mrg)
4040
number_of_regions(mrg::MultiRegionGrids) = lastindex(mrg)
4141

42+
minimum_xspacing(grid::MultiRegionGrid) =
43+
minimum(minimum_xspacing(grid[r]) for r in 1:number_of_regions(grid))
44+
45+
minimum_yspacing(grid::MultiRegionGrid) =
46+
minimum(minimum_yspacing(grid[r]) for r in 1:number_of_regions(grid))
47+
48+
minimum_zspacing(grid::MultiRegionGrid) =
49+
minimum(minimum_zspacing(grid[r]) for r in 1:number_of_regions(grid))
50+
4251
minimum_xspacing(grid::MultiRegionGrid, ℓx, ℓy, ℓz) =
4352
minimum(minimum_xspacing(grid[r], ℓx, ℓy, ℓz) for r in 1:number_of_regions(grid))
4453

src/OrthogonalSphericalShellGrids/OrthogonalSphericalShellGrids.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export TripolarGrid, RotatedLatitudeLongitudeGrid, ConformalCubedSpherePanelGrid
66
import Oceananigans
77
import Oceananigans.Architectures: on_architecture
88

9+
using CubedSphere
10+
911
using Oceananigans
1012
using Oceananigans.Grids
1113
using Oceananigans.Architectures: device, on_architecture, AbstractArchitecture, CPU, GPU
@@ -15,9 +17,7 @@ using Oceananigans.Utils
1517
using Oceananigans.BoundaryConditions: Zipper
1618
using Oceananigans.Fields: index_binary_search, convert_to_0_360
1719
using Oceananigans.Grids: RightConnected
18-
using Oceananigans.Grids: R_Earth,
19-
halo_size, spherical_area_quadrilateral,
20-
lat_lon_to_cartesian, generate_coordinate, topology
20+
using Oceananigans.Grids: R_Earth, halo_size, lat_lon_to_cartesian, generate_coordinate, topology
2121
using Oceananigans.Grids: total_length, add_halos, fill_metric_halo_regions!
2222

2323
using Oceananigans.Operators

src/OrthogonalSphericalShellGrids/rotated_latitude_longitude_grid.jl

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using CubedSphere
12
using Oceananigans.Grids: LatitudeLongitudeGrid, Bounded
23
using Oceananigans.Utils: KernelParameters
34
using StaticArrays
@@ -58,23 +59,6 @@ function rotate_metrics!(grid, shifted_lat_lon_grid)
5859
return nothing
5960
end
6061

61-
# Convert from Spherical to Cartesian
62-
function spherical_to_cartesian(λ, φ, r=1)
63-
x = r * cos(φ) * cos(λ)
64-
y = r * cos(φ) * sin(λ)
65-
z = r * sin(φ)
66-
return SVector(x, y, z)
67-
end
68-
69-
# Convert from Cartesian to Spherical
70-
function cartesian_to_spherical(X)
71-
x, y, z = X
72-
r = norm(X)
73-
φ = asin(z / r)
74-
λ = atan(y, x)
75-
return λ, φ
76-
end
77-
7862
# Rotation about x-axis by dλ (Change in Longitude)
7963
x_rotation(dλ) = @SMatrix [1 0 0
8064
0 cos(dλ) -sin(dλ)

0 commit comments

Comments
 (0)