% Material Properties
% Material Properties
% nodal coordinates
NX=[0 0;0 0.2540;0.5080 0.2540;0.5080 0];
% connectivity
C=[1 3 2;1 4 3];
% applied force data; each row node, dof, force value
forces=[3 1 22226;4 1 22226];
% displacement bc data; each row node, fixed bc type, value
dispbc =[1 1 0.0;1 2 0.0;2 1 0.0;2 2 0.0];
% analysis parameters
nelem=size(C,1); %no of elements
nnod=size(NX,1); %no of nodes
ndof=2; % dof/node
% D matrix
function D = elemstf(Ym, Pr, planeStress)
% Check if plane stress is specified as '1'
if planeStress == 1
% Constitutive matrix D for plane stress condition
D = (Ym / (1 - Pr^2)) * [1, Pr, 0;
Pr, 1, 0;
0, 0, (1 - Pr) / 2];
else
error('Only plane stress condition is supported. Set planeStress to 1.');
end
end
% initialisation
% global stiffness
%K = zeros();
% global force
%F = zeros(,1);
%freedof=zeros(,1);
K = zeros(nnod * ndof); % Global stiffness matrix
F = zeros(nnod * ndof, 1); % Global force vector
freedof = ones(nnod * ndof, 1); % Free DOF indicator
% Initiating global force vector
% form global stiffness, loop over all elements
for ielem = 1:nelem
conn=C(ielem, :); %get the connectivity for ielem
n1=conn(1);n2=conn(2);n3=conn(3);
%xe=; % get the nodal x coordinates for ielem
%ye=; % get the nodal y coordinates for ielem
xe = NX(conn, 1); % x-coordinates
ye = NX(conn, 2); % y-coordinates
% dest=; % destination matrixfor ielem
D=elemstf(Ym,Pr,1);
[Ke, sig] = stiffT3(xe, ye, D, th);
dest = [(n1-1)*ndof+1, (n1-1)*ndof+2, (n2-1)*ndof+1, (n2-1)*ndof+2, (n3-
1)*ndof+1, (n3-1)*ndof+2];
K(dest, dest) = K(dest, dest) + Ke;
% D matrix for plane stress
%Ke=stiffT3(); %function to create local stiffness matrix for T3 element
% assemble into K
Ke
if ielem == 1
Ke1=Ke;
end
if ielem == 2
Ke2=Ke;
end
end
Kg=K;
K
tempKg=K;
% there are only nodal forces in this problem
% form rhs force vector
%F=(0 0 0 0 -6.89e9*0.127 0 -6.89e9*0.127 0);
% Applying B.C.
%freedof() = ;
for i = 1:size(dispbc, 1)
node = dispbc(i, 1);
dof = dispbc(i, 2);
globalDof = (node - 1) * ndof + dof;
Kg(globalDof, :) = 0; % Zero out the row
Kg(:, globalDof) = 0; % Zero out the column
Kg(globalDof, globalDof) = 1; % Set diagonal to 1
F(globalDof) = dispbc(i, 3); % Set displacement value
end
Kg
% modify rhs for disp boundary condition
U=Kg\F;
% solve for U
U
Kg=tempKg;
% post processing
for ielem=1:nelem
conn=C(ielem, :);; %get the connectivity for ielem
n1=conn(1);n2=conn(2);n3=conn(3);
xe = NX(conn, 1); % x-coordinates
ye = NX(conn, 2); % y-coordinates