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

时间:2017-04-11 09:36:53

标签: matlab api optimization fminsearch

我正在尝试优化SAP2000 v18.1制作的结构数值模型。为此,我在MATLAB中获得了API函数,并尝试通过fminsearch函数进行优化。 MATLAB打开模型,进行修改并运行分析。然后提取我要求的数据并根据它们进行优化。但MATLAB SOMETIMES此时终止了。 “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文件之前终止。有人知道为什么吗? :( 感谢

1 个答案:

答案 0 :(得分:1)

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