Skip to content

Commit

Permalink
clarifying documentation and fixing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgiuliani committed May 17, 2024
1 parent 6426096 commit 6890be8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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

0 comments on commit 6890be8

Please sign in to comment.