The Stokes equations

The Stokes equations#

Author: Jørgen S. Dokken

SPDX-License-Identifier: MIT

We solve the Stokes equations

\[\begin{split} \begin{align} -\nu\Delta u + \nabla p &= f && \text{in } \Omega = [0, 1]^2,\\ \nabla\cdot u &= 0 && \text{in } \Omega,\\ u &= g && \text{on } \partial\Omega, \end{align} \end{split}\]

with a manufactured solution. The velocity is a vortex, given by the curl of the stream function \(\psi(x) = \mathrm{e}^{-a\vert x - x_0\vert^2}\) with \(a=40\) and \(x_0 = (0.4, 0.55)\), such that it is divergence free, and the pressure is \(p(x) = \sin(\pi x_0)\cos(\pi x_1)\).

Discretisation#

Each cell of degree \(k\) has a discontinuous velocity of degree \(k\) and a discontinuous pressure of degree \(k-1\). The problem has two fields, and each degree has one space for the velocity and one for the pressure on the submesh of its cells. The viscous term is discretised with the symmetric interior penalty method, and the velocity and pressure are coupled by [SchotzauST02]

\[ b(v, q) = -\sum_K\int_K q\nabla\cdot v~\mathrm{d}x + \sum_F\int_F \{q\}[v\cdot n]~\mathrm{d}s + \int_{\partial\Omega} q\, v\cdot n~\mathrm{d}s. \]

When the velocity is under-resolved, the discontinuous pressure can oscillate between the cells around a vertex. The jumps of the pressure are therefore penalised on the interior facets [CKSchotzauS02],

\[ c(p, q) = \sum_F \int_F \gamma_p\frac{h}{\nu}[p][q]~\mathrm{d}s, \]

which is subtracted from the continuity equation, with \(\gamma_p=1\) by default (pressure_stabilisation). The exact pressure has no jumps, so the method stays consistent.

With a Dirichlet condition on the whole boundary, the pressure is only determined up to a constant. The approach gives the constant pressure as the nullspace of the matrix (nullspace()), and the error of the pressure is measured after removing its mean value.

from mpi4py import MPI

import dolfinx
import pyvista
import ufl

from dolfinx_padapt.adaptivity import solve_adaptive
from dolfinx_padapt.approaches import SubmeshApproach
from dolfinx_padapt.forms import Parameters
from dolfinx_padapt.models import StokesProblem
from dolfinx_padapt.plotting import Animation, plot_history, plot_iteration

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 12, 12)
x0 = (0.4, 0.55)


def u_exact(x):
    psi = ufl.exp(-40 * ((x[0] - x0[0]) ** 2 + (x[1] - x0[1]) ** 2))
    return ufl.as_vector((psi.dx(1), -psi.dx(0)))


def p_exact(x):
    return ufl.sin(ufl.pi * x[0]) * ufl.cos(ufl.pi * x[1])


problem = StokesProblem(mesh, u_exact, p_exact, viscosity=1.0)

The adaptive loop#

The error indicator has the residual of the momentum equation and of the divergence on each cell, and the jumps of the velocity and of the normal flux \((\nu\nabla u - pI)n\) on the facets. The adaptive loop uses the error of the velocity in the broken \(H^1\)-seminorm. We plot the magnitude of the velocity and the degree of each cell at every iteration.

params = Parameters(pmin=1, pmax=5)
approach = SubmeshApproach(problem, params)
with Animation(mesh.comm, "stokes.gif") as animation:
    history = solve_adaptive(approach, max_iterations=20, tol=1e-2, callback=animation)
 it     dofs      error        eta  update   solve  estim.  values, degrees
  0     2016  7.604e+00  4.601e+01   0.024   0.015   0.001  u_H1=7.604230794, u_L2=0.1802202429, p_L2=0.1642769795, {1: 288}
  1     2232  4.534e+00  2.069e+01   0.025   0.016   0.001  u_H1=4.534135333, u_L2=0.08924260953, p_L2=0.2170056877, {1: 261, 2: 27}
  2     2388  3.595e+00  1.596e+01   0.024   0.025   0.001  u_H1=3.595399391, u_L2=0.0630676514, p_L2=0.2439990325, {1: 247, 2: 37, 3: 4}
  3     3177  1.349e+00  7.122e+00   0.024   0.033   0.001  u_H1=1.348577791, u_L2=0.02167870329, p_L2=0.1433076442, {1: 190, 2: 65, 3: 32, 4: 1}
  4     3725  6.554e-01  3.488e+00   0.025   0.039   0.001  u_H1=0.6553955429, u_L2=0.009822622453, p_L2=0.0958828795, {1: 159, 2: 70, 3: 57, 4: 2}
  5     4461  3.630e-01  1.931e+00   0.024   0.061   0.001  u_H1=0.3630135115, u_L2=0.006103898347, p_L2=0.0859859741, {1: 134, 2: 59, 3: 83, 4: 12}
  6     5539  1.794e-01  9.771e-01   0.025   0.096   0.002  u_H1=0.1794422753, u_L2=0.004245430731, p_L2=0.07251431506, {1: 111, 2: 41, 3: 96, 4: 37, 5: 3}
  7     6646  8.335e-02  4.629e-01   0.024   0.131   0.002  u_H1=0.0833509809, u_L2=0.003621524401, p_L2=0.06526611242, {1: 94, 2: 34, 3: 78, 4: 72, 5: 10}
  8     7850  4.757e-02  2.604e-01   0.025   0.178   0.002  u_H1=0.04757247644, u_L2=0.002869603073, p_L2=0.05763626834, {1: 73, 2: 25, 3: 77, 4: 87, 5: 26}
  9     9394  1.864e-02  1.094e-01   0.024   0.244   0.002  u_H1=0.01864340948, u_L2=0.0002881693872, p_L2=0.008870285965, {1: 12, 2: 76, 3: 51, 4: 97, 5: 52}
 10    10494  9.378e-03  5.708e-02   0.025   0.293   0.002  u_H1=0.00937828666, u_L2=8.091130963e-05, p_L2=0.003098297124, {1: 2, 2: 73, 3: 39, 4: 91, 5: 83}
gif

The errors of the velocity and the pressure at each iteration:

if mesh.comm.rank == 0:
    plot_history(
        {"adaptive": history}, "stokes_history.png", ylabel=r"$\Vert\nabla(u_h-u_{ex})\Vert$"
    )
    for result in history[-3:]:
        print(f"{result.iteration}: {result.num_dofs} dofs, {result.values}")
8: 7850 dofs, {'u_H1': 0.04757247643568454, 'u_L2': 0.002869603073111321, 'p_L2': 0.05763626833875315}
9: 9394 dofs, {'u_H1': 0.018643409477703803, 'u_L2': 0.00028816938715647285, 'p_L2': 0.008870285965233241}
10: 10494 dofs, {'u_H1': 0.009378286659941263, 'u_L2': 8.091130962910342e-05, 'p_L2': 0.00309829712383347}
../_images/26529b149b3ec7843879dbcb745ebc36876a942842bb9df7a98ca5a16722749f.png

history

Finally, we plot the pressure of the last iteration, together with the degrees.

plotter = plot_iteration(approach, field="p", title="Pressure")
if plotter is not None:
    if not pyvista.OFF_SCREEN:
        plotter.show()
    else:
        plotter.screenshot("stokes_pressure.png")
[CKSchotzauS02]

Bernardo Cockburn, Guido Kanschat, Dominik Schötzau, and Christoph Schwab. Local discontinuous Galerkin methods for the Stokes system. SIAM Journal on Numerical Analysis, 40(1):319–343, 2002. doi:10.1137/S0036142900380121.

[SchotzauST02]

Dominik Schötzau, Christoph Schwab, and Andrea Toselli. Mixed hp-DGFEM for incompressible flows. SIAM Journal on Numerical Analysis, 40(6):2171–2194, 2002. doi:10.1137/S0036142901399124.