pyoomph
  • Pyoomph Tutorial
    • 1. Preface
    • 2. Installation
    • 3. Temporal Ordinary Differential Equations
    • 4. Spatial Differential Equations
    • 5. Spatio-Temporal Differential Equations
      • 5.1. The wave equation
      • 5.2. Convection-diffusion equation
      • 5.3. Navier-Stokes equation
        • 5.3.1. Womersley flow
        • 5.3.2. Transient and nonlinear generalization of Stokes’ law
        • 5.3.3. Rayleigh-Taylor instability
        • 5.3.4. Marangoni instability
      • 5.4. Lubrication equation
      • 5.5. Continuing a stopped simulation
      • 5.6. Pattern formation, stability analysis and bifurcation tracking
    • 6. Moving Mesh (ALE) Methods
    • 7. Multi-Domain Methods
    • 8. Multi-Component Flow
    • 9. Discontinuous Galerkin methods
    • 10. Advanced stability analysis
    • 11. Plotting interface
    • 12. Coupling multiple simulations with preCICE
    • 13. Miscellaneous settings
    • 14. Mathematical expressions
    • 15. References
pyoomph
  • Pyoomph Tutorial
  • 5. Spatio-Temporal Differential Equations
  • 5.3. Navier-Stokes equation
  • View page source

5.3. Navier-Stokes equation

The Navier-Stokes equation is the same as the Stokes equation in Section 4.4, but with the addition of the inertia term \(\partial_t \vec{u}+\vec{u}\cdot\nabla \vec{u}\). Again, we have to make sure to meet the inf-sup criterion, i.e. we select a Taylor-Hood formulation:

from pyoomph import *
from pyoomph.expressions import *


class NavierStokesEquations(Equations):
     def __init__(self,rho,mu):
             super(NavierStokesEquations, self).__init__()
             self.rho, self.mu= rho,mu # Store viscosity and density

     def define_fields(self):
             self.define_vector_field("velocity","C2") # Taylor-Hood pair
             self.define_scalar_field("pressure","C1")

     def define_residuals(self):
             u,v=var_and_test("velocity") # get the fields and the corresponding test functions
             p,q=var_and_test("pressure")
             stress=-p*identity_matrix()+2*self.mu*sym(grad(u)) # see Stokes equation
             inertia=self.rho*material_derivative(u,u) # lhs of the Navier-Stokes eq. rho*Du/dt
             self.add_residual(weak(inertia,v)+ weak(stress,grad(v)) + weak(div(u),q))

The inertia term is obtained by using the function material_derivative(). Calling this function with any scalar, vectorial or tensorial expressions \(F\) and the velocity \(\mathbf{u}\) will return \(\partial_t F+\operatorname{grad}(F)\cdot\mathbf{u}\).

Warning

The trivial implementation of the Navier-Stokes equation does not allow for high Reynolds numbers. The reason is similar to the problem discussed with the advection-diffusion equation in the previous example. There are improved schemes using SUPG and pressure stabilization to accurately account for the term \(\vec{u}\cdot\nabla\vec{u}\).

We discuss a few examples of the Navier-Stokes equation in the following sections.

Previous Next

© Copyright 2025, Christian Diddens & Duarte Rocha.

Built with Sphinx using a theme provided by Read the Docs.