DARcorporation / xfoil-python

Stripped down version of XFOIL as compiled python module
GNU General Public License v3.0
87 stars 60 forks source link

Setting transition position XTR does not work #25

Open morihab opened 1 year ago

morihab commented 1 year ago

Hi there, first of all, it`s really great to have this module. I tried to set the transition position, but got the following error:

`>>> xf.xtr((1.0, 0.95)) Traceback (most recent call last): File "", line 1, in File "/home/moritz/.local/lib/python3.10/site-packages/xfoil/xfoil.py", line 126, in xtr return float(xtr_top), float(xtr_bot) ValueError: could not convert string to float: c_float(1.0)

` I used the included naca0012 airfoil.

Thanks in advance, Moritz

time-trader commented 1 year ago

To start with, the proper way to assign the property is: xf.xtr = (1.0, 0.95)

But you are right that there is problem on the property side of the wrapper (not on the setter).

What is happening:

You are setting xtr as a c_float type using ctypes package, so python float -> c_float, but python seems to have a problem converting c_float back to float. In particular in https://github.com/DARcorporation/xfoil-python/blob/0a8c2fce02ba73b7f89f72306e43d78291d1e024/xfoil/xfoil.py#L126

That line should be changed to: return xtr_top.value, xtr_bot.value This will fix the problem, I will make a pull request for that.

For now you can set xtr like this: xf.xtr = (1.0, 0.95)

Your code will run, and the wrapper will set xtr values for xfoil solver. But if you try to access the xf.xtr property from python code you will still get the error, until next PR.

BTW, check out https://github.com/aerosense-ai/panel-codes-service wrapper to run xfoil as a service (locally or on your own server/cloud). The service takes inputs and configurations as JSON files and produces JSON outputs.

morihab commented 1 year ago

Thank you very much for the reply! Setting the transition position the way you described works. I had the same idea of changing float(xtr_top) to xtr_top.value but after changing it other errors popped up and I was somehow stuck.

aerosense ai looks very promising, will look into it, thanks for the hint!

timjim333 commented 1 year ago

Thanks for posting the query and thanks for the solution hint! I had this problem a few months ago too, but never had time (or ctypes wrapping knowledge) to debug it.

I'll try this out and report back, unless a PR will go through soon? Thanks.

time-trader commented 1 year ago

@timjim333 I have not managed to get in contact with the repo authors / maintainers. Will probably fork, for more active development.