Skip to content

Commit

Permalink
orography smoothing was disabled through old size call
Browse files Browse the repository at this point in the history
  • Loading branch information
milankl committed Jul 4, 2024
1 parent 575529c commit acbe0c5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ext/SpeedyWeatherJLArraysExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using SpeedyWeather, JLArrays

# for RingGrids and LowerTriangularMatrices:
# every Array needs this method to strip away the parameters
SpeedyWeather.RingGrids.nonparametric_type(::Type{<:JLArray}) = JLArray
SpeedyWeather.LowerTriangularMatrices.nonparametric_type(::Type{<:JLArray}) = JLArray
RingGrids.nonparametric_type(::Type{<:JLArray}) = JLArray
LowerTriangularMatrices.nonparametric_type(::Type{<:JLArray}) = JLArray

end # module
4 changes: 2 additions & 2 deletions src/SpeedyTransforms/legendrepolarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This enables easier use with AssociatedLegendrePolynomials.jl which otherwise co
"matrix-style" (l, m) indexing of `LowerTriangularArray`. This type however doesn't support any
other operations than indexing and is purerly intended for internal purposes.
"""
struct AssociatedLegendrePolArray{T,N,M,V} <: AbstractArray{T,N}
data::LowerTriangularArray{T,M,V}
struct AssociatedLegendrePolArray{T, N, M, V} <: AbstractArray{T, N}
data::LowerTriangularArray{T, M, V}
end

"""2-dimensional `AssociatedLegendrePolArray` of type `T`` with its non-zero entries unravelled into a `Vector{T}`"""
Expand Down
8 changes: 4 additions & 4 deletions src/SpeedyTransforms/spectral_truncation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ end
Smooth the spectral field `A` following A *= (1-(1-c)*∇²ⁿ) with power n of a normalised Laplacian
so that the highest degree lmax is dampened by multiplication with c. Anti-diffusion for c>1."""
function spectral_smoothing!( A::LowerTriangularMatrix,
function spectral_smoothing!( L::LowerTriangularMatrix,
c::Real;
power::Real=1, # power of Laplacian used for smoothing
power::Real=1, # power of Laplacian used for smoothing
truncation::Int=-1) # smoothing wrt wavenumber (0 = largest)

lmax, mmax = size(A; as=Matrix)
lmax, mmax = size(L; as=Matrix)
# normalize by largest eigenvalue by default, or wrt to given truncation
eigenvalue_norm = truncation == -1 ? -mmax*(mmax+1) : -truncation*(truncation+1)

Expand All @@ -191,7 +191,7 @@ function spectral_smoothing!( A::LowerTriangularMatrix,
eigenvalue_normalised = -l*(l-1)/eigenvalue_norm
# for eigenvalue_norm < largest eigenvalue the factor becomes negative
# set to zero in that case
A[lm] *= max(1 - (1-c)*eigenvalue_normalised^power, 0)
L[lm] *= max(1 - (1-c)*eigenvalue_normalised^power, 0)
lm += 1
end
end
Expand Down
13 changes: 6 additions & 7 deletions src/dynamics/orography.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,12 @@ function initialize!( orog::EarthOrography,
orography .*= scale # scale orography (default 1)
spectral!(geopot_surf, orography, S) # no *gravity yet

if orog.smoothing # smooth orography in spectral space?
# translate smoothing_fraction to trunc to truncate beyond
trunc = (size(geopot_surf, 1) - 2)
truncation = round(Int, trunc * (1-orog.smoothing_fraction))
SpeedyTransforms.spectral_smoothing!(geopot_surf, orog.smoothing_strength,
power=orog.smoothing_power;
truncation)
if orog.smoothing # smooth orography in spectral space?
trunc = (size(geopot_surf, 1, as=Matrix) - 2) # get trunc=lmax from size of geopot_surf
truncation = round(Int, trunc * (1-orog.smoothing_fraction)) # degree of harmonics to be truncated
c = orog.smoothing_strength
power = orog.smoothing_power
SpeedyTransforms.spectral_smoothing!(geopot_surf, c; power, truncation)
end

gridded!(orography, geopot_surf, S) # to grid-point space
Expand Down
3 changes: 3 additions & 0 deletions test/lower_triangular_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ end
end
end

# only needed when the extension isn't loaded
# LowerTriangularMatrices.nonparametric_type(::Type{<:JLArray}) = JLArray

@testset "Zeros, ones, rand, and randn constructors" begin
for f in (ones, zeros, rand, randn)
s = (5, 5)
Expand Down
6 changes: 4 additions & 2 deletions test/spectral_transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ end
map = gridded(alms, S)
alms2 = spectral(map, S)

tol = 1e-3

for lm in SpeedyWeather.eachharmonic(alms, alms2)
@test alms[lm] alms2[lm] atol=1e-3 rtol=1e-3
@test alms[lm] alms2[lm] atol=tol rtol=tol
end
end
end
Expand Down Expand Up @@ -173,7 +175,7 @@ end
oro_grid2 = gridded(oro_spec1, S)
oro_spec2 = spectral(oro_grid2, S)

tol = 1e-1
tol = 1e-3

for lm in SpeedyWeather.eachharmonic(oro_spec1, oro_spec2)
@test oro_spec1[lm] oro_spec2[lm] atol=tol rtol=tol
Expand Down

0 comments on commit acbe0c5

Please sign in to comment.