1 Introduction

There are many popular methods for numerically solving the incompressible Navier–Stokes equations in complex geometries. For instance, the immersed boundary method [24], the immersed interface method [21] and the ghost fluid method [11] are popular since they allow one to use a regular grid with an immersed domain boundary. Other efficient methods for the Navier–Stokes or heat equation include [13, 14, 23]. These methods not only use a regular grid, but also utilize level set functions to ensure a sharp interface. In all cases, the regular grid and level set formulation alleviates many of the numerical difficulties introduced by curved or moving boundaries. In this paper, we focus on the volume penalty method [1, 2, 6, 7, 18], which loosely fits into the same class of methods.

As a result of their simplicity, penalty methods have been used in a wide variety of problems including electromagnetism, magnetohydrodynamics [22], shape optimization [9], fluid-solid interaction problems [10, 17] and even simpler problems such as the heat equation or Poisson equation [25]. In the context of fluids, they provide a simple means for solving the incompressible Navier–Stokes equations in domains with boundaries. The approach relies on replacing the often difficult to implement Dirichlet fluid boundary conditions, with a simpler to implement volumetric forcing term in the advection equation.

Despite the simplicity, the penalty method suffers from i) poor convergence in the penalty parameter, thereby restricting the accuracy of numerical methods and, ii) a lack of regularity in the velocity field which reduces the advantages of spectral methods. For example, solutions to the penalized equations have a discontinuous second derivative which limits the decay rate of the Fourier coefficients, as well as the ability to spectrally compute derivatives. Despite the lack of smoothness, stable and low order spectral methods have been successfully used to solve the penalized fluid equations [17, 19].

The focus of our paper is to introduce a systematic method for improving the accuracy of penalty methods. Current methods which improve accuracy rely on introducing a subgrid numerical construct in the vicinity of the domain boundary [26, 27]. Such approaches, however, are restrictive if one wishes to eventually use high order Fourier methods. One distinct difference with our approach is that we alter the equations at the continuous level to improve the analytic convergence rate of the penalized problem to the original unpenalized problem. The improved analytic convergence rate then allows for higher order numerical schemes.

We first introduce the original volume penalty method, followed by an introduction to the improved active penalty method. We then explicitly show how to analytically construct the new penalty term. Following the construction, we then examine a model equation to demonstrate how the active penalization improves the convergence rate for the Poisson equation.

After discussing the improved convergence, we focus on numerical details. First, we examine the stability of the new active penalty term, and show that it does not introduce additional numerical stiffness. We then provide numerical examples for the heat equation, in dimensions one and two, showing second and third order schemes. Lastly, we outline how to handle the divergence constraint for the Navier–Stokes equations and provide numerical examples showing second order convergence (in \(L^{\infty }\)) in the velocity field and first order in the pressure.

2 Navier–Stokes and Volume Penalty Equations

The aim of our work is to examine the behavior of a fluid in the vicinity of a solid or a porous medium. For instance, two examples include the motion of a fluid in a bounded domain with hard walls, or the motion around an immersed solid body such as the one shown in Fig. 1. In our case, we consider dimensions \(D = 2, 3\) and let \(\varOmega _p \subset {\mathbb {R}}^D\) denote the physical fluid domain. For our purposes, \(\varOmega _p\) is an open set with \(C^2\) boundary \(\Gamma = \partial \varOmega _p\).

2.1 Incompressible Navier–Stokes Equations

Through the conservation of mass and momentum, the incompressible Navier–Stokes equations govern the flow of an incompressible fluid for \(\mathbf {x} \in \varOmega _p\)

$$\begin{aligned} \partial _t \mathbf {u} + \mathbf {u}\cdot \nabla \mathbf {u}&= -\nabla p + \mu \Delta \mathbf {u} + \mathbf {f} \end{aligned}$$
(1)
$$\begin{aligned} \nabla \cdot \mathbf {u}&= 0. \end{aligned}$$
(2)

Here \(\mathbf {u}(\mathbf {x}, t)\) is the velocity vector field, \(p(\mathbf {x}, t)\) is the pressure, \(\mu > 0\) is the kinetic viscosity, and \(\mathbf {f}(\mathbf {x}, t)\) is an external forcing such as gravity.

To supplement the bulk equations (1)–(2), the fluid velocity also satisfies prescribed boundary conditions

$$\begin{aligned} \mathbf {u}&= \mathbf {g} \quad \,\,\, \text{ for } \mathbf {x} \in \Gamma \end{aligned}$$
(3)
$$\begin{aligned} \int \limits _{\Gamma } \mathbf {g}\cdot \mathbf {n} \, \mathrm {d}A&= 0 \end{aligned}$$
(4)

Here \(\mathbf {n}\) is an outward pointing normal, while Eq. (4) represents a consistency condition on the boundary data. Although we allow \(\mathbf {g} = \mathbf {g}(\mathbf {x}, t)\) to be a function of both space and time, the case of \(\mathbf {g} = 0\) represents the practical condition of a no-slip and no-flux boundary condition. Together, Eqs. (1)–(2) with boundary data (3) describe the evolution of an initial, divergence-free velocity field \(\mathbf {u}(\mathbf {x}, 0) = \mathbf {u}_0(\mathbf {x})\).

2.2 Volume Penalty Equations

Domains with curved boundaries \(\Gamma \) present several challenges to the numerical solution of Eqs. (1)–(2). For example, curved boundaries or immersed objects limit the use of Fourier methods since solutions are not periodic, or easily extended to periodic functions. One simple solution to handle complicated or moving boundaries is through the use of a volume penalty term in the Navier–Stokes equations. In such a case, one removes the Navier–Stokes boundary condition, and instead adds a drag term to the momentum equation.

To introduce the penalized equation, we first denote \(\varOmega _s\) as the solid domain of the obstacle or wall. Here the obstacle region \(\varOmega _s = \overline{\varOmega }_s\) is a closed set which shares the same boundary as the fluid, \(\partial \varOmega _s = \Gamma \). The penalized equations are then defined on a computational domain \(\varOmega \) which is the union of the physical and solid domains \(\varOmega = \varOmega _p \bigcup \varOmega _s\). In our case we take \(\varOmega \) to be a rectangular domain with periodic boundary conditions, i.e. \(\varOmega = {\mathbb {T}}^D\) where \({\mathbb {T}}^D\) is the D-dimensional torus.

Fig. 1
figure 1

Illustration of the physical fluid (\(\varOmega _p\)) and solid obstacle (\(\varOmega _s\)) domains

For a stationary obstacle with a \(\mathbf {g} = 0\) boundary condition, the volume penalty equations (see [35]) are

$$\begin{aligned} \partial _t \mathbf {u}_{\eta } + \mathbf {u}_{\eta }\cdot \nabla \mathbf {u}_{\eta }&= -\nabla p_{\eta } + \mu \Delta \mathbf {u}_{\eta } + \mathbf {f} - \eta ^{-1}\chi _s \; \mathbf {u}_{\eta }\quad \,\,\,\, \mathbf {x} \in \varOmega \end{aligned}$$
(5)
$$\begin{aligned} \nabla \cdot \mathbf {u}_{\eta }&= 0. \end{aligned}$$
(6)

Here \(\eta \) is a small parameter, and \(\chi _s(\mathbf {x})\) is the characteristic function on \(\varOmega _s\), namely

$$\begin{aligned} \chi _s(\mathbf {x}) = {\left\{ \begin{array}{ll} 0 &{} \text {for } \mathbf {x} \in \varOmega \setminus \varOmega _s \\ 1 &{} \text {for } \mathbf {x} \in \varOmega _s \end{array}\right. }. \end{aligned}$$
(7)

In the limit \(\eta \rightarrow 0\), the drag term in Eq. (5) becomes large and tends to slow the fluid inside \(\varOmega _s\). Rigorous convergence results by Angot et al. [3], and Carbou and Fabrie [8] show that the penalized velocity \(\mathbf {u}_{\eta }\) converges to the solution of the Navier–Stokes equations \(\mathbf {u}\) with an error rate of \(O(\eta ^{1/2})\) in the \(L^2(\varOmega _p)\) norm.

2.3 Improved Volume Penalty Equations

Although the volume penalty equations do converge to Navier–Stokes as \(\eta \rightarrow 0\), the convergence rate is slow and therefore may limit the accuracy of resulting numerical schemes. For example, let \(\mathbf {u}_{\eta , num}\) denote a numerical solution for the penalized equations. One is then interested in quantifying the numerical error for \(\mathbf {u}_{\eta , num}\) compared to \(\mathbf {u}\), the solution to the original Navier–Stokes problem (1)–(2). Using the triangle inequality,Footnote 1 the error can be controlled by

$$\begin{aligned} ||\mathbf {u} - \mathbf {u}_{\eta , num}||_2 \le ||\mathbf {u} - \mathbf {u}_{\eta }||_2 + ||\mathbf {u}_{\eta } - \mathbf {u}_{\eta , num}||_2. \end{aligned}$$
(8)

Rigorous convergence results then bound the first term as \(||\mathbf {u} - \mathbf {u}_{\eta }||_{2} \sim \eta ^{1/2}\), while \(||\mathbf {u}_{\eta } - \mathbf {u}_{\eta , num}||_2\) depends on the numerical details and order of the scheme. Finally, we note that the addition of the penalty term introduces time scales of \(O(\eta )\) and length scales of \(O(\eta ^{1/2})\) into the solution \(\mathbf {u}_{\eta }\). To appropriately resolve the boundary layers in the penalty equations (5)–(6), one then has a grid spacing of \(\Delta x \sim \sqrt{\eta }\) leading to a first order bound

$$\begin{aligned} ||\mathbf {u} - \mathbf {u}_{\eta , num}||_2 \le O(\Delta x). \end{aligned}$$
(9)

In light of the above observations, a high order penalty method must either increase the boundary layer width \(O(\sqrt{\eta })\), or improve the analytic convergence rate in the penalty parameter. We adopt the second approach, and outline how Eq. (5) can be modified to better approximate the original Navier–Stokes problem (1)–(2). Furthermore, we note that when modifying the penalty term, it is important to avoid the introduction of additional length or time scales which would hinder the development of high order numerical schemes. To improve the penalized equations, we exploit the fact that \(\mathbf {u}\) satisfies the boundary conditions on \(\Gamma \), and does not represent a physical flow inside \(\varOmega _s\). Specifically, we modify the penalty term so that the flow tracks an extension function \({\tilde{\mathbf {g}}}\) defined on \(\mathbf {x} \in \varOmega _s\). In such a case, the volume penalty equations take the form

$$\begin{aligned} \partial _t \mathbf {u}_{\eta } + \mathbf {u}_{\eta }\cdot \nabla \mathbf {u}_{\eta }&= -\nabla p_{\eta } + \mu \Delta \mathbf {u}_{\eta } + \mathbf {f} - \eta ^{-1}\chi _s \; (\mathbf {u}_{\eta } - {\tilde{\mathbf {g}}})\quad \,\, \mathbf {x} \in \varOmega \end{aligned}$$
(10)
$$\begin{aligned} \nabla \cdot \mathbf {u}_{\eta }&= 0 \quad \,\,\,\, \mathbf {x} \in \varOmega _p. \end{aligned}$$
(11)

At this point, we only specify the divergence constraint within the physical domain and defer a more detailed description of the divergence constraint inside \(\varOmega _s\) for Sect. 7. The idea is to choose \({\tilde{\mathbf {g}}}\) to reduce the artificial fluid boundary layer generated by the penalized equations in the vicinity of \(\Gamma \). Specifically, the function \({\tilde{\mathbf {g}}}\) should be a smooth, at least \(C^1\), extension of the prescribed boundary conditions. The extension is constructed for each component of \({\tilde{\mathbf {g}}}\), and each component of \({\tilde{\mathbf {g}}}\) should be chosen to match \(k\) derivatives of \(\mathbf {u}\) in the direction normal to \(\Gamma \). As a result, we prescribe the following general properties for \({\tilde{\mathbf {g}}}\)

  1. P1.

    \({\tilde{\mathbf {g}}}\) is an extension of the prescribed boundary values: \({\tilde{\mathbf {g}}} = \mathbf {g}\) for \(\mathbf {x} \in \Gamma \).

  2. P2.

    \({\tilde{\mathbf {g}}}\) has the same normal slope as \(\mathbf {u}\): \((\mathbf {n}\cdot \nabla ) u_i = (\mathbf {n} \cdot \nabla ) \tilde{g}_i\). Here \(u_i\) and \(\tilde{g}_i\) for \(i = 1\ldots D\) are the components of \(\mathbf {u}\) and \( {\tilde{\mathbf {g}}}\).

  3. P3.

    For higher derivatives, \((\mathbf {n}\cdot \nabla )^k u_i |_{\Gamma _p} = (\mathbf {n}\cdot \nabla )^k \tilde{g}_i\).

Since derivatives of \(\mathbf {u}\) may be discontinuous across \(\Gamma \), the notation \(\Gamma _p\) denotes the limit of the derivative from the physical domain \(\varOmega _p\).

3 Constructing the Extension \({\tilde{\mathbf {g}}}\)

In this section we discuss one possible construction for the extension function \({\tilde{\mathbf {g}}}\). The construction procedure is identical for each component \(g_i\) of \({\tilde{\mathbf {g}}}\) for \(i = 1\ldots D\).

In our approach, we assume the domain \(\varOmega _p\) has a smooth boundary, at least \(\Gamma \in C^2\). As a result, we omit a class of physically important domains such as rectangles. The general idea is to match the normal derivatives of \({\tilde{\mathbf {g}}}\) to those of \(\mathbf {u}\) on \(\Gamma \). With the appropriate boundary derivatives, we then let \({\tilde{\mathbf {g}}}\) decay to some constant value \(\mathbf {G}\) over a length scale \(l\). In our construction, the maximum length scale \(l\) is bounded by the minimum radius of curvature of the interface.

  1. Step 1.

    First introduce a family of smooth, one-dimensional basis functions \(B_j \in C^{k}\) with \(0 \le j \le k\) such that

    1. (i)

      The functions \(B_j\) form a basis for derivatives at \(x = 0\)

      $$\begin{aligned} \frac{d^i}{dx^i} B_j(0) = {\left\{ \begin{array}{ll} 1 &{} \text {for } j = i \\ 0 &{} \text {for } j \ne i \end{array}\right. } \end{aligned}$$
      (12)
    2. (ii)

      Each \(B_j(x)\) has support on \([0, 1]\). Namely \(B_j(x) = 0\) for \(x < 0\) and \(x > 1\).

    One can then use the functions \(B_j(x)\) to construct a \(C^k\) extension \(\tilde{f}(x)\) of a one-dimensional function \(f(x)\) on \(x \ge 0\) as

    $$\begin{aligned} \tilde{f}(x) = f(0) B_0(x) + f'(0) B_1(x) + \cdots + f^{(k)}(0) B_k(x). \end{aligned}$$
    (13)

    Note that by construction, the function \(\tilde{f}(x)\) matches k derivatives at \(x = 0\) and vanishes for \(x > 1\). The goal is now to modify the extension (13) to higher dimensions. Although there are many different choices for \(B_j(x)\), we now give an example of one such choice for matching \(k = 2\) derivatives. We do this by constructing \(B_j(x)\) out of stretched copies of the smoothly decaying function

    $$\begin{aligned} h(x) = {\left\{ \begin{array}{ll} e^{1 - \frac{1}{1-x}} &{} \text {for } 0 \le x < 1 \\ 0 &{} \text {for } x \ge 1 \end{array}\right. }. \end{aligned}$$
    (14)

    Using \(h(x)\), one can take the functions \(B_0, B_1, B_2\) (Fig. 2) as the weighted sums

    $$\begin{aligned} B_0(x)&= 3 \; h(x) - 3 \;h(2x) + h(3x) \end{aligned}$$
    (15)
    $$\begin{aligned} B_1(x)&= \frac{5}{2}\; h(x) - 4\; h(2x) + \frac{3}{2}\; h(3x) \end{aligned}$$
    (16)
    $$\begin{aligned} B_2(x)&= -\frac{1}{2}\; h(x) + h(2x) - \frac{1}{2}\; h(3x). \end{aligned}$$
    (17)
Fig. 2
figure 2

A plot of the \(1D\) basis functions \(B_0(x)\) (thick), \(B_1(x)\) (dashed) and \(B_2(x)\) (thin)

  1. Step 2.

    Construct a coordinate system inside the obstacle. The coordinate system should be orthogonal at the boundary, and only needs to extend a distance \(l\) inside the domain \(\varOmega _s\). To construct the coordinates, we follow a standard approach [12] shown in Fig. 3. Let \(\varvec{\xi }\in \Gamma \) denote the coordinates of the boundary \(\Gamma \). Any point \(\mathbf {x}\) within a distance \(l\) of the boundary may then be written as

    $$\begin{aligned} \mathbf {x} = \varvec{\xi }+ s \, \mathbf {n}(\varvec{\xi }). \end{aligned}$$
    (18)

    Here \(s\) is the normal distance inside \(\varOmega _s\) from the boundary. Within a small enough region, \(s \le l\), one may invertFootnote 2 equation (18) to write \(\varvec{\xi }= \varvec{\xi }(\mathbf {x})\) and \(s = s(\mathbf {x})\).

Fig. 3
figure 3

A local set of normal coordinates. Here \(\varvec{\xi }\in \Gamma \) is a point on the boundary, while \(s\) is the distance in the normal direction. A coordinate inside a neighborhood of \(\varOmega _s\) has the form \(\mathbf {x} = \varvec{\xi }+ s\, \mathbf {n}(\varvec{\xi })\)

Remark 1

In cases where a level set function \(\phi (\mathbf {x})\) describes the boundary \(\Gamma = \{ \mathbf {x} \in \varOmega \, | \, \phi (\mathbf {x}) = 0\}\), one may identify

$$\begin{aligned} \mathbf {n}&= \nabla \phi \end{aligned}$$
(19)
$$\begin{aligned} s&= \phi (\mathbf {x}). \end{aligned}$$
(20)

Here we have assumed \(|\nabla \phi | = 1\) and \(\phi (\mathbf {x}) > 0\) represents the domain \(\varOmega _s\) while \(\phi (\mathbf {x}) < 0\) corresponds to the domain \(\varOmega _p\).  \(\spadesuit \)

  1. Step 3.

    Construct the extension \({\tilde{\mathbf {g}}}\) using the functions \(B_j(x)\) and the coordinates \((\varvec{\xi }, s)\). For brevity, we introduce notation for the normal derivatives at the boundary \(\Gamma \).

    $$\begin{aligned} \mathbf {u}_n(\varvec{\xi })&= (\mathbf {n}\cdot \nabla ) \mathbf {u}|_{\Gamma } \end{aligned}$$
    (21)
    $$\begin{aligned} \mathbf {u}_{nn}(\varvec{\xi })&= (\mathbf {n}\cdot \nabla )^2 \mathbf {u} |_{\Gamma } \end{aligned}$$
    (22)
    $$\begin{aligned}&\vdots&\nonumber \\ \mathbf {u}_{n_k}(\varvec{\xi })&= (\mathbf {n} \cdot \nabla )^k \mathbf {u} |_{\Gamma } \end{aligned}$$
    (23)

    Again, we note that higher derivatives of \(\mathbf {u}\) are discontinuous across the boundary. Therefore, \(\mathbf {u}_{n_k}\) is evaluated as the limit approaching the boundary from the physical domain. The extension is then

    $$\begin{aligned} {\tilde{\mathbf {g}}}(\mathbf {x})&= \big ( \mathbf {g}(\varvec{\xi }) - \mathbf {G} \big )\,\, B_0\big ( s \, l^{-1} \big ) + l \,\, \mathbf {u}_n(\varvec{\xi }) \,\, B_1\big ( s \, l^{-1} \big ) \nonumber \\&\quad + l^2 \,\, \mathbf {u}_{nn}(\varvec{\xi }) \,\, B_2 \big (s \, l^{-1} \big ) + \cdots \nonumber \\&\quad + l^k \,\, \mathbf {u}_{n_k}(\varvec{\xi }) \,\, B_k \big (s \, l^{-1} \big ) + \mathbf {G}. \end{aligned}$$
    (24)

    Note that \({\tilde{\mathbf {g}}}\) decays to \(\mathbf {G}\), i.e. \({\tilde{\mathbf {g}}} \rightarrow \mathbf {G}\), as \(s \rightarrow l\). Therefore \(\mathbf {G}\) can be any time-dependent constant vector, however, for numerical purposes one should choose \(\mathbf {G}\) close to the boundary average of \(\mathbf {g}\)

    $$\begin{aligned} \mathbf {G}&= A^{-1} \int \limits _{\Gamma } \mathbf {g} \, \mathrm {d}A \end{aligned}$$
    (25)
    $$\begin{aligned} A&= \int \limits _{\Gamma } \, \mathrm {d}A. \end{aligned}$$
    (26)

Remark 2

Since values of \({\tilde{\mathbf {g}}}\) inside \(\varOmega _s\) depend on derivatives of \(\mathbf {u}\) on the boundary, the function \({\tilde{\mathbf {g}}}\) described in (24) depends linearly on \(\mathbf {u}\).  \(\spadesuit \)

Remark 3

We can check that the construction (24) satisfies the properties (P1)–(P3). For \(\mathbf {x} \in \Gamma \), we have \(s = 0\), so that \({\tilde{\mathbf {g}}} = \mathbf {g}\), thereby satisfying (P1). To check higher derivatives, we first note that differentiating (18) with respect to \(s\) yields \(\frac{\partial \mathbf {x}(\varvec{\xi }, s)}{\partial s} = \mathbf {n}(\varvec{\xi })\). As a result any function independent of \(s\), \(y(\varvec{\xi }, s) = y(\varvec{\xi })\), has the property that

$$\begin{aligned} (\mathbf {n}\cdot \nabla ) y(\varvec{\xi })&= \sum _j \frac{\partial x_j}{\partial s} \frac{\partial y(\varvec{\xi })}{ \partial x_j} \end{aligned}$$
(27)
$$\begin{aligned}&= \frac{\partial y(\varvec{\xi })}{\partial s} \end{aligned}$$
(28)
$$\begin{aligned}&= 0. \end{aligned}$$
(29)

Meanwhile, we also have

$$\begin{aligned} (\mathbf {n}\cdot \nabla )^i B_j(s \, l^{-1}) |_{s = 0}&= \Big (\frac{\partial }{\partial s} \Big )^i B_j(s \, l^{-1}) |_{s = 0}\end{aligned}$$
(30)
$$\begin{aligned}&= l^{-i} \delta _{ij} \end{aligned}$$
(31)

where \(\delta _{ij}\) is the Kronecker delta. Combining the two properties above, we have

$$\begin{aligned} (\mathbf {n}\cdot \nabla )^i {\tilde{\mathbf {g}}} |_{\mathbf {x} \in \Gamma }&= \mathbf {u}_{n_i}(\varvec{\xi }). \end{aligned}$$
(32)

Therefore, we recover properties (P2)–(P3).  \(\spadesuit \)

4 A Model Equation

In this section we examine solutions to the steady-state heat equation to provide some explanation for how the extension function \(\tilde{g}\) improves the analytic convergence rate of the penalized equations to the original problem. In particular, we seek to quantify the error that results from the additional penalty forcing. As a non-penalized problem, consider

$$\begin{aligned} \partial _{xx} v&= 0 \quad \,\,\, x \in [-1, 0] \end{aligned}$$
(33)

with boundary conditions: \(v(-1) = 1\), \(v(0) = 0\). The solution is then \(v(x) = -x\) for \(x \in [-1, 0]\).

We note that solving explicit examples of the steady-state equations do not give general sharp convergence estimates, however, they do provide a rigorous lower bound on the convergence rate of the penalized equation to the exact non-penalized equation. The equivalent one dimensional steady-state penalized problem is then

$$\begin{aligned} \partial _{xx} u&= \eta ^{-1}H(x) (u - \tilde{g}) \quad \,\,\, x \in [-1, \infty ) \end{aligned}$$
(34)

with boundary conditions \(u(-1) = 1\), \(u(\infty ) = 0\). Here \(H(x)\) is the Heaviside function

$$\begin{aligned} H(x) = {\left\{ \begin{array}{ll} 0 &{} \text {for } x < 0 \\ 1 &{} \text {for } x \ge 0 \end{array}\right. } \end{aligned}$$
(35)

We now examine the convergence of solutions \(u \rightarrow v\) in the limit \(\eta \rightarrow 0\) for different extensions \(\tilde{g}\).

Remark 4

As a result of the discontinuous Heaviside function \(H(x)\), the solution \(u\) to Eq. (34) has one continuous derivative (\(u \in C^1\)). Higher derivatives are discontinuous across \(x = 0\).  \(\spadesuit \)

In light of remark (4), we take \(\tilde{g}\) to have derivatives matching \(u\) from the physical domain \(x = 0^-\) and not \(x = 0^+\).

Proposition 1

Suppose that \(\tilde{g}\) is a bounded \(C^{k+1}\) function that matches \(k\) derivatives of \(u\) at \(x = 0^-\). Namely

  1. 1.

    \(\tilde{g}(0) = 0\)

  2. 2.

    \(\tilde{g}'(0) = u'(0)\)

  3. 3.

    \(\tilde{g}^{(m)}(0) = u^{(m)}(0^-) = 0\) for \(2 \le m \le k\).

Then the solution \(u\) converges to \(v\) as

$$\begin{aligned} \max _{x \in [-1, 0]} |u - v|&= O(\eta ^{(k+1)/2}) \end{aligned}$$
(36)

Proof

In the region \(-1 \le x \le 0\), \(u\) has the solution

$$\begin{aligned} u = (1 + c) + c x \end{aligned}$$
(37)

for some constant \(c\). To construct the solution on \(x \ge 0\), we note that one may write \(\tilde{g}\) as

$$\begin{aligned} \tilde{g}(x) = c x + x^{k + 1} R(x) \end{aligned}$$
(38)

for some remainder function \(R(x)\), where in general \(R(0) \ne 0\). By construction (38) matches the first \(k\) derivatives of \(u\) at \(x = 0^-\). In addition, we assume that \(\tilde{g}(x)\) and \(\tilde{g}'(x)\) are bounded, so that \(R(x)\) and \(R'(x)\) are also bounded functions. On \(x \ge 0\), \(u\) then solves

$$\begin{aligned} \partial _{xx} u - \eta ^{-1} u = -\eta ^{-1}\big (c x + x^{k + 1} R(x)\big ) \end{aligned}$$
(39)

To obtain the correct scaling, we rescale \(x = \eta ^{1/2}X\) to obtain

$$\begin{aligned} \partial _{XX} u - u = -c \eta ^{1/2} X + \eta ^{(k+1)/2} X^{k + 1} R(\eta ^{1/2} X) \end{aligned}$$
(40)

The general solution is then

$$\begin{aligned} u(X) = {\left\{ \begin{array}{ll} (1 + c) + c \eta ^{1/2} X &{} \text {if } X < 0 \\ b e^{-X} + c \eta ^{1/2} X + \eta ^{(k+1)/2} Q(X) &{} \text {if } X \ge 0 \end{array}\right. } \end{aligned}$$
(41)

where we have excluded the term \(e^{X}\) since it diverges as \(X \rightarrow \infty \). In addition, \(Q(X)\) is a particular solution (which stays bounded as \(X \rightarrow \infty \) ) to

$$\begin{aligned} Q_{XX} - Q = X^{k + 1} R(\eta ^{1/2} X) \end{aligned}$$
(42)

For instance, one may write a particular solution as

$$\begin{aligned} Q(X)&= \frac{1}{2}\int \limits _{0}^{X} (e^{X - y} - e^{-X + y}) y^{k+1}R(\eta ^{1/2} y) \, \mathrm {d}y - A e^{X} \end{aligned}$$
(43)
$$\begin{aligned} A&= \frac{1}{2} \int \limits _0^{\infty } e^{-y} y^{k+1} R(\eta ^{1/2} y) \, \mathrm {d}y \end{aligned}$$
(44)

Letting \(R_m = \max _{y} |R(y)|\), we also have the bound

$$\begin{aligned} |Q(0)| = |A|&\le \frac{R_m}{2} \int \limits _0^{\infty } y^{k+1}e^{-y} \, \mathrm {d}y = Q_0. \end{aligned}$$
(45)

The same type of argument holds for bounding \(|Q'(0)| \le Q_1\).

To solve for the unknown constants, \(c\) and \(b\), we use the fact that \(u\) and \(u'\) are continuous across \(x = 0\). We therefore obtain the two equations

$$\begin{aligned} 1 + c&= b + \eta ^{(k+1)/2} Q(0) \end{aligned}$$
(46)
$$\begin{aligned} \eta ^{1/2} c&= -b + \eta ^{1/2}c + \eta ^{(k+1)/2} Q'(0) \end{aligned}$$
(47)

Upon solving for \(b\) and \(c\), the error between \(u\) and \(v\) on the physical domain \(-1 \le x \le 0\) is

$$\begin{aligned} \max _{x \in [-1, 0]} |u - v|&= 1 + c\end{aligned}$$
(48)
$$\begin{aligned}&= (Q(0) + Q'(0) ) \eta ^{(k+1)/2} \end{aligned}$$
(49)
$$\begin{aligned}&\le (Q_0 + Q_1) \eta ^{(k+1)/2} \end{aligned}$$
(50)
$$\begin{aligned}&= O(\eta ^{(k+1)/2}) \end{aligned}$$
(51)

Hence, for the model problem, matching \(k\) derivatives of \(\tilde{g}\) yields a convergence rate of \((k+1)/2\). In particular, when \(k = 0\), we recover the known convergence rate \(\eta ^{1/2}\) of the standard penalty method. \(\square \)

Remark 5

Using higher derivatives in the construction of \(\tilde{g}\) which are taken as limits from the domain \(x \searrow 0^+\), does not yield the convergence rate stated in proposition (1). As an example, we take \(\tilde{g}^+ = u'(0) B_1(x) + u''(0^+) B_2(x)\) where

$$\begin{aligned} B_1(x)&= \frac{5}{2}e^{-x} - 4 e^{-2x} + \frac{3}{2}e^{-3x} \end{aligned}$$
(52)
$$\begin{aligned} B_2(x)&= \frac{1}{2}e^{-x} - e^{-2x} + \frac{1}{2}e^{-3x}. \end{aligned}$$
(53)

For such a \(\tilde{g}^+\), the solution \(u\) to problem (34) yields only a first order error

$$\begin{aligned} \max _{[-1,0]}|u - v| \sim \frac{11}{6}\eta . \end{aligned}$$
(54)

In contrast, taking \(\tilde{g}^- = u'(0) B_1(x) + u''(0^-) B_2(x)\) yields a convergence rate in agreement with (1)

$$\begin{aligned} \max _{[-1,0]}|u - v| \sim 11 \eta ^{3/2}. \end{aligned}$$
(55)

 \(\spadesuit \)

5 Stability

In this section we establish numerical stability criteria for the \(1D\) penalized heat equation. To examine stability, we work with the domain \(\varOmega _p = (0, \pi )\), \(\varOmega _s = [\pi , 2\pi ]\) and periodic boundary conditions. Moreover, we take \(g(0) = g(\pi ) = 0\) to capture a \(u = 0\) boundary condition at the fluid-solid boundary. A simple Euler scheme matching one derivative of \(u\) at the interface is then

$$\begin{aligned} u^{n+1}&= \big (I + \Delta t \; \Delta \big ) u^n - \Delta t \; \eta ^{-1} \chi _s \; (u^n - \tilde{g}^n) \end{aligned}$$
(56)
$$\begin{aligned} \tilde{g}^n&= u_x^n(\pi ) B_1(x - \pi ) - u_x^n(2\pi ) B_1(2\pi -x) \end{aligned}$$
(57)

In general, adding derivatives of \(u\) to \(\tilde{g}(x)\) can reduce, by factors of \(h\), the time step restriction for an explicit scheme. In the case at hand, however, the structure of \(\tilde{g}(x)\) results in the same time step restriction as the original volume penalty method, namely

$$\begin{aligned} \Delta t < \min \{ O(h^2), O(\eta ) \}. \end{aligned}$$
(58)

Here \(h\) is either the grid spacing of a finite difference scheme, or alternatively \(h^{-1}\) scales as the largest wavenumber in a Fourier method.

We note that although (56) is a linear recursion relation, the right hand side is not a normal operator. As a result, a rigorous proof of (58) requires bounding the eigenvalues for the spatially discrete system (56). The analysis is further complicated by the fact that the operators (or matrices) on the right hand side of (56) do not commute.

In this section we establish the time step restriction (58). To do so, we first compute the eigenvalues for the penalty term using a finite difference scheme. We show that although the penalty term contains derivatives of \(u\), the eigenvalues remain \(O(\eta ^{-1})\) and do not become \(O(\eta ^{-1} h^{-1})\).

Secondly, to show that the addition of the Laplacian does not alter the restriction (58), we numerically compute the eigenvalues for Eq. (56) using a finite difference scheme.

5.1 Eigenvalues of the Penalty Term (Finite Differences)

In practice, one does not observe the time step restriction governed by the norm of \(\tilde{g}\), but rather the larger bound in (58). Here we provide a stability criteria by analytically computing the penalty term eigenvalues for a finite difference scheme.

Let \(x_k = k h\) for \(0 \le k \le N - 1\) with grid spacing \(h = 2\pi /N\). Furthermore, denote the discrete vector \(\mathbf {u} = [u(x_0) \, u(x_1) \ldots u(x_{N-1})]^T\).

We are then interested in evaluating the eigenvalues of the penalty term

$$\begin{aligned} \mathbf {B} \mathbf {u}&= \lambda \mathbf {u} \end{aligned}$$
(59)
$$\begin{aligned} \mathbf {B}&= - \eta ^{-1}( \mathbf {I}_\chi - \mathbf {v}_1 \mathbf {d}_1^T - \mathbf {v}_2 \mathbf {d}_2^T) \end{aligned}$$
(60)

where \(\mathbf {B}\) is the finite difference matrix corresponding to the penalty term. Here \(\mathbf {I}_\chi \) is the identity matrix restricted to \(x \in \varOmega _s\) while \(\mathbf {v}_1\) and \(\mathbf {v}_2\), are vectors with components

$$\begin{aligned} (\mathbf {v}_1)_k&= \chi _s(x_k) B_1(x_k - \pi ) \end{aligned}$$
(61)
$$\begin{aligned} (\mathbf {v}_2)_k&= -\chi _s(x_k) B_1(2\pi - x_k) \end{aligned}$$
(62)

In addition, \(\mathbf {d}_1\) and \(\mathbf {d}_2\) are column vectors which approximate the derivatives of a vector \(\mathbf {u}\) as

$$\begin{aligned} u_x(\pi ) \approx \mathbf {d}_1^T \mathbf {u} \end{aligned}$$
(63)
$$\begin{aligned} u_x(2\pi ) \approx \mathbf {d}_2^T \mathbf {u} \end{aligned}$$
(64)

For instance, a centered difference approximation to the derivative \(u_x(2\pi )\) would have \((\mathbf {d}_2)_{N-1} = -(2h)^{-1}\), \((\mathbf {d}_2)_1 = (2h)^{-1}\) and \((\mathbf {d}_2)_k = 0\) for \(k = 0\) and \(1 < k < N-1\). Lastly, since the support of \(B_1(x)\) is restricted to \(x < 1\), the function \(B_1(x - \pi ) = 0\) for \(x > \pi + 1\). Hence, the numerical derivative of \(B_1(x - \pi )\) at \(x = 2\pi \) is zero (or similarly with \(B_1(2\pi - x)\) at \(x = 0\))

$$\begin{aligned} \mathbf {d}_2^T \mathbf {v}_1&= 0 \end{aligned}$$
(65)
$$\begin{aligned} \mathbf {d}_1^T \mathbf {v}_2&= 0. \end{aligned}$$
(66)

Combining the orthogonality conditions (65)–(66) with the fact that \(\mathbf {I}_\chi \mathbf {v}_{1, 2} = \mathbf {v}_{1, 2}\), implies that \(\mathbf {u} = \mathbf {v}_{1, 2}\) are eigenvectors with corresponding eigenvalues

$$\begin{aligned} \lambda _{1}&= -\eta ^{-1} (1 - \mathbf {d}_{1}^T \mathbf {v}_1) \end{aligned}$$
(67)
$$\begin{aligned} \lambda _{2}&= -\eta ^{-1} (1 - \mathbf {d}_{2}^T \mathbf {v}_2). \end{aligned}$$
(68)

All other eigenvalues of \(\mathbf {B}\) then lie in the space perpendicular to \(\mathbf {v}_1\) and \(\mathbf {v}_2\) resulting in either \(\lambda = 0\) or \(\lambda = -\eta ^{-1}\). The eigenvalues (67)–(68) are therefore directly a result of the modified penalty term and depend specifically on the component values of \(\mathbf {d}_{1,2}\). As a result, the products \(\mathbf {d}_{1 ,2}^T \mathbf {v}_{1, 2} \in (0, 1]\) depending on how one builds the numerical derivative vector \(\mathbf {d}_{1, 2}\).

As an example, taking a centered difference approximation to the derivative \(u_x(2\pi )\) yields

$$\begin{aligned} \mathbf {b}_2^T \mathbf {v}_2&= \frac{1}{2h}( (\mathbf {v}_2)_1 - (\mathbf {v}_2)_{N-1} ) \end{aligned}$$
(69)
$$\begin{aligned}&\approx 0.5. \end{aligned}$$
(70)

The second line follows since \((\mathbf {v}_2)_{N-1} = 0\) while \((\mathbf {v}_2)_1 \approx h\) because the function \(B_1'(0) = 1\).

In general, the product \(\mathbf {d}_{1 ,2}^T \mathbf {v}_{1, 2}\) will be a weighted average of the derivatives of \(B_1(x)\) on the left and right of the interface. As a result, all eigenvalues \(\lambda \) of \(\mathbf {B}\) satisfy \(-\eta ^{-1} \le \lambda \le 0\). Therefore, modifying the penalty term does not change the time step restriction \(\Delta t < 2 \eta \) for a simple Euler scheme \(\mathbf {u}^{n+1} = \mathbf {u}^n + \Delta t \; \mathbf {B}\mathbf {u}^n\).

5.2 Numerical Eigenvalues

In the follow section we numerically compute the eigenvalues of (56)–(57) using a finite difference scheme for the spatial derivatives.Footnote 3 The scheme then has the form

$$\begin{aligned} \mathbf {u}^{n+1}&= \big [ \mathbf {I} + \Delta t \; (\mathbf {L} + \mathbf {B}) \big ] \mathbf {u}^n \end{aligned}$$
(71)

where \(\mathbf {L}\) is the standard 3-point stencil discrete Laplacian. As a result, the eigenvalues of the linear system (71) approach the real values associated with the Laplacian \(\Delta \) when \(\eta \rightarrow \infty \), and the values associated with the penalty term when \(\eta \rightarrow 0\).

To compute the eigenvalues numerically, we fix a grid with \(N\) points (\(256 \le N \le 4096\)) and examine the range \(10^{-9} \le \eta \le 1\).

Proposition 2

(Practical stability) In practice, the numerical scheme (71) is stable provided one takes the time step restriction

$$\begin{aligned} \Delta t < \min \{ 0.5 h^2, 1.2 \eta \}. \end{aligned}$$
(72)

Remark 6

The exact constant \(1.2\) in (72) depends on numerical details such as how one interpolates derivatives to the interface or the nature of the functions \(B_0(x), B_1(x) \ldots \).  \(\spadesuit \)

Here Fig. 4 shows that the numerical eigenvalues for \(N = 2048\) and \(\eta = 10^{-7}\) are stable with a time step restriction (72).

Fig. 4
figure 4

Scatter plot of the numerical eigenvalues for (71). Here \(N = 2048\), \(\eta = 10^{-7}\) and \(\Delta t\) is taken from (72)

6 Numerical Example: Heat Equation

In the following section we provide numerical examples for the heat equation in dimension \(D = 1, 2\). Specifically, we combine the analytic convergence and stability results from the previous sections to show that one may achieve high order numerical schemes. As a starting point, we demonstrate high order convergence in \(D = 1\) dimension. We then move to \(D = 2\), and outline additional details that arise from the numerical construction of the extension \(\tilde{g}(\mathbf {x})\).

6.1 1D Heat Equation

To test the convergence rates for the penalized heat equation, we use a manufactured solution approach. We note that the forced heat equation on \(x \in [0, 2\pi ]\),

$$\begin{aligned} \partial _t u&= u_{xx} + f \end{aligned}$$
(73)
$$\begin{aligned} f&= e^{\sin (x+t)}\big [ \cos (x+t) + \sin (x+t) - \cos ^2(x+t)\big ] \end{aligned}$$
(74)
$$\begin{aligned} u(x, 0)&= e^{\sin (x)} \end{aligned}$$
(75)

has an exact solution \(u_e = e^{\sin (x+t)}\). To quantify the total error, we penalize equation (73) as

$$\begin{aligned} \partial _t u_{\eta }&= (u_{\eta })_{xx} + f - \eta ^{-1}\chi _s \; (u_{\eta } - \tilde{g}) \end{aligned}$$
(76)

and compare the numerical solution of (76) to the exact one from (73).Footnote 4

To discretize in space, we use an equispaced grid with fourth order stencils for all derivatives. In addition, we treat all terms explicitly in time with a second order (improved) Euler scheme. When constructing the extension \(\tilde{g}\), we first compute the derivatives of \(u\) at each grid point, i.e. \(u_x(x_k)\) or \(u_{xx}(x_k)\). We then interpolate the values of \(u_x\) and \(u_{xx}\) from the regular grid points to the points \(x_{\Gamma }\) on the interface.

Remark 7

The solution to the penalized heat equation \(u\) has a discontinuous second derivative \(u_{xx}\) across the interface. As a result, interpolating \(u_{xx}\) using regular grid points on both sides of the interface will produce a weighted average of right and left derivatives \(u_{xx}(0^-)\) and \(u_{xx}(0^+)\) in the construction of \(\tilde{g}\). We note that in practice, such a procedure does not appear to alter the final numerical convergence rate.  \(\spadesuit \)

For our tests, we choose a solid region centered at \(\pi \) to be \(\varOmega _s = [\pi - 0.7, \pi + 0.7]\). To satisfy the stability restriction, we then take \(\Delta t = 0.2 \; h^2\), \(h = 2\pi /N\) and slave \(\eta = 5 \; \Delta t\) so that all parameter values are fixed by the number of grid points \(N\). For each \(N = 2^k\), with \(6 \le k \le 12\), we then numerically integrate (76) up to a final time of \(T = 1\). We repeat the procedure using \(0, 1\) and \(2\) derivatives of \(u\) in constructing the extension \(\tilde{g}\) and compare the numerical solution to the exact one (i.e. that of the unpenalized problem). Here Fig. 5 shows the convergence rates for matching different derivatives, while Figs. 6 and 7 show a typical solution and the corresponding error, respectively.

Fig. 5
figure 5

Plot of numerical errors \(||u - u_{\eta , num}||_{\infty }\) for different values of \(N\). The three curves correspond to building \(\tilde{g}\) using 0, 1, 2 derivatives of \(u\) and result with convergence rates of 1, 2, 3, respectively

Fig. 6
figure 6

Plot of the numerical solution \(u_{\eta , num}\) (thin line) with the extension \(\tilde{g}\) (dashed line) for \(N = 2048\). Here \(\varOmega _s = [\pi - 0.7, \pi + 0.7]\) is the solid domain

Fig. 7
figure 7

Plot of the total error in solving the penalized equations matching \(1\) derivative of \(u\) in the extension. Here, \(N = 2048\), \(T = 1\) is the integration time, while \(\varOmega _s = [\pi - 0.7, \pi + 0.7]\) is the solid domain

6.2 2D Heat Equation

In the following subsection, we outline the numerical details for a \(D = 2\) scheme. Here we work with an equispaced, regular grid with \(N \times N\) points (\(64 \le N \le 512\)), and immerse the boundary \(\Gamma \). The main difference when moving to higher dimensions is how one computes the extension \(\tilde{g}(\mathbf {x})\). To illustrate the construction, we refer to Fig. 8. To build \(\tilde{g}(\mathbf {x})\) we first compute all appropriate derivatives at each grid point (both on \(\varOmega _s\) and \(\varOmega _p\)). For each grid point \(\mathbf {x} \in \varOmega _s\) within a distance \(l\) of \(\Gamma \), we compute \(\varvec{\xi }(\mathbf {x})\) as the orthogonal projection of \(\mathbf {x}\) onto \(\Gamma \) and \(s(\mathbf {x}) = ||\varvec{\xi }(\mathbf {x}) - \mathbf {x}||_2\). Using a regular 9 point stencil, we then perform a polynomial interpolation of all required derivatives from the grid points to \(\varvec{\xi }\). Using the interpolated derivatives at \(\varvec{\xi }\), one can then compute the normal derivatives of \(\mathbf {u}\) required in Eq. (24) to construct \(\tilde{g}(\mathbf {x})\) at each grid-point inside \(\varOmega _s\). Figure 9 illustrates a typical construction of \(\tilde{g}(\mathbf {x})\).

Fig. 8
figure 8

Regular grid with interpolation points

Fig. 9
figure 9

A sample 2D plot of \(\tilde{g}\) matching \(2\) normal derivatives of \(u(\mathbf {x})\). The plot is taken at \(t = 0\) for the heat equation tests

Remark 8

For computational efficiency, one can precompute and store the values of \(\varvec{\xi }\) as well as the appropriate coefficients required to extrapolate derivatives to the interface \(\Gamma \).  \(\spadesuit \)

As an example in \(D = 2\), we take the computational domain \(\varOmega \) to be a periodic square with side length \(2\pi \). For the penalized domain \(\varOmega _s\), we take a circle of radius \(r = 1/2\) and center \((x_c, y_c) = (\pi , \pi )\). The physical domain is then \(\varOmega _p = \varOmega \setminus \varOmega _s\). To perform convergence tests, we again use a manufactured solution where \(u_e = [e^{\sin (x)} + cos(y) ] \cos (t)\). Here we perform a convergence test for the penalty parameter \(\eta \). To compute the convergence rate, we fix \(N = 512\) and vary \(5\times 10^{-5} \le \eta \le 10^{-1}\), so that discrete numerical errors are smaller than the \(\eta \)-dependent error obtained by introducing the penalty term. For different values of \(\eta \), we then integrate the penalty equation for a time \(T = 0.1\) and compute the error. Figure 10 shows the \(L^{\infty }\) error between the penalized equation and the exact heat equation as a function of \(\eta \).

Fig. 10
figure 10

Converence plot of the \(L^{\infty }\) error at \(T = 0.1\) for the heat equation tests. The plot shows curves for matching 0 derivatives (triangles), \(1\) derivative (squares), and 2 derivatives (circles). The straight lines compare the expected convergence rates of \(O(\eta ^{0.5})\), \(O(\eta )\) and \(O(\eta ^{1.5})\), respectively

7 Numerical Example: 2D Incompressible Navier–Stokes

The primary difficulty when transitioning from a penalized heat equation to the penalized incompressible Navier–Stokes equations is the addition of the velocity divergence constraint. Other differences, such as moving from a scalar to a vector equation, or adding a nonlinear convective term do not pose new additional challenges to the penalized equations. Intuitively, the difficulty with the divergence can be outlined as follows. For the penalized heat equation, the active penalty term forces the function \(u\) to closely track the extension function \(\tilde{g}\). When moving to a set of vector equations, the velocity vector \(\mathbf {u}_{\eta }\) will closely track the term \({\tilde{\mathbf {g}}}\) inside the penalty region \(\varOmega _s\). However, the component-wise construction of \({\tilde{\mathbf {g}}}\) will in general be such that \(\nabla \cdot {\tilde{\mathbf {g}}} \ne 0\). Consequently, to remain consistent, one should not force \(\nabla \cdot \mathbf {u}_{\eta } = 0\) inside \(\varOmega _s\) but rather allow \(\nabla \cdot \mathbf {u}_{\eta }\) to loosely track \(\nabla \cdot {\tilde{\mathbf {g}}}\).

One approach for handling the divergence constraint is to replace \(\nabla \cdot \mathbf {u}_{\eta } = 0\) with a Pressure Poisson equation (PPE) [15, 16, 28, 29]. Such an approach can provide a consistent method to compute the pressure and obtain high order schemes. Since a PPE approach requires the additional solution of a Poisson equation with Neumann boundary conditions, we defer the implementation to future work. In our case, we utilize a projection method where we project the velocity divergence to zero inside the fluid domain. We now discretize equations (10)–(11) in time.

7.1 Discretization in Time

Here we outline a pseudo-spectral scheme for solving the Navier–Stokes equations. For a second order scheme in \(h\), we take a first order discretization in time with a time step restriction of the form outlined in (72). Since the domain is \(2\pi \) periodic, we can use the Fourier transform to invert the Poisson equation. In the following algorithm we take a regular \(N\times N\) grid. We also denote the discrete Fourier transform by \(\mathcal {F}\) so that \(\hat{p}^{n}(\mathbf {k}) = \mathcal {F}[p^n]\) with \(\mathbf {k} = (k_x, k_y)\) and \(k = |\mathbf {k}|\).

Algorithm 1

(Navier–Stokes)

  1. 1.

    Given the velocity \(\mathbf {u}_{\eta }^n\), compute an intermediate velocity \({\tilde{\mathbf {u}}}_{\eta }^{n+1}\)

    $$\begin{aligned} \frac{{\tilde{\mathbf {u}}}_{\eta }^{n+1} - \mathbf {u}_{\eta }^n}{\Delta t}&= \mathbf {F}^{n} - \frac{1}{\eta } \chi _s(\mathbf {x})(\mathbf {u}_{ \eta }^n - {\tilde{\mathbf {g}}}^n) \end{aligned}$$
    (77)
    $$\begin{aligned} \mathbf {F}^n&= -\mathbf {u}_{\eta }^n\cdot \nabla \mathbf {u}_{\eta }^n + \mu \Delta \mathbf {u}_{\eta }^n + \mathbf {f}^n \end{aligned}$$
    (78)
  2. 2.

    Compute the pressure

    $$\begin{aligned} \Delta p_{\eta }^{n+1}&= \frac{1}{\Delta t} ( \nabla \cdot {\tilde{\mathbf {u}}}_{\eta }^{n+1}) (1 - \chi _s) - \mathcal {A}. \end{aligned}$$
    (79)

    For \(k = 0\) set \(\hat{p}_{\eta }^{n+1}(0) = 0\), while for \(k \ne 0\) take

    $$\begin{aligned} \hat{p}_{\eta }^{n}(\mathbf {k})&= -\frac{1}{k^2} \mathcal {F}[ \frac{1}{\Delta t} ( \nabla \cdot {\tilde{\mathbf {u}}}_{\eta }^{n+1}) (1 - \chi _s)]. \end{aligned}$$
    (80)

    Note that \(\mathcal {A}\) does not appear in the Fourier transform and at no time does one ever compute \(\mathcal {A}\). The value of \(\mathcal {A}\) is hidden as a consistency condition in setting \(\hat{p}_{ \eta }^{n+1}(0) = 0\).

  3. 3.

    Update the velocity \(\mathbf {u}_{\eta }^{n+1}\)

    $$\begin{aligned} \mathbf {u}_{\eta }^{n+1}&= {\tilde{\mathbf {u}}}_{\eta }^{n+1} - (\Delta t)\mathcal {F}^{-1} [-\imath \mathbf {k} \hat{p}_{\eta }^{n}]. \end{aligned}$$
    (81)

Note that either Fourier transforms or a second order finite difference scheme can be used when computing the derivatives \(\partial _{x_j} \mathbf {u}_{\eta }\) in algorithm (1).

Since the second derivatives are discontinuous, we compute \(\Delta \mathbf {u}_{\eta }\) using finite differences.

In the Poisson equation for the pressure, \(p_{\eta }\) is only determined up to a constant. To uniquely determine \(p_{\eta }\) we enforce \(\int _{\varOmega } p_{\eta } \, \mathrm {d}V = 0\). Meanwhile the value of \(\mathcal {A}\) is chosen so that the Poisson equation satisfies the standard solvability condition. Namely,

$$\begin{aligned} \mathcal {A}&= \frac{\Delta t^{-1}}{V} \int \limits _{\varOmega _p} \nabla \cdot {\tilde{\mathbf {u}}}_{\eta } \, \mathrm {d}V \end{aligned}$$
(82)
$$\begin{aligned}&= \frac{\Delta t^{-1}}{V} \int \limits _{\Gamma } {\tilde{\mathbf {u}}}_{ \eta }\cdot \mathbf {n} \, \mathrm {d}A \end{aligned}$$
(83)
$$\begin{aligned}&= \frac{\Delta t^{-1}}{V} \int \limits _{\Gamma } ({\tilde{\mathbf {u}}}_{ \eta } - \mathbf {g})\cdot \mathbf {n} \, \mathrm {d}A \end{aligned}$$
(84)

where in the last line we have used the fact that \(\int _{\Gamma } \mathbf {g}\cdot \mathbf {n} = 0\). Here \(V = \int _{\varOmega _p} \, \mathrm {d}V\) is the volume of the physical domain. The last line also shows that \(\mathcal {A}\) is not nearly as large as \(\Delta t^{-1}\) since the jump \((\mathbf {u}_{\eta }-\mathbf {g})\cdot \mathbf {n}\) is expected to be small. Finally, we make a remark on the projection of \(\mathbf {u}\). Inside \(\varOmega _p\), we have

$$\begin{aligned} \nabla \cdot \mathbf {u}&= \nabla \cdot {\tilde{\mathbf {u}}} - (\Delta t) \Delta p \end{aligned}$$
(85)
$$\begin{aligned}&= (\Delta t) \mathcal {A} \end{aligned}$$
(86)
$$\begin{aligned}&\le C \max _{\mathbf {x} \in \Gamma } |{\tilde{\mathbf {u}}}_{\eta } - \mathbf {g}| \end{aligned}$$
(87)

where \(C\) is an appropriate constant. Hence any error in the divergence of \(\mathbf {u}\) is directly controlled by the error in the velocity boundary condition. In particular, for matching \(1\) derivative, we expect \(\nabla \cdot \mathbf {u} = O(\eta ) + O(\Delta t)\) inside \(\varOmega _f\). As a result, we can recover a second order scheme, however systematically moving to a higher order method will require an alternative formulation, such as a PPE scheme, for computing the pressure.

Remark 9

In order to guarantee second order spatial accuracy in algorithm (1), \({\tilde{\mathbf {g}}}\) should match at least 1 derivative of \(\mathbf {u}_{\eta }\).  \(\spadesuit \)

Remark 10

One could also consider solving the Poisson equation (79) with \(\mathcal {A} = 0\) and instead impose an interface condition on the normal pressure gradient:

$$\begin{aligned}&[\mathbf {n}\cdot \nabla p_{\eta } ]_{\Gamma } = \frac{1}{\Delta t}\mathbf {n}\cdot ({\tilde{\mathbf {u}}}_{\eta } - \mathbf {g})\end{aligned}$$
(88)
$$\begin{aligned}&[f ]_{\Gamma }:= \lim _{\epsilon \rightarrow 0} \big ( f(\mathbf {x} + \epsilon \mathbf {n}) - f(\mathbf {x} - \epsilon \mathbf {n}) \big )\quad \,\,\, \mathbf {x} \in \Gamma . \end{aligned}$$
(89)

In the definition (89), \(\mathbf {n}\) is taken as the unit normal directed outward from \(\varOmega _p\). Such an approach greatly simplifies the analysis for the behavior of the divergence \((\nabla \cdot \mathbf {u}_{\eta })\) in the resulting PPE scheme. However, we note that numerically solving (79) with (88) and \(\mathcal {A} = 0\) is harder than simply solving (79)–(82). Furthermore, the equations also allow for a direct solution using pseudo-spectral methods, while the interface problem does not.  \(\spadesuit \)

To test the order of accuracy of the active penalty method, we again use a manufactured solution of the form \(\mathbf {u}_e = (u_e, v_e)\) and \(p_e\) where

$$\begin{aligned} u_e&= \cos (x)\sin (y)\cos (t) \end{aligned}$$
(90)
$$\begin{aligned} v_e&= -\sin (x)\cos (y)\cos (t) \end{aligned}$$
(91)
$$\begin{aligned} p_e&= \sin (2x) \cos (y) \cos (t). \end{aligned}$$
(92)

Given initial data corresponding to the exact solution, we numerically evolve the velocity \(\mathbf {u}_{\eta }\) and pressure \(p_{\eta }\) using the pseudo-spectral method outlined in algorithm 1. Here we match 1 derivative of \(\mathbf {u}_{\eta }\) in the construction of \({\tilde{\mathbf {g}}}\) and take time steps, with the appropriate restriction, of \(\Delta t = O(h^2) = O(\eta )\). Figure 11 shows second order convergence of the velocity field (in \(L^{\infty }(\varOmega _p)\)), as well as the pressure and divergence (in \(L^2(\varOmega _p)\)). Meanwhile, the pressure and the divergence converge at one order less in \(L^{\infty }(\varOmega _p)\) (Fig. 12). As an example, Fig. 13a, b show the typical error for velocity and pressure while Fig. 14a, b show the velocity divergence. In addition, Fig. 15a, b show the horizontal velocity field along with the horizontal component of the extension \({\tilde{\mathbf {g}}}\cdot {\hat{\mathbf {x}}}\). Note that \(\mathbf {u}_{\eta }\) is again very close to \({\tilde{\mathbf {g}}}\) inside \(\varOmega _s\).

Fig. 11
figure 11

Navier–Stokes convergence plot. Second order convergence in \(L^{\infty }(\varOmega _p)\) for the velocity field (squares), and in \(L^2(\varOmega _p)\) for the pressure (triangles) and velocity divergence (circles)

Fig. 12
figure 12

Navier–Stokes convergence plot. First order convergence in \(L^{\infty }(\varOmega _p)\) for the pressure (triangles) and velocity divergence (circles). The weaker convergence in \(L^{\infty }(\varOmega _p)\) is due to the boundary layer in the pressure and divergence. The divergence was computed using second order finite differences

Fig. 13
figure 13

Error fields with \(N = 128\) for the velocity and pressure after \(T = 1\). a Velocity error. b Pressure error

Fig. 14
figure 14

Plots of the divergence \(\nabla \cdot \mathbf {u}_{\eta }\) in \(\varOmega \) (left) and in \(\varOmega _p\) (right) with \(N = 128\) after \(T = 1\). The plot in \(\varOmega _p\) shows the \(||\nabla \cdot \mathbf {u}_{\eta }||_{L^{\infty }(\varOmega _p)}\) error occurs at a point in a boundary layer near \(\Gamma \). a Full divergence. b Divergence error

Fig. 15
figure 15

The numerical velocity field for horizontal component \(u_{\eta , Num}\) along with the extension function. Here \(N = 128\) and \(T = 1\). a Velocity \(u_{\eta ,Num}\). b The extension \(\tilde{g}\cdot {\widehat{x}}\)

8 Flow Around an Impulsively Started Cylinder

In this section we test our method for the model problem of an impulsively started cylinder [20]. In this case, we solve the following initial value problem where the fluid starts at rest

$$\begin{aligned} \mathbf {u}_{\eta }(\mathbf {x}, 0) = 0 \quad \,\,\, \mathrm for \, \mathbf {x} \in \varOmega . \end{aligned}$$
(93)

The impulsively started cylinder is then modeled by a moving mask function with a time dependent set \(\varOmega _s(t)\) and the appropriate Dirichlet boundary condition. For \(t > 0\) we have

$$\begin{aligned} \varOmega _s(t) = \{ \mathbf {x}: |\mathbf {x} - \mathbf {x}_0 - \mathbf {u}_0 t| \le R \} \end{aligned}$$
(94)
$$\begin{aligned} \mathbf {u} = \mathbf {u}_0 \quad \,\,\, \mathrm for \, \mathbf {x} \in \Gamma . \end{aligned}$$
(95)

Here \(\mathbf {u}_0 = u_0 {\hat{\mathbf {e}}}_x\) is the velocity of the cylinder, and \((\mathbf {x}_0, R)\) denotes the center and radius of the cylinder.

To simplify the numerical calculation, we perform a Galilean transformation on the coordinates and solve the penalized equations with a stationary mask. The velocity field then solves the equation

$$\begin{aligned} \partial _t \mathbf {u}_{\eta } + (\mathbf {u}_{\eta } - \mathbf {u}_0)\cdot \nabla \mathbf {u}_{\eta }&= -\nabla p_{\eta } + \mu \Delta \mathbf {u}_{\eta } + \mathbf {f} - \eta ^{-1}\chi _s \; (\mathbf {u}_{\eta } - \mathbf {u}_0 - \tilde{\mathbf {g}}), \end{aligned}$$
(96)

with initial data \(\mathbf {u}(\mathbf {x}, 0) = 0\). Here \(\chi _s(\mathbf {x})\) is a stationary mask with \(\varOmega _s(0)\), while \({\tilde{\mathbf {g}}}\) is the active penalty term with a zero boundary condition \(\mathbf {g} = 0\).

To compare our results with pre-existing numerical tests, we adopt the following definition of the Reynolds number and time scales from [20]

$$\begin{aligned} \mathrm RE&= \frac{2 R u_0}{\mu } \end{aligned}$$
(97)
$$\begin{aligned} T&= \frac{u_0}{R} t. \end{aligned}$$
(98)

Using Eq. (96), we then solve for the velocity field in time, and compute the drag force and lift for the impulsively started cylinder. To compute the force we numerically evaluate the momentum transfer to the fluid

$$\begin{aligned} \mathbf {F}_b&= -\frac{d}{dt} \int \limits _{\varOmega _f} \mathbf {u} \, \mathrm {d}V \end{aligned}$$
(99)
$$\begin{aligned}&= -\frac{d}{dt} \int \limits _{\varOmega } \mathbf {u} \big (1 - \chi _s(\mathbf {x})\big ) \, \mathrm {d}V. \end{aligned}$$
(100)

The lift (\(C_L\)) and drag (\(C_D\)) coefficients are then evaluated as the non-dimensionalized components of the force

$$\begin{aligned} C_D = \frac{\mathbf {F}_b \cdot {\hat{\mathbf {e}}}_x}{R u_0^2} \qquad C_L = \frac{\mathbf {F}_b \cdot {\hat{\mathbf {e}}}_y}{R u_0^2}. \end{aligned}$$
(101)

In our numerical tests, we examine the impulsively started cylinder for RE \( = 40\) and RE \( = 550\). In both cases, we use \(R = 1\), \(u_0 = 10\) and the appropriate values of \(\mu \) to obtain RE. Here Figs. 16 and 17 show the drag versus time for an impulsively started cylinder with RE \( =40\) and RE \( =550\), respectively. Note that qualitatively the curves match the benchmark results from [20]. In particular, for the RE \( =40\), the drag coefficient monotonically decays to a value slightly below \(2\). Meanwhile, for RE \( =550\), the drag first drops, followed by a peak at \(T = 3.05\). Here Fig. 18 shows the early development of vorticity for the impulsive cylinder. We also extend the computation for a much longer time to verify the onset of vortex shedding. Here Fig. 19 shows the oscillations in the lift coefficient versus time, while Fig. 20 shows the vorticity at various times in the evolution. We note that due to the periodicity of the domain, the simulation effectively models an array of cylinders, as opposed to the conventional von Kármán street which arises from flow past one cylinder.

Fig. 16
figure 16

Drag versus time for RE \( = 40\). Here \(\eta = 2\times 10^{-4}\), \(N = 512\), \(l = 0.45\)

Fig. 17
figure 17

Drag versus time for RE \( = 550\). Here \(\eta = 10^{-3}\), \(N = 768\), \(l = 0.05\). Circles correspond to snapshots of the vorticity shown in Fig. 18

Fig. 18
figure 18

Snapshots of the vorticity for an impulsively started cylinder with RE \( = 550\). Images are taken at times (\(\hbox {l}-\hbox {r}\)) \(T = 1, 1.66, 2.33, 3, 3.66, 4.33\) and correspond to the circles in Fig. 17

Fig. 19
figure 19

Lift versus time for the onset of the von Kármám street at RE \(= 550\). The oscillations correspond to vortex shedding. Circles correspond to snapshots of the vorticity shown in Fig. 20

Fig. 20
figure 20

Snapshots of the vorticity for an impulsively started cylinder showing the onset of full vortex shedding and von Kármán type street [30]. Images are for RE \(= 550\), and taken at times \(T = 45, 51, 57, 63, 69, 75\) corresponding to the circles in Fig. 19

9 Conclusion

In this paper, we outline how to construct high order penalty methods. We do so by first introducing an active penalty term for the heat equation. When we increase the number of matched derivatives, we show that the penalty term improves the analytic convergence rate in terms of the penalty parameter. Secondly, we examine the numerical stability of the active penalty term. We show that it does not introduce additional stiffness into the equations or additional length scales that would need to be resolved. The combination of the high order convergence in the penalty parameter along with the numerical stability then leads to higher order numerical schemes. Lastly, we extend the penalized term from the heat equation to the incompressible Navier–Stokes equations. In particular, we show how to handle the divergence constraint on the velocity field. We also conclude with an application of flow around an impulsively started cylinder for RE \(=40\) and RE \(=550\). In the case of RE\(=550\), we demonstrate the onset of a von Kármán street.

Although we have outlined a high order approach, there are still remaining issues that limit the practical feasibility of the method. For instance, at no point do we improve the smoothness of the solution \(\mathbf {u}_{\eta }\). In fact the second derivatives of \(\mathbf {u}_{\eta }\) remain discontinuous across the curve \(\Gamma \), although matching more derivatives in the active penalty term may reduce the size of the discontinuity. As a result, Fourier methods still have a slow decay in the Fourier modes thereby limiting the ability to spectrally compute derivatives. In addition, interpolation of high order derivatives in the construction of \({\tilde{\mathbf {g}}}\) should be one-sided (i.e. from \(\varOmega _p\)) while in practice one would prefer to use points on both sides of \(\Gamma \). As a result, ongoing research includes improving the global smoothness of \(\mathbf {u}_{\eta }\) while retaining the high order convergence.