how to get a sub-matrix from a GenericMatrix?

Asked by Feiteng

Hi all, I want to get the a sub-matrix from a GenericMatrix with [rows, cols]. Is there any way to do this work ?
Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Blechta
Solved:
Last query:
Last reply:
Revision history for this message
Best Jan Blechta (blechta) said :
#1

That depends on situation. You can obtain dense numpy array by Matrix.array() method. Then you could somehow manipulate it using numpy. If you can't afford manipulating with dense representation you have to use some backend specific features. With uBLAS you can use Matrix.data() method. For other backends I'm not sure wheter there is an interface in DOLFIN for such kind of operations.

If you intent getting block of matrix corresponding to some subspace of a mixed space you could rather assemble directly on separate spaces and putting blocks together using cbc.block if needed. Sorry if that's off-topic.

Jan

Revision history for this message
Feiteng (hftenger) said :
#2

Thanks Jan Blechta, that solved my question.