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

CurveCWSFourier Class for CWS bounded coil optimization #420

Draft
wants to merge 131 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
6575949
just so I dont lose my work (! not working yet !)
joaopedrobiu6 Nov 29, 2022
d363075
Merge branch 'hiddenSymmetries:master' into jb/curvecws
joaopedrobiu6 Nov 29, 2022
10ecf48
curve parameterization algorithm done, no surface
joaopedrobiu6 Nov 30, 2022
3146188
surface part added but not tested
joaopedrobiu6 Dec 5, 2022
9271da0
tried to build the unfinished curvecws and linked with the python par…
joaopedrobiu6 Dec 24, 2022
697f1f2
upt everything I thought was needed, cant include
joaopedrobiu6 Dec 27, 2022
2623dc0
added to init_curves the function pycurverzfourier
rogeriojorge Jan 5, 2023
fb6ceb1
Removed override from curvecws set_surface
rogeriojorge Jan 5, 2023
72fc01d
removed cmake-build folder
joaopedrobiu6 Jan 8, 2023
e2a2a36
remove the autoindentation to prepare pull request
joaopedrobiu6 Jan 8, 2023
9348c8a
Merge branch 'hiddenSymmetries:master' into jb/curvecws
joaopedrobiu6 Jan 8, 2023
d4ac060
added a folder to git ignore
joaopedrobiu6 Jan 8, 2023
ec4f31f
added a folder to gitignore
joaopedrobiu6 Jan 8, 2023
aab7e13
Merge remote-tracking branch 'origin/jb/curvecws' into jb/curvecws
joaopedrobiu6 Jan 8, 2023
4543584
removed cmake-build folder
joaopedrobiu6 Jan 8, 2023
032a464
it compiles but still has a vector size related problem
joaopedrobiu6 Jan 9, 2023
5db804b
CWS_test added
joaopedrobiu6 Jan 12, 2023
6da4cf9
Fixed bug in curve CWS for initialization of r and z
rogeriojorge Jan 12, 2023
2b8d536
updated tests/geo/test_CurveCWS.py
joaopedrobiu6 Jan 19, 2023
110e3db
updated curvecws_gamma_impl to account for stellsym
joaopedrobiu6 Jan 19, 2023
ee532cb
added plot superimposing curve and surface
rogeriojorge Jan 19, 2023
df839a5
merging coil test
rogeriojorge Jan 19, 2023
40dc0fb
atribbute error in num_dofs_surface and get_dofs_surface
joaopedrobiu6 Feb 3, 2023
ecce5ce
implemented gammadash and gammadashdash
joaopedrobiu6 Feb 5, 2023
4265b85
Merge remote-tracking branch 'refs/remotes/origin/jb/curvecws' into j…
joaopedrobiu6 Feb 5, 2023
306cb12
Merge branch 'hiddenSymmetries:master' into jb/curvecws
joaopedrobiu6 Feb 5, 2023
5afd79e
commented the section that plots (r, z)
joaopedrobiu6 Feb 5, 2023
9008083
last commit
joaopedrobiu6 Feb 9, 2023
0bcdefe
get_dofs_surface and num_dofs_surface now with pybind11
rogeriojorge Feb 9, 2023
1fa3e0d
Bug fixed! i on rbc should be i-ntor
rogeriojorge Feb 9, 2023
61ade22
completed gamma###
joaopedrobiu6 Feb 12, 2023
5ab811c
bug fixed in the derivatives
joaopedrobiu6 Feb 15, 2023
10af126
Merge branch 'hiddenSymmetries:master' into jb/curvecws
joaopedrobiu6 Feb 15, 2023
2e59203
preparing for pull request
joaopedrobiu6 Feb 15, 2023
3af1110
preparing for pull request
joaopedrobiu6 Feb 15, 2023
5dad414
all ready for pull request
joaopedrobiu6 Feb 15, 2023
8115589
tried to implement dgamma_by_dcoeff - needs to be simplefied to run
joaopedrobiu6 Feb 18, 2023
3428a69
changed the name to CurveCWSFourier
joaopedrobiu6 Mar 5, 2023
32b2743
Merge branch 'hiddenSymmetries:master' into jb/curvecws
joaopedrobiu6 Mar 5, 2023
0cb5e63
still working on debugging dgamma_by_dcoeff
joaopedrobiu6 Mar 18, 2023
8f28017
changed the pragma directive to the surface for since its harder to c…
joaopedrobiu6 Mar 22, 2023
0f9f504
stellsym for dgamma_by_dcoeff done. I think its all working
joaopedrobiu6 Mar 22, 2023
7396950
Merge branch 'hiddenSymmetries:master' into jb/curvecwsfourier
joaopedrobiu6 Mar 31, 2023
442b7d1
updated dgamma by dcoeff
joaopedrobiu6 Mar 31, 2023
7247992
nothing just run some examples
joaopedrobiu6 Mar 31, 2023
10bd132
solved the bug on the derivatives
joaopedrobiu6 Apr 4, 2023
cf5f3ac
identation
joaopedrobiu6 Apr 4, 2023
0c45b82
implemented dgammadash_by_dcoeff
joaopedrobiu6 Apr 5, 2023
3db0c80
removed some unnecessary code
joaopedrobiu6 Apr 5, 2023
eb5e012
starting to implement dgammadashdash_by_dcoeff
joaopedrobiu6 Apr 8, 2023
a2dc43a
finalized dgammadashdash_by_dcoeff
joaopedrobiu6 Apr 8, 2023
9d66c3f
stellsym for dgammadash_by_dcoeff
joaopedrobiu6 Apr 13, 2023
6655104
error fix in dgammadash_by_dcoeff
joaopedrobiu6 Apr 13, 2023
8c94bf3
bug fix in grad calculation
joaopedrobiu6 Apr 14, 2023
9ec9737
update
joaopedrobiu6 Apr 21, 2023
771960f
debugging dgammabydcoeff
joaopedrobiu6 Apr 25, 2023
47081b6
changed the name of some variables for better understanding of the code
joaopedrobiu6 Apr 25, 2023
c36914a
changed the names o the variables and fixed some bugs
joaopedrobiu6 Apr 27, 2023
bc68232
bug fix
joaopedrobiu6 Apr 27, 2023
15fb675
Merge branch 'hiddenSymmetries:master' into jb/curvecwsfourier
joaopedrobiu6 Apr 27, 2023
aa8b1ea
bug fixing
joaopedrobiu6 Apr 27, 2023
ff8d179
fully fixed dgammadash_by_dcoeff
joaopedrobiu6 Apr 29, 2023
e0fc9f0
started to fix dgammadashdashdash_by_dcoeff
joaopedrobiu6 Apr 29, 2023
8765a11
Added optimization routine for curves and curves+cws
rogeriojorge Apr 29, 2023
f126aff
Added linting
rogeriojorge Apr 29, 2023
4151e37
Merge pull request #2 from hiddenSymmetries/rj/single_stage_PR
rogeriojorge Apr 29, 2023
a0e3137
Ran autopep
rogeriojorge Apr 29, 2023
545f6dd
First attempt at optimization of coils + surfaces
rogeriojorge Apr 29, 2023
102b6e7
Added single stage optimization with curveCWSfourier
rogeriojorge Apr 29, 2023
10ec969
Now curvecwsfourier allows loading from simsopt
rogeriojorge Apr 29, 2023
0e4f49a
finally some good parameters for single stage cws optimization
rogeriojorge Apr 30, 2023
617b6d3
trying to use both full and half period surfaces
rogeriojorge Apr 30, 2023
a6993e5
now with surf_full working
rogeriojorge Apr 30, 2023
05f6903
ran autopep
rogeriojorge Apr 30, 2023
f943c61
surf after stage 2 is now full
rogeriojorge Apr 30, 2023
ccecca1
optimization converging but still need to find optimal CWS and coil p…
rogeriojorge May 1, 2023
99fd52d
finally nailed down the parameters for the coils
rogeriojorge May 2, 2023
9c5f219
resulting configurations
rogeriojorge May 2, 2023
b4ff74e
same
rogeriojorge May 2, 2023
9b9539b
same
rogeriojorge May 2, 2023
ccfb293
same
rogeriojorge May 2, 2023
eda5c9e
optimized some code
joaopedrobiu6 May 3, 2023
7431e55
fixed a bug that ill double check tomorrow
joaopedrobiu6 May 4, 2023
b8372b2
stellsym for dgammadashdash_by_dcoeff
joaopedrobiu6 May 4, 2023
365f86d
bug fixes
joaopedrobiu6 May 4, 2023
8effd25
bug fixed related with parallelization
joaopedrobiu6 May 5, 2023
1acd41e
fixed a bug
joaopedrobiu6 May 5, 2023
4d70eac
bug fixes
joaopedrobiu6 May 5, 2023
be4783f
single stave curveCWS example created
rogeriojorge May 5, 2023
cc64114
Merge branch 'jb/curvecwsfourier' of https://github.com/joaopedrobiu6…
rogeriojorge May 5, 2023
ac86794
Now without test_curvecws and with linting
rogeriojorge May 5, 2023
3bdf42d
Merge branch 'hiddenSymmetries:master' into jb/curvecwsfourier
joaopedrobiu6 May 18, 2023
357fc75
one method was commented
joaopedrobiu6 May 18, 2023
aa7ad8e
Small refactoring of stage two surface
rogeriojorge May 19, 2023
7f4e547
Merge branch 'master' of ssh://github.com/hiddenSymmetries/simsopt in…
rogeriojorge Jun 6, 2023
3b0d5fe
Merge branch 'hiddenSymmetries-master' into jb/curvecwsfourier
rogeriojorge Jun 6, 2023
249ef0c
Merge branch 'master' of https://github.com/hiddenSymmetries/simsopt …
rogeriojorge Jun 7, 2023
47c7bff
Merge branch 'hiddenSymmetries-master' into jb/curvecwsfourier
rogeriojorge Jun 7, 2023
9d2fbca
definition of local according to new PR
rogeriojorge Jun 7, 2023
685ef3f
Test script to make sure that the single stage outputs are correct
rogeriojorge Jun 7, 2023
29965d2
ran autopep
rogeriojorge Jun 7, 2023
64bae2f
Merge branch 'hiddenSymmetries:master' into jb/curvecwsfourier
joaopedrobiu6 Jun 9, 2023
f330cab
update
joaopedrobiu6 Jun 9, 2023
a921515
made all changes
joaopedrobiu6 May 28, 2024
384075e
merged with simsopt master
joaopedrobiu6 May 28, 2024
ae07792
Merge branch 'hiddenSymmetries:master' into jb/curveCWS_new
joaopedrobiu6 Jun 3, 2024
8544749
missing declaration on python_curves.cpp
joaopedrobiu6 Jun 5, 2024
9335b2e
added info text to class constructor
joaopedrobiu6 Jun 6, 2024
9e787dd
info text updated
joaopedrobiu6 Jun 6, 2024
763e0fb
updated the text
joaopedrobiu6 Jun 6, 2024
c5c0935
Fixing linting test
rogeriojorge Jun 7, 2024
2bbf23a
Added windowpane example
rogeriojorge Jun 10, 2024
d26cea4
slight renaming and cleaning
rogeriojorge Jun 10, 2024
b37e54d
Merge branch 'hiddenSymmetries:master' into jb/curveCWS_new
joaopedrobiu6 Jun 14, 2024
ff33848
Merge branch 'hiddenSymmetries:master' into jb/curveCWS_new
joaopedrobiu6 Jun 26, 2024
8c75dfb
Removed examples of CWS coils and plasma optimizatino together
rogeriojorge Jul 2, 2024
94a8f1e
further cleaning of branch
rogeriojorge Jul 2, 2024
f817b9c
updated to pybind11 commit for simsopt
rogeriojorge Jul 2, 2024
646fa54
updated CMakeLists
rogeriojorge Jul 2, 2024
c89c202
same
rogeriojorge Jul 2, 2024
8750673
update cmakelists
rogeriojorge Jul 2, 2024
aea4604
Removed window pane example
rogeriojorge Jul 2, 2024
bc01f03
test
joaopedrobiu6 Jul 2, 2024
5472108
test
joaopedrobiu6 Jul 2, 2024
784d4bf
added curvecwsfourier to cmakelists
rogeriojorge Jul 2, 2024
1f00630
curve_test.py still failing for CurveCWSFourier
joaopedrobiu6 Jul 3, 2024
10c9917
Merge pull request #10 from hiddenSymmetries/master
joaopedrobiu6 Jul 16, 2024
fb04e68
flux objective
joaopedrobiu6 Jul 16, 2024
e310481
Revert "flux objective"
joaopedrobiu6 Jul 16, 2024
45bbe36
fixed error in dgammadash_by_dcoeff
joaopedrobiu6 Jul 24, 2024
f5deeba
fixed all the found errors
joaopedrobiu6 Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pybind11_add_module(${PROJECT_NAME}
src/simsoptpp/biot_savart_py.cpp
src/simsoptpp/biot_savart_vjp_py.cpp
src/simsoptpp/regular_grid_interpolant_3d_py.cpp
src/simsoptpp/curve.cpp src/simsoptpp/curverzfourier.cpp src/simsoptpp/curvexyzfourier.cpp src/simsoptpp/curveplanarfourier.cpp
src/simsoptpp/curve.cpp src/simsoptpp/curverzfourier.cpp src/simsoptpp/curvexyzfourier.cpp src/simsoptpp/curveplanarfourier.cpp src/simsoptpp/curvecwsfourier.cpp
src/simsoptpp/surface.cpp src/simsoptpp/surfacerzfourier.cpp src/simsoptpp/surfacexyzfourier.cpp
src/simsoptpp/integral_BdotN.cpp
src/simsoptpp/dipole_field.cpp src/simsoptpp/permanent_magnet_optimization.cpp
Expand Down Expand Up @@ -170,4 +170,4 @@ target_link_libraries(profiling PRIVATE fmt::fmt-header-only)
#install(TARGETS ${PROJECT_NAME}
# #LIBRARY
# DESTINATION src/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION .)
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION .)
32 changes: 31 additions & 1 deletion docs/source/simsopt.geo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ simsopt.geo.curverzfourier module
simsopt.geo.curveplanarfourier module
-------------------------------------

