


Add a set of obc nodes comprising a single obc boundary to Mesh structure
using a list of nodes.
Mobj = add_obc_nodes_list(Mobj, Nodelist, ObcName, ObcType)
DESCRIPTION:
Add a set of open boundary nodes for a given boundary using a list of
nodes.
INPUT
Mobj = Matlab mesh object with fields:
- nVerts - number of nodes in the domain
- nativeCoords - coordinates in which the model runs (only for
plotting the figure).
- x, y, lon, lat - mesh node coordinates (either cartesian or
spherical) (only for plotting the figure).
- tri - model grid triangulation (only for plotting the figure)
- h - model grid depths (only for plotting the figure)
Nodelist = List of nodes
ObcName = Name of the Open Boundary
ObcType = FVCOM Flag for OBC Type
plotFig = [optional] show a figure of the mesh (1 = yes)
OUTPUT:
Mobj = Matlab mesh object with an additional obc nodelist
EXAMPLE USAGE
Nodelist = 1:100;
Mobj = add_obc_nodes_list(Mobj, Nodelist, 'OpenOcean')
Author(s):
Geoff Cowles (University of Massachusetts Dartmouth)
Pierre Cazenave (Plymouth Marine Laboratory)
Karen Amoudry (National Oceanography Centre, Liverpool)
Revision history:
2012-11-26 Add ability to turn off the figures.
2013-01-02 KJA bug fix: amended usage of 'unique' in line 53 to
prevent it from sorting the values it returns. Amended by Pierre to
support pre-2012 versions of MATLAB whilst giving the same result.
2015-02-23 Output number of nodes if the verbose flag is set.
2017-08-31 Update the help to clarify what's needed.
==========================================================================

0001 function Mobj = add_obc_nodes_list(Mobj, Nodelist, ObcName, ObcType, plotFig) 0002 % Add a set of obc nodes comprising a single obc boundary to Mesh structure 0003 % using a list of nodes. 0004 % 0005 % Mobj = add_obc_nodes_list(Mobj, Nodelist, ObcName, ObcType) 0006 % 0007 % DESCRIPTION: 0008 % Add a set of open boundary nodes for a given boundary using a list of 0009 % nodes. 0010 % 0011 % INPUT 0012 % Mobj = Matlab mesh object with fields: 0013 % - nVerts - number of nodes in the domain 0014 % - nativeCoords - coordinates in which the model runs (only for 0015 % plotting the figure). 0016 % - x, y, lon, lat - mesh node coordinates (either cartesian or 0017 % spherical) (only for plotting the figure). 0018 % - tri - model grid triangulation (only for plotting the figure) 0019 % - h - model grid depths (only for plotting the figure) 0020 % Nodelist = List of nodes 0021 % ObcName = Name of the Open Boundary 0022 % ObcType = FVCOM Flag for OBC Type 0023 % plotFig = [optional] show a figure of the mesh (1 = yes) 0024 % 0025 % OUTPUT: 0026 % Mobj = Matlab mesh object with an additional obc nodelist 0027 % 0028 % EXAMPLE USAGE 0029 % Nodelist = 1:100; 0030 % Mobj = add_obc_nodes_list(Mobj, Nodelist, 'OpenOcean') 0031 % 0032 % Author(s): 0033 % Geoff Cowles (University of Massachusetts Dartmouth) 0034 % Pierre Cazenave (Plymouth Marine Laboratory) 0035 % Karen Amoudry (National Oceanography Centre, Liverpool) 0036 % 0037 % Revision history: 0038 % 2012-11-26 Add ability to turn off the figures. 0039 % 2013-01-02 KJA bug fix: amended usage of 'unique' in line 53 to 0040 % prevent it from sorting the values it returns. Amended by Pierre to 0041 % support pre-2012 versions of MATLAB whilst giving the same result. 0042 % 2015-02-23 Output number of nodes if the verbose flag is set. 0043 % 2017-08-31 Update the help to clarify what's needed. 0044 % 0045 %========================================================================== 0046 [~, subname] = fileparts(mfilename('fullpath')); 0047 global ftbverbose 0048 if ftbverbose 0049 fprintf('\nbegin : %s\n', subname) 0050 end 0051 0052 % Do we want a figure showing how we're getting along? 0053 if nargin == 4 0054 plotFig = 0; 0055 end 0056 0057 %-------------------------------------------------------------------------- 0058 % Get a unique list and make sure they are in the range of node numbers 0059 %-------------------------------------------------------------------------- 0060 % Make this works in versions of MATLAB older than 2012a (newer versions 0061 % can just use unique(A, 'stable'), but checking versions is a pain). 0062 [~, Nidx] = unique(Nodelist); 0063 Nodelist = Nodelist(sort(Nidx)); 0064 0065 assert(max(Nodelist) <= Mobj.nVerts, 'Your open boundary node number (%d) exceeds the total number of nodes in the domain (%d)', max(Nodelist), Mobj.nVerts) 0066 0067 %-------------------------------------------------------------------------- 0068 % Plot the mesh 0069 %-------------------------------------------------------------------------- 0070 if plotFig == 1 0071 if strcmpi(Mobj.nativeCoords(1:3), 'car') 0072 x = Mobj.x; 0073 y = Mobj.y; 0074 else 0075 x = Mobj.lon; 0076 y = Mobj.lat; 0077 end 0078 0079 figure 0080 patch('Vertices', [x, y] , 'Faces', Mobj.tri, ... 0081 'Cdata', Mobj.h, 'edgecolor', 'k', 'facecolor', 'interp') 0082 hold on 0083 whos Nlist 0084 plot(x(Nodelist), y(Nodelist), 'ro'); 0085 axis('equal', 'tight') 0086 title('open boundary nodes'); 0087 end 0088 0089 % add to mesh object 0090 npts = numel(Nodelist); 0091 Mobj.nObs = Mobj.nObs + 1; 0092 Mobj.nObcNodes(Mobj.nObs) = npts; 0093 Mobj.obc_nodes(Mobj.nObs,1:npts) = Nodelist; 0094 Mobj.obc_name{Mobj.nObs} = ObcName; 0095 Mobj.obc_type(Mobj.nObs) = ObcType; 0096 0097 if ftbverbose 0098 fprintf('found %d open boundary nodes', npts) 0099 end 0100 0101 if ftbverbose 0102 fprintf('\nend : %s\n', subname) 0103 end 0104