Skip to content

Commit 07f960f

Browse files
andrewwinters5000amruedaranocha
authored
Fix noncons mortars for remaining mesh types (#2134)
* fix P4estMesh and T8codeMesh plus tests * apply formatter * revert diffusion ref values. Mac values different from Ubuntu runners * fix TreeMesh2D plus test * apply formatter * fix TreeMesh 3D and tests plus formatting * hopefully fix broken MPI tests * add specialized parabolic 3d mortar projection to save on computation --------- Co-authored-by: Andrés Rueda-Ramírez <[email protected]> Co-authored-by: Hendrik Ranocha <[email protected]>
1 parent 29866b0 commit 07f960f

File tree

13 files changed

+600
-311
lines changed

13 files changed

+600
-311
lines changed

src/solvers/dgsem_p4est/dg_2d.jl

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ function create_cache(mesh::Union{P4estMesh{2}, T8codeMesh{2}}, equations,
1313
MA2d = MArray{Tuple{nvariables(equations), nnodes(mortar_l2)},
1414
uEltype, 2,
1515
nvariables(equations) * nnodes(mortar_l2)}
16-
fstar_upper_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
17-
fstar_lower_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
16+
fstar_primary_upper_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
17+
fstar_primary_lower_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
18+
fstar_secondary_upper_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
19+
fstar_secondary_lower_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
1820
u_threaded = MA2d[MA2d(undef) for _ in 1:Threads.nthreads()]
1921

20-
(; fstar_upper_threaded, fstar_lower_threaded, u_threaded)
22+
(; fstar_primary_upper_threaded, fstar_primary_lower_threaded,
23+
fstar_secondary_upper_threaded, fstar_secondary_lower_threaded,
24+
u_threaded)
2125
end
2226

2327
# index_to_start_step_2d(index::Symbol, index_range)
@@ -451,13 +455,17 @@ function calc_mortar_flux!(surface_flux_values,
451455
surface_integral, dg::DG, cache)
452456
@unpack neighbor_ids, node_indices = cache.mortars
453457
@unpack contravariant_vectors = cache.elements
454-
@unpack fstar_upper_threaded, fstar_lower_threaded = cache
458+
@unpack (fstar_primary_upper_threaded, fstar_primary_lower_threaded,
459+
fstar_secondary_upper_threaded, fstar_secondary_lower_threaded) = cache
455460
index_range = eachnode(dg)
456461

457462
@threaded for mortar in eachmortar(dg, cache)
458463
# Choose thread-specific pre-allocated container
459-
fstar = (fstar_lower_threaded[Threads.threadid()],
460-
fstar_upper_threaded[Threads.threadid()])
464+
fstar_primary = (fstar_primary_lower_threaded[Threads.threadid()],
465+
fstar_primary_upper_threaded[Threads.threadid()])
466+
467+
fstar_secondary = (fstar_secondary_lower_threaded[Threads.threadid()],
468+
fstar_secondary_upper_threaded[Threads.threadid()])
461469

462470
# Get index information on the small elements
463471
small_indices = node_indices[1, mortar]
@@ -480,7 +488,8 @@ function calc_mortar_flux!(surface_flux_values,
480488
contravariant_vectors,
481489
i_small, j_small, element)
482490

483-
calc_mortar_flux!(fstar, mesh, nonconservative_terms, equations,
491+
calc_mortar_flux!(fstar_primary, fstar_secondary,
492+
mesh, nonconservative_terms, equations,
484493
surface_integral, dg, cache,
485494
mortar, position, normal_direction,
486495
node)
@@ -501,14 +510,15 @@ function calc_mortar_flux!(surface_flux_values,
501510
# "mortar_fluxes_to_elements!" instead.
502511
mortar_fluxes_to_elements!(surface_flux_values,
503512
mesh, equations, mortar_l2, dg, cache,
504-
mortar, fstar, u_buffer)
513+
mortar, fstar_primary, fstar_secondary,
514+
u_buffer)
505515
end
506516

507517
return nothing
508518
end
509519

510520
# Inlined version of the mortar flux computation on small elements for conservation laws
511-
@inline function calc_mortar_flux!(fstar,
521+
@inline function calc_mortar_flux!(fstar_primary, fstar_secondary,
512522
mesh::Union{P4estMesh{2}, T8codeMesh{2}},
513523
nonconservative_terms::False, equations,
514524
surface_integral, dg::DG, cache,
@@ -523,12 +533,13 @@ end
523533
flux = surface_flux(u_ll, u_rr, normal_direction, equations)
524534

525535
# Copy flux to buffer
526-
set_node_vars!(fstar[position_index], flux, equations, dg, node_index)
536+
set_node_vars!(fstar_primary[position_index], flux, equations, dg, node_index)
537+
set_node_vars!(fstar_secondary[position_index], flux, equations, dg, node_index)
527538
end
528539

529540
# Inlined version of the mortar flux computation on small elements for equations with conservative and
530541
# nonconservative terms
531-
@inline function calc_mortar_flux!(fstar,
542+
@inline function calc_mortar_flux!(fstar_primary, fstar_secondary,
532543
mesh::Union{P4estMesh{2}, T8codeMesh{2}},
533544
nonconservative_terms::True, equations,
534545
surface_integral, dg::DG, cache,
@@ -547,19 +558,25 @@ end
547558
# The nonconservative flux is scaled by a factor of 0.5 based on
548559
# the interpretation of global SBP operators coupled discontinuously via
549560
# central fluxes/SATs
550-
noncons = nonconservative_flux(u_ll, u_rr, normal_direction, equations)
561+
noncons_primary = nonconservative_flux(u_ll, u_rr, normal_direction, equations)
562+
noncons_secondary = nonconservative_flux(u_rr, u_ll, normal_direction, equations)
551563

552-
flux_plus_noncons = flux + 0.5f0 * noncons
564+
flux_plus_noncons_primary = flux + 0.5f0 * noncons_primary
565+
flux_plus_noncons_secondary = flux + 0.5f0 * noncons_secondary
553566

554567
# Copy to buffer
555-
set_node_vars!(fstar[position_index], flux_plus_noncons, equations, dg, node_index)
568+
set_node_vars!(fstar_primary[position_index], flux_plus_noncons_primary, equations,
569+
dg, node_index)
570+
set_node_vars!(fstar_secondary[position_index], flux_plus_noncons_secondary,
571+
equations, dg, node_index)
556572
end
557573

558574
@inline function mortar_fluxes_to_elements!(surface_flux_values,
559575
mesh::Union{P4estMesh{2}, T8codeMesh{2}},
560576
equations,
561577
mortar_l2::LobattoLegendreMortarL2,
562-
dg::DGSEM, cache, mortar, fstar, u_buffer)
578+
dg::DGSEM, cache, mortar, fstar_primary,
579+
fstar_secondary, u_buffer)
563580
@unpack neighbor_ids, node_indices = cache.mortars
564581

565582
# Copy solution small to small
@@ -570,16 +587,16 @@ end
570587
element = neighbor_ids[position, mortar]
571588
for i in eachnode(dg)
572589
for v in eachvariable(equations)
573-
surface_flux_values[v, i, small_direction, element] = fstar[position][v,
574-
i]
590+
surface_flux_values[v, i, small_direction, element] = fstar_primary[position][v,
591+
i]
575592
end
576593
end
577594
end
578595

579596
# Project small fluxes to large element.
580597
multiply_dimensionwise!(u_buffer,
581-
mortar_l2.reverse_upper, fstar[2],
582-
mortar_l2.reverse_lower, fstar[1])
598+
mortar_l2.reverse_upper, fstar_secondary[2],
599+
mortar_l2.reverse_lower, fstar_secondary[1])
583600

584601
# The flux is calculated in the outward direction of the small elements,
585602
# so the sign must be switched to get the flux in outward direction

src/solvers/dgsem_p4est/dg_2d_parabolic.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ end
398398
mesh::Union{P4estMesh{2}, T8codeMesh{2}},
399399
equations::AbstractEquationsParabolic,
400400
mortar_l2::LobattoLegendreMortarL2,
401-
dg::DGSEM, cache, mortar, fstar, u_buffer)
401+
dg::DGSEM, cache, mortar, fstar_primary,
402+
fstar_secondary, u_buffer)
402403
@unpack neighbor_ids, node_indices = cache.mortars
403404
# Copy solution small to small
404405
small_indices = node_indices[1, mortar]
@@ -408,16 +409,16 @@ end
408409
element = neighbor_ids[position, mortar]
409410
for i in eachnode(dg)
410411
for v in eachvariable(equations)
411-
surface_flux_values[v, i, small_direction, element] = fstar[position][v,
412-
i]
412+
surface_flux_values[v, i, small_direction, element] = fstar_primary[position][v,
413+
i]
413414
end
414415
end
415416
end
416417

417418
# Project small fluxes to large element.
418419
multiply_dimensionwise!(u_buffer,
419-
mortar_l2.reverse_upper, fstar[2],
420-
mortar_l2.reverse_lower, fstar[1])
420+
mortar_l2.reverse_upper, fstar_secondary[2],
421+
mortar_l2.reverse_lower, fstar_secondary[1])
421422

422423
# Copy interpolated flux values from buffer to large element face in the
423424
# correct orientation.
@@ -772,13 +773,13 @@ function calc_mortar_flux_divergence!(surface_flux_values,
772773
surface_integral, dg::DG, cache)
773774
@unpack neighbor_ids, node_indices = cache.mortars
774775
@unpack contravariant_vectors = cache.elements
775-
@unpack fstar_upper_threaded, fstar_lower_threaded = cache
776+
@unpack fstar_primary_upper_threaded, fstar_primary_lower_threaded = cache
776777
index_range = eachnode(dg)
777778

778779
@threaded for mortar in eachmortar(dg, cache)
779780
# Choose thread-specific pre-allocated container
780-
fstar = (fstar_lower_threaded[Threads.threadid()],
781-
fstar_upper_threaded[Threads.threadid()])
781+
fstar = (fstar_primary_lower_threaded[Threads.threadid()],
782+
fstar_primary_upper_threaded[Threads.threadid()])
782783

783784
for position in 1:2
784785
for node in eachnode(dg)
@@ -802,7 +803,7 @@ function calc_mortar_flux_divergence!(surface_flux_values,
802803
# this reuses the hyperbolic version of `mortar_fluxes_to_elements!`
803804
mortar_fluxes_to_elements!(surface_flux_values,
804805
mesh, equations, mortar_l2, dg, cache,
805-
mortar, fstar, u_buffer)
806+
mortar, fstar, fstar, u_buffer)
806807
end
807808

808809
return nothing
@@ -813,7 +814,7 @@ end
813814
# The reasoning is that parabolic fluxes are treated like conservative
814815
# terms (e.g., we compute a viscous conservative "flux") and thus no
815816
# non-conservative terms are present.
816-
@inline function calc_mortar_flux!(fstar,
817+
@inline function calc_mortar_flux!(fstar_primary, fstar_secondary,
817818
mesh::Union{P4estMesh{2}, T8codeMesh{2}},
818819
nonconservative_terms::False,
819820
equations::AbstractEquationsParabolic,
@@ -830,7 +831,8 @@ end
830831
flux_ = 0.5f0 * (u_ll + u_rr)
831832

832833
# Copy flux to buffer
833-
set_node_vars!(fstar[position_index], flux_, equations, dg, node_index)
834+
set_node_vars!(fstar_primary[position_index], flux_, equations, dg, node_index)
835+
set_node_vars!(fstar_secondary[position_index], flux_, equations, dg, node_index)
834836
end
835837

836838
# TODO: parabolic, finish implementing `calc_boundary_flux_gradients!` and `calc_boundary_flux_divergence!`

src/solvers/dgsem_p4est/dg_2d_parallel.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ function calc_mpi_mortar_flux!(surface_flux_values,
209209
surface_integral, dg::DG, cache)
210210
@unpack local_neighbor_ids, local_neighbor_positions, node_indices = cache.mpi_mortars
211211
@unpack contravariant_vectors = cache.elements
212-
@unpack fstar_upper_threaded, fstar_lower_threaded = cache
212+
@unpack fstar_primary_upper_threaded, fstar_primary_lower_threaded = cache
213213
index_range = eachnode(dg)
214214

215215
@threaded for mortar in eachmpimortar(dg, cache)
216216
# Choose thread-specific pre-allocated container
217-
fstar = (fstar_lower_threaded[Threads.threadid()],
218-
fstar_upper_threaded[Threads.threadid()])
217+
fstar = (fstar_primary_lower_threaded[Threads.threadid()],
218+
fstar_primary_upper_threaded[Threads.threadid()])
219219

220220
# Get index information on the small elements
221221
small_indices = node_indices[1, mortar]

0 commit comments

Comments
 (0)