MATLAB 的 fminsearch 在 API 分析完成后无故终止SAP2000



我正在尝试优化SAP2000 v18.1 建立的结构数值模型。 为此,我在 MATLAB 中获取了 API 函数,并尝试通过 fminsearch 函数进行优化。MATLAB 打开模型,进行修改并运行分析。然后提取我要求的数据并基于它们进行优化。但 MATLAB 有时会在这一点上终止。"MATLAB 停止工作",当我按下"调试"按钮时,程序关闭。我检查了内存使用情况,这不是问题。我已经尝试了很多次运行该过程,有时在 2-3 次重复后,程序停止,但现在即使是第一次运行它也会终止。我想问题出在运行SAP2000并提取数据的函数中,因为那是程序停止工作的时候。 在这里你可以找到我写的部分代码:

function [ff] = OptimizeSAPMahsa(Varr)
%% Open SAP model file and unlock
%% update some parameters based on Varr
%% Run model (the analysis model)
ret = SapModel.Analyze.RunAnalysis();
%% Extract results
NumberResults = 0;
Obj = cellstr(' ');
Elm = cellstr(' ');
ACase = cellstr(' ');
StepType = cellstr(' ');
StepNum = reshape(0:1,2,1);
U1 = reshape(0:1,2,1);
U2 = reshape(0:1,2,1);
U3 = reshape(0:1,2,1);
R1 = reshape(0:1,2,1);
R2 = reshape(0:1,2,1);
R3 = reshape(0:1,2,1);
ObjectElm = 0;
ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput;
ret = SapModel.Results.Setup.SetCaseSelectedForOutput('Time History-16.04');
ret = SapModel.Results.Setup.SetOptionDirectHist(2); %step-by-step output
[ret, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3] = SapModel.Results.JointAcc('66', ObjectElm, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3);
acc66x_1604=U1;
acc66y_1604=U2;
NumberResults = 0;
Obj = cellstr(' ');
Elm = cellstr(' ');
ACase = cellstr(' ');
StepType = cellstr(' ');
StepNum = reshape(0:1,2,1);
U1 = reshape(0:1,2,1);
U2 = reshape(0:1,2,1);
U3 = reshape(0:1,2,1);
R1 = reshape(0:1,2,1);
R2 = reshape(0:1,2,1);
R3 = reshape(0:1,2,1);
ObjectElm = 0;
ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput;
ret = SapModel.Results.Setup.SetCaseSelectedForOutput('Time History-16.04');
ret = SapModel.Results.Setup.SetOptionDirectHist(2); %step-by-step output
[ret, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3] = SapModel.Results.JointAcc('73', ObjectElm, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3);
acc73x_1604=U1;
acc73y_1604=U2;
%% Close Sap2000
ret = SapObject.ApplicationExit(false());
SapModel = 0;
SapObject = 0;
[N66x1604] = SpecLinear(0.005,0.05,acc66x_1604,1);
[N73x1604] = SpecLinear(0.005,0.05,acc73x_1604,1);
[E66x1604] = SpecLinear(0.005,0.05,Joint66_x_1604,9.81);
[E73x1604] = SpecLinear(0.005,0.05,Joint73_x_1604,9.81);
ff=norm((N66x1604 - E66x1604).^2)+norm((N73x1604 - E73x1604).^2);
rezult(count)= ff;
const(:,count)= Varr';
count=count+1; 

然后将 ff 值报告给 fminsearch。但是问题出在我要求从模型中提取数据的行中,因为 MATLAB 在关闭SAP2000文件之前终止。有人知道为什么吗?:( 谢谢

我总是在每个 Ret 语句中使用SapObject.SapModel......试试看,这可能会有所帮助...

相关内容

  • 没有找到相关文章

最新更新