[no,el,fc]=sortmesh(origin,node,elem,face) sort nodes and elements in a mesh so that the indexed nodes and elements are closer to each order (this may reduce cache-miss in a calculation) author: Qianqian Fang, <q.fang at neu.edu> date: 2010/05/06 input: origin: sorting all nodes and elements with the distance and angles wrt this location, if origin=[], it will be node(1,:) node: list of nodes elem: list of elements (each row are indices of nodes of each element) ecol: list of columns in elem to participate sorting face: list of surface triangles (this can be omitted) fcol: list of columns in face to participate sorting output: no: node coordinates in the sorted order el: the element list in the sorted order fc: the surface triangle list in the sorted order (can be ignored) nodemap: the new node mapping order, no=node(nodemap,:) -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0001 function [no,el,fc,nodemap]=sortmesh(origin,node,elem,ecol,face,fcol) 0002 % 0003 % [no,el,fc]=sortmesh(origin,node,elem,face) 0004 % 0005 % sort nodes and elements in a mesh so that the indexed 0006 % nodes and elements are closer to each order 0007 % (this may reduce cache-miss in a calculation) 0008 % 0009 % author: Qianqian Fang, <q.fang at neu.edu> 0010 % date: 2010/05/06 0011 % 0012 % input: 0013 % origin: sorting all nodes and elements with the distance and 0014 % angles wrt this location, if origin=[], it will be 0015 % node(1,:) 0016 % node: list of nodes 0017 % elem: list of elements (each row are indices of nodes of each element) 0018 % ecol: list of columns in elem to participate sorting 0019 % face: list of surface triangles (this can be omitted) 0020 % fcol: list of columns in face to participate sorting 0021 % 0022 % output: 0023 % no: node coordinates in the sorted order 0024 % el: the element list in the sorted order 0025 % fc: the surface triangle list in the sorted order (can be ignored) 0026 % nodemap: the new node mapping order, no=node(nodemap,:) 0027 % 0028 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0029 % 0030 0031 if(isempty(origin)) 0032 origin=node(1,:); 0033 end 0034 sdist=node-repmat(origin,size(node,1),1); 0035 [theta,phi,R]=cart2sph(sdist(:,1),sdist(:,2),sdist(:,3)); 0036 sdist=[R,phi,theta]; 0037 [nval,nodemap]=sortrows(sdist); 0038 no=node(nodemap,:); 0039 0040 [nval,nidx]=sortrows(nodemap); 0041 el=elem; 0042 if(nargin<4) 0043 ecol=1:size(elem,2); 0044 end 0045 el(:,ecol)=sort(nidx(elem(:,ecol)),2); 0046 el=sortrows(el,ecol); 0047 0048 if(nargin>=5 && nargout==3) 0049 if(nargin<6) 0050 fcol=1:size(face,2); 0051 end 0052 fc=face; 0053 fc(:,fcol)=sort(nidx(face(:,fcol)),2); 0054 fc=sortrows(fc,fcol); 0055 end