Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions INGRID/gui/ingrid_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ def CreatePatches(self):
self.AnalyzeTopology()
self.controller.IngridSession.ConstructPatches()

self.controller.IngridSession.ApplyUpDownSymmetry()

self.controller.IngridSession.PlotPatches()

def CreateSubgrid(self):
Expand Down
57 changes: 47 additions & 10 deletions INGRID/ingrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,9 @@ def PlotPsiUNorm(self) -> None:
plt.draw()
except:
pass
self.PsiUNorm.plot_data(self.settings['grid_settings']['nlevs'])
self.PsiUNorm.plot_data(self.settings['grid_settings']['nlevs'],
up_down_symmetry=self.settings["grid_settings"]["up_down_symmetry"],
zmagx=self.magx[1] + self.settings["grid_settings"]["patch_generation"]["zmagx_shift"])

def PlotPsiNorm(self, view_mode: str = 'filled') -> None:
"""
Expand All @@ -813,7 +815,12 @@ def PlotPsiNorm(self, view_mode: str = 'filled') -> None:
except:
pass

self.PsiNorm.plot_data(nlevs=self.settings['grid_settings']['nlevs'], fig=self._PsiNormFig, ax=self.PsiNormAx, view_mode=view_mode)
self.PsiNorm.plot_data(nlevs=self.settings['grid_settings']['nlevs'],
fig=self._PsiNormFig,
ax=self.PsiNormAx,
view_mode=view_mode,
up_down_symmetry=self.settings["grid_settings"]["up_down_symmetry"],
zmagx=self.magx[1] + self.settings["grid_settings"]["patch_generation"]["zmagx_shift"])

def PlotPsiNormBounds(self) -> None:
"""
Expand All @@ -833,27 +840,33 @@ def PlotPsiNormBounds(self) -> None:

nxpt = self.settings['grid_settings']['num_xpt']
if nxpt == 1:
Dic = {'psi_1': 'lime',
self.contour_colour_dic = {'psi_1': 'lime',
'psi_core': 'cyan',
'psi_pf_1': 'white'}
num_psi_levels = 4
elif nxpt == 2:
Dic = {'psi_core': 'cyan',
self.contour_colour_dic = {'psi_core': 'cyan',
'psi_1': 'lime',
'psi_2': 'fuchsia',
'psi_pf_1': 'white',
'psi_pf_2': 'yellow'}
num_psi_levels = 7

for k, c in Dic.items():
self.PsiNorm.PlotLevel(self.settings['grid_settings'][k], color=Dic[k], label=k)
for k, c in self.contour_colour_dic.items():
self.PsiNorm.PlotLevel(self.settings['grid_settings'][k], color=self.contour_colour_dic[k], label=k)

self.PsiNorm.PlotLevel(1.0, color='red', label='Primary Separatrix')
if nxpt == 2:
self.PsiNorm.PlotLevel(
self.PsiNorm.get_psi(self.xpt2[0], self.xpt2[1]), color='blue', label='Secondary Separatrix')

handles, labels = self.PsiNorm.ax.get_legend_handles_labels()
contour_count = 0
contour_colours = list(self.contour_colour_dic.values()) + ["red", "blue"]
for i in range(len(handles)):
if isinstance(handles[i], matplotlib.collections.PathCollection):
handles[i] = matplotlib.lines.Line2D([0],[0],color=contour_colours[contour_count])
contour_count+=1
lookup = {label: handle for label, handle in zip(labels, handles)}
try:
self.PsiNorm.fig.legends[0].remove()
Expand All @@ -875,7 +888,7 @@ def PlotPsiNormMagReference(self, ax: object = None) -> None:
x += self.settings['grid_settings']['patch_generation']['rmagx_shift']
y += self.settings['grid_settings']['patch_generation']['zmagx_shift']
self.RemovePlotPoint(label='magx', ax=ax)
ax.plot(x, y, '+', color='yellow', ms=15, linewidth=5, label='magx')
ax.plot(x, y, '+', color='yellow', ms=15, linewidth=5, label='magx', zorder=9999)

(x, y) = self.xpt1
self.RemovePlotPoint(label='xpt1', ax=ax)
Expand Down Expand Up @@ -1181,7 +1194,10 @@ def PlotPatches(self) -> None:
pass
self._PatchFig = plt.figure('INGRID: ' + self.CurrentTopology.config + ' Patches', figsize=(6, 10))
self.PatchAx = self._PatchFig.add_subplot(111)
self.CurrentTopology.patch_diagram(fig=self._PatchFig, ax=self.PatchAx)
self.CurrentTopology.patch_diagram(fig=self._PatchFig,
ax=self.PatchAx,
up_down_symmetry=self.settings["grid_settings"]["up_down_symmetry"],
zmagx=self.magx[1] + self.settings["grid_settings"]["patch_generation"]["zmagx_shift"])
self.PlotStrikeGeometry(ax=self.PatchAx)
if self.settings['grid_settings']['patch_generation']['strike_pt_loc'] == 'target_plates':
self.RemovePlotLine(label='limiter', ax=self.PatchAx)
Expand All @@ -1196,7 +1212,10 @@ def PlotGrid(self) -> None:
pass
self._SubgridFig = plt.figure('INGRID: ' + self.CurrentTopology.config + ' Grid', figsize=(6, 10))
self._SubgridAx = self._SubgridFig.add_subplot(111)
self.CurrentTopology.grid_diagram(fig=self._SubgridFig, ax=self._SubgridAx)
self.CurrentTopology.grid_diagram(fig=self._SubgridFig,
ax=self._SubgridAx,
up_down_symmetry=self.settings["grid_settings"]["up_down_symmetry"],
zmagx=self.magx[1] + self.settings["grid_settings"]["patch_generation"]["zmagx_shift"])

def PlotSubgrid(self) -> None:
"""
Expand Down Expand Up @@ -1365,7 +1384,7 @@ def StartSetup(self, **kwargs) -> None:
+ 'Must be <= 2).'
raise ValueError(v_error_str)

self.LoadGEQDSK(self.settings['eqdsk'])
self.LoadGEQDSK(self.settings['eqdsk'], self.settings["grid_settings"]["up_down_symmetry"])
self.AutoRefineMagAxis()
self.AutoRefineXPoint()
if topology == 'DNL':
Expand Down Expand Up @@ -1501,6 +1520,24 @@ def LoadPatches(self, fname: str = '') -> None:
self.CurrentTopology.SetupPatchMatrix()
self.CheckPatches()

def ApplyUpDownSymmetry(self) -> None:
if self.settings["grid_settings"]["up_down_symmetry"]:
if self.CurrentTopology.config == "LSN":
del self.CurrentTopology.patches["C1"]
del self.CurrentTopology.patches["C2"]
del self.CurrentTopology.patches["D1"]
del self.CurrentTopology.patches["D2"]
elif self.CurrentTopology.config in ["SF15", "SF75"]:
del self.CurrentTopology.patches["C1"]
del self.CurrentTopology.patches["C2"]
del self.CurrentTopology.patches["C3"]
del self.CurrentTopology.patches["D1"]
del self.CurrentTopology.patches["D2"]
del self.CurrentTopology.patches["D3"]
else:
#TODO: Implement up/down symmetry for other geometries
raise Exception("Up/down symmetry not yet implemented for config " + self.CurrentTopology.config)
Comment on lines +1523 to +1539
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we ever do a proper refactor of ingrid, we can probably have each topology state which patches to delete. Could help keep things tidy and trickle in future changes


@_timer
def ConstructGrid(self, NewFig: bool = True, ShowVertices: bool = False) -> None:
"""
Expand Down
11 changes: 10 additions & 1 deletion INGRID/interpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from scipy.ndimage import zoom
from scipy.interpolate import RectBivariateSpline as rbs

Expand Down Expand Up @@ -240,7 +241,7 @@ def PlotLevel(self: object, level: float = 1.0, color: str = 'red', label: str =
plt.plot([],[], label=label, color=color)

def plot_data(self: object, nlevs: int = 30, interactive: bool = True, fig: object = None,
ax: object = None, view_mode: str = 'filled', refined: bool = True, refine_factor: int = 10):
ax: object = None, view_mode: str = 'filled', refined: bool = True, refine_factor: int = 10, up_down_symmetry: bool = False, zmagx: float = 0.0):
"""
Plot the EFIT data.

Expand All @@ -264,6 +265,10 @@ def plot_data(self: object, nlevs: int = 30, interactive: bool = True, fig: obje
Plot level with hi-resolution cubic spline representation
refine_factor: int, optional
Refinement factor for to be passed to SciPy zoom method
up_down_symmetry: bool, optional (defaults to False)
Up/down symmetry switch
zmagx: float, optional (defaults to 0.0)
Z position of magnetic axis (used in setting y-axis limits for the plot)
"""

lev = self.v.min() + (self.v.max() - self.v.min()) * np.arange(nlevs) / (nlevs - 1)
Expand All @@ -289,6 +294,10 @@ def plot_data(self: object, nlevs: int = 30, interactive: bool = True, fig: obje
self.ax.set_ylabel('Z')
self.ax.set_xlim(self.rmin, self.rmax)
self.ax.set_ylim(self.zmin, self.zmax)
if up_down_symmetry:
# Hide the upper half of the domain with a patch
self.ax.set_ylim(self.zmin, zmagx + 0.03*(self.zmax-self.zmin))
ax.add_patch(Rectangle((self.rmin,zmagx), self.rmax - self.rmin, self.zmax - zmagx, facecolor="white", zorder=999))
if interactive:
plt.ion()
self.fig.show()
Expand Down
7 changes: 6 additions & 1 deletion INGRID/line_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,12 @@ def save_line(x, y, linecolor=color, marker='.-', markersize=1.5):
if show_plot:
if hasattr(self.grid, 'ax') is False:
self.grid.plot_data()
self.grid.ax.plot(x, y, '.-', linewidth=2, color=color, markersize=1.5)
self.grid.ax.plot(x, y, '-', linewidth=0.5, color=color)
try:
self.cur_plot_point.set_ydata(y)
self.cur_plot_point.set_xdata(x)
except:
self.cur_plot_point, = self.grid.ax.plot(x, y, linestyle=None, marker="*", color="red", zorder=9999)
plt.draw()
plt.pause(np.finfo(float).eps)

Expand Down
77 changes: 53 additions & 24 deletions INGRID/topologies/sf15.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,30 +645,59 @@ def set_gridue(self):
ix_plate1 = 0
ix_cut1 = self.patches['A1'].npol - 1

ix_cut2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E']:
ix_cut2 += self.patches[alpha + '1'].npol - 1

ix_plate2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F']:
ix_plate2 += self.patches[alpha + '3'].npol - 1

ix_plate3 = ix_plate2 + 2

ix_cut3 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G']:
ix_cut3 += self.patches[alpha + '2'].npol - 1
ix_cut3 += 2

ix_cut4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']:
ix_cut4 += self.patches[alpha + '1'].npol - 1
ix_cut4 += 2

ix_plate4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']:
ix_plate4 += self.patches[alpha + '1'].npol - 1
ix_plate4 += 2
if self.settings["grid_settings"]["up_down_symmetry"] is True:
ix_cut2 = 0
for alpha in ['A', 'B', 'E']:
ix_cut2 += self.patches[alpha + '1'].npol - 1
ix_cut2 += 2

ix_plate2 = 0
for alpha in ['A', 'B', 'E', 'F']:
ix_plate2 += self.patches[alpha + '3'].npol - 1
ix_plate2 += 2

ix_plate3 = ix_plate2 + 2

ix_cut3 = 0
for alpha in ['A', 'B', 'E', 'F', 'G']:
ix_cut3 += self.patches[alpha + '2'].npol - 1
ix_cut3 += 4

ix_cut4 = 0
for alpha in ['A', 'B', 'E', 'F', 'G', 'H']:
ix_cut4 += self.patches[alpha + '1'].npol - 1
ix_cut4 += 4

ix_plate4 = 0
for alpha in ['A', 'B', 'E', 'F', 'G', 'H', 'I']:
ix_plate4 += self.patches[alpha + '1'].npol - 1
ix_plate4 += 4

elif self.settings["grid_settings"]["up_down_symmetry"] is False:
ix_cut2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E']:
ix_cut2 += self.patches[alpha + '1'].npol - 1

ix_plate2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F']:
ix_plate2 += self.patches[alpha + '3'].npol - 1

ix_plate3 = ix_plate2 + 2

ix_cut3 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G']:
ix_cut3 += self.patches[alpha + '2'].npol - 1
ix_cut3 += 2

ix_cut4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']:
ix_cut4 += self.patches[alpha + '1'].npol - 1
ix_cut4 += 2

ix_plate4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']:
ix_plate4 += self.patches[alpha + '1'].npol - 1
ix_plate4 += 2

psi = np.zeros((nxm + 2, nym + 2, 5), order='F')
br = np.zeros((nxm + 2, nym + 2, 5), order='F')
Expand Down
75 changes: 52 additions & 23 deletions INGRID/topologies/sf75.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,29 +609,58 @@ def set_gridue(self):
ix_plate1 = 0
ix_cut1 = self.patches['A1'].npol - 1

ix_cut2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E']:
ix_cut2 += self.patches[alpha + '1'].npol - 1

ix_plate2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G']:
ix_plate2 += self.patches[alpha + '3'].npol - 1

ix_plate3 = ix_plate2 + 2

ix_cut3 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F']:
ix_cut3 += self.patches[alpha + '1'].npol - 1

ix_cut4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']:
ix_cut4 += self.patches[alpha + '1'].npol - 1
ix_cut4 += 2

ix_plate4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']:
ix_plate4 += self.patches[alpha + '1'].npol - 1
ix_plate4 += 2
if self.settings["grid_settings"]["up_down_symmetry"] is True:
ix_cut2 = 0
for alpha in ['A', 'B', 'E']:
ix_cut2 += self.patches[alpha + '1'].npol - 1
ix_cut2 += 2

ix_plate2 = 0
for alpha in ['A', 'B', 'E', 'F', 'G']:
ix_plate2 += self.patches[alpha + '3'].npol - 1
ix_plate2 += 2

ix_plate3 = ix_plate2 + 2

ix_cut3 = 0
for alpha in ['A', 'B', 'E', 'F']:
ix_cut3 += self.patches[alpha + '1'].npol - 1
ix_cut3 += 2

ix_cut4 = 0
for alpha in ['A', 'B', 'E', 'F', 'G', 'H']:
ix_cut4 += self.patches[alpha + '1'].npol - 1
ix_cut4 += 4

ix_plate4 = 0
for alpha in ['A', 'B', 'E', 'F', 'G', 'H', 'I']:
ix_plate4 += self.patches[alpha + '1'].npol - 1
ix_plate4 += 4

elif self.settings["grid_settings"]["up_down_symmetry"] is False:
ix_cut2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E']:
ix_cut2 += self.patches[alpha + '1'].npol - 1

ix_plate2 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G']:
ix_plate2 += self.patches[alpha + '3'].npol - 1

ix_plate3 = ix_plate2 + 2

ix_cut3 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F']:
ix_cut3 += self.patches[alpha + '1'].npol - 1

ix_cut4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']:
ix_cut4 += self.patches[alpha + '1'].npol - 1
ix_cut4 += 2

ix_plate4 = 0
for alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']:
ix_plate4 += self.patches[alpha + '1'].npol - 1
ix_plate4 += 2

psi = np.zeros((nxm + 2, nym + 2, 5), order='F')
br = np.zeros((nxm + 2, nym + 2, 5), order='F')
Expand Down
Loading
Loading