Lampiran 1 : Kode MATLAB untuk Data Input
% INPUT DATA FORMAT
% Title of the problem:
Project_Title='Test for Linear Elastic Plane Stress Case Using Q4-elements';
% Control Data
% Ndofn: Number of degrees of freedom per nodal point
% Ngaus: The order of Gaussian numerical integration rule to be employed
% Ntype: Problem type parameter 1-Plane stress, 2-Plane strain Control_cards=[ 3 3 1 1 ];
% Nodal Coordinate
% Ipoin: Nodal point number
% Coord: Coordinate of the node Node_cards=[ % m
1 1 1 2 -1 1 3 -1 -1 4 1 -1];
% Element Connectivity
% Numel: Element number
% Matno: Material property number
% Lnods: Element node numbers listed per each element Element_cards=[
1 1 1 2 3 4];
% Nodal Boundary Condition
% Nofix: Restrained node number
% Ifpre: Condition of restraint
% Presc: Prescribed value of nodal displacements Restrained_cards=[
2 1 0 0 0 0 0 3 1 1 0 0 0 0];
% Material Properties
% Numat: Material identification number
% Props: Elastic modulus, Poisson's ratio, material thickness Material_cards=[ % KN/m2
1 210e06 0.3 0.1 ];
Lampiran 1 : Kode MATLAB untuk Data Input (sambungan)
% Nodal Force
% Lodpt: Node number
% Point: Applied nodal point forces Applied_load_cards=[ % KN
1 4 0 0 4 4 0 0];
Lampiran 2 : Kode MATLAB untuk Mengolah Data Input
function [Project_Title, Ndofn, NgausK , NgausP, Ntype , Npoin, Nelem, Nnode, Nsvab, ...
Lnods, Coord, Matno, Props, Ifpre, Fixed, Point] = ...
Echo_data (Input_file_name)
% Giving general information of the input data file and feeding
% the necessary input for subsequent calculation processes
%
% Input
% Input_file_name
%
% Output
% All of variables needed for subsequent calculation processes
eval(Input_file_name);
Project_Title
%
Ndofn= Control_cards(1,1);
fprintf('Number of degrees of freedom per nodal point: %d \n', Ndofn);
NgausK= Control_cards(1,2);
fprintf('The order of Gaussian numerical integration rule for K matrix: %d \n', NgausK);
NgausP= Control_cards(1,3);
fprintf('The order of Gaussian numerical integration rule for P matrix: %d \n', NgausP);
Ntype= Control_cards(1,4);
if Ntype==1
fprintf('Linear-elastic plane stress problem. \n') elseif Ntype==2
fprintf('Linear-elastic plane strain problem. \n') else
error('Wrong problem type parameter! \n');
end
%
Npoin=size(Node_cards,1); Ndime=size(Node_cards,2)-1;
fprintf('\nTotal number of nodal points in the structure: %d \n', Npoin);
fprintf('Number of coordinate components required to ');
fprintf('define each nodal points: %d \n', Ndime);
%
Nelem=size(Element_cards,1); Nnode=size(Element_cards,2)-2;
fprintf('\nTotal number of elements in the structure: %d \n', Nelem);
fprintf('Number of nodes per element: %d \n', Nnode);
%
Nmats=size(Material_cards,1);
fprintf('\nTotal number of different materials in the structure: %d \n', Nmats)
Lampiran 2 : Kode MATLAB untuk Mengolah Data Input (sambungan)
%
Nsvab=Npoin*Ndofn;
fprintf('\nNumber of global structural variables (DOF): %d \n', Nsvab)
%
Matno=Element_cards(:,2);
Lnods=Element_cards;
Lnods(:,[1 2])=[];
%
Coord=Node_cards;
Coord(:,1)=[];
%
Props=Material_cards(:,2:end);
%
Ifpre1=Restrained_cards(:,1: (1+Ndofn));
Fixed1=Restrained_cards(:, [ 1 (Ndofn+2):end ] );
Ifpre= Node2eqns(Ifpre1, Nsvab);
Fixed= Node2eqns(Fixed1, Nsvab);
%
Point= Node2eqns(Applied_load_cards, Nsvab);
Lampiran 3 : Kode MATLAB untuk Matriks Kekakuan untuk D-Type
function Estiff = StifpsQ4( Coord , Lnods , Ielem , Props , NgausK , NgausP , Ndofn , Matno , Ntype )
%Stifness Matriks for Membran Elements using D-Type
h = Props(Matno(Ielem),3);
Elcod=Coord(Lnods(Ielem,:),:);
[l,n] = lnmatx( Elcod );
%
[PosgpK, WeigpK] = GaussqK (NgausK);
K=zeros(12,12);
for Igaus = 1:NgausK for Jgaus = 1: NgausK
r=PosgpK(Igaus); s=PosgpK(Jgaus);
W1=WeigpK(Igaus); W2=WeigpK(Jgaus);
[Deriv, Shape , SShape, SDeriv, NB9] = SfrQ4(r,s);
[Djacb, Xjabi , Cartd] = Jacob(Ielem, Deriv, Elcod);
B = Bmatps(Cartd, Ndofn);
G = Gmatps(Xjabi , l , n , SDeriv);
Dmatx = Modps(Matno, Props, Ntype, Ielem);
K = K+h*W1*W2*[B G]'*Dmatx*[B G]*Djacb;
end end
%
Young = Props(Matno(Ielem),1);
Poiss = Props (Matno(Ielem),2);
[PosgpP, WeigpP] = GaussqP (NgausP);
P=zeros(12,12);
for Igaus = 1:NgausP for Jgaus = 1: NgausP
r=PosgpP(Igaus); s=PosgpP(Jgaus);
W1=WeigpP(Igaus); W2=WeigpP(Jgaus);
[Deriv, Shape , SShape, SDeriv, NB9] = SfrQ4(r,s);
[Djacb, Xjabi , Cartd] = Jacob(Ielem, Deriv, Elcod);
[b,g] = bgmatps( Cartd , Xjabi , l , n ,Shape , SDeriv );
gamma = Young/(2*(1+Poiss));
P = P+h*W1*W2*gamma*[b ; g]*[b ; g]'*Djacb;
end end
Estiff = K+P;
Lampiran 4 : Kode MATLAB untuk Matriks Kekakuan untuk M-Type
function Estiff = StifpsQ4( Coord , Lnods , Ielem , Props , NgausK , Ndofn , Matno , Ntype )
%Stiffness Matrix for Membran Elements using M-Type
Elcod=Coord(Lnods(Ielem,:),:);
E = Props(1);
v = Props(2);
h =Props(3);
[l,n] = lnmatx( Elcod );
%
[PosgpK, WeigpK] = GaussqK (NgausK);
K=zeros(12,12);
for Igaus = 1:NgausK for Jgaus = 1: NgausK
r=PosgpK(Igaus); s=PosgpK(Jgaus);
W1=WeigpK(Igaus); W2=WeigpK(Jgaus);
[Deriv, Shape , SShape, SDeriv, NB9] = SfrQ4(r,s);
[Djacb, Xjabi , Cartd] = Jacob(Ielem, Deriv, Elcod);
B = Bmatps(Cartd, Ndofn);
G = Gmatps(Xjabi , l , n , SDeriv);
%
Dmatx = Modps(Matno, Props, Ntype, Ielem);
K = K+h*W1*W2*[B G]'*Dmatx*[B G]*Djacb;
end end
%
[PosgpK, WeigpK] = GaussqK (NgausK);
h_e=zeros(12,1);
V = 0;
for Igaus = 1:NgausK for Jgaus = 1: NgausK
r=PosgpK(Igaus); s=PosgpK(Jgaus);
W1=WeigpK(Igaus); W2=WeigpK(Jgaus);
[Deriv, Shape , SShape, SDeriv, NB9] = SfrQ4(r,s);
[Djacb, Xjabi , Cartd] = Jacob(Ielem, Deriv, Elcod);
[b,g] = bgmatps( Cartd , Xjabi , l , n ,Shape , SDeriv );
h_e = h_e+h*W1*W2*[b ; g]*Djacb;
V = V + h*W1*W2*Djacb;
end end
gamma = E/(2*(1+v));
Estiff = K+gamma/V*h_e*h_e';
Lampiran 5 : Kode MATLAB untuk Tegangan dan Regangan
function Strsg = Stregps (Ielem, Lnods, Nnode, Ndofn, Xdisp, Coord, Props , Matno , Ntype)
% Calculating the stresses at the Gauss points for an element
%
% Input
% Ielem: Current element number
% Lnods: Element node numbers listed per each element
% Coord: Coordinate of the node
%
% Output
% Strsg: Stress components at element Gauss points
% Strsp: Principal stress values=(S1,S2,alpha)
% Identify the displacements of the element nodal points
% ---> Eldis Ncols=[];
for Inode=1:Nnode
Nodei=Lnods(Ielem,Inode);
for Idofn=1:Ndofn
Nrows(Idofn,:)=(Nodei-1)*Ndofn + Idofn;
end
Ncols=[Ncols; Nrows];
end
Eldis=Xdisp(Ncols,:);
Eldis12 = [];
Eldis3 = [];
for I = 1:Nnode
Eldis12((2*I-1):2*I,:) = Eldis((3*I-2):(3*I-1),:);
Eldis3(I,:) = Eldis(3*I,:);
end
% The elasticity matrix
Dmatx = Modps(Matno, Props, Ntype, Ielem);
% Elcod: Local array of nodal Cartesian coordinates of
% the element currently under consideration Elcod=Coord(Lnods(Ielem,:),:);
Ngaus = 2;
[Posgp, Weigp] = Gaussq (Ngaus);
Strsg=[];
for Igaus = 1:Ngaus for Jgaus = 1: Ngaus
Lampiran 5 : Kode MATLAB untuk Tegangan dan Regangan (sambungan)
r=Posgp(Igaus); s=Posgp(Jgaus);
[Deriv, Shape , SShape, SDeriv, NB9] = SfrQ4(r,s);
[Djacb, Xjabi, Cartd] = Jacob(Ielem, Deriv, Elcod);
[l,n] = lnmatx( Elcod );
B = Bmatps(Cartd, Ndofn);
G = Gmatps(Xjabi , l , n , SDeriv);
IStrsg = Dmatx*(B*Eldis12+G*Eldis3);
Strsg = [Strsg IStrsg];
end end
clear Istrsg;
Lampiran 6 : Kode MATLAB untuk Proses Utama dari Program
clear ;
%
% Input
%
Input_file_name='Input_NAFEMS2'; %input('Enter the input data file (excluding extension): ','s');
[Project_Title, Ndofn, NgausK, NgausP, Ntype , Npoin, Nelem, Nnode, Nsvab, Lnods, Coord, ...
Matno, Props, Ifpre, Fixed, Point] = Echo_data (Input_file_name);
%
Astiff= sparse(Nsvab,Nsvab);
Rload= zeros(Ndofn*Nnode,1);
for Ielem=1:Nelem IMatno=Matno(Ielem);
Estiff = StifpsQ4( Coord , Lnods , Ielem , Props , NgausK , ...
Ndofn , Matno , Ntype );
Mod_Estiff = Estiffps( Estiff );
Astiff= Astiff + Element2structure (Ielem, Mod_Estiff, Rload, ...
Lnods, Nsvab, Nnode, Ndofn);
end
clear Rload Ielem IMatno;
%
% Applying nodal point forces
%
Gload= Point; clear Point
%
% Imposing Displacement Boundary Conditions
%
[Mod_Astiff, Mod_Gload] = ...
Modify (Astiff, Gload, Nsvab, Ifpre, Fixed);
%
% The solution of equations
%
% Nonzero_Ifpre : Equation indices of fixed dofs or
% prescribed displacements
Nonzero_Ifpre = Nonzero_index (Ifpre, Fixed);
Xdisp = Solution (Mod_Astiff, Mod_Gload, Fixed, Nonzero_Ifpre);
% Scale=100;
% Plot_Deform( Project_Title, Lnods, Coord, Nelem, Npoin, ...
% Xdisp, Ndofn, Scale);
%
% Reactions
Lampiran 6 : Kode MATLAB untuk Proses Utama dari Program (sambungan)
%
React= Reaction (Astiff, Gload, Xdisp, Ndofn, Nonzero_Ifpre)
%
% Stresses
%
%Ngaus=1;
delete Stress.txt Strep.txt Svm.txt
fid1=fopen('Stress.txt','at'); fid2=fopen('Strep.txt','at');
fid3=fopen('Svm.txt','at');
Stress=zeros(Nnode*Nelem,3);
for Ielem=1:Nelem IMatno=Matno(Ielem);
Strsg = ... % Stress at Gauss Point
Stregps (Ielem, Lnods, Nnode, Ndofn, Xdisp, Coord, Props , Matno , Ntype);
%Strsp = Strepps (Strsg)
% Extrapolation to nodal points Strsex=[];
for Xi=-1:2:1 for Etha=-1:2:1
Strsex=[ Strsex Extrag2(Xi,Etha,Strsg)' ];
end end
Strsex=Strsex(:,[1 3 4 2]);
Stress( (Nnode*Ielem-3):(Nnode*Ielem), : )= Strsex';
Strsp = Strepps (Strsex);
Strsvm = Strevm (Strsex, Props(1,2));
fprintf(fid1,'%e %e %e\n',Strsex); fprintf(fid1,'\n');
fprintf(fid2,'%e %e %e\n',Strsp); fprintf(fid2,'\n');
fprintf(fid3,'%e %e %e %e\n',Strsvm);
end
fclose(fid1); fclose(fid2); fclose(fid3);
clear Ielem Imatno;
tic;
toc;
%
% Strain Energy
% SE=0;
for Ielem=1:Nelem IMatno=Matno(Ielem);
Estiff = StifpsQ4( Coord , Lnods , Ielem , Props , NgausK , ...
Lampiran 6 : Kode MATLAB untuk Proses Utama dari Program (sambungan)
Ndofn , Matno , Ntype );
Mod_Estiff = Estiffps( Estiff );
Eldis= Edisps( Ielem, Lnods, Nnode, Ndofn, Xdisp);
SE= SE + 0.5* Eldis' * Mod_Estiff* Eldis;
end
% SE-0.5*Xdisp'*Astiff*Xdisp
%
% Plotting
%
Ask_G='y';
while Ask_G == 'y' disp('Plotting option:')
disp('1. Undeformed shape of the structure') disp('2. Deformed shape of the structure') disp('3. Stress contours')
disp('4. Principal stress contours')
disp('5. Effective von Mises stress contours') disp('6. Exit')
Plot_case=input('Which one do you want to plot? ');
fprintf('\n\n')
for icase=1:size(Plot_case,2) switch Plot_case(1,icase) case 1
Plot_Undeform (Project_Title, Lnods, Coord, Nelem, Npoin);
case 2
Scale=input('Scale for the deformed plot (enter 0 for autoscale): ') Plot_Deform( Project_Title, Lnods, Coord, Nelem, Npoin, ...
Xdisp, Ndofn, Scale);
case 3
Plot_Stress (Lnods, Coord, Nelem, 'Stress.txt');
case 4
Plot_Strep (Lnods, Coord, Nelem, 'Strep.txt');
case 5
Plot_Strevm (Lnods, Coord, Nelem, 'Svm.txt') otherwise
Ask_G='n';
end end end
disp('Congratulations! The project has been completed.') disp('Check the results carefully!!')