Code covered by the BSD License

# Meshing thin shells using four noded elements

### Siva Srinivas Kolukula (view profile)

To mesh thin shells using four noded elements to use in Finite Element Analysis

```function [coordinates,nodes] = MeshCylindricalShell(Radius,theta,Height,NH,NT)
%  To Mesh a thin cylindrical shell with 4 noded Elements
%--------------------------------------------------------------------------
% Code written by : Siva Srinivas Kolukula                                |
%                   Senior Research Fellow                                |
%                   Structural Mechanics Laboratory                       |
%                   Indira Gandhi Center for Atomic Research              |
%                   India                                                 |
% E-mail : allwayzitzme@gmail.com                                         |
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% Purpose:
%          To Mesh a thin cylindrical shell to use in FEM Analysis
% Variable Description:
% Input :
%           theta - Angle of the sector to which Shell needed
%           Height - Height of the Cylindrical shell
%           NH - Number of Elements along Height (Number of Rings)
%           NT - Number of Angular sectors
% Output :
%           coordinates - The nodal coordinates of the mesh
%           -----> coordinates = [node X Y Z]
%           nodes - The nodal connectivity of the elements
%           -----> nodes = [node1 node2......]
%--------------------------------------------------------------------------
nel = NH*NT ;           % Total Number of Elements in the Mesh
nnel = 4 ;              % Number of nodes per Element
% Number of points (nodes) on the Height and Angluar discretization
npH = NH+1 ;
npT = NT+1 ;
nnode = npH*npT ;       % Number of nodes
% Discretizing the Height and Angle of the cylinder
nH = linspace(0,Height,npH) ;
nT = linspace(0,theta,npT)*pi/180 ;
[H T] = meshgrid(nH,nT) ;
% Convert grid to cylindrical coordintes
ZZ = H ;
%mesh(XX,YY,ZZ) ;
% To get the Nodal Connectivity Matrix
coordinates = [XX(:) YY(:) ZZ(:)] ; % Coordinates of (X,Y,Z)
NodeNo = 1:nnode ;
nodes = zeros(nel,nnel) ;
% If elements along the Height and Angular discretization are equal
if npH==npT
NodeNo = reshape(NodeNo,npT,npH);
nodes(:,1) = reshape(NodeNo(1:npH-1,1:npT-1),nel,1);
nodes(:,2) = reshape(NodeNo(2:npH,1:npT-1),nel,1);
nodes(:,3) = reshape(NodeNo(2:npH,2:npT),nel,1);
nodes(:,4) = reshape(NodeNo(1:npH-1,2:npT),nel,1);
% If the elements along the axes are different
else%if npH>npT
NodeNo = reshape(NodeNo,npT,npH);
nodes(:,1) = reshape(NodeNo(1:npT-1,1:npH-1),nel,1);
nodes(:,2) = reshape(NodeNo(2:npT,1:npH-1),nel,1);
nodes(:,3) = reshape(NodeNo(2:npT,2:npH),nel,1);
nodes(:,4) = reshape(NodeNo(1:npT-1,2:npH),nel,1);
end
%
% Plotting the Finite Element Mesh
% Initialization of the required matrices
X = zeros(nnel,nel) ;
Y = zeros(nnel,nel) ;
Z = zeros(nnel,nel) ;
% Extract X,Y,Z coordinates for the (iel)-th element
for iel = 1:nel
X(:,iel) = coordinates(nodes(iel,:),1) ;
Y(:,iel) = coordinates(nodes(iel,:),2) ;
Z(:,iel) = coordinates(nodes(iel,:),3) ;
end
% Figure
fh = figure ;
set(fh,'name','Preprocessing for FEA','numbertitle','off','color','w') ;
fill3(X,Y,Z,'w') ;
title('Finite Element Mesh of thin Cylindrical shell','HandleVisibility','off') ;