Skip to content

Commit

Permalink
refactor exceptions to be contained within class - makes it easier fo…
Browse files Browse the repository at this point in the history
…r end users to catch it
  • Loading branch information
peterdsharpe committed Feb 26, 2024
1 parent 7ee4447 commit 6e39b27
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions aerosandbox/aerodynamics/aero_2D/xfoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
import os


# Define XFoilError
class XFoilError(Exception):
pass


class XFoil(ExplicitAnalysis):
"""
Expand All @@ -38,6 +33,10 @@ class XFoil(ExplicitAnalysis):
"""

# Defines an exception to throw if XFoil fails externally
class XFoilError(Exception):
pass

def __init__(self,
airfoil: Airfoil,
Re: float = 0.,
Expand Down Expand Up @@ -314,18 +313,18 @@ def _run_xfoil(self,
)
except subprocess.CalledProcessError as e:
if e.returncode == 11:
raise RuntimeError(
raise self.XFoilError(
"XFoil segmentation-faulted. This is likely because your input airfoil has too many points.\n"
"Try repaneling your airfoil with `Airfoil.repanel()` before passing it into XFoil.\n"
"For further debugging, turn on the `verbose` flag when creating this AeroSandbox XFoil instance.")
elif e.returncode == 8 or e.returncode == 136:
raise RuntimeError(
raise self.XFoilError(
"XFoil returned a floating point exception. This is probably because you are trying to start\n"
"your analysis at an operating point where the viscous boundary layer can't be initialized based\n"
"on the computed inviscid flow. (You're probably hitting a Goldstein singularity.) Try starting\n"
"your XFoil run at a less-aggressive (alpha closer to 0, higher Re) operating point.")
elif e.returncode == 1:
raise RuntimeError(
raise self.XFoilError(
f"Command '{command}' returned non-zero exit status 1.\n"
f"This is likely because AeroSandbox does not see XFoil on PATH with the given command.\n"
f"Check the logs (`asb.XFoil(..., verbose=True)`) to verify that this is the case, and if so,\n"
Expand All @@ -339,7 +338,7 @@ def _run_xfoil(self,
with open(directory / output_filename) as f:
lines = f.readlines()
except FileNotFoundError:
raise FileNotFoundError(
raise self.XFoilError(
"It appears XFoil didn't produce an output file, probably because it crashed.\n"
"To troubleshoot, try some combination of the following:\n"
"\t - In the XFoil constructor, verify that either XFoil is on PATH or that the `xfoil_command` parameter is set.\n"
Expand Down Expand Up @@ -367,7 +366,7 @@ def _run_xfoil(self,
data_lines = lines[i + 1:]

except IndexError:
raise XFoilError(
raise self.XFoilError(
"XFoil output file is malformed; it doesn't have the expected number of lines.\n"
"For debugging, the raw output file from XFoil is printed below:\n"
+ "\n".join(lines)
Expand Down Expand Up @@ -415,7 +414,7 @@ def str_to_float(s: str) -> float:
]

if not len(data) == len(columns):
raise XFoilError(
raise self.XFoilError(
"XFoil output file is malformed; the header and data have different numbers of columns.\n"
"In previous testing, this occurs due to a bug in XFoil itself, with certain input combos.\n"
"For debugging, the raw output file from XFoil is printed below:\n"
Expand Down

0 comments on commit 6e39b27

Please sign in to comment.