Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch errors in HypnotoadGui.run() #24

Merged
merged 7 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
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
17 changes: 16 additions & 1 deletion hypnotoad/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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 @@ -323,8 +324,22 @@ 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):
self.statusbar.showMessage(
"Error in grid generation, change settings and run again!"
)
johnomotani marked this conversation as resolved.
Show resolved Hide resolved
self.statusbar.setStyleSheet(
f"QLineEdit {{ background-color: {COLOURS['red']} }}"
)
return

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

Expand Down