-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainRect.m
62 lines (60 loc) · 1.75 KB
/
MainRect.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
clear all
close all
clc
%Problem Data
LengthX=1;
LengthY=1;
Nx=50;
Ny=50;
Ne=Nx*Ny;
Nn=(Nx+1)*(Ny+1);
%Length of the elements in x and y-directions
Lx=LengthX/Nx;
Ly=LengthY/Ny;
%Evaluating the stiffness matrix
T1=CalcTRect(Lx,Ly);
%KK=CalcRect(T1,Lx,Ly);
KK=[2*(Lx*Lx+Ly*Ly) , Lx*Lx-2*Ly*Ly,- Lx*Lx-Ly*Ly ,-2*Lx*Lx+Ly*Ly ; ...
Lx*Lx-2*Ly*Ly, 2*(Lx*Lx+Ly*Ly),-2*Lx*Lx+Ly*Ly ,- Lx*Lx-Ly*Ly ; ...
- Lx*Lx-Ly*Ly ,-2*Lx*Lx+Ly*Ly , 2*(Lx*Lx+Ly*Ly), Lx*Lx-2*Ly*Ly; ...
-2*Lx*Lx+Ly*Ly ,- Lx*Lx-Ly*Ly , Lx*Lx-2*Ly*Ly, 2*(Lx*Lx+Ly*Ly)]/Lx/Ly/6;
[Nodes,Elements,BCs]=GenerateMesh(Nx,Ny,Lx,Ly);
%Creating Empty Global matrix
KGlobal=zeros(Nn,Nn);
%Looping on all elements
for ii=1:Ne
%Identifying the current element nodes and data
Node1=Elements(ii,1);
Node2=Elements(ii,2);
Node3=Elements(ii,3);
Node4=Elements(ii,4);
UV=[Node1,Node2,Node3,Node4];
%Assembling the global stiffness matrix
KGlobal(UV,UV)=KGlobal(UV,UV)+KK;
end
BCsC=[1:Nn]'; %Complementary boundary conditions
BCsC(BCs)=[];
%The matrix that will be multiplied by the boundary values
KAux=KGlobal(:,BCs);
KAux(BCs,:)=[];
%Getting reduced stiffness and force vector
% by applying boundary conditions
KReduced=KGlobal;
KReduced(BCs,:)=[];
KReduced(:,BCs)=[];
%The right-hand-side vector
FReduced=-KAux*Nodes(BCs,3);
%Solving for the function values
Displacements=KReduced\FReduced;
%Saving the solution values in the Nodes' registry
Nodes(BCsC,3)=Displacements;
for ii=1:Nx+1
Xx=(ii-1)*Lx; %x-coordinate
for jj=1:Ny+1
Yy=(jj-1)*Ly; %y-coordinate
NN=(jj-1)*(Nx+1) + ii; %node number
aa(ii,jj)=Nodes(NN,3); %saving the data
endfor
endfor
contour(aa)
grid