Although there are similar questions, I am also struggling with the implementation of the following term in "my own code" by Finite Element Method, namely, $\nabla \phi \cdot \nabla \phi$. $\phi$ is a state variable such as scalar potential. I think the descritization of this term is much more difficult than that of advection term in N-S equation. If possible, please tell me how to descritize and implement the term by FEM. The equation to solve is as follows, $\frac{\partial \phi}{\partial t} = (\nabla\phi)^2 + \nabla^2 \phi.$

  • $\begingroup$ Writing out your entire set of equations will definitely help. $\endgroup$
    – Paul
    Commented Sep 14, 2014 at 20:38

2 Answers 2


You should rather think of what you will need in the following step, which is probably the numerical time integration of the semi-discrete equations.

  1. If you are going to use a (semi) explicit time stepping scheme, all you need is a function that for a given $\phi_0$ assembles the vector $\langle (\nabla \phi_0)^2, v \rangle$, where $v$ are your test functions. In FEM packages like FEniCS this is straight forward.
  2. If you going for an implicit scheme, you will probably apply a Newton or Picard iteration for the given iteration point $\phi_0$, you will need the forms or matrices associated with $\langle \nabla \phi_0 \nabla u, v \rangle$ where $u$ are the trial functions. This is a linear form that is easy to assemble with standard FEM methods.
  3. For atmost generality you can tensorize your problem, express $(\nabla \phi)^2$ via $D_\nabla (\phi \otimes \phi)$ and assemble the associated linear form (linear in the Kronecker product). For an example considering the convection term $(u \cdot \nabla) u$ in the Navier-Stokes equations have a look at this python function.
  • $\begingroup$ Thank you for your answer. But I still have a question. It seems that the inner product in 1. is discretized as "source term". Is there theoretical reason for this? $\endgroup$ Commented Sep 15, 2014 at 23:37
  • $\begingroup$ Right. This comes out of explicit time integration schemes like the explicit Euler $u^{k+1} = u^k + \tau f(t^k)$. $\endgroup$
    – Jan
    Commented Sep 16, 2014 at 5:03

Nonlinear differential equations are really no different than other nonlinear equations that you can solve with a Newton method. You may want to take a look at the discussion how this is done in a typical finite element code for a stationary problem here: http://dealii.org/developer/doxygen/deal.II/step_15.html

The code shows how to do it for a stationary problem, but the process is the same for every time step if you use a fully implicit method. Of course, the process becomes a lot simpler if you treat the nonlinear term as explicit in the time stepping scheme.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.