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

Help to assemble nonlinear term in Navier-Stokes Equation

0 votes

Hi, could I ask a strong question that is it possible to assemble the nonlinear term in the Navier-Stokes equation? I tried the following codes but fails,

a = inner ( nabla_grad (U) * U, V ) * dx
A = assemble(a)

Since it is not a linear form for U, which is the velocity vector, I think the for the data might
be a 3D matrix.
Could I ask is it possible to get this assembling data directly through some functions in FEniCS? So thanks for your helps!

asked Jan 20, 2014 by Hrunx FEniCS Novice (910 points)

2 Answers

+6 votes
 
Best answer

If U is a Function you may assemble this form and obtain a
vector. You may also differentiate to obtain the Jacobian, which is
a matrix. However, the form must always be linear in arguments
that are trial or test functions.

answered Jan 20, 2014 by Kent-Andre Mardal FEniCS Expert (14,380 points)
selected Jul 27, 2014 by Hrunx

For former approach to linearization check demo_navier-stokes. For latter, demo_auto-adaptive-navier-stokes.

Thanks all for the helps. Could I ask one more question about are there some demo codes for assembling a high rank multilinear form?

Since my goal is not to solve this PDE equation directly, but to get this high rank tensor> Maybe I can use two trial functions which share the same function space to generate a multilinear form and calculate this tensor matrix. I tried the following codes but failed. Thanks a lot!

nx = ny = 2
mesh = UnitSquare(nx, ny)
# Define function spaces
V = VectorFunctionSpace(mesh, "CG", 2)
Q = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([V,V])
# Define test and trial functions
Trial = TrialFunction(W)
v1 = TestFunction(Q)
u1,u2 = split(Trial)
a1 = inner(grad(u1)*u2,v1)*dx
A = assemble(a1)   

Assembling ranks higher than two is not supported as there's no container for these in backends.

I believe that UFL language allows you to define multilinear forms (by using Argument class, not by using more TestFunctions). Still these can't be assembled but can be applied/contracted so that a result can be assembled (if has supported rank 0,1,2).

So thanks for your answers, they make things much clear! Could I ask the difference between Argument and TrialFunction? For example,

v = TrialFunction(V)
u = TestFunction(V)
w = Argument(V)

I checked the webpage ufl Package and can see the difference between TrialFunction and TestFunction, but failed to image what is Argument, is its basis set different?

Thanks again for your patience!

Both TestFunction and TrialFunction are subclasses of Argument,
Argument(-2), and Argument(-1), respectively.
You can have more arguments by, Argument(0), Argument(1) etc.
Arguments are different from Coefficients.

+3 votes

Have a look at the demo concerning a non-linear Poisson equation. There you will find how to formulate and solve equations with non-linear terms.

answered Jan 20, 2014 by Øyvind Evju FEniCS Expert (17,700 points)
...