Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep DGMulti for non-conservative shock capturing #1479

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5db872c
add volume integral cache for Gauss schemes
jlchan May 11, 2023
e5102d8
fix splatting
jlchan May 12, 2023
e276558
initial draft of indicator routines
jlchan May 12, 2023
ecf0110
fix typo, add TODO
jlchan May 12, 2023
d8cff0e
draft of indicator + smoothing
jlchan May 12, 2023
df462c0
some interfaces for DGMulti shock capturing
jlchan May 12, 2023
0d41c9f
fix ambiguity
jlchan May 12, 2023
f03d15f
fix nelements ambiguity
jlchan May 12, 2023
c234e38
add DGMultiBasis
jlchan May 12, 2023
6f3097f
draft of shock capturing routines
jlchan May 13, 2023
9d8322d
add test elixir
jlchan May 13, 2023
78d82ef
pass in volume flux instead of volume integral
jlchan May 13, 2023
c61ff0f
Merge branch 'jc/prep_for_DGMulti_SC' into jc/gauss_shock_capturing
jlchan May 13, 2023
9fddc49
dropped one
jlchan May 13, 2023
b6d2f65
Merge branch 'jc/prep_for_DGMulti_SC' into jc/gauss_shock_capturing
jlchan May 13, 2023
6353352
refactoring
jlchan May 13, 2023
76b7064
factor flux_differencing_kernel! out
jlchan May 13, 2023
a4c9404
use flux_differencing_kernel!
jlchan May 13, 2023
1c268e2
factor flux_differencing_kernel! out
jlchan May 13, 2023
1a3e38b
Merge branch 'jc/prep_for_DGMulti_SC' into jc/gauss_shock_capturing
jlchan May 13, 2023
bce2d9f
consistent formatting
jlchan May 13, 2023
519e82c
Merge branch 'jc/prep_for_DGMulti_SC' into jc/gauss_shock_capturing
jlchan May 13, 2023
7158df7
Update src/solvers/dgmulti/types.jl
jlchan May 13, 2023
b6c8012
add kwargs reference
jlchan May 13, 2023
7e0c458
add volume_flux specialization
jlchan May 13, 2023
520c116
Revert "add volume_flux specialization"
jlchan May 13, 2023
7c4b1cc
inlining `flux_differencing_kernel!`
jlchan May 13, 2023
b86ff6c
Merge branch 'jc/prep_for_DGMulti_SC' into jc/gauss_shock_capturing
jlchan May 13, 2023
84921fb
draft of the low order (FV) volume kernel
jlchan May 13, 2023
2d7926b
Merge branch 'main' into jc/prep_for_DGMulti_SC
ranocha May 14, 2023
4ee3e18
Merge branch 'main' into jc/prep_for_DGMulti_SC
jlchan May 14, 2023
a326dcc
Merge branch 'main' into jc/prep_for_DGMulti_SC
ranocha May 15, 2023
940f8cd
Merge branch 'jc/prep_for_DGMulti_SC' into jc/gauss_shock_capturing
jlchan May 15, 2023
87e32d8
Merge remote-tracking branch 'origin/main' into jc/gauss_shock_capturing
jlchan May 15, 2023
f12457d
remove some unpacks
jlchan May 15, 2023
ab6e0cb
working shock capturing
jlchan May 15, 2023
e01266e
add example elixir for shock capturing
jlchan May 15, 2023
ee0c93f
add test
jlchan May 15, 2023
f145588
remove some @unpacks
jlchan May 15, 2023
660c5b6
reduce allocations
jlchan May 15, 2023
476571a
reduce more allocations
jlchan May 15, 2023
0b3be2f
factor out rhs_local projection onto Gauss nodes
jlchan May 16, 2023
8b924d0
remove one more reshape to remove allocations
jlchan May 16, 2023
c26e417
fix indicator computations
jlchan May 16, 2023
8800778
comments
jlchan May 16, 2023
ce020ce
update l2, linf for tests
jlchan May 16, 2023
c839b28
Merge branch 'main' into jc/gauss_shock_capturing
jlchan May 16, 2023
c4cbc18
Update src/solvers/dgmulti/shock_capturing.jl
jlchan May 16, 2023
090faee
Merge branch 'main' into jc/gauss_shock_capturing
jlchan May 16, 2023
4a8938f
add Base.ReshapedArray comments
jlchan May 16, 2023
67531ac
improve clarity of variable names
jlchan May 16, 2023
6af7e67
removing normalization
jlchan May 16, 2023
18e9f0d
use adjoint
jlchan May 16, 2023
47a7701
Merge remote-tracking branch 'Trixi_fork/jc/gauss_shock_capturing' in…
jlchan May 16, 2023
69e2d30
Merge branch 'main' into jc/gauss_shock_capturing
ranocha May 16, 2023
69ec7db
Merge branch 'main' into jc/gauss_shock_capturing
jlchan May 16, 2023
b1e0e14
adding curved shock capturing
jlchan May 16, 2023
bf5b635
adding a test
jlchan May 16, 2023
a6d3888
formatting and comments
jlchan May 16, 2023
b4b0734
removing LazyMatrixLinearCombo for nonconservative scalings
jlchan May 16, 2023
921e4ae
Merge branch 'main' into jc/curved_gauss_shockcapturing
jlchan May 17, 2023
9b28d55
Merge branch 'jc/curved_gauss_shockcapturing' into jc/prep_DGMulti_no…
jlchan May 17, 2023
f778724
Merge branch 'main' into jc/prep_DGMulti_noncons_for_shock_capturing
jlchan May 17, 2023
e5865b9
Merge branch 'main' into jc/prep_DGMulti_noncons_for_shock_capturing
jlchan May 17, 2023
577522f
Merge branch 'main' into jc/prep_DGMulti_noncons_for_shock_capturing
ranocha May 18, 2023
348b33b
Merge branch 'main' into jc/prep_DGMulti_noncons_for_shock_capturing
jlchan Jun 16, 2023
6f54315
formatting
jlchan Jun 16, 2023
aa0a995
Merge branch 'main' into jc/prep_DGMulti_noncons_for_shock_capturing
jlchan Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 56 additions & 21 deletions src/solvers/dgmulti/flux_differencing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ end
# Version for dense operators and non-symmetric fluxes
@inline function hadamard_sum!(du, A,
flux_is_symmetric::False, volume_flux,
orientation::Integer, u, equations)
orientation::Integer, u, equations;
scaling = true)
row_ids, col_ids = axes(A)

