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

FourierRZToroidalSurface tangent vectors are always 0 or NaN #1532

Open
ddudt opened this issue Jan 21, 2025 · 5 comments
Open

FourierRZToroidalSurface tangent vectors are always 0 or NaN #1532

ddudt opened this issue Jan 21, 2025 · 5 comments
Assignees
Labels
P3 Highest Priority, someone is/should be actively working on this theory Requires theory work before coding

Comments

@ddudt
Copy link
Collaborator

ddudt commented Jan 21, 2025

The compute quantity n_zeta is supposed to be in the direction of $e^\zeta = \nabla\zeta$. In the code, it is computed as $(e_\rho \times e_\theta) / |e_\rho \times e_\theta|$. But since $e_\rho = 0$ is hard-coded for the FourierRZToroidalSurface, this always evaluates to n_zeta = 0 or NaN. The same issue exists for the quantity n_theta, which we compute as $(e_\zeta \times e_\rho) / |e_\zeta \times e_\rho|$.

For the case of n_zeta, I believe the correct implementation should be:

data["n_zeta"] = rpz2xyz_vec(
    jnp.vstack(
        (
            jnp.zeros(transforms["grid"].num_nodes),
            jnp.ones(transforms["grid"].num_nodes),
            jnp.zeros(transforms["grid"].num_nodes),
        )
    ).T,
    phi=data["phi"],
)

Assuming $\zeta = \phi$, this is by definition the unit vector in the direction of $\nabla\zeta$, and this implementation would work for all classes.

The case of n_theta is not as simple, but if the directors were orthogonal we could do something like:

n_theta = cross(n_rho, n_phi)
data["n_theta"] = n_theta / jnp.linalg.norm(n_theta, axis=-1)[:, None]
@ddudt ddudt added bug P3 Highest Priority, someone is/should be actively working on this theory Requires theory work before coding labels Jan 21, 2025
@ddudt ddudt changed the title Bug when computing surface tangent vectors FourierRZToroidalSurface tangent vectors are always 0 or NaN Jan 21, 2025
@dpanici
Copy link
Collaborator

dpanici commented Jan 21, 2025

IIRC, I think that n_zeta is meant to be for ZernikeRZToroidalSection as the normal vector in the zeta direction. The FourierRZToroidalSurface does not have a "normal" direction in the zeta direction because its normal direction is radially outwards, not toroidally directed.

I don't love how it currently is implemented though as it can lead to confusion like here.

@dpanici
Copy link
Collaborator

dpanici commented Jan 21, 2025

If you want the surface tangent vector, that should be things like e_theta or e_zeta, for getting $\frac{d \bm{x}}{d\theta}$ and $\frac{d \bm{x}}{d\zeta}$ on the surface

@ddudt
Copy link
Collaborator Author

ddudt commented Jan 21, 2025

The description for the variable n_zeta states it is the "Unit vector normal to constant zeta surface (direction of e^zeta)". Under the assumption $\zeta = \phi$, shouldn't that always be in the direction given by my code above for all classes? It definitely shouldn't be 0 or NaN.

In this case I do want the tangent vector that points only in the $\hat{\phi}$ direction, which is $e^\zeta$ and not $e_\zeta$.

I think we need to either fix how this is being computed, or change the description if it is supposed to be something else, or not have these quantities implemented for the FourierRZToroidalSurface class if they aren't well defined fort that class.

@unalmis
Copy link
Collaborator

unalmis commented Jan 22, 2025

The cause of this issue is #1127 .

Generally it is not possible to compute gradient vectors from data sampled over a surface because there is no information on the variation of the function in the direction normal to the surface.

The direction of the gradient vectors need not have the same restriction. Unit normals to the surface are known and so are gradients whose direction does not vary with the coordinate that specifies the surface.

$\nabla \phi = R^{-1} \hat{\phi} = R^{-2} e_{\phi}|_{R, Z}$ is such an example.

The gradients of general curvilinear coordinates are not.

Under the assumption ζ = ϕ , shouldn't that always be in the direction given by my code above for all classes? It definitely shouldn't be 0 or NaN.

Yes I agree

@unalmis unalmis removed the bug label Jan 22, 2025
@dpanici
Copy link
Collaborator

dpanici commented Jan 22, 2025

  • just use existing grad(phi)
  • don't let surfaces that n_zeta makes no sense compute n_zeta (i.e. remove from FourierRZToroidalSurface)

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 theory Requires theory work before coding
Projects
None yet
Development

No branches or pull requests

3 participants