0% found this document useful (0 votes)
66 views

New Main

The document describes implementing a 1D finite element analysis using isoparametric formulation with linear, quadratic, and cubic elements. It defines material properties and geometry, generates the mesh, computes the system stiffness matrix and applied loads, applies boundary conditions, and solves for displacements. It then outputs displacement and stress results, plotting the finite element solution alongside exact solutions. Key aspects covered include shape functions, natural derivatives, Gauss quadrature, and implementing the isoparametric approach for different element types.

Uploaded by

楊亞衡
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

New Main

The document describes implementing a 1D finite element analysis using isoparametric formulation with linear, quadratic, and cubic elements. It defines material properties and geometry, generates the mesh, computes the system stiffness matrix and applied loads, applies boundary conditions, and solves for displacements. It then outputs displacement and stress results, plotting the finite element solution alongside exact solutions. Key aspects covered include shape functions, natural derivatives, Gauss quadrature, and implementing the isoparametric approach for different element types.

Uploaded by

楊亞衡
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

New main

% 1D ADVANCED Using Isoparametric Formulation Implementation.


% (1) linear v.s. quadratic v.s. cubic element
% (2) force applied between nodes
clear
clc
% E: modulus of elasticity
% A: area of cross section
% L: length of bar
E=300e6; L = [4]; A = [8];
% numberElements: number of elements
numberElements = 1;
% nne = 2; % L element
% nne = 3; % Q element
nne = 4; % C element
[numberNodes,nodeCoordinates,elementNodes,elementLength]...
= mesh1D(2,6,numberElements,nne);
%-----------------------------------------------------------------------
% for structure:
% displacements: displacement vector
% force : force vector
% stiffness: stiffness matrix
force=zeros(numberNodes,1);
stiffness=zeros(numberNodes,numberNodes);
% applied load
% b: uniform load
b = @(x) 3.*x^2;
% impose displacements
GDof=numberNodes;
displacements=zeros(GDof,1);
% ---------------------------------------------------------------------
% computation of the system stiffness matrix for linear area
k = cell(numberElements,1);
for e=1:numberElements
% elementDof: element degrees of freedom (Dof)
xc = (nodeCoordinates(elementNodes(e,end)) + nodeCoordinates(elementNodes(e,1)))/2;
elementDof=elementNodes(e,:);
ngp=3;
[w,xi]=gauss1d(ngp);
detJacobian=L(e)/2;
invJacobian=1/detJacobian;
for n = 1:ngp
% Gauss point substituting into ksi
x = xc + detJacobian*xi(n);
% [shape,naturalDerivatives]=shapeFunctionL2(xi(n)); % L element
% [shape,naturalDerivatives]=shapeFunctionL3(xi(n)); % Q element
% [shape,naturalDerivatives]=shapeFunctionL4(xi(n)); % C element
[shape,naturalDerivatives]=shapeFunctionLx(xi(n),nne);
B=naturalDerivatives*invJacobian;
stiffness(elementDof,elementDof)...
= stiffness(elementDof,elementDof)+ B'*E*A(e)*B*detJacobian*w(n);
force(elementDof)...
= force(elementDof) + b(x)*shape'* detJacobian *w(n);
end
ksi = (4 - xc)/detJacobian;
[shape,~]=shapeFunctionLx(ksi,nne);
force(elementDof) = force(elementDof) + shape'*8;
k{e} = stiffness(elementDof,elementDof);
end
% ----------------------------------------------------------------------
% boundary conditions and solution
% prescribed dofs
%¡@prescribedDof=[3]; % L element
% prescribedDof=[5]; % Q element
prescribedDof=[1]; % C element
% solution
displacements=solution(displacements,GDof,prescribedDof,stiffness,force);
% output displacements/reactions
outputDisplacementsReactions(displacements,stiffness, ...
numberNodes,prescribedDof,force,elementNodes,k,nne);
% ----------------------------------------------------------------------
% axial stress
fprintf('Axial stress\n');
fprintf('%9s%5s %16s\n','element','ip','axial stress');
axial_Stress_global = [];
for e=1:numberElements
% elementDof: element degrees of freedom (Dof)
elementDof=elementNodes(e,:);
detJacobian=L(e)/2;
invJacobian=1/detJacobian;
axial_stress = zeros(nne,1);
% n = [-1 1]; % L element
% n = [-1 0 1]; % Q element
% n = [-1 -1/3 1/3 1]; % C element
n = linspace(-1,1,nne);
for i = 1:nne
% Gauss point substituting into ksi
% [~,naturalDerivatives]=shapeFunctionL2(n(i)); % L element
% [~,naturalDerivatives]=shapeFunctionL3(n(i)); % Q element
% [~,naturalDerivatives]=shapeFunctionL4(n(i)); % C element
[~,naturalDerivatives]=shapeFunctionLx(n(i),nne);
B=naturalDerivatives*invJacobian;
axial_stress(i) = E*B*displacements(elementDof);
fprintf('%6d%8d%17.4e\n',e,i,axial_stress(i));
end
axial_Stress_global = [axial_Stress_global axial_stress'];
end
% ----------------------------------------------------------------------
figure(1)
syms x
exact_disp = 112/E.*log(x/2)-(x.^3-8)/6/E-4/E.*log(x/4)*heaviside(x-4);
fplot(exact_disp,[2 6],'b-','LineWidth',1.5);
hold on
% plot displacement
physical_coor = []; % global real coordinate
disp = []; % global displacement
Natural_coor = linspace(-1,1,101); % local natural coordinate
ele_disp = zeros(1,length(Natural_coor)); % local displacement
for e = 1:numberElements
detJacobian = L(e)/2;
xc = (nodeCoordinates(elementNodes(e,end)) + nodeCoordinates(elementNodes(e,1)))/2;
for p = 1:size(Natural_coor,2)
% [shape,~] = shapeFunctionL2(Natural_coor(p)); % L element
% [shape,~] = shapeFunctionL3(Natural_coor(p)); % Q element
% [shape,~] = shapeFunctionL4(Natural_coor(p)); % C element
[shape,~]=shapeFunctionLx(Natural_coor(p),nne);
ele_disp(p) = shape*displacements(elementNodes(e,:));
end
disp = [disp ele_disp];
physical_coor = [physical_coor detJacobian*Natural_coor+xc];
end
plot(physical_coor,disp,'r--','LineWidth',1.5);
hold on
plot(nodeCoordinates(reshape(elementNodes',numel(elementNodes),1)),...
displacements(reshape(elementNodes',numel(elementNodes),1)),'ro');
legend('exact','FEM linearArea')
title('displacment')
ylabel('displacement , u')
xlabel('x')
axis([2 6 0 3e-7])
hold off
% --------------------------------------------------------------------
figure(2)
exact_stress = 112./x-x.^2/2-4./x*heaviside(x-4);
fplot(exact_stress,[2 6],'b-','LineWidth',1.5);
hold on
% ~
physical_coor = []; % global real coordinate
stress = []; % global displacement
Natural_coor = linspace(-1,1,101); % local natural coordinate
ele_stress = zeros(1,length(Natural_coor)); % local displacement
for e = 1:numberElements
detJacobian = L(e)/2;
xc = (nodeCoordinates(elementNodes(e,end)) + nodeCoordinates(elementNodes(e,1)))/2;
for p = 1:size(Natural_coor,2)
% [~,naturalDerivatives] = shapeFunctionL2(Natural_coor(p)); % L element
% [~,naturalDerivatives] = shapeFunctionL3(Natural_coor(p)); % Q element
% [~,naturalDerivatives] = shapeFunctionL4(Natural_coor(p)); % C element
[~,naturalDerivatives]=shapeFunctionLx(Natural_coor(p),nne);
ele_stress(p) =
E*naturalDerivatives*invJacobian*displacements(elementNodes(e,:));
end
stress = [stress ele_stress];
physical_coor = [physical_coor detJacobian*Natural_coor+xc];
end
plot(physical_coor,stress,'r--','LineWidth',1.5);
hold on
plot(nodeCoordinates(reshape(elementNodes',numel(elementNodes),1)),axial_Stress_global,
'ro');

legend('exact','FEM linearArea')
title('axial stress')
ylabel('axial stress , \sigma')
xlabel('x')
axis([2 6 0 60])
hold off
shapeFunctionLx
function [shape,naturalDerivatives] = shapeFunctionLx(location,L)
syms iop
xe=linspace(-1,1,L);
shape_function = sym(zeros(size(xe)));
for index = 1 : length(shape_function)
xi = xe(index);
xj = xe(xe ~= xi);% reture which not equal xi
shape_function(1, index) = prod((iop-xj) ./ (xi-xj));
end
shape=double(subs(shape_function,iop,location));
naturalDerivatives=double...
(subs(diff(shape_function,iop),iop,location));
end
shapeFunctionLxx
function [J,shape,naturalDerivatives] = ...
shapeFunctionLxx(location,L,array)
% array = nodeCoordinates(elementDof)
syms iop
xe=linspace(-1,1,L);
shape_function = sym(zeros(size(xe)));
for index = 1 : length(shape_function)
xi = xe(index);
xj = xe(xe ~= xi);% reture which not equal xi
shape_function(1, index) = prod((iop-xj) ./ (xi-xj));
end
% J=subs(shape_function*array',iop,0);
shape=double(subs(shape_function,iop,location));
naturalDerivatives=double...
(subs(diff(shape_function,iop),iop,location));
J=subs(diff(shape_function,iop)*array',iop,0);
end

You might also like