for i in row_ids
Expand All @@ -60,15 +61,17 @@ end
for j in col_ids
u_j = u[j]
f_ij = volume_flux(u_i, u_j, orientation, equations)
du_i = du_i + 2 * A[i, j] * f_ij
du_i = du_i + scaling * 2 * A[i, j] * f_ij
end
du[i] = du_i
end
end

# Version for dense operators and non-symmetric fluxes,
# but the normal direction is a vector.
@inline function hadamard_sum!(du, A,
flux_is_symmetric::False, volume_flux,
normal_direction::AbstractVector, u, equations)
normal_direction::AbstractVector, u, equations;
scaling = true)
row_ids, col_ids = axes(A)

for i in row_ids
Expand All @@ -80,9 +83,8 @@ end
# This is because on curved meshes, nonconservative fluxes are
# evaluated using both the normal and its average at interfaces.
f_ij = volume_flux(u_i, u_j, normal_direction, normal_direction, equations)
du_i = du_i + 2 * A[i, j] * f_ij
du_i = du_i + scaling * 2 * A[i, j] * f_ij
end
du[i] = du_i
end
end

Expand Down Expand Up @@ -120,7 +122,7 @@ end
end
end

# Version for sparse operators and symmetric fluxes with curved meshes
# Version for sparse operators and symmetric fluxes on curved meshes
@inline function hadamard_sum!(du,
A::LinearAlgebra.Adjoint{<:Any,
<:AbstractSparseMatrixCSC},
Expand Down Expand Up @@ -158,13 +160,13 @@ end
end
end

# TODO: DGMulti. Fix for curved meshes.
# Version for sparse operators and non-symmetric fluxes
@inline function hadamard_sum!(du,
A::LinearAlgebra.Adjoint{<:Any,
<:AbstractSparseMatrixCSC},
flux_is_symmetric::False, volume_flux,
normal_direction::AbstractVector, u, equations)
normal_direction::AbstractVector, u, equations;
scaling = true)
A_base = parent(A) # the adjoint of a SparseMatrixCSC is basically a SparseMatrixCSR
row_ids = axes(A, 2)
rows = rowvals(A_base)
Expand All @@ -181,19 +183,52 @@ end
# evaluated using both the normal and its average at interfaces.
u_j = u[j]
f_ij = volume_flux(u_i, u_j, normal_direction, normal_direction, equations)
du_i = du_i + 2 * A_ij * f_ij
du_i = du_i + scaling * 2 * A_ij * f_ij
end
du[i] = du_i
end
end

