modelProblem = 1; %Plane Stress (1) or Plane Strain (2)
c11=E*(1-mu)/((1+mu)*(1-2*mu));
C=[c11,c12,0; c21,c22,0; 0,0,c33];
% compute the shape coefficients
Ke=planeElastQuadStiffMatrix(nodes,elem,e,C,th);
rows=[elem(e,1)*2-1; elem(e,1)*2; elem(e,2)*2-1; elem(e,2)*2;...
elem(e,3)*2-1; elem(e,3)*2; elem(e,4)*2-1; elem(e,4)*2];
K(rows,colums)=K(rows,colums)+Ke; %assembly
%Fe=internalConstantForcesQuad(nodes,elem,e,th,internalForce); %if an internal constant force is defined
%F(rows,1)=F(rows,1)+Fe; %assembly
nodLoads=indRight'; %nodes where the force is applied
Q=applyLoadsQuad(nodes,elem,nodLoads,Q,forceLoad);
% fix displacements (essential BC)
u=zeros(numNod*ndim,1); %this way u is a column vector
fixedNodes=[indCircle*ndim-1 indCircle*ndim]; % x and y coordinates
freeNodes = setdiff(1:2*numNod,fixedNodes); %Complementary of fixed nodes
% Not modify the linear system, this is only valid if BC = 0.
Km=K(freeNodes,freeNodes);
displacements=[u(1:2:end),u(2:2:end)] %nodes disp x, y
0.0019 -0.0010
0.0381 0.0029
0.0019 -0.0008
0.0019 -0.0006
0.0020 -0.0005
0.0022 -0.0003
0.0025 -0.0001
0.0030 0.0001
0.0037 0.0005
0.0044 0.0011
% We show only displacements for the last 10 nodes
%displacements(end-9:end,:)
function [Q]=applyLoadsQuad(nodes,elem,nodLoads,Q,forceLoad)
% (c) Numerical Factory 2019
%------------------------------------------------------------------------
% Apply a load BC on a boundary of a quadrilateral meshed domain.
% The behabiour is very similar to the applyConvecQuad funtion used to
%-------------------------------------------------------------------------
[numNod,ndim]=size(nodes);
error('applyLoadQuad: It can''t manage a single node');
r=find(nodLoads==elem(k,j)); %find if j node of element k is in the boundary nodes list
if(~isempty(r)), aux(j)=1; end
%See the Triang version for the explanation of the binary number
% Here we codify both edges and corners on the boundaries
case 3, ij=[1,2,0,0]; % edge 1: aux=[1,1,0,0];
case 6, ij=[2,3,0,0]; % edge 2: aux=[0,1,1,0];
case 7, ij=[1,2,2,3]; % corner 2: aux=[1,1,1,0];
case 9, ij=[4,1,0,0]; % edge 4
case 11, ij=[4,1,1,2]; % corner 1
case 12, ij=[3,4,0,0]; % edge 3
case 13, ij=[3,4,4,1]; % corner 4
case 14, ij=[2,3,3,4]; % corner 3
case 15, error('applyLoadQuad: It can''t manage two corners'); % two corners
L=norm(nodes(n1,:)-nodes(n2,:));
posit=[n1*ndim-1, n1*ndim];
Q(posit)=Q(posit)+0.5*L*forceLoad; %same (x,y) force on both nodes
posit=[n2*ndim-1, n2*ndim];
Q(posit)=Q(posit)+0.5*L*forceLoad; %same (x,y) force on both nodes
function Ke=planeElastQuadStiffMatrix(nodes,elem,e,C,th)
N=2; %number of GaussPoints
[w,ptGaussRef]=gaussValues2DQuad(N);
% First compute Ke, Fe for each element
Psi1=@(x,y)(1-x).*(1-y)/4;
Psi2=@(x,y)(1+x).*(1-y)/4;
Psi3=@(x,y)(1+x).*(1+y)/4;
Psi4=@(x,y)(1-x).*(1+y)/4;
shapeFunctions = @(x,y)[Psi1(x,y),Psi2(x,y),Psi3(x,y),Psi4(x,y)];
% Shape function derivatives
Jacob =@(x,y) [dPsi11(x,y), dPsi21(x,y),dPsi31(x,y),dPsi41(x,y);...
dPsi12(x,y), dPsi22(x,y),dPsi32(x,y),dPsi42(x,y)];
% Compute the corresponding Gaussian points on the domain
% evaluate Shape functions on Gaussian reference points
% evaluate Jacobian contribution for each point
% We use a Matlab cell variable in order to load each matrix
Jtilde{i}=inv(Jacob(xx(i),yy(i))*vertices);
evalDetJacob(i) = det(Jacob(xx(i),yy(i))*vertices);
Jacobia{i}=Jacob(xx(i),yy(i)); %derivatives of the shape functions
shapeFun{i}=shapeFunctions(xx(i),yy(i));
ik1=1; ik2=1; %index of the derivatives here x-x
Kxx=compKijIntegQuad(ik1,ik2,Jacobia,w,evalDetJacob,Jtilde,numPtG);
Kxy=compKijIntegQuad(ik1,ik2,Jacobia,w,evalDetJacob,Jtilde,numPtG);
Kyx=compKijIntegQuad(ik1,ik2,Jacobia,w,evalDetJacob,Jtilde,numPtG);
Kyy=compKijIntegQuad(ik1,ik2,Jacobia,w,evalDetJacob,Jtilde,numPtG);
KK{i,j}=[C(1,1)*Kxx(i,j)+C(3,3)*Kyy(i,j), C(1,2)*Kxy(i,j)+C(3,3)*Kyx(i,j);
C(3,3)*Kxy(i,j)+C(2,1)*Kyx(i,j), C(3,3)*Kxx(i,j)+C(2,2)*Kyy(i,j)];
Ke =th*[KK{1,1}, KK{1,2}, KK{1,3}, KK{1,4};
KK{2,1}, KK{2,2}, KK{2,3}, KK{2,4};
KK{3,1}, KK{3,2}, KK{3,3}, KK{3,4};
KK{4,1}, KK{4,2}, KK{4,3}, KK{4,4}];