1 |
%----------------------------------------------------------------------- |
---|
2 |
% function [in,x,y,z]=reduce_bw(wantplot,in,x,y,z) |
---|
3 |
% This function reduces the bandwidth of a fem mesh using an extremely |
---|
4 |
% simple strategy with Matlab5.1 commands |
---|
5 |
%----------------------------------------------------------------------- |
---|
6 |
function [in,x,y,z]=reduce_bw(wantplot,in,x,y,z) |
---|
7 |
%----------------------------------------------------------------------- |
---|
8 |
% Input phase: load fe data, determine hbw, and plot |
---|
9 |
% |
---|
10 |
if nargin == 1 |
---|
11 |
mesh1=input('Enter the name of the input fem mesh: ','s') |
---|
12 |
[in,x,y,z,bnd]=loadgrid(mesh1); |
---|
13 |
end |
---|
14 |
% |
---|
15 |
hbw=(bwidth(in)-1)/2; |
---|
16 |
fprintf(1,'original halfbandwidth : %5i\n',hbw) |
---|
17 |
%----------------------------------------------------------------------- |
---|
18 |
% Determine whether sorting by x or y results in smallest hbw |
---|
19 |
% |
---|
20 |
[xx,isort]=sort(x);yx=y(isort);zx=z(isort);[ii,index]=sort(isort); |
---|
21 |
inx=index(in); |
---|
22 |
hbwx=(bwidth(inx)-1)/2; |
---|
23 |
fprintf(1,'new halfbandwidth when sorting by x: %5i\n',hbwx) |
---|
24 |
% |
---|
25 |
[yy,isort]=sort(y);xy=x(isort);zy=z(isort);[ii,index]=sort(isort); |
---|
26 |
iny=index(in); |
---|
27 |
hbwy=(bwidth(iny)-1)/2; |
---|
28 |
fprintf(1,'new halfbandwidth when sorting by y: %5i\n',hbwy) |
---|
29 |
%----------------------------------------------------------------------- |
---|
30 |
% Output results |
---|
31 |
% |
---|
32 |
mesh2=input('Enter the name of the output fem mesh: ','s'); |
---|
33 |
% |
---|
34 |
if hbwx <= hbwy |
---|
35 |
x=xx;y=yx;z=zx;in=inx; |
---|
36 |
else |
---|
37 |
x=xy;y=yy;z=zy;in=iny; |
---|
38 |
end |
---|
39 |
% |
---|
40 |
hbw=(bwidth(in)-1)/2; |
---|
41 |
fprintf(1,'new halfbandwidth : %5i\n',hbwy) |
---|
42 |
% |
---|
43 |
fnod=fopen([mesh2,'.nod'],'w'); |
---|
44 |
fele=fopen([mesh2,'.ele'],'w'); |
---|
45 |
fbat=fopen([mesh2,'.bat'],'w'); |
---|
46 |
for i=1:length(x) |
---|
47 |
fprintf(fbat,'%i %f\n',i,z(i)); |
---|
48 |
fprintf(fnod,'%i %f %f\n',i,x(i),y(i)); |
---|
49 |
end |
---|
50 |
for i=1:length(in(:,1)) |
---|
51 |
fprintf(fele,'%i %i %i %i\n',i,in(i,:)); |
---|
52 |
end |
---|
53 |
fclose(fnod);fclose(fele);fclose(fbat); |
---|
54 |
%----------------------------------------------------------------------- |
---|
55 |
% Plot mesh after reading new files? |
---|
56 |
% |
---|
57 |
if wantplot == 0;break;end; |
---|
58 |
tallfigure; |
---|
59 |
hel=drawelems(in,x,y); |
---|
60 |
set(hel,'color','b'); |
---|
61 |
axis('tight') |
---|
62 |
title([mesh2,':hbw = ',num2str(hbw)]) |
---|
63 |
%----------------------------------------------------------------------- |
---|