📄 efg_1d.asv
字号:
for i = 1 : (num_disp_nodes - 1)
sctr = [disp_nodes(i) disp_nodes(i+1)];
for q = 1:size(W1,1)
pt = Q1(q,:);
wt = W1(q);
[N,dNdxi] = lagrange_basis('L2',pt);
J0=dNdxi'*node(sctr,:);
Qu = [Qu; N' * node(sctr,:)];
Wu = [Wu; wt];
Ju = [Ju; norm(J0)];
end % of quadrature loop
end
% If Lagrange multiplier method is used
if disp_bc_method == 1
disp(' Lagrange multiplier method is used ')
% --------------------------------------
% Form vector q and matrix G
% --------------------------------------
qk = zeros(1,2*num_disp_nodes);
G = zeros(2*numnode,2*num_disp_nodes);
% If point collocation method is used. Assume that these collocation
% points are coincident to nodes on displacement boundary
if (la_approx == 200)
disp(' Point collocation method is used ')
for i = 1 : num_disp_nodes % loop on collocation points
pt = node(disp_nodes(i),:);
% compute exact displacement of Timoshenko problem, u_bar
x = pt(1,1) ; y = pt(1,2) ;
fac = P/(6*E*I);
ux_exact = fac*y*((6*L-3*x)*x+(2+nu)*(y^2-D*D/4));
uy_exact = -fac*((L-x)*3*nu*y^2+0.25*(4+5*nu)*D*D*x+(3*L-x)*x^2);
% qk vector
qk(1,2*i-1) = -ux_exact ;
qk(1,2*i) = -uy_exact ;
% S matrix
S = [1 0; 0 1]; % both directions
% G matrix
[index] = define_support(node,pt,di);
[phi,dphidx,dphidy] = MLS_ShapeFunction(pt,index,node,di,form);
for j = 1 : size(index,2)
row1 = 2*index(j)-1 ;
row2 = 2*index(j) ;
Gj = -phi(j) * S ;
G(row1:row2,2*i-1:2*i) = G(row1:row2,2*i-1:2*i) + Gj ;
end
end
end % end of if boundary point collocation is used
% if Lagrange multipliers are interpolated by finite elements
% along the displacement boundary
if (la_approx == 100)
disp(' Finite element interpolation for ML is used ')
m1 = 0 ;
for i = 1 : (num_disp_nodes - 1)
sctr = [disp_nodes(i) disp_nodes(i+1)];
m1 = m1 + 1 ;
m2 = m1 + 1 ;
%le = norm(disp_nodes(m1) - disp_nodes(m2));
le = norm(node(sctr(1),:) - node(sctr(2),:));
for q = 1:size(W1,1)
pt = Q1(q,:);
wt = W1(q);
[N,dNdxi] = lagrange_basis('L2',pt);
J0 = dNdxi'*node(sctr,:);
detJ = norm(J0) ;
pt = N' * node(sctr,:); % global GP
% compute exact displacement of Timoshenko problem, u_bar
x = pt(1,1) ; y = pt(1,2) ;
fac = P/(6*E*I);
ux_exact = fac*y*((6*L-3*x)*x+(2+nu)*(y^2-D*D/4));
uy_exact = -fac*((L-x)*3*nu*y^2+0.25*(4+5*nu)*D*D*x+(3*L-x)*x^2);
N1 = 1 - pt(1,2)/le ; N2 = 1 - N1 ;
% qk vector
qk(2*m1-1) = qk(2*m1-1) - wt * detJ * N1 * ux_exact ;
qk(2*m1) = qk(2*m1) - wt * detJ * N1 * uy_exact ;
qk(2*m2-1) = qk(2*m2-1) - wt * detJ * N2 * ux_exact ;
qk(2*m2) = qk(2*m2) - wt * detJ * N2 * uy_exact ;
% G matrix
[index] = define_support(node,pt,di);
[phi,dphidx,dphidy] = MLS_ShapeFunction(pt,index,node,di,form);
for j = 1 : size(index,2)
row1 = 2*index(j)-1 ;
row2 = 2*index(j) ;
G1 = - wt * detJ * phi(j) * [N1 0 ; 0 N1];
G2 = - wt * detJ * phi(j) * [N2 0 ; 0 N2];
G(row1:row2,2*m1-1:2*m1) = G(row1:row2,2*m1-1:2*m1) + G1;
G(row1:row2,2*m2-1:2*m2) = G(row1:row2,2*m2-1:2*m2) + G2;
end
end
end
end
end % end of if disp_bc_method = 'Lagrange'
% If penalty method is use, then one must modify the stiffness matrix and
% the nodal force vector
% $K_{ij}$ = Kij - alpha \int phi_i phi_j d \gamma_u
% fj = fj - alpha \int phi_i u_bar d \gamma_u
if disp_bc_method == 2
fu = zeros(2*numnode,1);
k = zeros(2*numnode,2*numnode);
for igp = 1 : size(Wu,1)
pt = Qu(igp,:); % quadrature point
wt = Wu(igp); % quadrature weight
[index] = define_support(node,pt,di);
[phi,dphidx,dphidy] = MLS_ShapeFunction(pt,index,node,di,form);
% compute exact displacement of Timoshenko problem
x = pt(1,1) ; y = pt(1,2) ;
fac = P/(6*E*I);
ux_exact = fac*y*((6*L-3*x)*x+(2+nu)*(y^2-D*D/4));
uy_exact = -fac*((L-x)*3*nu*y^2+0.25*(4+5*nu)*D*D*x+(3*L-x)*x^2);
le = size(index,2);
en = zeros(1,2*le);
force = zeros(1,2*le);
phiij = zeros(1,le);
for j = 1 : le
en(2*j-1) = 2*index(j)-1;
en(2*j ) = 2*index(j) ;
force(2*j-1) = phi(j)*ux_exact;
force(2*j ) = phi(j)*uy_exact;
end
fu(en) = fu(en) + Jt(igp) * wt * force' ;
k(en,en) = k(en,en) + Jt(igp) * wt * phi*phi' ;
end % end of loop on Gauss points
f = f - alpha*fu;
K = K - alpha*k;
end
% +++++++++++++++++++++++++++++++++++++
% SOLUTION OF THE EQUATIONS
% +++++++++++++++++++++++++++++++++++++
disp([num2str(toc),' SOLUTION OF EQUATIONS'])
% If penalty function is used, then the unknowns u is the same, just solve
% to get it:-)
if disp_bc_method == 2
d = K\f ;
u2 = d;
for i = 1 : numnode
u(1,i) = d(2*i-1); % x displacement
u(2,i) = d(2*i); % y displacement
end
end
% If Lagrange multiplier is used then, extend the unknowns u by lamda
if disp_bc_method == 1
f = [f;qk']; % f = {f;qk}
m = ([K G; G' zeros(num_disp_nodes*2)]); % m = [K GG;GG' 0]
d = m\f; % d = {u;lamda}
u2 = d(1:numnode*2);
% just get displacement parameters u_i
for i = 1 : numnode
u(1,i) = d(2*i-1); % x displacement
u(2,i) = d(2*i); % y displacement
end
end
clear d ;
% +++++++++++++++++++++++++++++++++++++
% COMPUTE THE TRUE DISPLACEMENTS
% +++++++++++++++++++++++++++++++++++++
disp([num2str(toc),' INTERPOLATION TO GET TRUE DISPLACEMENT'])
disp = zeros(1,2*numnode);
for i = 1 : numnode
[index] = define_support(node,node(i,:),di);
% shape function at nodes in neighbouring of node i
[phi,dphidx,dphidy] = MLS_ShapeFunction(node(i,:),index,node,di,form);
disp(1,2*i-1) = phi*u(1,index)'; % x nodal displacement
disp(1,2*i) = phi*u(2,index)'; % y nodal displacement
end
clear u;
% +++++++++++++++++++++++++++++++++++++
% COMPUTE STRESSES AT GAUSS POINTS
% +++++++++++++++++++++++++++++++++++++
disp([num2str(toc),' COMPUTE STRESS AT GAUSS POINTS'])
ind = 0 ;
for igp = 1 : size(W,1)
pt = Q(igp,:); % quadrature point
wt = W(igp); % quadrature weight
[index] = define_support(node,pt,di);
B = zeros(3,2*size(index,2)) ;
en = zeros(1,2*size(index,2));
[phi,dphidx,dphidy] = MLS_ShapeFunction(pt,index,node,di,form);
for m = 1 : size(index,2)
B(1:3,2*m-1:2*m) = [dphidx(m) 0 ;
0 dphidy(m);
dphidy(m) dphidx(m)];
en(2*m-1) = 2*index(m)-1;
en(2*m ) = 2*index(m) ;
end
ind = ind + 1 ;
stress_gp(1:3,ind) = C*B*u2(en); % sigma = C*epsilon = C*(B*u)
end
% +++++++++++++++++++++++++++++++++++++
% VISUALIATION
% +++++++++++++++++++++++++++++++++++++
% Deformed configuration
% ----------------------
figure
plot_mesh(node,element,'Q4','-');
fac = 200 ; % visualization factor
hold on
h = plot(node(:,1)+fac*disp(1,1:2:2*numnode-1)',...
node(:,2)+fac*disp(1,2:2:2*numnode)','b*');
set(h,'MarkerSize',7);
axis off
% Stress visualization
% ----------------------
% Stresses are computed at Gauss points
% Gauss points are then used to build a Delaunay triangulation, then plot
figure
hold on
tri = delaunay(Q(:,1),Q(:,2));
plot_field(Q,tri,'T3',stress_gp(1,:));
axis('equal');
xlabel('X');
ylabel('Y');
title('Sigma XX');
set(gcf,'color','white');
colorbar('vert');
opts = struct('Color','rgb','Bounds','tight');
exportfig(gcf,'beam_stress_x.eps',opts)
% Export to Tecplot for better plot
varname{1}='X';
varname{2}='Y';
varname{3}='sigma_xx';
varname{4}='sigma_yy';
varname{5}='sigma_xy';
%varname{6}='sigma_vonMises';
sigma=[stress_gp(1,:)' stress_gp(2,:)' stress_gp(3,:)'];
value=[Q(:,1) Q(:,2) sigma];
tecplotout(tri,'T3',Q,varname,value,'beam_stress.dat');
for igp = 1 : size(W,1)
pt = Q(igp,:); % quadrature point
x = pt(1,1);
y = pt(1,2);
sigma_xx(igp) = -P*(L-x)*y/I;
end
varname{1}='X';
varname{2}='Y';
varname{3}='sigma_xx';
value=[Q(:,1) Q(:,2) sigma_xx'];
tecplotout(tri,'T3',Q,varname,value,'beam_exact_stress.dat');
% Remove used memory
clear coord; clear Q; clear W; clear J; clear stress_gp;
% --------------------------------------------------------------------
% END OF THE PROGRAM
% --------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -