Skip to content

Commit 78f0349

Browse files
authored
Merge pull request #104 from boutproject/check-doublenull-connectedness
Check if equilibrium can be gridded as connected double-null
2 parents 0a2f6d4 + 3a1c146 commit 78f0349

3 files changed

Lines changed: 93 additions & 18 deletions

File tree

doc/whats-new.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ What's new
22
==========
33

44

5+
0.4.1 (26th May 2021)
6+
---------------------
7+
8+
### Bug fixes
9+
10+
- Check if an equilibrium can be gridded as a connected double-null before gridding.
11+
Prevents creation of invalid grids where second X-point is outside the first
12+
flux-surface in the SOL (#104)\
13+
By [John Omotani](https://github.com/johnomotani)
14+
515
0.4.0 (26th May 2021)
616
---------------------
717

hypnotoad/cases/tokamak.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,23 @@ def __init__(
364364
psi2D *= -1.0
365365
psi1D *= -1.0
366366

367+
self.psi_increasing = psi1D[-1] > psi1D[0]
368+
367369
if self.user_options.extrapolate_profiles:
368370
# Extend the array to outer-most psi on grid
369371
if pressure is not None:
370372
dpdpsi = (pressure[-1] - pressure[-2]) / (psi1D[-1] - psi1D[-2])
371373

372-
psi_increasing = psi1D[-1] > psi1D[0]
373-
if psi_increasing:
374+
if self.psi_increasing:
374375
psi_outer = max(
375376
self.user_options.psi_sol, self.user_options.psi_sol_inner
376377
)
377378
else:
378379
psi_outer = min(
379380
self.user_options.psi_sol, self.user_options.psi_sol_inner
380381
)
381-
if (psi_increasing and psi_outer > psi1D[-1]) or (
382-
not psi_increasing and psi_outer < psi1D[-1]
382+
if (self.psi_increasing and psi_outer > psi1D[-1]) or (
383+
not self.psi_increasing and psi_outer < psi1D[-1]
383384
):
384385
# if psi_outer is not beyond the last point of psi1D, no need to extend
385386
# Exclude first point since duplicates last point in core
@@ -1117,10 +1118,34 @@ def describeDoubleNull(self):
11171118
("outer_core", 1, "outer_lower_divertor", 1),
11181119
]
11191120

1121+
segments = self.segmentsWithPsivals(segments)
1122+
1123+
psi_check_sign = 1.0 if self.psi_increasing else -1.0
1124+
if (
1125+
psi_check_sign * segments["outer_sol"]["psi_vals"][1]
1126+
< psi_check_sign * self.psi_sep[1]
1127+
):
1128+
raise ValueError(
1129+
"Cannot create connected double-null grid - second X-point would "
1130+
"be outside first gridded flux-surface in the outer SOL. Try "
1131+
"increasing psi_spacing_separatrix_multiplier or setting "
1132+
"nx_inter_sep>0."
1133+
)
1134+
if (
1135+
psi_check_sign * segments["inner_sol"]["psi_vals"][1]
1136+
< psi_check_sign * self.psi_sep[1]
1137+
):
1138+
raise ValueError(
1139+
"Cannot create connected double-null grid - second X-point would "
1140+
"be outside first gridded flux-surface in the inner SOL. Try"
1141+
"increasing psi_spacing_separatrix_multiplier or setting "
1142+
"nx_inter_sep>0."
1143+
)
1144+
11201145
return (
11211146
leg_regions,
11221147
core_regions,
1123-
self.segmentsWithPsivals(segments),
1148+
segments,
11241149
connections,
11251150
)
11261151

hypnotoad/test_suite/test_tokamak.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def test_bounding():
187187
np.linspace(Rmin, Rmax, nx),
188188
np.linspace(Zmin, Zmax, ny),
189189
np.zeros((nx, ny)), # psi2d
190-
[],
191-
[], # psi1d, fpol
190+
np.linspace(0.0, 1.0, nx), # psi1d
191+
np.linspace(0.0, 1.0, nx), # fpol1d
192192
make_regions=False,
193193
)
194194

@@ -216,7 +216,12 @@ def psi_func(R, Z):
216216
)
217217

218218
eq = tokamak.TokamakEquilibrium(
219-
r1d, z1d, psi_func(r2d, z2d), [], [], make_regions=False # psi1d, fpol
219+
r1d,
220+
z1d,
221+
psi_func(r2d, z2d),
222+
np.linspace(0.0, 1.0, nx), # psi1d
223+
np.linspace(0.0, 1.0, nx), # fpol1d
224+
make_regions=False,
220225
)
221226

222227
assert len(eq.x_points) == 1
@@ -245,8 +250,8 @@ def test_wall_anticlockwise():
245250
np.linspace(Rmin, Rmax, nx),
246251
np.linspace(Zmin, Zmax, ny),
247252
np.zeros((nx, ny)), # psi2d
248-
[],
249-
[], # psi1d, fpol
253+
np.linspace(0.0, 1.0, nx), # psi1d
254+
np.linspace(0.0, 1.0, nx), # fpol1d
250255
wall=wall,
251256
make_regions=False,
252257
)
@@ -275,8 +280,8 @@ def test_wall_clockwise():
275280
np.linspace(Rmin, Rmax, nx),
276281
np.linspace(Zmin, Zmax, ny),
277282
np.zeros((nx, ny)), # psi2d
278-
[],
279-
[], # psi1d, fpol
283+
np.linspace(0.0, 1.0, nx), # psi1d
284+
np.linspace(0.0, 1.0, nx), # fpol1d
280285
wall=wall,
281286
make_regions=False,
282287
)
@@ -312,7 +317,12 @@ def psi_func(R, Z):
312317
)
313318

