1 |
%DRAWELEMS4 draw FEM element configuration |
---|
2 |
% DRAWELEMS4 a routine to draw element boundries given an element, |
---|
3 |
% node, and (optionally) bathymetry lists. If no z- |
---|
4 |
% coordinates are given, the mesh is drawn in 2-D. |
---|
5 |
% Otherwise, the mesh is drawn in 3-D, with the view |
---|
6 |
% perspective set to azimuth=-27 deg and |
---|
7 |
% elevation=30 deg. See the MATLAB VIEW command for |
---|
8 |
% more on view points. |
---|
9 |
% |
---|
10 |
% Input : |
---|
11 |
% elems - a 3- or 4-column matrix giving the nodes comprising |
---|
12 |
% each element. If there are 3 columns, each line |
---|
13 |
% should be "n1 n2 n3", a triangular element |
---|
14 |
% description. If there are 4 columns, each line |
---|
15 |
% should be "n1 n2 n3 n4", a quadrilateral |
---|
16 |
% element description. |
---|
17 |
% x - an x-coord list of nodes; |
---|
18 |
% y - a y-coord list of nodes; |
---|
19 |
% z - a z-coord list of nodes (optional); |
---|
20 |
% |
---|
21 |
% x,y,z must be 1-D vectors. |
---|
22 |
% |
---|
23 |
% Output : DRAWELEMS returns the handle of the element object. |
---|
24 |
% |
---|
25 |
% NOTES: 1) Element line-segments are drawn in solid white. |
---|
26 |
% This will be an optional argument in the future. |
---|
27 |
% 2) Existing plots are added to. |
---|
28 |
% 3) Axis limits are NOT set. 'axis('equal')' may |
---|
29 |
% need to be issued by the user, if it has not already. |
---|
30 |
% |
---|
31 |
% Call as: >> hel=drawelems4(elems,x,y,z); |
---|
32 |
% |
---|
33 |
% Written by: Brian O. Blanton |
---|
34 |
% |
---|
35 |
function hel=drawelems4(elems,x,y,z) |
---|
36 |
|
---|
37 |
% DEFINE ERROR STRINGS |
---|
38 |
err1=['matrix of elements must be 3 or 4 columns wide']; |
---|
39 |
err2=['more than 1 column in x-coordinate vector.']; |
---|
40 |
err3=['more than 1 column in y-coordinate vector.']; |
---|
41 |
err4=['more than 1 column in z-coordinate vector.']; |
---|
42 |
err6=['lengths of x & y must be equal']; |
---|
43 |
err7=['lengths of x, y, & z must be equal']; |
---|
44 |
|
---|
45 |
% CHECK SIZE OF ELEMENT MATRIX |
---|
46 |
% NELEMS = NUMBER OF ELEMENTS, S = # OF COLS |
---|
47 |
% |
---|
48 |
[nelems,s]=size(elems); |
---|
49 |
if s<3 | s>4 |
---|
50 |
error(err1); |
---|
51 |
elseif(s==4) |
---|
52 |
elems=elems(:,2:4); |
---|
53 |
end |
---|
54 |
|
---|
55 |
% COPY FIRST COLUMN TO LAST TO CLOSE ELEMENTS |
---|
56 |
% |
---|
57 |
elems=elems(:,[1 2 3 1]); |
---|
58 |
|
---|
59 |
% CHECK SIZE OF X-COORDINATE VECTOR |
---|
60 |
% NX = NUMBER OF X-COORDINATE VALUES, S = # OF COLS |
---|
61 |
% |
---|
62 |
[nx,s]=size(x); |
---|
63 |
if nx~=1&s~=1 |
---|
64 |
error(err2); |
---|
65 |
end |
---|
66 |
|
---|
67 |
% CHECK SIZE OF Y-COORDINATE VECTOR |
---|
68 |
% NY = NUMBER OF Y-COORDINATE VALUES, S = # OF COLS |
---|
69 |
% |
---|
70 |
[ny,s]=size(y); |
---|
71 |
if ny~=1&s~=1 |
---|
72 |
error(err3); |
---|
73 |
end |
---|
74 |
|
---|
75 |
% CHECK LENGTHS OF X & Y |
---|
76 |
% |
---|
77 |
if nx~=ny |
---|
78 |
error(err6); |
---|
79 |
end |
---|
80 |
|
---|
81 |
% CHECK SIZE OF Z-COORDINATE VECTOR |
---|
82 |
% NZ = NUMBER OF Z-COORDINATE VALUES, S = # OF COLS |
---|
83 |
% |
---|
84 |
if exist('z') |
---|
85 |
[nz,s]=size(z); |
---|
86 |
if nz~=1&s~=1 |
---|
87 |
error(err4); |
---|
88 |
end |
---|
89 |
% check lengths of x & z |
---|
90 |
if nx~=nz |
---|
91 |
error(err7); |
---|
92 |
end |
---|
93 |
end |
---|
94 |
|
---|
95 |
% MAKE SURE NUMBER OF NODES EQUALS THE MAX |
---|
96 |
% NODE NUMBER FOUND IN ELEMENT MATRIX |
---|
97 |
% MAXNN = MAXIMUM NODE NUMBER IN ELEMENT MATRIX |
---|
98 |
% |
---|
99 |
maxnn=max(max(elems)); |
---|
100 |
if maxnn~=length(x) | maxnn~=length(y) |
---|
101 |
disp('length of x, y, or z does not equal the') |
---|
102 |
disp('max node number found in element list.'); |
---|
103 |
error; |
---|
104 |
end |
---|
105 |
|
---|
106 |
elems=elems'; |
---|
107 |
[m,n]=size(elems); |
---|
108 |
xt=x(elems); |
---|
109 |
yt=y(elems); |
---|
110 |
if n~=1 |
---|
111 |
if m>n |
---|
112 |
xt=reshape(xt,n,m); |
---|
113 |
yt=reshape(yt,n,m); |
---|
114 |
else |
---|
115 |
xt=reshape(xt,m,n); |
---|
116 |
yt=reshape(yt,m,n); |
---|
117 |
end |
---|
118 |
xt=[xt |
---|
119 |
NaN*ones(size(1:length(xt)))]; |
---|
120 |
yt=[yt |
---|
121 |
NaN*ones(size(1:length(yt)))]; |
---|
122 |
end |
---|
123 |
xt=xt(:); |
---|
124 |
yt=yt(:); |
---|
125 |
% |
---|
126 |
% DRAW GRID |
---|
127 |
% |
---|
128 |
if exist('z') |
---|
129 |
zt=z(elems); |
---|
130 |
zt=reshape(zt,m,n); |
---|
131 |
zt=[zt |
---|
132 |
NaN*ones(size(1:length(zt)))]; |
---|
133 |
zt=zt(:); |
---|
134 |
hel=line(xt,yt,zt,'Linewidth',.05,'LineStyle','-','Color',[.8 .8 .8]); |
---|
135 |
% |
---|
136 |
% SET 3-D VIEWPOINT |
---|
137 |
% |
---|
138 |
view(-27,30); |
---|
139 |
else |
---|
140 |
hel=line(xt,yt,'Linewidth',.05,'LineStyle','-','Color',[.8 .8 .8]); |
---|
141 |
end |
---|
142 |
set(hel,'Tag','elements'); |
---|
143 |
|
---|
144 |
% |
---|
145 |
% Brian O. Blanton |
---|
146 |
% Curr. in Marine Sciences |
---|
147 |
% 15-1A Venable Hall |
---|
148 |
% CB# 3300 |
---|
149 |
% Uni. of North Carolina |
---|
150 |
% Chapel Hill, NC |
---|
151 |
% 27599-3300 |
---|
152 |
% |
---|
153 |
% 919-962-4466 |
---|
154 |
% blanton@cuda.chem.unc.edu |
---|
155 |
% |
---|