Skip to content

Dissipation dialled by a sensor ​

Problem. A central scheme does not damp what it cannot resolve: at a discontinuity it rings, and the ringing travels. An upwind-biased scheme damps everywhere, the smooth waves included. A hybrid wants the central scheme where the solution is smooth and the dissipation where it is not, with a sensor between the two. GIDEON writes the dissipation as a separate kernel, so the dial is one multiplication.

The kernels ​

KernelReturnsWindow
gideon_<data>_face_diss_c<2k>δ2k−1 at the face: the undivided odd difference, the flux of a dissipation of order 2kq(1-k:k)
gideon_<data>_face_diss_bl<p>the dissipation part of the left-biased face value: face_bl<p> − face_c<p+1> =Cδpq(-k:k+1), p=2k+1
gideon_<data>_face_diss_br<p>the same for the right-biased one, −Cδpthe same

The split is exact (proven in rationals by the generator, C7): gideon_fv_face_bl5 = gideon_fv_face_c6 + gideon_fv_face_diss_bl5, with gideon_fv_face_diss_bl5=−δ5/60 (FV_BDISS_S2). So

fortran
call gideon_fv_face_c6(u(i-2:i+3), c)          ! central, order 6
call gideon_fv_face_diss_bl5(u(i-2:i+3), d)    ! the dissipation of the upwind-biased bl5 (flow to the right)
f(i) = c + sigma(i)*d                          ! sigma = 0: central (bitwise); sigma = 1: bl5; between: a blend

Jameson, Schmidt and Turkel's blend of the second and fourth differences is written with the two smallest differences: f=fc−(ε2δ1−ε4δ3), δ1 = gideon_fv_face_diss_c2, δ3 = gideon_fv_face_diss_c4; the switch ε2, ε4 is the caller's.

Code ​

