Methods for computing the inverse of large sparse matrix

Dear Freefem users,I developed a set of finite element programs using FreeFEM,within the time-stepping loop, it is necessary to compute the inverse of a large sparse matrix M,Then, the inverse of M is left-multiplied with a sparse matrix L to obtain a new sparse matrix 𝑀^{-1}*𝐿(denoted as MinvL).The original design of my program was inefficient.As the spatial mesh is refined, the runtime of the program becomes excessively long.The matrix MinvL is used repeatedly and must be computed inside the time-stepping loop, so computing the matrix inverse is unavoidable.
I hope to find a more efficient programming approach to compute the inverse of large sparse matrices more effectively.I hope to receive some help. Thank you very much!
The following is the original design of my program.

varf a (psiany, w) = int2d(Th, qforder=10) (psiany * conj(w));
matrix M = a(Vh, Vh);
set(M, solver=UMFPACK);
int m = M.n;
complex[int, int] MinvDense(m, m);
for (int j = 0; j < m; j++) {
complex[int] b(m);
b = 0;
b[j] = 1.0 + 0i;
complex[int] p = M^-1 * b;
MinvDense(:, j) = p;
}
matrix Minv = MinvDense;

varf l(psiany, w)
=int2d(Th,qforder=10)(
1/(k^2)*(dx(psiany)*dx(conj(w))+dy(psiany)dy(conj(w)))
+1i/k (dx(psiany)A1x+dy(psiany)A1y)conj(w)
+conj(1i/k)
(A1x
dx(conj(w))+A1y
dy(conj(w)))psiany
+(A1x^2+A1y^2)psiany conj(w)
+ mu * psiany * conj(w)
);
matrix L = l(Vh, Vh);// matrix of (1i/k
grad+A)^2
psi+mu
psi
matrix MinvL = Minv * L ;

What do you apply MinvL to?

Yes,I aim to compute the matrix MinvL

Why? What do you compute with MinvL?

In the equation I am solving, the matrix MinvL is an essential component in the construction of the unknown.

What number of degrees of freedom would you ideally want in the finite element space Vh?

test-A(4.16).edp (6.7 KB)


The attachment contains my complete program, and the photo shows the part where the finite element spaces are defined.Later in the program, when computing the inverse of the matrix Mom (denoted as Mominv), I encountered the same issue.

You are not answering my question: what size nn would you like to use?

Thank you for your patience.
I intend to set nn = 16, 32, or 64,
so that“ mesh Th = square(nn, nn)” corresponds to a relatively fine mesh.
I will later use this high-density mesh to study the temporal convergence order.
Is my explanation clear? If there is anything that’s not clear, please feel free to let me know.

So, for nn set to 64, with P3 finite elements, you need about 11 GB of RAM just to store a dense matrix. Your problem is not tractable, it is still not clear to me why you need to actually form MinvL.

I’m looking for ways to optimize this part of the algorithm to speed up the computation.Are you suggesting that we should avoid forming the inverse matrix explicitly?If we can’t avoid computing the inverse and restrict ourselves to nn = 16, is there a more efficient way to write this part of the code?

Could you please write down the math? What is your algorithm computing? You should never invert a matrix and just compute a sequence of forward and backward solves.