314319
return tokamak.TokamakEquilibrium(
315-
r1d, z1d, psi_func(r2d, z2d), [], [], make_regions=False # psi1d, fpol
320+
r1d,
321+
z1d,
322+
psi_func(r2d, z2d),
323+
np.linspace(0.0, 1.0, nx), # psi1d
324+
np.linspace(0.0, 1.0, nx), # fpol1d
325+
make_regions=False,
316326
)
317327

318328

@@ -335,7 +345,12 @@ def psi_func(R, Z):
335345
)
336346

337347
return tokamak.TokamakEquilibrium(
338-
r1d, z1d, psi_func(r2d, z2d), [], [], make_regions=False # psi1d, fpol
348+
r1d,
349+
z1d,
350+
psi_func(r2d, z2d),
351+
np.linspace(0.0, 1.0, nx), # psi1d
352+
np.linspace(0.0, 1.0, nx), # fpol1d
353+
make_regions=False,
339354
)
340355

341356

@@ -359,7 +374,12 @@ def psi_func(R, Z):
359374
)
360375

361376
return tokamak.TokamakEquilibrium(
362-
r1d, z1d, psi_func(r2d, z2d), [], [], make_regions=False # psi1d, fpol
377+
r1d,
378+
z1d,
379+
psi_func(r2d, z2d),
380+
psi_func(np.linspace(1.6, 2.0, nx), np.zeros(nx)), # psi1d
381+
np.linspace(0.0, 1.0, nx), # fpol1d
382+
make_regions=False,
363383
)
364384

365385

@@ -382,7 +402,13 @@ def psi_func(R, Z):
382402
)
383403

384404
return tokamak.TokamakEquilibrium(
385-
r1d, z1d, psi_func(r2d, z2d), [], [], make_regions=False # psi1d, fpol
405+
r1d,
406+
z1d,
407+
psi_func(r2d, z2d),
408+
psi_func(np.linspace(1.6, 2.0, nx), np.zeros(nx)), # psi1d
409+
np.linspace(0.0, 1.0, nx), # fpol1d
410+
make_regions=False,
411+
settings={"nx_inter_sep": 1},
386412
)
387413

388414

@@ -405,7 +431,13 @@ def psi_func(R, Z):
405431
)
406432

407433
return tokamak.TokamakEquilibrium(
408-
r1d, z1d, psi_func(r2d, z2d), [], [], make_regions=False # psi1d, fpol
434+
r1d,
435+
z1d,
436+
psi_func(r2d, z2d),
437+
psi_func(np.linspace(1.6, 2.0, nx), np.zeros(nx)), # psi1d
438+
np.linspace(0.0, 1.0, nx), # fpol1d
439+
make_regions=False,
440+
settings={"nx_inter_sep": 1},
409441
)
410442

411443

@@ -431,8 +463,16 @@ def psi_func(R, Z):
431463
+ np.exp(-((R - r0) ** 2 + (Z - 2 * z0) ** 2) / 0.3 ** 2)
432464
)
433465

466+
settings.update(nx_inter_sep=1)
467+
434468
return tokamak.TokamakEquilibrium(
435-
r1d, z1d, psi_func(r2d, z2d), [], [], make_regions=False, settings=settings
469+
r1d,
470+
z1d,
471+
psi_func(r2d, z2d),
472+
psi_func(np.linspace(1.6, 2.0, nx), np.zeros(nx)), # psi1d
473+
np.linspace(0.0, 1.0, nx), # fpol1d
474+
make_regions=False,
475+
settings=settings,
436476
)
437477

438478

0 commit comments

Comments
 (0)