Define initial guess as vector
from dolfin import * mesh = UnitIntervalMesh(3) p = FunctionSpace(mesh, 'DG',0) pold = as_vector([1,1.5,1.5,1.5]) print shape(Function(p)) print shape(pold) pold = project(pold,Function(p)) plot(pold) interactive()
Thanks for the help.
poldand your mesh has four nodes).
Then you have to change the function space to CG:
from dolfin import * import numpy as np mesh = UnitIntervalMesh(3) p = FunctionSpace(mesh, 'CG',1) pold = Function(p) inds = vertex_to_dof_map(p) pold.vector()[inds] =np.array([1,1.5,1.5,1.5]) plot(pold) interactive()
Use project() on an expression and a function space, not a function:
pold = project(pold,p)
but this will fail anyway for your code. Project() projects an expression onto your function space, whereas I think you are actually trying to give it nodal answers like klunkean mentioned. Your function space is 1D, as your first shape() confirms (the empty bracket means 1). The dimension of 'pold' is 4 since it is a vector of 4 elements. Therefore you are trying to project a 4 dimensional vector onto a 1 dimensional function space and it fails (clearly).
If you do:
pold = Constant(1.5)
then it will work, and assign 1.5 to everywhere.
I think you might be confusing the 'vector' expression with the solution vector...