.. automodule:: simsopt.geo.curveplanarfourier
:members:
:undoc-members:
:show-inheritance:

simsopt.geo.curveplanarfourier module
-------------------------------------

.. automodule:: simsopt.geo.curveplanarfourier
:members:
:undoc-members:
Expand All @@ -76,6 +84,13 @@ simsopt.geo.curvexyzfourier module
:undoc-members:
:show-inheritance:

simsopt.geo.curvecwsfourier module
----------------------------------
.. automodule:: simsopt.geo.curvecwsfourier
:members:
:undoc-members:
:show-inheritance:

simsopt.geo.curvexyzfouriersymmetries module
--------------------------------------------

Expand All @@ -95,6 +110,14 @@ simsopt.geo.finitebuild module
simsopt.geo.framedcurve module
------------------------------

.. automodule:: simsopt.geo.framedcurve
:members:
:undoc-members:
:show-inheritance:

simsopt.geo.framedcurve module
------------------------------

.. automodule:: simsopt.geo.framedcurve
:members:
:undoc-members:
Expand All @@ -115,7 +138,6 @@ simsopt.geo.permanent\_magnet\_grid module
:members:
:undoc-members:
:show-inheritance:

simsopt.geo.plotting module
---------------------------

Expand All @@ -135,6 +157,14 @@ simsopt.geo.qfmsurface module
simsopt.geo.strain_optimization module
--------------------------------------

