Open VSP - Python

2,323 views
Skip to first unread message

Juliette P.

unread,
Feb 11, 2016, 8:00:32 AM2/11/16
to OpenVSP
Hi everyone !

I am trying to create a software of conceptual design of an airplane using Python. For the lift computation, I plan to use Open VSP (and the module VSPAERO). Problem : I need to link those two softwares. 
Do someone know how to open "Open VSP" in a Python script, launch an analysis and extract the results (of the lift coefficient) ?

Thank you in advance !

Juliette P.

Rob McDonald

unread,
Feb 11, 2016, 11:06:21 AM2/11/16
to ope...@googlegroups.com
Juliette,

OpenVSP has an API that has been wrapped in Python using SWIG. I.e.
you can make calls to VSP directly from Python.

Since the wrapper has to match the end-user's Python very closely, we
don't distribute pre-compiled wrappers. So, you'll have to set up to
compile OpenVSP yourself.

You will be able to use that wrapper to create and modify OpenVSP
models, and to trigger creation of the DegenGeom file output.

We haven't put VSPAERO execution into the API yet because it is a
command line tool that we're currently wrapping pretty thinly. It
shouldn't be much trouble to wrap it similarly from Python.

Rob
> --
> You received this message because you are subscribed to the Google Groups
> "OpenVSP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to openvsp+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Juliette Porto

unread,
Feb 12, 2016, 5:52:57 AM2/12/16
to ope...@googlegroups.com
Hi Rob !

Thank you for your quick answer. Unfortunately, this is my first time using Python (and I have not a good level in other programmation langages), so even if I understand what you mean, I have no idea on how to do it..
Do you know where I can find the API of Open VSP ? I have checked the Open VSP wiki, and they said that the operations are possible using an API, but nothing about the API itself. 



You received this message because you are subscribed to a topic in the Google Groups "OpenVSP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openvsp/SrmKL9k8zwQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openvsp+u...@googlegroups.com.

Rob McDonald

unread,
Feb 12, 2016, 11:49:14 AM2/12/16
to ope...@googlegroups.com
There is a test program that uses the Python API to make VSP do some
stuff... That is probably the best place for you to start thinking
about if this approach would work for you.

https://github.com/OpenVSP/OpenVSP/blob/master/src/python_api/test.py

Do you have someone in your group/team that has more programming
experience? None of what you'll need to do is particularly hard, but
it will have a series of obstacles that you'll need to clear.

Rob

Juliette Porto

unread,
Feb 12, 2016, 1:00:34 PM2/12/16
to ope...@googlegroups.com
Hi Rob !

I have looked at the link, but they are coding Open VSP in Python if I understand well. I don't think I have to go that far.. What I was thinking after looking at the API, is writing a file "wing.vspscript" in python and a file "DegenGeom.vspaero" in python too. Then launch the analysis with those two files. Do you think it may work ?

Unfortunately we are all students with no programming background so it is quite complicated as you can imagine. 

(Another question, linked to the writing of the "wing.vspscript" : do you know how to select an airfoil coming from a database?)

Thank you for your time and answers anyway !

Rob McDonald

unread,
Feb 12, 2016, 11:29:25 PM2/12/16
to ope...@googlegroups.com
> I have looked at the link, but they are coding Open VSP in Python if I
> understand well. I don't think I have to go that far.. What I was thinking
> after looking at the API, is writing a file "wing.vspscript" in python and a
> file "DegenGeom.vspaero" in python too. Then launch the analysis with those
> two files. Do you think it may work ?

You seem to be a bit wrapped around the axle.

Yes, accessing the VSP API by writing your own *.vspscript file is
probably the easiest way to go. Usually, such a script would be
written manually and then executed in a batch mode.

That script could tell OpenVSP to write out the DegenGeom *.csv file
containing the aircraft geometry.

You would probably then manually write a *.vspaero file containing the
run conditions for VSPAERO.

Depending on what you want to change/automate, you might modify some
of those steps. So far, none of this requires Python.

