real function burgex(x,t,u0) c Solve the Burger's equation problem: c u_t + u u_x = 0 u(x,0) = u0 + sin(x) u(x,t) = u(x + 2 pi,t) implicit none c parameters c position at which the exact solution is required real x c time at which the exact solution is required real t c average initial velocity real u0 c local c value of xbar = x - u0 t and a reduced value real xbar,xbar2 c xi-value, the change in xi_value, and the previous change real xi,dxi,dxiprv c iteration counter integer iter c pi real pi save pi data pi/0./ if(pi.eq.0.)pi=4.*atan(1.) c if t=0, trivial if(t.le.0.)then burgex=u0+sin(x) goto 900 endif c find xbar, and reduce to the interval from 0 to 2 pi xbar=x-u0*t 10 if(xbar.ge.0.)goto 20 xbar=xbar+2.*pi goto 10 20 if(xbar.lt.2.*pi)goto 30 xbar=xbar-2.*pi goto 20 30 continue c restrict xbar to from 0 to pi xbar2=xbar if(xbar.gt.pi)xbar2=2.*pi-xbar c use Newton iteration to solve (x-xi)/t - sin(xi) = 0 for xi c initialize xi xi=0. dxi=1.e30 do 100 iter=1,12345 c compute change in xi dxiprv=dxi dxi=-((xbar2-xi)/t-sin(xi))/(-1./t-cos(xi)) c check for convergence if(abs(dxi).ge.abs(dxiprv) .or. dxi.eq.0.)goto 110 c increment xi xi=xi+dxi 100 continue c no convergence. print an error message and stop. print*,'*** No convergence in burgex' stop c find u 110 burgex=(xbar2-xi)/t if(xbar.ne.xbar2)burgex=-burgex burgex=burgex+u0 900 return end