Xero64 / pyvlm

Vortex Lattice Method in Python
MIT License
4 stars 2 forks source link

Run aircraft.py #6

Closed IzzakQ closed 1 week ago

IzzakQ commented 1 month ago

Hi, thank you for your project! I want to run aircraft.py file from directory, but I've a problem

PS D:\xero> python .\scripts\aircraft.py     
Traceback (most recent call last):
  File "D:\xero\scripts\aircraft.py", line 12, in <module>
    lsys = latticesystem_from_json(jsonfilepath)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AkhmedovIA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvlm\classes\latticesystem.py", line 388, in latticesystem_from_json
    sys = latticesystem_from_dict(sysdct)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AkhmedovIA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvlm\classes\latticesystem.py", line 421, in latticesystem_from_dict
    sfc = latticesurface_from_json(surfdata)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AkhmedovIA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvlm\classes\latticesurface.py", line 235, in latticesurface_from_json
    x.append(sect.pnt.x)
             ^^^^^^^^
AttributeError: type object 'ValueError' has no attribute 'pnt'

how can I solve it?

Xero64 commented 1 month ago

Hi

It appears to run correctly on my side. See if you can pull the latest code to see if that sorts it out.

Otherwise, have you edited the "Aircraft.json" file or are you referring to a different input Json file. If so, then perhaps one of the section inputs doesn't have an "xpos", "ypos", "zpos".

If you are willing to share your input file, then I am happy to look for you.

Let me know if your issue is resolved.

IzzakQ commented 1 month ago

Yes, I have empty "xpos", "ypos", "zpos". Do you have working file for any simple aircraft?

{
                    "xpos": null,
                    "ypos": 0.21,
                    "zpos": null,
                    "chord": 0.35,
                    "angle": 0.0,
                    "numb": 5,
                    "bspace": "semi-cosine",
                    "airfoil": "NACA 2412"
                },
                {
                    "xpos": null,
                    "ypos": 0.8,
                    "zpos": null,
                    "chord": null,
                    "angle": null,
                    "numb": 20,
                    "bspace": "semi-cosine",
                    "airfoil": "NACA 2412"
                },
                {
                    "xpos": null,
                    "ypos": 1.8,
                    "zpos": null,
                    "chord": null,
                    "angle": null,
                    "numb": 15,
                    "bspace": "cosine",
                    "airfoil": "NACA 2412",
                    "controls": {
                        "aileron": {
                            "xhinge": 0.8,
                            "posgain": 1.0,
                            "neggain": 0.8,
                            "reverse": true,
                            "hvec": {"x": 0.0, "y": 0.0, "z": 0.0}
                        }
                    }
                },
Xero64 commented 1 month ago

I suspect the issue is because you have an older version of pyvlm where a ValueError was returned rather than raised.

Please upgrade to the latest pyvlm, and latest pygeom using:

pip install pygeom --upgrade pip install pyvlm --upgrade

Let me know if that manages to sort out your issue.

These repositories are very much beta project until later releases, so I highly recommend cloning the repositories so that you can pull the latest main branch when need.

IzzakQ commented 1 month ago

I try to run your project on Mac. It works more correctly, but I've same issue with running aircraft.json....

isak@MacBook-Air-Isak pyvlm % /usr/local/bin/python3 /Users/isak/Desktop/pyvlm/scripts/aircraft.py
# Lattice System Aircraft

| Name     | Sref  | cref | bref | xref  | yref  | zref  |
| :------: | :---: | :--: | :--: | :---: | :---: | :---: |
| Aircraft | 1.358 | 0.31 |  4.5 | 1.175 | 0.000 | 0.000 |

| # Strips | # Panels | # Controls |
| :------: | :------: | :--------: |
|      252 |     1926 |          3 |

