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

2nd Order NAE Constraints #1036

Draft
wants to merge 52 commits into
base: master
Choose a base branch
from
Draft

2nd Order NAE Constraints #1036

wants to merge 52 commits into from

Conversation

dpanici
Copy link
Collaborator

@dpanici dpanici commented May 24, 2024

  • make tests for this
  • write out the coefficients in a simpler form (see below)

Simpler way to write coefficients

from qsc import Qsc
import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft

name = 'precise QA'
stel = Qsc.from_paper(name)
R0 = stel.R0
Z0 = stel.Z0
dR0 = stel.R0p
ddR0 = stel.R0pp
dZ0 = stel.Z0p
ddZ0 = stel.Z0pp

x1_cos = stel.X1c*stel.normal_cylindrical.transpose()+stel.Y1c*stel.binormal_cylindrical.transpose()
x1_sin = stel.Y1s*stel.binormal_cylindrical.transpose()

x2_0 = stel.X20*stel.normal_cylindrical.transpose()+stel.Y20*stel.binormal_cylindrical.transpose()+stel.Z20*stel.tangent_cylindrical.transpose()
x2_cos = stel.X2c*stel.normal_cylindrical.transpose()+stel.Y2c*stel.binormal_cylindrical.transpose()+stel.Z2c*stel.tangent_cylindrical.transpose()
x2_sin = stel.X2s*stel.normal_cylindrical.transpose()+stel.Y2s*stel.binormal_cylindrical.transpose()+stel.Z2s*stel.tangent_cylindrical.transpose()

X1Rc = x1_cos[0,:]
dX1Rc = np.matmul(stel.d_d_phi, X1Rc)
X1Rs = x1_sin[0,:]
dX1Rs = np.matmul(stel.d_d_phi, X1Rs)
X1thc = x1_cos[1,:]
dX1thc = np.matmul(stel.d_d_phi, X1thc)
X1ths = x1_sin[1,:]
dX1ths = np.matmul(stel.d_d_phi, X1ths)
X1zc = x1_cos[2,:]
dX1zc = np.matmul(stel.d_d_phi, X1zc)
X1zs = x1_sin[2,:]
dX1zs = np.matmul(stel.d_d_phi, X1zs)
X2R0 = x2_0[0,:]
X2th0 = x2_0[1,:]
X2z0 = x2_0[2,:]
X2Rs = x2_sin[0,:]
X2ths = x2_sin[1,:]
X2zs = x2_sin[2,:]
X2Rc = x2_cos[0,:]
X2thc = x2_cos[1,:]
X2zc = x2_cos[2,:]

R1c = X1Rc - dR0/R0*X1thc
R1s = X1Rs - dR0/R0*X1ths

Z1c = X1zc - dZ0/R0*X1thc
Z1s = X1zs - dZ0/R0*X1ths

R20 = X2R0 - dR0**2*(X1thc**2+X1ths**2)/2/R0**3 + 1/4/R0*(X1thc**2 + X1ths**2 - 4*X2th0*dR0 - 2*X1thc*dX1Rc - 2*X1ths*dX1Rs) + \
    1/4/R0**2*(2*X1Rc*X1thc*dR0 + 2*X1Rs*X1ths*dR0 + 2*X1thc*dR0*dX1thc + 2*X1ths*dR0*dX1ths + 3*(X1thc**2+X1ths**2)*ddR0)
R2s = X2Rs - X1thc*X1ths*dR0**2/R0**3 -(2*X2ths*dR0 + X1ths*dX1Rc + X1thc*(-X1ths + dX1Rs))/(2*R0) + \
    (X1Rs*X1thc*dR0 + X1Rc*X1ths*dR0 + X1ths*dR0*dX1thc + X1thc*dR0*dX1ths + X1thc*X1ths*ddR0)/(2*R0**2)
R2c = X2Rc + (-X1thc**2 + X1ths**2)*dR0**2/(2*R0**3)+1/4/R0*(X1thc**2 - X1ths**2 - 4*X2thc*dR0 - \
    2*X1thc*dX1Rc + 2*X1ths*dX1Rs) + 1/4/R0**2*(2*X1Rc*X1thc*dR0 - 2*X1Rs*X1ths*dR0 + 2*X1thc*dR0*dX1thc - \
    2*X1ths*dR0*dX1ths + (X1thc**2-X1ths**2)*ddR0)

Z20 = X2z0 - (X1thc*dX1zc + X1ths*dX1zs + 2*X2th0*dZ0)/2/R0 + \
    (X1Rc*X1thc + X1Rs*X1ths + X1thc*dX1thc + X1ths*dX1ths)*dZ0/2/R0**2 + \
    (X1thc**2 + X1ths**2)*ddZ0/4/R0**2 - (X1thc**2 + X1ths**2)*dR0*dZ0/2/R0**3 

Z2s = X2zs - (X1ths*dX1zc + X1thc*dX1zs + 2*X2ths*dZ0)/2/R0 + \
    ((X1Rs*X1thc + X1Rc*X1ths+ X1ths*dX1thc + X1thc*dX1ths)*dZ0 + X1thc*X1ths*ddZ0)/2/R0**2 - \
    (X1thc*X1ths*dR0*dZ0)/R0**3 

Z2c = X2zc - (X1thc*dX1zc-X1ths*dX1zs+2*X2thc*dZ0)/2/R0 + \
    (X1Rc*X1thc - X1Rs*X1ths + X1thc*dX1thc - X1ths*dX1ths)*dZ0/2/R0**2 - \
    + (X1thc**2 - X1ths**2)*ddZ0/4/R0**2 - (X1thc**2 - X1ths**2)*dR0*dZ0/2/R0**3)

Copy link
Contributor

github-actions bot commented May 24, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +7.47 +/- 3.51     | +3.86e-02 +/- 1.81e-02 |  5.55e-01 +/- 1.6e-02  |  5.16e-01 +/- 8.8e-03  |
 test_equilibrium_init_medres            |     +5.54 +/- 8.34     | +2.27e-01 +/- 3.42e-01 |  4.33e+00 +/- 3.2e-01  |  4.10e+00 +/- 1.3e-01  |
 test_equilibrium_init_highres           |     -1.03 +/- 2.45     | -5.63e-02 +/- 1.34e-01 |  5.40e+00 +/- 5.4e-02  |  5.45e+00 +/- 1.2e-01  |
 test_objective_compile_dshape_current   |     +1.36 +/- 2.86     | +5.20e-02 +/- 1.09e-01 |  3.86e+00 +/- 6.2e-02  |  3.81e+00 +/- 8.9e-02  |
 test_objective_compute_dshape_current   |     -1.70 +/- 4.28     | -6.20e-05 +/- 1.57e-04 |  3.59e-03 +/- 1.5e-04  |  3.65e-03 +/- 4.6e-05  |
 test_objective_jac_dshape_current       |     -0.12 +/- 8.03     | -4.53e-05 +/- 3.14e-03 |  3.90e-02 +/- 1.9e-03  |  3.91e-02 +/- 2.5e-03  |
 test_perturb_2                          |     +0.86 +/- 4.17     | +1.48e-01 +/- 7.19e-01 |  1.74e+01 +/- 6.6e-01  |  1.73e+01 +/- 2.8e-01  |
 test_proximal_freeb_jac                 |     -0.28 +/- 1.27     | -2.06e-02 +/- 9.39e-02 |  7.40e+00 +/- 6.4e-02  |  7.42e+00 +/- 6.8e-02  |
 test_solve_fixed_iter                   |     +0.79 +/- 61.09    | +3.81e-02 +/- 2.95e+00 |  4.87e+00 +/- 2.0e+00  |  4.84e+00 +/- 2.1e+00  |
 test_build_transform_fft_midres         |     -5.16 +/- 3.33     | -3.55e-02 +/- 2.29e-02 |  6.53e-01 +/- 2.0e-02  |  6.88e-01 +/- 1.1e-02  |
 test_build_transform_fft_highres        |     -3.03 +/- 3.22     | -3.28e-02 +/- 3.49e-02 |  1.05e+00 +/- 1.8e-02  |  1.08e+00 +/- 3.0e-02  |
+test_equilibrium_init_lowres            |     -8.58 +/- 1.85     | -3.83e-01 +/- 8.26e-02 |  4.08e+00 +/- 4.7e-02  |  4.46e+00 +/- 6.8e-02  |
 test_objective_compile_atf              |     -2.42 +/- 2.09     | -2.09e-01 +/- 1.80e-01 |  8.40e+00 +/- 1.4e-01  |  8.61e+00 +/- 1.1e-01  |
 test_objective_compute_atf              |     +2.97 +/- 4.62     | +3.38e-04 +/- 5.25e-04 |  1.17e-02 +/- 4.6e-04  |  1.14e-02 +/- 2.6e-04  |
 test_objective_jac_atf                  |     -1.59 +/- 2.10     | -3.28e-02 +/- 4.33e-02 |  2.03e+00 +/- 3.1e-02  |  2.06e+00 +/- 3.0e-02  |
 test_perturb_1                          |     -5.26 +/- 2.18     | -7.41e-01 +/- 3.07e-01 |  1.33e+01 +/- 1.1e-01  |  1.41e+01 +/- 2.8e-01  |
 test_proximal_jac_atf                   |     -0.42 +/- 1.08     | -3.51e-02 +/- 9.05e-02 |  8.37e+00 +/- 8.0e-02  |  8.40e+00 +/- 4.2e-02  |
 test_proximal_freeb_compute             |     +0.76 +/- 1.13     | +1.44e-03 +/- 2.14e-03 |  1.91e-01 +/- 1.6e-03  |  1.89e-01 +/- 1.4e-03  |

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 88.82576% with 59 lines in your changes missing coverage. Please review.

Project coverage is 95.30%. Comparing base (75eafcc) to head (fd7b381).

Files with missing lines Patch % Lines
desc/objectives/nae_utils.py 91.85% 39 Missing ⚠️
desc/equilibrium/equilibrium.py 44.11% 19 Missing ⚠️
desc/objectives/getters.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1036      +/-   ##
==========================================
- Coverage   95.44%   95.30%   -0.15%     
==========================================
  Files          95       95              
  Lines       23423    23926     +503     
==========================================
+ Hits        22357    22803     +446     
- Misses       1066     1123      +57     
Flag Coverage Δ
95.30% <88.82%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
desc/objectives/linear_objectives.py 97.05% <100.00%> (+<0.01%) ⬆️
desc/objectives/utils.py 100.00% <ø> (ø)
desc/objectives/getters.py 95.18% <80.00%> (+0.11%) ⬆️
desc/equilibrium/equilibrium.py 93.29% <44.11%> (-2.43%) ⬇️
desc/objectives/nae_utils.py 93.50% <91.85%> (-3.72%) ⬇️

... and 1 file with indirect coverage changes

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.

2 participants