Python API Control Surfaces in VSPAERO

28 views
Skip to first unread message

Prahaas Kotni

unread,
Apr 22, 2026, 12:38:02 AM (3 days ago) Apr 22
to OpenVSP
I am trying to model a flying wing in OpenVSP and perform VSPAERO on it. Since there are only 2 elevons, I need to add them to 2 different control surface groups (pitch and roll). 

Now, when I list the available control surface before adding them to the groups, I get this: ('Wing_Surf0_Elevons', 'Wing_Surf1_Elevons', 'Wing_Surf0_Elevons', 'Wing_Surf1_Elevons'). I am assuming there are duplicates because it creates thin surface counterparts. And so, I add 3 & 4 to the control surface groups.

My question is: how do I get the ID names for these control surfaces so I can set the deflection gain values?

This is my current code:

vsp.ReadVSPFile(vsp3_path)
    geom_analysis = "VSPAEROComputeGeometry"
    vsp.SetAnalysisInputDefaults(geom_analysis)
    vsp.SetIntAnalysisInput(geom_analysis, "GeomSet", [vsp.SET_NONE])      
    vsp.SetIntAnalysisInput(geom_analysis, "ThinGeomSet", [vsp.SET_SHOWN])
   
    # Control surfaces
    cs_pitch_id = vsp.CreateVSPAEROControlSurfaceGroup() # Pitch
    print(vsp.GetAvailableCSNameVec(cs_pitch_id))
    vsp.SetVSPAEROControlGroupName("Pitch", cs_pitch_id)
    vsp.AddSelectedToCSGroup([3, 4], cs_pitch_id)
    cs_roll_id = vsp.CreateVSPAEROControlSurfaceGroup() # Roll
    print(vsp.GetAvailableCSNameVec(cs_roll_id))
    vsp.SetVSPAEROControlGroupName("Roll", cs_roll_id)
    vsp.AddSelectedToCSGroup([3, 4], cs_roll_id)
    vsp.Update()
    group_pitch_str = f"ControlSurfaceGroup_{cs_pitch_id + 1}"
    container_id = vsp.FindContainer("VSPAEROSettings", 0)
    wing_id = vsp.FindGeoms()[0]
    cs_id = vsp.GetSubSurfIDVec(wing_id)[0]
    vsp.SetParmVal(vsp.FindParm(container_id, f"Surf_{cs_id}_0_Gain", "ControlSurfaceGroup_0"), 1.0)
    vsp.SetParmVal(vsp.FindParm(container_id, f"Surf_{cs_id}_1_Gain", "ControlSurfaceGroup_0"), -1.0)
    vsp.SetParmVal(vsp.FindParm(container_id, f"Surf_{cs_id}_0_Gain", "ControlSurfaceGroup_1"), 1.0)
    vsp.SetParmVal(vsp.FindParm(container_id, f"Surf_{cs_id}_1_Gain", "ControlSurfaceGroup_1"), 1.0)
    vsp.ExecAnalysis(geom_analysis)

And this is the output I get:

('Wing_Surf0_Elevons', 'Wing_Surf1_Elevons', 'Wing_Surf0_Elevons', 'Wing_Surf1_Elevons')
('Wing_Surf0_Elevons', 'Wing_Surf1_Elevons', 'Wing_Surf0_Elevons', 'Wing_Surf1_Elevons')
Error Code: 4, Desc: FindParm::Can't Find Parm Surf_JHZXCHJFBJ_0_Gain ControlSurfaceGroup_0
Error Code: 4, Desc: SetParmVal::Can't Find Parm
Error Code: 4, Desc: FindParm::Can't Find Parm Surf_JHZXCHJFBJ_1_Gain ControlSurfaceGroup_0
Error Code: 4, Desc: SetParmVal::Can't Find Parm
Error Code: 4, Desc: FindParm::Can't Find Parm Surf_JHZXCHJFBJ_0_Gain ControlSurfaceGroup_1
Error Code: 4, Desc: SetParmVal::Can't Find Parm
Error Code: 4, Desc: FindParm::Can't Find Parm Surf_JHZXCHJFBJ_1_Gain ControlSurfaceGroup_1
Error Code: 4, Desc: SetParmVal::Can't Find Parm

