Skip to content

Use a sparse matrix format during assembly - #99

Merged
nikoscham merged 1 commit into
mainfrom
Feature/sparce-matrix-format
Oct 28, 2026
Merged

nikoscham merged 1 commit into
mainfrom
Feature/sparce-matrix-format

Conversation

@nikoscham

Copy link
Copy Markdown
Member
  • Add SparseMatrix (numerics/sparseMatrix.js): row-wise storage during assembly, with conversion to CSC (mathjs LU), CSR (Jacobi) and dense (WebGPU Jacobi)
  • Assemble every model into a SparseMatrix instead of a dense n x n array; Dirichlet boundary conditions clear a row in O(nnz) instead of O(n)
  • LU solver: build the mathjs sparse matrix directly from CSC, without a dense intermediate
  • Jacobi solver: iterate over CSR rows, O(nnz) per iteration instead of O(n^2)
  • Assembly: build a local element matrix and add it to the global matrix once per element; precompute reference basis functions per integration point in initializeFEA; reuse the coordinates from the isoparametric mapping; reuse derivative arrays; hoist integration factors out of the inner loops
  • Up to 3.7x faster with LU, 127x faster with Jacobi; at 6.5k DOFs the matrix needs 9 MB instead of 675 MB; solutions unchanged (within 1e-11)
  • Tests: add sparseMatrix unit test; move the Euler-Bernoulli beam test to tests/verification/analytical/eulerBernoulliBeam1DCantilever (closed-form checks, not a unit test); read the matrix with toDense() in beam tests

- Add SparseMatrix (numerics/sparseMatrix.js): row-wise storage during
  assembly, with conversion to CSC (mathjs LU), CSR (Jacobi) and dense
  (WebGPU Jacobi)
- Assemble every model into a SparseMatrix instead of a dense n x n array;
  Dirichlet boundary conditions clear a row in O(nnz) instead of O(n)
- LU solver: build the mathjs sparse matrix directly from CSC, without a
  dense intermediate
- Jacobi solver: iterate over CSR rows, O(nnz) per iteration instead of O(n^2)
- Assembly: build a local element matrix and add it to the global matrix
  once per element; precompute reference basis functions per integration
  point in initializeFEA; reuse the coordinates from the isoparametric
  mapping; reuse derivative arrays; hoist integration factors out of the
  inner loops
- Up to 3.7x faster with LU, 127x faster with Jacobi; at 6.5k DOFs the
  matrix needs 9 MB instead of 675 MB; solutions unchanged (within 1e-11)
- Tests: add sparseMatrix unit test; move the Euler-Bernoulli beam test to
  tests/verification/analytical/eulerBernoulliBeam1DCantilever (closed-form
  checks, not a unit test); read the matrix with toDense() in beam tests
@nikoscham nikoscham added this to the 0.3.0 milestone Oct 28, 2026
@nikoscham nikoscham self-assigned this Oct 28, 2026
@nikoscham nikoscham added the enhancement New feature or request label Oct 28, 2026
@nikoscham nikoscham linked an issue Oct 28, 2026 that may be closed by this pull request
@nikoscham
nikoscham merged commit 6110df0 into main Oct 28, 2026
2 checks passed
@nikoscham
nikoscham deleted the Feature/sparce-matrix-format branch October 28, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sparce matrix format

1 participant