Include Page | ||||
---|---|---|---|---|
|
Panel |
---|
Overview |
...
Include Page | ||||
---|---|---|---|---|
|
Creating a Structure for Two Elements
Extend to two elements
Let's now consider the case where we would like to create a structure to store the strain and stress values for two triangular elements.
...
We'll create the above structure by modifying the code from Step 1. Recall that the statements for creating the structure were
{{ Wiki Markup eps_val
=
\ [2
7
4
\];
%Nonsense
values
}}
{{R
=
2*eye(3);
%Dummy
R
}}
{{sig_val
=
(R*eps_val')';
%Derived
nonsense
}}
{{sigepsstruct
=
struct('eps',
eps_val,
...
}}
{{'sig',
sig_val);
}}
We have to create a second row for the eps and sig fields, corresponding to values for the second element. We can do this by looping over the elements, adding one row at a time.
...
We will keep the R matrix calculation out of the loop (since it doesn't need to be recalculated each time anew). This leaves us with the eps_val, sig_val
and sigepsstruct
statements inside the loop. In a real calculation, the strain values for each element , or equivalently, the rows of the eps field, are going to be different. To make the rows of the epsfield different, we'll blithely multiply each row by the loop counter. This is again done to explain programming concepts; it makes no sense from a solid mechanics sense.unmigrated-wiki-markup
{{numels
=
2;%Total
number
of
elements
}}
{{R
=
2*eye(3);
%Dummy
R
}}
{{for
iele
=
1:numels
}}
{{ eps eps_val
=
iele*
\[2
7
4
\];
%Nonsense
values}}
{{ sigvalues
sig_val
=
(R*eps_val')';
%Derived
nonsense
}}
{{end}}
end
Another thing: eps_val
and sig_val
above are row vectors. But the epsfield is a matrix. We'll create this matrix as follows: after each row of the matrix is calculated, we will "push" it into the appropriate row of the matrix. Let's call this matrix geps_val, the g prefix standing for global. The following assignment will push the current eps_val vector into the second row of the matrix.
...
%Extract data from structure
myeps = sigepsstruct.eps
sigxy2 = sigepsstruct.sig(2,3)
fieldnames(sigepsstruct)
Go to Step 3: Structure of handles