This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

generate a Vector or GenericVector in Python

0 votes

Hi, everyone!

some general things
I have played around in Python FEniCS a little bit. Some of the classes and functions are well documented for C++. As for Python user it is sometimes too few. There are many methods for functions, matrix, vector, are really useful in the computation. It would be great if there are more informations and examples in the web based help for these topics.

specific problem about vector
I would like to use powerful linear solver library in FEniCS and want to use solve() method. I have already got a dolfin.cpp.la.matrix instance(stiffness matrix). My right hand side is a rectangular matrix which is also a dolfin.cpp.la.matrix.

It is not possible to solve the linear system directly. So I tried to subtract each column of my rhs into a dolfin.cpp.la.vector object.

the question is
1. It seems impossible to obtain a dolfin.cpp.la.vector from dolfin.cpp.la.matrix
2. for generate a dolfin.cpp.la.vector instance. It also seems hard to realize in Python. (assign size and set_local method does not work)
3. for the method solve(A,x,b) I have to initialize an empty dolfin.cpp.la.vector x which I have no clue about the size.
4. I need to also do some matrix multiplication and transpose etc. but is it possible directly using method in dolfin? I have only seen operations on the matrix itself.

I have also somehow fixed everything by myself. But it is cumbersome.
For the solver problem:
I define new function as L0 = Function(V) and use L0.vector().set_local(rhs[:,0]) and then use solve(K,x,L0.vector())
For the matrix computation:
I have to send it to numpy

Could you give me a hint how to accomplish it?

asked Nov 30, 2015 by truemerlin FEniCS Novice (410 points)

1 Answer

0 votes

If you built dolfin with petsc4py and use PETSc as linear algebra backend, then you can get the columnvectors of A as the following way:

x = PETScVector()
as_backend_type(A).mat().getColumnVector(column_index, x.vec())
answered Dec 1, 2015 by Magne Nordaas FEniCS Expert (13,820 points)

you are right!

thanks!

...