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

4 months ago by
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$ρ(ut +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

4 months ago by


dot(inner(f1, grad(f2)), v)*dx​
Thank you, apparently this should work. However, now I face another issue:

"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)    

written 4 months ago by George  
Dear George,
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.
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
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
written 4 months ago by Murilo Moreira  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »