3 Read a PETSc matrix and print the value(s) at given row and column(s)
9 petsc4py.init(sys.argv)
10 from petsc4py
import PETSc
16 jacMat = PETSc.Mat().create(PETSc.COMM_WORLD)
17 viewer = PETSc.Viewer().createBinary(mat, comm=PETSc.COMM_WORLD)
21 print(
"Getting transposed values")
23 elif transposed ==
"0":
26 print(
"Error!!!transposed should be either 0 or 1")
29 rowVals = jacMat.getRow(int(rowI))
30 nCols = len(rowVals[0])
32 for i
in range(nCols):
33 if (int(colI) == -1)
or (int(rowVals[0][i]) == int(colI)):
34 if abs(rowVals[1][i]) > diffTol:
35 print(
"%16d %20.16e" % (rowVals[0][i], rowVals[1][i]))
38 if __name__ ==
"__main__":
39 print(
"\nUsage: python dafoam_matgetvalues.py matName rowI colI transposed")
40 print(
"Example python dafoam_matgetvalues.py dRdWT.bin 100 25 0")
41 print(
"NOTE: if colI=-1, print all columns\n")