Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAP2000 API using MATLAB - Time History Analysis 3

Status
Not open for further replies.

bridgehealth

Structural
May 23, 2011
2
I'm trying to run an time history analysis using the SAP API with MATLAB to run several different (100s) of time history records on a structure. I've been able to create the actual time history load case itself (using SAPMod.LoadCases.ModHistLinear.SetCase) and able to change the number of time steps (using SAPMod.LoadCases.ModHistLinear.SetTimeStep), but when I try to actually change the parameters of the time history (such as input, load pattern, etc...) using SAPMod.LoadCases.ModHistLinear.SetLoads, it doesn't work. However, I can do it manually and get the information back using SAPMod.LoadCases.ModHistLinear.GetLoads, but then just trying to put it back into it doesn't work.

Please help if you have any hints!
 
Replies continue below

Recommended for you

Post your code and maybe I could help you.
I'm currently runing a lot of NLRHA's in Matlab.
SAP2000 is used for comparision purposes.
I've tried SetLoads with Matlab and it works fine.
I've tried SAP200 API with Excel VBA and Matlab.
 
I have the same problem as jsipple has. I have added a nonlinear load case for eccentric load using ret=SapModel.LoadCases.StaticNonlinear.SetCase('eccentric');

However when I am trying to add load to it by following syntax

ret=SapModel.LoadCases.StaticNonlinear.SetLoads('eccentric',NumberLoads,LoadType,LoadName,sf)

It executes and give me value ret=0( It means it should add this load) but when I check in SAP2000 I dont find it added. If somebody could help me I would really appreciate that.

Thank You
 
Hint:
- The arguments of .SetLoads method must be column vectors or column cells. I mean, like LoadType = {'Accel'; 'Accel'}; or SF = [1; 1];
 
But I'm in trouble too.
I can not set or get the non-linear data of an NLink property. Matlab return the next message.

??? No method 'GetMultiLinearPoints' with matching signature found for class 'Interface.EE75FBEB_FFC3_4A85_9857_8F76CDDA159B'.

 
Thanks for the tip Osquro but I still cant get it added in SAP2000(although it executes in MATLAB, I mean ret=0).This is my main code in MATLAB...I have defined a nonlinear dead load case and wanted to add load type as load pattern and load name as DEAD with sf=1

ret=SapModel.LoadCases.StaticNonlinear.SetCase('Dead');%This works
NumberLoads=0;
LoadType={'Load Pattern'};
LoadName={'DEAD'};
sf=[1;1];
[ret]=SapModel.LoadCases.StaticNonlinear.SetLoads('Dead',NumberLoads,LoadType,LoadName,sf);

Please if I am defining something wrong here,correct me. I would really appreciate, if you can run this code in your matlab to check whether its adding loads to this defined nonlinear dead load case in SAP2000.

@Osquro....I can help you regarding your nonlinear data of NLink property.I have added Nlink elements with nonlinear data points to the model I am working on right now. Just post your main syntax with input arguments that you are defining.

Thanks!!


 
newtonthegrat,

Try something like this:

LTYPE_DEAD = 1;
ret = SapModel.LoadPatterns.Add('LoadPattern1', LTYPE_DEAD);
ret = SapModel.LoadCases.StaticNonlinear.SetCase('LoadCase1');
NumberLoads = 1;
LoadType = {'Load'; 'Load'};
LoadName = {'LoadPattern1'; 'LoadPattern1'};
SF = [1; 1];
ret = SapModel.LoadCases.StaticNonlinear.SetLoads(...
'LoadCase1', NumberLoads, LoadType, LoadName, SF);

Trick:
The variables LoadType, LoadName, and SF are defined for two load patterns but the variable NumberLoads tells SAP assing just one of them.
 
newtonthegreat,

My code, just in case you can help me:

DOFi = 1; %U1
Kinematic = 1;
NLType = Kinematic;
NumberPoints = 7;
for i = 1:4
Name = ['L', num2str(i)];
qy1 = Structure.BRB_qy1(i);
qy2 = Structure.BRB_qy2(i);
vy1 = Structure.BRB_vy1(i);
vy2 = Structure.BRB_vy2(i);
force = [-qy2; -qy2; -qy1; 0; qy1; qy2; qy2];
displ = [-2*vy2; -vy2; -vy1; 0; vy1; vy2; 2*vy2];
%plot(displ,force)
ret = SapModel.PropLink.SetMultiLinearPoints(...
Name, DOFi, NumberPoints, force, displ, NLType);
if ret ~= 0;
disp('ERROR: MULTILINEAR FORCE-DEFORMATION DATA NOT SET');
end
end
 
Osquro,
Thank you do much for the reply. Now my code is working just fine.

Regarding your code I checked it with every other possibility. Your syntax looks fine to me. The only problem is that your input data:
force = [-qy2; -qy2; -qy1; 0; qy1; qy2; qy2];
displ = [-2*vy2; -vy2; -vy1; 0; vy1; vy2; 2*vy2];