You mentioned Python (I don't really know why), but if you wanted to
use Python to automate the above, you could use the Python API instead
of the *.vspscript file -- they're largely interchangeable.


> Unfortunately we are all students with no programming background so it is
> quite complicated as you can imagine.

In my experience, student's minds are able to pick up some programming
concepts very quickly. I wouldn't sell yourself short.

Without any programming at all, I don't know how you'll accomplish
what you're trying to do -- of course, I still don't know what that
is...

> (Another question, linked to the writing of the "wing.vspscript" : do you
> know how to select an airfoil coming from a database?)

You can read in any airfoil file from the UIUC database through your
script. Something like this...

ChangeXSecShape( xsec_surf, 1, XS_FILE_AIRFOIL );
xsec = GetXSec( xsec_surf, 1 );
ReadFileAirfoil( xsec, "N0012_VSP.af" );

Rob

Michael Kruger

unread,
Feb 17, 2016, 5:56:47 AM2/17/16
to OpenVSP
Hi Juliette.

You can use the Python module 'subprocess' to make system calls, as if you are making the call in command line.

Here is some documentation on subprocess.

So if the vsp executable is in your system path (see here for some instructions on how to add a directory to your path), the following line in Python will execute VSP:

import subprocess
subprocess.call(args=["vsp"], shell=True)

So now that you know how to do this, you can play around in the subprocess and VSP documentation to find out how to send arguments to vsp and run scripts.

Hope this helps a little.

Francisco Capristan

unread,
Feb 17, 2016, 6:08:33 PM2/17/16
to OpenVSP
This might be of interest to you http://suave.stanford.edu/ 

Francisco

Juliette Porto

unread,
Mar 2, 2016, 10:35:16 AM3/2/16
to ope...@googlegroups.com
Hi all!

Sorry for the late answer.

@Rob McDonald: My project is to measure the impact of new technologies on a commercial aircraft (such as A320), by creating a software coded in Python. In order to do that, we separated our group in several parts, and I am in charge of the aerodynamics. At the end I want to obtain the polar curve (Cl as a function of Cd), for a realistic 3D wing. This is why I am using OpenVSP to obtain the Cl (through vspaero). My problem is that I need to integrate the processus of using OpenVSP in the Python Software, this is why it is required for me to use Python.
Thank you for the writing of the wing airfoil! I think the best for me is to do what you said, and to try to write the script using Python API.

@Michael Kruger: Thank you for the information! I will look in more details at it. The problem is I want to automatize the processus in OpenVSP, and not ask the user to create the file each time for efficiency reasons.

@Francisco Capristan: Thank you for the website ! I didn't know there were people doing the same kind of job, it's really interesting and I think I may find some good clues on it !

--

Juliette Porto

unread,
Mar 4, 2016, 3:48:15 PM3/4/16
to ope...@googlegroups.com
Hi everyone!

Now that I am using vspscript, it's almost done thanks to the API. Here is a version of my wing. The problem is I am not sure how to change the airfoil? I need to read .dat file for each of the three sections to obtain the real airfoils.
I tried using the code below, but it is not working:

    //==== Change Airfoil ====//
    ChangeXSecShape( xsec_surf, 1, XS_FILE_AIRFOIL );
    xsec1 = GetXSec( xsec_surf, 1 );
    ReadFileAirfoil( xsec1, "D:/OpenVSP-3.5.1-win32/airfoil/airfoil_f_15_15.dat" );

    array< vec3d > @up_array = GetAirfoilUpperPnts( xsec1 );
    array< vec3d > @low_array = GetAirfoilLowerPnts( xsec1 );

    for ( int i = 0 ; i < int(up_array.size()) ; i++ )
    {
        up_array[i].scale_y( 2.0 );
        low_array[i].scale_y( 0.5 );
    }

    SetAirfoilPnts( xsec1, up_array, low_array );

    Update();

(Remark: with normal four series airfoils, the script is working).

If someone could help me it would be amazing... ^^'
wing_airfoil_to_change.vspscript

Rob McDonald

unread,
Mar 5, 2016, 11:31:38 AM3/5/16
to ope...@googlegroups.com
Juliette,

You should probably get in the habit of putting something like this at
the end of your vspscript

//==== Check For API Errors ====//
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
Print( err.GetErrorString() );
}

