


AVERAGING - smooths the input over the mesh
This routine takes a list over the elements or the grids in input
and return a list over the grids.
For each iterations it computes the average over each element (average
of the vertices values) and then computes the average over each grid
by taking the average of the element around a grid weighted by the
elements volume
Usage:
md=averaging(md,data,iterations)
Examples:
velsmoothed=averaging(md,md.vel,4);
pressure=averaging(md,md.pressure,0);

0001 function average=averaging(md,data,iterations) 0002 %AVERAGING - smooths the input over the mesh 0003 % 0004 % This routine takes a list over the elements or the grids in input 0005 % and return a list over the grids. 0006 % For each iterations it computes the average over each element (average 0007 % of the vertices values) and then computes the average over each grid 0008 % by taking the average of the element around a grid weighted by the 0009 % elements volume 0010 % 0011 % Usage: 0012 % md=averaging(md,data,iterations) 0013 % 0014 % Examples: 0015 % velsmoothed=averaging(md,md.vel,4); 0016 % pressure=averaging(md,md.pressure,0); 0017 0018 if length(data)~=md.numberofelements & length(data)~=md.numberofgrids 0019 error('averaging error message: data not supported yet'); 0020 end 0021 0022 %initialization 0023 weights=zeros(md.numberofgrids,1); 0024 areas=zeros(md.numberofelements,1); 0025 data=data(:); 0026 0027 %load some variables (it is much faster if the variab;es are loaded from md once for all) 0028 index=md.elements; 0029 numberofgrids=md.numberofgrids; 0030 numberofelements=md.numberofelements; 0031 0032 %build some variables 0033 line=index(:); 0034 if strcmpi(md.type,'3d') 0035 rep=6; 0036 else 0037 rep=3; 0038 end 0039 summation=1/rep*ones(rep,1); 0040 linesize=rep*numberofelements; 0041 0042 %compute the volume of each element 0043 areas=area(md); 0044 0045 %update weights that holds the volume of all the element holding the grid i 0046 weights=sparse(line,ones(linesize,1),repmat(areas,rep,1),numberofgrids,1); 0047 0048 %initialization 0049 if length(data)==numberofelements 0050 average_grid=sparse(line,ones(linesize,1),repmat(areas.*data,rep,1),numberofgrids,1); 0051 average_grid=average_grid./weights; 0052 else 0053 average_grid=data; 0054 end 0055 0056 %loop over iteration 0057 for i=1:iterations 0058 average_el=average_grid(index)*summation; 0059 average_grid=sparse(line,ones(linesize,1),repmat(areas.*average_el,rep,1),numberofgrids,1); 0060 average_grid=average_grid./weights; 0061 end 0062 0063 %return output as a full matrix (C code do not like sparse matrices) 0064 average=full(average_grid);