By looking at your code I think that you are probably using multilinear plastic Nlink elements. I am rewriting your code simplifying it to my understanding and posting below...
First I defined two Nlink multilinearplastic elements L1 and L2, then writing your code by entering some numeric value in data points analogous to your inputs...
DOFi=1;
NumberPoints=7;
takeda=2;
NLType=takeda;% Took this to check that it assigns takeda or not

for i=1:2
Name=['L',num2str(i)]
f=zeros(7,1,'double');d=zeros(7,1,'double');
f(1)=-10; %Analogous to -qy2
d(1)=-20; %Analogous to -2*vy2

f(2)=-10; %Analogous to -qy2
d(2)=-10; %Analogous to -vy2

f(3)=-3 %Analogous to -qy1 ;
d(3)=-3; %Analogous to -vy1

f(4)=0 ; %Analogous to 0
d(4)=0; %Analogous to 0

f(5)=3; %Analogous to qy1
d(5)=3; %Analogous to vy1

f(6)=10 ; %Analogous to qy2
d(6)=10; %Analogous to vy2

f(7)=10; %Analogous to qy2
d(7)=20; %Analogous to 2*vy2

ret = SapModel.PropLink.SetMultiLinearPoints(.....Name, DOFi,NumberPoints, f, d,NLType);

end

This code on execution doesnt run or gives the error, as you are getting.
Now just on doing some little changes in above data inputs with everything remains same, it runs ...

f(1)=-10.0001; %Analogous to -qy2
d(1)=-20; %Analogous to -2*vy2

f(2)=-10; %Analogous to -qy2
d(2)=-10; %Analogous to -vy2

f(3)=-3 %Analogous to -qy1 ;
d(3)=-3; %Analogous to -vy1

f(4)=0 ; %Analogous to 0
d(4)=0; %Analogous to 0

f(5)=3; %Analogous to qy1
d(5)=3; %Analogous to vy1

f(6)=10 ; %Analogous to qy2
d(6)=10; %Analogous to vy2

f(7)=10.001; %Analogous to qy2
d(7)=20; %Analogous to 2vy2

Now it works and assign takeda NLType with above data points entered.

In conclusion it means that SAP takes data point in increasing order and Force-Displ relationship should be strictly increasing.
So in your case it was f(1)=-qy2 and f(2)=-qy2, which have same values on corresponding d(1) and d(2) values that was creating problem. Now if you just add some small number in your f(1) as in f(1)=-qy2-0.00001; and similarly to f(7)=qy2+0.0001 then it will work(like above inputs) because your function has become strictly increasing.

I hope my assessment is correct as I observed this by executing this code with every other possibility. I hope it should solve your problem. And if I am wrong then I would appreciate the feedback.

Thank You
 
newtonthegreat,

You're right, that's the problem.

Now the multilinear force-defomation data is like this:

qy1 = Structure.BRB_qy1(i);
qy2 = Structure.BRB_qy2(i);
qy3 = qy2 * (1 + 1e-10);

At the end of the day, SAP2000 can't handle as many decimal places as Matlab (16) and the NLink curve in the generated SAP2000 model is as expected to be.

Thanks a lot.
 
Osquro,
Thanks for the link above and I am glad to know that you got your problem resolved.
 
Errors like:

??? No method 'SetDampProportional' with matching signature found for class 'Interface.EE75FBEB_FFC3_4A85_9857_8F76CDDA159B'.

occurs when the method is called and some input arguments (that one may think are optional) are not provided.

For example, SapObject.SapModel.LoadCases.DirHistNonlinear.SetDampProportional
has 8 input arguments but only 4 of them are usefull according to the damping type selected. The other 4 arguments must be provided, no matter if they are ficticious.

In fact, according to the API help file, none of the 8 input arguments is Optional. In other words, if a input argument is not Optional, mus be provided (Obviously!!!).
 
Hello all, it seems like there are a bunch of solutions so I'll post the solution I used for my original problem.

It seems like the problem was the way that MATLAB is handling the single elements, the CSI tech support was able to help me troubleshoot this problem.

It seems like CSI added the Wiki link osquro posted to deal with this issue.

Working code:
clear all
close all
clc

% Link Sap2000 and matlab for passing one-dimensional arrays
feature('COM_SafeArraySingleDim', 1);

% Link Sap2000 and matlab for passing non-scalar arrays by reference
feature('COM_PassSafeArrayByRef', 1);

% Create Link Between Matlab and SAP
SAPObj = actxserver('SAP2000.SapObject');

% Start SAP
SAPObj.ApplicationStart;

% %Hide Application
% SAPObj.Hide;

% Create SAP Model
SAPMod = SAPObj.SapModel;

% Initialize Model
SAPMod.InitializeNewModel;

%Create model from template
SAPMod.File.New2DFrame('PortalFrame', 2, 144, 2, 288)

%Create TH function
SAPMod.Func.FuncTH.SetSine('TH-1', 1, 16, 4, 1.25)

%Create linear modal history load case
SAPMod.LoadCases.ModHistLinear.SetCase('LCASE1')

%Set Load Data
MyLoadType = {'Load'};
MyLoadName = {'DEAD'};
MyFunc = {'TH-1'};
MyCSys = {'Global'};
SF = zeros(2,1,'double');
SF(1) = 1.0;
TF = zeros(2,1,'double');
TF(1) = 1.0;
AT = zeros(2,1,'double');
AT(1) = 0.0;
Ang = zeros(2,1,'double');
Ang(1) = 0.0;
SAPMod.LoadCases.ModHistLinear.SetLoads('LCASE1', 1, MyLoadType, MyLoadName, MyFunc, SF, TF, AT, MyCSys, Ang)

%Close SAP
SAPObj.ApplicationExit(0);

%Release Link
SAPObj.release;
 
Osquru,
You are right about the input arguments that if its not an optional argument then you have to provide something.

bridgehealth,
Thanks for writing this code explicitly. It has become clear now.

From where can I get API help file ? I cant find that in my SAP2000.
And up till now I have been following command prompts from VBA but it will be helpful if I can have all these commands inside SAP2000.
 
Hello,
I am in trouble again. I want to assign solid surface springs at the bottom surface of the solid which I am modeling.However I am not able to execute this syntax and its giving me following error.

No method 'SetSpring' with matching signature found for class
'Interface.03DF9EC1_080E_4AB0_B982_4780C43458FF'

The details of the spring which I want to assign:
spring stiffness per unit area:10
simple spring resists: compression only
solid object face:5
spring tension direction:parallel to solid object local axis:3

Above details are just input values.I just want this syntax to run and assign the surface spring but its not happening. Can somebody help me or atleast hint me where I am going wrong.Frankly I cant understand the input arguments.Here is the syntax I have written.
For information the defined solid element can be modeled(using addbycoord) but error only comes in set spring command line which is giving above stated error.
%% clean workspace & command window
clear;
clc;
%% pass data to Sap2000 as one-dimensional arrays
feature('COM_SafeArraySingleDim', 1);

%% pass non-scalar arrays to Sap2000 API by reference
feature('COM_PassSafeArrayByRef', 1);

%% create Sap2000 object
SapObject = actxserver('sap2000.SapObject');

%% start Sap2000 application
SapObject.ApplicationStart;

%% create SapModel object
SapModel = SapObject.SapModel;

%% initialize model
ret = SapModel.InitializeNewModel;

%% create new blank model
ret = SapModel.File.NewBlank;

%add solid object by coordinates
Name='';
x=zeros(8,1); y= zeros(8,1); z= zeros(8,1)
x(1) = 1.5; y(1) = 1.5; z(1) = 0;
x(2) = 2.0; y(2) = 1.5; z(2) = 0;
x(3) = 1.5; y(3) = 2.0; z(3) = 0;
x(4) = 2.0; y(4) = 2.0; z(4) = 0;
x(5) = 1.5; y(5) = 1.5; z(5) = 0.5;
x(6) = 2.0; y(6) = 1.5; z(6) =0.5 ;
x(7) = 1.5; y(7) = 2.0; z(7) = 0.5;
x(8) = 2.0; y(8) = 2.0; z(8) = 0.5;
[ret,Name] = SapModel.SolidObj.AddByCoord(x, y, z, Name)

Mytype=zeros(2,1,'double');
Mytype(1)=2;
s=zeros(2,1,'double');
s(1)=10;
sst=zeros(2,1,'double');
sst=1;
face=zeros(2,1,'double');
face(1)=5;
sl=zeros(2,1,'double');
sl(1)=1;
dir=zeros(2,1,'double');
dir(1)=3;
vec=[1;0;0];
ang=zeros(2,1,'double');
ang(1)=0;

ret=SapModel.SolidObj.SetSpring('Name',Mytype,s,sst,'comp',face,sl,dir,false,vec,ang,true);

ret = SapModel.View.RefreshView(0, false());

I would appreciate the help.
Thank You
 
Osquru,
Thanks for trying. I am still trying, hoping that it will work eventually one day.

 
Hello everyone,
I am defining a body constraint in my model with all Degree of freedom constrained. I am facing a problem in getting this body constraint. When I run the following syntax:

Value=zeros(6,1)
Value(1) = true;
Value(2) = true;
Value(3) = true;
Value(4) = true;
Value(5) = true;
Value(6) = true;
ret = SapModel.ConstraintDef.SetBody('Body1', Value)

It defines a body constraint Body1 in SAP2000 but it shows that only Rx degree of freedom is constraint and others are free. However if you see my code above then I am assigning constrained at every degree of freedom(Ux,Uy,Uz,Rx,Ry,Rz).

When I ran this syntax in VBA (excel format) it ran correctly assigning all 6 degree of freedom as constrained but not getting in MATLAB.

I would appreciate if somebody can point out my mistake or give a hint that why its not happening through matlab.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor