# Attempting to index an object that is already indexed

**URL:** <https://fenicsproject.discourse.group/t/attempting-to-index-an-object-that-is-already-indexed/2127>\
**Category:** variational formulation\
**Created:** [December 20, 2019, 9:54am UTC](https://fenicsproject.discourse.group/t/attempting-to-index-an-object-that-is-already-indexed/2127 "2019-12-20T09:54:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rektangle](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rektangle/32/689_2.png) [@rektangle](https://fenicsproject.discourse.group/u/rektangle)\
**Post date:** [December 20, 2019, 9:54am UTC](https://fenicsproject.discourse.group/t/attempting-to-index-an-object-that-is-already-indexed/2127/1 "2019-12-20T09:54:55Z")

</div>

Hello!  
I am extremely new to FEniCS. I am trying to integrate the following system:  
 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/1X/a6d458e05837f21b80e228925b164fe9c34fa692.png)

I am using approach that is proposed in FEniCS for temporal derivaties: discretize it and iterate over time. Then, for each time step construct corresponding variational problem and solve it sequentially for all time steps.

As a machine I am using google colab  
dolfin version: 2019.1.0

> from fenics import \*  
> T = 5.0 # final time  
> num\_steps = 500 # number of time steps  
> dt = T / num\_steps # time step size  
> mesh = UnitIntervalMesh(10) # Define mesh for the coordinate interval  
> P1 = FiniteElement(‘P’, interval, 1) # Define function space for system of pressure and throughput  
> element = MixedElement([P1, P1])  
> V = FunctionSpace(mesh, element)  
> v\_1, v\_2 = TestFunctions(V) # Define test functions  
> u = Function(V) # Define functions for pressure and throughput  
> u\_n = Function(V)  
> u\_1, u\_2 = split(u) # Split system functions to access components  
> u\_n1, u\_n2 = split(u\_n)  
> k = Constant(dt) # Define expressions used in variational forms  
> two = Constant(2)  
> F = ((u\_1 - u\_n1) / k) \* v\_1 \* dx + div(u\_2) \* v\_1 \* dx   
> + two \* u\_1 \* div(u\_1) \* v\_2 \* dx + u\_2 \* abs(u\_2) \* v\_2 \* dx # Define variational problem  
> vtkfile\_u\_1 = File(‘transient\_system/u\_1.pvd’) #Create VTK files for visualization output  
> vtkfile\_u\_2 = File(‘transient\_system/u\_2.pvd’)  
> progress = Progress(‘Time-stepping’) # Create progress bar  
> set\_log\_level(LogLevel.PROGRESS)  
> t = 0 # Time-stepping  
> for n in range(num\_steps):  
> t += dt # Update current time  
> solve(F == 0, u) # Solve variational problem for time step  
> \_u\_1, \_u\_2, \_u\_3 = u.split() # Save solution to file (VTK)  
> vtkfile\_u\_1 \<\< (\_u\_1, t)  
> vtkfile\_u\_2 \<\< (\_u\_2, t)  
> vtkfile\_u\_3 \<\< (\_u\_3, t)  
> u\_n.assign(u) # Update previous solution  
> progress.update(t / T) # Update progress bar  
> interactive() # Hold plot

The error message is:

## Calling FFC just-in-time (JIT) compiler, this may take some time. Attempting to index with (Ellipsis, Index(8)), but object is already indexed:

UFLException Traceback (most recent call last)  
 in ()  
5  
6 # Solve variational problem for time step  
----\> 7 solve(F == 0, u)  
8 # Save solution to file (VTK)  
9 \_u\_1, \_u\_2, \_u\_3 = u.split()

26 frames  
/usr/lib/python3/dist-packages/ufl/log.py in error(self, \*message)  
170 “Write error message and raise an exception.”  
171 self.\_log.error(\*message)  
 → 172 raise self.\_exception\_type(self.\_format\_raw(\*message))  
173  
174 def begin(self, \*message):

UFLException: Attempting to index with (Ellipsis, Index(8)), but object is already indexed:

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [December 20, 2019, 5:13pm UTC](https://fenicsproject.discourse.group/t/attempting-to-index-an-object-that-is-already-indexed/2127/2 "2019-12-20T17:13:11Z")

</div>

The problem here is that the divergence operator is not defined for a scalar argument. If you want \partial f/ \partial x, for some function f, you can get this in UFL with `f.dx(0)`, i.e., the partial derivative in the 0^\text{th} spatial direction. Alternatively, you could take the 0^\text{th} component of the gradient, i.e., `grad(f)[0]`.

---

<div class="post-metadata">

**Author:** ![rektangle](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rektangle/32/689_2.png) [@rektangle](https://fenicsproject.discourse.group/u/rektangle)\
**Post date:** [December 23, 2019, 12:26pm UTC](https://fenicsproject.discourse.group/t/attempting-to-index-an-object-that-is-already-indexed/2127/3 "2019-12-23T12:26:29Z")

</div>

Thank you very much!  
It did help!
