Ssfem

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 13

clc

clear
close all
% q=input(sprintf('please choose you plane problem: strees problem(A) or strain
problem(B)= '),'s');
%% meshing
% a=[19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 4 4 4 4 4];
a=[ 100 100 100 100 100 100] ;
% m=input('please enter number of element in each row = ');
m=50;
le=a(1)/m;
% water_pressure=input('please enter the value of pressure on the side of dam =
');
nnp=(2*m+1)*6+(m+1)*5;
ndof=2*(2*m+1)*6+2*(m+1)*5; %????? ????? ????? ?? ????

nfe=5*m ; %????? ?????


for j=1:5
b(:,j)=(a(j+1)+a(j))/2;
end

for i=1:6
for j=1:2*m
x(i,j+1)=j*a(i)/(2*m);
end
end
for i=1:6
for j=1:(2*m+1)
y(i,j)=i-1;
end
end

for j=1:m
for i=1:5
xx(i,j+1)=j*b(i)/m;
end
end
for i=1:5
for j=1:(m+1)
yy(i,j)=(i-1)+0.5;
end
end

for i=1:5
X((3*m+2)*i-(3*m+1):(3*m+2)*i)=[x(i,:) xx(i,:)]';
end
X((3*m+2)*i+1:(3*m+2)*i+(2*m+1))=x(end,:);
for i=1:5
Y((3*m+2)*i-(3*m+1):(3*m+2)*i)=[y(i,:) yy(i,:)]';
end
Y((3*m+2)*i+1:(3*m+2)*i+(2*m+1))=y(end,:);

%% degree of freedom
% El=zeros(80,8);
A=[1 2 3 2*m+2 2*m+3 3*m+3 3*m+4 3*m+5];
El(1,:)=A;
for j=1:(m*5)-1
cc=mod(j+1,m);
if cc~=1
El(j+1,:)=[(El(j,1))+2 (El(j,2))+2 (El(j,3))+2 (El(j,4))+1 (El(j,5))+1
(El(j,6))+2 (El(j,7))+2 (El(j,8))+2 ];
else
El(j+1,:)=[(El(j,1))+(m+4) (El(j,2))+(m+4) (El(j,3))+(m+4) (El(j,4))+
((0.5*m+1)*4-1) (El(j,5))+((0.5*m+1)*4-1) (El(j,6))+(m+4) (El(j,7))+(m+4)
(El(j,8))+(m+4)];
end
end
for i=1:5*m
ELEMENT(i,:)=[(El(i,1)) (El(i,2)) (El(i,3)) (El(i,5)) (El(i,8)) (El(i,7))
(El(i,6)) (El(i,4)) ];
end
for i=1:m*5
for w=1:8
DI(i,2*w-1)=2*ELEMENT(i,w)-1;
DI(i,2*w)=2*ELEMENT(i,w);
end
end
LM=cell(5*m,1);
for i=1:5*m
LM{i}=ELEMENT(i,:)';
end

%% sketech
X=X';
Y=Y';
Y=Y/5;
XT=X;
YT=Y;

Xgloba=zeros(5*m,8);
Ygloba=zeros(5*m,8);
for i=1:5*m
for j=1:8
Xgloba(i,j)=X(ELEMENT(i,j));
Ygloba(i,j)=Y(ELEMENT(i,j));
end
end

rr=0;
for i=1:5*m
DI_LM{i}=DI(i,:)';
end
DI_LM=DI_LM';
xnod=[X Y];
nnp1 = size(xnod,1); % number of nodal points
% figure; hold on
% for i=1:5*m
% patch(Xgloba(i,:),Ygloba(i,:),'w');
% end
plot(xnod(:,1), xnod(:,2), 'r*');
text(xnod(:,1), xnod(:,2), num2str((1:nnp1)'), 'FontSize',12);
%% Boundray condition
r=0;
for i=1:(2*m+1)*6+(m+1)*5

if X(i)==0
r=r+1;
co_number_y(r,:)=[i];
end
end
r=0;
for i=1:(2*m+1)*6+(m+1)*5

if X(i)==a(1)
r=r+1;
co_number_y_right(r,:)=[i];
end
end
co_number_fixed_y=sort([co_number_y_right(:,1) ; co_number_y(:,1)]);
DI_co_number_fix_y=zeros(1,2*length(co_number_fixed_y));
for i=1:length(co_number_fixed_y)
DI_co_number_fix_y(2*i-1:2*i)=[2*co_number_fixed_y(i)-1
2*co_number_fixed_y(i)];
end
dof_fixed=zeros(2,2*length(co_number_fixed_y));
dof_fixed(1,:)= DI_co_number_fix_y;

%%
nfe=5*m; %element number
IEN=ELEMENT' ;
ned = 2; % number of dof per node
nen = size(IEN,1); % number of element nodes
nfee = size(IEN,2); % number of finite elements
nnpp = size(xnod,1); % number of nodal points
ndoff = ned*nnp; % number of degrees of freedom (dof)
neq = ned*nen; % number of element equations
%% initial deterministic variables and data
X = 1; % x index
Y = 2; % y index
nue = 0.3; % Poisson coefficient
te = 1; % solid thickness (m)
rhoe = 7850; % material density (kg/m^3)
g = 9.81; % gravity (m/s^2)
be = [0; -rhoe*g]; % mass forces vector
%% random field parameters
%Rf.type = Gaussian
mu_E = 1; % mean value of E
std_E = 0.1; % standard deviation of E
b = [100,1]; % correlation length x e y of the field
KLterms = 4; % number of K-L terms
cov_func = @(x1,x2) exp(-abs(x1-x2)/b);
dombounds = {[0 0],[100 1]}; % {[xmin ymin],[xmax ymax]}
[lambda,phi,phi_v] = KL_fredholm_analytical(KLterms, b, dombounds);

%% force vector and stiffness matrices assembling (numerical integration)


% Gauss-Legendre quadrature
f = zeros(ndof,1); % global force vector initialization
nglp = 4; % same quadrature order to xi and eta
[x_gl,w_gl] = gauss_quad(nglp,'legen'); % computing the roots and weights
% initializations
Kbar = spalloc(ndof,ndof,ndof^2); % global mean stiffness matrix
K_i = cell(KLterms+1,1); % global weighted stiffness matrices
N = cell(nfe,nglp,nglp); % shape function matrices
B = cell(nfe,nglp,nglp); % deformation matrices
% deterministic constitutive matrix - plane stress (Ref.(1) Eq.(5.4))
%CORREGIR E
ee=2e10
D_0 = ee/(1-nue^2)*[ 1 nue 0
nue 1 0
0 0 (1-nue)/2 ];
%% shape function
Nshape= @(xi,eta) [ -0.25*((1-xi)*(1-eta)*(1+xi+eta));
0.5*(1-eta)*(1+xi)*(1-xi) ;
0.25*(1+xi)*(1-eta)*(xi-eta-1) ;
0.5*(1+xi)*(1+eta)*(1-eta) ;
0.25*(1+xi)*(1+eta)*(xi+eta-1);
0.5*(1+eta)*(1+xi)*(1-xi) ;
0.25*(1-xi)*(1+eta)*(-xi+eta-1);
0.5*(1-xi)*(1+eta)*(1-eta) ];

dN_dxi=@(xi,eta) [ - ((eta - 1)*(eta + xi + 1))/4 - ((eta - 1)*(xi - 1))/4


(eta/2 - 1/2)*(xi - 1) + (eta/2 - 1/2)*(xi + 1)
((eta - 1)*(eta - xi + 1))/4 - (xi/4 + 1/4)*(eta - 1)
-((eta - 1)*(eta + 1))/2
(xi/4 + 1/4)*(eta + 1) + ((eta + 1)*(eta + xi - 1))/4
-(eta/2 + 1/2)*(xi - 1) - (eta/2 + 1/2)*(xi + 1)
(xi/4 - 1/4)*(eta + 1) + ((eta + 1)*(xi - eta + 1))/4
((eta - 1)*(eta + 1))/2
];

dN_deta = @(xi,eta) [ - ((xi - 1)*(eta + xi + 1))/4 - ((eta - 1)*(xi - 1))/4


((xi - 1)*(xi + 1))/2
(xi/4 + 1/4)*(eta - xi + 1) + (xi/4 + 1/4)*(eta - 1)
- (xi/2 + 1/2)*(eta - 1) - (xi/2 + 1/2)*(eta + 1)
(xi/4 + 1/4)*(eta + 1) + (xi/4 + 1/4)*(eta + xi - 1)
-((xi - 1)*(xi + 1))/2
(xi/4 - 1/4)*(xi - eta + 1) - (xi/4 - 1/4)*(eta + 1)
(xi/2 - 1/2)*(eta - 1) + (xi/2 - 1/2)*(eta + 1)
];

%% first level of assembly K [Eq.(3.18a-b) Part.(2) Ref.(2)]


tic;
% Calculation of K_0 = Kbar

for e = 1:nfe
% element stiffness matrices and force vector initialization
Kbar_e = zeros(neq);
fe = zeros(neq,1);
det_Je = zeros(nglp);

% element nodal coordinates in x and y axis


xe = xnod(IEN(:,e),X);
ye = xnod(IEN(:,e),Y);
% gauss-legendre quadrature integration. see Pag.148 Ref.(3)
for p = 1:nglp
xi_gl = x_gl(p);
for q = 1:nglp
eta_gl = x_gl(q);
NN = Nshape(xi_gl,eta_gl); % shape functions on GL points
ddN_dxi = dN_dxi(xi_gl,eta_gl); % shape functions on GL points
ddN_deta = dN_deta(xi_gl,eta_gl); % shape functions on GL points

% Eq.(3.9.6) Ref.(3)
dx_dxi = sum(ddN_dxi.*xe); dx_deta = sum(ddN_deta.*xe);
dy_dxi = sum(ddN_dxi.*ye); dy_deta = sum(ddN_deta.*ye);

% Jacobian matrix and determinant. Eq.(3.3.3) Ref.(3)


Je = [ dx_dxi dx_deta
dy_dxi dy_deta ]';
det_Je(p,q) = det(Je);

% Reserve memory
N{e,p,q} = zeros(ned,neq);
B{e,p,q} = zeros(3,neq);
for i = 1:nen
% Eq.(3.9.1)-(3.9.2) Ref.(3)
dNi_dx = (+dy_deta*ddN_dxi(i) - dy_dxi*ddN_deta(i))/det_Je(p,q);
dNi_dy = (-dx_deta*ddN_dxi(i) + dx_dxi*ddN_deta(i))/det_Je(p,q);

% strain-displacement matrix. Eq.(2.8.20) Ref.(3)


B{e,p,q}(:,[2*i-1 2*i]) = [ dNi_dx 0
0 dNi_dy
dNi_dy dNi_dx ];
% shape function matrix
N{e,p,q}(:,[2*i-1 2*i]) = [ NN(i) 0
0 NN(i) ];
end
% mean element stiffness matrix (Eq.(3.15) Part.(2) Ref.(2))
Kbar_e = Kbar_e +
mu_E*B{e,p,q}'*D_0*B{e,p,q}*te*det_Je(p,q)*w_gl(p)*w_gl(q);

% element force vector (Eq.(3.17) Part.(2) Ref.(2))


end
end
if any(any(det_Je <= 0))
error('Element %d has points with negative det_Je.\n', e);
end
Kbar(DI_LM{e},DI_LM{e}) = Kbar(DI_LM{e},DI_LM{e}) + Kbar_e;
end
% shift parameter in x e y, when the domain of the random field is nonsymm
Tx = (min(xnod(:,X))+max(xnod(:,X)))/2; % Eq.(2.15) Part.(2) Ref.(3)
Ty = (min(xnod(:,Y))+max(xnod(:,Y)))/2; % Eq.(2.15) Part.(2) Ref.(3)
K_i{1} = Kbar;
for i = 2:KLterms+1 % K_i{1} will be Kbar
K_i{i} = sparse(ndof,ndof);
for e = 1:nfe
% element stochastic stiffness matrices initialization and determinant
K_ie = zeros(neq);
det_Je = zeros(nglp);

% element nodal coordinates


xe = xnod(IEN(:,e),X);
ye = xnod(IEN(:,e),Y);

% gauss-legendre quadrature integration. see ref. 1 pag. 148


for p = 1:nglp
xi_gl = x_gl(p);
for q = 1:nglp
eta_gl = x_gl(q);
NN = Nshape(xi_gl,eta_gl); % shape functions on GL points
ddN_dxi = dN_dxi(xi_gl,eta_gl); % shape functions on GL points
ddN_deta = dN_deta(xi_gl,eta_gl); % shape functions on GL points

% Eq.(3.9.6) Ref.(3)
dx_dxi = sum(ddN_dxi.*xe); dx_deta = sum(ddN_deta.*xe);
dy_dxi = sum(ddN_dxi.*ye); dy_deta = sum(ddN_deta.*ye);

% Jacobian matrix and determinant. Eq.(3.3.3) Ref.(3)


Je = [ dx_dxi dx_deta
dy_dxi dy_deta ]';
det_Je(p,q) = det(Je);

% Compute global coordinates of element and apply shift


xx = sum(NN.*xe)-Tx;
yy = sum(NN.*ye)-Ty;

% weighted stochastic element stiffness matrix (Eq.(3.16) Part.(2) Ref.


(2))
varphi = phi{i-1}(xx,yy); % evaluating eigenfunctions
K_ie = K_ie + std_E*(sqrt(lambda(i-1))*varphi)*B{e,p,q}'*...
D_0*B{e,p,q}*te*det_Je(p,q)*w_gl(p)*w_gl(q);
end
end
K_i{i}(DI_LM{e},DI_LM{e}) = K_i{i}(DI_LM{e},DI_LM{e}) + K_ie;
end
end
t1 = toc;
fprintf('Elapsed time (1st level of assembly) = %g [s]\n\n', t1);
%% Mass

Mbar=sparse(ndof,ndof);

for e = 1:nfe
% element stiffness matrices and force vector initialization
Mbar_e = zeros(neq);

% element nodal coordinates in x and y axis


xe = xnod(IEN(:,e),X);
ye = xnod(IEN(:,e),Y);

area=(max(xe)-min(xe))*(max(ye)-min(ye));

% gauss-legendre quadrature integration. see Pag.148 Ref.(3)


for p = 1:nglp
xi_gl = x_gl(p);
for q = 1:nglp
eta_gl = x_gl(q);
NN = Nshape(xi_gl,eta_gl); % shape functions on GL points

% Reserve memory
N{e,p,q} = zeros(ned,neq);

for i = 1:nen
N{e,p,q}(:,[2*i-1 2*i]) = [ NN(i) 0 % shape
function matrix
0 NN(i) ];
end

% mean element stiffness matrix (Eq.(3.15) Part.(2) Ref.(2))


Mbar_e = Mbar_e +N{e,p,q}'*rhoe*area*N{e,p,q}*te*w_gl(p)*w_gl(q);

end
end

Mbar(DI_LM{e},DI_LM{e}) = Mbar(DI_LM{e},DI_LM{e}) + Mbar_e;

end
%% % global force vector initialization
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
tt =0:0.0125:2;
f = zeros(ndof,length(tt));
for qq=1:length(tt)

TT=tt(qq) ; % zaman moored nazar


TT=[TT TT-0.1]; % fasele bain niroha 4 metr ast
T1=TT(1);T2=TT(2);
F1d=-3650*5*(1+0.1*sin(10*pi*T1)+0.05*sin(40*pi*T1));
F2d=-14500*5*(1-0.1*sin(10*pi*T2)+0.05*sin(40*pi*T2));
force=[F1d F2d]; % barhay oboori az tir (N)
velocity=[80 80]; % sorat har kodam az barhay obori (m/s)
N_f=length(force);
ft=zeros(nfe,N_f);
X_Force=zeros(1,N_f);

for j=1:N_f
D_Force(j)=(TT(j)*velocity(j)) ; % makan har kodam az niroha DAR TOOL POOL

if (D_Force(j)<0 | D_Force(j)>100) ; % ba in shart agar bari az pool oboor kard


digar bar elemani vared namishavad
continue
end

for i=4*m+1:nfe
if ((i-(4*m+1))*le<=D_Force(j))&(D_Force(j)<=(i-4*m)*le) % ba in shart barnameh
mifahmeh ke niro roye kodam eleman ast.
ft(i,j)= force(j);

X_Force(j)=D_Force(j)-(i-(4*m+1))*le ;
break
end
end
% RR=1.6;
end

for e=1:nfe
fe=zeros(neq,1);
for j=1:length(X_Force)
kesi=((2*X_Force(j)/le)-1);
NN=Nshape(kesi,1);
NS=[NN(1) 0 NN(2) 0 NN(3) 0 NN(4) 0 -NN(5) 0 NN(6) 0 NN(7) 0 NN(8) 0

0 NN(1) 0 NN(2) 0 NN(3) 0 NN(4) 0 -NN(5) 0 NN(6) 0 NN(7) 0


NN(8)];
FF=[0 ft(e,j)]';
fe=fe+NS'*FF;
end
f(DI_LM{e},qq) = f(DI_LM{e},qq) + fe;
end
end

%% second level of assembly K (Eq.(3.20) Part.(2) Ref.(2))


% computing the (c_{ijk} tensor)
tic;
for ii=1:2
p_order=ii
% p_order = 2; % order of the polynomial chaos 0,1,...
cijk = c_ijk(KLterms,p_order,1);
%
alpha = multi_index(KLterms, p_order); % create the
multi-index
[Psi_s,Psi_p,PsiSqNorm,P] = Hermite_PC(KLterms, p_order, alpha); % 1D Hermite
polynomials
%
K = cell(P,P); % full stiffness matrix as a block
for j = 1:P
for k = 1:P
K{j,k} = sparse(ndof,ndof);
for i = 1:KLterms+1 % 1 ---> K_0 = Kbar
if cijk{i}(j,k) ~= 0 % to avoid unnecessary operations
K{j,k} = K{j,k} + cijk{i}(j,k)*K_i{i};
end
end
end
end

%%mass
Mtotal=cell(P,P);
for i=1:P
for j=1:P
Mtotal{i,j}=sparse(ndof,ndof);
Mtotal{i,i}=Mbar*PsiSqNorm(i);
if i~=j
Mtotal{i,j}=zeros(ndof);
end
end
end
MM=cell2mat(Mtotal);
t2 = toc;
fprintf('Elapsed time (2nd level of assembly) = %g [s]\n\n',t2);

% figure;
% nz = nnz(MM); spy(MM);
% set(gca,'FontSize',15);
% title(sprintf('$*nnz=%g~*P=%g$',nz,P),'FontSize',15); xlabel('');
%
%
K = cell2mat(K);
% figure;
% nz = nnz(K); spy(K);
% set(gca,'FontSize',15);
% title(sprintf('$*nnz=%g~*P=%g$',nz,P),'FontSize',15); xlabel('');

F=cell(P,size(f,2));
for i=2:P
for j=1:size(f,2)
F{1,j}=sparse(f(:,j));
F{i,j}=sparse(f(:,j))*0;
end
end
F=cell2mat(F);

sndof=dof_fixed(1,:);

cc = []; % fixed degrees of freedom


for j = 0:P-1
cc = [cc, (j*ndof + sndof)];
end
dd = setdiff(1:(ndof*P),cc)';
K = K(dd,dd);
MM = MM(dd,dd);
% C = C(dd,dd);
for i=1:size(f,2)
fc{i} = F(dd,i);
end
sdof=length(K);
C=zeros(sdof);
C=sparse(sdof,sdof);
ti = 0. ;
tf = 2;
dt = 0.0125 ;
t = ti:dt:tf ;
nt = fix((tf-ti)/dt) ;
n = length(MM) ;
ac = repmat(dof_fixed(2,:)',P,nt+1);
% Newmark Method for time integration
%acceleration = 'Average' ;
% acceleration = 'Average' ;
% [depl,vel,accl,U,t,delp] = NewmarkMethod(MM,K,C,fc,sdof,acceleration) ;
toc
tic;

%%
gaama = 1/2 ;
beta = 1/4 ;
%%
% Constants used in Newmark's integration
a1 = gaama/(beta*dt) ; a2 = 1/(beta*dt^2) ;
a3 = 1/(beta*dt) ; a4 = gaama/beta ;
a5 = 1/(2*beta) ; a6 = (gaama/(2*beta)-1)*dt ;
depl = zeros(n,nt) ;
vel = zeros(n,nt) ;
accl = zeros(n,nt) ;
U = zeros(sdof,nt) ;
% Initial Conditions
depl(:,1) = zeros;
vel(:,1) = zeros ;
% U(:,1) = phi*depl(:,1) ;
P0 = fc{1} ;
accl(:,1) = MM\(fc{1}-C*vel(:,1)-K*depl(:,1)) ;

Kcap = K+a1*C+a2*MM ;

a = a3*MM+a4*C ;
b = a5*MM+a6*C ;

% Tme step starts


for i = 2:nt
delPp = (fc{i}-fc{i-1})+a*vel(:,i)+b*accl(:,i) ;
delu = Kcap\delPp ;
delv = a1*delu-a4*vel(:,i)-a6*accl(:,i) ;
dela = a2*delu-a3*vel(:,i)-a5*accl(:,i);
depl(:,i+1) = depl(:,i)+delu ;
vel(:,i+1) = vel(:,i)+delv ;
accl(:,i+1) = accl(:,i)+dela ;
U(:,i+1) = depl(:,i+1) ;

end

a = zeros(ndof*P,nt+1); a(cc,:) = ac; a(dd,:) = depl(:,:);

for i=1:2*nnp
X_wreck(i)=a((2*i-1),80)*8;
Y_wreck(i)=a((2*i),80)*8;
end

X=XT';
Y=YT';

for i=1:nnp
X_new(i)=X_wreck(i)+X(i);
Y_new(i)=Y_wreck(i)+Y(i);
end
xnod_new=[X_new' Y_new'];
nnp1 = size(xnod_new,1); % number of nodal points
figure;
plot(xnod_new(:,1), xnod_new(:,2), 'r*');
text(xnod_new(:,1), xnod_new(:,2), num2str((1:nnp1)'), 'FontSize',12);
figure;hold on

plot(0:0.0125:2,a(811*2,:))
aforV80_mesh20=a;
plot(0:0.0125:2,a(811*2,:))
Xgloba=zeros(5*m,8);
Ygloba=zeros(5*m,8);
for i=1:5*m
for j=1:8
Xgloba(i,j)=X_new(ELEMENT(i,j));
Ygloba(i,j)=Y_new(ELEMENT(i,j));
end
end

for i=1:5*m
patch(Xgloba(i,:),Ygloba(i,:),'w');
end
scale = 0.1;%/max(abs(d(:,1
xdef=[X_new' Y_new'];
figure; hold on;
for e = 1:nfe
h1 = line(xnod(IEN([1:nen 1],e),1), xnod(IEN([1:nen 1],e),2)); % original
set(h1,'Color', 'Blue','LineStyle','-');
h2 = line(xdef(IEN([1:nen 1],e),1), xdef(IEN([1:nen 1],e),2)); % deformed
set(h2,'Color', 'Red','LineStyle','--');
end
legend('original','deformed')
% axis equal tight;
% leg = legend('Original','Mean response','Location', 'SouthOutside');
% set(leg,'FontSize',25); set(gca,'FontSize',20);
% title(sprintf('Mean response field (scaled %g times)',scale),'FontSize',20);
% xlabel('X','FontSize',20); ylabel('Y','FontSize',20);

%% plot
for i=1:size(f,2)
aho{i}=a(:,i);
end

for i=1:size(f,2)
d{i} = reshape(aho{i},ndof,P);
end
dmesh20=d;
% covariance response (Eq.(4.27) Ref.(1))
cov_u = zeros(ndof);
for j = 0:P-1
cov_u = cov_u + PsiSqNorm(j+1)*d{50}(:,j+1)*d{50}(:,j+1)';
end
% plot standard deviation field
std_u = sqrt(diag(cov_u));
std_ux = std_u(1:2:end);
std_uy = std_u(2:2:end);
% figure;
% % in x
% subplot(121);
% for e = 1:nfe
% fill(xnod(IEN(:,e),1),xnod(IEN(:,e),2),std_ux(IEN(:,e)))
% end
% axis equal tight; colorbar; set(gca,'FontSize',20);
% title('std field in X','FontSize',20);
% xlabel('X','FontSize',20); ylabel('Y','FontSize',20);
% % in y
% subplot(122);
% for e = 1:nfe
% fill(xnod(IEN(:,e),1),xnod(IEN(:,e),2),std_uy(IEN(:,e)))
% end
% axis equal tight; colorbar; set(gca,'FontSize',20);
% title('std field in Y','FontSize',20);
% xlabel('X','FontSize',20); ylabel('Y','FontSize',20);
%% representation of the response displacement
N = 1e4;
u = zeros(ndof, N);
xi = randn(N, KLterms);
% this step is required to evaluate the polynomials (sym form)
xi_v = sym('xi',[1, KLterms],'real'); % create symbolic vector
xi_n = num2cell(xi,1); % 'experimental design'
func = matlabFunction(Psi_s(2:end),'Vars',xi_v); % take out the 1st because it
is always one
Psi = [ones(N,1), func(xi_n{:})]; % then I add the ones here
% evaluate PCE
for j = 0:P-1
msg = fprintf('Evaluating PC expansion %g/%g', j, P);
psi_j = Psi(:,j+1);
d_j = d{51}(:,j+1);
for i = 1:ndof
u(i,:) = u(i,:) + d_j(i)*psi_j';
end
fprintf(repmat('\b',1,msg));
end
% PC approximation of the r.v. at chosen dof
dof = 811*2;
u_PC = u(dof,:); % evaluation
% [n1,x1] = hist(u_PC,ceil(sqrt(N))); % histogram
[PC_pdf,x2,bw1] = ksdensity(u_PC); % pdf
% [PC_cdf,x3] = ecdf(u_PC); % cdf
%[PC_cdf,x3] = ksdensity(u_PC,'function','cdf'); % cdf
U_PC(ii,:)=u_PC;
%
%
% % pdf
figure; hold on;
% % bar(x1,n1/trapz(x1,n1),'c','EdgeColor',[0,0,0]);
plot(x2,PC_pdf,'r--','LineWidth',2); % 'k-+' 'g-.' 'r--'
%
% grid minor; axis tight;
% xlabel('$$\xi$$','FontSize',15);
% ylabel('$$f_u(\xi)$$','FontSize',15);
% legend('Norm Hist','MCS',sprintf('%dth-order PC
approx',p_order),'Location','Best');
% set(gca,'FontSize',15);

% % cdf
% subplot(3,4,5:12);
% % plot(x5,PC_cdf_mcs,'b-','LineWidth',1); hold on;
% plot(x3,PC_cdf,'r--','LineWidth',1);
% grid minor; axis tight;
% xlabel('$$\xi$$','FontSize',15);
% ylabel('$$F_u(\xi)$$','FontSize',15);
% legend('MCS',sprintf('%dth-order PC approx',p_order),'Location','Best');
% set(gca,'FontSize',15);

end
t4 = toc;
fprintf('Elapsed time (1st level of assembly) = %g [s]\n\n', t4);

U_PC_mesh50_cov10_pcorder_step51=U_PC;

pc1=U_PC(1,:);
[PC_pdf,x2,bw1] = ksdensity(pc1);
pc2=U_PC(2,:);
[PC_pd,x3,bw2] = ksdensity(pc2);
% pc3=U_PC(3,:);
% [PC_p,x4,bw3] = ksdensity(pc3);
figure; hold on
plot(x2,PC_pdf,'r--','LineWidth',2); % 'k-+' 'g-.' 'r--'
plot(x3,PC_pd,'b-.','LineWidth',2); % 'k-+' 'g-.' 'r--'
% plot(x4,PC_p,'k:.','LineWidth',2); % 'k-+' 'g-.' 'r--'

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy