Skip to content

Add Tensor product tau basis and fix Robin conditions - #70

Merged
mikaem merged 8 commits into
mainfrom
tensor-product-tau-basis
Nov 19, 2026
Merged

mikaem merged 8 commits into
mainfrom
tensor-product-tau-basis

Conversation

@mikaem

@mikaem mikaem commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Tau test spaces (TauRecombined) could not yet be used on tensor-product or Cartesian-product spaces, so the channel-flow solvers and the Orr–Sommerfeld eigenvalue solver could not choose a tau basis per problem. This PR threads a tau_basis argument through get_testspace on every space type. It also adds a Heinrichs Chebyshev space (for verification purpose) and fixes Robin and weighted boundary conditions on non-reference domains. The Petrov–Galerkin (PG) and Galerkin-recombined (GR) test-space construction now stays in sparse diagonal storage throughout.

Types of Changes

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation update
  • Refactor / cleanup
  • Build / CI
  • Other (describe):

Related Issues

Fixes #
Refs #

Description of Changes

Tau basis on product spaces

  • get_testspace(kind, tau_basis=...) is now accepted by OrthogonalSpace, Jacobi, Composite, TensorProductSpace and CartesianBaseSpace.
    • Spaces without a tau test space ignore the argument.
    • So one tau_basis can be passed to a whole tensor product, and the axes with boundary conditions use it.
  • New TauBasis type alias in typing.py.
  • TauRecombined now takes each tau polynomial as (S, k).
    • S is a class or callable that builds an orthogonal space from N, for example ChebyshevU or partial(Ultraspherical, lambda_=2).
    • The same tau_basis therefore works for any N.
    • Mode indices may be negative.

Boundary conditions

  • BoundaryConditions now converts Robin (R) and weighted (W) conditions from physical units to the reference domain, as it already did for Neumann. Before, they were wrong on any domain other than [-1, 1].
  • The scale factor is kept exact with nsimplify, so round-off terms don't make a regular stencil row look singular.
  • The docstring now states each code's meaning, such as R: u + alpha u' = value.
  • BCGeneric no longer takes a redundant N. It derives its size from the lifting basis.

Sparse PG/GR construction (composite.py)

  • Stencil.matrix, PGComposite, GalerkinRecombined and _replace_rows no longer build dense (N, N) intermediates.

New Heinrichs space in Chebyshev.py: a Dirichlet basis phi_k = 4(1 - x^2) T_k, with stencil {-2: -1, 0: 2, 2: -1} plus two overridden rows. Used only for verification.

Examples

  • ChannelFlow2D, ChannelFlow3D, TurbulentChannel3D and the channel case config can select the test-space kind and tau basis.
  • OrrSommerfeld, OrrSommerfeld3D and OrrSommerfeld_eigs are updated to match.
  • sphere_helmholtz is updated for the changed API.

Screenshots / Logs (if applicable)

N/A

Breaking Changes

  • Yes (describe below)

  • No

  • BCGeneric(N, orthogonal, bcs, ...) becomes BCGeneric(orthogonal, bcs, ...). Remove the leading N.

  • Robin and weighted conditions passed as a dict on a non-reference domain now give different (correct) results. Pass a BoundaryConditions instance to keep values that are already in reference units.

  • TauRecombined tau_basis entries must be a class or callable that builds a space from N, not an instantiated space.

Checklist

  • Tests added or updated
  • Documentation updated (README, examples, docstrings)
  • Added type hints
  • Linting & formatting pass locally (pre-commit run --all-files)
  • All new and existing tests pass (uv run pytest)
  • Coverage does not decrease
  • Git history is clean (squash/fixup before merge)

Additional Notes

  • Tests changed in test_composite.py, test_galerkin_recombined.py, test_get_testspace.py and test_tau_testspaces.py.

mikaem and others added 6 commits October 30, 2026 09:53
split_transient_terms ran sp.expand_trig on every time-dependent term, which
also rewrote its spatial factors: cos(n*acos(x)) became its power-basis
Chebyshev polynomial. A source built from K Chebyshev modes then separated
into monomials x^j with O(K^2) scalar time terms, so compile time grew
steeply with K (more than 10 minutes at K = 48), and the assembled source lost
accuracy to cancellation, already from K ~ 20 in float32.

