-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunFEM.m
184 lines (161 loc) · 5.69 KB
/
runFEM.m
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This script executes the non-linear finite element method for a mesh
% composed of one 8-node hexahedral element with combined isotropic and
% kinematic hardening. The element is placed under uni-axial tension by
% applying a fixed dispalacement corresponding to 2% strain in the e1
% direction to nodes 2,3,6,7 while pinning node 1, allowing only e2
% displacement in node 4, and preventing only e1 displacement in nodes 5,8.
%
% 5-------8
% / | / |
% 6--|----7 |
% | 1----|--4
% | / | /
% 2-------3
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear
close all
%% Get nodal coordinates from data files
load 'nodes.dat';
load 'elements.dat';
nnode = size(nodes,1); %number of nodes
nel = size(elements,1); %number of elements
nnel = size(elements,2); %number of nodes per element
ndofn = size(nodes,2); %number of degrees of freedom per node
coors = zeros(nnel,ndofn,nel); %nodal coordinates for each element
ndoft = nnode*ndofn; %total number of degrees of freedom
ndofel = nnel*ndofn; %number of degrees of freedom per element
for i=1:nel
for j=1:nnel
coors(j,:,i) = nodes(elements(i,j),:);
end
end
%% elastic material properties
E = 11000; %elastic modulus
nu = 0.25; %poisson's ratio
lambda = (E*nu)/((1+nu)*(1-(2*nu))); %first lame constant
mu = E/(2*(1+nu)); %second lame constant
%% Plastic material properties
K0 = 120;
Kp = 900;
Hp = 2.5;
matprops = [lambda,mu,K0,Kp,Hp];
%% Define boundary conditions
utotal = 0.02; %total displacement of top surface in loading direction
nstep1 = 100; %number of steps until displacement total
nstep2 = 120; %final number of steps
du = utotal/nstep1; %displacement increment
fixDispDofs = [1 2 3 10 12 13 22 4 7 16 19]; %fixed displacement DoFs
nFixDispDofs = numel(fixDispDofs);
dFixDispVals = [zeros(1,7) du*ones(1,4)]; %fixed displacment increment values
freeDispDofs = setdiff(1:ndoft,fixDispDofs);
Fext = spalloc(ndoft,1,ndoft); %no external forces
%% Initialize plastic history variables
nintpel = 8; %number of integration points per element (2x2x2 quadrature)
nintpt = nintpel*nel; %number of integration points
nten = 6; %number of unique strain/stress tensor elements
ep = zeros(nten,nintpt); %plastic strain
qbar = zeros(nten,nintpt); %kinematic hardening
alpha = zeros(nintpt); %effective plastic strain
%% Preallocate history storage
sigmaRec = cell(1); %stress history
sigmaRec{1} = zeros(nten,nintpt);
epsilonRec = cell(1); %strain history
epsilonRec{1} = zeros(nten,nintpt);
epRec = cell(1); %plastic strain history
epRec{1} = ep;
alphaRec = zeros(nstep2+1,nintpt); %effective plastic strain history
qbarRec = cell(1); %kinematic hardening history
qbarRec{1} = qbar;
Urec = zeros(ndoft,nstep2+1); %displacement (columns are time steps)
Crec = cell(1); %material stiffness tensor history
C = matStiffTen3D(lambda,mu);
Crec{1} = repmat(C,1,1,nintpt);
%% Step through analysis
maxni = 200; %maximum number of newton iterations
tolFac = 1e-12; %tolerance factor
tic
for t=1:nstep2
U = zeros(ndoft,1);
U(fixDispDofs) = t*dFixDispVals;
%Newton iterations
for ni=1:maxni
%Build tangent stiffness and internal force
[KT,Fint,epsilon,ep,sigma,qbar,alpha,C] = ...
globTanStiff(elements,coors,U,epRec{t},qbarRec{t},alphaRec(t,:),matprops);
%Compute residual force
RF = Fext - Fint;
%Apply boundary conditions
KT(fixDispDofs,:) = zeros(nFixDispDofs,ndoft);
KT(fixDispDofs,fixDispDofs) = eye(nFixDispDofs);
%Evaluate condition
res = norm(RF(freeDispDofs));
fprintf('Time step: %i;\tIteration: %i;\tResidual: %g\n',t,ni,res)
if ni==1
tol = tolFac*res;
elseif res <= tol
break
elseif ni==maxni
error('Convergence failure!')
end
%Update displacement guess
U(freeDispDofs) = U(freeDispDofs) + ...
KT(freeDispDofs,freeDispDofs)\RF(freeDispDofs);
end
%record history variables
Urec(:,t+1) = U;
epRec{t+1} = ep;
epsilonRec{t+1} = epsilon;
sigmaRec{t+1} = sigma;
Crec{t+1} = C;
qbarRec{t+1} = qbar;
alphaRec(t+1,:) = alpha;
end
%% Plot results
tf1 = 1; dt = tf1/nstep1; t0 = 0; tf2 = dt*nstep2;
tvec = t0:dt:tf2; %time vector
intpi = 2; %integration point at which to plot
%plot stress
s11 = zeros(1,nstep2); s22 = zeros(1,nstep2);
s33 = zeros(1,nstep2); s12 = zeros(1,nstep2);
for t=1:nstep2+1
s11(t) = sigmaRec{t}(1,intpi); s22(t) = sigmaRec{t}(2,intpi);
s33(t) = sigmaRec{t}(3,intpi); s12(t) = sigmaRec{t}(4,intpi);
end
figure
plot(tvec,s11,tvec,s22,tvec,s33,tvec,s12,'LineWidth',2)
legend('s11','s22','s33','s12','Location','NorthWest')
xlabel('time')
ylabel('sigma')
%plot alpha
figure
plot(tvec,alphaRec(:,intpi),'LineWidth',2)
xlabel('time')
ylabel('alpha')
%plot qbar
q11 = zeros(1,nstep2); q22 = zeros(1,nstep2);
q33 = zeros(1,nstep2); q12 = zeros(1,nstep2);
for t=1:nstep2+1
q11(t) = qbarRec{t}(1,intpi); q22(t) = qbarRec{t}(2,intpi);
q33(t) = qbarRec{t}(3,intpi); q12(t) = qbarRec{t}(4,intpi);
end
figure
plot(tvec,q11,tvec,q22,tvec,q33,tvec,q12,'LineWidth',2)
legend('qbar11','qbar22','qbar33','qbar12','Location','NorthWest')
xlabel('time')
ylabel('qbar')
%plot C
C1111 = zeros(1,nstep2); C2222 = zeros(1,nstep2); C1212 = zeros(1,nstep2);
for t=1:nstep2+1
C1111(t) = Crec{t}(1,1,intpi);
C2222(t) = Crec{t}(2,2,intpi);
C1212(t) = Crec{t}(4,4,intpi);
end
figure
plot(tvec,C1111,tvec,C2222,tvec,C1212,'LineWidth',2)
legend('C1111','C2222','C1212')
xlabel('time')
ylabel('C')