3 Read a PETSc vector and print the value(s) at given row(s)
9 petsc4py.init(sys.argv)
10 from petsc4py
import PETSc
16 vec1 = PETSc.Vec().create(comm=PETSc.COMM_WORLD)
17 viewer = PETSc.Viewer().createBinary(vecName, comm=PETSc.COMM_WORLD)
22 vecSize = vec1.getSize()
25 for i
in range(vecSize):
26 if abs(vec1.getValue(i)) > diffTol:
27 print(
"%12d %16.14e" % (i, vec1.getValue(i)))
29 print(
"%12d %16.14e" % (rowI, vec1.getValue(rowI)))
32 if __name__ ==
"__main__":
33 print(
"\nUsage: python dafoam_vecgetvalues.py vecName rowI")
34 print(
"Example python dafoam_vecgetvalues.py dFdW.bin 100")
35 print(
"NOTE: if rowI=-1, print all elements\n")