Skip to content

Commit

Permalink
changes for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgiuliani committed May 8, 2024
1 parent 31cdd22 commit d68dec9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 3 additions & 6 deletions tests/geo/surface_test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_exact_surface(surface_type='SurfaceXYZFourier'):
return s


def get_boozer_surface(label="Volume", nphi=None, ntheta=None, boozer_type='exact', optimize_G=True):
def get_boozer_surface(label="Volume", nphi=None, ntheta=None, boozer_type='exact', optimize_G=True, converge=True, stellsym=True):
"""
Returns a boozer surface that will be used in unit tests.
"""
Expand All @@ -90,7 +90,6 @@ def get_boozer_surface(label="Volume", nphi=None, ntheta=None, boozer_type='exac
## 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
stellsym = True
nfp = 3

if boozer_type == 'exact':
Expand Down Expand Up @@ -122,9 +121,7 @@ def get_boozer_surface(label="Volume", nphi=None, ntheta=None, boozer_type='exac
## COMPUTE THE SURFACE
cw = None if boozer_type == 'exact' else 100.
boozer_surface = BoozerSurface(bs, s, lab, lab_target, constraint_weight=cw)
boozer_surface.run_code(boozer_type, iota, G=G0, verbose=True)

#res = boozer_surface.solve_residual_equation_exactly_newton(tol=1e-13, maxiter=20, iota=iota, G=G0)
#print(f"NEWTON {res['success']}: iter={res['iter']}, iota={res['iota']:.3f}, vol={s.volume():.3f}")
if converge:
boozer_surface.run_code(boozer_type, iota, G=G0, verbose=True)

return bs, boozer_surface
16 changes: 10 additions & 6 deletions tests/geo/test_surface_objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,15 @@ def df(dofs):
class LabelTests(unittest.TestCase):
def test_label_surface_derivative1(self):
for label in ["Volume", "ToroidalFlux", "Area", "AspectRatio"]:
with self.subTest(label=label):
self.subtest_label_derivative1(label)

def subtest_label_derivative1(self, label):
bs, boozer_surface = get_boozer_surface(label=label, nphi=13, ntheta=14)
for stellsym in stellsym_list:
for nphi, ntheta in [(13, 14), (None, None), (13, None), (None, 14)]:
with self.subTest(label=label, stellsym=stellsym, converge=stellsym):
# don't converge the BoozerSurface when stellsym=False because it takes a long time
# for a unit test
self.subtest_label_derivative1(label, stellsym=stellsym, converge=stellsym, nphi=nphi, ntheta=ntheta)

def subtest_label_derivative1(self, label, stellsym, converge, nphi, ntheta):
bs, boozer_surface = get_boozer_surface(label=label, nphi=nphi, ntheta=ntheta, converge=converge, stellsym=stellsym)
surface = boozer_surface.surface
label = boozer_surface.label
coeffs = surface.x
Expand All @@ -406,7 +410,7 @@ def df(dofs):
epsilons=np.power(2., -np.asarray(range(13, 19))))

def test_label_surface_derivative2(self):
for label in ["Volume", "ToroidalFlux", "Area"]:
for label in ["Volume", "ToroidalFlux", "Area", "AspectRatio"]:
with self.subTest(label=label):
self.subtest_label_derivative2(label)

Expand Down

0 comments on commit d68dec9

Please sign in to comment.