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 60 commits into
base: master
Choose a base branch
from
Draft

2nd Order NAE Constraints #1036

wants to merge 60 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)

dpanici added 30 commits March 8, 2023 21:26
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         |     +3.98 +/- 6.87     | +2.17e-02 +/- 3.75e-02 |  5.67e-01 +/- 3.0e-02  |  5.45e-01 +/- 2.3e-02  |
 test_equilibrium_init_medres            |     +0.68 +/- 3.96     | +3.03e-02 +/- 1.76e-01 |  4.48e+00 +/- 1.6e-01  |  4.45e+00 +/- 7.8e-02  |
 test_equilibrium_init_highres           |     -2.29 +/- 4.50     | -1.32e-01 +/- 2.60e-01 |  5.64e+00 +/- 2.2e-01  |  5.77e+00 +/- 1.4e-01  |
 test_objective_compile_dshape_current   |     +0.34 +/- 6.30     | +1.36e-02 +/- 2.54e-01 |  4.05e+00 +/- 1.9e-01  |  4.03e+00 +/- 1.6e-01  |
 test_objective_compute_dshape_current   |     -0.48 +/- 2.55     | -2.50e-05 +/- 1.33e-04 |  5.18e-03 +/- 1.1e-04  |  5.21e-03 +/- 8.0e-05  |
 test_objective_jac_dshape_current       |     +0.23 +/- 5.65     | +9.98e-05 +/- 2.44e-03 |  4.32e-02 +/- 1.8e-03  |  4.31e-02 +/- 1.7e-03  |
 test_perturb_2                          |     -1.24 +/- 3.24     | -2.53e-01 +/- 6.61e-01 |  2.02e+01 +/- 3.5e-01  |  2.04e+01 +/- 5.6e-01  |
 test_proximal_freeb_jac                 |     +0.31 +/- 0.70     | +2.27e-02 +/- 5.15e-02 |  7.39e+00 +/- 4.1e-02  |  7.37e+00 +/- 3.1e-02  |
 test_solve_fixed_iter                   |     +2.16 +/- 2.53     | +7.23e-01 +/- 8.48e-01 |  3.43e+01 +/- 6.7e-01  |  3.36e+01 +/- 5.3e-01  |
 test_LinearConstraintProjection_build   |     +0.37 +/- 2.35     | +3.88e-02 +/- 2.47e-01 |  1.05e+01 +/- 1.8e-01  |  1.05e+01 +/- 1.7e-01  |
 test_build_transform_fft_midres         |     +0.07 +/- 3.25     | +4.36e-04 +/- 2.07e-02 |  6.36e-01 +/- 1.7e-02  |  6.35e-01 +/- 1.2e-02  |
 test_build_transform_fft_highres        |     -0.35 +/- 1.73     | -3.52e-03 +/- 1.73e-02 |  9.97e-01 +/- 1.4e-02  |  1.00e+00 +/- 1.0e-02  |
 test_equilibrium_init_lowres            |     +0.47 +/- 1.74     | +1.91e-02 +/- 7.08e-02 |  4.09e+00 +/- 5.5e-02  |  4.07e+00 +/- 4.5e-02  |
 test_objective_compile_atf              |     -0.13 +/- 4.08     | -1.04e-02 +/- 3.36e-01 |  8.22e+00 +/- 2.6e-01  |  8.23e+00 +/- 2.1e-01  |
 test_objective_compute_atf              |     +0.16 +/- 3.44     | +2.61e-05 +/- 5.58e-04 |  1.62e-02 +/- 3.7e-04  |  1.62e-02 +/- 4.2e-04  |
 test_objective_jac_atf                  |     +1.43 +/- 2.12     | +2.78e-02 +/- 4.11e-02 |  1.97e+00 +/- 2.2e-02  |  1.94e+00 +/- 3.5e-02  |
 test_perturb_1                          |     +0.43 +/- 1.45     | +6.56e-02 +/- 2.21e-01 |  1.53e+01 +/- 1.4e-01  |  1.52e+01 +/- 1.7e-01  |
 test_proximal_jac_atf                   |     -0.32 +/- 0.32     | -2.69e-02 +/- 2.69e-02 |  8.27e+00 +/- 2.1e-02  |  8.29e+00 +/- 1.7e-02  |
 test_proximal_freeb_compute             |     -0.85 +/- 0.79     | -1.73e-03 +/- 1.60e-03 |  2.01e-01 +/- 1.2e-03  |  2.03e-01 +/- 1.1e-03  |
 test_solve_fixed_iter_compiled          |     +0.22 +/- 0.95     | +4.85e-02 +/- 2.11e-01 |  2.22e+01 +/- 1.4e-01  |  2.22e+01 +/- 1.5e-01  |

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 2.55906% with 495 lines in your changes missing coverage. Please review.

Project coverage is 93.06%. Comparing base (4bfa728) to head (6015f44).
Report is 38 commits behind head on master.

Files with missing lines Patch % Lines
desc/objectives/nae_utils.py 1.20% 493 Missing ⚠️
desc/objectives/getters.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1036      +/-   ##
==========================================
- Coverage   95.60%   93.06%   -2.54%     
==========================================
  Files          98       98              
  Lines       25300    25800     +500     
==========================================
- Hits        24188    24011     -177     
- Misses       1112     1789     +677     
Files with missing lines Coverage Δ
desc/equilibrium/equilibrium.py 95.66% <100.00%> (-0.41%) ⬇️
desc/objectives/getters.py 94.04% <60.00%> (-1.08%) ⬇️
desc/objectives/nae_utils.py 30.01% <1.20%> (-67.21%) ⬇️

... and 13 files 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