Skip to content

Commit

Permalink
Merge pull request #24 from boutproject/allow-rerun
Browse files Browse the repository at this point in the history
Catch errors in HypnotoadGui.run()
  • Loading branch information
ZedThree authored Apr 27, 2020
2 parents a96a324 + e60dac8 commit 9740ff1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
10 changes: 10 additions & 0 deletions doc/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ What's new
==========


0.1.1 (unreleased)
------------------

### New Features

- Catch errors in HypnotoadGui.run(), allows changing settings and pressing Run
button again if there was an error in grid generation (#24)\
By [John Omotani](https://github.com/johnomotani)


0.1.0 (24th April 2020)
-----------------------

Expand Down
15 changes: 11 additions & 4 deletions hypnotoad/cases/tokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class TokamakEquilibrium(Equilibrium):
psi_sol_inner=None, # Default: psinorm_sol_inner
psi_pf_lower=None, # Default: psinorm_pf_lower
psi_pf_upper=None, # Default: psinorm_pf_upper
#
# Tolerance for positioning points that should be at X-point, but need to be
# slightly displaced from the null so code can follow Grad(psi).
# Number between 0. and 1.
xpoint_offset=0.5,
).push(
Options(
# These are HypnotoadOptions
Expand Down Expand Up @@ -236,6 +241,9 @@ class Options (self.user_options)

super().__init__(**kwargs)

# Print the table of options
print(optionsTableString(self.user_options, self.default_options))

if make_regions:
# Create self.regions
self.makeRegions()
Expand Down Expand Up @@ -470,9 +478,6 @@ def psi_to_psinorm(psi):
np.abs((self.user_options.psi_core - self.user_options.psi_sol) / 20.0),
)

# Print the table of options
print(optionsTableString(self.user_options, self.default_options))

# Filter out the X-points not in range.
# Keep only those with normalised psi < psinorm_sol
self.psi_sep, self.x_points = zip(
Expand Down Expand Up @@ -1179,7 +1184,9 @@ def psival(angle):
]

# Add points to the beginning and end near (but not at) the X-points
diff = 0.5
diff = self.user_options.xpoint_offset
if diff < 0.0 or diff > 1.0:
raise ValueError(f"xpoint_offset={diff} should be between 0 and 1.")

region["points"] = (
[(1.0 - diff) * start_x + diff * points[0]]
Expand Down
27 changes: 23 additions & 4 deletions hypnotoad/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
QCompleter,
QTableWidgetItem,
QHeaderView,
QErrorMessage,
)
from Qt.QtCore import Qt

from .hypnotoad_mainWindow import Ui_Hypnotoad
from .matplotlib_widget import MatplotlibWidget
from ..cases import tokamak
from ..core.mesh import BoutMesh
from ..core.equilibrium import SolutionError
from ..__init__ import __version__


Expand Down Expand Up @@ -297,9 +299,15 @@ def read_geqdsk(self):
)
return

with open(geqdsk_filename, "rt") as f:
# Need to take a copy so that read_geqdsk doesn't delete used keys
self.eq = tokamak.read_geqdsk(f, options=copy.deepcopy(self.options))
try:
with open(geqdsk_filename, "rt") as f:
# Need to take a copy so that read_geqdsk doesn't delete used keys
self.eq = tokamak.read_geqdsk(f, options=copy.deepcopy(self.options))
except (ValueError, RuntimeError) as e:
error_message = QErrorMessage()
error_message.showMessage(str(e))
error_message.exec_()
return

self.plot_widget.clear()
self.eq.plotPotential(ncontours=40, axis=self.plot_widget.axes)
Expand All @@ -323,8 +331,19 @@ def run(self):
)
return

# Call read_geqdsk to recreate self.eq object in case any settings needed in
# __init__ have been changed
self.read_geqdsk()

self.statusbar.showMessage("Running...")
self.mesh = BoutMesh(self.eq)
try:
self.mesh = BoutMesh(self.eq)
except (ValueError, SolutionError) as e:
error_message = QErrorMessage()
error_message.showMessage(str(e))
error_message.exec_()
return

self.mesh.calculateRZ()
self.statusbar.showMessage("Done!", 2000)

Expand Down

0 comments on commit 9740ff1

Please sign in to comment.