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