Skip to content

Commit

Permalink
test normal field setter too
Browse files Browse the repository at this point in the history
  • Loading branch information
smiet committed Jul 5, 2024
1 parent ac81224 commit 800060f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/simsopt/mhd/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ def normal_field(self, normal_field):
"""
if not self.freebound:
raise ValueError('Normal field can only be set in freeboundary case')

Check warning on line 401 in src/simsopt/mhd/spec.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/mhd/spec.py#L401

Added line #L401 was not covered by tests
if not isinstance(normal_field, NormalField) or not isinstance(normal_field):
if not isinstance(normal_field, NormalField):
raise ValueError('Input should be a NormalField or CoilNormalField')

Check warning on line 403 in src/simsopt/mhd/spec.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/mhd/spec.py#L403

Added line #L403 was not covered by tests
if self._normal_field is not normal_field:
self.remove_parent(self._normal_field)
if self._computational_boundary is not normal_field.computational_boundary:
normal_field.computational_boundary = self._computational_boundary
if self._computational_boundary is not normal_field.surface:
normal_field.surface = self._computational_boundary
self._normal_field = normal_field
self.append_parent(normal_field)
return
Expand Down
22 changes: 22 additions & 0 deletions tests/mhd/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from simsopt.geo import SurfaceGarabedian
from simsopt.mhd import ProfileSpec
from simsopt.field import NormalField
from simsopt.objectives import LeastSquaresProblem
from simsopt.solve import least_squares_serial_solve

Expand Down Expand Up @@ -94,6 +95,27 @@ def test_init_freeboundary_nonstellsym(self):
self.assertAlmostEqual(s.normal_field.get_vns(3, -1), -1.269776831212886e-04, places)
self.assertAlmostEqual(s.normal_field.get_vnc(1, 0), 1.924871538367248e-04, places)
self.assertAlmostEqual(s.normal_field.get_vnc(1, -2), 4.070523669489626e-04, places)

def test_normal_field_setter(self):
"""
Try creating a Spec instance from a freeboundary file that is also
non-stellarator symmetric.
Check value of normal field
"""

filename = os.path.join(TEST_DIR, 'M16N08.sp')

with ScratchDir("."):
s = Spec(filename)
surface = s.boundary
old_normal = s.normal_field
new_normal = NormalField(s.nfp, stellsym=s.stellsym, mpol=s.mpol, ntor=s.ntor, surface=surface)
s.normal_field = new_normal
self.assertAlmostEqual(s.normal_field.get_vns(0,1), 0) # set to zeros
self.assertIs(s.normal_field.surface, s._computational_boundary) # normal field surface is set to spec computational boundary.
self.assertIsNot(old_normal, new_normal)



def test_init_freeboundary(self):
"""
Expand Down

0 comments on commit 800060f

Please sign in to comment.