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.
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:
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 operatorsIt 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):
| Geometry | Datum L_o | Target T |
|---|---|---|
fd node | the point value at | the n-th derivative at |
fd face | the point value at | the value at |
fv face | the average over | the n-th derivative at |
fv cell | the average over | 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 mono_point, mono_avg, mono_deriv_point, mono_deriv_avg): a point value is
2. Derivation
derive(data, place, kind, n, offsets) solves the moment system of the window,
fractions.Fraction. Then exact_degree applies the row to the monomials up to 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:
| Family | Windows | Derivatives |
|---|---|---|
fd_face_c | q(1-S:S), | 0 |
fd_node_c | q(-S:S), | 1–6 |
fv_face_c, fv_facedn_c | q(1-S:S), | 0–5 |
fv_cell_c | q(-S:S): the flux difference of the face row of derivative | 1–6 |
fv_face_u, fv_facedn_u | right q(1:S), left q(1-S:0), | 0–5 |
fv_cell_u | right q(0:S), left q(-S:0): the flux difference of the upwind face row | 1–6 |
deconv | q(-S:S), | 0 (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), | |
fv_face_b (#2) | q(1-k:k+1), q(-k:k), | 0 |
fd_face_bdiss, fv_face_bdiss (#2) | q(-k:k+1): | |
fd_filter_c, fv_filter_c (#2) | q(-k:k), | 0 (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 whatgideon_tablesstores. - Mirrors. Every left-side upwind row is derived independently on its own window and compared with the right-side row mirrored, times
: 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,
, 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.
is derived as the face derivative from data at , 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
on the centred window; that multiple, , becomes FD_BDISS_S<k>/FV_BDISS_S<k>.split_findingstries the same on the one-sided rows and reports which split (onlyur1). - Filters. The
weights solve the moments and the odd-even condition ; the result must be exact to degree 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 decimal arithmetic, at 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): onereal(R_P), parameterper stored row, its literalsp._R_P/q._R_P(the compiler folds the division in the build's kind): 148 rows and 8 scalar constants (the dissipation parts') 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_kernelwrites 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/dsforfdandd/(ds*ds)forfv, D4),!$acc routine seqand!$omp declare target. - Dispatchers (
gideon_dispatch.F90): one per operator,select caseover its orders,GIDEON_NANby default.window_exprfits the window bounds as expressions oforder(order/2 + cororder + 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,, the exact leading error on , constant-data property, mirror twin) and the routines that apply kernel iddirectly, 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
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: fv_face_pb): a tridiagonal band with both off-diagonals free,
The compact filters (fd_filter_p) keep _RIGHT and _ALPHA (
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.