The vsp scripting stuff has a flexible error checking system. You can
check for errors after every API call, or you can wait until the end
(like this), or you can ignore them entirely (what you're doing).

Adding this to the end will help us figure out which command is having
trouble -- and it may even tell what the trouble is.

Rob
> You received this message because you are subscribed to the Google Groups
> "OpenVSP" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Juliette Porto

unread,
Mar 6, 2016, 9:23:06 AM3/6/16
to ope...@googlegroups.com
Hello!

This is what I obtain when I run the code attached to this message. The problem is linked to the change of the airfoils, but I have not enough background in it to know how to correct the code. 
It seems that I need to declare xsec_surface ?

Images intégrées 1

wing_airfoil_dat.vspscript
airfoil_f_15_15.dat

Rob McDonald

unread,
Mar 6, 2016, 12:31:25 PM3/6/16
to ope...@googlegroups.com
Your script isn't even getting to the point where it can run.  Those errors are produced by the scripting language AngelScript when it 'compiles' your script.

Each error (starting from the top) is something that you need to fix.  The compiler does a pretty explicit job of telling you what the problem is.

The first error probably needs to be fixed with something like

string xsec_surf = GetXSecSurf( wid, 0 );

Before you ever use xsec_surf.

Rob


Juliette Porto

unread,
Mar 6, 2016, 1:56:26 PM3/6/16
to ope...@googlegroups.com
Hi !

After numerous errors, it finally works, thank you a lot for the help Mr. McDonald ! 

Here is my version to read an airfoil if someone needs it:

    //==== Change Airfoil 0====//
    string xsec_surf0 = GetXSecSurf( wid, 0 );
    ChangeXSecShape( xsec_surf0, 0, XS_FILE_AIRFOIL );
    string xsec0 = GetXSec( xsec_surf0, 0 );
    ReadFileAirfoil( xsec0, "D:/OpenVSP-3.5.1-win32/airfoil/airfoil_f_15_15.dat" );

    array< vec3d > @up_array0 = GetAirfoilUpperPnts( xsec0 );
    array< vec3d > @low_array0 = GetAirfoilLowerPnts( xsec0 );

    for ( int i = 0 ; i < int(up_array0.size()) ; i++ )
    {
        up_array0[i].scale_y( 2.0 );
        low_array0[i].scale_y( 0.5 );
    }

    SetAirfoilPnts( xsec0, up_array0, low_array0 );

    Update();

Rob McDonald

unread,
Mar 6, 2016, 2:44:44 PM3/6/16
to ope...@googlegroups.com
Glad to hear you got something working.

I know you pulled things from TestALL.vspscript, but it seems to me that you are very unlikely to want to do this part:


    array< vec3d > @up_array0 = GetAirfoilUpperPnts( xsec0 );
    array< vec3d > @low_array0 = GetAirfoilLowerPnts( xsec0 );

    for ( int i = 0 ; i < int(up_array0.size()) ; i++ )
    {
        up_array0[i].scale_y( 2.0 );
        low_array0[i].scale_y( 0.5 );
    }

    SetAirfoilPnts( xsec0, up_array0, low_array0 );


That part was there to test manipulating the points from the script.  This would allow a person to define an airfoil directly from code.  In this case, we take the points that were read from file, stretch the top surface, and shrink the bottom surface.  This makes for a clearly visible change to the airfoil -- something I could check to see if it did what was expected.

I would find it highly unusual that anyone would actually want to do this.

Rob

Juliette Porto

unread,
Mar 7, 2016, 11:33:07 AM3/7/16
to ope...@googlegroups.com
Oups, just forgot to take it off, you are right it has no interest in my case !

Văn Hưng Hoàng

unread,
Jan 4, 2023, 3:35:30 AM1/4/23
to OpenVSP
Hi Juliette!
Now I also have to deal with a math problem like you used to. Has your problem been resolved? Can you guide me? Thank you!

Vào lúc 19:33:07 UTC+3 ngày Thứ Hai, 7 tháng 3, 2016, Juliette P. đã viết:

Brandon Litherland

unread,
Jan 4, 2023, 11:00:12 AM1/4/23
to OpenVSP
Can you be more specific?  Are you just trying to launch the VSPAERO solver from the API or are you trying to set airfoil sections too?  What exactly are you trying to accomplish?
In the posts above, running VSPAERO from the API and setting airfoil sections were both addressed.

Reply all
Reply to author
Forward
0 new messages