Repository navigation
Improve Bernstein Basis Support; Add Quadrature For High Orders - #22
Open
davschneller wants to merge 14 commits into
Open
davschneller wants to merge 14 commits into
davschneller wants to merge 14 commits into
Conversation
basis_functions.bernstein_indices lists the multi-indices (a_1, ..., a_dim) of a degree by their sum a_1 + ... + a_dim, and within the same sum with a_dim slowest and a_1 fastest. A multi-index then has the same position in every degree it occurs in: the indices of a degree lead those of every higher degree, and b + e_0 has the position of b. The term of a_0 of the derivative, the elevation and its transpose thus lies on the diagonal, for the derivative the same entry in every direction; the tests check it. The functions themselves do not nest: the first count(m, dim) functions of degree n span lambda_0^(n - m) P_m, not P_m. Measured with tools/basis_benchmark (Bernstein, CSC and immediate, 1 and 8 simulations, orders 4, 6 and 8, dhsw and dskx, g++ 13.3, both working sets; six interleaved rounds, 3 % noise in the median): the CK, the Taylor sums, the traces and dynamic rupture change by -13 to +7 % per variant and by -5 to +3 % in the geometric mean, the stencil being a tenth of the flops of the CK. The lift and the nodal block in CSC with one simulation take 13 to 26 % less on dskx and change by -12 to +11 % on dhsw (512 MiB); that comes from the SLP vectoriser of g++, without which the lift in this order takes 1 to 14 % less than in the other. With the best storage per block, the time step of CK, Taylor, trace and lift takes 8 to 23 % less on dskx with one simulation and changes by -5 to +6 % elsewhere. Counted for a GPU with the rows of a column on 32 lanes, the gathers of the CK take 24 instead of 42 shuffles per column at order 6 and 54 instead of 101 at order 8. basis.json states the order. The matrices of the Bernstein basis are the same up to the permutation; in the ones that solve with the dense mass matrix (kDivM, kDivMT, the basis changes) the rounding differs by about 1e-14 of the largest entry, which also changes which of the rounding entries at exact zeros clear the threshold of json_io. The matrices of the Dubiner bases do not change. AI-generated. Model: Claude Opus 5.5
The operators that the generators get from a solve with a mass matrix (kDivM and kDivMT with and without a material order, rT, rDivM, the canonical traces and lifts, and the basis changes) go through operator_solve, which sets every entry of at most SOLVE_ZERO_TOLERANCE = 1e-10 of the largest one to zero. Where such an operator vanishes, the solve leaves rounding: in the Bernstein basis, whose mass matrix is dense with a condition number of 8e1, 1e3 and 2e4 at orders 4, 6 and 8, up to 6.3e-13 of the largest entry; in the Dubiner bases up to 4e-15, mostly in the canonical lifts. Over all three families, orders 2 to 8, material orders 1 to 3, all faces and orientations and both directions of the basis changes, the smallest entry that does not vanish is at least 1e-9 of the largest. The point-based matrices of dynamic rupture and plasticity keep their plain solves: their entries run down to 1e-15 of the largest one without a gap to cut at. Computing in numpy's float128 is no way around it. It is the x87 format with a 64-bit mantissa on x86-64, IEEE quad in software on aarch64 Linux and plain float64 on Windows and on macOS on arm64; numpy.linalg rejects it and scipy.linalg solves in float64. With the integrals from the float64 quadrature, a solve in it still leaves 4.5e-13 at order 8 (kDivMT of the Bernstein basis); only exact integrals together with a solve in extended precision bring that down, to 1.9e-16. The outputs of generate.py (ader with and without material orders 1 to 3, faces and basis, orders 2 to 8) lose 754048 of 2955286 entries for the Bernstein basis: 30 % of kDivM and kDivMT (at order 5, kDivMT had 405 to 432 entries where 146 are exact), 83 and 86 % of rT and rTCanonical. They lose 84171 of 1280508 for the Dubiner basis, nearly all in rDivMCanonical, and 617 of 1196954 for the normalised one. They gain none, and the entries they keep stay the same, up to the rounding of a solve whose input lost entries or that BLAS gives differently with another number of threads (Bernstein basis change at order 8: 4e-13 of the largest entry between one and two threads). A new test checks that kDivMT and the canonical traces of the Bernstein basis vanish exactly where the exact operators do, for orders 2 to 8; it fails without the change. AI-generated. Model: Claude Opus 5.5
…ints The nodes are refined by Newton's method in decimal arithmetic of 40 digits from the nodes of scipy, and the weights follow from the derivative of the Jacobi polynomial there, so that both are rounded to double once. The iteration in double, which stopped once the polynomial fell below 1e-14 at the node, never stops for the Legendre rule of 40 points, which the time basis asks for at order 20, since the rounding of the polynomial is larger there; its weights carried relative errors of 2e-13 at 30 points. Each rule is computed once per process. AI-generated. Model: Claude Opus 5.5
The tetrahedral rules of degrees 22 to 40 and the triangular ones of degrees 1 to 42, from the same commit of SummationByParts.jl as those of the tetrahedron up to degree 21, which tools/import_worku_hicken_zingg_rules.py converts alike (it writes those byte for byte). SymmetricTet selects them for the degrees 22 to 40, where they are the only fully symmetric rules with positive weights and points inside. Most of them come closer to the boundary than 1e-3 (down to 8.8e-7 at degree 40), so the bound holds up to degree 21 alone; above, every rule with its points inside qualifies. SymmetricTri selects from the three families up to degree 42 by the rule it had, which now takes the Worku-Hicken-Zingg rules of degrees 3, 16 and 19, whose points keep farther from the boundary than the ones with as many points before; no file of SeisSol uses these degrees. A selection is read once per process, and the symmetry checks look for the partners of the points in a k-d tree, which the rules of some thousand points need. AI-generated. Model: Claude Opus 5.5
The bilinear and trilinear forms of the scheme ask for rules of the degree of the product, 2 * order on the cell and on its faces, and more with a material basis; the Jaskowiec-Sukumar and Witherden-Vincent rules end at degree 20. Beyond, the forms take Stroud's conical product rule of the degree (ConicalProduct), exact for any degree with positive weights, so that the orders above 10 integrate exactly. The rules up to degree 20 are the ones they were. A family without a rule of the degree asked for says so, instead of failing on an empty sequence. AI-generated. Model: Claude Opus 5.5
dr_rules adds the fully symmetric rule exact up to degree 2 * order (quad_points.symmetric, from SymmetricTri), which every order up to 21 has: 55 points at order 8 against 61 of the Dunavant and 81 of the Stroud rule, and 304 at order 20 against 441. The Dunavant rules end at order 9 and the Witherden-Vincent rules at order 10; above, dr_rules leaves them out. AI-generated. Model: Claude Opus 5.5
The tables of the nodal points of the face (nodes_<order>.txt, up to order 7) and of the cell (nb_<order>.txt, up to order 8) are the warp and blend points of Warburton as Hesthaven and Warburton compute them (Nodes2D, Nodes3D) with their optimised blending parameters: nodal_points computes them to within 7e-16 of the tables for every order there, and for every degree beyond, with the fixed parameters Hesthaven and Warburton give above degree 15. The tables go; the nodal boundary matrices and the nodal plasticity points (nb) take the points of the degree of the scheme from there, so that every order has them. The Vandermonde matrices of the orthonormal bases stay below a condition number of 3e4 up to degree 19. The point of degree 0 of the cell is its centroid; the table of order 1 had the one of a face. AI-generated. Model: Claude Opus 5.5
An integral of the forms counted as zero up to 1e-12 of the largest one of its form, and an operator a solve gives up to 1e-10 of its largest entry. Beyond order 12 the Dubiner basis has integrals below these that do not vanish: the integrals of a form span 16 orders of magnitude at order 20, from the scale of the functions, while the rounding of each scales with its own integrand. An integral now vanishes where it is at most 1e-13 of the integral of the absolute value of its integrand (vanish). Up to order 20 that lies above the rounding, below 3e-14 of it (two exact rules with different points agree to that), and below the smallest integral that does not vanish, 1.2e-13 of it at order 20 from the cancellation in the derivatives and above 1e-8 up to order 8. The sum of two forms, as for the derivative of a product with the material, vanishes by the sum of their bounds; the moments of the canonical traces and of the changes of basis alike. A diagonal mass matrix divides the rows of what it is solved with, so that the operators of the Dubiner bases keep the zeros of their integrals exactly; after a solve with a dense one (the Bernstein basis) the entries up to 1e-10 of the largest one still vanish. A barycentric coordinate within four units in the last place of zero is zero, so that the Bernstein polynomials that vanish on the slanted face vanish at its points, where 1 - x - y - z rounds to some 1e-17 (the zeros of fMrT(3)). Up to order 8 every operator of the three bases has the zeros it had, with and without a material of order 3, and the values within 7e-14 of the ones before. At order 20, two exact rules with different points give the same zeros but for 5 of 1.4 million entries of the derivatives, at 3e-14 of their largest entry. AI-generated. Model: Claude Opus 5.5
json_io.write_file and xml_io.write_file write the tensors of a file at once, in the layout of a new file written tensor by tensor (the same bytes, which the tests check), and format the entries of a tensor in chunks. write_tensors reads and rewrites the whole file for every tensor it appends and formats every index of a tensor in Python, which does not scale to the 82 million entries of the plasticity points of order 20; write_file formats 10 million entries in 12 s. A file whose name ends with .xz is compressed with xz: with the preset 6 up to 2^18 entries (some 10 MB of text), with the preset 1 above, which compresses 17 MB/s instead of 1.2 MB/s for files some 15% larger. read_json and read_xml read compressed files as well. AI-generated. Model: Claude Opus 5.5
ORDERS reaches order 20, and --orders selects some of the orders (as 2-8 or 9,10,12). The Bernstein basis ends at order 10 (ORDER_LIMITS): its operators are solved with mass matrices whose condition number is 2.9e5 at order 10, where they agree with the exact operators to 1e-10 (the lift; the derivatives to 1e-11) and vanish where those vanish. At order 11 the lift is off by 1.5e-9, and from order 12 on the derivatives have entries where the exact ones have none. The visualisation has the degrees up to the one of the highest order, and at least up to 8. AI-generated. Model: Claude Opus 5.5
generate.py seissol writes the files SeisSol's code generator reads from codegen/matrices, for a basis and orders (seissol_directory): aderdg, mass, lower beyond the Dubiner basis, the faults of the rules stroud, dunavant and symmetric as far as an order has them, face-sq, the point sets ip, nb and sq, the nodal boundary and the gravitational energy, and with the Dubiner basis stp and vtkbase; with --compress compressed with xz, and with --reference-dir with the points of a fault from the files of a reference directory where it has them, so that a fault keeps its points. dg_matrices.projection gives the derivatives and elevations between the degrees and the embeddings of the lower degrees into the basis of the cell. tools/compare_matrix_directories.py compares two such directories file by file. Written for the orders 2 to 8, the three bases have the tensors of SeisSol's directories (davschneller/nodal) with the same zeros, and values within 3.3e-14 (Dubiner), 1.9e-14 (normalized Dubiner) and 1.3e-11 (Bernstein) of the largest entry of a tensor; they lack only what SeisSol does not read: Zinv in stp_2 to stp_7, V2QuadTo2m and V2mTo2Quad at order 8, and the file of the Witherden-Vincent rule of order 8. SeisSol's fault of the Dunavant rule of order 8 has 19 points, exact up to degree 9 (the other orders: 2 * order); without a reference directory it has the 61 points of degree 16. One order of the Dubiner basis takes 92 s and 93 MB compressed at order 12, and 573 s, 2.1 GB of memory and 1.7 GB compressed (5.9 GB of text) at order 20, of which the point set ip (Stroud, 9261 points) has 0.85 GB. At order 20 the matrices satisfy their identities to 3e-14 (the derivatives against those of the basis, vInv v = I for ip and sq, the resampling of a fault), the inverse of the Vandermonde matrix of the nodal points to 6e-11. AI-generated. Model: Claude Opus 5.5
The mass matrices of the Bernstein basis have condition numbers of 2.9e5 at order 10, 1.0e9 at order 16 and 2.5e11 at order 20, and its operators solved with them in double held up to order 10 alone. bernstein_exact computes them exactly: the integrals of products of Bernstein polynomials are rationals in closed form, and so are the derivatives, elevations, traces and face permutations; FLINT (python-flint) inverts the mass matrices exactly (15 s at order 20; the inverse has entries of some 50 bits) and multiplies the rationals. What takes values at points, whose coordinates and weights are doubles, is applied to the exact inverse in ball arithmetic of 192 bits (the projections of the faults, of the point sets and of the nodal boundary, the inverse of a Vandermonde matrix at the nodal points). Every result is rounded to double once. dg_generator takes the mass and stiffness matrices, kDivM, kDivMT, the traces and lifts (also in the canonical frame), fMrT, fP and the integrals of the basis from there, and projection the derivatives and elevations between the degrees; dr_generator, PlasticityGenerator and NodalBoundaryGenerator their solves. The change into the Bernstein basis is the inverse of the one out of it. The forms with a material basis are still solved in double and hold up to order 10 (BERNSTEIN_DOUBLE_LIMIT); beyond, they raise. The Bernstein basis has every order of SUPPORTED_ORDERS. Written for the orders 2 to 8, the Bernstein directory has the tensors and zeros of SeisSol's, with the values within 1.1e-11, the error of those files. At order 14 the derivative is E D to 1e-13, the lift its factorisation (Chan and Warburton) to 1e-13 of its largest entry, and the projection from the symmetric points reproduces the basis to 1e-10. At order 20, the projection from the symmetric points solved in double is off by 4e-6, in QR by 7e-11; applied in double to a smooth field, the exact kDivM, E D and lift lose up to 3e-15, the projection 2e-10 (its entries reach 3e4): the conditioning of the basis, not of the matrices. AI-generated. Model: Claude Opus 5.5
The directory of the Dubiner basis holds, besides its own matrices, the files SeisSol reads for every basis: the time basis of the predictor and the points of the visualisation, which are written here, and the matrices of the equations (equation-*.json) and the directions an anisotropic material is sampled in (sampling_directions.json), which are not computed here. These are now copied from the reference directory as they are (SHARED_FILES), so that a directory written for some orders, say those above 8, is complete for a build of SeisSol. Writing into the reference directory itself leaves them alone. AI-generated. Model: Claude Opus 5.5
The point set ip, Stroud's conical product of order + 1 points per direction, is SeisSol's volume quadrature: the initial condition is projected with it, the error of an analysis and the energies are integrated with it. It is exact up to degree 2 order + 1 with (order + 1)^3 points: 2197 at order 12, 9261 at order 20, where its file takes 47 MB and 0.85 GB compressed and its basis and projection two dense tensors of 114 MB each in the generated code. The new point set qp is the fully symmetric rule of degree 2 order, exact for the square of the polynomial of degree order the error of the scheme leads with: 469 points at order 10, 756 at order 12, 3815 at order 20. The rule sq, of degree 2 (order - 1), would do for a projection, but not for the norm of an error: over 20 planar waves projected on a tetrahedron (h |k| = 1.26, orders 6 to 12), sq misjudges the L2 norm of the error by 2 to 17 % (median), qp by 0.1 to 0.6 %, ip by 0.02 to 0.1 %. The directory of SeisSol has ip up to order 8 (STROUD_ORDERS) and qp above (point_sets). The rules among the point sets carry their weights on the unit tetrahedron (vWeights, summing to 1/6), at the end of their files. AI-generated. Model: Claude Opus 5.5
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.