Skip to content

Interpolate the mgrid field cubically and free the vacuum arrays between runs - #27

Draft
krystophny wants to merge 2 commits into
hiddenSymmetries:masterfrom
itpplasma:offer/cubic-mgrid-precal-cleanup
Draft

krystophny wants to merge 2 commits into
hiddenSymmetries:masterfrom
itpplasma:offer/cubic-mgrid-precal-cleanup

Conversation

@krystophny

Copy link
Copy Markdown

This PR holds two free-boundary fixes, one commit each.

Cubic mgrid interpolation (a4f8dc4). becoil interpolates the mgrid field bilinearly in $(R, Z)$ (becoil.f#L61-L87). The interpolation error is $O(h^2)$ in the table spacing $h$ and shifts the computed boundary and magnetic axis. The commit uses cubic Lagrange interpolation with 4 points per direction in $R$ and $Z$, one-sided at the table edges (becoil.f#L63-L87), with an $O(h^4)$ interpolation error.

test_mgrid_resolution solves a tokamak with its axis near $R = 1.6$ m in an analytic field (1/R toroidal field plus two circular loops) tabulated at 50 mm and at 12.5 mm. The axis from the 50 mm table lies 48.5 mm (bilinear) and 0.23 mm (cubic) from the axis from the 12.5 mm table.

On the public DIII-D example, input.DIII-D_lasym_false run with LASYM = T, MPOL = 16, NS = 128 and PHIEDGE scaled by 0.95, in mgrid_d3d_ef.nc ($R \times Z$ = 126 x 201 nodes), a table with half the spacing moves the bilinear axis by 0.37 mm and the plasma volume by $4.5\times10^{-4}$ relative. With cubic interpolation the two tables give the same axis within 1 µm and the same volume within $3\times10^{-7}$.

Second run in one process (1a47748). precal allocates four NESTOR work arrays (precal.f#L152, #L224) that neither the Python interface's cleanup nor fileout frees, so a second free-boundary run in the same Python process stops with

STOP Allocation error in scalpot

The commit frees them in both places (cleanup.f90#L52-L56, fileout.f#L329-L334). test_second_run solves the tokamak of test_mgrid_resolution twice in one process and requires the same axis and volume.

On 70c637a both new tests fail. With the two commits they pass with 1 and 2 MPI ranks, and test_simple and test_regression pass unchanged.

Chris&AI

becoil interpolated the coil field bilinearly, an O(h**2) error that moves
the free boundary with the grid spacing. On the DIII-D deck (126 x 201
grid, 16 mm spacing) refining the grid 2x moved the volume by 4.5e-4 and
the axis by 0.37 mm. A tensor 4-point Lagrange stencil, centred and
shifted inward at the grid edges, gives the same result on the original
and the refined grid and agrees with VMEC++, which interpolates the same
way.

The new test solves a small tokamak in an analytic field tabulated at
50 mm; bilinear interpolation moves its axis by 48 mm from the fine-grid
result, cubic by 0.2 mm.
precal allocates sinmni, cosmni, counts_vac and disps_vac, which neither cleanup (called by the Python interface between runs) nor fileout freed, so a second free-boundary run in one process stopped with an allocation error. test_second_run solves the same case twice in one process.

This branch has not been deployed

No deployments
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