# Version for sparse operators and non-symmetric fluxes on curved meshes
@inline function hadamard_sum!(du,
A::LinearAlgebra.Adjoint{<:Any, <:AbstractSparseMatrixCSC
},
flux_is_symmetric::False, volume_flux,
normal_directions::AbstractVector{<:AbstractVector},
u, equations; scaling = true)
A_base = parent(A) # the adjoint of a SparseMatrixCSC is basically a SparseMatrixCSR
row_ids = axes(A, 2)
rows = rowvals(A_base)
vals = nonzeros(A_base)

for i in row_ids
u_i = u[i]
du_i = du[i]
for id in nzrange(A_base, i)
A_ij = vals[id]
j = rows[id]

# provably entropy stable de-aliasing of geometric terms
normal_direction = 0.5 * (getindex.(normal_directions, i) +
getindex.(normal_directions, j))

# The `normal_direction::AbstractVector` has to be passed in twice.
# This is because on curved meshes, nonconservative fluxes are
# evaluated using both the normal and its average at interfaces.
u_j = u[j]
f_ij = volume_flux(u_i, u_j, normal_direction, normal_direction, equations)
du_i = du_i + scaling * 2 * A_ij * f_ij
end
end
end

# For DGMulti implementations, we construct "physical" differentiation operators by taking linear
# combinations of reference differentiation operators scaled by geometric change of variables terms.
# We use a lazy evaluation of physical differentiation operators, so that we can compute linear
# combinations of differentiation operators on-the-fly in an allocation-free manner.
@inline function build_lazy_physical_derivative(element, orientation,
mesh::DGMultiMesh{1}, dg, cache,
operator_scaling = 1.0)
operator_scaling = true)
@unpack Qrst_skew = cache
@unpack rxJ = mesh.md
# ignore orientation
Expand All @@ -202,7 +237,7 @@ end

@inline function build_lazy_physical_derivative(element, orientation,
mesh::DGMultiMesh{2}, dg, cache,
operator_scaling = 1.0)
operator_scaling = true)
@unpack Qrst_skew = cache
@unpack rxJ, sxJ, ryJ, syJ = mesh.md
if orientation == 1
Expand All @@ -218,7 +253,7 @@ end

@inline function build_lazy_physical_derivative(element, orientation,
mesh::DGMultiMesh{3}, dg, cache,
operator_scaling = 1.0)
operator_scaling = true)
@unpack Qrst_skew = cache
@unpack rxJ, sxJ, txJ, ryJ, syJ, tyJ, rzJ, szJ, tzJ = mesh.md
if orientation == 1
Expand Down Expand Up @@ -247,7 +282,8 @@ end
# appear when using the chain rule to compute physical derivatives as a linear
# combination of reference derivatives.
@inline function get_contravariant_vector(element, orientation,
mesh::DGMultiMesh{NDIMS}, cache) where {NDIMS}
mesh::DGMultiMesh{NDIMS},
cache) where {NDIMS}
# note that rstxyzJ = [rxJ, sxJ, txJ; ryJ syJ tyJ; rzJ szJ tzJ], so that this will return
# SVector{2}(rxJ[1, element], ryJ[1, element]) in 2D.

Expand Down Expand Up @@ -484,12 +520,11 @@ end
dim, u_local, equations)

# The final argument .5 scales the operator by 1/2 for the nonconservative terms.
half_Qi_skew = build_lazy_physical_derivative(element_index, dim, mesh, dg,
cache, 0.5)
# False() indicates the flux is non-symmetric.
hadamard_sum!(fluxdiff_local, half_Qi_skew,
hadamard_sum!(fluxdiff_local, Qi_skew,
False(), flux_nonconservative,
dim, u_local, equations)
dim, u_local, equations;
scaling = 0.5)
end
end

Expand Down Expand Up @@ -541,11 +576,11 @@ end
normal_direction, u_local, equations)

# We scale the operator by 1/2 for the nonconservative terms.
half_Q_skew = LazyMatrixLinearCombo((Q_skew,), (0.5,))
# False() indicates the flux is non-symmetric
hadamard_sum!(fluxdiff_local, half_Q_skew,
hadamard_sum!(fluxdiff_local, Q_skew,
False(), flux_nonconservative,
normal_direction, u_local, equations)
normal_direction, u_local, equations;
scaling = 0.5)
end
end

Expand Down
Loading