Skip to content

The generator ​

scripts/gen_gideon.py is the only author of GIDEON's numerics. It derives every row from its meaning in exact rational arithmetic, checks it against that meaning and against ADAM, measures its order, and writes the Fortran: the rows, the kernels, the dispatchers, the 3-D operators, the compact operators and their line solvers, the test registries and the tables of Operators and Compact operators. Every generated file starts with !< Generated by scripts/gen_gideon.py: do not edit; a change of a kernel is a change of the generator. Python 3.10 or later, the standard library only.

bash
python3 scripts/gen_gideon.py --check            # derive, verify, cross-check; write nothing
python3 scripts/gen_gideon.py --check --list     # the same, and list every kernel with its window and order
python3 scripts/gen_gideon.py                    # the same, then write the generated sources
python3 scripts/gen_gideon.py --check --json F   # also write the derived data as JSON (the documentation's figures)

The run takes about half a second and ends with its findings:

text
checked 93 ADAM rows
split fd: gideon_fd_face_ur1 = gideon_fd_face_c2 + (1/2) delta^1; no centred row + one face difference: gideon_fd_face_ur2, ...
split fv: gideon_fv_face_ur1 = gideon_fv_face_c2 + (1/2) delta^1; no centred row + one face difference: gideon_fv_face_ur2, ...
orders: 332 rows, smallest margin -0.002 (gideon_fv_face_ur9, observed 8.998)
lines: Pirozzoli (2002) as recalled, tier A, agrees: gideon_fv_face_pbl5 [['1/2', '1/6'], ['1/18', '19/18', '5/9']]
lines: Lele (1992) as recalled, tier A, agrees: gideon_fd_d1_p4, gideon_fd_d1_p6, ...
lines: Gaitonde and Visbal (2000) as recalled, tier A, agrees: gideon_fd_filter_p2, ...
lines: 29 rows, residual orders at 100 digits, smallest margin -0.000 (gideon_fv_face_pbr7, observed 7.000)
332 kernels derived, 29 compact operators

It exits 1, writing nothing, on any MISMATCH, NOT GENERATED or ORDER finding, and stops on an assertion when a row fails a structural check (below). A recalled value that differs (RECALLED VALUE DIFFERS) is reported, never fatal: the derivation by meaning is the evidence, a recollection is not (§ 7).

1. Geometry ​

In units of the grid step, the datum at offset o is (Conventions):

GeometryDatum L_oTarget T
fd nodethe point value at x=othe n-th derivative at x=0
fd facethe point value at x=o−1/2the value at x=0, between nodes 0 and 1
fv facethe average over [o−1,o]the n-th derivative at x=0, between cells 0 and 1
fv cellthe average over [o−1/2,o+1/2]the average of the n-th derivative over cell 0, or the point value at its centre

sampler and target evaluate these functionals on the monomial xj exactly (mono_point, mono_avg, mono_deriv_point, mono_deriv_avg): a point value is xj, an average is the difference of the primitive over the cell width.

2. Derivation ​

derive(data, place, kind, n, offsets) solves the moment system of the window,

∑owoLo(xj)=T(xj),j=0,…,N−1,

N the number of offsets, by Gauss–Jordan elimination in fractions.Fraction. Then exact_degree applies the row to the monomials up to N+4 and records the largest K on which it is exact; the order is K+1−n. The order is a measurement, not a count: it is at least N−n, and more when the row is exact beyond its own system (an even derivative on a centred window: gideon_fd_d2_c2 reads 3 points at order 2, gideon_fv_point_c4 3 at order 4). A row of no order of at least 1 is dropped; a row exact on fewer monomials than its own system stops the generator.

3. The families ​

build() derives every kernel of the release, by family:

