Skip to content

Commit

Permalink
Add option to build grid for only a single region
Browse files Browse the repository at this point in the history
  • Loading branch information
johnomotani committed Nov 7, 2024
1 parent 7c6d49a commit 23c7db8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
32 changes: 27 additions & 5 deletions hypnotoad/cases/tokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ class TokamakEquilibrium(Equilibrium):
doc="Reverse the sign of toroidal magnetic field Bt.",
value_type=bool,
),
single_region=WithMeta(
None,
doc="Select only a single region of the equilibrium to mesh. Currently "
"this must be a divertor leg region.",
value_type=[NoneType, str],
),
start_at_upper_outer=WithMeta(
False,
doc=(
Expand Down Expand Up @@ -767,10 +773,23 @@ def inside_wall(point: Point2D):
# Specifications for a double null (connected or disconnected)
leg_regions, core_regions, segments, connections = self.describeDoubleNull()

# Create a new dictionary, which will contain all regions
# including core and legs
all_regions = leg_regions.copy()
all_regions.update(self.coreRegionToRegion(core_regions))
if self.user_options.single_region != None:
this_region_name = self.user_options.single_region
if this_region_name not in leg_regions:
raise ValueError(
f"single_region option only supports leg regions so far. Region "
f"{this_region_name} not found in leg_regions {leg_regions.keys()}."
)
# Select just the single region `this_region_name`
all_regions = {this_region_name: leg_regions[this_region_name]}

# Delete any connections, because we only have a single region
connections = []
else:
# Create a new dictionary, which will contain all regions
# including core and legs
all_regions = leg_regions.copy()
all_regions.update(self.coreRegionToRegion(core_regions))

# Create the regions in an OrderedDict, assign to self.regions
self.regions = self.createRegionObjects(all_regions, segments)
Expand Down Expand Up @@ -1635,7 +1654,10 @@ def createRegionObjects(self, all_regions, segments):
# The region objects need to be sorted, so that the
# BoutMesh generator can use jyseps indices to introduce branch cuts

if "inner_lower_divertor" in region_objects:
if self.user_options.single_region != None:
# Only a single region present
ordering = [self.user_options.single_region]
elif "inner_lower_divertor" in region_objects:
if not self.user_options.start_at_upper_outer:
ordering = [
"inner_lower_divertor",
Expand Down
24 changes: 20 additions & 4 deletions hypnotoad/core/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,11 @@ def geometry2(self):
self.dphidy = self.hy * self.Btxy / (self.Bpxy * self.Rxy)

def capBpYlowXpoint(self):
if self.equilibriumRegion.xPointsAtStart[self.radialIndex] is not None:
if (
self.equilibriumRegion.xPointsAtStart[self.radialIndex] is not None
and self.equilibriumRegion.connections[self.radialIndex]["lower"]
is not None
):
# Choose a minumum Bp as the average of the two values of Bpxy.centre
# nearest to the X-point
Bp_min = min(
Expand All @@ -941,7 +945,11 @@ def capBpYlowXpoint(self):
self.Bpxy.ylow[i, 0] = Bp_min
else:
break
if self.equilibriumRegion.xPointsAtStart[self.radialIndex + 1] is not None:
if (
self.equilibriumRegion.xPointsAtStart[self.radialIndex + 1] is not None
and self.equilibriumRegion.connections[self.radialIndex + 1]["lower"]
is not None
):
# Choose a minumum Bp as the average of the two values of Bpxy.centre
# nearest to the X-point
Bp_min = min(
Expand All @@ -952,7 +960,11 @@ def capBpYlowXpoint(self):
self.Bpxy.ylow[-i - 1, 0] = Bp_min
else:
break
if self.equilibriumRegion.xPointsAtEnd[self.radialIndex] is not None:
if (
self.equilibriumRegion.xPointsAtEnd[self.radialIndex] is not None
and self.equilibriumRegion.connections[self.radialIndex]["upper"]
is not None
):
# Choose a minumum Bp as the average of the two values of Bpxy.centre
# nearest to the X-point
Bp_min = min(
Expand All @@ -963,7 +975,11 @@ def capBpYlowXpoint(self):
self.Bpxy.ylow[i, -1] = Bp_min
else:
break
if self.equilibriumRegion.xPointsAtEnd[self.radialIndex + 1] is not None:
if (
self.equilibriumRegion.xPointsAtEnd[self.radialIndex + 1] is not None
and self.equilibriumRegion.connections[self.radialIndex + 1]["upper"]
is not None
):
# Choose a minumum Bp as the average of the two values of Bpxy.centre
# nearest to the X-point
Bp_min = min(
Expand Down

0 comments on commit 23c7db8

Please sign in to comment.