Home > tt2 > misc > tt_Fd_mtx2.m

tt_Fd_mtx2

PURPOSE ^

TT-representation of the diffusion matrix

SYNOPSIS ^

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

DESCRIPTION ^

TT-representation of the diffusion matrix
   [TTM] = TT_FD_MTX2(TT_A, BOUND1, BOUND2, EPS) Computes TT
   representation of a simplest discretization of the diffusion operator
   with operator given in the QTT-format (TT_A). 


 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_mtx2(tt_a, bound1, bound2, eps)
0002 %TT-representation of the diffusion matrix
0003 %   [TTM] = TT_FD_MTX2(TT_A, BOUND1, BOUND2, EPS) Computes TT
0004 %   representation of a simplest discretization of the diffusion operator
0005 %   with operator given in the QTT-format (TT_A).
0006 %
0007 %
0008 % TT-Toolbox 2.2, 2009-2012
0009 %
0010 %This is TT Toolbox, written by Ivan Oseledets et al.
0011 %Institute of Numerical Mathematics, Moscow, Russia
0012 %webpage: http://spring.inm.ras.ru/osel
0013 %
0014 %For all questions, bugs and suggestions please mail
0015 %ivan.oseledets@gmail.com
0016 %---------------------------
0017 
0018 d = size(tt_a, 1);
0019 n = zeros(1,d);
0020 for q=1:d
0021     n(q)=size(tt_a{q}, 1);
0022 end;
0023 
0024 if (max(size(bound1))==1) bound1 = bound1*ones(1,d); end;
0025 if (max(size(bound2))==1) bound2 = bound2*ones(1,d); end;
0026 
0027 ranks_a = tt_ranks(tt_a);
0028 
0029 for q=1:d
0030     cur_tt = cell(d,1);
0031     
0032     cur_tt{1}=zeros(n(1),n(1),ranks_a(1));
0033     for k=1:ranks_a(1)
0034             lp1 = diag(-1*ones(n(1)-1,1), [-1])+diag(2*ones(n(1), 1), [0])+diag(-1*ones(n(1)-1,1), [1]);
0035             Mp1 = diag((1/6)*ones(n(1)-1,1), [-1])+diag((4/6)*ones(n(1), 1), [0])+diag((1/6)*ones(n(1)-1,1), [1]);                        
0036             if (bound1(1)==1) lp1(1,1)=1; end;
0037             if (bound2(1)==1) lp1(n(1),n(1))=1; end;
0038             h = 1/(n(1)+1);
0039             if ((bound1(1)==1)||(bound2(1)==1)) h = 1/n(1); end;
0040             if ((bound1(1)==1)&&(bound2(1)==1)) h = 1/(n(1)-1); end;
0041             Mlp1 = diag(tt_a{1}(2:n(1),k), [-1])+diag(tt_a{1}(2:n(1),k), [1]);
0042             Mlp1 = Mlp1 + diag(tt_a{1}(1:n(1),k)+[tt_a{1}(2:n(1),k)' tt_a{1}(n(1),k)]', [0])*0.5;
0043         if (q==1)            
0044             cur_tt{1}(:,:,k) = Mlp1.*(lp1/h^2);
0045         else            
0046             cur_tt{1}(:,:,k) = Mlp1.*Mp1;
0047 %             cur_tt{1}(:,:,k) = diag(tt_a{1}(1:n(1),k)+[tt_a{1}(2:n(1),k)' tt_a{1}(n(1),k)]', [0])*0.5;
0048         end;
0049     end;
0050     
0051     for p=2:d-1
0052         cur_tt{p}=zeros(n(p),n(p),ranks_a(p-1),ranks_a(p));
0053         for k1=1:ranks_a(p-1)
0054             for k2=1:ranks_a(p)
0055                     lp1 = diag(-1*ones(n(p)-1,1), [-1])+diag(2*ones(n(p), 1), [0])+diag(-1*ones(n(p)-1,1), [1]);
0056                     Mp1 = diag((1/6)*ones(n(1)-1,1), [-1])+diag((4/6)*ones(n(1), 1), [0])+diag((1/6)*ones(n(1)-1,1), [1]);                                        
0057                     if (bound1(p)==1) lp1(1,1)=1; end;
0058                     if (bound2(p)==1) lp1(n(p),n(p))=1; end;
0059                     h = 1/(n(p)+1);
0060                     if ((bound1(p)==1)||(bound2(p)==1)) h = 1/n(p); end;
0061                     if ((bound1(p)==1)&&(bound2(p)==1)) h = 1/(n(p)-1); end;
0062                     Mlp1 = diag(tt_a{p}(2:n(p),k1,k2), [-1])+diag(tt_a{p}(2:n(p),k1,k2), [1]);
0063                     Mlp1 = Mlp1 + diag(tt_a{p}(1:n(p),k1,k2)+[tt_a{p}(2:n(p),k1,k2)' tt_a{p}(n(p),k1,k2)]', [0])*0.5;
0064                 if (p==q)                           
0065                     cur_tt{p}(:,:,k1,k2) = Mlp1.*(lp1/h^2);             
0066                 else
0067                     cur_tt{p}(:,:,k1,k2) = Mlp1.*Mp1;
0068 %                     cur_tt{p}(:,:,k1,k2) = diag(tt_a{p}(1:n(p),k1,k2)+[tt_a{p}(2:n(p),k1,k2)' tt_a{p}(n(p),k1,k2)]', [0])*0.5;
0069                 end;
0070             end;
0071         end;
0072     end;
0073     
0074     cur_tt{d}=zeros(n(d),n(d),ranks_a(d-1));
0075     for k=1:ranks_a(d-1)
0076             lp1 = diag(-1*ones(n(d)-1,1), [-1])+diag(2*ones(n(d), 1), [0])+diag(-1*ones(n(d)-1,1), [1]);
0077             Mp1 = diag((1/6)*ones(n(1)-1,1), [-1])+diag((4/6)*ones(n(1), 1), [0])+diag((1/6)*ones(n(1)-1,1), [1]);                                                    
0078             if (bound1(d)==1) lp1(1,1)=1; end;
0079             if (bound2(d)==1) lp1(n(d),n(d))=1; end;
0080             h = 1/(n(d)+1);
0081             if ((bound1(d)==1)||(bound2(d)==1)) h = 1/n(d); end;
0082             if ((bound1(d)==1)&&(bound2(d)==1)) h = 1/(n(d)-1); end;
0083             Mlp1 = diag(tt_a{d}(2:n(d),k), [-1])+diag(tt_a{d}(2:n(d),k), [1]);
0084             Mlp1 = Mlp1 + diag(tt_a{d}(1:n(d),k)+[tt_a{d}(2:n(d),k)' tt_a{d}(n(d),k)]', [0])*0.5;
0085         if (q==d)            
0086             cur_tt{d}(:,:,k) = Mlp1.*(lp1/h^2);
0087         else
0088             cur_tt{d}(:,:,k) = Mlp1.*Mp1;
0089 %             cur_tt{d}(:,:,k) = diag(tt_a{d}(1:n(d),k)+[tt_a{d}(2:n(d),k)' tt_a{d}(n(d),k)]', [0])*0.5;
0090         end;
0091     end;    
0092     
0093     if (q==1)
0094         ttm = cur_tt;
0095     else
0096         ttm = ttm_add(ttm, cur_tt);
0097         ttm = tt_mat_compr(ttm, eps);
0098     end;
0099 end;
0100 
0101 end

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