Skip to content

Averages and point values ​

Problem. A finite-volume solver holds cell averages u¯i, but some of its work needs point values: a nonlinear flux, a source term, an initial condition given as a function, a diagnostic compared with point data. The two differ by h2u″/24+O(h4); ignoring the difference makes the step second order whatever the order of the reconstruction around it.

The kernels ​

KernelFromToWindowOrder
gideon_fv_point_c<p>cell averagesthe point value at the centre of cell 0q(-S:S)p=2S+2: 4, 6, 8, 10, 12
gideon_fd_average_c<p>point values at the cell centresthe average over cell 0q(-S:S)the same

Both are symmetric rows in pair form, derived by their meaning: gideon_fv_point_c4 is exact on every cubic, ui=1312u¯i−124(u¯i+1+u¯i−1), i.e. u¯i−δ2u¯i/24; gideon_fd_average_c4 is 1112ui+124(ui+1+ui−1). They are each other's inverse to their order, not exactly: a round trip returns the data plus an O(hp) error. ADAM's compute_avg_to_point and compute_point_to_avg are the same rows (bitwise, Replace ADAM's FDV calls).

When an FV solver needs them ​

  • A nonlinear flux. The average of f(u) over a cell is not f(u¯): for f=u2/2 they differ by h2(u′)2/24+O(h4). The route to order 4 and above: deconvolve the averages to point values, evaluate f at the points, convolve back to the average of f. Each step costs one window, so the ghost layer is two half-widths (here 2 for order 4, 4 for order 6).
  • Initial conditions. A solution given as a function is sampled at the centres and averaged with gideon_fd_average_c<p>, at the order of the scheme; where the cell integral is known in closed form, that is exact.
  • Diagnostics and output. A plot, a probe, an error norm against a point-wise reference: gideon_fv_point_c<p> first, or the comparison carries the O(h2) difference.

In more dimensions the average over a box is the product of the three 1-D averages, so the 1-D kernels applied along each axis in turn give the box conversion at the same order.

Code: the average of u2/2 ​

The cell averages of u=sin⁡2πx on a periodic grid, and the average of f=u2/2 over each cell three ways: f(u¯); deconvolution, f at the points and convolution at order 4; the same at order 6:

fortran
program cookbook_deconvolution
!< Cookbook, averages and point values: the cell average of a nonlinear flux f(u) = u^2/2 from the cell averages of
!< u = sin(2 pi x). f(<u>) is second order whatever the reconstruction that follows; deconvolving to point values
!< (gideon_fv_point_c<p>), evaluating f there and convolving back (gideon_fd_average_c<p>) is of order p.
use gideon
implicit none
integer(I4P), parameter :: NGRID = 4, G = 4          ! grids of 16..128 cells; ghosts: two windows of half-width 2
real(R_P),    parameter :: PI = acos(-1._R_P)
real(R_P), allocatable  :: a(:), fp4(:), fp6(:)      ! averages of u; f at the point values, orders 4 and 6
real(R_P)               :: h, v, fex, err(3,NGRID)
integer(I4P)            :: n, i, k

err = 0._R_P
do k=1, NGRID
   n = 8 * 2**k
   h = 1._R_P / n
   allocate(a(1-G:n+G), fp4(-1:n+2), fp6(-1:n+2))
   do i=1-G, n+G                                     ! cell i spans [(i - 1) h, i h]; periodic, so the ghosts are known
      a(i) = (cos(2*PI*(i - 1)*h) - cos(2*PI*i*h))/(2*PI*h)
   enddo
   do i=-1, n+2                                      ! point values at the centres, then f there
      call gideon_fv_point_c4(a(i-1:i+1), v) ; fp4(i) = v**2/2
      call gideon_fv_point_c6(a(i-2:i+2), v) ; fp6(i) = v**2/2
   enddo
   do i=1, n
      ! exact <f> = (1 - <cos(4 pi x)>)/4 over the cell
      fex = (1 - (sin(4*PI*i*h) - sin(4*PI*(i - 1)*h))/(4*PI*h))/4
      err(1,k) = max(err(1,k), abs(a(i)**2/2 - fex))  ! f(<u>)
      call gideon_fd_average_c4(fp4(i-1:i+1), v) ; err(2,k) = max(err(2,k), abs(v - fex))
      call gideon_fd_average_c6(fp6(i-2:i+2), v) ; err(3,k) = max(err(3,k), abs(v - fex))
   enddo
   deallocate(a, fp4, fp6)
enddo

print '(A)', 'cell average of u^2/2, u = sin(2 pi x), max error over the cells'
print '(A)', '     n     f(<u>)   order 4   order 6'
do k=1, NGRID
   print '(I6,3ES10.2)', 8 * 2**k, err(:,k)
enddo
print '(A)', 'observed orders, log2(e(n/2) / e(n))'
do k=2, NGRID
   print '(I6,3F10.2)', 8 * 2**k, log(err(:,k-1) / err(:,k)) / log(2._R_P)
enddo
endprogram cookbook_deconvolution
text
cell average of u^2/2, u = sin(2 pi x), max error over the cells
     n     f(<u>)   order 4   order 6
    16  6.13E-03  2.59E-04  1.96E-05
    32  1.59E-03  1.72E-05  3.37E-07
    64  4.00E-04  1.09E-06  5.39E-09
   128  1.00E-04  6.85E-08  8.47E-11
observed orders, log2(e(n/2) / e(n))
    32      1.95      3.91      5.86
    64      1.99      3.98      5.97
   128      2.00      3.99      5.99

f(u¯) converges at order 2, whatever the scheme around it; the deconvolve-evaluate-convolve route at the order of its kernels. The point-value array fp4 is computed on cells −1…N+2, one half-width beyond the cells whose average is wanted, because the convolution needs it there.

Reference. The expansion u¯=u+h2u″/24+…, as ADAM cites it from P. McCorquodale, P. Colella, A high-order finite-volume method for conservation laws on locally refined grids, Comm. App. Math. Comp. Sci. 6 (2011) 1–25 (Sources); GIDEON derives the rows from the cell averages of monomials, not from the expansion. The rows' exactness and order: Exactness and leading error, Orders of accuracy.

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