


Find the elements which fall along the boundary.
Mobj = find_boundary_elements(Mobj)
DESCRIPTION:
Find the elements which are bounded by the open boundaries described by
the nodes in Mobj.read_obc_nodes.
INPUT:
Mobj - required fields:
- read_obc_nodes
- obc_nodes
- tri
OUTPUT:
Mobj - new field of a cell array read_obc_elements which contains the
IDs of the elements which fall on the model open boundaries and
nObcElements which is the total number of boundary elements
along each boundary.
NOTES:
This will be pretty slow if your unstructured grid has an enormous
number of elements in it (it loops through every element and compares
against the boundary nodes). I'm sure there's a quicker way, so feel
free to have at it.
EXAMPLE USAGE:
Mobj = find_boundary_elements(Mobj)
Author(s):
Pierre Cazenave (Plymouth Marine Laboratory)
Revision history:
2013-02-26 First version.
2013-02-28 Add new field to the output (total number of boundary
elements as nObcElements).
==========================================================================

0001 function Mobj = find_boundary_elements(Mobj) 0002 % Find the elements which fall along the boundary. 0003 % 0004 % Mobj = find_boundary_elements(Mobj) 0005 % 0006 % DESCRIPTION: 0007 % Find the elements which are bounded by the open boundaries described by 0008 % the nodes in Mobj.read_obc_nodes. 0009 % 0010 % INPUT: 0011 % Mobj - required fields: 0012 % - read_obc_nodes 0013 % - obc_nodes 0014 % - tri 0015 % 0016 % OUTPUT: 0017 % Mobj - new field of a cell array read_obc_elements which contains the 0018 % IDs of the elements which fall on the model open boundaries and 0019 % nObcElements which is the total number of boundary elements 0020 % along each boundary. 0021 % 0022 % NOTES: 0023 % This will be pretty slow if your unstructured grid has an enormous 0024 % number of elements in it (it loops through every element and compares 0025 % against the boundary nodes). I'm sure there's a quicker way, so feel 0026 % free to have at it. 0027 % 0028 % EXAMPLE USAGE: 0029 % Mobj = find_boundary_elements(Mobj) 0030 % 0031 % Author(s): 0032 % Pierre Cazenave (Plymouth Marine Laboratory) 0033 % 0034 % Revision history: 0035 % 2013-02-26 First version. 0036 % 2013-02-28 Add new field to the output (total number of boundary 0037 % elements as nObcElements). 0038 % 0039 %========================================================================== 0040 0041 subname = 'find_boundary_elements'; 0042 0043 global ftbverbose 0044 if ftbverbose 0045 fprintf('\n') 0046 fprintf('begin : %s\n', subname) 0047 end 0048 0049 ne = length(Mobj.tri); % number of elements 0050 nb = length(Mobj.read_obc_nodes); % number of boundaries 0051 0052 obc_elems = cell(nb, 1); 0053 nObcElements = nan(nb, 1); 0054 0055 for i = 1:nb 0056 0057 % Do the current boundary's nodes 0058 nodeIDs = Mobj.obc_nodes(i, Mobj.obc_nodes(i, :) ~= 0); 0059 0060 f = 0; 0061 0062 for ttt = 1:ne 0063 tri = Mobj.tri(ttt, :); 0064 C = intersect(tri, nodeIDs); 0065 % Only those with a face along the boundary count (i.e. two nodes 0066 % on the boundary), particularly for the mean flow. 0067 if numel(C) == 2 0068 f = f + 1; % increment the found counter 0069 obc_elems{i}(f) = ttt; 0070 if ftbverbose 0071 fprintf('Found boundary element ID %i\n', ttt) 0072 end 0073 end 0074 end 0075 nObcElements(i) = numel(obc_elems{i}(:)); 0076 end 0077 0078 Mobj.read_obc_elements = obc_elems; 0079 Mobj.nObcElements = nObcElements; 0080 0081 % Check it's worked for the first model boundary. 0082 % xc = nodes2elems(Mobj.x, Mobj); 0083 % yc = nodes2elems(Mobj.y, Mobj); 0084 % figure(1) 0085 % clf 0086 % plot(Mobj.x, Mobj.y, 'r.', xc, yc, 'ko') 0087 % hold on 0088 % plot(xc(Mobj.read_obc_elements{1}), yc(Mobj.read_obc_elements{1}), 'gx') 0089 % axis('equal', 'tight') 0090 0091 if ftbverbose 0092 fprintf('end : %s \n', subname) 0093 end