How to compute $\nabla \phi$ if $\phi$ is a function of degree one ?
12 months ago by
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?
Community: FEniCS Project
11 months ago by
You can simply do
project(grad(phi), V), where
Vcould 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
ps: sorry for the edits, didn't quite get the new syntax..
Please login to add an answer/comment or follow this question.