from fenics import *
import numpy as np
# Create mesh and function space
mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, 'P', 1)
# Define trial and test functions
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v)) * dx
A = PETScMatrix()
assemble(a, tensor=A)
AM = np.array(A.array())
print(f"A[0,0] = {AM[0,0]}")
This is the basic idea that i am using to access few entries of the matrix A to update something for the next iteration in my code. But due to storing large size global matrix its giving me memory error. Can you provide me an alternative so that i don’t get this error and my code work for higher values of M like 256,384,512 etc.