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

247

views

0

Hi, I am solving coupled problem where p (scalar) and

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

any suggestions...

FEniCS version 1.6.0

Thanks for the help

**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

Something is most likely wrong with 'h'. Need a MWE.

For I will try to give MWE but h I have defined as:

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

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