### NotImplementedError: Cannot take length of non-vector expression.

247
views
0
11 months ago by
Hi, I am solving coupled problem where p (scalar) and u(vector) are unknowns, after initial solution trying to apply constrain and update for the next step. h1 and h2 are two definition to check and apply constrain. I have got error in line 2:  NotImplementedError: Cannot take length of non-vector expression.
parray = p.vector().array()
parray[h1(u) < h2(u)]=0.0

​

print parray: [ 0. 0. 0. ..., 0. 0. 0.]

any suggestions...
FEniCS version 1.6.0
Thanks for the help
Community: FEniCS Project

0
11 months ago by
Something is most likely wrong with 'h'.  Need a MWE.
For I will try to give MWE but h I have defined as:
def h2(u):
return 0.5*kn*( 0.5*(tr(eps(u)) - abs(tr(eps(u)))) )**2​
written 11 months ago by hirshikesh
h1 and h2 must return np.arrays.
written 11 months ago by pf4d
Thanks for pointing out the error in h. I have rectified this issue .... (I was not projecting on space). Now while assigning to p_old  I am getting Error: Unable to successfully call PETSc function 'VecCopy'. Do we have to do something while assigning ....
# to adjust p
V = FunctionSpace(mesh,'CG',1 )
pold = Function(V)

h2 = NN(u).vector().array()
h1 = PP(u).vector().array()
parray[h1 < h2]=0.0
p.vector().set_local(parray)

pold.assign(p)

# getting error in last line​
written 11 months ago by hirshikesh