### Error in Defining vector by expression

27

views

0

Dear Fenics community,

I am trying to calculate the error for my three Trial functions but I have faced a problem by defining my exact solutions as follows:

and I am trying to compute L_2 errors after all as follows:

But I've got an error as below:

Thank you in advance.

Alen

I am trying to calculate the error for my three Trial functions but I have faced a problem by defining my exact solutions as follows:

```
#define exact solution
u_e = Expression('0.5*x[1]*x[1]*x[1] + 0.5*sin((pi*x[1])/2)', degree = 3)
U_e = as_vector([u_e , 0.])
y_e = Expression('1.5*x[1]*x[1] + (pi/4)*cos(pi*x[1]/2)', degree = 2)
Y_e1 = as_vector([0. , 0.])
Y_e2 = as_vector([y_e, 0.])
p_e = Expression('1.5*x[1]*x[1] + (pi/4)*cos(pi*x[1]/2)', degree = 2)
P_e1 = as_vector(0. , p_e)
P_e2 = as_vector(p_e , 0.)
B_1 = Expression('(pi*pi/8)*(sin(pi*x[1]/2) - 3*x[1]', degree = 2)
B = as_vector(B_1, 0.)
```

and I am trying to compute L_2 errors after all as follows:

```
#compute L2 errors
error_L2u = errornorm(U_e, W, 'L2')
error_L2y1 = errornorm(Y_e1, L[0], 'L2')
error_L2y2 = errornorm(Y_e2, L[1], 'L2')
error_L2y = sqrt(error_L2y1 + error_L2y2)
error_L2p1 = errornorm(P_e1, P[0], 'L2')
error_L2p2 = errornorm(P_e2, P[1], 'L2')
error_L2p = sqrt(error_L2p1 + error_L2p2)
```

But I've got an error as below:

```
P_e1 = as_vector(0. , p_e)
File "/usr/local/lib/python2.7/dist-packages/ufl/tensors.py", line 321, in as_
vector
error("Expecting a single Index object.")
File "/usr/local/lib/python2.7/dist-packages/ufl/log.py", line 172, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Expecting a single Index object.
Aborted
```

Thank you in advance.

Alen

Community: FEniCS Project

### 1 Answer

0

I guess you forgot the brackets...

Note that the parenthesis might be on the wrong place, it depends onyour desired evaluation of the expression...

```
p_e = Expression('1.5*x[1]*x[1] + (pi/4)*cos(pi*x[1]/2)', degree = 2)
P_e1 = as_vector([0. , p_e])
P_e2 = as_vector([p_e , 0.])
```

and on the following line one parenthesis and brackets:

```
B_1 = Expression('(pi*pi/8)*(sin(pi*x[1]/2) - 3*x[1])', degree = 2)
B = as_vector([B_1, 0.])
```

Note that the parenthesis might be on the wrong place, it depends onyour desired evaluation of the expression...

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