0001
0002
0003
0004
0005
0006 function xi = solvePrecond(L, P, rhs, xL, xR, opts )
0007
0008 if nargin==5
0009 opts.precond_tol = 1e-5;
0010 opts.precond_maxit = 5;
0011 end
0012
0013 P_rhs = precond_laplace( P, rhs );
0014
0015
0016
0017 function y = fun_A(x)
0018
0019 x_tangent = fill_with_vectorized( dummy, x );
0020 x_ttemps = tangent_to_TTeMPS( x_tangent );
0021 y_ttemps = apply(L, x_ttemps);
0022 y_tangent = TTeMPS_tangent_orth( xL, xR, y_ttemps );
0023 y = vectorize_tangent( y_tangent );
0024 end
0025
0026 function y = fun_P(x)
0027 x_tangent = fill_with_vectorized( dummy, x );
0028 eta = precond_laplace( P, x_tangent );
0029 y = vectorize_tangent( eta );
0030 end
0031
0032 if opts.precond_maxit > 1
0033 dummy = rhs;
0034
0035 tol = opts.precond_tol;
0036 maxit = opts.precond_maxit-1;
0037
0038 [xi_vec,flag,relres,iter] = pcg(@fun_A, vectorize_tangent(rhs), tol, maxit, @fun_P, [], vectorize_tangent(P_rhs) );
0039 iter
0040 xi = fill_with_vectorized( dummy, xi_vec );
0041 else
0042 xi = P_rhs;
0043 end
0044
0045 end