Home > utilities > find_relaxation_boundary.m

find_relaxation_boundary

PURPOSE ^

Find the elements which fall along the boundary for a nested

SYNOPSIS ^

function Mobj = find_relaxation_boundary(Mobj)

DESCRIPTION ^

 Find the elements which fall along the boundary for a nested
 configuration.

 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 and which go to a depth of
   Mobj.relax_bc_Nnodes.

 INPUT:
   Mobj - required fields:
           - read_obc_nodes - cell array of open boundary node IDs.
           - tri - mesh triangulation
           - relax_bc_Nnodes - array (length is Mobj.nObs) of number of
           elements from the open boundary over which to relax the nested
           inputs.

 OUTPUT:
   Mobj - mesh object with the following new fields:
           - relaxBC_nodes = node IDs for the relaxed region
           - relaxBC_elems = element IDs for the relaxed region
           - relaxnBC_nodes = number of nodes in the relaxed region
           - relaxnBC_elems = number of elements in the relaxed region

 EXAMPLE USAGE:
   Mobj = find_relaxation_boundary(Mobj)

 Author(s):
   Pierre Cazenave (Plymouth Marine Laboratory)
   Ricardo Torres (Plymouth Marine Laboratory)

 Revision history:
   2016-12-15 Add support for varying depth of nested region over each
   open boundary. Also update help to actually refer to what this function
   does.

 Author(s):
   Pierre Cazenave (Plymouth Marine Laboratory)
   Ricardo Torres (Plymouth Marine Laboratory)

 Revision history:
   2016-12-15 Update help to actually refer to what this function does.

==========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Mobj = find_relaxation_boundary(Mobj)
0002 % Find the elements which fall along the boundary for a nested
0003 % configuration.
0004 %
0005 % Mobj = find_boundary_elements(Mobj)
0006 %
0007 % DESCRIPTION:
0008 %   Find the elements which are bounded by the open boundaries described by
0009 %   the nodes in Mobj.read_obc_nodes and which go to a depth of
0010 %   Mobj.relax_bc_Nnodes.
0011 %
0012 % INPUT:
0013 %   Mobj - required fields:
0014 %           - read_obc_nodes - cell array of open boundary node IDs.
0015 %           - tri - mesh triangulation
0016 %           - relax_bc_Nnodes - array (length is Mobj.nObs) of number of
0017 %           elements from the open boundary over which to relax the nested
0018 %           inputs.
0019 %
0020 % OUTPUT:
0021 %   Mobj - mesh object with the following new fields:
0022 %           - relaxBC_nodes = node IDs for the relaxed region
0023 %           - relaxBC_elems = element IDs for the relaxed region
0024 %           - relaxnBC_nodes = number of nodes in the relaxed region
0025 %           - relaxnBC_elems = number of elements in the relaxed region
0026 %
0027 % EXAMPLE USAGE:
0028 %   Mobj = find_relaxation_boundary(Mobj)
0029 %
0030 % Author(s):
0031 %   Pierre Cazenave (Plymouth Marine Laboratory)
0032 %   Ricardo Torres (Plymouth Marine Laboratory)
0033 %
0034 % Revision history:
0035 %   2016-12-15 Add support for varying depth of nested region over each
0036 %   open boundary. Also update help to actually refer to what this function
0037 %   does.
0038 %
0039 % Author(s):
0040 %   Pierre Cazenave (Plymouth Marine Laboratory)
0041 %   Ricardo Torres (Plymouth Marine Laboratory)
0042 %
0043 % Revision history:
0044 %   2016-12-15 Update help to actually refer to what this function does.
0045 %
0046 %==========================================================================
0047 
0048 subname = 'find_boundary_elements';
0049 
0050 global ftbverbose
0051 if ftbverbose
0052     fprintf('\nbegin : %s\n', subname)
0053 end
0054 
0055 nb = length(Mobj.read_obc_nodes); % number of boundaries
0056 bc_width = Mobj.relax_bc_Nnodes;
0057 obc_elems = cell(nb, 1);
0058 nObcElements = nan(nb, 1);
0059 
0060 for i = 1:nb
0061     
0062     % Do the current boundary's nodes
0063     nodeIDs = Mobj.read_obc_nodes{i};
0064     [C1,~] = ismember(Mobj.tri(:,1), nodeIDs(:), 'rows');
0065     [C2,~] = ismember(Mobj.tri(:,2), nodeIDs(:), 'rows');
0066     [C3,~] = ismember(Mobj.tri(:,3), nodeIDs(:), 'rows');
0067     obc_elems{i} = unique([find(C1); find(C2); find(C3)]);
0068     if iscolumn(obc_elems{i})
0069         obc_elems{i} = obc_elems{i}';
0070     end
0071     nObcElements(i) = numel(obc_elems{i}(:));
0072     
0073 end
0074 Mobj.relaxBC_nodes = {[Mobj.read_obc_nodes{:}]};
0075 Mobj.relaxBC_elems = {[obc_elems{:}]};
0076 
0077 for bb = 2:bc_width
0078     nodeIDs = Mobj.tri(Mobj.relaxBC_elems{bb-1}, :);
0079     nodeIDs = unique(nodeIDs(:));
0080     % Find connected nodes.
0081     bc_nodes = Mobj.relaxBC_nodes{1:bb-1};
0082     if ~iscolumn(bc_nodes)
0083         bc_nodes = bc_nodes';
0084     end
0085     C1 = setdiff(nodeIDs(:), bc_nodes, 'rows');
0086     Mobj.relaxBC_nodes(bb) = {C1};
0087     % And now elements.
0088     [C1,~] = ismember(Mobj.tri(:,1), nodeIDs(:), 'rows');
0089     [C2,~] = ismember(Mobj.tri(:,2), nodeIDs(:), 'rows');
0090     [C3,~] = ismember(Mobj.tri(:,3), nodeIDs(:), 'rows');
0091     bc_elems = Mobj.relaxBC_elems{1:bb-1};
0092     if ~iscolumn(bc_elems)
0093         bc_elems = bc_elems';
0094     end
0095     C1 = setdiff(unique([find(C1); find(C2); find(C3)]), ...
0096         bc_elems, 'rows');
0097     Mobj.relaxBC_elems(bb) = {C1};
0098 end
0099 
0100 all_nest_elems = Mobj.relaxBC_elems{:};
0101 all_nest_nodes = Mobj.relaxBC_nodes{:};
0102 Mobj.relaxnBC_elems = length(all_nest_elems);
0103 Mobj.relaxnBC_nodes = length(all_nest_nodes);
0104 
0105 % Check it's worked for the first model boundary.
0106 % xc = nodes2elems(Mobj.x, Mobj);
0107 % yc = nodes2elems(Mobj.y, Mobj);
0108 % figure
0109 % clf
0110 % triplot(Mobj.tri,Mobj.x,Mobj.y,'k');
0111 % hold on
0112 %
0113 % symbols = {'r.', 'k.', 'rx', 'kx', 'ro', 'ko'};
0114 % for nn = 1:length(Mobj.relaxBC_nodes)
0115 %     plot(Mobj.x(Mobj.relaxBC_nodes{nn}), ...
0116 %         Mobj.y(Mobj.relaxBC_nodes{nn}), ...
0117 %         symbols{mod(nn, length(Mobj.relaxBC_nodes)) + 1})
0118 % end
0119 % plot(xc(Mobj.relaxBC_elems{3}), yc(Mobj.relaxBC_elems{3}), 'kx')
0120 % axis('equal', 'tight')
0121 
0122 if ftbverbose
0123     fprintf('end   : %s \n', subname)
0124 end

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