USE rbmat
USE cbmat
USE fft
USE gnuplot
USE BoostConv
INTEGER nx=800
REAL Lx=20
REAL alpha=1.0035
REAL dt=1.E-3
REAL toll=1.E-6
COMPLEX mu0=0.52
COMPLEX mu2=-0.01
COMPLEX cu=0.2
COMPLEX cd=-1;
COMPLEX ni=2+0.2*I
COMPLEX gamma=1+cd*I
INTEGER plotfreq=1000
INTEGER plotres=1000
INTEGER boostfreq=100
BOOLEAN boost=YES
INTEGER nkrylov=35
REAL tboost=100
WRITE
WRITE "!-------Eigenvalues of Equation on infinite domain------"
h=SQRT(-2*mu2*gamma)
COMPLEX eigg=0;
eigg=mu0-cu^2 - ni^2 / (4*gamma) - 0.5*h
WRITE "Autovalore 1=", eigg
eigg=mu0-cu^2 - ni^2 / (4*gamma) - 1.5*h
WRITE "Autovalore 2=", eigg
eigg=mu0-cu^2 - ni^2 / (4*gamma) - 2.5*h
WRITE "Autovalore 3=", eigg
WRITE "!------------------------------------------------------"
WRITE
WRITE
COMPLEX FUNCTION mu(REAL x)=(mu0-cu^2)+mu2*x^2/2
INTEGER nxi=nx DIV 2
REAL dx=Lx/nxi
ARRAY(-nx..nx) OF REAL x=0
DO x(i)=i*dx FOR i=-nxi TO nxi
DO x(i+1)=x(i)*alpha FOR i=nxi TO nx-1
DO x(-i-1)=x(-i)*alpha FOR i=nxi TO (nx-1)
WRITE "Domain: [Lx1..Lx1]=]["x(-nx)".."x(nx)"] ---------------"
WRITE
WRITE "dx in uniform domain=" dx
WRITE
WRITE
WRITE "Press any key to continue..."
READ
SUBROUTINE GL(COMPLEX F^(*),A(*))
F(-nx)=gamma*[A(-nx+1)-2*A(-nx)+A(nx-1)]/(dx^2)-ni*[A(-nx+1)-A(nx-1)]/(2*dx)+mu(x(-nx))*A(-nx)-NORM(A(-nx))*A(-nx)
LOOP FOR ix=-nx+1 TO nx-1
F(ix)=gamma*[A(ix+1)-2*A(ix)+A(ix-1)]/(dx^2)-ni*[A(ix+1)-A(ix-1)]/(2*dx)+mu(x(ix))*A(ix)-NORM(A(ix))*A(ix)
REPEAT LOOP
F(nx)=gamma*[A(-nx+1)-2*A(nx)+A(nx-1)]/(dx^2)-ni*[A(-nx+1)-A(nx-1)]/(2*dx)+mu(x(nx))*A(nx)-NORM(A(nx))*A(nx)
END GL
ARRAY(-nx..nx) OF COMPLEX A=0,Ain=0,Aold=0,dA=0
ARRAY(-nx..nx) OF COMPLEX k1,k2,k3,k4
Ain(0)=1/dx
ARRAY(-nx..nx) OF REAL Res=0;
REAL res=1
INTEGER itboost=0
FILE PROFILO=CREATE("field.out")
FILE RES=CREATE("residual.out")
INTEGER it=0
REAL t=0
A=Ain
DO
GL(k1,A)
res=MAXABS(k1)
Res=k1.REALIFIED
IF (it MOD plotfreq)=0 THEN
LOOP FOR ix=-nx TO nx
WRITE TO PROFILO x(ix),t,A(ix).REAL,A(ix).IMAG
REPEAT LOOP
WRITE TO PROFILO
END IF
IF (it MOD plotres)=0 THEN
WRITE BY NAME it,t,,res
WRITE TO RES it,t,res
END IF
it=it+1
t=dt*it
GL(k2,A+0.5*dt*k1)
GL(k3,A+0.5*dt*k2)
GL(k4,A+dt*k3)
A=A+dt*[k1+2*k2+2*k3+k4]/6
IF (t>tboost AND (it MOD boostfreq=0) AND (boost=TRUE)) THEN
INC itboost
IF itboost>1 THEN
dA=[A-Aold]
BoostConv(dA.REALIFIED,length=nkrylov)
A.REALIFIED=Aold.REALIFIED+dA.REALIFIED
END IF
Aold=A
END IF
WHILE res>toll
CLOSE(PROFILO)
CLOSE(RES)
OPENGRAPH
WRITE TO gnuplot 'set term x11 0 position 0,0'
WRITE TO gnuplot 'splot "field.out" u 1:2:3 notitle w l '
WRITE TO gnuplot 'set xlabel "x"; set ylabel "t"; set title "Evolution of Real(A)"'
WRITE TO gnuplot 'set pm3d;unset surface; set view map; set grid; set cbr[-0.35:0.55];set grid ; rep'
SHOWGRAPH
WRITE TO gnuplot 'set term x11 1 position 650,0'
WRITE TO gnuplot 'plot "residual.out" u 2:3 title "Maxabs(residual)" w lp ps 0.5 '
WRITE TO gnuplot 'unset colorbox; set xlabel "t"; set ylabel "maxabs(Res)"; set title "Evolution of Residual "'
WRITE TO gnuplot 'set grid ; set termoption enhanced ; set format y "10^{%T}"; set logscale y 10; rep'
SHOWGRAPH
READ