|
48 | 48 |
|
49 | 49 | function Bretherton_transforms_original!(lin_cache, t, ::Type{FT}) where {FT}
|
50 | 50 | (; ᶜx, ᶠx, ᶜz, ᶠz) = lin_cache
|
51 |
| - (; x_max, z_max, u₀, δ, cₛ², grav, f, ρₛ) = lin_cache |
52 |
| - (; ρfb_init_array, ᶜfourier_factor, ᶠfourier_factor) = lin_cache |
| 51 | + (; x_max, z_max, u₀) = lin_cache |
| 52 | + (; max_ikx, max_ikz) = lin_cache |
53 | 53 | (; ᶜpb, ᶜρb, ᶜub, ᶜvb, ᶠwb) = lin_cache
|
54 | 54 |
|
55 | 55 | ᶜpb .= FT(0)
|
56 | 56 | ᶜρb .= FT(0)
|
57 | 57 | ᶜub .= FT(0)
|
58 | 58 | ᶜvb .= FT(0)
|
59 | 59 | ᶠwb .= FT(0)
|
60 |
| - max_ikx, max_ikz = (size(ρfb_init_array) .- 1) .÷ 2 |
61 |
| - @inbounds for ikx in (-max_ikx):max_ikx, ikz in (-max_ikz):max_ikz |
62 |
| - kx = 2 * π / x_max * ikx |
63 |
| - kz = 2 * π / (2 * z_max) * ikz |
64 |
| - |
65 |
| - # Fourier coefficient of ᶜρb_init (for current kx and kz) |
66 |
| - ρfb_init = ρfb_init_array[ikx + max_ikx + 1, ikz + max_ikz + 1] |
67 |
| - |
68 |
| - # Fourier factors, shifted by u₀ * t along the x-axis |
69 |
| - @. ᶜfourier_factor = exp(im * (kx * (ᶜx - u₀ * t) + kz * ᶜz)) |
70 |
| - @. ᶠfourier_factor = exp(im * (kx * (ᶠx - u₀ * t) + kz * ᶠz)) |
71 |
| - |
72 |
| - # roots of a₁(s) |
73 |
| - p₁ = cₛ² * (kx^2 + kz^2 + δ^2 / 4) + f^2 |
74 |
| - q₁ = grav * kx^2 * (cₛ² * δ - grav) + cₛ² * f^2 * (kz^2 + δ^2 / 4) |
75 |
| - α² = p₁ / 2 - sqrt(p₁^2 / 4 - q₁) |
76 |
| - β² = p₁ / 2 + sqrt(p₁^2 / 4 - q₁) |
77 |
| - α = sqrt(α²) |
78 |
| - β = sqrt(β²) |
79 |
| - |
80 |
| - # inverse Laplace transform of s^p/((s^2 + α^2)(s^2 + β^2)) for p ∈ -1:3 |
81 |
| - if α == 0 |
82 |
| - L₋₁ = (β² * t^2 / 2 - 1 + cos(β * t)) / β^4 |
83 |
| - L₀ = (β * t - sin(β * t)) / β^3 |
84 |
| - else |
85 |
| - L₋₁ = |
86 |
| - (-cos(α * t) / α² + cos(β * t) / β²) / (β² - α²) + 1 / (α² * β²) |
87 |
| - L₀ = (sin(α * t) / α - sin(β * t) / β) / (β² - α²) |
| 60 | + |
| 61 | + @inbounds begin |
| 62 | + for ikx in (-max_ikx):max_ikx |
| 63 | + for ikz in (-max_ikz):max_ikz |
| 64 | + (; pfb, ρfb, ufb, vfb, wfb) = |
| 65 | + Bretherton_transform_coeffs(lin_cache, ikx, ikz, t, FT) |
| 66 | + # Fourier coefficient of ᶜρb_init (for current kx and kz) |
| 67 | + kx::FT = 2 * π / x_max * ikx |
| 68 | + kz::FT = 2 * π / (2 * z_max) * ikz |
| 69 | + |
| 70 | + # Fourier factors, shifted by u₀ * t along the x-axis |
| 71 | + @. ᶜpb += real(pfb * exp(im * (kx * (ᶜx - u₀ * t) + kz * ᶜz))) |
| 72 | + @. ᶜρb += real(ρfb * exp(im * (kx * (ᶜx - u₀ * t) + kz * ᶜz))) |
| 73 | + @. ᶜub += real(ufb * exp(im * (kx * (ᶜx - u₀ * t) + kz * ᶜz))) |
| 74 | + @. ᶜvb += real(vfb * exp(im * (kx * (ᶜx - u₀ * t) + kz * ᶜz))) |
| 75 | + @. ᶠwb += real(wfb * exp(im * (kx * (ᶠx - u₀ * t) + kz * ᶠz))) |
| 76 | + end |
88 | 77 | end
|
89 |
| - L₁ = (cos(α * t) - cos(β * t)) / (β² - α²) |
90 |
| - L₂ = (-sin(α * t) * α + sin(β * t) * β) / (β² - α²) |
91 |
| - L₃ = (-cos(α * t) * α² + cos(β * t) * β²) / (β² - α²) |
92 |
| - |
93 |
| - # Fourier coefficients of Bretherton transforms of final perturbations |
94 |
| - C₁ = grav * (grav - cₛ² * (im * kz + δ / 2)) |
95 |
| - C₂ = grav * (im * kz - δ / 2) |
96 |
| - pfb = -ρfb_init * (L₁ + L₋₁ * f^2) * C₁ |
97 |
| - ρfb = |
98 |
| - ρfb_init * |
99 |
| - (L₃ + L₁ * (p₁ + C₂) + L₋₁ * f^2 * (cₛ² * (kz^2 + δ^2 / 4) + C₂)) |
100 |
| - ufb = ρfb_init * L₀ * im * kx * C₁ / ρₛ |
101 |
| - vfb = -ρfb_init * L₋₁ * im * kx * f * C₁ / ρₛ |
102 |
| - wfb = -ρfb_init * (L₂ + L₀ * (f^2 + cₛ² * kx^2)) * grav / ρₛ |
103 |
| - |
104 |
| - # Bretherton transforms of final perturbations |
105 |
| - @. ᶜpb += real(pfb * ᶜfourier_factor) |
106 |
| - @. ᶜρb += real(ρfb * ᶜfourier_factor) |
107 |
| - @. ᶜub += real(ufb * ᶜfourier_factor) |
108 |
| - @. ᶜvb += real(vfb * ᶜfourier_factor) |
109 |
| - @. ᶠwb += real(wfb * ᶠfourier_factor) |
110 |
| - # The imaginary components should be 0 (or at least very close to 0). |
111 | 78 | end
|
112 | 79 | return nothing
|
113 | 80 | end
|
@@ -151,4 +118,50 @@ function linear_solution!(Y, lin_cache, t, ::Type{FT}) where {FT}
|
151 | 118 | return nothing
|
152 | 119 | end
|
153 | 120 |
|
| 121 | +function Bretherton_transform_coeffs(args, ikx, ikz, t, ::Type{FT}) where {FT} |
| 122 | + (; ᶜρb_init_xz, unit_integral, ρfb_init_array) = args |
| 123 | + (; max_ikx, max_ikz) = args |
| 124 | + (; x_max, z_max, u₀, δ, cₛ², grav, f, ρₛ) = args |
| 125 | + |
| 126 | + # Fourier coefficient of ᶜρb_init (for current kx and kz) |
| 127 | + kx::FT = 2 * π / x_max * ikx |
| 128 | + kz::FT = 2 * π / (2 * z_max) * ikz |
| 129 | + |
| 130 | + ρfb_init = ρfb_init_array[ikx + max_ikx + 1, ikz + max_ikz + 1] |
| 131 | + |
| 132 | + # roots of a₁(s) |
| 133 | + p₁ = cₛ² * (kx^2 + kz^2 + δ^2 / 4) + f^2 |
| 134 | + q₁ = grav * kx^2 * (cₛ² * δ - grav) + cₛ² * f^2 * (kz^2 + δ^2 / 4) |
| 135 | + α² = p₁ / 2 - sqrt(p₁^2 / 4 - q₁) |
| 136 | + β² = p₁ / 2 + sqrt(p₁^2 / 4 - q₁) |
| 137 | + α = sqrt(α²) |
| 138 | + β = sqrt(β²) |
| 139 | + |
| 140 | + # inverse Laplace transform of s^p/((s^2 + α^2)(s^2 + β^2)) for p ∈ -1:3 |
| 141 | + if α == 0 |
| 142 | + L₋₁ = (β² * t^2 / 2 - 1 + cos(β * t)) / β^4 |
| 143 | + L₀ = (β * t - sin(β * t)) / β^3 |
| 144 | + else |
| 145 | + L₋₁ = (-cos(α * t) / α² + cos(β * t) / β²) / (β² - α²) + 1 / (α² * β²) |
| 146 | + L₀ = (sin(α * t) / α - sin(β * t) / β) / (β² - α²) |
| 147 | + end |
| 148 | + L₁ = (cos(α * t) - cos(β * t)) / (β² - α²) |
| 149 | + L₂ = (-sin(α * t) * α + sin(β * t) * β) / (β² - α²) |
| 150 | + L₃ = (-cos(α * t) * α² + cos(β * t) * β²) / (β² - α²) |
| 151 | + |
| 152 | + # Fourier coefficients of Bretherton transforms of final perturbations |
| 153 | + C₁ = grav * (grav - cₛ² * (im * kz + δ / 2)) |
| 154 | + C₂ = grav * (im * kz - δ / 2) |
| 155 | + pfb = -ρfb_init * (L₁ + L₋₁ * f^2) * C₁ |
| 156 | + ρfb = |
| 157 | + ρfb_init * |
| 158 | + (L₃ + L₁ * (p₁ + C₂) + L₋₁ * f^2 * (cₛ² * (kz^2 + δ^2 / 4) + C₂)) |
| 159 | + ufb = ρfb_init * L₀ * im * kx * C₁ / ρₛ |
| 160 | + vfb = -ρfb_init * L₋₁ * im * kx * f * C₁ / ρₛ |
| 161 | + wfb = -ρfb_init * (L₂ + L₀ * (f^2 + cₛ² * kx^2)) * grav / ρₛ |
| 162 | + |
| 163 | + # Bretherton transforms of final perturbations |
| 164 | + return (; pfb, ρfb, ufb, vfb, wfb) |
| 165 | +end |
| 166 | + |
154 | 167 | end # module
|
0 commit comments