A smooth bump and a square wave advected once around a periodic line (ut+ux=0, 100 cells, SSP-RK3 from SELAH, CFL 0.4), with four face values: the central c6; c6 plus the whole dissipation of bl5 (that is bl5); the same with the dissipation scaled by a sensor (the normalised second difference of the averages, four times, clipped at 1); and JST on the central c2 (Jameson's k2=1/2, k4=1/32):

fortran
program cookbook_dissipation
!< Cookbook: dissipation dialled by a sensor. A smooth bump and a square wave advected once around a periodic line
!< (u_t + u_x = 0, cell averages, SSP-RK3: SELAH's) with four face values: centred of order 6; the centred one plus the dissipation part of the
!< upwind-biased bl5 (that is bl5 itself); the same with the dissipation scaled by a sensor; and Jameson-Schmidt-Turkel's
!< blend of the second and fourth face differences on the centred value of order 2.
use gideon
use selah, only : stepper, box, box_interior, SCHEME_SSP_33, FORM_SHU_OSHER_2R   ! the time integrator: SELAH's
implicit none
integer(I4P), parameter :: N = 100, G = 3       ! cells, ghost cells
real(R_P),    parameter :: CFL = 0.4_R_P
character(*), parameter :: NAMES(4) = [character(16) :: 'central c6', 'biased bl5', 'sensor c6 + s d', 'JST on c2']
real(R_P)    :: u(1-G:N+G), u0(N), x, h, dt, mass0
real(R_P), pointer :: r(:)
integer(I4P) :: scheme, i, step, nsteps, k
type(stepper) :: st
type(box)     :: bx

h = 1._R_P/N
dt = CFL*h
nsteps = nint(1._R_P/dt)
dt = 1._R_P/nsteps                                ! exactly one period
do i=1, N ! a Gaussian bump on [0, 1/2), a square wave on [0.6, 0.85]: cell averages (the bump's by a 5-point Gauss rule)
   x = (i - 0.5_R_P)*h
   u0(i) = merge(1._R_P, 0._R_P, x > 0.6_R_P .and. x < 0.85_R_P) + bump_average(x - h/2, x + h/2)
enddo
print '(A)', 'a bump and a square wave advected once around 100 cells, CFL 0.4, SSP-RK3'
print '(A)', 'scheme           bump error  square overshoot  undershoot  mass conserved'
bx = box_interior(lb=[1_I4P-G], ub=[N+G], ngc=G, components=.false.)    ! the cells 1..N of u(1-G:N+G)
call st%initialize(SCHEME_SSP_33, FORM_SHU_OSHER_2R, lb=[1_I4P-G], ub=[N+G], components=.false.)
do scheme=1, 4
   u(1:N) = u0
   mass0 = sum(u0)
   do step=1, nsteps                              ! SSP-RK3: SELAH's SCHEME_SSP_33, the stage state is u itself
      call st%begin_step(bx, u)
      do k=1, st%stages()
         call st%begin_stage(k, bx, dt, u)
         call st%rhs_register_view(r)
         call residual(scheme, u, r(1:N))
         call st%end_stage(k, bx, dt, u)
      enddo
      call st%finish_step(bx, dt, u)
   enddo
   print '(A16,F11.5,F18.5,F12.5,L16)', NAMES(scheme), sum(abs(u(1:N/2) - u0(1:N/2)))*h, &
      maxval(u(N/2+1:N)) - 1, max(0._R_P, -minval(u(N/2+1:N))), abs(sum(u(1:N)) - mass0) < 1.e-12_R_P*N
enddo
call st%destroy
contains
   pure function bump_average(a, b) result(v)
   !< The average over [a, b] of exp(-((x - 1/4)/0.06)^2), a 5-point Gauss-Legendre rule (exact to 1e-14 here).
   real(R_P), intent(in) :: a, b
   real(R_P)             :: v
   real(R_P), parameter  :: XG(5) = [-0.9061798459386640_R_P, -0.5384693101056831_R_P, 0._R_P, &
                                      0.5384693101056831_R_P, 0.9061798459386640_R_P]
   real(R_P), parameter  :: WG(5) = [0.2369268850561891_R_P, 0.4786286704993665_R_P, 0.5688888888888889_R_P, &
                                      0.4786286704993665_R_P, 0.2369268850561891_R_P]
   v = sum(WG*exp(-(((a + b)/2 + (b - a)/2*XG - 0.25_R_P)/0.06_R_P)**2))/2
   endfunction bump_average

   subroutine residual(scheme, u, res)
   !< The residual of the flux difference: res = -(f(i+1/2) - f(i-1/2))/h, the face values GIDEON's.
   integer(I4P), intent(in)    :: scheme
   real(R_P),    intent(inout) :: u(1-G:N+G)
   real(R_P),    intent(out)   :: res(N)
   real(R_P)                   :: f(0:N), c, d, s, d1, d3, e2, e4, nu(0:N+1)
   integer(I4P)                :: i
   u(1-G:0) = u(N-G+1:N) ; u(N+1:N+G) = u(1:G)   ! periodic ghosts
   do i=0, N+1                                    ! a pressure-like switch: the normalised second difference
      nu(i) = abs(u(i+1) - 2*u(i) + u(i-1))/(abs(u(i+1)) + 2*abs(u(i)) + abs(u(i-1)) + 1.e-12_R_P)
   enddo
   do i=0, N                                      ! the face i+1/2, between cells i and i+1
      select case(scheme)
      case(1)
         call gideon_fv_face_c6(u(i-2:i+3), f(i))
      case(2, 3)
         call gideon_fv_face_c6(u(i-2:i+3), c)
         call gideon_fv_face_diss_bl5(u(i-2:i+3), d) ! bl5 = c6 + d, exactly in rationals
         s = 1._R_P
         if (scheme == 3) s = min(1._R_P, 4*max(nu(i), nu(i+1)))
         f(i) = c + s*d
      case(4)
         call gideon_fv_face_c2(u(i:i+1), c)
         call gideon_fv_face_diss_c2(u(i:i+1), d1)     ! delta^1 = u(i+1) - u(i)
         call gideon_fv_face_diss_c4(u(i-1:i+2), d3)   ! delta^3
         e2 = 0.5_R_P*max(nu(i), nu(i+1))              ! Jameson's k2 = 1/2, k4 = 1/32, the wave speed 1
         e4 = max(0._R_P, 1._R_P/32 - e2)
         f(i) = c - (e2*d1 - e4*d3)
      endselect
   enddo
   do i=1, N
      res(i) = -(f(i) - f(i-1))/h
   enddo
   endsubroutine residual
endprogram cookbook_dissipation
text
a bump and a square wave advected once around 100 cells, CFL 0.4, SSP-RK3
scheme           bump error  square overshoot  undershoot  mass conserved
central c6          0.01415           0.15593     0.12166               T
biased bl5          0.00082           0.08175     0.08179               T
sensor c6 + s d     0.00053           0.10387     0.09296               T
JST on c2           0.02472           0.21184     0.00000               T
  • Central. The ringing of the square wave spreads into the whole line: the bump, far from any discontinuity, ends with an error 17 times the biased scheme's.
  • Biased (sigma = 1). The ringing is damped, and so, slightly, is the bump.
  • Sensor. The bump keeps the central scheme (its second differences are small, the sensor stays near 0) and is the most accurate of the four; the square wave gets most of the dissipation, its overshoot between the central and the biased scheme's. A sharper sensor, or a nonlinear value where it fires, is the next step (Compact-WENO rows).
  • JST. The second difference switched on at the square wave removes the undershoot entirely, but not the overshoot, the largest of the four; the bump, on a second-order central scheme with fourth-order background dissipation, is the least accurate. JST was built for pressure switches on shocks, not for a linear square wave: the row shows the blend written with GIDEON's differences, not a tuned scheme.
  • Every scheme conserves the total exactly: one face value per face, a flux difference per cell.

Reference. Roadmap issue #2, phase 1 (1.1–1.3). The split and its constants: Operators. The sensor and the blend are the caller's: GIDEON provides the operators (decision D7).

Released under your choice of GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT.