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

Mesh Functions FEA PROJECT

The document describes functions to plot finite element method (FEM) meshes and fields on meshes. It provides functions to plot undeformed and deformed meshes in 2D and 3D. It can plot nodal numbers and element numbers. It can plot component profiles like displacement and stress on the meshes. The functions were created by Siva Srinivas Kolukula to visualize FEM results.

Uploaded by

Kamalakcshy S S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Mesh Functions FEA PROJECT

The document describes functions to plot finite element method (FEM) meshes and fields on meshes. It provides functions to plot undeformed and deformed meshes in 2D and 3D. It can plot nodal numbers and element numbers. It can plot component profiles like displacement and stress on the meshes. The functions were created by Siva Srinivas Kolukula to visualize FEM results.

Uploaded by

Kamalakcshy S S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

function PlotMesh(coordinates,nodes,show)

%--------------------------------------------------------------------------

% Purpose:

% To plot the Finite Element Method Mesh

% Synopsis :

% PlotMesh(coordinates,nodes)

% Variable Description:

% coordinates - The nodal coordinates of the mesh

% -----> coordinates = [X Y Z]

% nodes - The nodal connectivity of the elements

% -----> nodes = [node1 node2......]

% show - to dispaly nodal and element numbers

% 0 (default) - do not display

% 1 - display

% Coded by : Siva Srinivas Kolukula, PhD

% Indian Tsunami Early Warning Centre (ITEWC)

% Advisory Services and Satellite Oceanography Group (ASG)

% Indian National Centre for Ocean Information Services (INCOIS)

% Hyderabad, INDIA

% E-mail : [email protected]

% web-link : https://sites.google.com/site/kolukulasivasrinivas/

% version 1: 28 August 2011

% Version 2: 16 September 2016

%--------------------------------------------------------------------------

if nargin == 2

show = 0 ;

end

dimension = size(coordinates,2) ; % Dimension of the mesh

nel = length(nodes) ; % number of elements

nnode = length(coordinates) ; % total number of nodes in system

nnel = size(nodes,2); % number of nodes per element

% Initialization of the required matrices


X = zeros(nnel,nel) ;

Y = zeros(nnel,nel) ;

Z = zeros(nnel,nel) ;

if dimension == 3 % For 3D plots

if nnel==4 % surface in 3D

for iel=1:nel

nd = nodes(iel,:) ;

X(:,iel)=coordinates(nd,1); % extract x value of the node

Y(:,iel)=coordinates(nd,2); % extract y value of the node

Z(:,iel)=coordinates(nd,3) ; % extract z value of the node

end

% Plotting the FEM mesh

figure

fill3(X,Y,Z,'w')

rotate3d ;

title('Finite Element Mesh') ;

axis off ;

% display Node numbers and Element numbers

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

elseif nnel==8 % solid in 3D

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) ;

XYZ{e} = [X(:,e) Y(:,e) Z(:,e)] ;

end

% Plot FEM mesh

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)

set(gca,'XTick',[]) ; set(gca,'YTick',[]); set(gca,'ZTick',[]) ;

% display Node numbers and Element numbers

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

elseif dimension == 2 % For 2D plots

for iel=1:nel

nd = nodes(iel,:) ;

X(:,iel)=coordinates(nd,1); % extract x value of the node

Y(:,iel)=coordinates(nd,2); % extract y value of the node

end

% Plotting the FEM mesh, diaplay Node numbers and Element numbers

figure
fill(X,Y,'w')

title('Finite Element Mesh') ;

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:

% To plot the profile of a component on deformed mesh

% Synopsis :

% ProfileonDefoMesh(coordinates,nodes,component)

% Variable Description:

% coordinates - The nodal coordinates of the mesh

% -----> coordinates = [X Y Z]

% nodes - The nodal connectivity of the elements

% -----> nodes = [node1 node2......]

% factor - Amplification factor (Change accordingly, trial)

% depl - Nodal displacements

% -----> depl = [UX UY UZ]

% component - The components whose profile to be plotted

% -----> components = a column vector in the order of node

% numbers

% Coded by : Siva Srinivas Kolukula, PhD

% Indian Tsunami Early Warning Centre (ITEWC)

% Advisory Services and Satellite Oceanography Group (ASG)

% Indian National Centre for Ocean Information Services (INCOIS)

% Hyderabad, INDIA
% E-mail : [email protected]

% web-link : https://sites.google.com/site/kolukulasivasrinivas/

% version 1: 28 August 2011

% Version 2: 16 September 2016

%--------------------------------------------------------------------------

dimension = size(coordinates,2) ; % Dimension of the mesh

nel = length(nodes) ; % number of elements

nnode = length(coordinates) ; % total number of nodes in system

nnel = size(nodes,2); % number of nodes per element

% Initialization of the required matrices

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) ;

if dimension == 3 % For 3D plots

ux = depl(:,1) ;

uy = depl(:,2) ;

uz = depl(:,3) ;

if nnel == 4 % surface in 3D

for iel=1:nel

nd=nodes(iel,:); % extract connected node for (iel)-th element

X(:,iel)=coordinates(nd,1); % extract x value of the node

Y(:,iel)=coordinates(nd,2); % extract y value of the node

Z(:,iel)=coordinates(nd,3) ; % extract z value of the node

UX(:,iel) = ux(nd') ; % extract displacement value's of the node

UY(:,iel) = uy(nd') ;

UZ(:,iel) = uz(nd') ;

profile(:,iel) = component(nd') ;

end

% Plotting the profile of a property on the deformed mesh

defoX = X+factor*UX ;
defoY = Y+factor*UY ;

defoZ = Z+factor*UZ ;

figure

fill3(defoX,defoY,defoZ,profile)

title('Profile of component on deformed Mesh') ;

rotate3d on ;

axis off ;

% Colorbar Setting

SetColorbar

elseif nnel==8 % solid in 3D

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)

set(gca,'XTick',[]) ; set(gca,'YTick',[]); set(gca,'ZTick',[]) ;

% Colorbar Setting

SetColorbar

end

elseif dimension == 2 % For 2D plots

ux = depl(:,1) ;

uy = depl(:,2) ;

for iel=1:nel
nd=nodes(iel,:); % extract connected node for (iel)-th element

X(:,iel)=coordinates(nd,2); % extract x value of the node

Y(:,iel)=coordinates(nd,3); % extract y value of the node

UX(:,iel) = ux(nd') ;

UY(:,iel) = uy(nd') ;

profile(:,iel) = component(nd') ;

end

% Plotting the profile of a property on the deformed mesh

defoX = X+factor*UX ;

defoY = Y+factor*UY ;

figure

plot(defoX,defoY,'k')

fill(defoX,defoY,profile)

title('Profile of UX on deformed Mesh') ;

axis off ;

% Colorbar Setting

SetColorbar

end

function PlotFieldonMesh(coordinates,nodes,component)

%--------------------------------------------------------------------------

% Purpose:

% To plot the profile of a component on mesh

% Synopsis :

% ProfileonMesh(coordinates,nodes,component)

% Variable Description:

% coordinates - The nodal coordinates of the mesh

% -----> coordinates = [X Y Z]

% nodes - The nodal connectivity of the elements

% -----> nodes = [node1 node2......]

% component - The components whose profile to be plotted

% -----> components = a column vector in the order of node


% numbers

% Coded by : Siva Srinivas Kolukula, PhD

% Indian Tsunami Early Warning Centre (ITEWC)

% Advisory Services and Satellite Oceanography Group (ASG)

% Indian National Centre for Ocean Information Services (INCOIS)

% Hyderabad, INDIA

% E-mail : [email protected]

% web-link : https://sites.google.com/site/kolukulasivasrinivas/

% version 1: 28 August 2011

% Version 2: 16 September 2016

%--------------------------------------------------------------------------

dimension = size(coordinates,2) ; % Dimension of the mesh

nel = length(nodes) ; % number of elements

nnode = length(coordinates) ; % total number of nodes in system

nnel = size(nodes,2); % number of nodes per element

% Initialization of the required matrices

X = zeros(nnel,nel) ;

Y = zeros(nnel,nel) ;

Z = zeros(nnel,nel) ;

profile = zeros(nnel,nel) ;

if dimension == 3 % For 3D plots

if nnel == 4 % Surface in 3D

for iel=1:nel

nd=nodes(iel,:); % extract connected node for (iel)-th element

X(:,iel)=coordinates(nd,1); % extract x value of the node

Y(:,iel)=coordinates(nd,2); % extract y value of the node

Z(:,iel)=coordinates(nd,3) ; % extract z value of the node

profile(:,iel) = component(nd') ; % extract component value of the node

end

% Plotting the FEM mesh and profile of the given component

figure
fill3(X,Y,Z,profile)

rotate3d on ;

title('Profile of component on Mesh') ;

axis off ;

% Colorbar Setting

SetColorbar

elseif nnel == 8 % solid in 3D

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)

set(gca,'XTick',[]) ; set(gca,'YTick',[]); set(gca,'ZTick',[]) ;

% Colorbar Setting

SetColorbar

end

elseif dimension == 2 % For 2D plots

for iel=1:nel

nd=nodes(iel,:); % extract connected node for (iel)-th element

X(:,iel)=coordinates(nd,1); % extract x value of the node

Y(:,iel)=coordinates(nd,2); % extract y value of the node


profile(:,iel) = component(nd') ; % extract component value of the
node

end

% Plotting the FEM mesh and profile of the given component

figure

% plot(X,Y,'k')

fill(X,Y,profile)

title('Profile of component on Mesh') ;

axis off ;

% Colorbar Setting

SetColorbar

end

% Post processing the Finite Element Results

% Plotting the profile of components on Finite Element mesh / deformed mesh

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

% Warning : On running this the workspace memory will be deleted. Save if

% any data present before running the code !!

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%--------------------------------------------------------------------------

% Code written by : Siva Srinivas Kolukula |

% Senior Research Fellow |

% Structural Mechanics Laboratory |

% Indira Gandhi Center for Atomic Research |

% India |

% E-mail : [email protected] |

% http://sites.google.com/site/kolukulasivasrinivas/ |

%--------------------------------------------------------------------------
%--------------------------------------------------------------------------

% Variable descriptions

% coordinates.dat - data file of nodal coordinates of the nodes

% nodes.dat - data file of elemental nodal connectivity

% displacements - displacement results obtained from FEA

% factor - amplication factor for deformed mesh

% NOTE : Please note that in coordinates ,displacements first column is

% node number and in nodes forst column is element number .

%--------------------------------------------------------------------------

clear all;clc ; close all;

%--------------------------------------------------------------------------

% input data

%--------------------------------------------------------------------------

load coordinates.dat ; coordinates = coordinates(:,2:end) ;

load nodes.dat ; nodes = nodes(:,2:end) ;

load displacements.dat ;

%--------------------------------------------------------------------------

% Sorting the values accordingly

%--------------------------------------------------------------------------

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) ;

%--------------------------------------------------------------------------

% Plotting the mesh and profiles

%--------------------------------------------------------------------------

PlotMesh(coordinates,nodes,1) ; % Plot the FEM mesh

component = UZ ;
PlotFieldonMesh(coordinates,nodes,component) ; % Plot the component profile on mesh

depl = [UX UY UZ] ;

factor = 90 ; % Plot the component profile on deformed mesh

PlotFieldonDefoMesh(coordinates,nodes,factor,depl,component) ;

function SetColorbar

cbar = colorbar;

% Dimensions of the colorbar

% cpos = get(cbar,'position');

% cpos(3) = cpos(3)/4 ; % Reduce the width of colorbar by half

% cpos(2) = cpos(2)+.1 ;

% cpos(4) = cpos(4)-.2 ;

%set(cbar,'Position',cpos) ;

brighten(0.5);

% Title of the colorbar

set(get(cbar,'title'),'string','VAL');

%locate = get(cbar,'title');

%tpos = get(locate,'position');

%tpos(3) = tpos(3)+5. ;

%set(locate,'pos',tpos);

% Setting the values on colorbar

% get the color limits

clim = caxis;

ylim(cbar,[clim(1) clim(2)]);

numpts = 24 ; % Number of points to be displayed on colorbar

kssv = linspace(clim(1),clim(2),numpts);

set(cbar,'YtickMode','manual','YTick',kssv); % Set the tickmode to manual

for i = 1:numpts

imep = num2str(kssv(i),'%+3.2E');

vasu(i) = {imep} ;

end

set(cbar,'YTickLabel',vasu(1:numpts),'fontsize',9);

You might also like