Home > vbmeg > external > iso2mesh > elemvolume.m

elemvolume

PURPOSE ^

SYNOPSIS ^

function vol=elemvolume(node,elem,option)

DESCRIPTION ^

 vol=elemvolume(node,elem,option)

 calculate the volume for a list of simplexes

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2007/11/21

 input:
    node:  node coordinates
    elem:  element table of a mesh
    option: if option='signed', the volume is the raw determinant,
            else, the results will be the absolute values

 output:
    vol:   volume values for all elements

 -- 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 vol=elemvolume(node,elem,option)
0002 %
0003 % vol=elemvolume(node,elem,option)
0004 %
0005 % calculate the volume for a list of simplexes
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 % date: 2007/11/21
0009 %
0010 % input:
0011 %    node:  node coordinates
0012 %    elem:  element table of a mesh
0013 %    option: if option='signed', the volume is the raw determinant,
0014 %            else, the results will be the absolute values
0015 %
0016 % output:
0017 %    vol:   volume values for all elements
0018 %
0019 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0020 %
0021 
0022 if(size(elem,2)==size(node,2))
0023     enum=size(elem,1);
0024     vol=zeros(enum,1);
0025     acol=ones(3,1);
0026     for i=1:enum
0027         e1=det([node(elem(i,:),2),node(elem(i,:),3),acol]);
0028         e2=det([node(elem(i,:),3),node(elem(i,:),1),acol]);
0029         e3=det([node(elem(i,:),1),node(elem(i,:),2),acol]);
0030         vol(i)=sqrt(e1*e1+e2*e2+e3*e3)/2;
0031     end
0032     return;
0033 end
0034 dim=size(elem,2);
0035 enum=size(elem,1);
0036 vol=zeros(enum,1);
0037 for i=1:enum
0038     detmat=[node(elem(i,:),:)';ones(1,dim)];
0039     vol(i)=det(detmat);
0040 end
0041 if(nargin==3 && strcmp(option,'signed'))
0042   vol=vol/prod(1:size(node,2));
0043 else
0044   vol=abs(vol)/prod(1:size(node,2));
0045 end

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