Home > fvcom_prepro > smoothfield.m

smoothfield

PURPOSE ^

Smooth a vertex-based field using averages

SYNOPSIS ^

function [field] = smoothfield(fieldin,Mobj,SmoothFactor,nLoops,SmoothPts)

DESCRIPTION ^

 Smooth a vertex-based field using averages  

 [field] = function smoothfield(fieldin,Mobj,SmoothFactor,nLoops,SmoothPts)  

 DESCRIPTION:
    Smooth a vertex based field 

 INPUT
    Mobj         = Matlab mesh object
    fielin       = vertex based field
    SmoothFactor = smoothing factor (0, no smoothing, 1 full smoothing)
    nLoops       = number of smoothing iterations
    SmoothPts    = list of vertices to smooth [optional, default = all]

 OUTPUT:
    field = smoothed, vertex-based field

 EXAMPLE USAGE
    Mobj.h = smoothfield(Mobj.h,Mobj,0.5,4)

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [field]  = smoothfield(fieldin,Mobj,SmoothFactor,nLoops,SmoothPts)
0002 
0003 % Smooth a vertex-based field using averages
0004 %
0005 % [field] = function smoothfield(fieldin,Mobj,SmoothFactor,nLoops,SmoothPts)
0006 %
0007 % DESCRIPTION:
0008 %    Smooth a vertex based field
0009 %
0010 % INPUT
0011 %    Mobj         = Matlab mesh object
0012 %    fielin       = vertex based field
0013 %    SmoothFactor = smoothing factor (0, no smoothing, 1 full smoothing)
0014 %    nLoops       = number of smoothing iterations
0015 %    SmoothPts    = list of vertices to smooth [optional, default = all]
0016 %
0017 % OUTPUT:
0018 %    field = smoothed, vertex-based field
0019 %
0020 % EXAMPLE USAGE
0021 %    Mobj.h = smoothfield(Mobj.h,Mobj,0.5,4)
0022 %
0023 % Author(s):
0024 %    Geoff Cowles (University of Massachusetts Dartmouth)
0025 %
0026 % Revision history
0027 %
0028 %==============================================================================
0029 subname = 'smoothfield';
0030 %fprintf('\n')
0031 %fprintf(['begin : ' subname '\n'])
0032 
0033 %------------------------------------------------------------------------------
0034 % Parse input
0035 %------------------------------------------------------------------------------
0036 
0037 if(exist('fieldin')*exist('Mobj')*exist('SmoothFactor')*exist('nLoops') == 0)
0038     error('arguments to smoothfield are missing')
0039 end;
0040 
0041 if(exist('SmoothPts'))
0042     nPts = length(SmoothPts);
0043 else
0044     nPts       = Mobj.nVerts;
0045     SmoothPts  = 1:Mobj.nVerts;
0046 end;
0047 
0048 if(~Mobj.have_mets)
0049     error('cannot smooth field, need mesh metrics for smoothing, use setup_metrics')
0050 end;
0051 
0052 %------------------------------------------------------------------------------
0053 % Smoothing Loops
0054 %------------------------------------------------------------------------------
0055 
0056 % initialize iteration
0057 field = fieldin;
0058 
0059 %iterate
0060 for ll=1:nLoops;
0061     field = fieldin;
0062     for ii=1:nPts;
0063           i = SmoothPts(ii);
0064           ss = 0.;
0065           for k=1:Mobj.ntsn(i); 
0066             node = Mobj.nbsn(i,k);
0067             ss = ss + field(node)/real(Mobj.ntsn(i));
0068           end;
0069           fieldin(i) = (1-SmoothFactor)*field(i) + SmoothFactor*ss;
0070     end;
0071 end;
0072 field = fieldin; 
0073 
0074 
0075 %fprintf(['end   : ' subname '\n'])
0076

Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005