Skip to content

Face values and derivatives from point values ​

Problem. A finite-difference solver holds point values ui at the nodes and needs quantities at the faces i+1/2 between them: the gradient of a viscous flux, the face value an upwind flux reads, or the value at a boundary face that no node sits on. Written by hand, each is a row of fractions copied from a paper (FLUME writes its viscous row (27(W1−W0)−(W2−W−1))/24Δx inline); GIDEON derives them by their meaning, like every other row.

The kernels ​

All read point values at x=o−1/2 around the face x=0 (offset 0 is node i, offset 1 node i+1), so the section for the face i+1/2 is u(i+LO:i+HI):

KernelReturnsWindowOrders
gideon_fd_face_c<p>the value at the face, centredq(1-S:S)2–10
gideon_fd_face_dN_c<p>the N-th derivative at the face, centred (N = 1 … 5)q(1-S:S)d1 2–10; d2, d3 2–8; d4, d5 2–6
gideon_fd_face_bl<p>the value at the face, upwind-biased: k+1 points on its left, k on its rightq(-k:k)3, 5, 7, 9
gideon_fd_face_br<p>the same, one point more on the rightq(1-k:k+1)3, 5, 7, 9
gideon_fd_face_ur<p>the value at the face from the S points on its right only (extrapolation)q(1:S)1–9
gideon_fd_face_ul<p>the same from the points on its leftq(1-S:0)1–9

gideon_fd_face_d1_c4 is FLUME's row, 98(q1−q0)−124(q2−q−1), divided by the step; gideon_fd_face_bl3 is (−q−1+6q0+3q1)/8 and gideon_fd_face_bl5(3q−2−20q−1+90q0+60q1−5q2)/128, the linear upwind interpolation of point values that a WENO scheme on point values starts from. The left-side and left-biased kernels are the mirrors of the right ones (o→1−o), proven by the generator and tested bitwise (Mirrors and symmetries). Each has a run-time order dispatcher: gideon_fd_face_d1_c(order, ...), gideon_fd_face_bl(order, ...), … (API).

Which one ​

  • A viscous or diffusive flux μ∂u/∂x at the face: gideon_fd_face_d1_c<p>, the same order as the convective part. It reads the nodes on both sides, so it is centred by construction; the second and higher face derivatives serve hyperviscosity and the fourth-order dissipation terms.
  • A convective face value: centred (gideon_fd_face_c<p>) where no upwinding is wanted, as in a split or energy-preserving form; upwind-biased (bl when the flow goes to the right, br to the left) where the scheme needs the dissipation of the upwind side. A biased stencil of 2k+1 points is order 2k+1, one less than the centred stencil of 2k+2 points, and its error is larger at equal width (below): the price of the bias, which damps the shortest waves instead of letting them disperse. That trade is the same one the FV upwind kernels make (Spectral properties).
  • A boundary face where only interior nodes exist: gideon_fd_face_ur<p> at a left boundary (the nodes lie to its right), ul at a right one. One-sided extrapolation amplifies the data's noise as its width grows: the sum of the absolute weights is 2 for ur2, 7/2 for ur3, 6 for ur4 ((35,−35,21,−5)/16) and about 110 for ur9, against 5/4 for the centred c4. A closure takes the lowest order that keeps the scheme's global order, as for any one-sided stencil.

Code ​

The three uses, each measured by halving the step: the viscous derivative at every face of a periodic grid; centred and upwind-biased face values; the value at the boundary face x=0 from the nodes x=h/2,3h/2,… inside:

fortran
!< Cookbook, face derivatives and face values from point values: the viscous flux, upwind-biased interpolation and
!< one-sided extrapolation to a boundary face, each with its error halving the step.
program cookbook_face_from_points
!< Cookbook, face derivatives and face values from point values: the viscous flux, upwind-biased interpolation and
!< one-sided extrapolation to a boundary face, each with its error halving the step.
use gideon
implicit none
real(R_P), parameter :: PI = acos(-1._R_P)
integer              :: k
real(R_P)            :: e1, e2

print '(A)', 'the first derivative at the faces i+1/2 of a periodic grid (the viscous flux), max error on sin(2 pi x)'
do k=1, 3
   e1 = viscous(k, 32) ; e2 = viscous(k, 64)
   print '(A,I0,A,2ES11.3,A,F5.2)', '  gideon_fd_face_d1_c', 2*k, '  N = 32, 64:', e1, e2, '   observed order ', &
                                    log(e1/e2)/log(2._R_P)
enddo
print '(A)', 'the value at the faces, centred and upwind-biased, max error on sin(2 pi x)'
do k=1, 4
   e1 = interpolation(k, 32) ; e2 = interpolation(k, 64)
   print '(A,A,2ES11.3,A,F5.2)', '  ', kernel_i(k), e1, e2, '   observed order ', log(e1/e2)/log(2._R_P)
enddo
print '(A)', 'the value at the boundary face x = 0 from the points inside, exp(x) at x = h/2, 3h/2, ...'
do k=2, 4
   e1 = extrapolation(k, 32) ; e2 = extrapolation(k, 64)
   print '(A,I0,A,2ES11.3,A,F5.2)', '  gideon_fd_face_ur', k, '        N = 32, 64:', e1, e2, '   observed order ', &
                                    log(e1/e2)/log(2._R_P)
enddo
contains
   function viscous(k, n) result(e)
   !< Max error of the face first derivative of order 2k on n points, nodes x_i = i h.
   integer, intent(in) :: k, n
   real(R_P)           :: e, u(-4:n+5), h, d
   integer             :: i
   h = 1._R_P/n
   do i=-4, n+5
      u(i) = sin(2*PI*i*h)
   enddo
   e = 0._R_P
   do i=0, n-1 ! the face between nodes i and i+1: offset 0 is node i, offset 1 node i+1
      select case(k)
      case(1) ; call gideon_fd_face_d1_c2(u(i:i+1), h, d)
      case(2) ; call gideon_fd_face_d1_c4(u(i-1:i+2), h, d)     ! FLUME's (27(W1-W0) - (W2-W-1))/(24 dx)
      case(3) ; call gideon_fd_face_d1_c6(u(i-2:i+3), h, d)
      endselect
      e = max(e, abs(d - 2*PI*cos(2*PI*(i + 0.5_R_P)*h)))
   enddo
   endfunction viscous

   function kernel_i(k) result(name)
   !< The kernel of the k-th interpolation.
   integer, intent(in)     :: k
   character(30)           :: name
   character(30), parameter :: NAMES(4) = [character(30) :: 'gideon_fd_face_c4  N = 32, 64:', &
                                           'gideon_fd_face_bl3 N = 32, 64:', 'gideon_fd_face_bl5 N = 32, 64:', &
                                           'gideon_fd_face_c6  N = 32, 64:']
   name = NAMES(k)
   endfunction kernel_i

   function interpolation(k, n) result(e)
   !< Max error of the k-th face interpolation on n points.
   integer, intent(in) :: k, n
   real(R_P)           :: e, u(-4:n+5), h, f
   integer             :: i
   h = 1._R_P/n
   do i=-4, n+5
      u(i) = sin(2*PI*i*h)
   enddo
   e = 0._R_P
   do i=0, n-1
      select case(k)
      case(1) ; call gideon_fd_face_c4(u(i-1:i+2), f)  ! centred, four points
      case(2) ; call gideon_fd_face_bl3(u(i-1:i+1), f) ! two points left of the face, one right: upwind for a > 0
      case(3) ; call gideon_fd_face_bl5(u(i-2:i+2), f) ! three left, two right
      case(4) ; call gideon_fd_face_c6(u(i-2:i+3), f)  ! centred, six points
      endselect
      e = max(e, abs(f - sin(2*PI*(i + 0.5_R_P)*h)))
   enddo
   endfunction interpolation

   function extrapolation(k, n) result(e)
   !< Error of the one-sided value at x = 0 from the k points x = h/2, 3h/2, ... (offsets 1..k).
   integer, intent(in) :: k, n
   real(R_P)           :: e, u(1:n), h, f
   integer             :: j
   h = 1._R_P/n
   do j=1, n
      u(j) = exp((j - 0.5_R_P)*h)
   enddo
   select case(k)
   case(2) ; call gideon_fd_face_ur2(u(1:2), f)
   case(3) ; call gideon_fd_face_ur3(u(1:3), f)
   case(4) ; call gideon_fd_face_ur4(u(1:4), f)
   endselect
   e = abs(f - 1._R_P)
   endfunction extrapolation
endprogram cookbook_face_from_points
text
the first derivative at the faces i+1/2 of a periodic grid (the viscous flux), max error on sin(2 pi x)
  gideon_fd_face_d1_c2  N = 32, 64:  1.004E-02  2.520E-03   observed order  1.99
  gideon_fd_face_d1_c4  N = 32, 64:  4.347E-05  2.731E-06   observed order  3.99
  gideon_fd_face_d1_c6  N = 32, 64:  2.488E-07  3.915E-09   observed order  5.99
the value at the faces, centred and upwind-biased, max error on sin(2 pi x)
  gideon_fd_face_c4  N = 32, 64:  3.456E-05  2.173E-06   observed order  3.99
  gideon_fd_face_bl3 N = 32, 64:  4.720E-04  5.910E-05   observed order  3.00
  gideon_fd_face_bl5 N = 32, 64:  3.404E-06  1.067E-07   observed order  4.99
  gideon_fd_face_c6  N = 32, 64:  2.768E-07  4.360E-09   observed order  5.99
the value at the boundary face x = 0 from the points inside, exp(x) at x = h/2, 3h/2, ...
  gideon_fd_face_ur2        N = 32, 64:  3.739E-04  9.251E-05   observed order  2.02
  gideon_fd_face_ur3        N = 32, 64:  9.879E-06  1.213E-06   observed order  3.03
  gideon_fd_face_ur4        N = 32, 64:  2.742E-07  1.671E-08   observed order  4.04

Every kernel shows its order. The five-point bl5 is less accurate than the four-point centred c4 on this smooth field, and bl3 than both: the upwind bias costs accuracy where nothing needs damping, and buys stability where something does. The ghost cells each kernel needs follow from its window (Ghost cells for a window).

Reference. Roadmap issue #1, phase 2 (2.1, 2.2). The rows are derived in exact rationals by the generator (The generator); their orders are observed in quadruple precision with every other kernel (Orders of accuracy).

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