Simple Wing Creation using Python API

449 views
Skip to first unread message

Marvynn Fletcher

unread,
Oct 3, 2023, 8:28:58 AM10/3/23
to OpenVSP
Hello,

I am trying to create a simple tapered wing using python api.

I failed to insert the CST coefficients to define the airfoil. vsp3 file is created but cst foil I want to create is not there. I am adding the code below, could anyone advise me what I am doing wrong.

Thanks

import openvsp as vsp
import numpy as np
from cst_modeling.section import cst_foil, cst_curve, cst_foil_fit, foil_bump_modify, foil_increment
from matplotlib import pyplot as plt

cst_u = np.array([ 0.118598,  0.118914,  0.155731,  0.136732,  0.209265,  0.148305,  0.193591])
cst_l = np.array([-0.115514, -0.134195, -0.109145, -0.253206, -0.012220, -0.118463,  0.064100])



vsp.VSPCheckSetup()
vsp.VSPRenew()
vsp.ClearVSPModel()
vsp.DeleteAllResults()

wing = vsp.AddGeom("WING", "")


vsp.SetParmVal( wing, "Root_Chord", "XSec_1", 5.0 )
vsp.SetParmVal( wing, "Tip_Chord", "XSec_1", 3.0 )
vsp.SetParmVal( wing, "Span", "XSec_1", 10.0 )
vsp.SetParmVal( wing, "Sweep", "XSec_1", 10.0)
vsp.InsertXSec(wing, 0, vsp.XS_CST_AIRFOIL)

vsp.SetUpperCST("XSecCurve_0", 6, cst_u)
vsp.SetLowerCST("XSecCurve_0", 6, cst_l)

vsp.Update()

vsp.WriteVSPFile("wing.vsp3")

Rob McDonald

unread,
Oct 3, 2023, 6:11:50 PM10/3/23
to OpenVSP
I think you need a call to vsp.Update() after inserting the XSec.

Anything that changes the number / kind of Parms will typically need an Update() to fully take effect.

Rob

Marvynn Fletcher

unread,
Oct 4, 2023, 1:06:02 AM10/4/23
to OpenVSP
Hello Rob,

Thank you for the response, I updated the code as follows but unfortunately it took no effect.

import openvsp as vsp
import numpy as np
from cst_modeling.section import cst_foil, cst_curve, cst_foil_fit, foil_bump_modify, foil_increment
from matplotlib import pyplot as plt

cst_u = np.array([ 0.118598,  0.118914,  0.155731,  0.136732,  0.209265,  0.148305,  0.193591])
cst_l = np.array([-0.115514, -0.134195, -0.109145, -0.253206, -0.012220, -0.118463,  0.064100])


vsp.VSPCheckSetup()
vsp.VSPRenew()
vsp.ClearVSPModel()
vsp.DeleteAllResults()

wing = vsp.AddGeom("WING", "")


vsp.SetParmVal( wing, "Root_Chord", "XSec_1", 5.0 )
vsp.SetParmVal( wing, "Tip_Chord", "XSec_1", 3.0 )
vsp.SetParmVal( wing, "Span", "XSec_1", 10.0 )
vsp.SetParmVal( wing, "Sweep", "XSec_1", 10.0)

vsp.Update()

vsp.InsertXSec(wing, 0, vsp.XS_CST_AIRFOIL)

vsp.Update()


vsp.SetUpperCST("XSecCurve_0", 6, cst_u)
vsp.SetLowerCST("XSecCurve_0", 6, cst_l)

vsp.Update()

vsp.WriteVSPFile("wing.vsp3")


Regards,




4 Ekim 2023 Çarşamba tarihinde saat 01:11:50 UTC+3 itibarıyla Rob McDonald şunları yazdı:

Tim Swait

unread,
Oct 5, 2023, 5:25:14 AM10/5/23
to OpenVSP
I found it easier to start with a file with at least a wing object in it and then modify that. I work in Jupyter-lab so I run things through one cell at a time so I can check and debug it as I go along. It also helps to keep saving the .vsp3 file as you go and keep opening it in OpenVSP so you can check it's doing what you want. So my code was as below. I've also attached the blankwing file that it loaded by this.

import openvsp as vsp
import csv
#Load blankwing
fname = 'blankwing.vsp3'
vsp.VSPRenew()
vsp.ReadVSPFile((path+fname))
geoms = vsp.FindGeoms()
print(geoms)

#Extend with the required number of sections
wid = geoms[0]
for i in range(2,len(sections)):
    vsp.InsertXSec(wid, 1, 12)
vsp.Update()

#Save and open this file to check it worked
fnamenew = 'sectwing.vsp3'
vsp.WriteVSPFile(path+fnamenew)
vsp.VSPRenew()
vsp.ReadVSPFile((path+fnamenew))
geoms = vsp.FindGeoms()

#Set the size of each segment (chord and span
for i in range(len(spans)):
    xsec = 'XSec_'+str(i+1)
    print(xsec)
    b_id = vsp.GetParm(wid, "Span",xsec)
    c_id = vsp.GetParm(wid, "Root_Chord",xsec)
    print('before',vsp.GetParmVal(b_id),vsp.GetParmVal(c_id))
    vsp.SetParmVal(b_id, spans[i])
    vsp.Update()
    vsp.SetParmVal(c_id, chords[i])
    vsp.Update()
    print('After',vsp.GetParmVal(b_id),vsp.GetParmVal(c_id))
c_id = vsp.GetParm(wid, "Tip_Chord",xsec)
vsp.SetParmVal(c_id, chords[-1])

#Check this bit worked
fnamenew = 'P7API.vsp3'
vsp.WriteVSPFile(path+fnamenew)
vsp.VSPRenew()
vsp.ReadVSPFile((path+fnamenew))

#Assign aerofoils to each segment
xsec_surf = vsp.GetXSecSurf( wid, 0 )
print(xsec_surf)
for i in range(len(sections)):
    xsec = vsp.GetXSec(xsec_surf, i)
    fname = path+'sections/sec'+str(i)+'.dat'
    print(xsec, fname)
    vsp.ReadFileAirfoil(xsec, fname)
    vsp.Update()
blankwing.vsp3

Marvynn Fletcher

unread,
Oct 6, 2023, 3:12:23 AM10/6/23
to OpenVSP
Thank you for the response Tim, I found your code to be quite useful. The problem I am having is that I use CST parametization for airfoil definition which even input but command
it doesnt take effect in the vsp model, I noticed that you read airfoil files to define it however I use other codes to perform wing optimizations and I dont want to print and read coordinates file which would
make the process I want longer. But at least I have your solution now thank you.

Kind Regards

5 Ekim 2023 Perşembe tarihinde saat 12:25:14 UTC+3 itibarıyla Tim Swait şunları yazdı:
Reply all
Reply to author
Forward
0 new messages