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
    fieldin      = 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)
    Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history
   2014-02-25 Add verbose flag and some minor cosmetic changes.
   
==========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function field = smoothfield(fieldin,Mobj,SmoothFactor,nLoops,SmoothPts)
0002 % Smooth a vertex-based field using averages
0003 %
0004 % [field] = function smoothfield(fieldin,Mobj,SmoothFactor,nLoops,SmoothPts)
0005 %
0006 % DESCRIPTION:
0007 %    Smooth a vertex based field
0008 %
0009 % INPUT
0010 %    Mobj         = Matlab mesh object
0011 %    fieldin      = vertex based field
0012 %    SmoothFactor = smoothing factor (0, no smoothing, 1 full smoothing)
0013 %    nLoops       = number of smoothing iterations
0014 %    SmoothPts    = list of vertices to smooth [optional, default = all]
0015 %
0016 % OUTPUT:
0017 %    field = smoothed, vertex-based field
0018 %
0019 % EXAMPLE USAGE
0020 %    Mobj.h = smoothfield(Mobj.h,Mobj,0.5,4)
0021 %
0022 % Author(s):
0023 %    Geoff Cowles (University of Massachusetts Dartmouth)
0024 %    Pierre Cazenave (Plymouth Marine Laboratory)
0025 %
0026 % Revision history
0027 %   2014-02-25 Add verbose flag and some minor cosmetic changes.
0028 %
0029 %==========================================================================
0030 
0031 global ftbverbose;
0032 [~, subname] = fileparts(mfilename('fullpath'));
0033 if ftbverbose
0034     fprintf('\nbegin : %s\n', subname)
0035 end
0036 
0037 %--------------------------------------------------------------------------
0038 % Parse input
0039 %--------------------------------------------------------------------------
0040 
0041 if exist('fieldin', 'var') * exist('Mobj', 'var') * exist('SmoothFactor', 'var') * exist('nLoops', 'var') == 0
0042     error('Arguments to smoothfield are missing')
0043 end
0044 
0045 if exist('SmoothPts', 'var')
0046     nPts = length(SmoothPts);
0047 else
0048     nPts       = Mobj.nVerts;
0049     SmoothPts  = 1:Mobj.nVerts;
0050 end
0051 
0052 if ~Mobj.have_mets
0053     error('Cannot smooth field, need mesh metrics for smoothing, use setup_metrics.')
0054 end
0055 
0056 %--------------------------------------------------------------------------
0057 % Smoothing Loops
0058 %--------------------------------------------------------------------------
0059 
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 if ftbverbose
0075     fprintf('end   : %s\n', subname)
0076 end

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005