@@ -13,8 +13,8 @@ coordinate system associated with the domain, to the coordinate system _intrinsi
13
13
14
14
_extrinsic_ coordinate systems are:
15
15
16
- - Cartesian for any grid that discretizes a Cartesian domain (e.g. a `RectilinearGrid`)
17
- - Geographic coordinates for any grid that discretizes a Spherical domain (e.g. an `AbstractCurvilinearGrid`)
16
+ - Cartesian coordinates for any grid that discretizes a cartesian domain (e.g. a `RectilinearGrid`)
17
+ - Geographic coordinates for any grid that discretizes a spherical domain (e.g. an `AbstractCurvilinearGrid`)
18
18
19
19
Therefore, for the [`RectilinearGrid`](@ref) and the [`LatitudeLongitudeGrid`](@ref), the _extrinsic_ and the
20
20
_intrinsic_ coordinate system are equivalent. However, for other grids (e.g., for the
@@ -31,8 +31,8 @@ system of the grid, to the _extrinsic_ coordinate system associated with the dom
31
31
32
32
_extrinsic_ coordinate systems are:
33
33
34
- - Cartesian for any grid that discretizes a Cartesian domain (e.g. a `RectilinearGrid`)
35
- - Geographic coordinates for any grid that discretizes a Spherical domain (e.g. an `AbstractCurvilinearGrid`)
34
+ - Cartesian coordinates for any grid that discretizes a cartesian domain (e.g. a `RectilinearGrid`)
35
+ - Geographic coordinates for any grid that discretizes a spherical domain (e.g. an `AbstractCurvilinearGrid`)
36
36
37
37
Therefore, for the [`RectilinearGrid`](@ref) and the [`LatitudeLongitudeGrid`](@ref), the _extrinsic_ and the
38
38
_intrinsic_ coordinate systems are equivalent. However, for other grids (e.g., for the
@@ -48,14 +48,15 @@ _intrinsic_ coordinate systems are equivalent. However, for other grids (e.g., f
48
48
@inline extrinsic_vector (i, j, k, grid:: AbstractGrid , uᵢ, vᵢ) =
49
49
getvalue (uᵢ, i, j, k, grid), getvalue (vᵢ, i, j, k, grid)
50
50
51
- # Intrinsic and extrinsic conversion for `OrthogonalSphericalShellGrid`s,
52
- # i.e. curvilinear grids defined on a sphere which are locally orthogonal.
53
- # If the coordinates match with the coordinates of a latitude-longitude grid
54
- # (i.e. globally orthogonal), these functions collapse to
55
- # uₑ, vₑ, wₑ = uᵢ, vᵢ, wᵢ
56
51
57
- # 2D vectors
58
- @inline function intrinsic_vector (i, j, k, grid:: OrthogonalSphericalShellGrid , uₑ, vₑ)
52
+ """
53
+ rotation_angle(i, j, grid::OrthogonalSphericalShellGrid)
54
+
55
+ Return the rotation angle (in degrees) of the `i, j`-th point of the `grid`.
56
+ The rotation angle is the angle (positive counter-clockwise) that we need to rotate
57
+ the grid's intrinsic coordinates in order to match the grid's extrinsic coordinates.
58
+ """
59
+ @inline function rotation_angle (i, j, grid:: OrthogonalSphericalShellGrid )
59
60
60
61
φᶠᶠᵃ⁺⁺ = φnode (i+ 1 , j+ 1 , 1 , grid, Face (), Face (), Center ())
61
62
φᶠᶠᵃ⁺⁻ = φnode (i+ 1 , j, 1 , grid, Face (), Face (), Center ())
@@ -67,21 +68,40 @@ _intrinsic_ coordinate systems are equivalent. However, for other grids (e.g., f
67
68
Δxᶜᶠᵃ⁺ = Δxᶜᶠᶜ (i, j+ 1 , 1 , grid)
68
69
Δxᶜᶠᵃ⁻ = Δxᶜᶠᶜ (i, j, 1 , grid)
69
70
70
- # θᵢ is the rotation angle between intrinsic and extrinsic reference frame
71
- Rcosθ = (deg2rad (φᶠᶠᵃ⁺⁺ - φᶠᶠᵃ⁺⁻) / Δyᶠᶜᵃ⁺ + deg2rad (φᶠᶠᵃ⁻⁺ - φᶠᶠᵃ⁻⁻) / Δyᶠᶜᵃ⁻) / 2
71
+ Rcosθ₁ = ifelse (Δyᶠᶜᵃ⁺ == 0 , zero (grid), deg2rad (φᶠᶠᵃ⁺⁺ - φᶠᶠᵃ⁺⁻) / Δyᶠᶜᵃ⁺)
72
+ Rcosθ₂ = ifelse (Δyᶠᶜᵃ⁻ == 0 , zero (grid), deg2rad (φᶠᶠᵃ⁻⁺ - φᶠᶠᵃ⁻⁻) / Δyᶠᶜᵃ⁻)
73
+
74
+ # θ is the rotation angle between intrinsic and extrinsic reference frame
75
+ Rcosθ = (Rcosθ₁ + Rcosθ₂) / 2
72
76
Rsinθ = - (deg2rad (φᶠᶠᵃ⁺⁺ - φᶠᶠᵃ⁻⁺) / Δxᶜᶠᵃ⁺ + deg2rad (φᶠᶠᵃ⁺⁻ - φᶠᶠᵃ⁻⁻) / Δxᶜᶠᵃ⁻) / 2
73
77
74
78
# Normalization for the rotation angles
75
79
R = sqrt (Rcosθ^ 2 + Rsinθ^ 2 )
76
80
77
- u = getvalue (uₑ, i, j, k, grid)
78
- v = getvalue (vₑ, i, j, k, grid)
81
+ cosθ, sinθ = Rcosθ / R, Rsinθ / R
82
+
83
+ θ_degrees = atand (sinθ / cosθ)
84
+ return θ_degrees
85
+ end
86
+
87
+ # Intrinsic and extrinsic conversion for `OrthogonalSphericalShellGrid`s,
88
+ # i.e. curvilinear grids defined on a sphere which are locally orthogonal.
89
+ # If the coordinates match with the coordinates of a latitude-longitude grid
90
+ # (i.e. globally orthogonal), these functions collapse to
91
+ # uₑ, vₑ, wₑ = uᵢ, vᵢ, wᵢ
92
+
93
+ # 2D vectors
94
+ @inline function intrinsic_vector (i, j, k, grid:: OrthogonalSphericalShellGrid , uₑ, vₑ)
79
95
80
- cosθ = Rcosθ / R
81
- sinθ = Rsinθ / R
96
+ u = getvalue (uₑ, i, j, k, grid)
97
+ v = getvalue (vₑ, i, j, k, grid)
82
98
83
- uᵢ = u * cosθ + v * sinθ
84
- vᵢ = - u * sinθ + v * cosθ
99
+ θ_degrees = rotation_angle (i, j, grid:: OrthogonalSphericalShellGrid )
100
+ sinθ = sind (θ_degrees)
101
+ cosθ = cosd (θ_degrees)
102
+
103
+ uᵢ = u * cosθ - v * sinθ
104
+ vᵢ = u * sinθ + v * cosθ
85
105
86
106
return uᵢ, vᵢ
87
107
end
98
118
# 2D vectors
99
119
@inline function extrinsic_vector (i, j, k, grid:: OrthogonalSphericalShellGrid , uᵢ, vᵢ)
100
120
101
- φᶠᶠᵃ⁺⁺ = φnode (i+ 1 , j+ 1 , 1 , grid, Face (), Face (), Center ())
102
- φᶠᶠᵃ⁺⁻ = φnode (i+ 1 , j, 1 , grid, Face (), Face (), Center ())
103
- φᶠᶠᵃ⁻⁺ = φnode (i, j+ 1 , 1 , grid, Face (), Face (), Center ())
104
- φᶠᶠᵃ⁻⁻ = φnode (i, j, 1 , grid, Face (), Face (), Center ())
121
+ u = getvalue (uᵢ, i, j, k, grid)
122
+ v = getvalue (vᵢ, i, j, k, grid)
105
123
106
- Δyᶠᶜᵃ⁺ = Δyᶠᶜᶜ (i+ 1 , j, 1 , grid)
107
- Δyᶠᶜᵃ⁻ = Δyᶠᶜᶜ (i, j, 1 , grid)
108
- Δxᶜᶠᵃ⁺ = Δxᶜᶠᶜ (i, j+ 1 , 1 , grid)
109
- Δxᶜᶠᵃ⁻ = Δxᶜᶠᶜ (i, j, 1 , grid)
124
+ θ_degrees = rotation_angle (i, j, grid:: OrthogonalSphericalShellGrid )
125
+ sinθ = sind (θ_degrees)
126
+ cosθ = cosd (θ_degrees)
110
127
111
- # θᵢ is the rotation angle between intrinsic and extrinsic reference frame
112
- Rcosθ = (deg2rad (φᶠᶠᵃ⁺⁺ - φᶠᶠᵃ⁺⁻) / Δyᶠᶜᵃ⁺ + deg2rad (φᶠᶠᵃ⁻⁺ - φᶠᶠᵃ⁻⁻) / Δyᶠᶜᵃ⁻) / 2
113
- Rsinθ = - (deg2rad (φᶠᶠᵃ⁺⁺ - φᶠᶠᵃ⁻⁺) / Δxᶜᶠᵃ⁺ + deg2rad (φᶠᶠᵃ⁺⁻ - φᶠᶠᵃ⁻⁻) / Δxᶜᶠᵃ⁻) / 2
114
-
115
- # Normalization for the rotation angles
116
- R = sqrt (Rcosθ^ 2 + Rsinθ^ 2 )
117
-
118
- u = getvalue (uᵢ, i, j, k, grid)
119
- v = getvalue (vᵢ, i, j, k, grid)
120
-
121
- cosθ = Rcosθ / R
122
- sinθ = Rsinθ / R
123
-
124
- uₑ = u * cosθ - v * sinθ
125
- vₑ = u * sinθ + v * cosθ
128
+ uₑ = + u * cosθ + v * sinθ
129
+ vₑ = - u * sinθ + v * cosθ
126
130
127
131
return uₑ, vₑ
128
132
end
134
138
wₑ = getvalue (wᵢ, i, j, k, grid)
135
139
136
140
return uₑ, vₑ, wₑ
137
- end
141
+ end
0 commit comments