I would like to solve the PDE $\frac{\partial u}{\partial t}=(1-x)\frac{\partial u}{\partial x}$, in the interval $[0,1]$, with initial condition $u(0,x)=e^{-218(\frac{-2}{3}-ln(1-x))^2}$, by manually implementing a pseudospectral method with Chebyshev nodes for spatial discretization and a Taylor method for time integration. The first ListPlot appears in a matter of seconds, but after that the code keeps running forever, to the point that I do not even know if it produces the correct results at the end. Is the code correct, and if so, can it become quicker? Please let me know for any clarifications.
a=218;
b=-2/3;
x0=0;
x1=1;
u[x_,t_,a1_,b1_]:=Exp[-a1*(b1+t-Log[1-x])^2];
f[x_]:=u[x,0,a,b];
D[t,u]-(1-x)*D[x,u]
der1[x0_]:=NDSolve`FiniteDifferenceDerivative[Derivative[1],x0,
"DifferenceOrder"->"Pseudospectral"]@"DifferentiationMatrix";
Nx=2^8;
II=IdentityMatrix[Nx];
n=Nx-1;
theta=N[Table[i*Pi/n,{i,0,n}]];
X=N[Chop[((x0+x1)/2)+((x0-x1)/2)*Cos[theta]]];
dt=N[0.01*(x1-x0)/n];
D1=der1[X];
L=(1-x)*D1;
L2=L.L;
L3=L2.L;
M = (II+dt*L+((dt^2)/2)*L2+((dt^3)/6)*L3);
M= Developer`ToPackedArray[M, Real];
Nt=10^5;
T=Table[it*dt,{it,0,Nt-1}];
U=ConstantArray[0.,{Nt, Nx}];
U[[1, All]]=f[X];
U= Developer`ToPackedArray[U, Real];
ListPlot[Transpose[{X, U[[1, All]]}], PlotRange->All, Joined->True]
Do[U[[it+1,All]]=M.U [[it,All]],{it,1,Nt-1}]
ListPlot[Transpose[{X,U[[Nt, All]]}], PlotRange->All, Joined->True]
ListPlot[Transpose[{X,U[[Nt, All]]-f[X-T[[Nt]]]}], PlotRange->All, Joined->True]
Do[U[[it+1,All]]=M.U [[it,All]],{it,1,Nt-1}]
You could try Compilâtion or ParallelEvaluate. $\endgroup$