Now, if use indexes 1 & 2 to add to the CS group instead of 3 & 4, I get this output:

ERROR 7: Could not open History file: C:/Users/kprah/Desktop/Prahaas/WatArrow/VSP Automation/Wing.history
        File: D:\a\OpenVSP\OpenVSP\src\geom_core\VSPAEROMgr.cpp         Line:2296
ERROR 7: Could not open Load file: C:/Users/kprah/Desktop/Prahaas/WatArrow/VSP Automation/Wing.lod
        File: D:\a\OpenVSP\OpenVSP\src\geom_core\VSPAEROMgr.cpp         Line:2883

Error: Aerothermal database (*.adb) file not found. Execute VSPAERO before running the CpSlicer
Error Code: 5, Desc: FindLatestResultsID::Can't Find Name VSPAERO_Stab

For reference, I am on:
- OpenVSP 3.47.0
- Python 3.13

Please provide some guidance.

Omer Kandemir

unread,
Apr 22, 2026, 3:16:31 AM (3 days ago) Apr 22
to ope...@googlegroups.com
I'm using something similar in my set up to the following script:

  1. first set your control surface groups with " set_control_surface_groups" method which will return you " control_surface_groups" dictionary with Name and Index
  2. Then use " set_control_surface_deflections" method to set your deflections by giving  " control_surface_groups" dictionary and "deflections" list.
import openvsp as vsp
from dataclasses import dataclass 
@dataclass
class VSPAero:
    .....
    @classmethod
    def set_control_surface_groups(cls,control_surfaces,  gains=[-1,1]  ):
        control_surface_groups = {"GroupName":[],"GroupIndex":[]}
        for control_surface in control_surfaces:
           CSGroupIndex = cls.add_control_surface_group(control_surface,gains=gains)
           control_surface_groups["GroupName"].append(control_surface.tag)
           control_surface_groups["GroupIndex"].append(CSGroupIndex)
       
        return control_surface_groups
   
    @staticmethod
    def add_control_surface_group(control_surface,gains=[1,-1]):
        CSGroupIndex = vsp.CreateVSPAEROControlSurfaceGroup()
        vsp.SetVSPAEROControlGroupName(control_surface.tag, CSGroupIndex)
        cs_name_vec = vsp.GetAvailableCSNameVec(CSGroupIndex)
        selected_ind_vec = []
        for i, cs_name in enumerate(cs_name_vec):
            if control_surface.tag in cs_name:
                selected_ind_vec.append(i + 1)
        vsp.AddSelectedToCSGroup(selected_ind_vec, CSGroupIndex)
        vsp.Update()
        cont_id = vsp.FindContainer("VSPAEROSettings", 0 )
        vsp.SetParmVal(cont_id,f"Surf_{control_surface.vspID}_0_Gain",f"ControlSurfaceGroup_{CSGroupIndex}",float(gains[0]))
        vsp.SetParmVal(cont_id,f"Surf_{control_surface.vspID}_1_Gain",f"ControlSurfaceGroup_{CSGroupIndex}",float(gains[1]))
        vsp.Update()
        return CSGroupIndex
   
    @classmethod
    def set_control_surface_deflections(cls,control_surface_groups,deflections):
        for name, index in zip(control_surface_groups["GroupName"],
                               control_surface_groups["GroupIndex"]):
            for group, deflection in deflections.items():
                if name == group:
                   cls.set_control_surface_deflection(deflection, index)
                   
        return -1
    @staticmethod
    def set_control_surface_deflection(deflection,GroupIndex):
        cont_id = vsp.FindContainer("VSPAEROSettings", 0 )
        vsp.SetParmVal(cont_id,"DeflectionAngle",f"ControlSurfaceGroup_{GroupIndex}",float(deflection))

hope this will solve your problem
Ömer

--
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.
To view this discussion visit https://groups.google.com/d/msgid/openvsp/282ce900-cdd8-47fc-b2de-26f1cb03c610n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages