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

Multifilament coil approximation #223

Merged
merged 16 commits into from
Apr 28, 2022
Merged

Multifilament coil approximation #223

merged 16 commits into from
Apr 28, 2022

Conversation

florianwechsung
Copy link
Contributor

Adds the approach presented in Singh et al to approximate finite-build coils using multiple filaments.

@codecov
Copy link

codecov bot commented Apr 22, 2022

Codecov Report

Merging #223 (f3e4bdb) into master (f90d8f5) will increase coverage by 0.18%.
The diff coverage is 99.43%.

@@            Coverage Diff             @@
##           master     #223      +/-   ##
==========================================
+ Coverage   90.83%   91.01%   +0.18%     
==========================================
  Files          59       60       +1     
  Lines        7733     7899     +166     
==========================================
+ Hits         7024     7189     +165     
- Misses        709      710       +1     
Flag Coverage Δ
unittests 91.01% <99.43%> (+0.18%) ⬆️

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

Impacted Files Coverage Δ
src/simsopt/geo/finitebuild.py 99.34% <99.34%> (ø)
src/simsopt/field/coil.py 98.33% <100.00%> (+0.46%) ⬆️
src/simsopt/util/zoo.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f90d8f5...f3e4bdb. Read the comment docs.

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.

Thanks for contributing this!

codecov is flagging a few cases and functions in curvefilament.py that are not covered. You might see if a few of these cases can be covered without much extra work.

Consider moving stage_two_optimization_finitebuild.py to the 3_Advanced subdirectory?

@@ -0,0 +1,151 @@
#!/usr/bin/env python
r"""
In this example we solve a FOCUS like Stage II coil optimisation problem: the
Copy link
Contributor

Choose a reason for hiding this comment

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

In this docstring, how about saying something about finite build, discuss how the parameter space for this optimization includes the Fourier modes of alpha(theta), and compare and contrast this example with stage_two_optimization.py. It would also be nice to add a reference to the Singh paper here (I see there is a reference in the source, but one here too would be useful to help explain how this example works.)

Comment on lines 74 to 77
numfilaments_n = 1
numfilaments_b = 5
gapsize_n = 0.01
gapsize_b = 0.01
Copy link
Contributor

Choose a reason for hiding this comment

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

How about moving these 4 parameters from lines 74-77 up to around line 52 so they are with the other parameters. Also it would be helpful to explain in comments what _n and _b and gapsize mean.



base_curves_finite_build = sum([
create_multifilament_grid(c, numfilaments_n, numfilaments_b, gapsize_n, gapsize_b, rotation_order=3) for c in base_curves], [])
Copy link
Contributor

Choose a reason for hiding this comment

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

How about making rotation_order one of the parameters as in lines 30-54, so users have an easier time spotting how to control this aspect of the parameter space.

# Define the objective function:
Jf = SquaredFlux(s, bs)
Jls = [CurveLength(c) for c in base_curves]
curves_for_dist = [c.curve for c in coils[::(numfilaments_n*numfilaments_b)]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth a comment about what is going on here.

@@ -72,6 +72,31 @@ def __neg__(self):
return ScaledCurrent(self, -1.)


def apply_symmetries_to_curves(base_curves, nfp, stellsym):
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring

Comment on lines 111 to 116
fils = create_multifilament_grid(
c, numfilaments_n, numfilaments_b, gapsize_n, gapsize_b,
rotation_order=3, rotation_scaling=None)

xr = fils[0].rotation.x
fils[0].rotation.x = xr + 1e-2*np.random.standard_normal(size=xr.shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these lines after line 110 do anything?

Comment on lines 102 to 104
fils = create_multifilament_grid(
c, numfilaments_n, numfilaments_b, gapsize_n, gapsize_b,
rotation_order=3, rotation_scaling=None)
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 unnecessary?



class MultifilamentTesting(unittest.TestCase):

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth adding a test case in this file which is basically the Taylor test in stage_two_optimization_finitebuild.py but with asserts? If the Taylor test in that example fails, presently no error is raised. The Taylor test in that example ensures that the finite build machinery works even when applying nfp-symmetry and stellarator-symmetry and plugging the finite-build coils into Biot-Savart, and it's not obvious that the other tests in test_curvefilament.py cover those aspects.

base_currents[0].fix_all()


base_curves_finite_build = sum([
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 line 88, the sum is not obvious. What does it mean to sum two curves? I guess it is list concatenation? Can you add a comment about what the sum does in these contexts?



class ZeroRotation(Optimizable):

Copy link
Contributor

Choose a reason for hiding this comment

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

docstring

@florianwechsung
Copy link
Contributor Author

@landreman I think I have addressed all of your comments. Can you please have a look again?

@florianwechsung florianwechsung merged commit 7704190 into master Apr 28, 2022
@florianwechsung florianwechsung deleted the fw/multifilament branch June 3, 2022 21:50
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