This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Navier-Stokes-Acceleration-Term: 'Unable to extract all indices'.

0 votes

Hi everyone,

i´m trying to solve the Navier-Stokes-Equation and struggling with the Acceleration-Term in Fenics 1.4.

from dolfin import *

A = 0.2     # High Inlet/Outlet
Cellnumber = 10
radius = 1.0

### Create Initial Mesh/Boundary:
mesh = Mesh(Circle(0.0, 0.0, radius),Cellnumber)

V = VectorFunctionSpace(mesh, "CG", 2)
Q = FunctionSpace(mesh, "CG", 1)
W = V * Q

class Inlet(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and (x[0]<0) and (abs(x[1])<A) \
        and ((sqrt(x[0]**2 + x[1]**2)-radius)<DOLFIN_EPS)

class Outlet(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and x[0]>0 and abs(x[1])<A \
        and ((sqrt(x[0]**2 + x[1]**2)-radius)<DOLFIN_EPS)

class Shape(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary \
        and not(x[0]<0 and abs(x[1])<A and ((sqrt(x[0]**2 + x[1]**2)-radius)<DOLFIN_EPS)) \
        and not(x[0]>0 and abs(x[1])<A and ((sqrt(x[0]**2 + x[1]**2)-radius)<DOLFIN_EPS))

boundaries = FacetFunction("size_t", mesh)
boundaries.set_all(0)
Inlet().mark(boundaries, 1)
Outlet().mark(boundaries, 2)
Shape().mark(boundaries, 3)

inflow = Expression(('-x[0]-0.9', '0.0'))
bc0 = DirichletBC(W.sub(0), inflow, boundaries, 1)
bc1 = DirichletBC(W.sub(0), (0.0,0.0), boundaries, 3)
bc2 = DirichletBC(W.sub(1), 0.0, boundaries, 2)
bcs = [bc0, bc1, bc2]

(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)
f = Constant((0.0, 0.0))
g = Constant(0.0)
n = FacetNormal(mesh)
ds = Measure("ds")[boundaries]

#a = (inner(nabla_grad(u),nabla_grad(v)) - p*div(v) + div(u)*q)*dx + (inner(p*n,v) \
#   - inner(nabla_grad(u)*n,v))*ds(1)
#       + inner(u[0]*u.dx(0),v)*dx
#       + inner(dot(nabla_grad(u),u),v)*dx
#L = (inner(f, v) + g*q)*dx

F = (inner(nabla_grad(u),nabla_grad(v)) - p*div(v) + div(u)*q)*dx + (inner(p*n,v) \
    - inner(nabla_grad(u)*n,v))*ds(1) - (inner(f, v) + g*q)*dx

U = Function(W)
#solve(a == L, U, bcs)
solve(F==0,U,bcs)

u, p = U.split()

plot(u)
interactive()

When i use solve(a == L, U, bcs) with the terms inner(u[0]*u.dx(0),v)*dx or inner(dot(nabla_grad(u),u),v)*dx i´m getting the error :
Exception: Unable to extract all indices.
When i use solve(F==0,U,bcs) i´m getting the error:
All terms in form must have same rank.

In this example, it works with inner(grad(u)*u, v)*dx, but it gives also the 'indices'-error.
Could you please help to find my error? What i´m missing?

asked Sep 23, 2014 by MrCoffeee FEniCS Novice (230 points)

1 Answer

0 votes

Some mistakes are

  1. In bilinear form a you cannot use the TrialFunction u more than once in the same expression.
  2. You want dot(grad(u), u) and not dot(nabla_grad(u), u). nabla_grad(u) is the gradient of u transposed, i.e., $\nabla u^T$.
  3. F == 0 expects a linear form F containing only TestFunctions and no TrialFunction. For nonlinear equations use Function instead of TrialFunction. The expressions may then be nonlinear in the Function.
  4. u[0]*u.dx(0) is not convection. It is component u[0] times the partial derivative of u in the x-direction.
answered Sep 25, 2014 by mikael-mortensen FEniCS Expert (29,340 points)

Hello and thx for your answer!
Also sorry for my late response, i was out of town.
I fixed the problem using this Incompressible Navier-Stokes-Demo and just ignore the time-dependancies.

...