FamilyWindowsDerivatives
fd_face_cq(1-S:S), S=1…50
fd_node_cq(-S:S), S=1…51–6
fv_face_c, fv_facedn_cq(1-S:S), S=1…50–5
fv_cell_cq(-S:S): the flux difference of the face row of derivative n−11–6
fv_face_u, fv_facedn_uright q(1:S), left q(1-S:0), S=1…90–5
fv_cell_uright q(0:S), left q(-S:0): the flux difference of the upwind face row1–6
deconvq(-S:S), S=1…50 (average → point, point → average)
fd_facedn_c, fd_face_u, fd_face_b (#1 phase 2)q(1-S:S); q(1:S), q(1-S:0); q(1-k:k+1), q(-k:k)1–5; 0; 0
fd_face_diss, fv_face_diss (#2)q(1-k:k), k=1…5: δ2k−1, undivided2k−1 at h=1
fv_face_b (#2)q(1-k:k+1), q(-k:k), k=1…40
fd_face_bdiss, fv_face_bdiss (#2)q(-k:k+1): ±Ckδ2k+1, the biased row minus the centred one2k+1 at h=1
fd_filter_c, fv_filter_c (#2)q(-k:k), k=1…50 (filtered)

The ranges are owner decision D2: ADAM's half-stencils 1 to 5 for the centred families, one-sided widths 1 to 9 and the sixth derivative for the upwind ones. Along the way each row passes the structural checks that make the kernels' arithmetic legal:

  • Pair form. A centred row must be symmetric or antisymmetric about its centre (check_pairs); its half-row is what gideon_tables stores.
  • Mirrors. Every left-side upwind row is derived independently on its own window and compared with the right-side row mirrored, times (−1)n: equal, or the generator stops. Only the right row is stored; the left kernel reads it mirrored, so ADAM's audit item A (a row mirrored twice) cannot be written.
  • Flux differences. A cell derivative is assembled from the face row, g(+1/2)−g(−1/2), as full weights on the cells, and its order is measured on those weights (composite_order); the mirrored left operator must keep it.

The P2 families add three proofs:

  • Face differences. δ2k−1 is derived as the face derivative d2k−1 from 2k data at h=1, on point values and on cell averages: the two rows must be equal and binomial.
  • The split. For every biased face row, the centred row of the next order is subtracted and the remainder must be a single multiple of δ2k+1 on the centred window; that multiple, Ck, becomes FD_BDISS_S<k> / FV_BDISS_S<k>. split_findings tries the same on the one-sided rows and reports which split (only ur1).
  • Filters. The 2k+1 weights solve the moments 0…2k−1 and the odd-even condition ∑o(−1)owo=0; the result must be exact to degree 2k−1 and not beyond, the same on both data, and the binomial filter.

4. Cross-check against ADAM ​

parse_adam_tables reads ADAM's committed tables from notes/adam-reference/adam_fdv_operators_library.F90 into exact fractions, and cross_check_adam compares each non-zero row with the derived one, through ADAM's storage conventions (its left-side upwind face rows are stored in ascending cell order; its FVUR/FVUL face-derivative tables multiply the cells nearest first). The 93 non-zero rows agree. ADAM is a check, never a source: a disagreement is reported (MISMATCH, or NOT GENERATED for an ADAM row with no derived counterpart) and fails the run, it is never adopted. ADAM's zero rows are skipped: they are the unsupported orders of audit item C, absent kernels in GIDEON.

5. Orders at 100 digits ​

check_orders applies every row, with its exact weights, to the cell averages or point values of g(x)=sin⁡(1.3x+0.4)+0.5cos⁡(0.7x−0.2) around x0=0.37, in 100-digit decimal arithmetic, at h=2−11 and 2−12, and computes the observed order log2⁡(e1/e2). Two incommensurate waves at a generic point: no derivative vanishes, so no leading term cancels by accident. With round-off out of the way, this is the rows' own order; the frozen bound is design − 0.25, the smallest margin is −0.002 (gideon_fv_face_ur9, 8.998). The compiled kernels' orders are measured again by gideon_test_order, where each kind's round-off allows (Precision).

6. Emission ​

  • Rows (gideon_tables.F90): one real(R_P), parameter per stored row, its literals p._R_P/q._R_P (the compiler folds the division in the build's kind): 148 rows and 8 scalar constants (the dissipation parts' Ck) for 332 kernels, since left-side and cell kernels read the rows of their right-side and face twins, and the FD and FV differences and filters share theirs; then the 56 bands and right sides of the 29 compact operators.
  • Kernels (gideon_fd_centred.F90, gideon_fd_upwind.F90, gideon_fv_centred.F90, gideon_fv_upwind.F90, gideon_deconvolution.F90, gideon_dissipation.F90, gideon_filters.F90): emit_kernel writes the explicit-shape window, the loop over the compile-time row in ADAM's arithmetic shape (pair form, D3; the step divided inside, d/ds/ds for fd and d/(ds*ds) for fv, D4), !$acc routine seq and !$omp declare target.
  • Dispatchers (gideon_dispatch.F90): one per operator, select case over its orders, GIDEON_NAN by default. window_expr fits the window bounds as expressions of order (order/2 + c or order + c) and checks the formula against every kernel of the group.
  • 3-D operators (gideon_operators_3d.F90): gradient, divergence, curl and Laplacian of every centred FD and FV d1 (d2 for the Laplacian) order, over directional stencils, summed in x, y, z order, and their dispatchers.
  • Test registry (src/tests/gideon_test_registry.F90): every kernel's metadata (geometry, target, derivative, order, window, exact degree, ∑|c|, the exact leading error on xK+1, constant-data property, mirror twin) and the routines that apply kernel id directly, on the device, through its dispatcher, and through its dispatcher at an order without a kernel. The tests loop over it (Add an operator).
  • Documentation (docs/guide/_operators-table.md): the table of every kernel.

Before writing, the emitted rows are parsed back from the Fortran text and compared with the derived fractions; then only the files whose text changed are written, so a run that changes nothing touches nothing.

7. Compact operators (#2) ​

build_lines() derives the compact operators with derive_implicit(geom, n, left_offsets, right_offsets): the band α (with α0=1) and the right weights w are the unknowns of one moment system,

∑jαjTj(xm)−∑owoLo(xm)=0,m=0,…,U−1,

U the number of unknowns, Tj the n-th derivative at the unknown j (a node, or a face, both at x=j), Lo the datum. The solution is the row of highest exact degree on that band and window; its residual on the next monomial is the row's exact leading error (lerror). The families: node d1 and d2 (fd_node_p), the faces from point values (fd_face_p, fd_facedn_p) and from cell averages (fv_face_p), each on tridiagonal bands with 1 or 2 pairs on the right and pentadiagonal bands with 2 or 3, orders 4, 6, 8, 10 (asserted: 2(l+s)); the upwind-biased faces from cell averages (fv_face_pb): a tridiagonal band with both off-diagonals free, 2k+1 cells, order 2k+3, the left-biased row derived independently and proven the mirror of the right one, the band asserted diagonally dominant.

The compact filters (fd_filter_p) keep αf free: their conditions are linear in it, so the generator solves at αf=0 and 1, stores _RIGHT and _ALPHA (w=w0+αfw1), and proves the linearity by solving at 3/10 and comparing; the exact degree is checked at 0, 3/10 and 49/100.

Every row's residual is measured at 100 digits on the generic function (the residual's order is the operator's: the band is uniformly invertible), and compared with the values recalled from Lele (1992), Gaitonde and Visbal (2000) and Pirozzoli (2002) (LELE_RECALLED, GV_RECALLED, PIROZZOLI_RECALLED). These are recollections, tier A: they agree, and they are not evidence; the papers are listed for the owner to obtain (Sources).

Emitted: the right-side kernels (gideon_compact.F90, emit_line_kernel), the bands and rows (appended to gideon_tables.F90), the line solvers (gideon_line_solvers.F90, emit_line_solvers from SOLVER_TEMPLATES, one template in three variants: $a(i) becomes a(i), a, or merge(0._R_P, a, mask(i))), the line test registry (src/tests/gideon_test_lines_registry.F90, whose band is the library's constants, never a copy) and the table of Compact operators (docs/guide/_compact-table.md).

Adding to it ​

The order of the work, from the meaning of the new operator to a new golden file: Add an operator.

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