-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotContour.m
More file actions
139 lines (122 loc) · 4.63 KB
/
plotContour.m
File metadata and controls
139 lines (122 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
% Written By: Matthew Jon Pais, University of Florida (2010)
% Website: http://sites.google.com/site/matthewjpais/Home
% Email: mpais@ufl.edu, matthewjpais@gmail.com
function plotContour(Sxx,Sxy,Syy,Svm)
% This file plots the stress contours from the stress values calculated by
% elemStress.m
global CONNEC CRACK DOMAIN INC PLOT VOID XYZ
nXElem = DOMAIN(1); % Number of elements in x-direction
nYElem = DOMAIN(2); % Number of elements in y-direction
nNodes = (nXElem+1)*(nYElem+1); % Number of nodes
lXElem = DOMAIN(3); % Length of elements in x-direction
X = zeros(nXElem+1,nYElem+1); Y = X; Z = X;
% Average nodal values if not already done
if size(Sxx,2) == 4 % Average nodal stress values
stressXX = Sxx; stressXY = Sxy; stressYY = Syy; stressVM = Svm;
Sxx = zeros(nNodes,2); Sxy = Sxx; Syy = Sxx; Svm = Sxx;
% Construct stress vectors
for iE = 1:(nXElem*nYElem)
for iN = 1:4
nNode = CONNEC(iE,iN+1);
Sxx(nNode,:) = Sxx(nNode,:) + [stressXX(iE,iN) 1];
Sxy(nNode,:) = Sxy(nNode,:) + [stressXY(iE,iN) 1];
Syy(nNode,:) = Syy(nNode,:) + [stressYY(iE,iN) 1];
Svm(nNode,:) = Svm(nNode,:) + [stressVM(iE,iN) 1];
end
end
% Average nodal stress values
Sxx(:,1) = Sxx(:,1)./Sxx(:,2); Sxx(:,2) = [];
Sxy(:,1) = Sxy(:,1)./Sxy(:,2); Sxy(:,2) = [];
Syy(:,1) = Syy(:,1)./Syy(:,2); Syy(:,2) = [];
Svm(:,1) = Svm(:,1)./Svm(:,2); Svm(:,2) = [];
end
% Plot the contours
if PLOT(5,3) == 1, nPlot = 1; else nPlot = 3; end
for i = 1:nPlot
figure; hold on;
if nPlot == 3
if i == 1
z = Sxx;
title('\sigma_x_x')
elseif i == 2
z = Sxy;
title('\sigma_x_y')
elseif i == 3
z = Syy;
title('\sigma_y_y')
end
else
z = Svm;
title('\sigma_v_m')
end
iNode = 1;
for yE = 1:(nYElem+1)
for xE = 1:(nXElem+1)
X(xE,yE) = XYZ(iNode,2);
Y(xE,yE) = XYZ(iNode,3);
Z(xE,yE) = z(iNode);
iNode = iNode+1;
end
end
if PLOT(5,2) == 1 % Filled contour
contourf(X,Y,Z,40,'LineStyle','none');
else
contour(X,Y,Z); % Contour lines
end
% Plot the crack
if isempty(CRACK) == 0
nPt = size(CRACK,1);
for iPt = 2:nPt
xc = [CRACK(iPt-1,1) CRACK(iPt,1)];
yc = [CRACK(iPt-1,2) CRACK(iPt,2)];
plot(xc,yc,'w','LineWidth',2)
end
end
% Plot the inclusions
if isempty(INC) == 0
nINC = size(INC,1);
xMax = nXElem*lXElem;
yMax = nYElem*lXElem;
for iI = 1:nINC
if size(INC,2)==3
xc = INC(iI,1); yc = INC(iI,2); rc = INC(iI,3);
theta = (0:256)*pi*2/256;
xp = rc*cos(theta)+xc;
yp = rc*sin(theta)+yc;
for j = 1:length(xp)
if (xp(j) > xMax) || (xp(j) < 0)
xp(j) = NaN; yp(j) = NaN;
elseif (yp(j) > yMax) || (yp(j) < 0)
xp(j) = NaN; yp(j) = NaN;
end
end
plot(xp,yp,'w','LineWidth',2)
else
line([INC(iI,1), INC(iI,3)], [INC(iI,2), INC(iI,4)], 'LineWidth', 2)
end
end
end
% Plot the voids
if isempty(VOID) == 0
nVOID = size(VOID,1);
xMax = nXElem*lXElem;
yMax = nYElem*lXElem;
for iI = 1:nVOID
xc = VOID(iI,1); yc = VOID(iI,2); rc = VOID(iI,3);
theta = 0:0.5:360;
xp = rc*cosd(theta)+xc;
yp = rc*sind(theta)+yc;
for j = 1:length(xp)
if (xp(j) > xMax) || (xp(j) < 0)
xp(j) = 0; yp(j) = 0;
elseif (yp(j) > yMax) || (yp(j) < 0)
xp(j) = 0; yp(j) = 0;
end
end
fill(xp,yp,'w','LineStyle','none')
end
end
axis equal; axis([0 nXElem*lXElem 0 nYElem*lXElem]);
set(gca,'XTick',[],'YTick',[],'XColor','w','YColor','w')
colorbar('horiz');
end