Helper function for zeroing out PETSc vectors.
(x: PETSc.Vec)
| 43 | |
| 44 | |
| 45 | def _zero_vector(x: PETSc.Vec): # type: ignore[name-defined] |
| 46 | """Helper function for zeroing out PETSc vectors.""" |
| 47 | if x.getType() == PETSc.Vec.Type.NEST: # type: ignore[attr-defined] |
| 48 | for x_sub in x.getNestSubVecs(): |
| 49 | with x_sub.localForm() as x_sub_local: |
| 50 | x_sub_local.set(0.0) |
| 51 | x_sub.destroy() |
| 52 | else: |
| 53 | with x.localForm() as x_local: |
| 54 | x_local.set(0.0) |
| 55 | |
| 56 | |
| 57 | def create_vector_wrap(x: Vector) -> PETSc.Vec: # type: ignore[name-defined] |