# Model Implementation

The original truss structure used in this example is available at [1]. The Young's moduli of the material of the beams as well as the direction of the load, applied to the two top nodes of the structure, are taken as random parameters.

## Input

### Young's moduli

25 random variables are defined for the Young's moduli of the bars. It is possible to create one random variable and then use the copy-paste functionality to create all the necessary random variables. They are Normally distributed with mean of 1e7 Pa and standard deviation of 500000 Pa. At the end, the GUI should show all the random variables as shown in the figure, named E_1 to E_25.

Additionally, the random angle of the force which module is fixed to 500 N is defined. The load is inserted in the structure as three components along the three axis x, y and z. Thus, the deviation of the force direction is identified by the two angles $\theta$ and $\phi$ for the deviation from the z direction and for the in-plane direction respectively. $\theta$ is introduced as a uniform random variable between -5 and 5 degrees, while $\phi$ varies between 0 and 360 degrees, since the force has no preferred in-plane direction.

Then, 3 Functions object are used to compute the force components in the three directions. In this functions the angles are converted from degrees to radians.

### Beams sections

The beam sections of the antenna are the design variables of the optimization. In order to perform a robust design, these must be used at a first step as parameters of the model. in a second step, a mapping between the design variables and the model parameter will be defined. Thus, it is necessary to introduce the beam sections as Parameter objects, where the value of the parameter corresponds to the nominal value of the sections. The 25 beams are grouped into 6 beam sections, listed in the following table.

Beam group Section Nominal value [m^2]
A1 0.4
A2 0.1
A3 3.4
A4 1.3
A5 0.9
A6 1.0

Finally, all the random variables must be added in a random variable set.

## Evaluator

A Matlab script is used to determine the maximum stress and the volume of the beams.

### Matlab Script (Structure I/O)

Since a structure I/O is used, the order of the input is not important. All the input quantities defined in the previous section can be selected and added to the Mio. Moreover, two output quantities, named "beamVolumes" and "maxDisp" should be defined.

The following Matlab script is used to create and solve the truss structure. The input quantities are accessed as fieldnames of the input structure Tinput (e.g., Tinput(i).E_1 contains the values of the Young's modulus of the first beam, E_1, for the i-th sample). The output quantities must be put in the structure Toutput.

% =========================================================================
% COSSAN-X
% University of Innsbruck, Austria, EU
% =========================================================================

% Cycle over realizations (samples)
for isample= 1:length(Tinput)
%% construct the antenna structure from the sampled values. D is a
% structure containing:
% - nodal coordinate (D.Coord)
% - nodal connectivity (D.Con)
% - boundary conditions (D.Re)
% - beams Young's moduli (D.E)
% - beams sections (D.A)
%%  Definition of the 25 beams truss structure
% Get structural parameter from input struct sample
% E - random variables (a for-loop with eval is use here for brevity)
for ibeam=1:25
eval(['E' num2str(ibeam) '= Tinput(isample).E_' num2str(ibeam) ';']);
end
% Fx, Fy, Fz - function of the random variables theta and phi
Fx = Tinput(isample).Fx;
Fy = Tinput(isample).Fy;
Fz = Tinput(isample).Fz;
% Ai (sections of the beams) - parameter. The values of these parameters
% are set from the outer loop design variables
A1 = Tinput(isample).A1;
A2 = Tinput(isample).A2;
A3 = Tinput(isample).A3;
A4 = Tinput(isample).A4;
A5 = Tinput(isample).A5;
A6 = Tinput(isample).A6;

%% Construct the struct of the truss.
% Truss structure definition and solution based on http://www.mathworks.com/matlabcentral/fileexchange/14313-truss-analysis
% Nodal Coordinates
Coord=[-37.5 0 200;37.5 0 200;-37.5 37.5 100;37.5 37.5 100;37.5 -37.5 100; -37.5 -37.5 100;-100 100 0;100 100 0;100 -100 0;-100 -100 0];

%  Connectivity
Con=[1 2;1 4;2 3;1 5;2 6;2 4;2 5;1 3;1 6;3 6;4 5;3 4;5 6; 3 10;6 7;4 9;5 8;4 7;3 8;5 10;6 9;6 10;3 7;4 8;5 9];

% Definition of Degree of freedom (free=0 &  fixed=1).
% The nodes 7 to 10 are fixed in all the three degrees of freedom
Re=zeros(size(Coord));Re(7:10,:)=[1 1 1;1 1 1;1 1 1;1 1 1];

% Definition of Nodal loads. The Loads are applied at the two top nodes.

% Definition of Modulus of Elasticity
E = [E1 E2 E3 E4 E5 E6 E7 E8 E9 E10 E11 E12 E13 ...
E14 E15 E16 E17 E18 E19 E20 E21 E22 E23 E24 E25];

% Definition of beams sections
A=[A1 A2 A2 A2 A2 A3 A3 A3 A3 A1 A1 A4 A4 A5 A5 A5 A5 A6 A6 A6 A6 A3 A3 A3 A3];

% Convert to structure
%% compute the nodal displacements in the 3 degrees of freedom
%   Compute the stresses, nodal diplacements and reaction forces given the
%   struct describing the truss.
%   The stiffness matrix is assembled and used to computed the
%   aforementioned quantities.
w=size(D.Re);S=zeros(3*w(2));U=1-D.Re;f=find(U);
for i=1:size(D.Con,2)
H=D.Con(:,i);C=D.Coord(:,H(2))-D.Coord(:,H(1));Le=norm(C);
T=C/Le;s=T*T';G=D.E(i)*D.A(i)/Le;Tj(:,i)=G*T;
e=[3*H(1)-2:3*H(1),3*H(2)-2:3*H(2)];S(e,e)=S(e,e)+G*[s -s;-s s];
end
R=reshape(S*U(:),w);R(f)=0;
%% compute the norms of the nodal displacements
normU = zeros(1,size(U,2));
for inode = 1:size(U,2)
normU(inode) = norm(U(:,inode));
end
% assign the maximum displacement to the first output
Toutput(isample).maxDisp = max(normU);
%% compute the beam length
%   Compute length of beams given the struct describing the truss.
beamLengths=zeros(1,size(D.Con,2));
for i=1:size(D.Con,2)
H=D.Con(:,i);C=D.Coord(:,H(2))-D.Coord(:,H(1));
beamLengths(i)=norm(C);
end
%% compute the beam volumes and assign them to the sencond output
Toutput(isample).beamVolumes = beamLengths' .* D.A;
end


## Model

Finally, a model used in the inner loop of the robust design optimization can be created. This is easily done by adding the evaluator previously created (XmioA) by pressing the + sign.