L.zeroEntries() VS loc_L.set(0)

hello,

a quick question on the custom newton solver presented here:

https://jorgensd.github.io/dolfinx-tutorial/chapter4/newton-solver.html

J = ufl.derivative(residual, u) # jacobian of the newton method
J_form = dolfinx.fem.form(J)
r_form = dolfinx.fem.form(residual)
A = dolfinx.fem.petsc.create_matrix(J_form)
L = dolfinx.fem.petsc.create_vector(r_form)

is this code
with L.localForm() as loc_L:
loc_L.set(0)

equivalent to this one:
L.zeroEntries()

?

tbanks,

sebastien
PS: Why is there always 78 ways to do the same thing in Python? (XD)

1 Like

See, e.g., VecZeroEntries and what Vec.localForm() calls which in turn implements VecGhostGetLocalForm.

Use whichever makes sense regarding how you want to handle the ghost entries.

PS: Why is there always 78 ways to do the same thing in Python? (XD)

petsc4py is the python binding for PETSc, not necessarily a python issue. Also these two methods enact different functionality. It’s very challenging to make function and method names which clearly highlight these differences for the uninitiated. The documentation should help, but sometimes I have to read the source code to decipher functions’ utilities.

3 Likes