Skip to content

Sync Discontinuous-Galerkin with main - #54

Open
rogeriojorge wants to merge 55 commits into
Discontinuous-Galerkinfrom
sync/dg-with-main
Open

rogeriojorge wants to merge 55 commits into
Discontinuous-Galerkinfrom
sync/dg-with-main

Conversation

@rogeriojorge

@rogeriojorge rogeriojorge commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Problem. Discontinuous-Galerkin was 96 commits behind main (merge base bcd41c4).

Change. A merge of current main (ab87385, includes #49/#52/#53) into the branch, so the DG history and the open PRs #45/#39 stay valid.

Conflicts and how they were resolved:

  • spectrax/_model.py, _simulation.py, _initialization.py: kept the DG solver. Main's rFFT layout, _twothirds_mask and Fourier default state do not apply to a DG discretization. From main, kept solver_stats in the simulation output.
  • spectrax/midpoint_solver.py: took main's cleaned version. It removes the broken _preconditioning/jaxopt imports that DG had commented out.
  • DG examples (1D_Landau_damping, 1D_two_stream, 1D_Weibel, 2D_Orszag_Tang and their TOMLs): kept the DG versions. The Weibel files are kept even though main deleted them. Main's adaptive_time_step TOML key is not taken, because the DG simulation does not accept it.
  • Everything else comes from main: diagnostics, the inverse-transform norm fix, _initialize_maxwellian, the old_src/crank_nicolson removals, docs, README and tests.

Follow-up commit: main's #52 test (a 2D multi-Hermite TOML with no initial state) failed on DG. legT was only given the x grid, and the default Ck_0 ignored Nm/Np. Both are fixed. The test asserts the DG shape (t, Ns*Nn*Nm*Np, Ny, Nx, Nz, Nl).

Tests.

  • pytest tests: 9 passed, with and without JAX_ENABLE_X64=1.
  • DG Landau example (Nx=33, Nn=40, N_DG=2): E-field damping rate -0.104. Main's Fourier solver gives about -0.099.
  • DG two-stream example: the pre-existing legT old-signature call is fixed (3 lines). It runs in 105 s. The E-field growth rate fitted over t in [5,15] is 0.221, and kinetic linear theory gives 0.218 for k=5.0, u=+-0.1, alpha=0.0707. The fit depends on the window (0.21-0.38) because the 1% seed saturates by t of about 12.
  • DG Weibel runs.
  • DG Orszag-Tang at reduced size (12x12, Nn=Nm=3, t=5) runs and stays finite.

Known issues (already on DG before this merge).

  • Main's Fourier-only additions (1D_Landau_damping_dr_curve.py, 1D_two_stream_gr_curve.py, orszag_tang_data_analysis.py) do not run on the DG solver. They are kept so a later DG to main merge does not delete them.

Merge order: this PR, then #45, then #39.

Update 2026-10-03 (head 2f4ee44)

  • Re-checked against main ab87385 (unchanged since the merge): git rev-list origin/main ^HEAD is empty.
  • README: a short note at the top states that simulation on this branch is Legendre DG in space, lists the four DG examples, and says that 1D_Landau_damping_dr_curve.py, 1D_two_stream_gr_curve.py, orszag_tang_data_analysis.py and the diagnostics/plot/inverse_HF_transform utilities come from main, assume the Fourier layout and do not run on DG output. No code change.
  • Tests: pytest tests 9 passed (also with JAX_ENABLE_X64=1), Python 3.12, JAX 0.11.2, CPU.
  • Open question for review: main's diagnostics is exported here but is commented out in the DG simulation; a DG energy diagnostic would need Legendre mass weights, not rFFT weights.

Stack: this PR -> #45 (base now sync/dg-with-main) -> #39 (base now agent/dg-autodiff).

Update 2026-10-23 (head a5998a8)

MattHeup and others added 30 commits March 21, 2026 20:05
Switch to RFFT for Fourier transforms
* Fix periodic Orszag-Tang grid

* Simplify periodic Orszag-Tang grid fix
The solver stores Ck with irfftn(..., norm="forward") (Ck at k = 0 is the
spatial mean), but inverse_HF_transform used the default backward norm,
so every reconstructed f(x, v) was Nx*Ny*Nz times too small.
Random real C_nmp on odd and even grids go through the solver's
rfftn(norm="forward") and back; the density and first velocity moments
of f, integrated by Gauss-Hermite quadrature, must return C_000 and
C_100/sqrt(2), C_010/sqrt(2), C_001/sqrt(2).
Use the solver's Fourier normalization in inverse_HF_transform
Landau damping example: pass its initial field to the solver
Build the default initial state on the requested grid, so 2D TOMLs without Ck_0 run
Keep the DG solver core (_model, _simulation, _initialization) and DG examples;
take main's cleaned midpoint_solver, diagnostics, inverse transform, docs and tests;
expose solver_stats from the DG simulation.
…ling

An under-resolved run (too few Hermite modes or too weak hypercollisions
for the filamentation reaching the cutoff, or a species whose Hermite
width is narrower than it becomes) makes the adaptive step collapse; the
solve then crawls for hours towards the hard-coded 1e6 steps. dtmin (off
by default) stops it with an error at the collapse; max_steps is now a
parameter.
simulation(throw=False) returns and puts diffrax's sol.result in output['solver_result'].
rogeriojorge and others added 10 commits October 3, 2026 09:23
spectrax imports diffrax (time integration) and orthax (inverse Hermite transform), but pyproject.toml did not list them, so pip install left the package unimportable in a clean environment.
diffrax 0.7, matplotlib 3.10+ and current jax need at least 3.11, tomllib is in
the standard library from 3.11, and CI tests 3.11 and 3.12. The old >=3.5
could not resolve.
The logo was a 4.7 MB 1576x1476 screenshot with embedded metadata; the
README shows it at 30% width. It is now 800 px wide with a 256-colour
palette and no metadata (193 KB). Tracked __pycache__ files are removed;
__pycache__/ is already ignored.
dCk must differ from Ck only in each species' uniform density slot; the k=0
first Hermite moment (mean current) and all k != 0 coefficients are kept, and
the net mean current still drives the uniform field.
Three species with unequal (Nn, Nm, Np) check that flat Hermite index
s*Nn*Nm*Np + p*Nn*Nm + m*Nn + n maps to state[s, p, m, n], and a fixed-step run
restarted from a saved (Ck, Fk) snapshot matches the uninterrupted run.
@Benjamin-Herfray

Copy link
Copy Markdown

This sync is with an older version of DG branch. Should be rechecked against newer commits. Growth/decay rate scans can be omitted from the sync.

Compress the logo and stop tracking bytecode
Declare diffrax and orthax as dependencies
…ions

Fix multispecies perturbation bookkeeping
Expose dtmin, max_steps and throw so a collapsing step stops, or is reported, instead of crawling
Take the newer DG solver, examples and utilities (DG_project, inverse_HDG_transform,
DG diagnostics and plots). Drop the Fourier growth/decay rate scans and their data.
Keep solver_stats in the output and size the default Ck_0 by Nn*Nm*Np.
Take main's deps, logo, bytecode removal and dtmin/max_steps/throw solver options.
Carry them onto the DG simulation: keep (Ck, Fk) as a structured solver state, let
ImplicitMidpoint take a pytree state, and adapt main's tests to the DG layout.
Update the README DG note and add the new solver options to the parameter table.
@rogeriojorge

Copy link
Copy Markdown
Member Author

Thanks. Re-synced against the current DG branch (21f5068) and main (b668d87), with DG code and examples taking precedence. The growth/decay rate scans and their data files are removed from the branch. Details and test results are in the PR body update.

@rogeriojorge

Copy link
Copy Markdown
Member Author

Handed over to @Benjamin-Herfray together with the DG parallel chain; see the handoff comment on #74 for the order (refresh this sync, then rebase the chain) and the jax 0.12 test fix.

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.

4 participants