Anaconda/Spyder Python VSPAero use

771 views
Skip to first unread message

Bhumika Dutta

unread,
May 16, 2022, 2:33:02 PM5/16/22
to OpenVSP
Hi,

I'm planning on using Spyder through Anaconda to run VSPAero analysis. I installed the Python API using this video. Also, I viewed Justin's presentation on Python Integration for some help. In his presentation, he mentioned that if we get an error about the VSPAero solver not being found, we should copy executables to python directory. What does that mean exactly? 

Additionally, I'm new to this, so is there some kind of tutorial that goes over how to use Python API to run VSPAero? Specifically, how would I do it through Spyder? 

Thanks in advance for the help. I appreciate it!

Bhumika

Screenshot 2022-05-16 132135.png

Brandon Litherland

unread,
May 16, 2022, 3:01:40 PM5/16/22
to OpenVSP
He might have meant to copy the vspaero.exe and the *.DLL files over to the python directory.  Probably an issue with relative paths.
Can you post the script you are using and maybe we can take a look.  I should really make a VSPAERO API tutorial sooner than later for the Ground School.

Bhumika Dutta

unread,
May 16, 2022, 3:55:32 PM5/16/22
to OpenVSP
I copied over VSPAero.exe. As for script I haven't run anything yet besides import openvsp as vsp and vsp.VSPCheckSetup() in python. I'm not sure what other script to write and run. 
Message has been deleted

Bhumika Dutta

unread,
May 17, 2022, 1:31:55 PM5/17/22
to OpenVSP
Are the scripts in the scripts folder what I use to get all the functions I need? Is it AngelScript? How do I translate it to python? Do I look at the TestAnalysisVSPAero file?

Brandon Litherland

unread,
May 17, 2022, 2:52:26 PM5/17/22
to OpenVSP
The API functions are well documented and generally up to date at http://openvsp.org/api_docs/latest/.
For a VSPAERO example specifically, I recommend the "vspaero_automation_test.py" script located in the python directory.  This will give you a really good idea on how to get started.

Bhumika Dutta

unread,
May 18, 2022, 1:04:10 PM5/18/22
to OpenVSP
The automation file would be helpful for me, but I can't find it in my python directory for some reason. I looked in the other folders as well. 

Brandon Litherland

unread,
May 18, 2022, 1:39:21 PM5/18/22
to OpenVSP
Oops.  Sorry about that.  That PY file is one that I use and keep with my main VSP build.  It won't be available to all users.
The VSPSCRIPT syntax and API syntax are very similar so you can generally work out how to write the API scripts and functions by looking at the scripts as examples.
See the various VSPAERO-related scripts in the scripts directory to get a sense of the code.  If you just want to execute a script, then use one of the examples as a template and build from there.

Sorry again about the confusion.

Bhumika Dutta

unread,
May 18, 2022, 1:43:36 PM5/18/22
to OpenVSP
Thanks for help!

Bhumika Dutta

unread,
May 18, 2022, 4:24:51 PM5/18/22
to OpenVSP
In order to run analysis, I need to 'read' the vsp file I want to use, right? I'm trying to follow the example script that I have in the screenshot. I have to set it up using the code laid out in the TestVSPAeroComputeGeomPanel() method?  Also, the lines I highlighted in the screenshot, I'm not sure what they're doing exactly. What is the purpose of the second line I highlighted? 
Screenshot 2022-05-18 152048.png

Brandon Litherland

unread,
May 20, 2022, 2:38:45 PM5/20/22
to OpenVSP
The highlighted lines are basically setting the vspaero analysis type to Panel.
Note that Analysis 1 isn't an acceptable string for the script.  You will want one of the analyses available in the API. Get a list of these by running vsp.ListAnalysis()

Bhumika Dutta

unread,
May 24, 2022, 12:41:58 PM5/24/22
to OpenVSP
What is the :: operator doing? I'm trying to translate it to python, but I'm not sure what the "VSPAERO::PANEL" does specifically. Also, when I try running print(vsp.ListAnalysis()), I'm getting a line that says "Reloaded Modules" and then empty (). I don't see any analyses that you mentioned unless the reloaded modules is supposed to be what I'm looking for. 

Brandon Litherland

unread,
May 25, 2022, 6:37:07 AM5/25/22
to OpenVSP
I was testing out the API last week and a bit yesterday and I've run into this as well.  I've rebuilt VSP and the API several times to see if this is a version problem in python or something else.  What's really strange is that I was getting the list from vsp.ListAnalysis() just fine Friday morning and by Friday afternoon they were gone.  I'm still chasing this down and testing in both py3.6 and py3.9 for current and prior OpenVSP versions.  If I can get one working then hopefully I can chase down what happened.  For now, you can probably get around this by interacting with your model in the API and saving the changes > clear the vsp model > read vsp model > run a vspscript for the analysis portion.

Bhumika Dutta

unread,
May 25, 2022, 5:44:04 PM5/25/22
to OpenVSP
I want to start by changing just alpha and mach start for running Panel. I don't really need to change anything about the model as of right now. When you say interacting with the model in the API, are you just referring to dimensions of the model, etc.? What do you mean by run a vspscript for the analysis portion? Do you just mean following and setting up code based on the example script files? Sorry if it seems like a silly question, I'm still new to this. 

Brandon Litherland

unread,
May 25, 2022, 7:35:44 PM5/25/22
to OpenVSP
You should be able to make model changes via the API then save the file when you're done.  From there, you can do an os.system() call to execute vspscript.  Python is great for writing your own vspaero input files and then executing scripts.  Alternatively, you can use a vspscript to set up all the vspaero inputs and geometry changes too and just use Python to edit those files using a string replace.  If you are only looking to run alpha and Mach sweeps you can do that from the GUI or by setting the vector in the vspaero input file.  To see what this looks like, create a default wing model and run vspaero from the gui with multiple alpha and Mach.  Take a look at the vspaero input file that is created for the run.  Essentially just comma separated values.

Bhumika Dutta

unread,
May 29, 2022, 11:56:34 AM5/29/22
to OpenVSP
I have some lines of code now I'm running just to see what happens. I commented out the last couple of lines, but I'm getting 'None" when I print vsp.SetIntAnalysisInputs(). Why is that? I thought that vsp.SetAnalysisInputDefaults() was supposed to account for the inputs. What would I need to fix?
Screenshot 2022-05-29 105534.png

Brandon Litherland

unread,
May 31, 2022, 5:42:08 AM5/31/22
to OpenVSP
I'm still working on getting this built back up.  The API is usually much more stable with py3.6.  I'm going to do a fresh build and try remaking the API with 3.6 to see if that fixes anything.  I recommend giving that a try. 
You'll want to set up different environments in Python, one for 3.6 and one for 3.9 (https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html).

The python3.9 version of OpenVSP _should_ work just fine but something has gotten mixed up.  I'm still not sure what yet.

Bhumika Dutta

unread,
Jun 1, 2022, 2:33:55 PM6/1/22
to OpenVSP
Alright, I just tried with 3.6 by making a new environment and I'm running into the same issue. 

Bhumika Dutta

unread,
Jun 1, 2022, 4:52:58 PM6/1/22
to OpenVSP
How would I go about changing mach and alpha from the API? Earlier you said to create a vector, what functions would that be referring to?  SetVec3dAnalysisInput()? Or would it be something under Parm Functions on the documentation page?

Rob McDonald

unread,
Jun 1, 2022, 7:33:20 PM6/1/22
to OpenVSP
Have you considered looking at the example scripts?  They are in AngelScript, but the API calls map 1:1 to the Python ones.


Rob

Message has been deleted

Bhumika Dutta

unread,
Jun 5, 2022, 5:41:29 PM6/5/22
to OpenVSP
Hi Rob, 

I've been following the example scripts, but I'm running into some trouble. Whenever I try to use PrintAnalysisInputs(), I'm getting "None". I already tried using SetAnalysisInputDefaults() and using SetDoubleAnalysisInput() (from the example script linked) for alpha and mach, but that doesn't seem to be working. Additionally, I tried python 3.9 as well as 3.6. Earlier in the thread, it was mentioned that I could use os.system() to run a vspscript. I've never used that before, so I'm not sure what command to use in the parenthesis. What would I need to do exactly? Should that be something I do instead of trying to write and run a python script myself? If you need my files/additional information, please let me know!

Brandon Litherland

unread,
Jun 6, 2022, 5:55:14 AM6/6/22
to OpenVSP
For the os.system() calls, you'll import os.  The string that goes in the parentheses is the same as what you would input to a command line such as:

Setting the command in the same line.
    os.system('vspaero -omp 4 myaircraft_DegenGeom')

Setting the command in a string variable and sending that to the system call.
    vsp_pardrag_command = 'vspscript -script RunParasiteDragExample.vspscript myaircraft.vsp3'
    os.system(vsp_pardrag_command)

Setting the command in the same line while passing input and output files.
    os.system('flops < FlopsInputFile.in > FlopsOutputFile.out')  * In this case you are passing the program an input file with '<' and telling it what the output file is called with '>'.  Also works with XROTOR, XFOIL, and other tools.  

Now, you _could_ just edit the vspaero input file manually with a string replace operation (or just write a new one each time) but this requires a lot of file operation, parsing, saving, etc. which takes extra time.  If you are running a large design space, this will significantly lengthen your runs.  Better is to write the VSPSCRIPT file to directly interact with the Analysis Manager and Results Manager exactly as shown in the example scripts and the API documentation.  This will let you grab the results you want directly from memory and write that out in a format or structure that's easy to manipulate and plot.  Here's the rub.  Because you are executing VSP from a system call rather than directly from the Python API, the Results Mgr won't be in memory for Python to grab without parsing a file.  At least, I don't think you can pause the os.system call while the results are still in memory somewhere and interact with that location through Python.  I could be wrong but it sounds tricky if possible.  Unless you are running several hundred cases or more, parsing the output files to get the values into Python memory as lists, dictionaries, Classes, etc. will probably work okay.

String replace is really easy in Python.  Here's an example where I use a template file, with the parts I wanted to replace set as specific strings, to create the input file for a FLOPS case.
    with open(TemplateFile, "rt") as fin:
        with open("FlopsInputFile.in", "wt") as fout:
            for line in fin:
                fout.write(line.replace('WINGCARGOWEIGHT', WingCargoWeight)
                               .replace('GENERATORWEIGHT', GeneratorWeight)
                               .replace('ELECTRICALWEIGHT', ElectricalWeight)
                               .replace('NEWTHRUST', NewThrust)
                               .replace('EXTRACTEDPOWER', ExtractedPower)
                               .replace('FUELLEAKRATE', FuelLeakRate)
                               .replace('CDOFRACTION', CD0Fraction))


Brandon Litherland

unread,
Jun 9, 2022, 2:13:52 PM6/9/22
to OpenVSP
So, something weird happened while I was trying to debug this today.  Do me a favor and try to run the test.py and test_degen_geom.py scripts from your IDE.  It doesn't matter if they work or not.  Once you do that, try and run "vsp.ListAnalysis()" and see if they don't show up.  It should look like this:

vsp.ListAnalysis()
Out[17]:
('BladeElement',
 'CfdMeshAnalysis',
 'CompGeom',
 'CpSlicer',
 'DegenGeom',
 'EmintonLord',
 'FeaMeshAnalysis',
 'MassProp',
 'ParasiteDrag',
 'PlanarSlice',
 'Projection',
 'SurfaceIntersection',
 'SurfacePatches',
 'VSPAEROComputeGeometry',
 'VSPAERODegenGeom',
 'VSPAEROSinglePoint',
 'VSPAEROSweep',
 'WaveDrag')

vsp.GetNumAnalysis()
Out[18]: 18


I'm still chasing this down.

Brandon Litherland

unread,
Jun 9, 2022, 2:14:43 PM6/9/22
to OpenVSP
Apologies.  Those are in the OpenVSP\python\openvsp\openvsp\tests\ folder.

Brandon Litherland

unread,
Jun 10, 2022, 3:21:43 PM6/10/22
to OpenVSP
Update: I think something is getting disconnected or isn't set up quite right on the initial "import openvsp as vsp" step.  However, if you run "vsp.VSPRenew()" then it seems that the connections are remade and the Analysis Manager works fine.  Still hunting for the actual root of this problem.

Bhumika Dutta

unread,
Jun 13, 2022, 1:30:46 PM6/13/22
to OpenVSP
Hey, sorry for the late reply - I've been sick. I tried doing what you told but I keep getting an error now that says "no module named 'openvsp' ". Not sure why this is happening - I used the Renew command too. Last week when I would try ListAnalysis(), sometimes I would get the correct output, but it's not consistent. 

I was wondering, is there a way to take the raw data for each panel (before running any analysis) that can be put into a csv file? Since Panel method still has some issues, my team and I were hoping to take the raw data (x, y, z, area, normal vector, Cp) and do some of our own analysis with it in python. 

José Alfredo Rosas

unread,
Jul 2, 2022, 3:44:22 AM7/2/22
to OpenVSP
Hello Brandon:

I've been trying to translate the TestAnalysisVSPAERO.vspscript into Python (the .py file is appended below) but have ran into some problems. The TestVSPAeroComputeGeom() and TestVSPAeroComputeGeomPanel() functions work as expected when using the Python syntax, but when trying to run the TestVSPAeroSharpTrailingEdge() analysis, the program gets stuck (funnily enough in the geometry generation part of the function). I have ran the tests you mentioned in this conversation and I was able to generate the analyses name list, so I am not sure if this would exactly qualify as the same problem discussed here but I am pretty sure it is related. I am running the Python 3.6 API, should I change to 3.9 perhaps?
vspaero_api_test.py
Reply all
Reply to author
Forward
0 new messages