The new separate_time_in_angles applies only the angle-addition formula to
sin, cos, sinh and cosh whose argument mixes time with a non-number, and
leaves every other factor as written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l matrices in intermediate steps of derivation

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Heinrichs stencil produces incorrect basis coefficients, while keyword collisions and incomplete span checks cause Galerkin test-space construction to fail.

3 open issues
What changed in this PR

This PR extends tau test spaces to tensor and Cartesian products, enabling configurable test bases in the channel-flow solvers. It also corrects boundary-condition scaling and reduces memory use in test-space construction.

Changes:

  • Propagate callable tau-basis definitions through space APIs and solver configuration.
  • Correct Robin and weighted boundary scaling, revise lifting-space sizing, and use sparse PG/GR construction.
  • Add the Heinrichs verification basis, improve transient-source handling and eigenvalue solving, and expand regression coverage.
File Description
tests/​integrators/​test_integrator_skeleton.py Tests time separation without rewriting spatial modes.
tests/​galerkin/​test_tau_testspaces.py Adapts tests to callable tau-basis definitions.
tests/​galerkin/​test_inner_source.py Clarifies the angle-splitting comment.
tests/​galerkin/​test_get_testspace.py Tests tau bases on product spaces.
tests/​galerkin/​test_galerkin_recombined.py Adds a construction-memory regression test.
tests/​galerkin/​test_composite.py Tests boundary scaling, lifting, and sparse stencils.
src/​jaxfun/​typing.py Defines the shared TauBasis type.
src/​jaxfun/​integrators/​_utils.py Separates mixed time-space angles selectively.
src/​jaxfun/​galerkin/​tensorproductspace.py Passes tau bases to each axis.
src/​jaxfun/​galerkin/​orthogonal.py Accepts unused tau-basis arguments for compatibility.
src/​jaxfun/​galerkin/​Jacobi.py Aligns the test-space API with tau arguments.
src/​jaxfun/​galerkin/​functionspace.py Updates boundary-lifting construction.
src/​jaxfun/​galerkin/​composite.py Fixes boundary scaling and revises sparse test-space assembly.
src/​jaxfun/​galerkin/​Chebyshev.py Adds the Heinrichs verification space.
src/​jaxfun/​galerkin/​cartesianproductspace.py Passes tau bases to each component.
sandbox/​poisson2D_polygon.py Switches to an MLP space and adjusts training.
examples/​navierstokes/​OrrSommerfeld_eigs.py Adds generalized and shift-invert eigenvalue solving.
examples/​navierstokes/​3D/​TurbulentChannel3D.py Applies configured tau-polynomial choices.
examples/​navierstokes/​3D/​OrrSommerfeld3D.py Uses the short GR enum alias.
examples/​navierstokes/​3D/​ChannelFlow3D.py Enables PG and configurable tau test spaces.
examples/​navierstokes/​3D/​channel_case.py Adds tau-polynomial configuration.
examples/​navierstokes/​3D/​cases/​re180.toml Documents the tau-polynomial setting.
examples/​navierstokes/​2D/​OrrSommerfeld.py Exposes tau-polynomial selection.
examples/​navierstokes/​2D/​ChannelFlow2D.py Enables PG and configurable tau test spaces.
examples/​curvilinear/​sphere_helmholtz.py Updates assembly, metric handling, and example parameters.

Review effort: Balanced

Comment thread src/jaxfun/galerkin/Chebyshev.py Resolved
Comment thread src/jaxfun/galerkin/Chebyshev.py Resolved
Comment on lines +1669 to +1673
i = np.setdiff1d(np.arange(S_pg.shape[0]), replaced)
a = np.arange(s + 1)
w = np.arange(s + t + 1)
B = _band_strip(S_trial, i, a, w) # (rows, s + 1, s + t + 1)
rows = _band_strip(S_pg, i, np.zeros(1, dtype=int), w)[:, 0, :]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to not allow GR for Heinrichs, but now throwing a correct error message

@mikaem
mikaem marked this pull request as ready for review November 17, 2026 09:41
@mikaem
mikaem merged commit 44d1158 into main Nov 19, 2026
15 checks passed
@mikaem
mikaem deleted the tensor-product-tau-basis branch November 19, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants