### Assigning PETSc Vector to the given function space

120

views

-1

```
// I am trying to solve a P2P1 mixed formulation of the Stokes flow.
V_velocity = dolfin.VectorFunctionSpace(mesh, "CG", 2)
V_pressure = dolfin. FunctionSpace(mesh, "CG", 1)
V = V_velocity * V_pressure
u_out = dolfin.Function(V)
// I have my Petsc compiled outside of fenics. I run MPI version of the PETSc solve
// outside fenics and now want to import the solution of the linear solve for post
// processing.
petsc_viewer = PETSc.Viewer()
petsc_viewer.createBinary(name='/tmp/solution.dat', mode=0)
solution_vec = PETSc.Vec().create()
solution_vec.load(viewer=petsc_viewer)
// How do I now assign the solution_vec to the internal Generic vector of the u_out
u_out.vector() = solution_vec // this is not working.
```

Community: FEniCS Project

Please login to add an answer/comment or follow this question.

?

It gives me this error. Any other suggestion?

The following works for me in 2017.2. (Sorry if this appears twice; I may have run into some sort of weird glitch with the forum.)

`V_velocity = VectorElement("CG", mesh.ufl_cell(), 2)`

`V_velocity = VectorElement("CG", 2)`