Traceback (most recent call last):
  File "/Users/isak/Desktop/pyvlm/scripts/aircraft.py", line 22, in <module>
    display_markdown(lres)
  File "/Users/isak/Library/Python/3.12/lib/python/site-packages/IPython/core/display.py", line 145, in display_markdown
    _display_mimetype('text/markdown', objs, **kwargs)
  File "/Users/isak/Library/Python/3.12/lib/python/site-packages/IPython/core/display.py", line 86, in _display_mimetype
    display_functions.display(*objs, raw=raw, metadata=metadata, include=[mimetype])
  File "/Users/isak/Library/Python/3.12/lib/python/site-packages/IPython/core/display_functions.py", line 265, in display
    print(*objs)
  File "/Users/isak/Desktop/pyvlm/pyvlm/classes/latticeresult.py", line 980, in __str__
    return self.to_mdobj()._repr_markdown_()
           ^^^^^^^^^^^^^^^
  File "/Users/isak/Desktop/pyvlm/pyvlm/classes/latticeresult.py", line 910, in to_mdobj
    report.add_heading(f'Lattice Result {self.name:s} for {self.sys.name:s}', 1)
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'MDReport' object has no attribute 'add_heading'

Anyway, I've some questions to your project:

  1. Do you validate your soft with another open-source project? (Like XFLR5 or AVL)
  2. Can I help for you create a GUI interface, so if you have in plan to add it?
Xero64 commented 1 month ago

Hi

My apologies, I forgot that I referred to the latest py2md for markdown reports. You will need the latest py2md as well.

Install with pip install py2md --upgrade.

In terms of your questions:

  1. I did extensive validation against AVL in terms of getting correct force calculation for simple cases. It matched very well.
  2. I do have a long-term plan to add a simple GUI to the code, but the license doesn't restrict you from creating your own. Please share info on it if you would like to develop a GUI and I would gladly also be a contributor to such an effort.

I also developed pyapm, which is a full 3D panel method. It uses the same input file as pyvlm. I have been working on pygeom to create geometry to blend fuselages with wings, to get their interaction correctly modelled. It is a side project but am hoping to be able to bring everything together at some point in the not-too-distant future. After that, the plan was for a GUI.

Hopefully with the pip install above, all the debugging issues are resolved. Let me know.

IzzakQ commented 1 month ago

Yes, everything is correct except for a couple of lines that I managed to comment out and everything worked.


latticeresult_to_msh(lres, '../results/Aircraft.msh')
latticeresult_to_prf(lsys, '../results/Aircults/Aircraft_pressures.json')

The files themselves are not in your repository, as I understand.

As for the questions:

  1. I'm trying to develop my own VLM solver based on XFLR5 and AVL examples, but since it's all closed code, I'm having some difficulties in implementation. Right now I am validating my project on the AGARD wing example and comparing polars to make sure the formulas are correct

  2. In the future, I would like to join GUI development, but for now I want to get my hands on the simple stuff

P.S. Don't you find the data output a bit unreadable?

Xero64 commented 1 month ago

Hi

It is great to hear that you got it working.

To fix the two lines you commented: you just need to create a directory called results one directory up from your current directory or you can edit the path. They are written out from the code, so you don't need them. You can then open the "msh" file to view in GMSH as shown below.

image

  1. I developed my own solver because I wanted to add span load optimisation to the solver. Python was the best option to do so; and using the vector math of pygeom it simplifies everything quite substantially. Unless you plan to do something different with it then solvers like XFLR5 and AVL are ready to use and well documented. Not sure about XFLR5, but AVL is open source, and you can view the source code. It comes with the download as a zip file, but it is written in Fortran and therefore is only readable if you know Fortran. I got clues on where the control points are positioned, etc, but the math for VLM is widely available. I just needed to look in the AVL source to try and get an exact correlation. I am interested in your motivations for developing a solver of your own?
  2. That sounds like a plan. Currently I am working with k3d in Jupyter notebook to generate the 3D plots for a new code I am writing. It is good enough for me while I validate the new code to make sure everything is correct. I will keep in mind that you are interested in developing a GUI.

Since I use Jupyter notebooks the markdown is displayed quite nicely. I am not sure of your exact setup, but I run the scripts in VS Code as an Interactive notebook. See the output below.

image

IzzakQ commented 1 month ago

I suspect the issue is because you have an older version of pyvlm where a ValueError was returned rather than raised.

Please upgrade to the latest pyvlm, and latest pygeom using:

pip install pygeom --upgrade pip install pyvlm --upgrade

Let me know if that manages to sort out your issue.

These repositories are very much beta project until later releases, so I highly recommend cloning the repositories so that you can pull the latest main branch when need.

After use "pip upgrade" It's on Win Machine