.. automodule:: simsopt.geo.strain_optimization
:members:
:undoc-members:
:show-inheritance:

simsopt.geo.strain_optimization module
--------------------------------------

.. automodule:: simsopt.geo.strain_optimization
:members:
:undoc-members:
Expand Down
204 changes: 204 additions & 0 deletions examples/2_Intermediate/stage_two_curveCWSfourier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#!/usr/bin/env python
r"""
In this example we solve a FOCUS like Stage II coil optimisation problem: the
goal is to find coils that generate a specific target normal field on a given
surface. The coils are bounded to stick to a particular surface. In this
particular case we consider a vacuum field, so the target is just zero.

The objective is given by

J = (1/2) \int |B dot n|^2 ds
+ LENGTH_WEIGHT * (Maximum CurveLength THRESHOLD)
+ CURVATURE_WEIGHT * CurvaturePenalty(CURVATURE_THRESHOLD)
+ MSC_WEIGHT * MeanSquaredCurvaturePenalty(MSC_THRESHOLD)

if any of the weights are increased, or the thresholds are tightened, the coils
are more regular and better separated, but the target normal field may not be
achieved as well. This example demonstrates the adjustment of weights and
penalties via the use of the `Weight` class.

The target equilibrium is the QA configuration of arXiv:2108.03711.
"""


