Skip to content
Open
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
873 changes: 873 additions & 0 deletions INGRID/gridue_to_bout.py

Large diffs are not rendered by default.

57 changes: 53 additions & 4 deletions INGRID/ingrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
from INGRID.topologies.sf135 import SF135
from INGRID.topologies.sf165 import SF165
from INGRID.topologies.udn import UDN
from INGRID.topologies.cdn import CDN
from INGRID.geometry import Point, Line

from INGRID.gridue_to_bout import Convert_grids

def QuickStart() -> None:
"""
Expand Down Expand Up @@ -1237,6 +1239,9 @@ def SetTopology(self, topology: str) -> None:

elif topology == 'UDN':
ingrid_topology = UDN(self, topology)

elif topology == 'CDN':
ingrid_topology = CDN(self, topology)

elif topology == 'SF15':
ingrid_topology = SF15(self, topology)
Expand Down Expand Up @@ -1452,6 +1457,31 @@ def CreateSubgrid(self, NewFig: bool = True, ShowVertices: bool = False) -> None
"""
self.ConstructGrid(NewFig, ShowVertices)

def ExportBOUTgrid(self, gridue_file, bout_grid_name: str = 'bout_from_in.grd.nc', plotting = True, verbose = True, ignore_checks = False):
"""
Export a BOUT grid file for the created grid.

Parameters
----------
gridue_file : str, mandatory
Name of gridue file to convert to BOUT grid.

bout_grid_name : str, optional
Name of BOUT grid file to save.

plotting : bool, optional
If True, plot the gridue file before conversion.

verbose : bool, optional
If True, print verbose output during conversion.

ignore_checks : bool, optional
If True, ignore checks for gridue file format and structure.

"""
bout_grid_name = gridue_file + "_" + bout_grid_name
Convert_grids(gridue_file,bout_grid_name,plotting, verbose, ignore_checks)

def ExportGridue(self, fname: str = 'gridue', guard_cell_eps=1e-3) -> None:
"""
Export a gridue file for the created grid.
Expand All @@ -1467,9 +1497,12 @@ def ExportGridue(self, fname: str = 'gridue', guard_cell_eps=1e-3) -> None:
if type(self.CurrentTopology) in [SNL]:
if self.WriteGridueSNL(self.CurrentTopology.gridue_settings, fname):
print(f"# Successfully saved gridue file as '{fname}'")
elif type(self.CurrentTopology) in [SF15, SF45, SF75, SF105, SF135, SF165, UDN]:
self.ExportBOUTgrid(fname, 'bout_from_in.grd.nc', plotting = True, verbose = True, ignore_checks = False)
elif type(self.CurrentTopology) in [SF15, SF45, SF75, SF105, SF135, SF165, UDN, CDN]:
if self.WriteGridueDNL(self.CurrentTopology.gridue_settings, fname):
print(f"# Successfully saved gridue file as '{fname}'")
self.ExportBOUTgrid(fname, 'bout_from_in.grd.nc', plotting = True, verbose = True, ignore_checks = False)


@staticmethod
def ImportGridue(fname: str = 'gridue') -> dict:
Expand All @@ -1489,9 +1522,25 @@ def ImportGridue(fname: str = 'gridue') -> dict:
try:
f = open(fname, mode='r')
Values = [int(x) for x in next(f).split()]
HeaderItems = ['nxm', 'nym', 'ixpt1', 'ixpt2', 'iyseptrx1']
gridue_settings = dict(zip(HeaderItems, Values))
next(f)

# Very crude method of checking what format the gridue is in
if len(Values) > 2:
HeaderItems = ['nxm', 'nym', 'ixpt1', 'ixpt2', 'iyseptrx1']
gridue_settings = dict(zip(HeaderItems, Values))
next(f)
else:
gridue_settings = {}
header_rows = [
['nxm', 'nym'],
['iyseparatrix1', 'iyseparatrix2'],
['ix_plate1', 'ix_cut1', '_FILLER_', 'ix_cut2', 'ix_plate2'],
['iyseparatrix3', 'iyseparatrix4'],
['ix_plate3', 'ix_cut3', '_FILLER_', 'ix_cut4', 'ix_plate4']
]
for row in header_rows:
gridue_settings = {**gridue_settings, **dict(zip(row, Values))}
Values = [int(x) for x in next(f).split()]

BodyItems = ['rm', 'zm', 'psi', 'br', 'bz', 'bpol', 'bphi', 'b']
Str = {i: [] for i in BodyItems}
k = iter(Str.keys())
Expand Down
6 changes: 3 additions & 3 deletions INGRID/interpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ def PlotLevel(self: object, level: float = 1.0, color: str = 'red', label: str =
np.linspace(self.zmin, self.zmax, data.shape[1]),
indexing='ij')
try:
self.psi_levels[label].collections[0].remove()
self.psi_levels[label].remove()
self.psi_levels[label] = plt.contour(rgrid, zgrid, data, [float(level)], colors=color, label=label, linestyles=linestyles)
self.psi_levels[label].collections[0].set_label(label)
self.psi_levels[label].set_label(label)
except:
self.psi_levels[label] = plt.contour(rgrid, zgrid, data, [float(level)], colors=color, label=label, linestyles=linestyles)
self.psi_levels[label].collections[0].set_label(label)
self.psi_levels[label].set_label(label)

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):
Expand Down
11 changes: 7 additions & 4 deletions INGRID/line_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,13 @@ def limiter_split(start, end, limiter):
self.config = 'SF15'
elif self.line_group_intersect == xptNW_midLine.points():
self.config = 'SF165'
elif self.line_group_intersect == midline_topline_west.points():
self.config = 'UDN'
elif self.line_group_intersect == midline_topline_east.points():
self.config = 'UDN'
elif (self.line_group_intersect == midline_topline_west.points()
or self.line_group_intersect == midline_topline_east.points()
):
if np.isclose(abs(xpt1["center"][1]), abs(xpt2["center"][1])):
self.config = 'CDN'
else:
self.config = 'UDN'
break

elif region == 'PF':
Expand Down
Loading