Hi,
i did it this way : (i found this solution somewhere in this forum but i dont know where :-)
from dolfin import*
import numpy as np
from petsc4py import PETSc
import scipy.sparse as sp_sparse
Your matrices and bc come here
test = S.mat()
row, col, data = test.getValuesCSR()
S_scipy = sp_sparse.csc_matrix((data, col, row), shape=(N_row, N_row),dtype=np.float)
test = T.mat()
row, col, data = test.getValuesCSR()
T_scipy = sp_sparse.csc_matrix((data, col, row), shape=(N_row, N_row),dtype=np.float)
nv = S_scipy.shape[0]
auxu = np.zeros((nv,1))
bcinds = []
bcdict = bc.get_boundary_values()
auxu[bcdict.keys(),0] = bcdict.values()
bcinds.extend(bcdict.keys())
fvbc = S_scipy*auxu
invinds = np.setdiff1d(range(nv),bcinds)
S_red = S_scipy[invinds,:][:,invinds]
T_red = T_scipy[invinds,:][:,invinds]
S = PETScMatrix(PETSc.Mat().createAIJ(size=S_red.shape,csr=(S_red.indptr, S_red.indices,S_red.data)))
T = PETScMatrix(PETSc.Mat().createAIJ(size=S_red.shape,csr=(T_red.indptr, T_red.indices,T_red.data)))
You need scipy, numpy and petsc4py for this i guess. For me this solution works flawlessly. However, it does hardly give any performance gain (for me).
Kind regards
Johann