Skip to content

Commit

Permalink
Merge pull request #351 from hiddenSymmetries/cbs/spec_nonstellsym_fix
Browse files Browse the repository at this point in the history
Cbs/spec nonstellsym fix
  • Loading branch information
landreman authored Sep 15, 2023
2 parents f8f9d59 + d02fa16 commit 48b6b54
Show file tree
Hide file tree
Showing 4 changed files with 1,241 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/simsopt/field/normal_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ def from_spec(cls, filename):
if ph['istellsym']:
vnc = None
else:
vnc = np.asarray(ph['vnc'][1:])
vnc = np.asarray(ph['vnc'])

nf = cls(
nfp=ph['nfp'],
stellsym=ph['istellsym'],
mpol=ph['Mpol'],
normal_field = cls(
nfp=ph['nfp'],
stellsym=bool(ph['istellsym']),
mpol=ph['Mpol'],
ntor=ph['Ntor'],
vns=vns,
vnc=vnc
)

return nf
return normal_field

def get_index_in_dofs(self, m, n, mpol=None, ntor=None, even=False):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/mhd/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __init__(self,
if si.lfreebound:
self.normal_field = NormalField.from_spec(filename)
else:
self.normal_field = None
self.normal_field: Optional[NormalField] = None

# By default, all dofs owned by SPEC directly, as opposed to
# dofs owned by the boundary surface object, are fixed.
Expand Down
18 changes: 18 additions & 0 deletions tests/mhd/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ def test_init_from_file(self):
self.assertAlmostEqual(s.boundary.get_rc(0, 1), 0.1, places=places)
self.assertAlmostEqual(s.boundary.get_zs(0, 1), 0.1, places=places)

def test_init_freeboundary_nonstellsym(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)

places = 7
self.assertAlmostEqual(s.normal_field.get_vns(0, 1), 3.615260745287559e-04, places)
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_init_freeboundary(self):
"""
Try creating a Spec instance from a freeboundary file. Check value
Expand Down
Loading

0 comments on commit 48b6b54

Please sign in to comment.