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 hold | You want | Kernel family | Window |
|---|---|---|---|
| point values at nodes | a derivative at a node | gideon_fd_dN_c<p> | centred, q(-S:S) |
| point values at nodes | the value midway between two nodes | gideon_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 nodes | a derivative midway between two nodes (a viscous flux) | gideon_fd_face_dN_c<p> | q(1-S:S) |
| point values inside a boundary | the value at the boundary face | gideon_fd_face_ur<p>, _ul<p> | one side, q(1:p) or q(1-p:0) |
| cell averages | the 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 averages | a 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 averages | the average of a derivative over a cell | gideon_fv_dN_c<p>, _ur<p>, _ul<p> | q(-S:S), q(0:W), q(-W:0) |
| cell averages | the point value at the cell centre | gideon_fv_point_c<p> | q(-S:S) |
| point values | the cell average | gideon_fd_average_c<p> | q(-S:S) |
| one stencil per axis | gradient, divergence, curl, Laplacian | gideon_{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
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_choosed/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.00The 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,, 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, sogideon_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_ul1and_ul2damp every wavenumber of a right-moving wave;gideon_fv_d1_ul3to_ul9amplify a band. For_ul3the real part of its symbol is, so it amplifies every wavenumber ; 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):points on the upwind side of the face and on the other, order , 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-sidedur/ulface 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 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) | Data | Result | Stencil | Orders: points in the window |
|---|---|---|---|---|
gideon_fd_face_c | point values | value at the face | centred | 2: 2, 4: 4, 6: 6, 8: 8, 10: 10 |
gideon_fd_d1_c | point values | d1 at the node | centred | 2: 3, 4: 5, 6: 7, 8: 9, 10: 11 |
gideon_fd_d2_c | point values | d2 at the node | centred | 2: 3, 4: 5, 6: 7, 8: 9, 10: 11 |
gideon_fd_d3_c | point values | d3 at the node | centred | 2: 5, 4: 7, 6: 9, 8: 11 |
gideon_fd_d4_c | point values | d4 at the node | centred | 2: 5, 4: 7, 6: 9, 8: 11 |
gideon_fd_d5_c | point values | d5 at the node | centred | 2: 7, 4: 9, 6: 11 |
gideon_fd_d6_c | point values | d6 at the node | centred | 2: 7, 4: 9, 6: 11 |
gideon_fd_face_d1_c | point values | d1 at the face | centred | 2: 2, 4: 4, 6: 6, 8: 8, 10: 10 |
gideon_fd_face_d2_c | point values | d2 at the face | centred | 2: 4, 4: 6, 6: 8, 8: 10 |
gideon_fd_face_d3_c | point values | d3 at the face | centred | 2: 4, 4: 6, 6: 8, 8: 10 |
gideon_fd_face_d4_c | point values | d4 at the face | centred | 2: 6, 4: 8, 6: 10 |
gideon_fd_face_d5_c | point values | d5 at the face | centred | 2: 6, 4: 8, 6: 10 |
gideon_fd_face_ur | point values | value at the face | right side | 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 |
gideon_fd_face_ul | point values | value at the face | left side | 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 |
gideon_fd_face_br | point values | value at the face | biased right | 3: 3, 5: 5, 7: 7, 9: 9 |
gideon_fd_face_bl | point values | value at the face | biased left | 3: 3, 5: 5, 7: 7, 9: 9 |
gideon_fv_face_c | cell averages | value at the face | centred | 2: 2, 4: 4, 6: 6, 8: 8, 10: 10 |
gideon_fv_face_d1_c | cell averages | d1 at the face | centred | 2: 2, 4: 4, 6: 6, 8: 8, 10: 10 |
gideon_fv_face_d2_c | cell averages | d2 at the face | centred | 2: 4, 4: 6, 6: 8, 8: 10 |
gideon_fv_face_d3_c | cell averages | d3 at the face | centred | 2: 4, 4: 6, 6: 8, 8: 10 |
gideon_fv_face_d4_c | cell averages | d4 at the face | centred | 2: 6, 4: 8, 6: 10 |
gideon_fv_face_d5_c | cell averages | d5 at the face | centred | 2: 6, 4: 8, 6: 10 |
gideon_fv_d1_c | cell averages | d1 averaged over the cell | centred | 2: 3, 4: 5, 6: 7, 8: 9, 10: 11 |
gideon_fv_d2_c | cell averages | d2 averaged over the cell | centred | 2: 3, 4: 5, 6: 7, 8: 9, 10: 11 |
gideon_fv_d3_c | cell averages | d3 averaged over the cell | centred | 2: 5, 4: 7, 6: 9, 8: 11 |
gideon_fv_d4_c | cell averages | d4 averaged over the cell | centred | 2: 5, 4: 7, 6: 9, 8: 11 |
gideon_fv_d5_c | cell averages | d5 averaged over the cell | centred | 2: 7, 4: 9, 6: 11 |
gideon_fv_d6_c | cell averages | d6 averaged over the cell | centred | 2: 7, 4: 9, 6: 11 |
gideon_fv_face_ur | cell averages | value at the face | right side | 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 |
gideon_fv_face_ul | cell averages | value at the face | left side | 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 |
gideon_fv_face_d1_ur | cell averages | d1 at the face | right side | 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9 |
gideon_fv_face_d1_ul | cell averages | d1 at the face | left side | 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9 |
gideon_fv_face_d2_ur | cell averages | d2 at the face | right side | 1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9 |
gideon_fv_face_d2_ul | cell averages | d2 at the face | left side | 1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9 |
gideon_fv_face_d3_ur | cell averages | d3 at the face | right side | 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9 |
gideon_fv_face_d3_ul | cell averages | d3 at the face | left side | 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9 |
gideon_fv_face_d4_ur | cell averages | d4 at the face | right side | 1: 5, 2: 6, 3: 7, 4: 8, 5: 9 |
gideon_fv_face_d4_ul | cell averages | d4 at the face | left side | 1: 5, 2: 6, 3: 7, 4: 8, 5: 9 |
gideon_fv_face_d5_ur | cell averages | d5 at the face | right side | 1: 6, 2: 7, 3: 8, 4: 9 |
gideon_fv_face_d5_ul | cell averages | d5 at the face | left side | 1: 6, 2: 7, 3: 8, 4: 9 |
gideon_fv_d1_ur | cell averages | d1 averaged over the cell | right side | 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10 |
gideon_fv_d1_ul | cell averages | d1 averaged over the cell | left side | 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10 |
gideon_fv_d2_ur | cell averages | d2 averaged over the cell | right side | 1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9, 8: 10 |
gideon_fv_d2_ul | cell averages | d2 averaged over the cell | left side | 1: 3, 2: 4, 3: 5, 4: 6, 5: 7, 6: 8, 7: 9, 8: 10 |
gideon_fv_d3_ur | cell averages | d3 averaged over the cell | right side | 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10 |
gideon_fv_d3_ul | cell averages | d3 averaged over the cell | left side | 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10 |
gideon_fv_d4_ur | cell averages | d4 averaged over the cell | right side | 1: 5, 2: 6, 3: 7, 4: 8, 5: 9, 6: 10 |
gideon_fv_d4_ul | cell averages | d4 averaged over the cell | left side | 1: 5, 2: 6, 3: 7, 4: 8, 5: 9, 6: 10 |
gideon_fv_d5_ur | cell averages | d5 averaged over the cell | right side | 1: 6, 2: 7, 3: 8, 4: 9, 5: 10 |
gideon_fv_d5_ul | cell averages | d5 averaged over the cell | left side | 1: 6, 2: 7, 3: 8, 4: 9, 5: 10 |
gideon_fv_d6_ur | cell averages | d6 averaged over the cell | right side | 1: 7, 2: 8, 3: 9, 4: 10 |
gideon_fv_d6_ul | cell averages | d6 averaged over the cell | left side | 1: 7, 2: 8, 3: 9, 4: 10 |
gideon_fv_face_br | cell averages | value at the face | biased right | 3: 3, 5: 5, 7: 7, 9: 9 |
gideon_fv_face_bl | cell averages | value at the face | biased left | 3: 3, 5: 5, 7: 7, 9: 9 |
gideon_fv_point_c | cell averages | point value at the cell centre | centred | 4: 3, 6: 5, 8: 7, 10: 9, 12: 11 |
gideon_fd_average_c | point values | cell average | centred | 4: 3, 6: 5, 8: 7, 10: 9, 12: 11 |
gideon_fd_face_diss_c | point values | undivided difference at the face (the order: of the dissipation) | centred | 2: 2, 4: 4, 6: 6, 8: 8, 10: 10 |
gideon_fv_face_diss_c | cell averages | undivided difference at the face (the order: of the dissipation) | centred | 2: 2, 4: 4, 6: 6, 8: 8, 10: 10 |
gideon_fd_face_diss_br | point values | dissipation part of the biased face value (the order: the biased value's) | biased right | 3: 4, 5: 6, 7: 8, 9: 10 |
gideon_fd_face_diss_bl | point values | dissipation part of the biased face value (the order: the biased value's) | biased left | 3: 4, 5: 6, 7: 8, 9: 10 |
gideon_fv_face_diss_br | cell averages | dissipation part of the biased face value (the order: the biased value's) | biased right | 3: 4, 5: 6, 7: 8, 9: 10 |
gideon_fv_face_diss_bl | cell averages | dissipation part of the biased face value (the order: the biased value's) | biased left | 3: 4, 5: 6, 7: 8, 9: 10 |
gideon_fd_filter_c | point values | filtered value at the node | centred | 2: 3, 4: 5, 6: 7, 8: 9, 10: 11 |
gideon_fv_filter_c | cell averages | filtered cell average | centred | 2: 3, 4: 5, 6: 7, 8: 9, 10: 11 |
Which order
The error of a kernel of order kerror in the test registry). Higher
- Resolution. For a mode of wavenumber
, the gain from one order to the next is a factor of order : at four points per wavelength ( ) 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
: 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).