Home > vbmeg > external > iso2mesh > meshremap.m

meshremap

PURPOSE ^

SYNOPSIS ^

function newval=meshremap(fromval,elemid,elembary,toelem,nodeto)

DESCRIPTION ^

 newval=meshremap(fromval,elemid,elembary,toelem,nodeto)

 Redistribute nodal values from the source mesh to the target mesh so that 
 the sum of each property on each mesh is the same

 author: Qianqian Fang (q.fang at neu.edu)

 input:
     fromval: values defined at the source mesh nodes, the row or column
              number must be the same as the source mesh node number, which
              is the same as the elemid length
     elemid: the IDs of the target mesh element that encloses the nodes of
            the source mesh nodes; a vector of length of src mesh node
            count; elemid and elembary can be generated by calling

           [elemid,elembary]=tsearchn(node_target, elem_target, node_src);

           note that the mapping here is inverse to that in meshinterp()

     elembary: the bary-centric coordinates of each source mesh nodes
             within the target mesh elements, sum of each row is 1, expect
             3 or 4 columns (or can be N-D)
    toelem: the element list of the target mesh
    nodeto: the total number of target mesh nodes


 output:
     newval: a 2D array with rows equal to the target mesh nodes (nodeto), 
            and columns equals to the value numbers defined at each source
            mesh node
 example:

    [n1,f1,e1]=meshabox([0 0 0],[10 20 5],1); % src mesh
    [n2,f2,e2]=meshabox([0 0 0],[10 20 5],2); % target mesh
    [id, ww]=tsearchn(n2,e2,n1);              % project src to target mesh
    value_src=n1(:,[2 3 1]);             % create dummy values at src mesh
    newval=meshremap(value_src,id,ww,e2,size(n2,1)); % map to target

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newval=meshremap(fromval,elemid,elembary,toelem,nodeto)
0002 %
0003 % newval=meshremap(fromval,elemid,elembary,toelem,nodeto)
0004 %
0005 % Redistribute nodal values from the source mesh to the target mesh so that
0006 % the sum of each property on each mesh is the same
0007 %
0008 % author: Qianqian Fang (q.fang at neu.edu)
0009 %
0010 % input:
0011 %     fromval: values defined at the source mesh nodes, the row or column
0012 %              number must be the same as the source mesh node number, which
0013 %              is the same as the elemid length
0014 %     elemid: the IDs of the target mesh element that encloses the nodes of
0015 %            the source mesh nodes; a vector of length of src mesh node
0016 %            count; elemid and elembary can be generated by calling
0017 %
0018 %           [elemid,elembary]=tsearchn(node_target, elem_target, node_src);
0019 %
0020 %           note that the mapping here is inverse to that in meshinterp()
0021 %
0022 %     elembary: the bary-centric coordinates of each source mesh nodes
0023 %             within the target mesh elements, sum of each row is 1, expect
0024 %             3 or 4 columns (or can be N-D)
0025 %    toelem: the element list of the target mesh
0026 %    nodeto: the total number of target mesh nodes
0027 %
0028 %
0029 % output:
0030 %     newval: a 2D array with rows equal to the target mesh nodes (nodeto),
0031 %            and columns equals to the value numbers defined at each source
0032 %            mesh node
0033 % example:
0034 %
0035 %    [n1,f1,e1]=meshabox([0 0 0],[10 20 5],1); % src mesh
0036 %    [n2,f2,e2]=meshabox([0 0 0],[10 20 5],2); % target mesh
0037 %    [id, ww]=tsearchn(n2,e2,n1);              % project src to target mesh
0038 %    value_src=n1(:,[2 3 1]);             % create dummy values at src mesh
0039 %    newval=meshremap(value_src,id,ww,e2,size(n2,1)); % map to target
0040 %
0041 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0042 %
0043 
0044 if(size(fromval,1)==1)
0045     fromval=fromval(:);
0046 end
0047 
0048 if(size(fromval,2)==length(elemid))
0049     fromval=fromval.';
0050 end
0051 
0052 newval=zeros(nodeto,size(fromval,2));
0053 
0054 idx=~isnan(elemid);
0055 fromval=fromval(idx,:);
0056 elembary=elembary(idx,:);
0057 idx=elemid(idx);
0058 
0059 nodeval=repmat(fromval,1,1,size(elembary,2)).*repmat(permute(elembary,[1,3,2]),1,size(fromval,2),1);
0060 
0061 for i=1:size(elembary,2)
0062     [ix,iy]=meshgrid(toelem(idx,i),1:size(fromval,2));
0063     nval=nodeval(:,:,i).';
0064     newval=newval + accumarray([ix(:),iy(:)],nval(:), size(newval));
0065 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005