How to access print assembled matrix from variational form

hello sir’
I am not able to access the assembled matrix.

 L = r * (T[0]+T[1]) * f * dx+ \
        r * k_0 * T[0] * (srer_im * (- 2*H_phi_0_re) + srer_re * (- 2*H_phi_0_im)) * ds(5) +\
        r * k_0 * T[1] * (srer_im * (- 2*H_phi_0_im) - srer_re * (- 2*H_phi_0_re)) * ds(5)    
    
    b=assemble(L)
    print(b.array()[:]) ```

error is 
Traceback (most recent call last):
  File "maw_sar_bioheat1.py", line 238, in <module>
    SAR(mesh, cf, mf, 50)
  File "maw_sar_bioheat1.py", line 184, in SAR
    print(b.array()[:])
AttributeError: 'dolfin.cpp.la.Vector' object has no attribute 'array'

Next time, please make a minimal reproducable example.
Your can print the vector with get_local() as illustrated in the code below.:

from dolfin import *
mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, "CG", 1)

v = TestFunction(V)

L = v*dx
b = assemble(L)
print(b.get_local())

or for a matrix, use array:

from dolfin import *
mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, "CG", 1)

v = TestFunction(V)
u = TrialFunction(V)
L = u*v*dx
A = assemble(L)
print(A.array())
1 Like

Thank you for your reply, and i am learning something from you, sir.

please solve the issue.

from dolfin import*
import scipy.sparse
import matplotlib.pyplot as plt

mesh = UnitCubeMesh(10, 10, 10)

V=FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 2)

u=TrialFunction(V)
v=TestFunction(V)

mu0 = 3.14159*4*1e-7
c0 = 299792458
eps0 = 10**7/4/3.14159/c0/c0
Z0 = mu0*c0

eps_r = 1;
mu_r = 1;
freq = 1e9;

m = eps_r*inner(v, u)*dx # Mass form
s = (1/mu_r)*dot(curl(v), curl(u))*dx # Stiffness form

a=assemble(m)
b=assemble(s)
print(a.array())
#print(b.array())

error is

Traceback (most recent call last):
File "vec1.py", line 29, in <module>
print(a.array())
MemoryError: std::bad_alloc```