Is it possible to modify the elements in the PETSc matrix in parallel computation

When using DDM and PETSc to solving a large problem with multiple parallel processors, the matrix “A“ is usually transferred from FreeFem++ to PETSc, like

Apetsc = A;
set(Apetsc, sparams = “-pc_type hypre -ksp_type bcgs”);

Is it possible to modify the elements in the PETSc matrix Apetsc? For example, we want to a behavior like the setBC operator.

Although we know this can be implemented by first modify the FreeFem++ matrix and then transfer the modified matrix to a PETSc matrix. Is it possible change the order? i.e., first directly transfer to a PETSc matrix from the variational form varf, then just modify the PETSc matrix.

It is not possible to this date. Could you maybe share a little bit more context to see if another approach would be worthwhile? For example, there is an interface to MatZeroRows() if you want an equivalent of setBC() for a PETSc Mat.

Thanks for your reply. My work is about enforcing the Dirichlet boundary condition, especially the point constraint like that implemented in setBC().

From the name of MatZeroRows(), it seems it can be used to zero some specific rows of a matrix. Is this function only usful in PETSc, or it can be used in FreeFem++ with some interface?

If it is the latter, is there any minimal working tutorial? For example, I have a matrix like follows:

[1, 2, 3
 4, 5, 6
 7, 8, 9]

Is it possible let all the elements in 2nd row and 2nd column (except the diagonal one element ) to be zero using the MatZeroRows() in FreeFem++?

There are some examples using MatZeroRows() in the sources.

1 Like