Home > tt2 > tests > test_steps2.m

test_steps2

PURPOSE ^

Crank-Nicolson scheme with local time-stepping

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

Crank-Nicolson scheme with local time-stepping

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %Crank-Nicolson scheme with local time-stepping
0002 d0t = 10; % quantics dims for t
0003 d0x = 9; % quantics dims for x
0004 dpx = 2; % phys. dims for x
0005 
0006 a=0; 
0007 b=1;
0008 h = (b-a)/(2^d0x+1);
0009 
0010 tol = 1e-6;
0011 eps = 1e-8;
0012 maxit=20;
0013 
0014 T = 0.5;
0015 tau = T/(2^d0t);
0016 
0017 Ax = tt_qlaplace_dd(d0x*ones(1,dpx));
0018 Ax = Ax/(h^2);
0019 
0020 x = (-a+h:h:b-h)';
0021 u0 = kron(sin(pi*x), sin(pi*x));
0022 x = tt_tensor(x);
0023 x = tt_reshape(x, 2*ones(d0x, 1), eps);
0024 e1 = tt_ones(2, d0x);
0025 
0026 u0 = tt_reshape(tt_tensor(u0), 2*ones(1,2*d0x), eps);
0027 % u0 = kron(x.*(e1-x), e1).*kron(e1, x.*(e1-x));
0028 % u0 = round(u0, eps);
0029 % u0 = tt_tensor(tt_ones(d0x*dpx,2));
0030 
0031 spacial_rhs = u0*0;
0032 
0033 
0034 % Now, generate parts of KN scheme:
0035 KNm = tt_eye(2,dpx*d0x)/tau - Ax*0.5;
0036 KNm = round(KNm, eps);
0037 
0038 KNp = tt_eye(2,dpx*d0x)/tau + Ax*0.5;
0039 KNp = round(KNp, eps);
0040 
0041 Euler = tt_eye(2,dpx*d0x) - Ax*tau;
0042 Euler = round(Euler, eps);
0043 
0044 ttimes = zeros(1,2^d0t);
0045 resids = zeros(1,2^d0t);
0046 dmrg_resids = zeros(1,2^d0t);
0047 dmrg_swps = zeros(1,2^d0t);
0048 eranks = zeros(1,2^d0t);
0049 u = u0;
0050 for t=1:1:2^d0t
0051     times_0 = tic;    
0052     u_new = mvk3(KNm, u, tol, 'nswp', 20, 'y0', u); % 1\tI - A/2
0053     u_new = u_new + spacial_rhs;
0054     u = mvk3(Euler, u, tol, 'nswp', 20, 'y0', u) + tau*spacial_rhs;    
0055 %     for i=1:maxit
0056 %         [u,swps] = dmrg_solve2(KNp, u_new, u, tol, [], [], 100, []);
0057         [u,swps] = dmrg_solve2(KNp, u_new, tol, 'x0', u, 'nswp', 1, 'min_drank', 0, 'ddrank', 0, 'min_dpow', 0);
0058 %         dmrg_resid = norm(KNp*u-u_new)/norm(u_new);
0059 %         fprintf('-- dmrg sweep: %d, resid: %3.3e\n', i, dmrg_resid);
0060 %         if (dmrg_resid<tol*5)
0061 %             break;
0062 %         end;
0063 %     end;
0064     ttimes(t)=toc(times_0);    
0065     
0066     mesh(full(u, 2^d0x*[1,1]))
0067     appr = norm(u-u0*exp(-2*pi^2*t*tau))/norm(u0*exp(-2*pi^2*t*tau))
0068     
0069     dmrg_resid = norm(KNp*u-u_new)/norm(u_new);
0070     dmrg_swps(t)=swps;
0071     
0072     dmrg_resids(t) = dmrg_resid;
0073     resids(t) = norm(Ax*u - spacial_rhs)/norm(spacial_rhs);
0074 %     resids(t) = dot(Ax*u, u)/norm(Ax*u)/norm(u)-1;
0075     eranks(t) = erank(u);
0076     
0077     fprintf('\nTime step %d (%3.5e) done. ttimes: %3.5f, dmrg_resid: %3.3e, sweeps: %d, spac_resid: %3.5e, erank: %3.2f\n', t, t*tau, ttimes(t), dmrg_resids(t), dmrg_swps(t), resids(t), eranks(t));
0078 %     mesh(full(u, [2^d0x,2^d0x]));
0079     pause(0.01);
0080 %     keyboard;
0081 end;

Generated on Wed 08-Feb-2012 18:20:24 by m2html © 2005