# Attempting to index an object that is already indexed

Hello!
I am extremely new to FEniCS. I am trying to integrate the following system:

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:

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].

1 Like

Thank you very much!
It did help!