NotImplementedError: Cannot take length of non-vector expression.


94
views
0
3 months ago by
hsk  
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
adjp = p.array().set_local(parray)

​

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

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

1 Answer


0
3 months ago by
pf4d  
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 3 months ago by hsk  
h1 and h2 must return np.arrays.
written 3 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 3 months ago by hsk  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »