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

Navier Stokes with Mixed BDM/DG: invalid ranks

0 votes

I was trying to solve Navier Stokes Equation in a cavity using the following code:

from dolfin import *

# Print log messages only from the root process in parallel
parameters["std_out_all_processes"] = False;

# Load mesh from file
Lx = 1.
Ly = 1.
nx = 20*10
ny = 20*10
mesh = RectangleMesh(Point(0., 0.), Point(Lx, Ly), nx, ny, 'left')

# Define function spaces (BDM-DG)
V = FunctionSpace(mesh, "BDM", 1)
Q = FunctionSpace(mesh, "DG", 0)    
W = V * Q

# Define test functions
(v, q) = TestFunctions(W)
# Define trial functions
w       = Function(W)
(u, p)  = TrialFunctions(W)

# Set parameter values
nu = 1.

# Define boundary conditions
def boundary_noslip(x,on_boundary):
    return on_boundary and (near(x[0],0.0) or near(x[0],Lx) \
        or near(x[1],0.0))

def boundary_fflow(x,on_boundary):
    return on_boundary and (near(x[1],Ly))

noslip = DirichletBC(W.sub(0), (0., 0.), boundary_noslip)

fflow  = DirichletBC(W.sub(0), (1., 0.), boundary_fflow )

bcu = [noslip, fflow]

# Stress tensor
T = nu*(grad(u) + grad(u).T) - p*Identity(2)

# Weak form
F = ( inner(u*grad(u), v) \
    + inner(nu*grad(u), grad(v)) \
    + inner(T, grad(v))   \
    - div(u)*q \ # <------ ERROR
    )*dx

# Solve
solve(F == 0, w, bcu, solver_parameters={ "newton_solver": 
                                     { "absolute_tolerance": 1.0e-10,
                                       "relative_tolerance": 1.0e-6 } })

# Plot sigma and u
(uF, pF) = w.split()
plot(uF)
plot(pF)
interactive()

But I have an error where the weak formulation is defined:

ufl.log.UFLException: Invalid ranks 1 and 2 in product.

Both q and div(u) seem to have a rank equal to 0 (using *.rank() ). Where is the problem?

asked Nov 16, 2015 by Mixart FEniCS Novice (120 points)

Hi, Mixart.
I guess I met the same problem as what you indicated here. The problem can be in weak form, u*grad(u). In my case, u has rank 1 and grad(u) has rank 2.
If you have fixed this problem, could you share some experience here?

Hi Mixart,
I am also getting the same problem in the weak form, where I'm multiplying rank 1 to rank 2 tensor. if you are able to fix the problem, do share it?

1 Answer

+2 votes

I think the problem could be anywhere in your definition since it is a multiline form. You should split the terms to narrow down which one is causing problems. I suspect the u*grad(u)-Term could be the problem, since the div-term looks okay.

Anyway, the bigger problem with your formulation is that it will most certainly not produce meaningful results. You cannot take an H1-Problem, use an Hdiv-space and get away with it. The built-in inter-element continuities do not match, thus the lack of tangential continuity has to be compensated by DG-like interior penalty terms if you want this to be stable. If you cannot find suitable references I can provide some.

answered Nov 17, 2015 by Christian Waluga FEniCS Expert (12,310 points)
edited Nov 17, 2015 by Christian Waluga
...