Skip to content

Commit

Permalink
Fix redundant type conversion in LobattoLegendreBasis (#2239)
Browse files Browse the repository at this point in the history
* Fix

* Fix

* Fix

* Update src/solvers/dgsem/basis_lobatto_legendre.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Update src/solvers/dgsem/basis_lobatto_legendre.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Update src/solvers/dgsem/basis_lobatto_legendre.jl

Co-authored-by: Hendrik Ranocha <[email protected]>

* Format

---------

Co-authored-by: Hendrik Ranocha <[email protected]>
  • Loading branch information
huiyuxie and ranocha authored Jan 18, 2025
1 parent fdd22a8 commit 6349413
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/solvers/dgsem/basis_lobatto_legendre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,27 @@ function LobattoLegendreBasis(RealT, polydeg::Integer)
nodes_, weights_ = gauss_lobatto_nodes_weights(nnodes_, RealT)
inverse_weights_ = inv.(weights_)

_, inverse_vandermonde_legendre_ = vandermonde_legendre(nodes_, RealT)
_, inverse_vandermonde_legendre = vandermonde_legendre(nodes_, RealT)

boundary_interpolation_ = zeros(RealT, nnodes_, 2)
boundary_interpolation_[:, 1] = calc_lhat(-one(RealT), nodes_, weights_)
boundary_interpolation_[:, 2] = calc_lhat(one(RealT), nodes_, weights_)
boundary_interpolation = zeros(RealT, nnodes_, 2)
boundary_interpolation[:, 1] = calc_lhat(-one(RealT), nodes_, weights_)
boundary_interpolation[:, 2] = calc_lhat(one(RealT), nodes_, weights_)

derivative_matrix_ = polynomial_derivative_matrix(nodes_)
derivative_split_ = calc_dsplit(nodes_, weights_)
derivative_split_transpose_ = Matrix(derivative_split_')
derivative_dhat_ = calc_dhat(nodes_, weights_)
derivative_matrix = polynomial_derivative_matrix(nodes_)
derivative_split = calc_dsplit(nodes_, weights_)
derivative_split_transpose = Matrix(derivative_split')
derivative_dhat = calc_dhat(nodes_, weights_)

# type conversions to get the requested real type and enable possible
# optimizations of runtime performance and latency
# Type conversions to enable possible optimizations of runtime performance
# and latency
nodes = SVector{nnodes_, RealT}(nodes_)
weights = SVector{nnodes_, RealT}(weights_)
inverse_weights = SVector{nnodes_, RealT}(inverse_weights_)

inverse_vandermonde_legendre = convert.(RealT, inverse_vandermonde_legendre_)
boundary_interpolation = convert.(RealT, boundary_interpolation_)

# Usually as fast as `SMatrix` (when using `let` in the volume integral/`@threaded`)
derivative_matrix = Matrix{RealT}(derivative_matrix_)
derivative_split = Matrix{RealT}(derivative_split_)
derivative_split_transpose = Matrix{RealT}(derivative_split_transpose_)
derivative_dhat = Matrix{RealT}(derivative_dhat_)
# We keep the matrices above stored using the standard `Matrix` type
# since this is usually as fast as `SMatrix`
# (when using `let` in the volume integral/`@threaded`)
# and reduces latency

return LobattoLegendreBasis{RealT, nnodes_, typeof(nodes),
typeof(inverse_vandermonde_legendre),
Expand Down

0 comments on commit 6349413

Please sign in to comment.