Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFTInterpolator for singular integral gives bad results #1522

Open
unalmis opened this issue Jan 17, 2025 · 1 comment · May be fixed by #1440
Open

DFTInterpolator for singular integral gives bad results #1522

unalmis opened this issue Jan 17, 2025 · 1 comment · May be fixed by #1440
Assignees
Labels
P3 Highest Priority, someone is/should be actively working on this

Comments

@unalmis
Copy link
Collaborator

unalmis commented Jan 17, 2025

When the DFTInterpolator is used in the singular integral routine the results are not correct, and also not deterministic on my machine. Running this test multiple times gives different results. Attached is example output.

@pytest.mark.unit
def test_singular_integral_vac_estell(self):
    """Test calculating Bplasma for vacuum estell, which should be near 0."""
    eq = get("ESTELL")
    grid = LinearGrid(M=25, N=25, NFP=eq.NFP)
    keys = [
        "K_vc",
        "B",
        "|B|^2",
        "R",
        "phi",
        "Z",
        "e^rho",
        "n_rho",
        "|e_theta x e_zeta|",
    ]
    data = eq.compute(keys, grid=grid)
    k = min(grid.num_theta, grid.num_zeta * grid.NFP)
    s = k - 1
    q = k // 2 + int(np.sqrt(k))
    interpolator = DFTInterpolator(grid, grid, s, q)
    Bplasma = virtual_casing_biot_savart(data, data, interpolator, loop=True)
    # need extra factor of B/2 bc we're evaluating on plasma surface
    Bplasma += data["B"] / 2
    Bplasma = np.linalg.norm(Bplasma, axis=-1)
    # scale by total field magnitude
    B = Bplasma / np.linalg.norm(data["B"], axis=-1).mean()
    np.testing.assert_allclose(B, 0, atol=0.005)
@unalmis
Copy link
Collaborator Author

unalmis commented Jan 17, 2025

  • The issue occurs more often on larger problem sizes.
  • I suspect there might be a numerics issue caused by computing the pseudoinverse of the vandermonde matrix A. A solution would be to compute $c = A^{-1} f$ directly with a Fourier transform and then retain the other basis matrix to interpolate via B@c.

@unalmis unalmis added the bug label Jan 17, 2025
@unalmis unalmis linked a pull request Jan 17, 2025 that will close this issue
@unalmis unalmis self-assigned this Jan 18, 2025
@unalmis unalmis added the P3 Highest Priority, someone is/should be actively working on this label Jan 18, 2025
@unalmis unalmis linked a pull request Jan 22, 2025 that will close this issue
@unalmis unalmis removed the bug label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Highest Priority, someone is/should be actively working on this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant