Home > utilities > connectivity.m

connectivity

PURPOSE ^

CONNECTIVITY: Assemble connectivity data for a triangular mesh.

SYNOPSIS ^

function [e,te,e2t,bnd] = connectivity(p,t)

DESCRIPTION ^

  CONNECTIVITY: Assemble connectivity data for a triangular mesh.

 The edge based connectivity is built for a triangular mesh and the
 boundary nodes identified. This data should be useful when implementing
 FE/FV methods using triangular meshes.

  [e,te,et2,bnd] = connectivity(p,t);

  p   : Nx2 array of nodes coordinates, [x1,y1; x2,y2; etc]
  t   : Mx3 array of triangles as indices, [n11,n12,n13; n21,n22,n23; etc]

  e   : Kx2 array of unique mesh edges - [n11,n12; n21,n22; etc]
  te  : Mx3 array of triangles as indices into E, [e11,e12,e13; 
                                                   e21,e22,e23; etc]
  e2t : Kx2 array of triangle neighbours for unique mesh edges -
        [t11,t12; t21,t22; etc]. Each row has two entries corresponding to
        the triangle numbers associated with each edge in E. Boundary
        edges have e2t(i,2)=0.
  bnd : Nx1 logical array identifying boundary nodes. P(i,:) is a boundary
        node if BND(i)=TRUE.

 See also MESH2D, REFINE

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [e,te,e2t,bnd] = connectivity(p,t)
0002 %  CONNECTIVITY: Assemble connectivity data for a triangular mesh.
0003 %
0004 % The edge based connectivity is built for a triangular mesh and the
0005 % boundary nodes identified. This data should be useful when implementing
0006 % FE/FV methods using triangular meshes.
0007 %
0008 %  [e,te,et2,bnd] = connectivity(p,t);
0009 %
0010 %  p   : Nx2 array of nodes coordinates, [x1,y1; x2,y2; etc]
0011 %  t   : Mx3 array of triangles as indices, [n11,n12,n13; n21,n22,n23; etc]
0012 %
0013 %  e   : Kx2 array of unique mesh edges - [n11,n12; n21,n22; etc]
0014 %  te  : Mx3 array of triangles as indices into E, [e11,e12,e13;
0015 %                                                   e21,e22,e23; etc]
0016 %  e2t : Kx2 array of triangle neighbours for unique mesh edges -
0017 %        [t11,t12; t21,t22; etc]. Each row has two entries corresponding to
0018 %        the triangle numbers associated with each edge in E. Boundary
0019 %        edges have e2t(i,2)=0.
0020 %  bnd : Nx1 logical array identifying boundary nodes. P(i,:) is a boundary
0021 %        node if BND(i)=TRUE.
0022 %
0023 % See also MESH2D, REFINE
0024 
0025 % Darren Engwirda - 2007
0026 
0027 if nargin<2
0028    error('Wrong number of inputs');
0029 end
0030 if nargout>4
0031    error('Wrong number of outputs');
0032 end
0033 if numel(p)~=2*size(p,1)
0034    error('P must be an Nx2 array');
0035 end
0036 if numel(t)~=3*size(t,1)
0037    error('T must be an Mx3 array');
0038 end
0039 if any(t(:)<1) || max(t(:)>size(p,1))
0040    error('Invalid T');
0041 end
0042 
0043 % Unique mesh edges as indices into P
0044 numt = size(t,1);
0045 vect = 1:numt;                                 % Triangle indices
0046 e = [t(:,[1,2]); t(:,[2,3]); t(:,[3,1])];      % Edges - not unique
0047 [e,j,j] = unique(sort(e,2),'rows');            % Unique edges
0048 te = [j(vect), j(vect+numt), j(vect+2*numt)];  % Unique edges in each triangle
0049 
0050 % Edge-to-triangle connectivity
0051 % Each row has two entries corresponding to the triangle numbers
0052 % associated with each edge. Boundary edges have e2t(i,2)=0.
0053 nume = size(e,1);
0054 e2t  = zeros(nume,2);
0055 for k = 1:numt
0056    j = 1;
0057    while j<=3
0058       ce = te(k,j);
0059       if e2t(ce,1)==0
0060          e2t(ce,1) = k;
0061       else
0062          e2t(ce,2) = k;
0063       end
0064       j = j+1;
0065    end
0066 end
0067 
0068 % Flag boundary nodes
0069 bnd = false(size(p,1),1);
0070 bnd(e(e2t(:,2)==0,:)) = true;                  % True for bnd nodes
0071 
0072 end      % connectivity()

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005