📄 main.asv
字号:
en(2*j ) = 2*index(j) ;
force(2*j-1) = tx*phi(j);
force(2*j ) = ty*phi(j);
end
f(en) = f(en) + Jt(igp) * wt * force' ;
end
% +++++++++++++++++++++++++++++++++++++
% INTEGRATE ON DISPLACEMENT BOUNDARY
% +++++++++++++++++++++++++++++++++++++
% Steps:
% 1. Build up Gauss points on the boundary, 4 GPs are used
% 2. Loop on these GPs to form the vector q and matrix G
disp([num2str(toc),' INTEGRATION ON DISPLACEMENT BOUNDARY'])
% --------------------------------------
% Generation of Gauss points
% --------------------------------------
Wu = [];
Qu = [];
Ju = [];
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
% --------------------------------------
% 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)
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 ;
% 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) ;
G(row1:row2,2*i-1:2*i) = G(row1:row2,2*i-1:2*i) + ...
[-phi(j) 0 ; 0 -phi(j)];
end
end
end % end of if boundary point collocation is used
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);
phi_ij = 0;
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);
for j = 1 : size(index,2*le)
phi_ij = phi_ij + phi(j)*phi(j);
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' ;
end % end of loop on Gauss points
f = f - alpha*fu;
K(en,en) = K(en,en) - alpha*phi_ij ;
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 ;
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; zeros(2*num_disp_nodes,1)];
f(numnode*2+1:numnode*2+num_disp_nodes*2,1) = 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; clear d;
% +++++++++++++++++++++++++++++++++++++
% 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
%x_stressex(1,ind) = (P/Imo)*(Lb-gg(1,1))*gg(2,1);
%x_stressex(2,ind) = 0;
%x_stressex(3,ind) = -P/(2*Imo)*(D^2/4 - gg(2,1)^2);
%end
% +++++++++++++++++++++++++++++++++++++
% VISUALIATION
% +++++++++++++++++++++++++++++++++++++
% Deformed configuration
% ----------------------
figure
plot_mesh(node,element,'Q4','-');
fac = 50 ; % 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 + -