Skip to content

Commit

Permalink
Merge pull request #415 from hiddenSymmetries/ag/pr
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgiuliani authored May 20, 2024
2 parents 6426096 + 11f176b commit 56b52d5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/simsopt/geo/boozersurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ def __init__(self, biotsavart, surface, label, targetlabel, constraint_weight=No
# set the default options now
if 'verbose' not in options:
options['verbose'] = True
if 'G' not in options:
options['G'] = None

# default solver options for the BoozerExact and BoozerLS solvers
if self.boozer_type == 'exact':
Expand Down Expand Up @@ -120,7 +118,7 @@ def run_code(self, iota, G=None):
Args:
boozer_type: either 'exact' or 'ls', to indicate whether a BoozerExact or a BoozerLS surface is to be computed.
iota: guess for value of rotational transform on the surface,
G: guess for value of G on surface, defaults to None.
G: guess for value of G on surface, defaults to None. Note that if None is used, then the coil currents must be fixed.
options: dictionary of solver options. If keyword is not specified, then a default
value is used. Possible keywords are:
`verbose`: display convergence information
Expand All @@ -134,6 +132,10 @@ def run_code(self, iota, G=None):
if not self.need_to_run_code:
return

# for coil optimizations, the gradient calculations of the objective assume that the coil currents are fixed when G is None.
if G is None:
assert np.all([c.current.dofs.all_fixed() for c in self.biotsavart.coils])

# BoozerExact default solver
if self.boozer_type == 'exact':
res = self.solve_residual_equation_exactly_newton(iota=iota, G=G, tol=self.options['newton_tol'], maxiter=self.options['newton_maxiter'], verbose=self.options['verbose'])
Expand Down
5 changes: 5 additions & 0 deletions tests/geo/surface_test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def get_boozer_surface(label="Volume", nphi=None, ntheta=None, boozer_type='exac
current_sum = sum(abs(c.current.get_value()) for c in coils)
G0 = 2. * np.pi * current_sum * (4 * np.pi * 10**(-7) / (2 * np.pi)) if optimize_G else None

# currents need to be fixed if optimize_G is None
if optimize_G is False:
for c in bs.coils:
c.current.fix_all()

## RESOLUTION DETAILS OF SURFACE ON WHICH WE OPTIMIZE FOR QA
mpol = 6 if boozer_type == 'exact' else 3
ntor = 6 if boozer_type == 'exact' else 3
Expand Down
15 changes: 11 additions & 4 deletions tests/geo/test_boozersurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,22 @@ def test_run_code(self):
# this second time should not actually run
boozer_surface.run_code(boozer_surface.res['iota'], G=boozer_surface.res['G'])

for c in bs.coils:
c.current.fix_all()

boozer_surface.need_to_run_code=True
# run without providing value of G
boozer_surface.run_code(boozer_surface.res['iota'])

bs, boozer_surface = get_boozer_surface(boozer_type='exact')
boozer_surface.run_code(boozer_surface.res['iota'], G=boozer_surface.res['G'])

# this second time should not actually run
boozer_surface.run_code(boozer_surface.res['iota'], G=boozer_surface.res['G'])

boozer_surface.need_to_run_code=True
# run without providing value of G
boozer_surface.run_code(boozer_surface.res['iota'])
# run the BoozerExact algorithm without a guess for G
boozer_surface.need_to_run_code = True
boozer_surface.solve_residual_equation_exactly_newton(iota=boozer_surface.res['iota'])

def test_convergence_cpp_and_notcpp_same(self):
"""
Expand Down

0 comments on commit 56b52d5

Please sign in to comment.