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

Planar #358

Merged
merged 25 commits into from
Nov 27, 2023
Merged

Planar #358

merged 25 commits into from
Nov 27, 2023

Conversation

AlexWiedman
Copy link
Contributor

Created a curve class for planar coils with a fourier series in polar coordinates, a quaternion based rotation vector, and a center vector in cartesian coordinates. This allows for planar coils to be constructed and used in optimization.

@codecov
Copy link

codecov bot commented Oct 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4da5214) 91.40% compared to head (60cb677) 91.43%.
Report is 31 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #358      +/-   ##
==========================================
+ Coverage   91.40%   91.43%   +0.03%     
==========================================
  Files          72       73       +1     
  Lines       12659    12709      +50     
==========================================
+ Hits        11571    11621      +50     
  Misses       1088     1088              
Flag Coverage Δ
unittests 91.43% <100.00%> (+0.03%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@landreman landreman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AlexWiedman, thanks for working on this!!

src/simsoptpp/curveplanarfourier.cpp Outdated Show resolved Hide resolved
Comment on lines 21 to 34
for (int k = 0; k < numquadpoints; ++k) {
double phi = 2 * M_PI * quadpoints[k];
for (int i = 0; i < order+1; ++i) {
data(k, 0) += rc[i] * cos(i*phi) * cos(phi);
data(k, 1) += rc[i] * cos(i*phi) * sin(phi);
}
}
for (int k = 0; k < numquadpoints; ++k) {
double phi = 2 * M_PI * quadpoints[k];
for (int i = 1; i < order+1; ++i) {
data(k, 0) += rs[i-1] * sin(i*phi) * cos(phi);
data(k, 1) += rs[i-1] * sin(i*phi) * sin(phi);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the other subroutines in this file, these two k loops can be combined into a single loop. And if you separate out the i=0 case, then the i loops can be combined as well. Also I'd evaluate cos(i*phi), sin(i*phi), cos(phi), and sin(phi) just once rather than multiple times. Those trig functions can be the rate-limiting step.

src/simsoptpp/curveplanarfourier.cpp Outdated Show resolved Hide resolved
src/simsoptpp/curveplanarfourier.cpp Outdated Show resolved Hide resolved
src/simsopt/geo/curve.py Show resolved Hide resolved
src/simsopt/geo/curveplanarfourier.py Outdated Show resolved Hide resolved
tests/test_files/input.NewConfiguration Outdated Show resolved Hide resolved
same normalized quaternion. Normalizing the dofs directly would create a
dependence between the quaternion dofs, which may cause issues during
optimization.

Copy link
Contributor

@andrewgiuliani andrewgiuliani Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with quaternions -- is there a computational advantage using them over a simple solid body rotation matrix + translation? You would have 3 dofs for the rotation (three rotation angles) and 3 dofs for the translation. If there is a computational advantage, can that be added to the docstring for the class? The formulas in curveplanarfourier.cpp on lines 43-45 are opaque to me.

j = data(m, 1);
k = data(m, 2);

data(m, 0) = (i - 2 * (q_norm[2] * q_norm[2] + q_norm[3] * q_norm[3]) * i + 2 * (q_norm[1] * q_norm[2] - q_norm[3] * q_norm[0]) * j + 2 * (q_norm[1] * q_norm[3] + q_norm[2] * q_norm[0]) * k) + center[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines 43, 44, 45 are opaque to me. Do they complete the solid body rotation? can you comment the code here to explain, and maybe give a reference?

Comment on lines 25 to 34
sinphi = sin(phi);
cosphi = cos(phi);
data(k, 0) = rc[0] * cosphi;
data(k, 1) = rc[0] * sinphi;
for (int i = 1; i < order+1; ++i) {
siniphi = sin(i * phi);
cosiphi = cos(i * phi);
data(k, 0) += (rc[i] * cosiphi + rs[i-1] * siniphi) * cosphi;
data(k, 1) += (rc[i] * cosiphi + rs[i-1] * siniphi) * sinphi;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at how I refactored this loop to minimize the number of calls to sin() and cos(). These transcendental functions are slow, so it is good to call them as few times as possible, by storing the results in cosphi, cosiphi, etc. Please apply a similar refactoring to the other functions in this file to reduce the number of calls to sin() and cos().

Comment on lines +1554 to +1557

#include "xtensor-python/pyarray.hpp" // Numpy bindings
typedef xt::pyarray<double> Array;
template class CurvePlanarFourier<Array>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these lines needed, or can they be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure exactly what these lines do, but they are included in both of the other curve classes, so I thought it would be safest to include them.

@landreman landreman self-requested a review November 27, 2023 17:25
@landreman landreman merged commit 1eeab4b into hiddenSymmetries:master Nov 27, 2023
36 of 37 checks passed
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.

3 participants