scalar_hyp
PURPOSE
SCALAR_HYP Numerical solution of scalar linear hyperbolic equations,
SYNOPSIS
function [x,u,err,Psi,Phi]=scalar_hyp(xa,xb,t0,T,beta,uex,u0,ul,nx,deltat,param)
DESCRIPTION
CROSS-REFERENCE INFORMATION
This function calls:
- simpcz SIMPCX. Composite Simpson Quadrature Formula
- derlgl DERLGL Spectral (Legendre Gauss Lobatto) derivative matrix
- xwlgl XWLGL Computes nodes and weights of the Legendre-Gauss-Lobatto quadrature formula.
This function is called by:
- call_hyp CALL_HYP. Script to set input data and call scalar_hyp and stag_scalar_hyp
SOURCE CODE
0001 function [x,u,err,Psi,Phi]=scalar_hyp(xa,xb,t0,T,beta,uex,u0,ul,nx,deltat,param)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 delt1=1/deltat;
0056 tt=(t0:deltat:T)';nt=length(tt);
0057 Phi=[]; UN1=[]; UL=[];Psi=[]; INTU=[];
0058 npdx=nx+1;
0059 [x,wx]=xwlgl(npdx);
0060 [dx]=derlgl(x,npdx);
0061 jac=(xb-xa)*5.d-1;
0062 x=x*jac+(xa+xb)*5.d-1;
0063 alpha=25/12; alpha0=4; alpha1=-3; alpha2=4/3; alpha3=-0.25;
0064
0065
0066 tau=param(2)/(jac*wx(1));
0067 t=t0;
0068 un=zeros(npdx,1); un=u0(x);
0069 intu0=sum(un.*wx)*jac;
0070 UL=[UL;un(npdx)-ul(t)];
0071 INTU=[INTU;0];
0072 intu1ul=0;
0073 psi=0;
0074 Psi=[Psi;psi];
0075
0076
0077
0078
0079
0080
0081 if param(1)==1
0082
0083 A=-beta*dx/jac;
0084
0085 elseif param(1)==2
0086
0087 A=beta*dx'*diag(wx);
0088 A(npdx,npdx)=A(npdx,npdx)-beta;
0089
0090 elseif param(1)==3
0091
0092 A=-beta*diag(wx)*dx;
0093 A(1,1)=A(1,1)-tau*beta*wx(1)*jac;
0094
0095 end
0096 deltat2=deltat*0.5;
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 for it=1:nt-1
0108 t=tt(it);
0109 if(param(1)==1)
0110 w1=A*un;
0111 w2=A*(un+deltat2*w1);
0112 w3=A*(un+deltat2*w2);
0113 w4=A*(un+deltat*w3);
0114 u=un+deltat/6*(w1+2*w2+2*w3+w4); u(1)=ul(tt(it+1));
0115 elseif(param(1)==2)
0116 w1=A*un; w1(1)=w1(1)+beta*ul(t); w1=(w1./wx)/jac;
0117 w2=A*(un+deltat2*w1); t=t+deltat2; w2(1)=w2(1)+beta*ul(t);w2=(w2./wx)/jac;
0118 w3=A*(un+deltat2*w2);w3(1)=w3(1)+beta*ul(t);w3=(w3./wx)/jac;
0119 w4=A*(un+deltat*w3); t=t+deltat2; w4(1)=w4(1)+beta*ul(t);w4=(w4./wx)/jac;
0120 u=un+deltat/6*(w1+2*w2+2*w3+w4);
0121 elseif(param(1)==3)
0122 w1=A*un; w1(1)=w1(1)+tau*beta*ul(t)*wx(1)*jac;w1=(w1./wx)/jac;
0123 w2=A*(un+deltat2*w1); t=t+deltat2; w2(1)=w2(1)+tau*beta*ul(t)*wx(1)*jac;
0124 w2=(w2./wx)/jac;
0125 w3=A*(un+deltat2*w2);w3(1)=w3(1)+tau*beta*ul(t)*wx(1)*jac;w3=(w3./wx)/jac;
0126 w4=A*(un+deltat*w3); t=t+deltat2; w4(1)=w4(1)+tau*beta*ul(t)*wx(1)*jac;
0127 w4=(w4./wx)/jac;
0128 u=un+deltat/6*(w1+2*w2+2*w3+w4);
0129 end
0130
0131 intu=sum(u.*wx)*jac;
0132 t=tt(it+1); UL=[UL;u(npdx)-ul(t)];
0133 INTU=[INTU;intu-intu0];
0134
0135 if(fix((it+1)/2)*2~=it+1)
0136 intu1ul=intu1ul+simpcz(tt(it-1:it+1),UL(it-1:it+1));
0137 psi=intu-intu0+beta*intu1ul;
0138 Psi=[Psi;psi];
0139 end
0140 nor=sum(u.*u.*wx)*jac;
0141
0142
0143
0144
0145
0146
0147
0148 if(it==1)
0149 un=u; nor0=nor;
0150 elseif (it==2)
0151 un1=un; un=u;nor1=nor0; nor0=nor;
0152 elseif(it==3)
0153 un2=un1; un1=un; un=u;nor2=nor1;nor1=nor0; nor0=nor;
0154 elseif(it==4)
0155 un3=un2; un2=un1; un1=un; un=u;
0156 nor3=nor2;nor2=nor1;nor1=nor0; nor0=nor;
0157 else
0158 u1=u(1);u2=u(npdx);
0159 phi1=5.d-1*beta*(-u1^2+u2^2)+...
0160 5.d-1*delt1*(alpha*nor-(alpha0*nor0+alpha1*nor1+alpha2*nor2+alpha3*nor3));
0161 Phi=[Phi;phi1];
0162 un3=un2; un2=un1; un1=un; un=u;
0163 nor3=nor2;nor2=nor1;nor1=nor0; nor0=nor;
0164 end
0165 end
0166
0167
0168
0169
0170 ue=uex(x,tt(nt));
0171 err=norm(u-ue);
0172
0173
0174
0175
0176
0177
Generated on Fri 21-Sep-2007 10:07:00 by m2html © 2003