Skip to content

Choose an operator and its order ​

Four choices fix a kernel, gideon_<data>_<op>_<bias><order>: the data you hold, the quantity you want, the side of the stencil, the order of accuracy. Each is settled by the scheme, not by taste; this page says how, and what each choice costs in window width.

The decision table ​

You holdYou wantKernel familyWindow
point values at nodesa derivative at a nodegideon_fd_dN_c<p>centred, q(-S:S)
point values at nodesthe value midway between two nodesgideon_fd_face_c<p>, _bl<p>, _br<p>centred q(1-S:S), upwind-biased q(-k:k) or q(1-k:k+1)
point values at nodesa derivative midway between two nodes (a viscous flux)gideon_fd_face_dN_c<p>q(1-S:S)
point values inside a boundarythe value at the boundary facegideon_fd_face_ur<p>, _ul<p>one side, q(1:p) or q(1-p:0)
cell averagesthe value at a face (the flux a conservative scheme differences)gideon_fv_face_c<p>, _ur<p>, _ul<p>centred q(1-S:S), one side q(1:p) or q(1-p:0)
cell averagesa derivative at a face (a viscous flux)gideon_fv_face_dN_c<p>, _ur<p>, _ul<p>as the face value, wider by the derivative
cell averagesthe average of a derivative over a cellgideon_fv_dN_c<p>, _ur<p>, _ul<p>q(-S:S), q(0:W), q(-W:0)
cell averagesthe point value at the cell centregideon_fv_point_c<p>q(-S:S)
point valuesthe cell averagegideon_fd_average_c<p>q(-S:S)
one stencil per axisgradient, divergence, curl, Laplaciangideon_{fd,fv}_<op>_c<p>(-S:S) per axis

A cell kernel gideon_fv_dN_* is the flux difference of the face kernel of the derivative below, (g(+1/2) − g(−1/2))/ds^N, computed inside: the same value, to the last bit, as differencing the face values yourself (Ghost cells checks it). Call the face kernel when the flux needs work between the reconstruction and the difference (a Riemann solver, an upwind choice per face, a flux function); call the cell kernel when it does not.

FD or FV: the data decide ​

A kernel's row is exact on the data it was derived for. Point values and cell averages of the same function differ by h2u″/24+O(h4), so feeding averages to an FD kernel, or point values to an FV one, adds an O(h2) error whatever the kernel's order. The program below takes the first derivative of sin⁡2πx with sixth-order kernels three ways:

fortran
program cookbook_choose
!< Cookbook, choose an operator: the first derivative of u = sin(2 pi x) on a periodic grid of n cells, sixth-order
!< centred kernels. The FD kernel on point values and the FV kernel on cell averages reach order 6; the FD kernel fed
!< with cell averages (the wrong data) stops at order 2, whatever its own order.
use gideon
implicit none
integer(I4P), parameter :: NGRID = 4                 ! grids of 16, 32, 64, 128 cells
real(R_P),    parameter :: PI = acos(-1._R_P)
real(R_P)               :: h, x, d, err(3,NGRID)     ! step, a centre, a derivative, max error per case and grid
real(R_P)               :: p(-3:3), a(-3:3)          ! point values and averages around one cell, by offset
integer(I4P)            :: n, i, k, o

err = 0._R_P
do k=1, NGRID
   n = 8 * 2**k
   h = 1._R_P / n
   do i=1, n
      x = (i - 0.5_R_P)*h                            ! centre of cell i (periodic: no ghosts needed, u is known)
      do o=-3, 3
         p(o) = sin(2*PI*(x + o*h))                                        ! point values at the centres
         a(o) = (cos(2*PI*(x + (o - 0.5_R_P)*h)) - cos(2*PI*(x + (o + 0.5_R_P)*h)))/(2*PI*h) ! cell averages
      enddo
      ! FD kernel on point values: the derivative at the centre
      call gideon_fd_d1_c6(p, h, d)
      err(1,k) = max(err(1,k), abs(d - 2*PI*cos(2*PI*x)))
      ! FV kernel on cell averages: the average of the derivative over the cell
      call gideon_fv_d1_c6(a, h, d)
      err(2,k) = max(err(2,k), abs(d - (sin(2*PI*(x + h/2)) - sin(2*PI*(x - h/2)))/h))
      ! FD kernel on cell averages, read as point values: the wrong data
      call gideon_fd_d1_c6(a, h, d)
      err(3,k) = max(err(3,k), abs(d - 2*PI*cos(2*PI*x)))
   enddo
enddo

print '(A)', 'd/dx sin(2 pi x), sixth-order centred kernels, max error over the cells'
print '(A)', '     n  fd on points  fv on averages  fd on averages'
do k=1, NGRID
   print '(I6,ES13.3,ES16.3,ES16.3)', 8 * 2**k, err(:,k)
enddo
print '(A)', 'observed orders, log2(e(n/2) / e(n))'
do k=2, NGRID
   print '(I6,F13.2,F16.2,F16.2)', 8 * 2**k, log(err(:,k-1) / err(:,k)) / log(2._R_P)
enddo
endprogram cookbook_choose
text
d/dx sin(2 pi x), sixth-order centred kernels, max error over the cells
     n  fd on points  fv on averages  fd on averages
    16    1.567E-04       1.557E-04       3.968E-02
    32    2.540E-06       2.536E-06       1.004E-02
    64    4.006E-08       4.004E-08       2.520E-03
   128    6.274E-10       6.274E-10       6.306E-04
observed orders, log2(e(n/2) / e(n))
    32         5.95            5.94            1.98
    64         5.99            5.98            1.99
   128         6.00            6.00            2.00

The FD kernel on point values and the FV kernel on averages converge at order 6 (each against its own target: the derivative at the centre, the average of the derivative over the cell). The FD kernel on averages stalls at order 2. To move between the two kinds of data at high order, use the deconvolution kernels (Averages and point values).

Centred or upwind ​

  • Centred (c): the pair form, cm(qm±q−m), makes a first derivative antisymmetric and a second one symmetric exactly: no numerical dissipation (the imaginary part of the modified wavenumber is zero to round-off, Spectral properties). The default for smooth fields, viscous and diffusive terms, the 3-D operators, and the linear part of a hybrid scheme.
  • Upwind (ur, ul): the stencil on one side only. Name it by where the stencil lies: for a flow to the right (positive speed) the upwind side of a face is its left, so gideon_fv_face_ul<p>; for a flow to the left, gideon_fv_face_ur<p>. A solver switches between the two per face on the sign of the speed. The FV stencils are fully one-sided, and only the narrowest are stable advection operators on their own. The modified wavenumber of the left-side cell first derivative, the flux difference of the left-side faces, decides it (gideon_test_spectral, Spectral properties): gideon_fv_d1_ul1 and _ul2 damp every wavenumber of a right-moving wave; gideon_fv_d1_ul3 to _ul9 amplify a band. For _ul3 the real part of its symbol is −(cos⁡ξ−1)2(4cos⁡ξ−1)/3, so it amplifies every wavenumber 0<ξ<arccos⁡(1/4)≈0.42π; the wider ones amplify more, and higher (the right-side twins mirror all this for a left-moving wave). The one-sided rows of 3 to 9 cells are building blocks, as the candidate stencils of a WENO reconstruction are: exact to their order, combined by a scheme that supplies the stability (kept by owner decision). GIDEON provides them; it does not make them a scheme.
  • Upwind-biased (bl, br, point values only): k+1 points on the upwind side of the face and k on the other, order 2k+1, named by the side holding the extra point (gideon_fd_face_bl<p> for a flow to the right). The linear upwind interpolation of point values; on point values the fully one-sided ur/ul face values are extrapolations, for boundary faces (Face values from point values).

The derivative and the order are two numbers ​

The name carries the order of accuracy p; the derivative N is in the operator (d1…d6). For a fixed window, a higher derivative leaves fewer degrees of freedom for accuracy: a centred window of 2S+1 nodes gives order 2S for d1 and d2, 2S−2 for d3 and d4, 2S−4 for d5 and d6. So gideon_fd_d1_c6 reads 7 nodes and gideon_fd_d3_c6 reads 9. The orders are measured by the generator from the row's exact degree, not assumed from the window (The generator). The table below lists, for every operator, its orders and the points of the window of each (order: points):

Operator (dispatcher)DataResultStencilOrders: points in the window
gideon_fd_face_cpoint valuesvalue at the facecentred2: 2, 4: 4, 6: 6, 8: 8, 10: 10
gideon_fd_d1_cpoint valuesd1 at the nodecentred2: 3, 4: 5, 6: 7, 8: 9, 10: 11
gideon_fd_d2_cpoint valuesd2 at the nodecentred2: 3, 4: 5, 6: 7, 8: 9, 10: 11
gideon_fd_d3_cpoint valuesd3 at the nodecentred2: 5, 4: 7, 6: 9, 8: 11
gideon_fd_d4_cpoint valuesd4 at the nodecentred2: 5, 4: 7, 6: 9, 8: 11
gideon_fd_d5_cpoint valuesd5 at the nodecentred2: 7, 4: 9, 6: 11
gideon_fd_d6_cpoint valuesd6 at the nodecentred2: 7, 4: 9, 6: 11
gideon_fd_face_d1_cpoint valuesd1 at the facecentred2: 2, 4: 4, 6: 6, 8: 8, 10: 10
gideon_fd_face_d2_cpoint valuesd2 at the facecentred2: 4, 4: 6, 6: 8, 8: 10
gideon_fd_face_d3_cpoint valuesd3 at the facecentred2: 4, 4: 6, 6: 8, 8: 10
gideon_fd_face_d4_cpoint valuesd4 at the facecentred2: 6, 4: 8, 6: 10
gideon_fd_face_d5_cpoint valuesd5 at the facecentred2: 6, 4: 8, 6: 10
gideon_fd_face_urpoint valuesvalue at the faceright side1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9
gideon_fd_face_ulpoint valuesvalue at the faceleft side1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9
gideon_fd_face_brpoint valuesvalue at the facebiased right3: 3, 5: 5, 7: 7, 9: 9
gideon_fd_face_blpoint valuesvalue at the facebiased left3: 3, 5: 5, 7: 7, 9: 9
gideon_fv_face_ccell averagesvalue at the facecentred2: 2, 4: 4, 6: 6, 8: 8, 10: 10
gideon_fv_face_d1_ccell averagesd1 at the facecentred2: 2, 4: 4, 6: 6, 8: 8, 10: 10
gideon_fv_face_d2_ccell averagesd2 at the facecentred2: 4, 4: 6, 6: 8, 8: 10
gideon_fv_face_d3_ccell averagesd3 at the facecentred2: 4, 4: 6, 6: 8, 8: 10
gideon_fv_face_d4_ccell averagesd4 at the facecentred2: 6, 4: 8, 6: 10
gideon_fv_face_d5_ccell averagesd5 at the facecentred2: 6, 4: 8, 6: 10
gideon_fv_d1_ccell averagesd1 averaged over the cellcentred2: 3, 4: 5, 6: 7, 8: 9, 10: 11
gideon_fv_d2_ccell averagesd2 averaged over the cellcentred2: 3, 4: 5, 6: 7, 8: 9, 10: 11
gideon_fv_d3_ccell averagesd3 averaged over the cellcentred2: 5, 4: 7, 6: 9, 8: 11
gideon_fv_d4_ccell averagesd4 averaged over the cellcentred2: 5, 4: 7, 6: 9, 8: 11
gideon_fv_d5_ccell averagesd5 averaged over the cellcentred2: 7, 4: 9, 6: 11
gideon_fv_d6_ccell averagesd6 averaged over the cellcentred2: 7, 4: 9, 6: 11
gideon_fv_face_urcell averagesvalue at the faceright side1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9
gideon_fv_face_ulcell averagesvalue at the faceleft side1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9
gideon_fv_face_d1_urcell averagesd1 at the faceright side1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9
gideon_fv_face_d1_ulcell averagesd1 at the faceleft side1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9
gideon_fv_face_d2_urcell averagesd2 at the faceright side1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9
gideon_fv_face_d2_ulcell averagesd2 at the faceleft side1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9
gideon_fv_face_d3_urcell averagesd3 at the faceright side1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9
gideon_fv_face_d3_ulcell averagesd3 at the faceleft side1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9
gideon_fv_face_d4_urcell averagesd4 at the faceright side1: 5, 2: 6, 3: 7, 4: 8, 5: 9
gideon_fv_face_d4_ulcell averagesd4 at the faceleft side1: 5, 2: 6, 3: 7, 4: 8, 5: 9
gideon_fv_face_d5_urcell averagesd5 at the faceright side1: 6, 2: 7, 3: 8, 4: 9
gideon_fv_face_d5_ulcell averagesd5 at the faceleft side1: 6, 2: 7, 3: 8, 4: 9
gideon_fv_d1_urcell averagesd1 averaged over the cellright side1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10
gideon_fv_d1_ulcell averagesd1 averaged over the cellleft side1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10
gideon_fv_d2_urcell averagesd2 averaged over the cellright side1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9, 8: 10
gideon_fv_d2_ulcell averagesd2 averaged over the cellleft side1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9, 8: 10
gideon_fv_d3_urcell averagesd3 averaged over the cellright side1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10
gideon_fv_d3_ulcell averagesd3 averaged over the cellleft side1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10
gideon_fv_d4_urcell averagesd4 averaged over the cellright side1: 5, 2: 6, 3: 7, 4: 8, 5: 9, 6: 10
gideon_fv_d4_ulcell averagesd4 averaged over the cellleft side1: 5, 2: 6, 3: 7, 4: 8, 5: 9, 6: 10
gideon_fv_d5_urcell averagesd5 averaged over the cellright side1: 6, 2: 7, 3: 8, 4: 9, 5: 10
gideon_fv_d5_ulcell averagesd5 averaged over the cellleft side1: 6, 2: 7, 3: 8, 4: 9, 5: 10
gideon_fv_d6_urcell averagesd6 averaged over the cellright side1: 7, 2: 8, 3: 9, 4: 10
gideon_fv_d6_ulcell averagesd6 averaged over the cellleft side1: 7, 2: 8, 3: 9, 4: 10
gideon_fv_face_brcell averagesvalue at the facebiased right3: 3, 5: 5, 7: 7, 9: 9
gideon_fv_face_blcell averagesvalue at the facebiased left3: 3, 5: 5, 7: 7, 9: 9
gideon_fv_point_ccell averagespoint value at the cell centrecentred4: 3, 6: 5, 8: 7, 10: 9, 12: 11
gideon_fd_average_cpoint valuescell averagecentred4: 3, 6: 5, 8: 7, 10: 9, 12: 11
gideon_fd_face_diss_cpoint valuesundivided difference at the face (the order: of the dissipation)centred2: 2, 4: 4, 6: 6, 8: 8, 10: 10
gideon_fv_face_diss_ccell averagesundivided difference at the face (the order: of the dissipation)centred2: 2, 4: 4, 6: 6, 8: 8, 10: 10
gideon_fd_face_diss_brpoint valuesdissipation part of the biased face value (the order: the biased value's)biased right3: 4, 5: 6, 7: 8, 9: 10
gideon_fd_face_diss_blpoint valuesdissipation part of the biased face value (the order: the biased value's)biased left3: 4, 5: 6, 7: 8, 9: 10
gideon_fv_face_diss_brcell averagesdissipation part of the biased face value (the order: the biased value's)biased right3: 4, 5: 6, 7: 8, 9: 10
gideon_fv_face_diss_blcell averagesdissipation part of the biased face value (the order: the biased value's)biased left3: 4, 5: 6, 7: 8, 9: 10
gideon_fd_filter_cpoint valuesfiltered value at the nodecentred2: 3, 4: 5, 6: 7, 8: 9, 10: 11
gideon_fv_filter_ccell averagesfiltered cell averagecentred2: 3, 4: 5, 6: 7, 8: 9, 10: 11

Which order ​

The error of a kernel of order p at step h is Chp|u(N+p)|, with C the exact leading-error constant the generator derives (kerror in the test registry). Higher p pays off while u is resolved and its error is above the round-off floor, about ε∑k|ck|max|q|/hN:

  • Resolution. For a mode of wavenumber k, the gain from one order to the next is a factor of order (kh)2: at four points per wavelength (kh=π/2) a wider stencil gains little. Order 6 to 10 pays off for well resolved turbulence or wave propagation; at under-resolved scales the dispersion error (the modified wavenumber) decides, Spectral properties.
  • Round-off. The floor grows like h−N: a d4 or d6 at a small step reaches it early, in R4P first (Single and quadruple precision).
  • Ghosts and cost. The window sets the halo (Ghost cells) and the flops: one multiply-add per pair for a centred kernel, per cell for an upwind one.
  • Run-time choice. When the order is an input, one dispatcher covers every order of an operator, at a measured 9 to 18 % over the kernel (A run-time order, fast).

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