%
%  fixed_fixed_fixed_fixed_plate_pressure_altb.m   ver 1.2  by Tom Irvine
%


% app.disp_transfer,app.von_Mises_stress_transfer,f,app.HM_stress_xx,app.HM_stress_yy,app.HM_stress_xy,...
%                                                                   app.H_stress_xx,app.H_stress_yy,app.H_stress_xy

function[disp_transfer,von_Mises_stress_transfer,f,HM_stress_xx,HM_stress_yy,HM_stress_xy,...
                                                   H_stress_xx,H_stress_yy,H_stress_xy]=...
    fixed_fixed_fixed_fixed_plate_pressure_altb(E,rho,mu,a,b,h,...
                        fn,fig_num,P,dPdx,d2Pdx2,W,dWdy,d2Wdy2,norm,PF,damp,x,y,fmin,fmax,iu)
%
if(x>a)
   disp(' Warning: x reset to total length');
   x=a;
end
%
if(y>b)
   disp(' Warning: y reset to total length');
   y=b;
end
%
%
nf=20000;
%
clear f;
f(1)=fmin;
for k=2:nf
    f(k)=f(k-1)*2^(1/48);
    if(f(k)>fmax)
        break;
    end    
end
nf=max(size(f));
%
clear omega;
clear HM;
clear HM_stress_xx;
clear HM_stress_yy;
clear HM_stress_xy;
clear HM_stress_vM;
%
omega=2*pi*f;
omegamn=2*pi*fn;
%%

%
H=zeros(nf,1);
H_stress_xx=zeros(nf,1);
H_stress_yy=zeros(nf,1);
H_stress_xy=zeros(nf,1);
HM_stress_vM=zeros(nf,1);
%
for k=1:nf
   
%            
    num=P(x)*W(y);
%            
    den=(omegamn^2-omega(k)^2) + (1i)*2*damp*omega(k)*omegamn;
%
    H(k)=num/den;
%
    dxx=d2Pdx2(x)*W(y);
    dyy=     P(x)*d2Wdy2(y);
    dxy=  dPdx(x)*dWdy(y);
%
    H_stress_xx(k)= (dxx + mu*dyy)/den;
    H_stress_yy(k)= (mu*dxx + dyy)/den;
    H_stress_xy(k)=  dxy/den;
%
end
%
PP=PF/(rho*h*norm);
%
H=PP*H;
H_stress_xx=PP*H_stress_xx;
H_stress_yy=PP*H_stress_yy;
H_stress_xy=PP*H_stress_xy;
%
zh=h/2;
AA=-E*zh/(1-mu^2);
BB=-E*zh/(1+mu);
%
H_stress_xx=H_stress_xx*AA;
H_stress_yy=H_stress_yy*AA;
H_stress_xy=H_stress_xy*BB;
%
A=[1 -0.5 0; -0.5 1 0; 0 0 3];

for k=1:nf
    sxx=H_stress_xx(k);   
    syy=H_stress_yy(k);   
    sxy=H_stress_xy(k);  

    sss=[sxx; syy; sxy];

    vvv=(conj(sss))'*A*sss;

    HM_stress_vM(k)=sqrt(abs(vvv));
end
%
HM=abs(H);
HM_stress_xx=abs(H_stress_xx);
HM_stress_yy=abs(H_stress_yy);
HM_stress_xy=abs(H_stress_xy);
HM_stress_vM=abs(HM_stress_vM);
%
%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

[fig_num]=acoustic_plate_plots_alt(fig_num,x,y,iu,f,H,H_stress_xx,H_stress_yy,H_stress_xy,HM_stress_vM);
%
%
f=fix_size(f);

xc=[f HM];
disp_transfer=xc;
clear C;
clear I;
[C,I]=max(xc);
xmax=xc(I(2),2);
fmax=xc(I(2),1);
%
if(iu==1)
    out1=sprintf('\n Displacement: max = %8.4g in/psi at %8.4g Hz  ',xmax,fmax);
else
    out1=sprintf('\n Displacement: max = %8.4g m/Pa at %8.4g Hz  ',xmax,fmax);    
end
disp(out1);
%
%
%%%%%%
%

xc=[f HM_stress_vM];
von_Mises_stress_transfer=xc;

clear C;
clear I;
[~,I]=max(xc);
xmax=xc(I(2),2);
fmax=xc(I(2),1);
%
disp(' ');
if(iu==1)
    out1=sprintf('von Mises stress: max = %8.4g (psi/psi) at %8.4g Hz  ',xmax,fmax);
else
    out1=sprintf('von Mises stress: max = %8.4g (Pa/Pa) at %8.4g Hz  ',xmax,fmax);    
end
disp(out1);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%