Skip to content

Commit 43cd98d

Browse files
dannys4ranochaDanielDoehring
authored
moving out OneTo in DGMulti shock capturing (#2469)
* moving out OneTo in shock capturing * Fix bug in reshaped modal * Update src/solvers/dgmulti/shock_capturing.jl Co-authored-by: Hendrik Ranocha <[email protected]> * Update src/solvers/dgmulti/shock_capturing.jl Co-authored-by: Hendrik Ranocha <[email protected]> * Comment on Returns in shock capture --------- Co-authored-by: Hendrik Ranocha <[email protected]> Co-authored-by: Daniel Doehring <[email protected]>
1 parent 0ad97bc commit 43cd98d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/solvers/dgmulti/shock_capturing.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,27 @@ function (indicator_hg::IndicatorHennemannGassner)(u, mesh::DGMultiMesh,
7979
# multiply by invVDM::SimpleKronecker
8080
LinearAlgebra.mul!(modal_, inverse_vandermonde, indicator)
8181

82+
# Create Returns functors to return the constructor args (e.g., Base.OneTo(dg.basis.N)) no matter what
83+
# Returns(Base.OneTo(dg.basis.N)) equiv to _ -> Base.OneTo(dg.basis.N), with possibly fewer allocs
84+
return_N_plus_one = Returns(dg.basis.N + 1)
85+
return_to_N_minus_one = Returns(Base.OneTo(dg.basis.N - 1))
86+
return_to_N = Returns(Base.OneTo(dg.basis.N))
87+
8288
# As of Julia 1.9, Base.ReshapedArray does not produce allocations when setting values.
8389
# Thus, Base.ReshapedArray should be used if you are setting values in the array.
8490
# `reshape` is fine if you are only accessing values.
8591
# Here, we reshape modal coefficients to expose the tensor product structure.
86-
modal = Base.ReshapedArray(modal_, ntuple(_ -> dg.basis.N + 1, NDIMS), ())
92+
93+
modal = Base.ReshapedArray(modal_, ntuple(return_N_plus_one, NDIMS), ())
8794

8895
# Calculate total energies for all modes, all modes minus the highest mode, and
8996
# all modes without the two highest modes
90-
total_energy = sum(x -> x^2, modal)
91-
clip_1_ranges = ntuple(_ -> Base.OneTo(dg.basis.N), NDIMS)
92-
clip_2_ranges = ntuple(_ -> Base.OneTo(dg.basis.N - 1), NDIMS)
97+
total_energy = sum(abs2, modal)
98+
clip_1_ranges = ntuple(return_to_N, NDIMS)
99+
clip_2_ranges = ntuple(return_to_N_minus_one, NDIMS)
93100
# These splattings do not seem to allocate as of Julia 1.9.0?
94-
total_energy_clip1 = sum(x -> x^2, view(modal, clip_1_ranges...))
95-
total_energy_clip2 = sum(x -> x^2, view(modal, clip_2_ranges...))
101+
total_energy_clip1 = sum(abs2, view(modal, clip_1_ranges...))
102+
total_energy_clip2 = sum(abs2, view(modal, clip_2_ranges...))
96103

97104
# Calculate energy in higher modes
98105
if !(iszero(total_energy))

0 commit comments

Comments
 (0)