понеділок, 21 липня 2025 р. о 13:16:42 UTC+3 Ishaan Khullar пише:
Hi,
Thanks so much for your help, I have almost got it working. I just had a couple of questions: I wanted to calculate the L/D ratio and hence wanted the total drag coefficient rather than the induced drag coefficient is there any way of getting this coefficient? (The only way i can think of currently is using aerodynamic formulas (CD = CD0 + KCL^2)). Also I don't think it is generating the vsp file properly such that I can view it properly in the GUI. Here is my revised code based on your suggestions. Any more tips? Thanks so much in advance
import sys
import csv
import pandas as pd
# Add OpenVSP Python module path
sys.path.append(r"C:\Users\khull\OneDrive\Documents\OpenVsp\OpenVSP-3.43.0-win64\python\openvsp")
import vsp
vsp.SetVSPAEROPath(r"C:\Users\khull\OneDrive\Documents\OpenVsp\OpenVSP-3.43.0-win64\python\openvsp\openvsp")
# Analysis conditions
aoa = 3.0
mach = 0.1
altitude = 0.0
# Design parameter ranges
camber_list = [0, 0.02, 0.04, 0.06]
cloc_list = [0.3, 0.4, 0.5]
tc_list = [0.09, 0.12, 0.15]
# Wing constants
span = 11.0
root_chord = 1.625
tip_chord = 0.325
sref = 16.32
cref = 1.38
bref = span
df = pd.DataFrame(columns=["Camber", "Camber_Loc", "Thickness", "CL", "CD", "L/D"])
# Loop through param combinations
for m in camber_list:
for p in cloc_list:
for t in tc_list:
print(f"\n Running: camber={m}%, cloc={p}, thickness={t}")
try:
vsp.ClearVSPModel()
wing_id = vsp.AddGeom("WING")
vsp.SetGeomName(wing_id, "ParametricWing")
# Set wing shape
print("no")
vsp.SetParmVal(wing_id, "Sym_Planar_Flag", "Sym", vsp.SYM_XZ)
print("HI1")
vsp.SetParmVal(wing_id, "SectTess_U", "XSec_1", 20)
vsp.SetParmVal(wing_id, "Span", "XSec_1", span)
print("HI2")
vsp.SetParmVal(wing_id, "Sweep", "XSec_1", 0.0)
print("HI3")
vsp.SetParmVal(wing_id, "Dihedral", "XSec_1", 1.5)
print("HI4")
vsp.SetParmVal(wing_id, "Twist", "XSec_1", -2.0)
print("HI5")
vsp.SetParmVal(wing_id, "Root_Chord", "XSec_1", root_chord)
print("HI6")
vsp.SetParmVal(wing_id, "Tip_Chord", "XSec_1", tip_chord)
# Set airfoil type and parameters
xsecsurf_id = vsp.GetXSecSurf(wing_id, 0)
# Change root and tip shapes
vsp.ChangeXSecShape(xsecsurf_id, 0, vsp.XS_FOUR_SERIES)
vsp.ChangeXSecShape(xsecsurf_id, 1, vsp.XS_FOUR_SERIES)
vsp.Update()
# Get section IDs
xsec_id_root = vsp.GetXSec(xsecsurf_id, 0)
xsec_id_tip = vsp.GetXSec(xsecsurf_id, 1)
# Set NACA parameters at root
camber = vsp.GetXSecParm(xsec_id_root, "Camber")
camber_loc = vsp.GetXSecParm(xsec_id_root, "CamberLoc")
thickness = vsp.GetXSecParm(xsec_id_root, "ThickChord")
vsp.SetParmVal(camber, m)
vsp.SetParmVal(camber_loc, p)
vsp.SetParmVal(thickness, t)
# Set NACA parameters at tip
camber = vsp.GetXSecParm(xsec_id_tip, "Camber")
camber_loc = vsp.GetXSecParm(xsec_id_tip, "CamberLoc")
thickness = vsp.GetXSecParm(xsec_id_tip, "ThickChord")
vsp.SetParmVal(camber, m)
vsp.SetParmVal(camber_loc, p)
vsp.SetParmVal(thickness, t)
vsp.Update()
print("HI8")
# Save geometry for checking
vsp_filename = f"vspaero_geom_c{m}_cloc{p}_t{t}.vsp3"
vsp.WriteVSPFile(vsp_filename, vsp.SET_ALL)
print(" Available results:")
history_res = vsp.FindLatestResultsID("VSPAERO_History")
cl_vals = vsp.GetDoubleResults(history_res, "CL")
cd_vals = vsp.GetDoubleResults(history_res, "CDi")
if cl_vals and cd_vals:
CL = cl_vals[0]
CD = cd_vals[0]
L_D = CL / CD if CD != 0 else 0
print(f" Done: CL={CL:.4f}, CD={CD:.4f}, L/D={L_D:.2f}")
new_row = {"Camber": m, "Camber_Loc": p, "Thickness": t, "CL": CL, "CD": CD, "L/D": L_D}
df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
else:
raise ValueError("Missing CL/CD values in VSPAERO results")
except Exception as e:
print(f" Error for camber={m}, cloc={p}, thickness={t}: {e}")
except Exception as e:
print(f" Error for camber={m}, cloc={p}, thickness={t}: {e}")