Is it possible to create a matrix with linear form

Hello

If I have the following terms

f = Coefficient(V)
v = Testfunction(V)
a = f * v * dx

then if I assemble the form, I will get a vector, but if it possible to keep it as a matrix, like the mass matrix, but here I want to keep the function f be something that I can input myself, so I didn’t define it as a Trial function.

What do you mean by input yourself?

You can just make the mass matrix with a trial function, and then use matrix-vector multiplication at a later stage if you want to re-use the data.

I need to change the function f frequently, and I need to do operation on the element of this matrix.

Then create he mass matrix (using a trial function), and then do MatVec operations internally.
I for instance do this in Python within oasisx:

using MatMult — PETSc 3.22.1 documentation

1 Like