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

Bug in math for surface computations #1174

Closed
unalmis opened this issue Aug 12, 2024 · 1 comment · Fixed by #1175
Closed

Bug in math for surface computations #1174

unalmis opened this issue Aug 12, 2024 · 1 comment · Fixed by #1175
Assignees
Labels
bug Something isn't working

Comments

@unalmis
Copy link
Collaborator

unalmis commented Aug 12, 2024

Let $R$ be a position vector and $x^i$ be the coordinates of a curvilinear system and $y^j$ those of an orthonormal system.
Then $\hat{y}^j$ can be defined unambiguously

$$\hat{y}^j = \frac{\partial R}{\partial y^j} / \Vert \frac{\partial R}{\partial y^j} \Vert $$

Now, the relation below does not follow (hence the $\neq$)

$$\frac{\partial R}{\partial x^i} \cdot \hat{y}^j \neq \frac{\partial y^j}{\partial x^i}$$

However, DESC assumed it does for all surface computations. (Note that a sufficient condition for the relation to hold is if the basis vectors associated with $y^j$ for all $j$ are orthonormal and constant, which is not true in a cylindrical system.)

After fixing this, here are some of the quantities that significantly differ once corrected.

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.geometry.surface.FourierRZToroidalSurface. Name: phi_z.
Mismatched elements: 225 / 225 (100%)
Max absolute difference: 10.2
Max relative difference: 0.91071429
 x: array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,...
 y: array([11.2     , 11.113545, 10.869131, 10.509017, 10.095472,  9.7     ,
        9.390983,  9.221852,  9.221852,  9.390983,  9.7     , 10.095472,
       10.509017, 10.869131, 11.113545, 11.182709, 11.096255, 10.85184 ,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.geometry.surface.FourierRZToroidalSurface. Name: e_phi|r,t.
Mismatched elements: 660 / 675 (97.8%)
Max absolute difference: 10.2
Max relative difference: 10.2
 x: array([[ 0.      , 11.2     , -0.2     ],
       [ 0.      , 11.113545, -0.2     ],
       [ 0.      , 10.869131, -0.2     ],...
 y: array([[ 0.      ,  1.      , -0.017857],
       [ 0.      ,  1.      , -0.017996],
       [ 0.      ,  1.      , -0.018401],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.geometry.surface.FourierRZToroidalSurface. Name: e_phi.
Mismatched elements: 660 / 675 (97.8%)
Max absolute difference: 10.2
Max relative difference: 10.2
 x: array([[ 0.      , 11.2     , -0.2     ],
       [ 0.      , 11.113545, -0.2     ],
       [ 0.      , 10.869131, -0.2     ],...
 y: array([[ 0.      ,  1.      , -0.017857],
       [ 0.      ,  1.      , -0.017996],
       [ 0.      ,  1.      , -0.018401],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.geometry.surface.ZernikeRZToroidalSection. Name: phi_z.
Mismatched elements: 120 / 120 (100%)
Max absolute difference: 1.
Max relative difference: inf
 x: array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,...
 y: array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.geometry.surface.ZernikeRZToroidalSection. Name: e_phi|r,t.
x and y nan location mismatch:
 x: array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.],...
 y: array([[nan, nan, nan],
       [nan, nan, nan],
       [nan, nan, nan],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.geometry.surface.ZernikeRZToroidalSection. Name: e_theta|r,p.
x and y nan location mismatch:
 x: array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],...
 y: array([[nan, nan, nan],
       [nan, nan, nan],
       [nan, nan, nan],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.geometry.surface.ZernikeRZToroidalSection. Name: e_phi.
x and y nan location mismatch:
 x: array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.],...
 y: array([[nan, nan, nan],
       [nan, nan, nan],
       [nan, nan, nan],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.magnetic_fields._current_potential.CurrentPotentialField. Name: phi_z.
Mismatched elements: 225 / 225 (100%)
Max absolute difference: 10.2
Max relative difference: 0.91071429
 x: array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,...
 y: array([11.2     , 11.113545, 10.869131, 10.509017, 10.095472,  9.7     ,
        9.390983,  9.221852,  9.221852,  9.390983,  9.7     , 10.095472,
       10.509017, 10.869131, 11.113545, 11.182709, 11.096255, 10.85184 ,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.magnetic_fields._current_potential.CurrentPotentialField. Name: e_phi|r,t.
Mismatched elements: 660 / 675 (97.8%)
Max absolute difference: 10.2
Max relative difference: 10.2
 x: array([[ 0.      , 11.2     , -0.2     ],
       [ 0.      , 11.113545, -0.2     ],
       [ 0.      , 10.869131, -0.2     ],...
 y: array([[ 0.      ,  1.      , -0.017857],
       [ 0.      ,  1.      , -0.017996],
       [ 0.      ,  1.      , -0.018401],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.magnetic_fields._current_potential.CurrentPotentialField. Name: e_phi.
Mismatched elements: 660 / 675 (97.8%)
Max absolute difference: 10.2
Max relative difference: 10.2
 x: array([[ 0.      , 11.2     , -0.2     ],
       [ 0.      , 11.113545, -0.2     ],
       [ 0.      , 10.869131, -0.2     ],...
 y: array([[ 0.      ,  1.      , -0.017857],
       [ 0.      ,  1.      , -0.017996],
       [ 0.      ,  1.      , -0.018401],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.magnetic_fields._current_potential.FourierCurrentPotentialField. Name: phi_z.
Mismatched elements: 225 / 225 (100%)
Max absolute difference: 10.2
Max relative difference: 0.91071429
 x: array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,...
 y: array([11.2     , 11.113545, 10.869131, 10.509017, 10.095472,  9.7     ,
        9.390983,  9.221852,  9.221852,  9.390983,  9.7     , 10.095472,
       10.509017, 10.869131, 11.113545, 11.182709, 11.096255, 10.85184 ,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.magnetic_fields._current_potential.FourierCurrentPotentialField. Name: e_phi|r,t.
Mismatched elements: 660 / 675 (97.8%)
Max absolute difference: 10.2
Max relative difference: 10.2
 x: array([[ 0.      , 11.2     , -0.2     ],
       [ 0.      , 11.113545, -0.2     ],
       [ 0.      , 10.869131, -0.2     ],...
 y: array([[ 0.      ,  1.      , -0.017857],
       [ 0.      ,  1.      , -0.017996],
       [ 0.      ,  1.      , -0.018401],...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.magnetic_fields._current_potential.FourierCurrentPotentialField. Name: e_phi.
Mismatched elements: 660 / 675 (97.8%)
Max absolute difference: 10.2
Max relative difference: 10.2
 x: array([[ 0.      , 11.2     , -0.2     ],
       [ 0.      , 11.113545, -0.2     ],
       [ 0.      , 10.869131, -0.2     ],...
 y: array([[ 0.      ,  1.      , -0.017857],
       [ 0.      ,  1.      , -0.017996],
       [ 0.      ,  1.      , -0.018401],...

@unalmis unalmis added the bug Something isn't working label Aug 12, 2024
@unalmis unalmis self-assigned this Aug 12, 2024
@dpanici
Copy link
Collaborator

dpanici commented Aug 12, 2024

phi_z it should be just 1 right? Are the x arrays the corrected (on your PR) values and the y array the current values in master? EDIT: ah I see that they are, ok good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants