Mesh Functions FEA PROJECT
Mesh Functions FEA PROJECT
%--------------------------------------------------------------------------
% Purpose:
% Synopsis :
% PlotMesh(coordinates,nodes)
% Variable Description:
% -----> coordinates = [X Y Z]
% 1 - display
% Hyderabad, INDIA
% E-mail : [email protected]
% web-link : https://sites.google.com/site/kolukulasivasrinivas/
%--------------------------------------------------------------------------
if nargin == 2
show = 0 ;
end
Y = zeros(nnel,nel) ;
Z = zeros(nnel,nel) ;
if nnel==4 % surface in 3D
for iel=1:nel
nd = nodes(iel,:) ;
end
figure
fill3(X,Y,Z,'w')
rotate3d ;
axis off ;
if show ~= 0
k = 1:nnode ;
nd = k' ;
for i = 1:nel
text(X(:,i),Y(:,i),Z(:,i),int2str(nd(i)),....
'fontsize',8,'color','k');
text(sum(X(:,i))/4,sum(Y(:,i))/4,sum(Z(:,i))/4,int2str(i),.....
'fontsize',10,'color','r') ;
end
end
fm = [1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8; 1 2 3 4; 5 6 7 8];
XYZ = cell(1,nel) ;
for e=1:nel
nd=nodes(e,:);
X(:,e) = coordinates(nd,1) ;
Y(:,e) = coordinates(nd,2) ;
Z(:,e) = coordinates(nd,3) ;
end
figure
set(gcf,'color','w')
axis off
cellfun(@patch,repmat({'Vertices'},1,nel),XYZ,.......
repmat({'Faces'},1,nel),repmat({fm},1,nel),......
repmat({'FaceColor'},1,nel),repmat({'w'},1,nel));
view(3)
if show ~= 0
k = 1:nnode ;
nd = k' ;
for i = 1:nel
text(X(:,i),Y(:,i),Z(:,i),int2str(nd(i)),....
'fontsize',8,'color','k');
text(sum(X(:,i))/8,sum(Y(:,i))/8,sum(Z(:,i))/8,int2str(i),.....
'fontsize',10,'color','r') ;
end
end
end
for iel=1:nel
nd = nodes(iel,:) ;
end
% Plotting the FEM mesh, diaplay Node numbers and Element numbers
figure
fill(X,Y,'w')
axis off ;
if show ~= 0
k = 1:nnode ;
nd = k' ;
for i = 1:nel
text(X(:,i),Y(:,i),int2str(nd(i)),'fontsize',8,'color','k');
text(sum(X(:,i))/4,sum(Y(:,i))/4,int2str(i),'fontsize',10,'color','r') ;
end
end
end
function PlotFieldonDefoMesh(coordinates,nodes,factor,depl,component)
%--------------------------------------------------------------------------
% Purpose:
% Synopsis :
% ProfileonDefoMesh(coordinates,nodes,component)
% Variable Description:
% -----> coordinates = [X Y Z]
% numbers
% Hyderabad, INDIA
% E-mail : [email protected]
% web-link : https://sites.google.com/site/kolukulasivasrinivas/
%--------------------------------------------------------------------------
X = zeros(nnel,nel) ; UX = zeros(nnel,nel) ;
Y = zeros(nnel,nel) ; UY = zeros(nnel,nel) ;
Z = zeros(nnel,nel) ; UZ = zeros(nnel,nel) ;
profile = zeros(nnel,nel) ;
ux = depl(:,1) ;
uy = depl(:,2) ;
uz = depl(:,3) ;
if nnel == 4 % surface in 3D
for iel=1:nel
UY(:,iel) = uy(nd') ;
UZ(:,iel) = uz(nd') ;
profile(:,iel) = component(nd') ;
end
defoX = X+factor*UX ;
defoY = Y+factor*UY ;
defoZ = Z+factor*UZ ;
figure
fill3(defoX,defoY,defoZ,profile)
rotate3d on ;
axis off ;
% Colorbar Setting
SetColorbar
fm = [1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8; 1 2 3 4; 5 6 7 8];
XYZ = cell(1,nel) ;
profile = XYZ ;
for e=1:nel
nd=nodes(e,:);
X = coordinates(nd,1)+factor*ux(nd) ;
Y = coordinates(nd,2)+factor*uy(nd) ;
Z = coordinates(nd,3)+factor*uz(nd) ;
XYZ{e} = [X Y Z] ;
profile{e} = component(nd) ;
end
figure
cellfun(@patch,repmat({'Vertices'},1,nel),XYZ,.......
repmat({'Faces'},1,nel),repmat({fm},1,nel),......
repmat({'FaceVertexCdata'},1,nel),profile,......
repmat({'FaceColor'},1,nel),repmat({'interp'},1,nel));
view(3)
% Colorbar Setting
SetColorbar
end
ux = depl(:,1) ;
uy = depl(:,2) ;
for iel=1:nel
nd=nodes(iel,:); % extract connected node for (iel)-th element
UX(:,iel) = ux(nd') ;
UY(:,iel) = uy(nd') ;
profile(:,iel) = component(nd') ;
end
defoX = X+factor*UX ;
defoY = Y+factor*UY ;
figure
plot(defoX,defoY,'k')
fill(defoX,defoY,profile)
axis off ;
% Colorbar Setting
SetColorbar
end
function PlotFieldonMesh(coordinates,nodes,component)
%--------------------------------------------------------------------------
% Purpose:
% Synopsis :
% ProfileonMesh(coordinates,nodes,component)
% Variable Description:
% -----> coordinates = [X Y Z]
% Hyderabad, INDIA
% E-mail : [email protected]
% web-link : https://sites.google.com/site/kolukulasivasrinivas/
%--------------------------------------------------------------------------
X = zeros(nnel,nel) ;
Y = zeros(nnel,nel) ;
Z = zeros(nnel,nel) ;
profile = zeros(nnel,nel) ;
if nnel == 4 % Surface in 3D
for iel=1:nel
end
figure
fill3(X,Y,Z,profile)
rotate3d on ;
axis off ;
% Colorbar Setting
SetColorbar
fm = [1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8; 1 2 3 4; 5 6 7 8];
XYZ = cell(1,nel) ;
profile = XYZ ;
for e=1:nel
nd=nodes(e,:);
X = coordinates(nd,1) ;
Y = coordinates(nd,2) ;
Z = coordinates(nd,3) ;
XYZ{e} = [X Y Z] ;
profile{e} = component(nd) ;
end
figure
cellfun(@patch,repmat({'Vertices'},1,nel),XYZ,.......
repmat({'Faces'},1,nel),repmat({fm},1,nel),......
repmat({'FaceVertexCdata'},1,nel),profile,......
repmat({'FaceColor'},1,nel),repmat({'interp'},1,nel));
view(3)
% Colorbar Setting
SetColorbar
end
for iel=1:nel
end
figure
% plot(X,Y,'k')
fill(X,Y,profile)
axis off ;
% Colorbar Setting
SetColorbar
end
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%--------------------------------------------------------------------------
% India |
% E-mail : [email protected] |
% http://sites.google.com/site/kolukulasivasrinivas/ |
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% Variable descriptions
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% input data
%--------------------------------------------------------------------------
load displacements.dat ;
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
UX = displacements(:,2) ;
UY = displacements(:,3) ;
UZ = displacements(:,4) ;
U = sqrt(UX.^2+UY.^2+UZ.^2) ;
RX = displacements(:,5) ;
RY = displacements(:,6) ;
RZ = displacements(:,7) ;
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
component = UZ ;
PlotFieldonMesh(coordinates,nodes,component) ; % Plot the component profile on mesh
PlotFieldonDefoMesh(coordinates,nodes,factor,depl,component) ;
function SetColorbar
cbar = colorbar;
% cpos = get(cbar,'position');
% cpos(2) = cpos(2)+.1 ;
% cpos(4) = cpos(4)-.2 ;
%set(cbar,'Position',cpos) ;
brighten(0.5);
set(get(cbar,'title'),'string','VAL');
%locate = get(cbar,'title');
%tpos = get(locate,'position');
%tpos(3) = tpos(3)+5. ;
%set(locate,'pos',tpos);
clim = caxis;
ylim(cbar,[clim(1) clim(2)]);
kssv = linspace(clim(1),clim(2),numpts);
for i = 1:numpts
imep = num2str(kssv(i),'%+3.2E');
vasu(i) = {imep} ;
end
set(cbar,'YTickLabel',vasu(1:numpts),'fontsize',9);