Migrate magnetic response table to Eigen3 AoS layout; consolidate nested-vector overloads as wrappers#490
Draft
Migrate magnetic response table to Eigen3 AoS layout; consolidate nested-vector overloads as wrappers#490
Conversation
Copilot created this pull request from a session on behalf of
jurasic-pf
April 24, 2026 22:50
View session
… intermediate allocations Agent-Logs-Url: https://github.com/proximafusion/vmecpp/sessions/65c3a9ff-885f-47f8-8eb5-df4cd04cdcfd Co-authored-by: jurasic-pf <166746189+jurasic-pf@users.noreply.github.com>
Agent-Logs-Url: https://github.com/proximafusion/vmecpp/sessions/65c3a9ff-885f-47f8-8eb5-df4cd04cdcfd Co-authored-by: jurasic-pf <166746189+jurasic-pf@users.noreply.github.com>
…mplementations Agent-Logs-Url: https://github.com/proximafusion/vmecpp/sessions/de8e1d90-6465-4aa1-a851-a12a0616a754 Co-authored-by: jurasic-pf <166746189+jurasic-pf@users.noreply.github.com>
Co-authored-by: jurasic-pf <166746189+jurasic-pf@users.noreply.github.com>
2ad49e4 to
c6aeccb
Compare
Collaborator
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
jons-pf
requested changes
Apr 27, 2026
Collaborator
jons-pf
left a comment
There was a problem hiding this comment.
LGTM, except that I would suggest to also migrate the magnetic field computation for InfiniteStraightFilament to accept the AoS data directly for consistency.
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.

ComputeMagneticFieldResponseTableandComputeVectorPotentialCacheusedstd::vector<std::vector<double>>as an intermediary between Eigen and ABSCAB, causing ~1M small heap allocations per call and strided memory access in the hot loops. Additionally, the same ABSCAB call logic was duplicated across two independent sets of overloads.Memory layout: 3×N → N×3 (AoS)
RowMatrix3Xdis changed fromMatrix<double, 3, Dynamic, RowMajor>toMatrix<double, Dynamic, 3, RowMajor>. In N×3 row-major,.data()is directly the flat AoS array[x0,y0,z0, x1,y1,z1, …]that ABSCAB expects, and per-point coordinate access(i, 0/1/2)is contiguous. Fixes theTODO(jurasic) bad loop orderinMakeCylindricalGrid.New flat-pointer AoS overloads (canonical implementations)
Added
MagneticField/VectorPotentialoverloads for all filament types andMagneticConfigurationtaking(int N, const double* eval_pos, double* result). These pass the Eigen.data()pointer directly to ABSCAB with zero copies.Eliminated all STL intermediates in the hot path
ComputeMagneticFieldResponseTableandComputeVectorPotentialCacheno longer allocatecylindrical_grid_stlormagnetic_field_stl. The field buffer is allocated once outside the circuit loop and reused viasetZero(). TheMagneticConfigurationcopy is also hoisted out of the loop.Nested-vector overloads consolidated as thin wrappers
The six existing
MagneticField/VectorPotentialoverloads takingvector<vector<double>>(used byLinkingCurrentand all tests) are now thin conversion wrappers that build a flat eval-positions buffer once, call the AoS implementation, and scatter the result back. This eliminates the duplicated ABSCAB setup logic while keeping the public API intact.Result
test_bench_response_table_from_coils: ~1.32 s vs ~1.41 s baseline (~6% improvement). The remaining cost is the ABSCAB Biot-Savart integration itself (already OpenMP-parallelised internally).