1

我正在尝试优化由 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 文件之前终止。有人知道为什么吗?:( 谢谢

4

1 回答 1

1

我总是SapObject.SapModel在每个 Ret 语句中使用……试试看,它可能会有所帮助……</p>

于 2020-04-20T07:19:09.037 回答