0001 function VOL = get_elem_volume( fwd_model, map_node )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if nargin==1; map_node= 0; end
0014
0015
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
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
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
0053
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