Home > tt2 > misc > tt_Fd_mtx.m

tt_Fd_mtx

PURPOSE ^

Generates finite-difference diffusion matrix in QTT

SYNOPSIS ^

function [ttm] = tt_Fd_mtx(d_phys, tt_a, bound1, bound2, eps)

DESCRIPTION ^

Generates finite-difference diffusion matrix in QTT
   [TTM] = TT_FD_MTX(D_PHYS, TT_A, BOUND1, BOUND2, PEPS) Generates 
   finite-difference diffusion matrix in QTTM from the coefficient TT_A 
   in QTT, D_PHYS - physical dimension of the problem, BOUND1,2 - 
   boundary conditions at 0 and 1:
       0 - Dirichlet,
       1 - Neumann
   EPS is the accuracy of the approximation. This function uses TT1.0
   format.


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ttm] = tt_Fd_mtx(d_phys, tt_a, bound1, bound2, eps)
0002 %Generates finite-difference diffusion matrix in QTT
0003 %   [TTM] = TT_FD_MTX(D_PHYS, TT_A, BOUND1, BOUND2, PEPS) Generates
0004 %   finite-difference diffusion matrix in QTTM from the coefficient TT_A
0005 %   in QTT, D_PHYS - physical dimension of the problem, BOUND1,2 -
0006 %   boundary conditions at 0 and 1:
0007 %       0 - Dirichlet,
0008 %       1 - Neumann
0009 %   EPS is the accuracy of the approximation. This function uses TT1.0
0010 %   format.
0011 %
0012 %
0013 % TT-Toolbox 2.2, 2009-2012
0014 %
0015 %This is TT Toolbox, written by Ivan Oseledets et al.
0016 %Institute of Numerical Mathematics, Moscow, Russia
0017 %webpage: http://spring.inm.ras.ru/osel
0018 %
0019 %For all questions, bugs and suggestions please mail
0020 %ivan.oseledets@gmail.com
0021 %---------------------------
0022 
0023 
0024 
0025 d = size(tt_a, 1);
0026 d1 = round(d/d_phys);
0027 dims = ones(1,d_phys-1);
0028 for i=1:d_phys-1
0029     dims(i) = d1*i;
0030 end;
0031 ranks = tt_ranks(tt_a);
0032 phys_ranks = ranks(dims);
0033 phys_j = ones(1, d_phys-1);
0034 first_comp=1;
0035 % ttm = tt_zeros(d,2);
0036 
0037 while (phys_j(d_phys-1)<=phys_ranks(d_phys-1))
0038     
0039     for q=1:d_phys
0040         M = cell(d, 1);
0041         cur_a = cell(d1,1);
0042 
0043         for k=1:d1-1
0044             cur_a{k}=tt_a{k};
0045         end;
0046         cur_a{d1} = tt_a{d1}(:,:,phys_j(1));
0047         if (q==1)
0048             cur_a = tt_Fd_mtx1(cur_a, bound1, bound2,eps);
0049         else
0050             cur_a = tt_diag_av1(cur_a, eps);
0051         end;
0052         for k=1:d1-1
0053             M{k}=cur_a{k};
0054         end;
0055         M{d1}(1:2,1:2,1:size(cur_a{d1}, 3),1)=reshape(cur_a{d1}, 2, 2, size(cur_a{d1}, 3), 1);
0056 
0057         
0058         for p=2:d_phys-1
0059             cur_a{1} = permute(tt_a{d1*(p-1)+1}(:,phys_j(p-1),:), [1 3 2]);
0060             for k=2:d1-1
0061                 cur_a{k}=tt_a{d1*(p-1)+k};
0062             end;
0063             cur_a{d1} = tt_a{d1*p}(:,:,phys_j(p));
0064             
0065             if (p==q)
0066                 cur_a = tt_Fd_mtx1(cur_a, bound1, bound2,eps);
0067             else
0068                 cur_a = tt_diag_av1(cur_a, eps);
0069             end;
0070             
0071             M{d1*(p-1)+1}(1:2,1:2,1,1:size(cur_a{1},3)) = reshape(cur_a{1}, 2, 2, 1, size(cur_a{1},3));
0072             for k=2:d1-1
0073                 M{d1*(p-1)+k}(1:2,1:2,1:size(cur_a{k},3),1:size(cur_a{k},4))=cur_a{k};
0074             end;
0075             M{d1*p}(1:2,1:2,1:size(cur_a{d1},3), 1) = reshape(cur_a{d1}, 2, 2, size(cur_a{d1},3), 1);
0076         end;
0077         
0078         cur_a{1} = permute(tt_a{d1*(d_phys-1)+1}(:,phys_j(d_phys-1),:), [1 3 2]);
0079         for k=2:d1-1
0080             cur_a{k}=tt_a{d1*(d_phys-1)+k};
0081         end;
0082         cur_a{d1} = tt_a{d1*d_phys}(:,:,1);
0083         
0084         if (q==d_phys)
0085             cur_a = tt_Fd_mtx1(cur_a, bound1, bound2,eps);
0086         else
0087             cur_a = tt_diag_av1(cur_a, eps);
0088         end;
0089         
0090         M{d1*(d_phys-1)+1}(1:2,1:2,1,1:size(cur_a{1},3)) = reshape(cur_a{1}, 2, 2, 1, size(cur_a{1},3));
0091         for k=2:d1-1
0092             M{d1*(d_phys-1)+k}(1:2,1:2,1:size(cur_a{k},3),1:size(cur_a{k},4))=cur_a{k};
0093         end;
0094         M{d1*d_phys}(1:2,1:2,1:size(cur_a{d1},3), 1) = reshape(cur_a{d1}, 2, 2, size(cur_a{d1},3), 1);
0095         
0096         if (first_comp==1)
0097             ttm = M;
0098             first_comp=0;
0099         else
0100             ttm = ttm_add(ttm, M);
0101             ttm = tt_mat_compr(ttm, eps);
0102         end;
0103     end;
0104     
0105     phys_j(1)=phys_j(1)+1;
0106     for i=1:d_phys-2
0107         if (phys_j(i)>phys_ranks(i))
0108             phys_j(i)=1;
0109             phys_j(i+1)=phys_j(i+1)+1;
0110         end;
0111     end;
0112 end;
0113 
0114 end

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