From d6170fade27b09c0facdb59fb32de63dce01174e Mon Sep 17 00:00:00 2001 From: Peter Sharpe Date: Mon, 4 Mar 2024 01:17:48 -0500 Subject: [PATCH] refactor XFoil to suppress window generation always --- aerosandbox/aerodynamics/aero_2D/xfoil.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/aerosandbox/aerodynamics/aero_2D/xfoil.py b/aerosandbox/aerodynamics/aero_2D/xfoil.py index bdff59a3..b37ca5c9 100644 --- a/aerosandbox/aerodynamics/aero_2D/xfoil.py +++ b/aerosandbox/aerodynamics/aero_2D/xfoil.py @@ -161,6 +161,7 @@ def __repr__(self): return f"XFoil(airfoil={self.airfoil}, Re={self.Re}, mach={self.mach}, n_crit={self.n_crit})" def _default_keystrokes(self, + airfoil_filename: str, output_filename: str, ) -> List[str]: """ @@ -179,6 +180,11 @@ def _default_keystrokes(self, "", ] + # Load the airfoil + run_file_contents += [ + f"load {airfoil_filename}", + ] + if self.xfoil_repanel: run_file_contents += [ "ppar", @@ -278,7 +284,10 @@ def _run_xfoil(self, self.airfoil.write_dat(directory / airfoil_file) # Handle the keystroke file - keystrokes = self._default_keystrokes(output_filename=output_filename) + keystrokes = self._default_keystrokes( + airfoil_filename=airfoil_file, + output_filename=output_filename + ) keystrokes += [run_command] keystrokes += [ "pacc", # End polar accumulation @@ -295,9 +304,8 @@ def _run_xfoil(self, ### Execute try: # command = f'{self.xfoil_command} {airfoil_file}' # Old syntax; try this if calls are not working - command = [self.xfoil_command, airfoil_file] proc = subprocess.Popen( - command, + self.xfoil_command, cwd=directory, stdin=subprocess.PIPE, stdout=None if self.verbose else subprocess.DEVNULL, @@ -337,7 +345,7 @@ def _run_xfoil(self, "your XFoil run at a less-aggressive (alpha closer to 0, higher Re) operating point.") elif e.returncode == 1: raise self.XFoilError( - f"Command '{command}' returned non-zero exit status 1.\n" + f"Command '{self.xfoil_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" f"provide the correct path to the XFoil executable in the asb.XFoil constructor via `xfoil_command=`."