Skip to content

Use traced parallel length for Dommaschk metric/J validation#62

Draft
rogeriojorge wants to merge 1 commit intoboutproject:masterfrom
rogeriojorge:dommaschk-minimal-metric
Draft

Use traced parallel length for Dommaschk metric/J validation#62
rogeriojorge wants to merge 1 commit intoboutproject:masterfrom
rogeriojorge:dommaschk-minimal-metric

Conversation

@rogeriojorge
Copy link

@rogeriojorge rogeriojorge commented Mar 17, 2026

Problem

For simple geometries, the old metric treatment is often good enough.

For a Dommaschk field, it is too optimistic about the distance travelled along the magnetic field between neighboring toroidal slices. In plain terms, the old metric assumes a shorter and simpler path than the field line actually takes in 3D.

That matters because the grid volume depends on the parallel part of the metric. If that parallel distance is underestimated, then the resulting metric and Jacobian are less faithful to the real Dommaschk geometry.

Visual Summary

3D before/after

The old metric treats the parallel path between toroidal slices as shorter than it really is. The traced metric captures the longer field-line path in the Dommaschk geometry.

dommaschk_parallel_3d_before_after

Poloidal-plane before/after

On a representative slice, the old metric locally underestimates the parallel cell length. The traced metric increases it where the Dommaschk geometry bends more strongly.

dommaschk_parallel_plane_before_after

Volume error comparison

Once the parallel metric is traced instead of approximated, the grid volume from J * dx * dy * dz moves closer to the true geometric Dommaschk volume.

dommaschk_volume_error_before_after

What This PR Changes

This PR keeps only the Dommaschk-relevant metric part of better-metric.

It does three things:

  1. Adds a helper to measure the length of a traced field-line segment in 3D.
  2. Uses that traced parallel length when constructing the exported grid metric.
  3. Adds a Dommaschk regression test that checks the grid volume against a geometric reference volume.

Why This Helps The Dommaschk Case

The main improvement is that the parallel metric is no longer based only on a simpler local estimate.

Instead, it is measured from the traced field line itself.

For Dommaschk, that is the right thing to do because the field-line path between slices is genuinely three-dimensional. The old approach effectively treats that path as shorter and simpler than it really is. This PR replaces that optimistic estimate with the traced path length, so the exported metric and Jacobian better represent the real geometry.

The practical consequence is that the grid volume computed from the exported metric agrees better with the true Dommaschk volume.

Code Changes

zoidberg/diff.py

Adds field_line_length(...), which converts traced field-line points into a physical 3D arc length.

zoidberg/zoidberg.py

This is the core change.

  • It adds half-step parallel targets and refined tracing in make_maps(...).
  • It computes traced parallel lengths and improved Jacobian data from those traced paths.
  • It writes the corrected parallel metric terms into the exported grid.

This reduced branch keeps that logic self-contained in zoidberg.py, so it does not need the separate grid.py changes from the larger better-metric branch.

zoidberg/test_volume_dommaschk.py

Adds a Dommaschk-specific regression test.

The test compares:

  • a geometric/reference Dommaschk volume, and
  • the grid volume computed from J * dx * dy * dz

The point of the test is to show that the traced metric improves the geometric fidelity of the exported grid for the Dommaschk case.

Validation

Ran:

/opt/local/bin/python -m pytest -q zoidberg/test_volume_dommaschk.py

Result:

1 passed, 1 warning in ~78s

The warning is only from xarray trying to load the optional bout_adios2 backend without adios2 installed.

Why This PR Is Smaller Than better-metric

better-metric mixes several themes together:

  • metric and Jacobian changes
  • slab DAGP support
  • ny=1 support
  • findIndex() behavior changes
  • FusionSC integration
  • dependency and test extras

This PR intentionally keeps only the part that is validated for the Dommaschk use case, so it is much easier to review.

@rogeriojorge
Copy link
Author

This is still a draft PR

@rogeriojorge rogeriojorge marked this pull request as draft March 17, 2026 18:45
@rogeriojorge
Copy link
Author

Changes are not significant, so I think this PR can be closed. The original method appears to be good enough.

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.

1 participant