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

Intialize dolfin.Vector from dolfin.FunctionSpace (python interface, FEniCS 1.6 or later)

+1 vote

What is the safe way to initialize a dolfin.Vector which is compatible with a given dolfin.FunctionSpace?

More specifically, let Vh be an instance of dolfin.FuctionSpace.

Then if I want to create a new dolfin.Vector u which is compatible with Vh I can simply do

u = dolfin.Function(Vh).vector()

However what if I want to initialize an already existing dolfin.Vector v to be compatible with Vh?

Is the following code safe, or am I missing something?

v = dl.Vector()
v.init(Vh.mesh().mpi_comm(), Vh.dofmap().ownership_range() )

Thanks in advance.

Best regards,

Umberto

asked Sep 7, 2016 by umberto FEniCS User (6,440 points)
...