### How to define the variational problem for Navier-Stokes with an external force depending on a the product of a scalar and a gradient functions

187

views

0

Hi,

I'm trying to solve the Navier-Stokes equation, following the footsteps of the tutorial solution by Hans Petter Langtangen and Anders Logg.

The equation is: $\rho\left(\frac{\partial u}{\partial t}+u.\nabla u\right)=\nabla.\sigma\left(u,p\right)+f$

In the variational form, the term involving f would, in principle, be written as

Now, in my case this external force

If I try:

f = f1*grad(f2) # Error: ufl.log.UFLException: Invalid ranks 1 and 2 in product.

dot(f, v)*dx

Any clues? I appreciate your attention and help.

I'm trying to solve the Navier-Stokes equation, following the footsteps of the tutorial solution by Hans Petter Langtangen and Anders Logg.

The equation is: $\rho\left(\frac{\partial u}{\partial t}+u.\nabla u\right)=\nabla.\sigma\left(u,p\right)+f$

`ρ`(∂`u`∂`t`+`u`.∇`u`)=∇.`σ`(`u`,`p`)+`ƒ`, where the variables are: u: velocity, p: pressure, \sigma is a stress tensor and f an external force.In the variational form, the term involving f would, in principle, be written as

*dot(f, v)*dx*for some test function v for velocity.Now, in my case this external force

*f*has a more complicated form. It is given as the product of a scalar function say f1 and a gradient of another scalar function (f2), such as $\text{ f = f1}\cdot\nabla\left(f2\right)$ f = f1·∇(`ƒ`2). Then, at this point, I don't know how to treat the variational problem.If I try:

f = f1*grad(f2) # Error: ufl.log.UFLException: Invalid ranks 1 and 2 in product.

dot(f, v)*dx

Any clues? I appreciate your attention and help.

Community: FEniCS Project

### 1 Answer

1

Hi,

try:

try:

`dot(inner(f1, grad(f2)), v)*dx`

Dear George,

I may be missing a point, but why do you use a mixed element for f1 and f2?

All the best, Murilo

I may be missing a point, but why do you use a mixed element for f1 and f2?

All the best, Murilo

written
4 months ago by
Murilo Moreira

f1 represents concentration of a given electrolyte and f2 is the field caused due to the concentration of such electrolyte.

They give rise to this external electrical force f that I'm trying to fit in the equation. I was trying to solve using the splitting method described in the Fenics tutorial, where in this first step the test function "lived" in the velocity space, but as I added this mixed term, I'm confused on how to proceed with the test function.

They give rise to this external electrical force f that I'm trying to fit in the equation. I was trying to solve using the splitting method described in the Fenics tutorial, where in this first step the test function "lived" in the velocity space, but as I added this mixed term, I'm confused on how to proceed with the test function.

written
4 months ago by
George

If w is a mixed function space and v, q trial functions then:

`(v, q) = TrialFunctions(W)`

written
4 months ago by
Minas Mattheakis

So, what you're saying (in this context) is that f1, f2 and u should live in the same mixed function space?

u: velocity

f: external force, f = f1*grad(f2) where f1 and f2 are scalars

u: velocity

f: external force, f = f1*grad(f2) where f1 and f2 are scalars

written
4 months ago by
George

You should search for a tutorial in mixed elements with fenics. Otherwise post a part of your code (or all of it if not too big) so someone can debug it.

written
4 months ago by
Minas Mattheakis

Ofcourse. The test function must live on a mixed function space too.

written
4 months ago by
Minas Mattheakis

Dear Minas,

Thank you for your answer!

But aren't f1 and f2 normal (in the sense of not being test functions haha not related to any normal) functions that define the RHS of the author's problem?

Because when you multiply it by a test function from the vector space, I think that we will have a mismatch of shapes.

Sorry if I am mistaken.

If you can explain your point of view and why your answer should work, I will be thankful!

All the best, Murilo

Thank you for your answer!

But aren't f1 and f2 normal (in the sense of not being test functions haha not related to any normal) functions that define the RHS of the author's problem?

Because when you multiply it by a test function from the vector space, I think that we will have a mismatch of shapes.

Sorry if I am mistaken.

If you can explain your point of view and why your answer should work, I will be thankful!

All the best, Murilo

written
4 months ago by
Murilo Moreira

Please login to add an answer/comment or follow this question.

"ufl.log.UFLException: Shapes do not match:"

Are there any particularly requirement for the elements of the functions involved?

v comes from:

V = VectorFunctionSpace(mesh, 'P', 2) #velocity function space (quadratic)

v = TestFunction(V)

whereas f1 and f2 from:

P1 = FiniteElement('P',tetrahedron, 1)

element = MixedElement([P1, P1,P1])

fspace = FunctionSpace(mesh, element) f1 = Function(fspace)

f2 = Function(fspace)