### How to compute $\nabla \phi$ if $\phi$ is a function of degree one ?

238

views

0

Hi, all.

My new question comes again.

I defined two function space, such as P2-P1 for velocity and pressure.

And I need to do the minus: $u=m-\nabla\phi$

Though, I have seen some related function, Project and Interpolate. see here and here. I still do not know the answer properly. I worry about the error influence the stability of my algorithm.

DO YOU HAVE SOME COMMENTS?

BEST, Hamilton
The answer depends on what you want to do with that. Please provide some extra information and hopefully a minimal working example if possible.

My new question comes again.

I defined two function space, such as P2-P1 for velocity and pressure.

And I need to do the minus: $u=m-\nabla\phi$

`u`=`m`−∇`ϕ`, where $m$`m`and $u$`u`are frome P2 vector function space, and $\phi$`ϕ`comes from P1 function space. So, the $\nabla\phi$∇`ϕ`becomes a constant in every triangle. Do I need to reconstruct the gradient $\nabla\phi$∇`ϕ`before doing the minus?Though, I have seen some related function, Project and Interpolate. see here and here. I still do not know the answer properly. I worry about the error influence the stability of my algorithm.

DO YOU HAVE SOME COMMENTS?

BEST, Hamilton

Community: FEniCS Project

written
10 months ago by
Nicolás Barnafi

### 1 Answer

0

I guess from your post that you're implementing a projection scheme for Navier-Stokes?

You can simply do

If you need to compute this sum often (which I guess is the case), you should cast it into variational form, assemble it beforehand, and then compute it with

ps: sorry for the edits, didn't quite get the new syntax..

You can simply do

`project(grad(phi), V)`

, where `V`

could be a DG0 function space. You can project to P2, too, and directly compute: ` u.vector()[:] = m.vector() + project(grad(phi), V).vector()`

`project(grad(phi), V)`

solves \((u, v) = \langle \nabla \phi, v\rangle\) for \(u, v\in V\).If you need to compute this sum often (which I guess is the case), you should cast it into variational form, assemble it beforehand, and then compute it with

`solve(A, u.vector(), b)`

. (At least the projection of the gradient, then add the P2 vectors with `axpy`

).ps: sorry for the edits, didn't quite get the new syntax..

Yes, I am implementing a project scheme for NS equations.

Thanks for your comment. I will try your comment.

The demo of FEniCS has code of Chorin's project method for L-shape domain fluid. see: https://bitbucket.org/fenics-project/dolfin/src/c81e84b7b75dfa642792430793b3e87ac07b3f88/demo/documented/navier-stokes/?at=master

Or, IPCS method, see: https://github.com/hplgit/fenics-tutorial/blob/master/pub/python/vol1/ft07_navier_stokes_channel.py

What I want to implement is one of these kind methods, called gauge method, some details can be found in https://web.math.princeton.edu/~weinan/pdf%20files/gauge%20method.pdf

When I try to implement this method, I encouter several problems. And some of them are posted in community.

If you are interested at this topic, see,

https://www.allanswered.com/post/mgml/how-to-solve-poisson-equation-with-tangential-boundary-condition/

mainly talks about how to implement the tangential velocity. Some questions still be remained, I am glad if you can give some comments.

Best, regs.

Thanks for your comment. I will try your comment.

The demo of FEniCS has code of Chorin's project method for L-shape domain fluid. see: https://bitbucket.org/fenics-project/dolfin/src/c81e84b7b75dfa642792430793b3e87ac07b3f88/demo/documented/navier-stokes/?at=master

Or, IPCS method, see: https://github.com/hplgit/fenics-tutorial/blob/master/pub/python/vol1/ft07_navier_stokes_channel.py

What I want to implement is one of these kind methods, called gauge method, some details can be found in https://web.math.princeton.edu/~weinan/pdf%20files/gauge%20method.pdf

When I try to implement this method, I encouter several problems. And some of them are posted in community.

If you are interested at this topic, see,

https://www.allanswered.com/post/mgml/how-to-solve-poisson-equation-with-tangential-boundary-condition/

mainly talks about how to implement the tangential velocity. Some questions still be remained, I am glad if you can give some comments.

Best, regs.

written
9 months ago by
Hamilton

Well, in the IPCS example they do exactly what you want (and what I've explained).

+ solves involving a3, L3. done.

`# Define variational problem for step 3`

`a3 = dot(u, v)*dx`

`L3 = dot(u_, v)*dx - k*dot(nabla_grad(p_ - p_n), v)*dx`

+ solves involving a3, L3. done.

written
9 months ago by
David Nolte

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