Traceback (most recent call last):
  File "d:\xero\scripts\aircraft.py", line 12, in <module>
    lsys = latticesystem_from_json(jsonfilepath)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AkhmedovIA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvlm\classes\latticesystem.py", line 414, in latticesystem_from_json
    sys = latticesystem_from_dict(sysdct)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AkhmedovIA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvlm\classes\latticesystem.py", line 472, in latticesystem_from_dict
    lsys.mesh()
  File "C:\Users\AkhmedovIA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvlm\classes\latticesystem.py", line 74, in mesh
    lsid, lpid = srfc.mesh(lsid, lpid)
                 ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AkhmedovIA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvlm\classes\latticesurface.py", line 90, in mesh
    lenc = len(self.cspc)
           ^^^^^^^^^^^^^^
TypeError: object of type 'NoneType' has no len()
IzzakQ commented 1 month ago

Hi

It is great to hear that you got it working.

To fix the two lines you commented: you just need to create a directory called results one directory up from your current directory or you can edit the path. They are written out from the code, so you don't need them. You can then open the "msh" file to view in GMSH as shown below.

image

  1. I developed my own solver because I wanted to add span load optimisation to the solver. Python was the best option to do so; and using the vector math of pygeom it simplifies everything quite substantially. Unless you plan to do something different with it then solvers like XFLR5 and AVL are ready to use and well documented. Not sure about XFLR5, but AVL is open source, and you can view the source code. It comes with the download as a zip file, but it is written in Fortran and therefore is only readable if you know Fortran. I got clues on where the control points are positioned, etc, but the math for VLM is widely available. I just needed to look in the AVL source to try and get an exact correlation. I am interested in your motivations for developing a solver of your own?
  2. That sounds like a plan. Currently I am working with k3d in Jupyter notebook to generate the 3D plots for a new code I am writing. It is good enough for me while I validate the new code to make sure everything is correct. I will keep in mind that you are interested in developing a GUI.

Since I use Jupyter notebooks the markdown is displayed quite nicely. I am not sure of your exact setup, but I run the scripts in VS Code as an Interactive notebook. See the output below.

image

WoW, your Interactive notebook on Jupyter looks awesome!

  1. Yes, I agree with you that VLM has a wide knowledge base, but when creating my own solver, I could not make the results beat well against already known solvers (XFLR5, AVL). My motivation is to create almost the same solution as yours, but with the addition of a fuselage, control surfaces, flight range with a specified payload mass, Specific engine consumption, Cruising Mach number and much more.

  2. So far, I am creating the output of Matplotlib graphs via PyQt5 and using the button to output and export these graphs to .*csv. I think that when visualizing data, you should not try to reinvent the wheel and it is better to use ready-made 2d and 3d visualization solutions. But for now, the main task is to solve the convergence with XFLR5. I got good convergence with the XFLR5 flat wing, but as soon as I add the NACA profiles, the convergence leaves much to be desired.....

image Blue - XFLR5 Orange - my sol

Xero64 commented 1 month ago

As for the error you are getting on your Windows machine, I am not sure why that would be the case. I will try and add more error checking and validation on the weekend to pyvlm, but you will only be able to get the updates if you git clone this repository and add the directory to the PythonPath environment variable. I don't think I will publish another update to pip install until I fix a few more issues on my list of issues.

  1. I have much the same motivation for developing my own panel methods. I managed to get to control surfaces, Mach numbers, as well as control and stability derivatives to work, and it does match AVL very well. My only issue is with side slip, which I plan to remedy in the not-too-distant future. I also really want to get to the point of including a fuselage. I have other code for specific fuel consumption, range, climb, propeller performance, but it is very new, and not well tested, so I haven't made it public yet.
  2. I don't plan to reinvent any 2D or 3D visualisation solutions. XFLR5, I think, has multiple options. You can use it for VLM, and then full 3D potential methods. The full 3D method will have a slightly higher CLa than a VLM. In other words, the Cla is slightly more than standard 2*pi for a flat plate, and this then gets extended to the 3D polars as well. This may account for the difference, although you should also see profile drag if you are using the 3D panel method. It is difficult to tell. I spent many hours trying to figure out why I am getting difference from AVL.

All the best for your coding. It is such a great tool to learn new things.