#%% from __future__ import print_function, absolute_import, division import sys sys.path.append('../') import tt from tt.amen import amen_solve """ This program test two subroutines: matrix-by-vector multiplication and linear system solution via AMR scheme""" d = 12 A = tt.qlaplace_dd([d]) x = tt.ones(2,d) y = amen_solve(A,x,x,1e-6) #%% c = tt.multifuncrs2([a, b], lambda x: np.sum(x, axis=1), eps=1E-6) y = amen_solve(A,x,x,1e-6) # %% y # %% A # %% x # %% z=tt.matvec(A,x) # %% z
# #matrix-vector multiplication to maintain f and g and sum both to get the complete righside b b1_qtt = tt.matvec(Lf_qtt,f1_qtt) + tt.matvec(Lbd_qtt,g1_qtt) b2_qtt = tt.matvec(Lf_qtt,f2_qtt) + tt.matvec(Lbd_qtt,g2_qtt) #------------------solving higher order linear system in TT-format------------------ #defining initial guess vector x_qtt= tt.ones(2,int(np.log2(n+1)*(d))) #solving the higher order linear system with AMEN print("") print("Solving Problem 1 with AMEN") print("") u1_qtt=amen_solve(L_qtt,b1_qtt,x_qtt,1e-10,nswp=100) time.sleep(0.01) print("") print("Solving Problem 2 with AMEN") print("") u2_qtt=amen_solve(L_qtt,b2_qtt,x_qtt,1e-10,nswp=100) u2_qtt=u2_qtt.round(1e-10,8) #------------------calculating RMS-Error for the Solution------------------ u1_qtt=np.reshape(u1_qtt.full(),(n+1,n+1,n+1)) u2_qtt=np.reshape(u2_qtt.full(),(n+1,n+1,n+1)) L2_1_qtt = np.sum((u1_qtt-uref1)**2) / n/n/n
#consts I0 = 1 rho = 1 tau = 1 r02 = 1 k_sc = 1 k_abs = 1 k_t = 1 Cv = 1 T0 = 1 #tensor dim dx = 50 pt = 50 dt = 1e-10 #initialisation' t1 = time.time() A = matrix(dx, rho, Cv, k_t) Qs = vector(dx, pt, tau, I0, r02, k_sc, k_abs, rho, Cv, T0) t0 = initial_cond(T0, dx) A, Qs = full_matrix(A, Qs, t0, pt, dt) y = amen_solve(A, Qs, Qs, 1e-14) t2 = time.time() print('error:', (tt.matvec(A, y) - Qs).norm() / Qs.norm()) print('time:', (t2-t1))
from __future__ import print_function, absolute_import, division import sys sys.path.append('../') import tt from tt.amen import amen_solve """ This program test two subroutines: matrix-by-vector multiplication and linear system solution via AMR scheme""" d = 12 A = tt.qlaplace_dd([d]) x = tt.ones(2,d) y = amen_solve(A,x,x,1e-6)
L_tt1 = tt.kron(tt.kron(L_tt, Identity_tt), Identity_tt) L_tt2 = tt.kron(tt.kron(Identity_tt, L_tt), Identity_tt) L_tt3 = tt.kron(tt.kron(Identity_tt, Identity_tt), L_tt) L_tt = L_tt1 + L_tt2 + L_tt3 #------------------solving higher order linear system in TT-format------------------ #defining initial guess vector x = tt.ones(11, d) #solving the higher order linear system with AMEN print("") print("Solving Problem 1 with AMEN") print("") u1 = amen_solve(L_tt, b1_tt, x, 1e-6) time.sleep(0.01) print("") print("Solving Problem 2 with AMEN") print("") u2 = amen_solve(L_tt, b2_tt, x, 1e-6) #------------------calculating RMS-Error for the Solution------------------ RMSE1 = np.sqrt(1 / n * np.sum(u1.full() - uref1)**2) RMSE2 = np.sqrt(1 / n * np.sum(u2.full() - uref2)**2) time.sleep(0.01) #print the Error print("") print("The RMS-Error for Problem 1 is:", RMSE1)