vspscript analysis result issue

110 views
Skip to first unread message

Michael Kang

unread,
Nov 9, 2025, 11:55:41 PMNov 9
to OpenVSP
Hello everyone
I made a Matlab function to write and run vspscript file and included a loop for parametric study about different CG location on main code.
The goal is to compare lift-to-drag ratio and static margin against normalized c.g. location between front wing and rear wing.

But, I'm stuck with some problems.
1. I realized that the results from each loop were exactly same, even though the Xcg in vspscript is updated.
2.  the results I got from OpenVSP GUI and vspscript were different.
Did I make any mistake in my workflow or on the code? 

Thank you for any advise.
Michael

Version: OpenVSP-3.46.0

Workflow:
1. Design geometry model(Tandem wing) and set some variables in vspaero settings.
2. Save the model in vsp3 file.
3. Read vsp3 file in vspsript and only change Xcg value through matlab code.

Code:
main code
캡처.PNG
function static margin: filter L/D and calculate SM
캡처.PNG
function analysis_result: write vspscript and ratain data from history file
function analysis_result = VSPAERO_batch_46_new(FUSELAGE, FWWING, RWWING, AIRCRAFT, geom_type)
id_vsp = fopen('QTR_VSP.vspscript', 'w');
fprintf(id_vsp, 'void main()\n{\n');
% clear any existing geometries
fprintf(id_vsp, ' ClearVSPModel();\n\n');
fprintf(id_vsp, ' DeleteAllResults();\n');
current_dir = pwd;
vsp3_full_path = fullfile(current_dir, 'QTR_VSP.vsp3');
vsp3_full_path_for_vsp = strrep(vsp3_full_path, '\', '/');
fprintf(id_vsp, ' string model_file = "%s";\n', vsp3_full_path_for_vsp);
fprintf(id_vsp, ' ReadVSPFile( model_file );\n');
fprintf(id_vsp, ' Update();\n\n');
fprintf(id_vsp, ' // Prepare analysis input for VSPAERO sweep analysis\n');
fprintf(id_vsp, ' string analysis_name = "VSPAEROSweep";\n');
fprintf(id_vsp, ' SetAnalysisInputDefaults( analysis_name );\n');
fprintf(id_vsp, ' Update();\n\n');
fprintf(id_vsp, ' array< double > Sref;\n');
fprintf(id_vsp, ' Sref.push_back( %.3f );\n', AIRCRAFT.S);
fprintf(id_vsp, ' SetDoubleAnalysisInput( analysis_name, "Sref", Sref, 0 );\n\n');
fprintf(id_vsp, ' array< double > Xcg;\n');
fprintf(id_vsp, ' Xcg.push_back( %.3f );\n', AIRCRAFT.X_cg);
fprintf(id_vsp, ' SetDoubleAnalysisInput( analysis_name, "Xcg", Xcg, 0 );\n\n');
fprintf(id_vsp, ' array< double > re;\n');
fprintf(id_vsp, ' re.push_back( %.2f );\n', 32.1740*AIRCRAFT.rho*AIRCRAFT.V_s*FUSELAGE.length/AIRCRAFT.mu);
fprintf(id_vsp, ' SetDoubleAnalysisInput( analysis_name, "ReCref", re, 0 );\n\n');
fprintf(id_vsp, ' array< double > Rho;\n');
fprintf(id_vsp, ' Rho.push_back( %.5f );\n',AIRCRAFT.rho);
fprintf(id_vsp, ' SetDoubleAnalysisInput( analysis_name, "Rho", Rho, 0 );\n\n');
fprintf(id_vsp, ' array< double > Vinf;\n');
fprintf(id_vsp, ' Vinf.push_back( %.2f );\n',AIRCRAFT.V_s);
fprintf(id_vsp, ' SetDoubleAnalysisInput( analysis_name, "Vinf", Vinf, 0 );\n\n');
fprintf(id_vsp, ' Update();\n\n')
fprintf(id_vsp, ' Print("Recomputing DegenGeom for updated Xcg...");\n');
fprintf(id_vsp, ' string compgeom_name = "VSPAEROComputeGeometry";\n');
fprintf(id_vsp, ' SetAnalysisInputDefaults(compgeom_name);\n');
fprintf(id_vsp, ' Update();\n');
fprintf(id_vsp, ' string compgeom_resid = ExecAnalysis(compgeom_name);\n');
fprintf(id_vsp, ' PrintResults(compgeom_resid);\n\n');
fprintf(id_vsp, ' Print("Running VSPAERO Sweep Analysis...");\n');
fprintf(id_vsp, ' string rid = ExecAnalysis(analysis_name);\n');
fprintf(id_vsp, ' PrintResults(rid);\n');
fprintf(id_vsp, ' Print("VSPAERO Sweep COMPLETE");\n');
fprintf(id_vsp, '}');
fclose(id_vsp);
cmd_sys = sprintf('%svsp.exe -script %s ','.\OpenVSP-3.46.0-win64\','QTR_VSP.vspscript');
[status,cmdout] = system(cmd_sys);
pause(5.0);
id_out1 = fopen('QTR_VSP.history', 'r');
case_num = 0;
analysis_result = [];
while ~feof(id_out1)
line = fgetl(id_out1);
if contains(line, 'Iter')
disp(case_num)
for i = 1:19
fgetl(id_out1);
end
line = fgetl(id_out1); disp(line)
result = str2double(split(line))';
analysis_result = [analysis_result; result(1:end)];
case_num = case_num + 1;
end
if case_num == alphanpts
break
end
end
fclose(id_out1);
end
QTR_VSP.vsp3
QTR_VSP.vspscript
Message has been deleted

Michael Kang

unread,
Nov 10, 2025, 4:03:21 AMNov 10
to OpenVSP
Update)

I realized that reading .vsp3 file in .vspscript does not include the vspaero settings, even though I made all the  vspaero  analysis settings and save it in .vsp3 on OpenVSP GUI.
Is there any way to read vspaero settings from .vsp3 in vspscript?
Please let me know.

Michael

2025년 11월 10일 월요일 오후 1시 55분 41초 UTC+9에 Michael Kang님이 작성:

Brandon Litherland

unread,
Nov 13, 2025, 7:08:47 PM (13 days ago) Nov 13
to OpenVSP
At the step where you set the analysis input defaults, it will overwrite the saved variables in the vsp3 file, as expected.
Before you go resetting everything to the defaults with that line of code, try simply checking if any inputs already exist and printing them with PrintAnalysisInputs( analysis_name ) as shown in https://openvsp.org/api_docs/latest/group___analysis.html#gab7afbab22139c02b81d72dd2364ed4d8.  If the inputs print out as you saved them, you should already be good to go.

Michael Kang

unread,
Nov 17, 2025, 1:37:42 AM (10 days ago) Nov 17
to OpenVSP
Thank you for your reply.

I tried simple script that read the vsp3 file and print inputs, as you said, then I noticed that OpenVSP could not parse XML Document.

I tried the following things, but I could not solve the parsing problem

1. Open the vsp3 file in OpenVSP GUI and save as new file.
2. Move the vsp3 file to simple directory.

Here's  vspscript code and the error screenshot.

void main()
{
ClearVSPModel();
ReadVSPFile( "C:/Temp/QTP_VSP.vsp3" );
string analysis_name = "VSPAEROComputeGeometry";

PrintAnalysisInputs( analysis_name );
Update();
}
1.PNG
2025년 11월 14일 금요일 오전 9시 8분 47초 UTC+9에 Brandon Litherland님이 작성:

Rob McDonald

unread,
Nov 17, 2025, 12:22:10 PM (9 days ago) Nov 17
to OpenVSP
OK, first you need to figure out why it won't load that file.  Check the file name, path, and capitalization carefully.

Next, the AnalysisMgr keeps its own set of settings for each analysis.  These are initialized when OpenVSP starts.

When you load a *.vsp3 file, these do not change.  If you want to load the analysis settings stored in the *.vsp3 file into the AnalysisMgr, that is what you use SetAnalysisInputDefaults() for.

Setting the defaults sets the AnalysisMgr inputs equal to whatever is stored in the currently loaded model -- which was read in from the *.vsp3 file.

So, the normal order of operations is:

Read VSP3 file.
Load Analysis Defaults
// This is a good place to PrintAnalysisInputs()
Change any analysis parameters as required
Execute Analysis
Query Results

Rob

Brandon Litherland

unread,
Nov 17, 2025, 1:24:04 PM (9 days ago) Nov 17
to OpenVSP
That was a misunderstanding on my part then. Sorry to lead you astray, Michael.

Michael Kang

unread,
Nov 25, 2025, 1:21:22 AM (yesterday) Nov 25
to OpenVSP
Hello, sorry for late reply..
Thank you Brandon and Rob.

I checked the settings that I made on OpenVSP were correctly loaded, however, the results between manually written script and automatically written script by Matlab code were still not same.
Also, the results from automatically written script were exactly same even though the Ref CG shifts rearward in every loop.
Is there any probable cause in my workflow?

PS) Xcg calculation formula changed in matlab code.

캡처.PNG
2025년 11월 18일 화요일 오전 3시 24분 4초 UTC+9에 Brandon Litherland님이 작성:
QTR_VSP_auto.history
QTR_VSP_auto.vspscript
QTR_VSP_manual.history
QTR_VSP_manual.vspscript
Reply all
Reply to author
Forward
0 new messages