import os
import numpy as np
from pathlib import Path
from scipy.optimize import minimize
from simsopt.geo import SurfaceRZFourier
from simsopt.objectives import SquaredFlux
from simsopt.objectives import QuadraticPenalty
from simsopt.geo import curves_to_vtk
from simsopt.field import BiotSavart, Current, coils_via_symmetries
from simsopt.geo import (
CurveLength, CurveCurveDistance,
MeanSquaredCurvature, LpCurveCurvature, CurveCWSFourier
)
from simsopt.util import in_github_actions

OUT_DIR = "./output/"
os.makedirs(OUT_DIR, exist_ok=True)

# Number of unique coil shapes, i.e. the number of coils per half field period:
# (Since the configuration has nfp = 2, multiply by 4 to get the total number of coils.)
ncoils = 4

# Number of Fourier modes describing each Cartesian component of each coil:
order = 8

# Choose a circular CWS for the initial coils. If false, the CWS will be
# extended via the normal from the plasma boundary distance_cws_plasma away:
circular_cws = False
distance_cws_plasma = 0.25

# Threshold and weight for the maximum length of each individual coil:
LENGTH_THRESHOLD = 7.0
LENGTH_WEIGHT = 0.01

# Threshold and weight for the coil-to-coil distance penalty in the objective function:
CC_THRESHOLD = 0.07
CC_WEIGHT = 10

# Threshold and weight for the curvature penalty in the objective function:
CURVATURE_THRESHOLD = 25
CURVATURE_WEIGHT = 1e-3

# Threshold and weight for the mean squared curvature penalty in the objective function:
MSC_THRESHOLD = 25
MSC_WEIGHT = 1e-6

# Number of iterations to perform:
MAXITER = 50 if in_github_actions else 400

# File for the desired boundary magnetic surface:
TEST_DIR = (Path(__file__).parent / ".." / ".." / "tests" / "test_files").resolve()
filename = TEST_DIR / 'input.LandremanPaul2021_QA'

#######################################################
# End of input parameters.
#######################################################

# Initialize the boundary magnetic surface:
nphi = 32
ntheta = 32
s = SurfaceRZFourier.from_vmec_input(filename, range="half period", nphi=nphi, ntheta=ntheta)

# Initialize the coil winding surface
if circular_cws:
cws = SurfaceRZFourier.from_nphi_ntheta(nphi, ntheta, "half period", s.nfp, mpol=1, ntor=1)
cws.stellsym = s.stellsym
R = s.get_rc(0, 0)
cws.rc[0, 1] = R
cws.rc[1, 1] = s.get_zs(1, 0)+distance_cws_plasma
cws.zs[1, 1] = s.get_zs(1, 0)+distance_cws_plasma
cws.local_full_x = cws.get_dofs()
else:
cws = SurfaceRZFourier.from_vmec_input(filename, range="half period", nphi=nphi, ntheta=ntheta)
cws.extend_via_normal(distance_cws_plasma)

# Initialize a set of base curves that lie on top of the boundary magnetic surface:
base_curves = []
for i in range(ncoils):
curve_cws = CurveCWSFourier(
mpol=cws.mpol,
ntor=cws.ntor,
idofs=cws.x,
quadpoints=150,
order=order,
nfp=cws.nfp,
stellsym=cws.stellsym,
)
angle = (i+0.5)*(2*np.pi)/((2)*s.nfp*ncoils)
curve_dofs = np.zeros(len(curve_cws.get_dofs()),)
curve_dofs[0] = 1
curve_dofs[2*order+2] = 0
curve_dofs[2*order+3] = angle
curve_cws.set_dofs(curve_dofs)
curve_cws.fix(0)
curve_cws.fix(2*order+2)
base_curves.append(curve_cws)
base_currents = [Current(1)*1e5 for i in range(ncoils)]
# Since the target field is zero, one possible solution is just to set all
# currents to 0. To avoid the minimizer finding that solution, we fix one
# of the currents:
base_currents[0].fix_all()

coils = coils_via_symmetries(base_curves, base_currents, s.nfp, True)
bs = BiotSavart(coils)
bs.set_points(s.gamma().reshape((-1, 3)))

curves = [c.curve for c in coils]
curves_to_vtk(curves, OUT_DIR + "curves_init")
curves_to_vtk(base_curves, OUT_DIR + "base_curves_init")
pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]}
s.to_vtk(OUT_DIR + "surf_init", extra_data=pointData)
cws.to_vtk(OUT_DIR + "cws")

# Define the individual terms objective function:
Jf = SquaredFlux(s, bs)
Jls = [CurveLength(c) for c in base_curves]
Jccdist = CurveCurveDistance(curves, CC_THRESHOLD)
Jcs = [LpCurveCurvature(c, 2, CURVATURE_THRESHOLD) for c in base_curves]
Jmscs = [MeanSquaredCurvature(c) for c in base_curves]

# Form the total objective function. To do this, we can exploit the
# fact that Optimizable objects with J() and dJ() functions can be
# multiplied by scalars and added:
JF = (
Jf
+ LENGTH_WEIGHT * sum(QuadraticPenalty(J, LENGTH_THRESHOLD, "max") for J in Jls)
+ CC_WEIGHT * Jccdist
+ CURVATURE_WEIGHT * sum(Jcs)
+ MSC_WEIGHT * sum(QuadraticPenalty(J, MSC_THRESHOLD, "max") for J in Jmscs)
)

# We don't have a general interface in SIMSOPT for optimisation problems that
# are not in least-squares form, so we write a little wrapper function that we
# pass directly to scipy.optimize.minimize


def fun(dofs):
JF.x = dofs
J = JF.J()
grad = JF.dJ()
jf = Jf.J()
BdotN = np.mean(np.abs(np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)))
outstr = f"J={J:.3e}, Jf={jf:.3e}, ⟨B·n⟩={BdotN:.1e}"
cl_string = ", ".join([f"{J.J():.1f}" for J in Jls])
kap_string = ", ".join(f"{np.max(c.kappa()):.1f}" for c in base_curves)
msc_string = ", ".join(f"{J.J():.1f}" for J in Jmscs)
outstr += f", Len=sum([{cl_string}])={sum(J.J() for J in Jls):.1f}, ϰ=[{kap_string}], ∫ϰ²/L=[{msc_string}]"
outstr += f", C-C-Sep={Jccdist.shortest_distance():.2f}"
print(outstr)
return J, grad


print("""
################################################################################
### Perform a Taylor test ######################################################
################################################################################
""")
f = fun
dofs = JF.x
np.random.seed(1)
h = np.random.uniform(size=dofs.shape)
J0, dJ0 = f(dofs)
dJh = sum(dJ0 * h)
for eps in [1e-3, 1e-4, 1e-5, 1e-6, 1e-7]:
J1, _ = f(dofs + eps*h)
J2, _ = f(dofs - eps*h)
print("err", (J1-J2)/(2*eps) - dJh)

print("""
################################################################################
### Run the optimisation #######################################################
################################################################################
""")
res = minimize(fun, dofs, jac=True, method='L-BFGS-B', options={'maxiter': MAXITER, 'maxcor': 300}, tol=1e-15)
curves_to_vtk(base_curves, OUT_DIR + "base_curves_opt")
curves_to_vtk(curves, OUT_DIR + "curves_opt")
pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]}
s.to_vtk(OUT_DIR + "surf_opt", extra_data=pointData)

# Save the optimized coil shapes and currents so they can be loaded into other scripts for analysis:
bs.save(OUT_DIR + "biot_savart_opt.json")
9 changes: 9 additions & 0 deletions src/simsopt/geo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import jax
jax.config.update("jax_enable_x64", True)
import jax
jax.config.update("jax_enable_x64", True)
from .config import *

from .curve import *
from .curvehelical import *
from .curverzfourier import *
from .curvexyzfourier import *
from .curvexyzfouriersymmetries import *
from .curvexyzfouriersymmetries import *
from .curveperturbed import *
from .curveobjectives import *
from .curvecwsfourier import *
from .curveplanarfourier import *
from .framedcurve import *
from .finitebuild import *
Expand All @@ -24,19 +28,24 @@
from .surfacexyzfourier import *
from .surfacexyztensorfourier import *
from .strain_optimization import *
from .strain_optimization import *

from .permanent_magnet_grid import *

__all__ = (curve.__all__ + curvehelical.__all__ +
curvecwsfourier.__all__ +
curverzfourier.__all__ + curvexyzfourier.__all__ +
curvexyzfouriersymmetries.__all__ +
curvexyzfouriersymmetries.__all__ +
curveperturbed.__all__ + curveobjectives.__all__ +
curveplanarfourier.__all__ +
curveplanarfourier.__all__ +
finitebuild.__all__ + plotting.__all__ +
boozersurface.__all__ + qfmsurface.__all__ +
surface.__all__ +
surfacegarabedian.__all__ + surfacehenneberg.__all__ +
surfacerzfourier.__all__ + surfacexyzfourier.__all__ +
surfacexyztensorfourier.__all__ + surfaceobjectives.__all__ +
strain_optimization.__all__ + framedcurve.__all__ +
strain_optimization.__all__ + framedcurve.__all__ +
permanent_magnet_grid.__all__)
Loading