get_elem_volume

PURPOSE ^

GET_ELEM_VOLUME: VOL = get_elem_volume(fwd_model, map_node )

SYNOPSIS ^

function VOL = get_elem_volume( fwd_model, map_node )

DESCRIPTION ^

 GET_ELEM_VOLUME: VOL = get_elem_volume(fwd_model, map_node )
 Calculate volume (or area) of each element in model

 If the model has a 'coarse2fine' element, then the
 returned VOL applies to the coarse matrix

 if map_node == 1, then calculated volumes are the volume fraction for each node

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function VOL = get_elem_volume( fwd_model, map_node )
0002 % GET_ELEM_VOLUME: VOL = get_elem_volume(fwd_model, map_node )
0003 % Calculate volume (or area) of each element in model
0004 %
0005 % If the model has a 'coarse2fine' element, then the
0006 % returned VOL applies to the coarse matrix
0007 %
0008 % if map_node == 1, then calculated volumes are the volume fraction for each node
0009 
0010 % (C) 2009 Andy Adler. License: GPL version 2 or version 3
0011 % $Id: get_elem_volume.html 2819 2011-09-07 16:43:11Z aadler $
0012 
0013 if nargin==1; map_node= 0; end
0014 
0015 % calculate element volume and surface area
0016 NODE = fwd_model.nodes';
0017 ELEM = fwd_model.elems';
0018 [d,e]= size(ELEM);
0019 
0020 VOL=zeros(e,1);
0021 ones_d = ones(1,d);
0022 d1fac = prod( 1:d-1 );
0023 if d > size(NODE,1)
0024    for i=1:e
0025        this_elem = NODE(:,ELEM(:,i)); 
0026        VOL(i)= abs(det([ones_d;this_elem])) / d1fac;
0027    end
0028 elseif d == 3 % 3D nodes in 2D mesh
0029    for i=1:e
0030        this_elem = NODE(:,ELEM(:,i)); 
0031        d12= det([ones_d;this_elem([1,2],:)])^2;
0032        d13= det([ones_d;this_elem([1,3],:)])^2;
0033        d23= det([ones_d;this_elem([2,3],:)])^2;
0034        VOL(i)= sqrt(d12 + d13 + d23 ) / d1fac;
0035    end
0036 elseif d == 2 % 3D nodes in 1D mesh (ie resistor mesh)
0037    for i=1:e
0038        this_elem = NODE(:,ELEM(:,i)); 
0039        d12= det([ones_d;this_elem([1],:)])^2;
0040        d13= det([ones_d;this_elem([2],:)])^2;
0041        d23= det([ones_d;this_elem([3],:)])^2;
0042        VOL(i)= sqrt(d12 + d13 + d23 ) / d1fac;
0043    end
0044 else
0045    error('mesh size not understood when calculating volumes')
0046 end
0047 
0048 if isfield(fwd_model,'coarse2fine')
0049    VOL= fwd_model.coarse2fine' * VOL;
0050 end
0051 
0052 % Calculate the mapping of each element onto the associated node
0053 % Map(i,j) = 1/Ne if elem j has node i
0054 if map_node
0055    map = sparse( ELEM, ones(d,1)*(1:e), 1/d, size(NODE,2),e);
0056    VOL = map * VOL;
0057 end

Generated on Tue 09-Aug-2011 11:38:31 by m2html © 2005