Python API on Linux?

90 views
Skip to first unread message

Tim Swait

unread,
Mar 8, 2023, 12:42:10 PM3/8/23
to OpenVSP
I've installed OpenVSP on Ubuntu 22.04 using the appropriate .deb. However I would like to use the Python API, I can find tutorials for using it with Windows but can't find any tutorials to install it under Linux. Can someone point my to some instructions on how to do this please?

Brandon Litherland

unread,
Mar 8, 2023, 2:21:43 PM3/8/23
to OpenVSP
I may be wrong, but if you have your conda environment running the same version of Python that was used with the OpenVSP build then you should just be able to use "pip install -r requirements-dev.txt" from the command line.
I use a remote Jupyter notebook to import OpenVSP and run scripts.  I'm less familiar with exactly how to accomplish this on the Linux side.

Tim Swait

unread,
Mar 10, 2023, 8:57:58 AM3/10/23
to OpenVSP
Thank you, I ran that and it installed some requirements (most of them were already satisfied anyway). However it doesn't actually seem to have installed the API (I still get "ModuleNotFoundError: No module named 'openvsp'" when I try "import openvsp" in Python. I am also using Jupyter Notebook.

Brandon Litherland

unread,
Mar 10, 2023, 10:41:20 AM3/10/23
to OpenVSP
When you run the pip install does it echo out the progress and show what packages it's installing or replacing?  It should print what versions were successfully installed.
Just checking.

Tim Swait

unread,
Mar 10, 2023, 12:36:51 PM3/10/23
to OpenVSP
Thanks, got it working. Searching for the "requirements-dev.txt" found me the readme file (which is at /opt/OpenVSP/python/README.md in Linux installs). This explained how to install it. I then had "ERROR 7: VSPAERO Solver Not Found." when importing Open VSP, but fixed it using the workaround here:
Although, there I had to find the right folder to copy in to as it wasn't in quite the same folder structure as given above (mine was at $HOME/anaconda3/envs/vsppytools/lib/python3.10/site-packages/openvsp)
Anyway, now got it installed and it successfully ran the test script at https://github.com/OpenVSP/OpenVSP/blob/main/src/python_api/test.py except for errors on with not being able to find vsp.CFD_SRF_TYPE or  vsp.CFD_SRF_FILE_NAME, but these aren't functions I intend to use so shouldn't matter.

Are there any tutorials showing actually how to use the API to set up a model, run a VSPAERO analysis and output the results?

Brandon Litherland

unread,
Mar 10, 2023, 2:39:53 PM3/10/23
to OpenVSP
There are some discussions on the forum about scripting VSPAERO.  My first advice is always to look in the /scripts/ folder for examples of how to interact with things.

Setting up a model depends on how much of a design space you intend to explore.  If the models are all relatively similar, then my recommendation is to set things up in the GUI first, then use the API to modify those parms you care about.  The Results Manager is reading all of the VSPAERO output into memory so you can pick and choose what data you care about and export in your desired format.  I'm a big fan of writing results as comma delimited CSV files (no space after comma) and then reading that file in as a Pandas Dataframe.

Tim Swait

unread,
Mar 11, 2023, 1:09:34 PM3/11/23
to OpenVSP
Thank you for your help. I do already have a rough geometry that I set up in the GUI that now I'm trying to optimise. To start off with I thought I'd just try and practice by changing the overall span and chord values for the wing, but these aren't doing what I would expect. I found the Parms from the boxes on the GUI's so tried changing them, however this happens:
vsp.ReadVSPFile((path+fname))
geoms = vsp.FindGeoms()
span_id = vsp.GetParm(geoms[2], "TotalSpan",'WingGeom')
chord_id = vsp.GetParm(geoms[2], "TotalChord",'WingGeom')
print('Span:',vsp.GetParmVal(span_id), 'Chord:',vsp.GetParmVal(chord_id))
Span: 1.5271752771667715 Chord: 0.2832616732426238

So that gives me the existing values that match the values in the box on the GUI. So I try changing the span for example:

vsp.SetParmVal(span_id, 2)
print('Span:',vsp.GetParmVal(span_id), 'Chord:',vsp.GetParmVal(chord_id))
Span: 2.0 Chord: 0.2832616732426238

This appears to work, the span is now set to 2m. HOWEVER:

vsp.WriteVSPFile(path+fnamenew)
vsp.VSPRenew()
vsp.ReadVSPFile((path+fnamenew))
print('Span:',vsp.GetParmVal(span_id), 'Chord:',vsp.GetParmVal(chord_id))
Span: 1.5271752771667715 Chord: 0.2832616732426238


When I save and reload the file then my change is gone, it's back to the original value. Even stranger:

vsp.SetParmVal(chord_id, 0.2)
print('Span:',vsp.GetParmVal(span_id), 'Chord:',vsp.GetParmVal(chord_id))
Span: 1.5271752771667715 Chord: 0.2
 
I change the Chord and it seems to change. BUT when I save the file and reopen it:

vsp.WriteVSPFile(path+fnamenew)
vsp.VSPRenew()
vsp.ReadVSPFile((path+fnamenew))
print('Span:',vsp.GetParmVal(span_id), 'Chord:',vsp.GetParmVal(chord_id))
Span: 1.8174722773178038 Chord: 0.23801750912175504

The chord has changed, but to a value about halfway between what it was initially and what I had changed it to and now the span has changed to a new value also!
What on earth is going on here? Why aren't the values I'm setting staying set?
Tim


Tim Swait

unread,
Mar 17, 2023, 7:08:26 AM3/17/23
to OpenVSP
Can anyone suggest why these parms aren't changing to the values I'm setting?
Thanks,
Tim

Rob McDonald

unread,
Mar 17, 2023, 12:02:23 PM3/17/23
to OpenVSP
Try calling Update() after you change the total span parameter, but before you write out the file.

Rob

Tim Swait

unread,
Mar 17, 2023, 3:30:36 PM3/17/23
to OpenVSP
Thank you! Yes, that works.
Reply all
Reply to author
Forward
0 new messages