diff --git a/hypnotoad/cases/tokamak.py b/hypnotoad/cases/tokamak.py index e573bdee..c595e7e4 100644 --- a/hypnotoad/cases/tokamak.py +++ b/hypnotoad/cases/tokamak.py @@ -782,9 +782,6 @@ def inside_wall(point: Point2D): ) # 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 @@ -795,8 +792,13 @@ def inside_wall(point: Point2D): self.regions = self.createRegionObjects(all_regions, segments) # Make the connections between regions - for connection in connections: - self.makeConnection(*connection) + if self.user_options.single_region != None: + print("making connections for single_region") + for connection in connections: + self.makeSingleRegionConnection(*connection) + else: + for connection in connections: + self.makeConnection(*connection) def describeSingleNull(self): """ diff --git a/hypnotoad/core/equilibrium.py b/hypnotoad/core/equilibrium.py index d4b75f04..376f2f35 100644 --- a/hypnotoad/core/equilibrium.py +++ b/hypnotoad/core/equilibrium.py @@ -3910,6 +3910,31 @@ def makeConnection(self, lowerRegion, lowerSegment, upperRegion, upperSegment): lRegion.connections[lowerSegment]["upper"] = (upperRegion, upperSegment) uRegion.connections[upperSegment]["lower"] = (lowerRegion, lowerSegment) + def makeSingleRegionConnection(self, lowerRegion, lowerSegment, upperRegion, upperSegment): + """ + Make fake connections for a `single_region` grid, if an edge of the region + should be connected in a full grid. + """ + # Needs to be OrderedDict so that Mesh can iterate through it in consistent order + if not isinstance(self.regions, OrderedDict): + raise ValueError("self.regions should be OrderedDict") + + print("makeSingleRegionConnection ", lowerRegion, lowerSegment, upperRegion, upperSegment) + single_region_name = [*self.regions.keys()][0] + single_region = self.regions[single_region_name] + if lowerRegion == single_region_name: + if single_region.connections[lowerSegment]["upper"] is not None: + raise ValueError( + "single_region.connections['upper'] should not have been set already" + ) + single_region.connections[lowerSegment]["upper"] = ("fake", upperSegment) + elif upperRegion == single_region_name: + if single_region.connections[upperSegment]["lower"] is not None: + raise ValueError( + "single_region.connections['lower'] should not have been set already" + ) + single_region.connections[upperSegment]["lower"] = ("fake", lowerSegment) + def handleMultiLocationArray(getResult): @functools.wraps(getResult) # Define a function which handles MultiLocationArray arguments diff --git a/hypnotoad/core/mesh.py b/hypnotoad/core/mesh.py index 3ae87469..8be29f13 100644 --- a/hypnotoad/core/mesh.py +++ b/hypnotoad/core/mesh.py @@ -1383,7 +1383,7 @@ def calcHy(self): ) hy.centre[i, :] = d[2::2] - d[:-2:2] hy.ylow[i, 1:-1] = d[3:-1:2] - d[1:-3:2] - if self.connections["lower"] is not None: + if self.connections["lower"] not in (None, "fake"): cbelow = self.getNeighbour("lower").contours[2 * i + 1] dbelow = cbelow.get_distance(psi=self.equilibriumRegion.psi) hy.ylow[i, 0] = d[1] - d[0] + dbelow[-1] - dbelow[-2] @@ -1391,7 +1391,7 @@ def calcHy(self): # no region below, so estimate distance to point before '0' as the same # as from '0' to '1' hy.ylow[i, 0] = 2.0 * (d[1] - d[0]) - if self.connections["upper"] is not None: + if self.connections["upper"] not in (None, "fake"): cabove = self.getNeighbour("upper").contours[2 * i + 1] dabove = cabove.get_distance(psi=self.equilibriumRegion.psi) hy.ylow[i, -1] = d[-1] - d[-2] + dabove[1] - dabove[0] @@ -1411,7 +1411,7 @@ def calcHy(self): ) hy.xlow[i, :] = d[2::2] - d[:-2:2] hy.corners[i, 1:-1] = d[3:-1:2] - d[1:-3:2] - if self.connections["lower"] is not None: + if self.connections["lower"] not in (None, "fake"): cbelow = self.getNeighbour("lower").contours[2 * i] dbelow = cbelow.get_distance(psi=self.equilibriumRegion.psi) hy.corners[i, 0] = d[1] - d[0] + dbelow[-1] - dbelow[-2] @@ -1419,7 +1419,7 @@ def calcHy(self): # no region below, so estimate distance to point before '0' as the same # as from '0' to '1' hy.corners[i, 0] = 2.0 * (d[1] - d[0]) - if self.connections["upper"] is not None: + if self.connections["upper"] not in (None, "fake"): cabove = self.getNeighbour("upper").contours[2 * i] dabove = cabove.get_distance(psi=self.equilibriumRegion.psi) hy.corners[i, -1] = d[-1] - d[-2] + dabove[1] - dabove[0] @@ -2456,7 +2456,7 @@ def _find_intersection( if upper_wall: if lower_wall: - starti = len(contour // 2) + starti = len(contour) // 2 else: starti = 0 @@ -2692,7 +2692,9 @@ def __init__(self, equilibrium, settings): region = equilibrium.regions[eq_reg] c = region.connections[i] for key, val in c.items(): - if val is not None: + if val is not None and val[0] == "fake": + self.connections[region_id][key] = "fake" + elif val is not None: self.connections[region_id][key] = self.region_lookup[val] else: self.connections[region_id][key] = None