Solve system given function instead of matrix

Typically, when solving a classical problem like the Laplace equation, we may construct the matrix A starting from the bilinear form, build the right-hand side b and solve the system using A^(-1)*b. When the matrix A is sparse there is no problem. However, if some non-local terms are in the bilinear form, the matrix of the bilinear form may be full so I would like to avoid constructing it.

On the other hand, constructing a function which computes A*v where v is a vector is quite efficient in my case. Is there a functionality in FreeFEM which allows to solve a system of equations A*x=b if instead of the matrix A we have a function computing the product A*v for an arbitrary v? (I know such a functionality exists for Eigenvalue problems, but I cannot find it quickly in the documentation for a linear system).

Thank you in advance.

I found the solution in the examples file: examples/tutorial/algo.edp

You can also do the same thing using PETSc, e.g., FreeFem-tutorial - Section 8 - example11.edp

you can use l

// the grad of the bilinear part of J (the RHS in remove)
  LinearCG(DJ,u,eps=1.e-6,nbiter=20,precon=matId,verbosity=verb);
  cout << "LinearGC (Affine) : J(u) = " << J(u) << " err=" << error(u,b) << endl;
  LinearCG(DJ,u,eps=1.e-15,nbiter=20,precon=matId,verbosity=50,stop=stop);
  cout << "LinearGC (Affine with stop) : J(u) = " << J(u) << " err=" << error(u,b) << endl;
  LinearCG(DJ0,u,b,eps=1.e-6,nbiter=20,precon=matId,verbosity=verb);
  cout << "LinearGC (Linear) : J(u) = " << J(u) << " err=" << error(u,b) << endl;
  cout << "LinearGMRES (Affine) : J(u) = " << J(u) << " err=" << error(u,b) << endl;
  LinearGMRES(DJ0,u,b,eps=1.e-6,nbiter=20,precon=matId,verbosity=verb);
  cout << "LinearGMRES (Linear) : J(u) = " << J(u) << " err=" << error(u,b) << endl;
{ // ---  a real non linear test ---

form
algo.edp (6.0 KB)

1 Like