peterdsharpe / AeroSandbox

Aircraft design optimization made fast through modern automatic differentiation. Composable analysis tools for aerodynamics, propulsion, structures, trajectory design, and much more.
https://peterdsharpe.github.io/AeroSandbox/
MIT License
687 stars 111 forks source link

airfoil.generate_polars can't work well in Ubuntu #94

Closed Zcaic closed 11 months ago

Zcaic commented 1 year ago

1.airfoil.generate_polars work well in Windows, but it can't work in Ubuntu22.04. I found it caused by Xfoil .

  1. I also found there is a bug "def _run_xfoil()" in Xfoil.py ( lines 264) , In linux , it does not support "try: command = f'{self.xfoil_command} {airfoil_file}' proc = subprocess.Popen( command, ................ "

I change line 264 to "command = [f'{self.xfoil_command}',f'{airfoil_file}']" , it can call Xfoil, but unfortunately, Xfoil can not work as expected.

peterdsharpe commented 1 year ago

Hey @Zcaic ,

Thank you for posting about this issue!

When you say

I change line 264 to "command = [f'{self.xfoil_command}',f'{airfoil_file}']" , it can call Xfoil, but unfortunately, Xfoil can not work as expected.

Can you describe:

a) Expected behavior b) Observed behavior

Similarly, when you say that the original command "does not support" on Linux, can you also describe the same expected and observed behavior here?

This will help us reproduce, understand, and fix the issue here. Thanks!

Zcaic commented 1 year ago

Hello @peterdsharpe, I'm glad you got back to me

I test aerosandbox/aerodynamics/aero_2D/xfoil.py in Ubuntu 22.04, I add "print (result_at_single_alpha)" at end. xfoil.py.txt

  1. a) Expected behavior: get correct result. b) Observed behavior: it raise :"FileNotFoundError: [Errno 2] No such file or directory: 'xfoil airfoil.dat'". then I found the reason of this error, I change line 272 "command = f'{self.xfoil_command} {airfoil_file}'" to "command = [self.xfoil_command,airfoil_file]",

  2. it does not raise error , but I sitll dont get correct result. b) Observed behavior: "{'alpha': array([], dtype=float64), 'CL': array([], dtype=float64), 'CD': array([], dtype=float64), 'CDp': array([], dtype=float64), 'CM': array([], dtype=float64), 'Top_Xtr': array([], dtype=float64), 'Bot_Xtr': array([], dtype=float64), 'Top_Itr': array([], dtype=float64), 'Bot_Itr': array([], dtype=float64)}" it can found that "result_at_single_alpha" is empty.

  3. then I Uncomment "verbose=true" in line 536 to see what happen, and it raise: " **Enter polar output filename s> At line 664 of file ../src/iopol.f (unit = 19, file = 'output.txt') Fortran runtime error: Unexpected element '(1X,F7.3 ,F9.4 ,F10.5 ,F10.5 ,F9.4 ,

Error termination. Backtrace:

0 0x7f15f8508a4f in data_transfer_init

    at /usr/src/debug/gcc/gcc/libgfortran/io/transfer.c:3161

1 0x55c188ea1e61 in ???

2 0x55c188e38582 in ???

3 0x55c188e24acb in ???

4 0x55c188e1c39e in ???

5 0x7f15f7eaf84f in ???

6 0x7f15f7eaf909 in ???

7 0x55c188e1c3c4 in ???

8 0xffffffffffffffff in ???**

" But it can work and print correct result in Windows, because I'm not familiar with xfoil, I guess the there is a problem with the parameter passed to xfoil in Linux。

Could you see what's wrong ,thanks!

Zcaic commented 1 year ago

It has same problem in Arch Linux, So I think it is not a problem caused by Ubuntu.

max-97 commented 12 months ago

I had an issue in Ubuntu WSL on Windows 10 and in a docker image with Debian as well. Xfoil crashed with SIGFPE: floating-point exception - erroneous arithmetic operation. The issue seems to be that the Xfoil package wasn't compiled properly under Linux.

Bug report on the Xfoil Ubuntu package: https://bugs.launchpad.net/ubuntu/+source/xfoil/+bug/1885919

(Most likely) cause of the problem: https://groups.google.com/g/comp.lang.fortran/c/xnSwYtQH6_E?pli=1 TL;DR: It was probably compiled with "-ffpe-trap=inexact".

"For any (non-trivial) code, which is doing floating point arithmetic, the code will raise FE_INEXACT."

At least that was the issue for me. So I compiled Xfoil from source:

apt-get install -y build-essential gfortran libx11-dev cmake
git clone https://github.com/RobotLocomotion/xfoil.git
cd xfoil && mkdir build && cd build
cmake .. && make install

I changed some default keystrokes as well. pwrt to safe the output doesn't work reliably, at least in my case. You can just use pacc to write into a file as well.

# xfoil.py
def _default_keystrokes(self) -> List[str]:
    ...
     # Set polar accumulation
     run_file_contents += [
         "pacc",
         f"{self.output_filename}",   
         "",
     ]
    ...
    return run_file_contents

def _run_xfoil(self, run_command: List[str],) -> Dict[str, np.ndarray]:
    ...
     # Handle the keystroke file
     keystrokes = self._default_keystrokes()
     keystrokes += run_command
     keystrokes += [
         "pacc",   # end accumulation
          "",
          "quit"
     ]

Because I'm using WSL and Docker I had to change the command for Xfoil to

command = f"xvfb-run {self.xfoil_command} {airfoil_file}"

and add a sleep. Otherwise xvfb wouldn't start sometimes

outs, errs = proc.communicate(input="\n".join(keystrokes), timeout=self.timeout)

time.sleep(0.1)

Hope that helps.

Zcaic commented 12 months ago

Thank you for your reply, I will try your proposal.

Zcaic commented 11 months ago

@max-97 thanks very much. I change code about "pwrt" and "pacc" as you said, it works as expect. Thanks a lot!

peterdsharpe commented 11 months ago

Glad to hear it @Zcaic ! Thanks for the tip here, @max-97 .

New versions of AeroSandbox will have the option of using our new NeuralFoil package to generate airfoil polar functions instead of XFoil - since NeuralFoil is pure Python + NumPy, this should eliminate the need to have a local XFoil copy for most users. This will make cross-platform use vastly easier.

A preview is available in the AeroSandbox feature/neuralfoil-merge branch, but should go live on master + develop soon.

peterdsharpe commented 11 months ago

@max-97 @Zcaic , the fix proposed by @max-97 has been worked into the feature/neuralfoil-merge WIP branch, and will be incorporated into the next AeroSandbox release (probably later this week). This fix has been verified to maintain compatibility on Windows as well.

https://github.com/peterdsharpe/AeroSandbox/commit/932f82db134b92e26462c6384f88ae87caffe144

Nice work!

Zcaic commented 11 months ago

I'm glad to hear the good news

Zcaic commented 11 months ago

@peterdsharpe When I learn DAWNDESIGNTOOL, I found the description of the function lib_winds.tropopause_altitude to be problematic. Code show as below: 微信截图_20230718020629 It seems that the comment inside the red box should be changed to

"latitude"   : latitude, in degree
peterdsharpe commented 11 months ago

Good catch, thanks! Fix committed, incoming here:

https://github.com/peterdsharpe/AeroSandbox/commit/d132cf40442ebaa34968b74d58bad37fa5544d0c

max-97 commented 11 months ago

Glad I could help. The neuralfoil feature looks great!