NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FEM/detbndy.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 % DETBNDY compute a boundary segment list for a FEM domain
2 %
3 % DETBNDY bnd=detbndy(e,outfile);
4 %         This function computes a boundary for the FEM domain
5 %         described a file containing element connectivity list (e).
6 %         It uses sparse matrix techniques to determine the element
7 %         edges on the boundary of the FEM domain.
8 %
9 % Input:  ele -  element list; 3 (.tri) or 4 (.ele) columns wide
10 %         file - name of output file (.bnd extension)
11 %                (*optional*)
12 % Output: bnd -  a 2-column list of boundary-node numbers, returned
13 %                to the local workspace
14 %
15 %         The output boundary list are pairs of node numbers, not
16 %         coordinates, describing the edges of elements on the
17 %         exterior of the domain, including islands.  The segments
18 %         are not connected.
19 %
20 %         Call as: bnd=detbndy(e,outfile);
21 %
22 % Written by : Brian O. Blanton at The University of North Carolina
23 %              at Chapel Hill, Mar 1995.
24 %
25 function bnd=detbndy(in,outfile)
26
27 % DEFINE ERROR STRINGS
28 err1=['Max input arguments to DETBNDY. Type "help detbndy"'];
29 err2=['Element list passed to DETBNDY does not have 3 or 4 columns'];
30 err3=str2mat(['??? Error using ==> detbndy'],...
31              ['DETBNDY must have one output argument.'],...
32              ['Call as: >>  bnd=detbndy(in);'],...
33              [' ']);
34 % check argument list
35
36 if nargin>2
37    error(err1);
38 end
39
40 if nargout~=1
41    disp(err3);
42    return
43 end
44  
45  
46 % Check size of element list
47 [nelems,ncol]=size(in);
48 if ncol < 3 | ncol > 4
49    error(err2);
50    return
51 elseif ncol==4
52    in=in(:,2:4);
53 end
54
55 % Form (i,j) connection list from .ele element list
56 %
57 i=[in(:,1);in(:,2);in(:,3)];
58 j=[in(:,2);in(:,3);in(:,1)];
59
60 % Form the sparse adjacency matrix and add transpose.
61 %
62 n = max(max(i),max(j));
63 A = sparse(i,j,-1,n,n);
64 A = A + A';
65
66 % Consider only the upper part of A, since A is symmetric
67 %
68 A=A.*triu(A);
69
70 % The boundary segments are A's with value == 1
71 %
72 B=A==1;
73
74 % Extract the row,col from B for the boundary list.
75 %
76 [ib,jb,s]=find(B);
77 bnd=[ib(:),jb(:)];
78
79 % Output .bnd list
80
81 if nargin==2
82    fp=fopen(outfile,'w');
83    for i=1:length(bnd)
84       fprintf(fp,'%d %d\n', bnd(i,1),bnd(i,2)); 
85    end
86 end
87 return;
88 %
89 %        Brian O. Blanton
90 %        Curriculum in Marine Sciences
91 %        15-1A Venable Hall
92 %        CB# 3300
93 %        University of North Carolina
94 %        Chapel Hill, NC
95 %                 27599-3300
96 %
97 %        919-962-4466
98 %        blanton@marine.unc.edu
99 %
100
Note: See TracBrowser for help on using the browser.