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

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

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

Initial import of Stark code.

Line 
1 function [re,rx,ry,rz,rbnd,perm]=reduce(e,x,y,z,b)
2 % REDUCE compute a bandwidth-reduced FEM domain connectivity list
3 %
4 %        REDUCE reduces the bandwidth of a FEM element list
5 %        using the symmetric reverse Cuthill-McKee bandwidth reduction
6 %        algorithm.  It employs the MATLAB routine SYMRCM to perform
7 %        the reordering and then permutes the remaining input arguments
8 %        according to the new node numbering.
9 %
10 %  INPUT: e        -  element list; 3 (.tri) or 4 (.ele) columns wide (REQ)
11 %         x,y,z    -  nodal coordinate lists (OPT)
12 %
13 % OUTPUT: re       -  reordered element list (REQ)
14 %         rx,ry,rz -  reordered nodal coordinates (OPT)
15 %         rb       -  reordered boundary segment list (OPT)
16 %         perm     -  permutation list (REQ)
17 %
18 %   CALL: REDUCE requires one of the following calling formats:
19 %         1) [re,perm]=reduce(e);
20 %         2) [re,rx,ry,rz,rbnd,perm]=reduce(e,x,y,z);
21 %
22 % Written by : Brian O. Blanton
23 %              October 1995
24 %
25
26 % DEFINE ERROR STRINGS
27 err1=['REDUCE requires 1 or 4 input arguments. Type "help reduce"'];
28 err2=['Element list passed to REDUCE does not have 3 or 4 columns'];
29 err3=['REDUCE requires 2 or 6 output arguments.  Type "help reduce"'];
30 err6=['node coordinate vectors must be the same length'];
31 err10=['more than 1 column in x-coordinate vector.'];
32 err11=['more than 1 column in y-coordinate vector.'];
33 err12=['more than 1 column in z-coordinate vector.'];
34
35 errusingstr=['??? Error using ==> reduce'];
36 err4=str2mat(errusingstr,...
37              ['If REDUCE has 1 input argument, it must have 2 output arguments.'],...
38              ['Type "help reduce".']);
39 err5=str2mat(errusingstr,...
40              ['If REDUCE has 4 input arguments, it must have 6 output arguments.'],...
41              ['Type "help reduce".']);
42 err14=str2mat(errusingstr,...
43               ['Maximum node number in element list ~= length of coordinate vectors'],...
44               ['Type "help reduce".']);
45
46
47 % check argument lists
48 if nargin~=1&nargin~=4
49    error(err1);
50 end
51
52 if nargout~=2&nargout~=6
53    disp(err3);
54    return
55 end
56
57 if nargin==1&nargout~=2
58    disp(err4);
59    return
60 end
61 if nargin==4&nargout~=6
62    disp(err5);
63    return
64 end
65
66 % Check size of element list
67 [nelems,ncol]=size(e);
68 if ncol < 3 | ncol > 4
69    error(err2);
70    return
71 elseif ncol==4
72    in=in(:,2:4);
73 end
74
75 if nargin==4
76    % CHECK SIZE OF X-COORDINATE VECTOR
77    % NX = NUMBER OF X-COORDINATE VALUES, S = # OF COLS
78    %
79    [nx,s]=size(x);           
80    if nx~=1&s~=1
81       error(err10);
82    end
83    x=x(:);
84    % CHECK SIZE OF Y-COORDINATE VECTOR
85    % NY = NUMBER OF Y-COORDINATE VALUES, S = # OF COLS
86    %
87    [ny,s]=size(y);           
88    if ny~=1&s~=1
89       error(err11);
90    end
91    y=y(:);
92    % CHECK SIZE OF Z-COORDINATE VECTOR
93    % NZ = NUMBER OF Z-COORDINATE VALUES, S = # OF COLS
94    %
95    [nz,s]=size(z);           
96    if nz~=1&s~=1
97       error(err12);
98    end
99    z=z(:);
100    %check coordinate lists
101    if length(x) ~= length(y)
102       error(err6);
103    end
104    if length(x) ~= length(z)
105       error(err6);
106    end
107
108    maxnode=max(max(e));
109    if maxnode ~= length(x)
110       disp(err14);
111       return
112    end
113
114 end
115
116 % Report original bandwidth to screen
117 disp(['Initial 1/2 Bandwidth = ',int2str((bwidth(e)-1)/2)])
118
119 disp('Forming adjacency matrix ...');
120 % Form (i,j) connection list from .ele element list
121 %
122 i=[e(:,1);e(:,2);e(:,3)];
123 j=[e(:,2);e(:,3);e(:,1)];
124
125 % Form the sparse adjacency matrix.
126 %
127 n = max(max(i),max(j));
128 A = sparse(i,j,1,n,n);
129 disp('Cuthill-McKee ...');
130 perm=symrcm(A);
131 perm=perm(:);
132
133 % The reduced bandwidth adjacency matrix in
134 % sparse form for boundary segment determination
135 %
136 ARBW=A(perm,perm);
137
138 disp('Permute inputs ...');
139 % Reverse the permutation "direction"
140 %
141 orignodelist=1:n;
142 l = zeros(n,1);
143 v=perm;
144 l(v)=orignodelist;
145
146 %Permute the element list
147 re=NaN*ones(size(e));
148 re(:,1) = l(e(:,1));
149 re(:,2) = l(e(:,2));
150 re(:,3) = l(e(:,3));
151 %[ju,l]=sort(re(:,1));
152 %re=re(l,:);
153
154 % Report reduced bandwidth to screen
155 disp(['Reduced 1/2 Bandwidth = ',int2str((bwidth(re)-1)/2)])
156
157 % return arguments
158 if nargin==4
159    % Permute remaining input arguments
160    rx=x(perm);
161    ry=y(perm);
162    rz=z(perm);
163    % Compute new boundary
164    disp('Computing new boundary ...');
165    ARBW = ARBW + ARBW';
166    ARBW=ARBW.*triu(ARBW);
167    B=ARBW==1;
168    [ib,jb,s]=find(B);
169    rbnd=[ib(:),jb(:)];
170 else
171    rx=perm;
172 end
173
174 %
175 %        Brian O. Blanton
176 %        Curriculum in Marine Sciences
177 %        15-1A Venable Hall
178 %        CB# 3300
179 %        University of North Carolina
180 %        Chapel Hill, NC
181 %                 27599-3300
182 %
183 %        919-962-4466
184 %        blanton@marine.unc.edu
185 %
186
Note: See TracBrowser for help on using the browser.