Use traced parallel length for Dommaschk metric/J validation#62
Draft
rogeriojorge wants to merge 1 commit intoboutproject:masterfrom
Draft
Use traced parallel length for Dommaschk metric/J validation#62rogeriojorge wants to merge 1 commit intoboutproject:masterfrom
rogeriojorge wants to merge 1 commit intoboutproject:masterfrom
Conversation
Author
|
This is still a draft PR |
Author
|
Changes are not significant, so I think this PR can be closed. The original method appears to be good enough. |
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.
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.
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.
Volume error comparison
Once the parallel metric is traced instead of approximated, the grid volume from
J * dx * dy * dzmoves closer to the true geometric Dommaschk volume.What This PR Changes
This PR keeps only the Dommaschk-relevant metric part of
better-metric.It does three things:
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.pyAdds
field_line_length(...), which converts traced field-line points into a physical 3D arc length.zoidberg/zoidberg.pyThis is the core change.
make_maps(...).This reduced branch keeps that logic self-contained in
zoidberg.py, so it does not need the separategrid.pychanges from the largerbetter-metricbranch.zoidberg/test_volume_dommaschk.pyAdds a Dommaschk-specific regression test.
The test compares:
J * dx * dy * dzThe 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:
Result:
The warning is only from xarray trying to load the optional
bout_adios2backend withoutadios2installed.Why This PR Is Smaller Than
better-metricbetter-metricmixes several themes together:ny=1supportfindIndex()behavior changesThis PR intentionally keeps only the part that is validated for the Dommaschk use case, so it is much easier to review.