From 03373352353cb383e312af5417ebe57b089a39af Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Tue, 17 Jun 2025 12:39:11 -0700 Subject: [PATCH 1/3] tokamak: leg_extend options Extends the divertor leg by the specified distance beyond where the separatrix intersects the divertor target. This is useful in combination with the penalty boundary condition, enabling the mesh to cover the whole divertor volume. --- hypnotoad/cases/tokamak.py | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/hypnotoad/cases/tokamak.py b/hypnotoad/cases/tokamak.py index 4a472c31..217359fa 100644 --- a/hypnotoad/cases/tokamak.py +++ b/hypnotoad/cases/tokamak.py @@ -78,6 +78,36 @@ class TokamakEquilibrium(Equilibrium): value_type=float, check_all=is_positive, ), + leg_extend=WithMeta( + 0.0, + doc="Extend divertor legs by this length [m]", + value_type=float, + check_all=is_positive, + ), + leg_extend_lower_inner=WithMeta( + "leg_extend", + doc="Extend lower inner divertor leg", + value_type=float, + check_all=is_positive, + ), + leg_extend_lower_outer=WithMeta( + "leg_extend", + doc="Extend lower outer divertor leg", + value_type=float, + check_all=is_positive, + ), + leg_extend_upper_inner=WithMeta( + "leg_extend", + doc="Extend upper inner divertor leg", + value_type=float, + check_all=is_positive, + ), + leg_extend_upper_outer=WithMeta( + "leg_extend", + doc="Extend upper outer divertor leg", + value_type=float, + check_all=is_positive, + ), nx_core=WithMeta( 5, doc="Number of radial points in the core", @@ -616,6 +646,20 @@ def findLegs(self, xpoint, radius=0.01, step=0.01): # The sign is used to tell which way to integrate sign = np.sign((leg[0] - xpoint.R) * Br + (leg[1] - xpoint.Z) * Bz) + # Get the length that the leg should be extended by + if leg[1] > xpoint.Z: + # Upper + if leg[0] > xpoint.R: + leg_extend = self.user_options.leg_extend_upper_outer + else: + leg_extend = self.user_options.leg_extend_upper_inner + else: + # Lower + if leg[0] > xpoint.R: + leg_extend = self.user_options.leg_extend_lower_outer + else: + leg_extend = self.user_options.leg_extend_lower_inner + # Integrate in this direction until the wall is intersected # This is affected by sign, which determines which way to integrate def dpos_dl(distance, pos): @@ -644,6 +688,20 @@ def dpos_dl(distance, pos): intersect = self.wallIntersection(Point2D(*pos), Point2D(*newpos)) if intersect is not None: line.append(intersect) # Put the intersection in the line + if leg_extend > 0.0: + nsteps = int(leg_extend / step + 0.5) + extend_step = leg_extend / nsteps + pos = (intersect.R, intersect.Z) + for i in range(nsteps): + solve_result = solve_ivp( + dpos_dl, + (0.0, extend_step), + pos, + rtol=0.0, + atol=self.user_options.leg_trace_atol, + ) + pos = (solve_result.y[0][1], solve_result.y[1][1]) + line.append(Point2D(*pos)) break pos = newpos line.append(Point2D(*pos)) From b28e2f44e493b7225a982dd171306ff7016741bc Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Tue, 17 Jun 2025 13:13:51 -0700 Subject: [PATCH 2/3] leg_extend: change check to is_non_negative --- hypnotoad/cases/tokamak.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hypnotoad/cases/tokamak.py b/hypnotoad/cases/tokamak.py index 217359fa..86c52bf0 100644 --- a/hypnotoad/cases/tokamak.py +++ b/hypnotoad/cases/tokamak.py @@ -82,31 +82,31 @@ class TokamakEquilibrium(Equilibrium): 0.0, doc="Extend divertor legs by this length [m]", value_type=float, - check_all=is_positive, + check_all=is_non_negative, ), leg_extend_lower_inner=WithMeta( "leg_extend", doc="Extend lower inner divertor leg", value_type=float, - check_all=is_positive, + check_all=is_non_negative, ), leg_extend_lower_outer=WithMeta( "leg_extend", doc="Extend lower outer divertor leg", value_type=float, - check_all=is_positive, + check_all=is_non_negative, ), leg_extend_upper_inner=WithMeta( "leg_extend", doc="Extend upper inner divertor leg", value_type=float, - check_all=is_positive, + check_all=is_non_negative, ), leg_extend_upper_outer=WithMeta( "leg_extend", doc="Extend upper outer divertor leg", value_type=float, - check_all=is_positive, + check_all=is_non_negative, ), nx_core=WithMeta( 5, From b707fc76ba17677b75b0a9b1fd4776a99764a8f4 Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Wed, 18 Jun 2025 10:39:56 -0700 Subject: [PATCH 3/3] leg_extend: Add summary to whats-new.md --- doc/whats-new.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats-new.md b/doc/whats-new.md index b2e376a4..593b91a2 100644 --- a/doc/whats-new.md +++ b/doc/whats-new.md @@ -25,6 +25,9 @@ Release history - Wall coordinates are written to output grid as `closed_wall_R` and `closed_wall_Z` (#176) By [Ben Dudson](https://github.com/bendudson) +- Extend divertor legs with `leg_extend` options. These specify how far each + leg should extend beyond the wall intersection (#195). + By [Ben Dudson](https://github.com/bendudson) 0.5.2 (13th March 2023) -------------------------