Path: blob/main/src/solvers/dgsem_structured/dg_2d_subcell_limiters.jl
5591 views
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).1# Since these FMAs can increase the performance of many numerical algorithms,2# we need to opt-in explicitly.3# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.4@muladd begin5#! format: noindent67# Calculate the DG staggered volume fluxes `fhat` in subcell FV-form inside the element8# (**without non-conservative terms**).9#10# See also `flux_differencing_kernel!`.11@inline function calcflux_fhat!(fhat1_L, fhat1_R, fhat2_L, fhat2_R, u,12::Type{<:Union{StructuredMesh{2}, P4estMesh{2}}},13have_nonconservative_terms::False, equations,14volume_flux, dg::DGSEM, element, cache)15(; contravariant_vectors) = cache.elements16(; weights, derivative_split) = dg.basis17(; flux_temp_threaded) = cache1819flux_temp = flux_temp_threaded[Threads.threadid()]2021# The FV-form fluxes are calculated in a recursive manner, i.e.:22# fhat_(0,1) = w_0 * FVol_0,23# fhat_(j,j+1) = fhat_(j-1,j) + w_j * FVol_j, for j=1,...,N-1,24# with the split form volume fluxes FVol_j = -2 * sum_i=0^N D_ji f*_(j,i).2526# To use the symmetry of the `volume_flux`, the split form volume flux is precalculated27# like in `calc_volume_integral!` for the `VolumeIntegralFluxDifferencing`28# and saved in in `flux_temp`.2930# Split form volume flux in orientation 1: x direction31flux_temp .= zero(eltype(flux_temp))3233for j in eachnode(dg), i in eachnode(dg)34u_node = get_node_vars(u, equations, dg, i, j, element)3536# pull the contravariant vectors in each coordinate direction37Ja1_node = get_contravariant_vector(1, contravariant_vectors, i, j, element) # x direction3839# All diagonal entries of `derivative_split` are zero. Thus, we can skip40# the computation of the diagonal terms. In addition, we use the symmetry41# of the `volume_flux` to save half of the possible two-point flux42# computations.4344# x direction45for ii in (i + 1):nnodes(dg)46u_node_ii = get_node_vars(u, equations, dg, ii, j, element)47# pull the contravariant vectors and compute the average48Ja1_node_ii = get_contravariant_vector(1, contravariant_vectors, ii, j,49element)50Ja1_avg = 0.5f0 * (Ja1_node + Ja1_node_ii)5152# compute the contravariant sharp flux in the direction of the averaged contravariant vector53fluxtilde1 = volume_flux(u_node, u_node_ii, Ja1_avg, equations)54multiply_add_to_node_vars!(flux_temp, derivative_split[i, ii], fluxtilde1,55equations, dg, i, j)56multiply_add_to_node_vars!(flux_temp, derivative_split[ii, i], fluxtilde1,57equations, dg, ii, j)58end59end6061# FV-form flux `fhat` in x direction62for j in eachnode(dg), i in 1:(nnodes(dg) - 1)63for v in eachvariable(equations)64fhat1_L[v, i + 1, j] = fhat1_L[v, i, j] + weights[i] * flux_temp[v, i, j]65fhat1_R[v, i + 1, j] = fhat1_L[v, i + 1, j]66end67end6869# Split form volume flux in orientation 2: y direction70flux_temp .= zero(eltype(flux_temp))7172for j in eachnode(dg), i in eachnode(dg)73u_node = get_node_vars(u, equations, dg, i, j, element)7475# pull the contravariant vectors in each coordinate direction76Ja2_node = get_contravariant_vector(2, contravariant_vectors, i, j, element)7778# y direction79for jj in (j + 1):nnodes(dg)80u_node_jj = get_node_vars(u, equations, dg, i, jj, element)81# pull the contravariant vectors and compute the average82Ja2_node_jj = get_contravariant_vector(2, contravariant_vectors, i, jj,83element)84Ja2_avg = 0.5f0 * (Ja2_node + Ja2_node_jj)85# compute the contravariant sharp flux in the direction of the averaged contravariant vector86fluxtilde2 = volume_flux(u_node, u_node_jj, Ja2_avg, equations)87multiply_add_to_node_vars!(flux_temp, derivative_split[j, jj], fluxtilde2,88equations, dg, i, j)89multiply_add_to_node_vars!(flux_temp, derivative_split[jj, j], fluxtilde2,90equations, dg, i, jj)91end92end9394# FV-form flux `fhat` in y direction95for j in 1:(nnodes(dg) - 1), i in eachnode(dg)96for v in eachvariable(equations)97fhat2_L[v, i, j + 1] = fhat2_L[v, i, j] + weights[j] * flux_temp[v, i, j]98fhat2_R[v, i, j + 1] = fhat2_L[v, i, j + 1]99end100end101102return nothing103end104105# Calculate the DG staggered volume fluxes `fhat` in subcell FV-form inside the element106# (**with non-conservative terms in "local * symmetric" form**).107#108# See also `flux_differencing_kernel!`.109#110# The calculation of the non-conservative staggered "fluxes" requires non-conservative111# terms that can be written as a product of local and a symmetric contributions. See, e.g.,112#113# - Rueda-RamÃrez, Gassner (2023). A Flux-Differencing Formula for Split-Form Summation By Parts114# Discretizations of Non-Conservative Systems. https://arxiv.org/pdf/2211.14009.pdf.115#116@inline function calcflux_fhat!(fhat1_L, fhat1_R, fhat2_L, fhat2_R, u,117::Type{<:Union{StructuredMesh{2}, P4estMesh{2}}},118have_nonconservative_terms::True, equations,119volume_flux::Tuple{F_CONS, F_NONCONS}, dg::DGSEM,120element,121cache) where {122F_CONS <: Function,123F_NONCONS <:124FluxNonConservative{NonConservativeSymmetric()}125}126(; contravariant_vectors) = cache.elements127(; weights, derivative_split) = dg.basis128(; flux_temp_threaded, flux_nonconservative_temp_threaded) = cache129(; fhat_temp_threaded, fhat_nonconservative_temp_threaded, phi_threaded) = cache130131volume_flux_cons, volume_flux_noncons = volume_flux132133flux_temp = flux_temp_threaded[Threads.threadid()]134flux_noncons_temp = flux_nonconservative_temp_threaded[Threads.threadid()]135136fhat_temp = fhat_temp_threaded[Threads.threadid()]137fhat_noncons_temp = fhat_nonconservative_temp_threaded[Threads.threadid()]138phi = phi_threaded[Threads.threadid()]139140# The FV-form fluxes are calculated in a recursive manner, i.e.:141# fhat_(0,1) = w_0 * FVol_0,142# fhat_(j,j+1) = fhat_(j-1,j) + w_j * FVol_j, for j=1,...,N-1,143# with the split form volume fluxes FVol_j = -2 * sum_i=0^N D_ji f*_(j,i).144145# To use the symmetry of the `volume_flux`, the split form volume flux is precalculated146# like in `calc_volume_integral!` for the `VolumeIntegralFluxDifferencing`147# and saved in in `flux_temp`.148149# Split form volume flux in orientation 1: x direction150flux_temp .= zero(eltype(flux_temp))151flux_noncons_temp .= zero(eltype(flux_noncons_temp))152153for j in eachnode(dg), i in eachnode(dg)154u_node = get_node_vars(u, equations, dg, i, j, element)155156# pull the contravariant vectors in each coordinate direction157Ja1_node = get_contravariant_vector(1, contravariant_vectors, i, j, element) # x direction158159# All diagonal entries of `derivative_split` are zero. Thus, we can skip160# the computation of the diagonal terms. In addition, we use the symmetry161# of `volume_flux_cons` and `volume_flux_noncons` to save half of the possible two-point flux162# computations.163for ii in (i + 1):nnodes(dg)164u_node_ii = get_node_vars(u, equations, dg, ii, j, element)165# pull the contravariant vectors and compute the average166Ja1_node_ii = get_contravariant_vector(1, contravariant_vectors, ii, j,167element)168Ja1_avg = 0.5f0 * (Ja1_node + Ja1_node_ii)169170# compute the contravariant sharp flux in the direction of the averaged contravariant vector171fluxtilde1 = volume_flux_cons(u_node, u_node_ii, Ja1_avg, equations)172multiply_add_to_node_vars!(flux_temp, derivative_split[i, ii], fluxtilde1,173equations, dg, i, j)174multiply_add_to_node_vars!(flux_temp, derivative_split[ii, i], fluxtilde1,175equations, dg, ii, j)176for noncons in 1:n_nonconservative_terms(volume_flux_noncons)177# We multiply by 0.5 because that is done in other parts of Trixi178flux1_noncons = volume_flux_noncons(u_node, u_node_ii, Ja1_avg,179equations,180NonConservativeSymmetric(), noncons)181multiply_add_to_node_vars!(flux_noncons_temp,1820.5f0 * derivative_split[i, ii],183flux1_noncons,184equations, dg, noncons, i, j)185multiply_add_to_node_vars!(flux_noncons_temp,1860.5f0 * derivative_split[ii, i],187flux1_noncons,188equations, dg, noncons, ii, j)189end190end191end192193# FV-form flux `fhat` in x direction194fhat_temp[:, 1, :] .= zero(eltype(fhat1_L))195fhat_noncons_temp[:, :, 1, :] .= zero(eltype(fhat1_L))196197# Compute local contribution to non-conservative flux198for j in eachnode(dg), i in eachnode(dg)199u_local = get_node_vars(u, equations, dg, i, j, element)200# pull the local contravariant vector201Ja1_node = get_contravariant_vector(1, contravariant_vectors, i, j, element)202for noncons in 1:n_nonconservative_terms(volume_flux_noncons)203set_node_vars!(phi,204volume_flux_noncons(u_local, Ja1_node, equations,205NonConservativeLocal(), noncons),206equations, dg, noncons, i, j)207end208end209210for j in eachnode(dg), i in 1:(nnodes(dg) - 1)211# Conservative part212for v in eachvariable(equations)213value = fhat_temp[v, i, j] + weights[i] * flux_temp[v, i, j]214fhat_temp[v, i + 1, j] = value215fhat1_L[v, i + 1, j] = value216fhat1_R[v, i + 1, j] = value217end218# Nonconservative part219for noncons in 1:n_nonconservative_terms(volume_flux_noncons),220v in eachvariable(equations)221222value = fhat_noncons_temp[v, noncons, i, j] +223weights[i] * flux_noncons_temp[v, noncons, i, j]224fhat_noncons_temp[v, noncons, i + 1, j] = value225226fhat1_L[v, i + 1, j] = fhat1_L[v, i + 1, j] + phi[v, noncons, i, j] * value227fhat1_R[v, i + 1, j] = fhat1_R[v, i + 1, j] +228phi[v, noncons, i + 1, j] * value229end230end231232# Split form volume flux in orientation 2: y direction233flux_temp .= zero(eltype(flux_temp))234flux_noncons_temp .= zero(eltype(flux_noncons_temp))235236for j in eachnode(dg), i in eachnode(dg)237u_node = get_node_vars(u, equations, dg, i, j, element)238239# pull the contravariant vectors in each coordinate direction240Ja2_node = get_contravariant_vector(2, contravariant_vectors, i, j, element)241242for jj in (j + 1):nnodes(dg)243u_node_jj = get_node_vars(u, equations, dg, i, jj, element)244# pull the contravariant vectors and compute the average245Ja2_node_jj = get_contravariant_vector(2, contravariant_vectors, i, jj,246element)247Ja2_avg = 0.5f0 * (Ja2_node + Ja2_node_jj)248# compute the contravariant sharp flux in the direction of the averaged contravariant vector249fluxtilde2 = volume_flux_cons(u_node, u_node_jj, Ja2_avg, equations)250multiply_add_to_node_vars!(flux_temp, derivative_split[j, jj], fluxtilde2,251equations, dg, i, j)252multiply_add_to_node_vars!(flux_temp, derivative_split[jj, j], fluxtilde2,253equations, dg, i, jj)254for noncons in 1:n_nonconservative_terms(volume_flux_noncons)255# We multiply by 0.5 because that is done in other parts of Trixi256flux2_noncons = volume_flux_noncons(u_node, u_node_jj, Ja2_avg,257equations,258NonConservativeSymmetric(), noncons)259multiply_add_to_node_vars!(flux_noncons_temp,2600.5f0 * derivative_split[j, jj],261flux2_noncons,262equations, dg, noncons, i, j)263multiply_add_to_node_vars!(flux_noncons_temp,2640.5f0 * derivative_split[jj, j],265flux2_noncons,266equations, dg, noncons, i, jj)267end268end269end270271# FV-form flux `fhat` in y direction272fhat_temp[:, :, 1] .= zero(eltype(fhat1_L))273fhat_noncons_temp[:, :, :, 1] .= zero(eltype(fhat1_L))274275# Compute local contribution to non-conservative flux276for j in eachnode(dg), i in eachnode(dg)277u_local = get_node_vars(u, equations, dg, i, j, element)278# pull the local contravariant vector279Ja2_node = get_contravariant_vector(2, contravariant_vectors, i, j, element)280for noncons in 1:n_nonconservative_terms(volume_flux_noncons)281set_node_vars!(phi,282volume_flux_noncons(u_local, Ja2_node, equations,283NonConservativeLocal(), noncons),284equations, dg, noncons, i, j)285end286end287288for j in 1:(nnodes(dg) - 1), i in eachnode(dg)289# Conservative part290for v in eachvariable(equations)291value = fhat_temp[v, i, j] + weights[j] * flux_temp[v, i, j]292fhat_temp[v, i, j + 1] = value293fhat2_L[v, i, j + 1] = value294fhat2_R[v, i, j + 1] = value295end296# Nonconservative part297for noncons in 1:n_nonconservative_terms(volume_flux_noncons),298v in eachvariable(equations)299300value = fhat_noncons_temp[v, noncons, i, j] +301weights[j] * flux_noncons_temp[v, noncons, i, j]302fhat_noncons_temp[v, noncons, i, j + 1] = value303304fhat2_L[v, i, j + 1] = fhat2_L[v, i, j + 1] + phi[v, noncons, i, j] * value305fhat2_R[v, i, j + 1] = fhat2_R[v, i, j + 1] +306phi[v, noncons, i, j + 1] * value307end308end309310return nothing311end312313# Calculate the DG staggered volume fluxes `fhat` in subcell FV-form inside the element314# (**with non-conservative terms in "local * jump" form**).315#316# See also `flux_differencing_kernel!`.317#318# The calculation of the non-conservative staggered "fluxes" requires non-conservative319# terms that can be written as a product of local and jump contributions.320@inline function calcflux_fhat!(fhat1_L, fhat1_R, fhat2_L, fhat2_R, u,321::Type{<:Union{StructuredMesh{2}, P4estMesh{2}}},322have_nonconservative_terms::True, equations,323volume_flux::Tuple{F_CONS, F_NONCONS}, dg::DGSEM,324element,325cache) where {326F_CONS <: Function,327F_NONCONS <:328FluxNonConservative{NonConservativeJump()}329}330(; contravariant_vectors) = cache.elements331(; weights, derivative_split) = dg.basis332(; flux_temp_threaded, flux_nonconservative_temp_threaded) = cache333(; fhat_temp_threaded, fhat_nonconservative_temp_threaded, phi_threaded) = cache334335volume_flux_cons, volume_flux_noncons = volume_flux336337flux_temp = flux_temp_threaded[Threads.threadid()]338flux_noncons_temp = flux_nonconservative_temp_threaded[Threads.threadid()]339340fhat_temp = fhat_temp_threaded[Threads.threadid()]341fhat_noncons_temp = fhat_nonconservative_temp_threaded[Threads.threadid()]342phi = phi_threaded[Threads.threadid()]343344# The FV-form fluxes are calculated in a recursive manner, i.e.:345# fhat_(0,1) = w_0 * FVol_0,346# fhat_(j,j+1) = fhat_(j-1,j) + w_j * FVol_j, for j=1,...,N-1,347# with the split form volume fluxes FVol_j = -2 * sum_i=0^N D_ji f*_(j,i).348349# To use the symmetry of the `volume_flux`, the split form volume flux is precalculated350# like in `calc_volume_integral!` for the `VolumeIntegralFluxDifferencing`351# and saved in in `flux_temp`.352353# Split form volume flux in orientation 1: x direction354flux_temp .= zero(eltype(flux_temp))355flux_noncons_temp .= zero(eltype(flux_noncons_temp))356357for j in eachnode(dg), i in eachnode(dg)358u_node = get_node_vars(u, equations, dg, i, j, element)359360# pull the contravariant vectors in each coordinate direction361Ja1_node = get_contravariant_vector(1, contravariant_vectors, i, j, element) # x direction362363# All diagonal entries of `derivative_split` are zero. Thus, we can skip364# the computation of the diagonal terms. In addition, we use the symmetry365# of `volume_flux_cons` and `volume_flux_noncons` to save half of the possible two-point flux366# computations.367for ii in (i + 1):nnodes(dg)368u_node_ii = get_node_vars(u, equations, dg, ii, j, element)369# pull the contravariant vectors and compute the average370Ja1_node_ii = get_contravariant_vector(1, contravariant_vectors, ii, j,371element)372Ja1_avg = 0.5f0 * (Ja1_node + Ja1_node_ii)373374# compute the contravariant sharp flux in the direction of the averaged contravariant vector375fluxtilde1 = volume_flux_cons(u_node, u_node_ii, Ja1_avg, equations)376multiply_add_to_node_vars!(flux_temp, derivative_split[i, ii], fluxtilde1,377equations, dg, i, j)378multiply_add_to_node_vars!(flux_temp, derivative_split[ii, i], fluxtilde1,379equations, dg, ii, j)380for noncons in 1:n_nonconservative_terms(volume_flux_noncons)381# We multiply by 0.5 because that is done in other parts of Trixi382flux1_noncons = volume_flux_noncons(u_node, u_node_ii, Ja1_avg,383equations,384NonConservativeJump(), noncons)385multiply_add_to_node_vars!(flux_noncons_temp,3860.5f0 * derivative_split[i, ii],387flux1_noncons,388equations, dg, noncons, i, j)389multiply_add_to_node_vars!(flux_noncons_temp,390-0.5f0 * derivative_split[ii, i],391flux1_noncons,392equations, dg, noncons, ii, j)393end394end395end396397# FV-form flux `fhat` in x direction398fhat_temp[:, 1, :] .= zero(eltype(fhat1_L))399fhat_noncons_temp[:, :, 1, :] .= zero(eltype(fhat1_L))400401# Compute local contribution to non-conservative flux402for j in eachnode(dg), i in eachnode(dg)403u_local = get_node_vars(u, equations, dg, i, j, element)404# pull the local contravariant vector405Ja1_node = get_contravariant_vector(1, contravariant_vectors, i, j, element)406for noncons in 1:n_nonconservative_terms(volume_flux_noncons)407set_node_vars!(phi,408volume_flux_noncons(u_local, Ja1_node, equations,409NonConservativeLocal(), noncons),410equations, dg, noncons, i, j)411end412end413414for j in eachnode(dg), i in 1:(nnodes(dg) - 1)415# Conservative part416for v in eachvariable(equations)417value = fhat_temp[v, i, j] + weights[i] * flux_temp[v, i, j]418fhat_temp[v, i + 1, j] = value419fhat1_L[v, i + 1, j] = value420fhat1_R[v, i + 1, j] = value421end422# Nonconservative part423for noncons in 1:n_nonconservative_terms(volume_flux_noncons),424v in eachvariable(equations)425426value = fhat_noncons_temp[v, noncons, i, j] +427weights[i] * flux_noncons_temp[v, noncons, i, j]428fhat_noncons_temp[v, noncons, i + 1, j] = value429430fhat1_L[v, i + 1, j] = fhat1_L[v, i + 1, j] + phi[v, noncons, i, j] * value431fhat1_R[v, i + 1, j] = fhat1_R[v, i + 1, j] +432phi[v, noncons, i + 1, j] * value433end434end435436# Apply correction term to the flux-differencing formula for nonconservative local * jump fluxes.437for j in eachnode(dg)438u_0 = get_node_vars(u, equations, dg, 1, j, element)439Ja1_node_0 = get_contravariant_vector(1, contravariant_vectors, 1, j, element)440441for i in 2:(nnodes(dg) - 1)442u_i = get_node_vars(u, equations, dg, i, j, element)443Ja1_node_i = get_contravariant_vector(1, contravariant_vectors, i, j,444element)445Ja1_avg = 0.5f0 * (Ja1_node_0 + Ja1_node_i)446447for noncons in 1:n_nonconservative_terms(volume_flux_noncons)448phi_jump = volume_flux_noncons(u_0, u_i, Ja1_avg, equations,449NonConservativeJump(), noncons)450451for v in eachvariable(equations)452# The factor of 2 is missing on each term because Trixi multiplies all the non-cons terms with 0.5453fhat1_R[v, i, j] -= phi[v, noncons, i, j] * phi_jump[v]454fhat1_L[v, i + 1, j] -= phi[v, noncons, i, j] * phi_jump[v]455end456end457end458u_N = get_node_vars(u, equations, dg, nnodes(dg), j, element)459Ja1_node_N = get_contravariant_vector(1, contravariant_vectors, nnodes(dg), j,460element)461Ja1_avg = 0.5f0 * (Ja1_node_0 + Ja1_node_N)462463for noncons in 1:n_nonconservative_terms(volume_flux_noncons)464phi_jump = volume_flux_noncons(u_0, u_N, Ja1_avg, equations,465NonConservativeJump(), noncons)466467for v in eachvariable(equations)468# The factor of 2 is missing because Trixi multiplies all the non-cons terms with 0.5469fhat1_R[v, nnodes(dg), j] -= phi[v, noncons, nnodes(dg), j] *470phi_jump[v]471end472end473end474475# Split form volume flux in orientation 2: y direction476flux_temp .= zero(eltype(flux_temp))477flux_noncons_temp .= zero(eltype(flux_noncons_temp))478479for j in eachnode(dg), i in eachnode(dg)480u_node = get_node_vars(u, equations, dg, i, j, element)481482# pull the contravariant vectors in each coordinate direction483Ja2_node = get_contravariant_vector(2, contravariant_vectors, i, j, element)484485for jj in (j + 1):nnodes(dg)486u_node_jj = get_node_vars(u, equations, dg, i, jj, element)487# pull the contravariant vectors and compute the average488Ja2_node_jj = get_contravariant_vector(2, contravariant_vectors, i, jj,489element)490Ja2_avg = 0.5f0 * (Ja2_node + Ja2_node_jj)491# compute the contravariant sharp flux in the direction of the averaged contravariant vector492fluxtilde2 = volume_flux_cons(u_node, u_node_jj, Ja2_avg, equations)493multiply_add_to_node_vars!(flux_temp, derivative_split[j, jj], fluxtilde2,494equations, dg, i, j)495multiply_add_to_node_vars!(flux_temp, derivative_split[jj, j], fluxtilde2,496equations, dg, i, jj)497for noncons in 1:n_nonconservative_terms(volume_flux_noncons)498# We multiply by 0.5 because that is done in other parts of Trixi499flux2_noncons = volume_flux_noncons(u_node, u_node_jj, Ja2_avg,500equations,501NonConservativeJump(), noncons)502multiply_add_to_node_vars!(flux_noncons_temp,5030.5f0 * derivative_split[j, jj],504flux2_noncons,505equations, dg, noncons, i, j)506multiply_add_to_node_vars!(flux_noncons_temp,507-0.5f0 * derivative_split[jj, j],508flux2_noncons,509equations, dg, noncons, i, jj)510end511end512end513514# FV-form flux `fhat` in y direction515fhat_temp[:, :, 1] .= zero(eltype(fhat1_L))516fhat_noncons_temp[:, :, :, 1] .= zero(eltype(fhat1_L))517518# Compute local contribution to non-conservative flux519for j in eachnode(dg), i in eachnode(dg)520u_local = get_node_vars(u, equations, dg, i, j, element)521# pull the local contravariant vector522Ja2_node = get_contravariant_vector(2, contravariant_vectors, i, j, element)523for noncons in 1:n_nonconservative_terms(volume_flux_noncons)524set_node_vars!(phi,525volume_flux_noncons(u_local, Ja2_node, equations,526NonConservativeLocal(), noncons),527equations, dg, noncons, i, j)528end529end530531for j in 1:(nnodes(dg) - 1), i in eachnode(dg)532# Conservative part533for v in eachvariable(equations)534value = fhat_temp[v, i, j] + weights[j] * flux_temp[v, i, j]535fhat_temp[v, i, j + 1] = value536fhat2_L[v, i, j + 1] = value537fhat2_R[v, i, j + 1] = value538end539# Nonconservative part540for noncons in 1:n_nonconservative_terms(volume_flux_noncons),541v in eachvariable(equations)542543value = fhat_noncons_temp[v, noncons, i, j] +544weights[j] * flux_noncons_temp[v, noncons, i, j]545fhat_noncons_temp[v, noncons, i, j + 1] = value546547fhat2_L[v, i, j + 1] = fhat2_L[v, i, j + 1] + phi[v, noncons, i, j] * value548fhat2_R[v, i, j + 1] = fhat2_R[v, i, j + 1] +549phi[v, noncons, i, j + 1] * value550end551end552553# Apply correction term to the flux-differencing formula for nonconservative local * jump fluxes.554for i in eachnode(dg)555u_0 = get_node_vars(u, equations, dg, i, 1, element)556Ja2_node_0 = get_contravariant_vector(2, contravariant_vectors, i, 1, element)557558for j in 2:(nnodes(dg) - 1)559u_j = get_node_vars(u, equations, dg, i, j, element)560Ja2_node_j = get_contravariant_vector(2, contravariant_vectors, i, j,561element)562Ja2_avg = 0.5f0 * (Ja2_node_0 + Ja2_node_j)563564for noncons in 1:n_nonconservative_terms(volume_flux_noncons)565phi_jump = volume_flux_noncons(u_0, u_j, Ja2_avg, equations,566NonConservativeJump(), noncons)567568for v in eachvariable(equations)569# The factor of 2 is missing on each term because Trixi multiplies all the non-cons terms with 0.5570fhat2_R[v, i, j] -= phi[v, noncons, i, j] * phi_jump[v]571fhat2_L[v, i, j + 1] -= phi[v, noncons, i, j] * phi_jump[v]572end573end574end575u_N = get_node_vars(u, equations, dg, i, nnodes(dg), element)576Ja2_node_N = get_contravariant_vector(2, contravariant_vectors, i, nnodes(dg),577element)578Ja2_avg = 0.5f0 * (Ja2_node_0 + Ja2_node_N)579580for noncons in 1:n_nonconservative_terms(volume_flux_noncons)581phi_jump = volume_flux_noncons(u_0, u_N, Ja2_avg, equations,582NonConservativeJump(), noncons)583584for v in eachvariable(equations)585# The factor of 2 is missing cause Trixi multiplies all the non-cons terms with 0.5586fhat2_R[v, i, nnodes(dg)] -= phi[v, noncons, i, nnodes(dg)] *587phi_jump[v]588end589end590end591592return nothing593end594end # @muladd595596597