FEATool  v1.8
Finite Element Analysis Toolbox
 All Files Functions Pages
grid_cell_type.m File Reference

Description

GRID_CELL_TYPE Determine grid cell type.

[ CELL_TYPE, N_SDIM, N_VC ] = GRID_CELL_TYPE( VARARGIN ) Determines the cell type from cell vertex connectivity array C, or alternatively the number of space dimensions N_SDIM, and the number of vertices per cell N_VC. Returns the CELL_TYPE, N_SDIM, and N_VC. Also assigns the cell_type integer code variables (LINE, TRI, QUAD, TET, and HEX) in the workspace of the caller function.

Code listing

 assignin( 'caller', 'LINE', 12 );
 assignin( 'caller', 'TRI',  23 );
 assignin( 'caller', 'QUAD', 24 );
 assignin( 'caller', 'TET',  34 );
 assignin( 'caller', 'HEX',  38 );


 if( nargin>=1 && nargin<=2 && all(cellfun(@isnumeric,varargin)) )

   if( nargin==1 && numel(varargin{1})>1 )

     c = varargin{1};
     n_vc = size(c,1);
     if( n_vc==4 )
       if( size(c,2)==1 )
         warning(['Cannot separate from quadrilateral or tetrahedral cell.',char(10),'Defaulting to quadrilateral.'])
       end

       [~,tmp] = unique( sort( [ c(1:3,:) c([1 2 4],:) c([2 3 4],:) c([3 1 4],:) ], 1 )', 'rows' );
       is_quad = numel(tmp) == 4*size(c,2);
       n_sdim = 2 + ~is_quad;
     else
       n_sdim = (n_vc==2) + 2*(n_vc==3) + 3*(n_vc==8);
     end

     varargin = { n_sdim n_vc };

   end

   cell_type = cell2mat( varargin ) * [10.^[(numel(varargin)-1):-1:0]]';

   n_sdim = floor(cell_type/10);
   n_vc   = rem(cell_type,10);

 end