Next Article in Journal
Improving the Representativeness of a Simple Random Sample: An Optimization Model and Its Application to the Continuous Sample of Working Lives
Next Article in Special Issue
Fourier-Spectral Method for the Phase-Field Equations
Previous Article in Journal
Using an Adaptive Fuzzy Neural Network Based on a Multi-Strategy-Based Artificial Bee Colony for Mobile Robot Control
Previous Article in Special Issue
Finite Difference Method for the Multi-Asset Black–Scholes Equations
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A Simple Parallel Solution Method for the Navier–Stokes Cahn–Hilliard Equations

Faculty of Informatics/Mathematics, HTW Dresden, Friedrich-List-Platz 1, 01069 Dresden, Germany
*
Author to whom correspondence should be addressed.
Mathematics 2020, 8(8), 1224; https://doi.org/10.3390/math8081224
Submission received: 29 June 2020 / Revised: 23 July 2020 / Accepted: 24 July 2020 / Published: 25 July 2020
(This article belongs to the Special Issue Open Source Codes for Numerical Analysis)

Abstract

:
We present a discretization method of the Navier–Stokes Cahn–Hilliard equations which offers an impressing simplicity, making it easy to implement a scalable parallel code from scratch. The method is based on a special pressure projection scheme with incomplete pressure iterations. The resulting scheme admits solution by an explicit Euler method. Hence, all unknowns decouple, which enables a very simple implementation. This goes along with the opportunity of a straightforward parallelization, for example, by few lines of Open Multi-Processing (OpenMP) or Message Passing Interface (MPI) routines. Using a standard benchmark case of a rising bubble, we show that the method provides accurate results and good parallel scalability.

1. Introduction

Phase-field (or diffuse-interface) models have become a valuable tool for the numerical simulation of two-phase flows. In many fields these methods have been proven advantageous compared to traditional sharp interface methods (e.g., Level-Set, Arbitrary Lagrangian–Eulerian, Volume-Of-Fluid). Phase field methods can easily handle (i) moving contact lines (e.g., [1]), (ii) topological transitions (e.g., [2,3]), and (iii) additional chemical species in the fluid and on the interface (e.g., [4]). Further, these methods are relatively robust and do not require additional stabilization techniques such as reinitialization or convection stabilization. It has been shown in recent years that phase field models can be computationally cheap [5] and accurate [6,7] depending on the simulated problem.
Mathematically, phase field methods for two-phase flow are typically described by the Navier–Stokes Cahn–Hilliard equations. Efficient techniques have been proposed for their discretization in space (e.g., [8]) and in time (e.g., [5,9,10]). Due to the necessary high resolution at the fluid–fluid interface, typical discretizations are based on adaptive finite element methods which comes along with a complexity that makes implementations from scratch almost impossible. In addition, the scalable parallelization of such methods is typically challenging and requires a solid knowledge on memory-distributed matrices and vectors and parallel preconditioning and solution techniques. However, given the current shift from serial towards parallel computing, parallelizability is the key component of future numerical algorithms. The goal of this paper is to combine parallelizability with simplicity in a single numerical method. Therefore, we propose a parallel finite difference scheme for the Navier–Stokes Cahn–Hilliard equations.
A finite difference scheme is arguably the simplest way to discretize partial differential equations in space. Efficient finite difference schemes have been proposed for phase field methods, e.g., in [2,3]. Recently, the method has been extended to feature mass conservation and energy stability [11]. All these approaches are rather difficult to understand for a novice and complicated to parallelize as they all involve solvers for coupled systems of equations. Parallel implementations from scratch usually require several thousand lines of code.
Here we aim to avoid the solution of (non-)linear systems of equations by employment of an explicit (forward) Euler method. In this case all unknowns decouple, no system of equations needs to be assembled, and all degrees of freedom can be directly computed from values of the previous time step. This enables straightforward parallelization by few lines of Open Multi-Processing (OpenMP) or Message Passing Interface (MPI) routines. We make this explicit time discretization applicable to these equations of saddle-point structure by a special pressure projection scheme with incomplete pressure iterations. It is known that explicit Euler methods introduce strong time step restrictions of the form d t < C h 2 for a second order equation and d t < C h 4 for a fourth order equation, such as the Cahn–Hilliard equation. However, we will show that in practice these restrictions are much less severe and that our proposed method is very efficient as the number of computations per time step is low.
Accordingly, we develop a parallel solution method for the Navier–Stokes equations which can be understood and implemented even for a novice within a few days. We share the (short) code attached to this publication and expect it to be valuable for PhD students and numerical analysts who want to have an easy-to-understand code basis at hand to solve two-phase flow problems with a fast parallel method. Using a standard benchmark case of a rising bubble, we show that our method can provide accurate results in a highly efficient, yet very simple, parallel implementation.
The structure of the remaining paper is as follows. In Section 2 we present the Navier–Stokes Cahn–Hilliard equations. In Section 3 and Section 4, we present the time and space discretization, respectively. The resulting method is challenged in a standard two-phase flow benchmark in Section 5. Afterwards we give some comments on the attached implementation of the method in Section 6. Finally, conclusions are drawn in Section 7.

2. Navier–Stokes Cahn–Hilliard Equations for Two-Phase Flow

The phase field method was originally developed to model solid–liquid phase transitions, see, e.g., [12,13,14]. The interface is represented as a thin layer of finite thickness ε and an auxiliary function, the phase field ϕ , is used to indicate the phases. The phase field function varies smoothly between distinct values in both phases and the interface can be associated with an intermediate level set of the phase field function. Diffuse interface approaches for mixtures of two immiscible, incompressible fluids lead to the Navier–Stokes Cahn–Hilliard equations and have been considered by several authors, see, e.g., [8,15,16,17]. If variable (phase-dependent) densities are involved, different formulations of the model equations have been proposed [17,18,19,20]. However, in real scenarios away from the critical point, the involved interface thickness ε is small such that all these models yield comparable results [6]. Therefore, we use the simplest model which reads [17]
ρ ( ϕ ) t u + ( u · ) u = p + · η ( ϕ ) D ( u ) + f + σ ˜ ε 1 μ ϕ ,
· u = 0 ,
t ϕ + u · ϕ = m Δ μ ,
μ = ϕ 3 ϕ ε 2 Δ ϕ ,
in the domain Ω . Here u , p, ϕ , and μ are the velocity, pressure, phase field variable, and chemical potential, respectively. The parameter m is a mobility constant, ε defines a length scale over which the interface is smeared out. Furthermore, D ( u ) = u + u T is the (doubled) viscous rate of strain tensor, ρ ( ϕ ) , η ( ϕ ) , and f are the (phase dependent) density, viscosity, and body force. The polynomial ϕ 3 ϕ arises as the first derivative of the double well potential W ( ϕ ) = 1 / 4 ( ϕ 2 1 ) 2 with respect to ϕ . This choice of the polynomial leads to the values ϕ ± 1 in two distinct fluid phases. The parameter σ ˜ is a scaled surface tension which is a multiple of the physical surface tension σ . For the given double-well potential, the relation σ ˜ = σ 3 2 2 holds [21].
Since the solution of the Cahn–Hilliard equation does not satisfy a maximum principle, we follow the approach in [22] and use a truncated phase field function
ϕ ^ = ϕ , | ϕ | 1 , sign ( ϕ ) , | ϕ | > 1 ,
to construct linear interpolations of the viscosity η and density ρ ,
η ( ϕ ) = ϕ ^ + 1 2 ( η + 1 η 1 ) + η 1 ,
ρ ( ϕ ) = ϕ ^ + 1 2 ( ρ + 1 ρ 1 ) + ρ 1 ,
where η ± 1 and ρ ± 1 denote the viscosity and density in the fluid phases where the phase field is ± 1 , respectively. Similar truncated phase field functions have played an essential role in the simulation of multi-agent systems [23].

3. Time Discretization

In this section we adopt the explicit Euler scheme for the time discretization of the Navier–Stokes Cahn–Hilliard equations. Let the time interval [ 0 , T ] be divided in N subintervals of size d t , such that t n : = n · d t , where the upper index denotes the time step number.
Before applying the time discretization to the individual systems we use an operator splitting approach to decouple the Navier–Stokes equations from the Cahn–Hilliard equations. To be more precise, both problems are solved subsequently in every time step. First, we solve the Navier–Stokes system using the values of ϕ and μ from the previous time step. Then we solve the Cahn–Hilliard system using the just computed velocity field.

3.1. Time Discretization of the Navier–Stokes Equations

The main difficulty in numerically solving the Navier–Stokes equations is that the pressure field is coupled indirectly to the velocity by the incompressibility condition. Chorin [24] and Temam [25] proposed an effective way to decouple the pressure from the velocity by a projection type scheme. As their original scheme has poor accuracy in time many improved versions of these schemes have been introduced since, for details we refer to the review article [26]. Keeping in mind that we aim for an explicit time discretization which enforces small time steps, the time stepping error of the original scheme becomes less important.
In terms of simplicity, the original scheme of Chorin [24] and Temam [25] surpassed all its succeeding versions. The idea is to decouple the momentum and mass balance equations. To this end, an intermediate velocity field u ˜ n + 1 is computed, which satisfies the momentum balance (without the pressure term), but is not divergence-free. Then this field is projected to the space of divergence free functions to obtain the velocity u n + 1 . The latter step involves to first solve an additional equation for the pressure field p n + 1 which is then used to update the velocity field. Combined with an explicit time discretization the scheme reads:
ρ u ˜ n + 1 u n d t + u n · u n = · η D ( u n ) + f n + σ ˜ ε μ n ϕ n ,
· 1 ρ p n + 1 = · u ˜ n + 1 d t , p n + 1 n | Ω = 0 ,
ρ u n + 1 u ˜ n + 1 d t = p n + 1 ,
where / n denotes the normal derivative on the domain boundary Ω .
Equations (8)–(10) are decoupled and can be solved subsequently. The first equation is used to compute an intermediate (not divergence-free) velocity field u ˜ n + 1 . The second equation computes the pressure which is then used to obtain a divergence-free velocity field u n + 1 from the last equation. Hence, Equations (9) and (10) can be seen as the projection of u ˜ n + 1 onto the space of divergence-free vector fields.
The first and third equation are completely explicit, i.e., the sought variables u ˜ n + 1 and u n + 1 can be directly computed. The second equation is a Poisson equation and is usually handled by assembling a matrix which can be solved with the conjugate gradient method or by shifting the problem to Fourier space and solving with spectral methods.
Again, as we aim for simplicity we follow a different approach here. The idea is to make Equation (9) amenable to an explicit Euler method by including a time derivative of the pressure. In fact, the solution p n + 1 from Equation (9) can be seen as the stationary solution of the convergent heat equation
t p · 1 ρ p = · u ˜ n + 1 d t , p n + 1 n | Ω = 0 .
Instead of solving this equation exactly, we propose to solve only K steps of the time evolution by an explicit Euler scheme. Accordingly, we introduce K 1 intermediate values p n + k / K for k = 1 , , K 1 which can be computed successively from
p n + k + 1 K p n + k K d t ˜ · 1 ρ p n + k K = · u ˜ n d t , k = 0 , K 1 ,
with a different time step size d t ˜ . As we aim for the stationary solution it is desired to choose d t ˜ as large as possible. From the explicit Euler scheme, the time step restriction d t ˜ < ρ h 2 / 4 emerges. To be well below this barrier, we use half of this time step size, d t ˜ = ρ h 2 / 8 , throughout this work.
As the time step size of the overall projection method, d t , is small, we can expect that the velocity and pressure change only slightly in every time step. Hence, very few iterations K of Equation (11) should suffice to update the pressure. In the simplest case, K = 1 , Equation (11) reduces to a direct computation of p n + 1 by
p n + 1 p n d t ˜ · 1 ρ p n = · u ˜ n d t .
This choice can be sufficient if the time step size is small enough.

3.2. Time Discretization of the Cahn–Hilliard Equations

The explicit Euler scheme for the Cahn–Hilliard equation reads
ϕ n + 1 ϕ n d t + u n + 1 · ϕ n = m Δ μ n ,
μ n = ε 2 Δ ϕ n + ( ϕ n ) 3 ϕ n .
Due to the explicit presence of a fourth order space derivative, a time step restriction arises: d t < C h 4 / ( m ε 2 ) . Luckily, this restriction turns out to be less severe after the following considerations. Firstly, the interface length ε is very small. The real thickness of a fluid–fluid interface is in the order of nanometers, unless the temperature is close to the critical point. This length scale cannot be resolved in numerical methods as soon as the length scale of the problem exceeds the micrometer range. Hence, in any useful numerical approximation that aims to be close to the real physical solution, ε is chosen as small as possible. In practice, that means ε is chosen similar to the grid size, ε h . Consequently, the above time step restriction effectively reduces to d t < C h 2 / m . This condition is weakened further, as m is typically very small. The interface moves physically with the fluid velocity, thus m needs to be so small that the right-hand side of Equation (12) hardly moves the interface but only conserves the interface shape, similar to reinitialization in Level-Set methods. In addition, matched asymptotic analysis shows the convergence of diffuse-interface methods toward the sharp interface equations only for small CH mobility [20].
The remaining time step restriction can be tolerated, given that the number of computations in each time step is relatively low in comparison to implicit time discretization methods. While the latter reduces time step restrictions, they typically involve several orders more computations per time step, due to the necessary solution of a (linear) system of equations, which is avoided in our method.

4. Space Discretization

The time discrete scheme presented in the previous section is discretized in space by a finite difference method. We use an equidistant rectangular grid with equal spacing h in all directions. For simplicity the following discussion is restricted to two dimensions, but we note that the scheme can be easily extended to three dimensions. The rectangular computational domain Ω = [ 0 , L x ] × [ 0 , L y ] is subdivided into N x · N y square cells with N x = L x / h , N y = L y / h .
Scalar variables are defined in the centers of these cells. One additional layer of ghost points is included outside of each boundary facet. To stay close to the implementation we use only integer indices to describe the values of all variables on the grid points. Hence, the discrete grid values of a scalar field q ( x , y ) are defined as
q i , j = q i 1 2 h , j 1 2 h , i = 0 , , N x + 1 , j = 0 , , N y + 1 ,
where q is a placeholder for ϕ , μ , p .
To avoid spatial oscillations from the odd-even decoupling between pressure and velocity, a staggered Cartesian grid is employed [27]. On a staggered grid the velocity variables ( u 0 , u 1 ) = : u are shifted by h / 2 in their respective direction to the cell faces. Figure 1 shows the arrangement of all the different variables on the grid. To stay close to the implementation we use only integer indices to describe the values of all variables on the grid points:
u 0 i , j = u 0 i 1 h , j 1 2 h , i = 0 , , N x + 2 , j = 0 , , N y + 1 , u 1 i , j = u 1 i 1 2 h , j 1 h , i = 0 , , N x + 1 , j = 0 , , N y + 2 .
Note, that ghost points are also included for the velocity field. While this might not be necessary, depending on the boundary condition, it simplifies and unifies indexing and implementation at negligible additional memory consumption.
We introduce for some quantity q the discrete Laplacian Δ h , all-sided average A, horizontal and vertical averages A x , A y , backward differences D x , D y , and central differences D 2 x , D 2 y as follows:
Δ h q i , j : = ( q i + 1 , j + q i 1 , j + q i , j + 1 + q i , j 1 4 q i , j ) / h 2 , A q i , j : = ( q i , j + q i 1 , j + q i , j 1 + q i 1 , j 1 ) / 4 , A x q i , j : = ( q i , j + q i 1 , j ) / 2 , A y q i , j : = ( q i , j + q i , j 1 ) / 2 , D x q i , j : = ( q i , j q i 1 , j ) / h , D y q i , j : = ( q i , j q i , j 1 ) / h , D 2 x q i , j : = ( q i + 1 , j q i 1 , j ) / 2 h , D 2 y q i , j : = ( q i , j + 1 q i , j 1 ) / 2 h .

4.1. Matched Densities and Viscosities

In the beginning let us consider the simple case of matched viscosity ( η = η 1 = η + 1 ) and matched density ( ρ = ρ 1 = ρ + 1 ). In this case the viscous stress contribution reduces to η Δ u and the space discretization of Equation (8) reads
u ˜ 0 i , j n + 1 = u 0 i , j n d t u n · u n 0 i , j + d t ρ η Δ h u 0 i , j n + σ ˜ ε A x μ i , j n · D x ϕ i , j n + f 0 i , j n for i = 2 , , N x ; j = 1 , , N y ,
u ˜ 1 i , j n + 1 = u 1 i , j n d t u n · u n 1 i , j + d t ρ η Δ h u 1 i , j n + σ ˜ ε A y μ i , j n · D y ϕ i , j n + f 1 i , j n for i = 1 , , N x ; j = 2 , , N y ,
with
u n · u n i , j = u 0 i , j n D 2 x u 0 i , j n + A u 1 i , j + 1 n D 2 y u 0 i , j n A u 0 i + 1 , j n D 2 x u 1 i , j n + u 1 i , j n D 2 y u 1 i , j n .
Boundary conditions to the velocity are included in this step as explained in the Appendix A.
After computing u ˜ n + 1 directly from these equations, the pressure p n + 1 is calculated from the discretized version of Equation (11),
p i , j n + k + 1 K = p i , j n + k K + h 2 8 Δ h p i , j n + k K ρ h 8 d t u ˜ 0 i + 1 , j n u ˜ 0 i , j n + u ˜ 1 i , j + 1 n u ˜ 1 i , j n for i = 1 , , N x ; j = 1 , , N y ,
which is solved for k = 0 , K 1 to successively compute p i , j n + 1 K , p i , j n + 2 K , , p i , j n + 1 , for a small constant K.
Finally, the new velocity field is computed from
u 0 i , j n + 1 = u ˜ 0 i , j n + 1 d t ρ D x p i , j n + 1 for i = 2 , , N x ; j = 1 , , N y ,
u 1 i , j n + 1 = u ˜ 1 i , j n + 1 d t ρ D y p i , j n + 1 for i = 1 , , N x ; j = 2 , , N y .
After calculation of the new velocity, the Cahn–Hilliard system is solved. Using central differences for the advective term, a second order in space discretization of the Cahn–Hilliard Equations (12) and (13) reads
μ i , j n = ε 2 Δ h ϕ i , j n + ( ϕ i , j n ) 3 ϕ i , j n , ϕ i , j n + 1 = ϕ i , j n d t A x u 0 i + 1 , j n + 1 · D 2 x ϕ i , j n + A y u 1 i , j + 1 n + 1 · D 2 y ϕ i , j n + m d t Δ h μ i , j n for i = 1 , , N x ; j = 1 , , N y .
The homogeneous Neumann boundary conditions are included as explained in the Appendix A.
Equations (14)–(19) provide a way to directly solve the Navier–Stokes Cahn–Hilliard system. We again note the equations can be solved individually for each i and j, no coupled system of equations is involved. Hence, the solution algorithm can be easily implemented with a few dozen lines of code. Due to the direct calculation, parallelization (e.g., with OpenMP or MPI) is straightforward, can be done with a few lines of code and can be expected to scale very well.

4.2. Non-Matched Density and Viscosity

In the general case of non-matched density and viscosity the discretization becomes more elaborate. We define η i , j n = η ( ϕ i , j n ) and ρ i , j n = ρ ( ϕ i , j n ) and replace ρ in Equations (14) and (17) by A x ρ i , j n and in Equations (15) and (18) by A y ρ i , j n . Additionally, in Equation (16) we replace ρ by ρ i , j n and Δ h p i , j n + k K by
ρ n · 1 ρ n p n + k K i , j = Δ p n + k K + ρ n 1 ρ n · p n + k K i , j = Δ h p i , j n + k K + ρ i , j n D 2 x 1 ρ i , j n · D 2 x p i , j n + k K + D 2 y 1 ρ i , j n · D 2 y p i , j n + k K .
To deal with non-constant viscosity we introduce the fields α , β , γ to represent the viscous stress,
α γ γ β : = η u + ( u ) T .
In the discrete case, α and β are naturally defined in the cell centers, γ is defined on the cell vertices. This leads to
α i , j n = 2 η i , j n D x u 0 i + 1 , j n , β i , j n = 2 η i , j n D y u 1 i , j + 1 n , γ i , j n = D y u 0 i , j n + D x u 1 i , j n A η i , j n .
These terms are then used to replace the viscous terms η Δ h u 0 i , j n and η Δ h u 1 i , j n in Equations (14) and (15) by D x α i , j n + D y γ i , j + 1 n and D y β i , j n + D x γ i + 1 , j n , respectively.

5. Benchmark Test Results

To validate the accuracy of the model, a benchmark test as described by test case 1 in [28] is conducted. This test can be seen as the standard benchmark for two-phase flows and has been conducted for many different numerical methods (e.g., Level-Set, Volume-of-Fluid, Arbitrary Lagrangian–Eulerian). The benchmark was applied to various phase field methods in [6].

5.1. Test Scenario

The test specifies a circular bubble of one fluid (here ϕ 1 ), which rises in a rectangular domain Ω = [ 1 , 0 ] × [ 2 , 0 ] filled with another fluid (here ϕ 1 ). The initial position of the center of the bubble is at ( 0.5 , 0.5 ) and its radius is 0.25, which results in the initial condition
ϕ i , j 0 = tanh 0.25 i 0.5 · h 0.5 2 j 0.5 · h 0.5 2 2 ε
Test case 1 of [28] prescribes for the outer fluid the physical quantities ρ 1 = 1000 and η 1 = 10 . The inner fluid of the bubble is defined by ρ + 1 = 100 and η + 1 = 1 . Furthermore, the gravitational force vector is set to f = ( 0 , 0.98 ( ρ ( ϕ ) ρ 1 ) ) and the surface tension σ to 24.5 . No slip boundary conditions are specified at the top and bottom, a free slip condition is imposed at the lateral boundaries. Due to the different densities of the inner and outer fluids, the bubble will rise in the vertical tube over time. The simulation is run for 3 time units during which some benchmark quantities are computed.
The chosen four combinations of numerical parameters are listed in Table 1. Their choice is guided by reported values in the phase field benchmark [6]: The interface thickness ε is refined proportional to grid size h, which keeps the number of elements along the interface fixed.
The mobility is set to a small constant, m = 0.01 , which is by a factor ten higher than the value chosen in [6] (acknowledging the different scaling of mu there). We conducted a preliminary study to determine that this value of m is large enough to keep a good shape of the phase field interface profile while introducing only small (undesired) Cahn–Hilliard diffusion, which is confirmed by the accuracy of the results in Section 5.3. In addition, note that results are essentially independent of m when ϵ 0 , see [20]. Given the previously discussed time step restrictions, the time step size is scaled quadratically with grid size.
Similar to [6], the total number of degrees of freedom per time step is reported for the four different simulations. Additionally, the CPU time of each parameter case is listed in Table 1 for an OpenMP implementation running on four cores.

5.2. Measured Quantities

In order to compare our results with the literature some of the benchmark quantities presented in [28] are used. Their calculation is described below:
(1) Center of Mass
y c = Ω ϕ + 1 · y Ω ϕ + 1 ,
(2) Rise Velocity
V c = Ω ϕ + 1 · u 1 Ω ϕ + 1 .
(3) Error Norms and Orders of Convergence
The following three error norms are also specified in [28] and will be used for the evaluation of our results:
e 1 = n = 1 N | q r e f n q n | n = 1 N | q r e f n | , e 2 = n = 1 N | q r e f n q n | 2 n = 1 N | q r e f n | 2 0.5 , e = max n | q r e f n q n | max n | q r e f n | ,
where q n is the temporal evolution of quantity q. We use the results of the simulation with the finest grid and smallest time steps as the reference solution q r e f n . Spline interpolation is used to match the time steps of the reference solution with our solution. Using the so defined errors, a rate of convergence (ROC) can be computed as follows:
R O C = log error 2 h error h / log ( 2 ) ,
where error h denotes the error as defined above on a grid of grid size h.

5.3. Results

5.3.1. Bubble Shape

As already described in [28], the initial circular bubble changes its shape over time to an ellipsoidal shape. In Figure 2 one can see the different bubble shapes at the end time t = 3 compared to the reference results from group 1 in [28]. It shows that the shapes of our model approximate the reference solution as grid resolution and interface thickness are refined. Especially the final bubble shapes of the two finest grids with h = 1 / 128 and h = 1 / 256 got very close to the reference results, as they are wider than the bubble shapes produced by the other two simulations.

5.3.2. Benchmark Quantities

In addition to the bubble shapes, we evaluated different benchmark quantities as defined before. Figure 3 shows the center of mass and the rise velocity of the bubble over time in comparison to the reference solution from [28].
Both measured quantities approach the reference values with increasing grid resolutions. In the “eye norm” the center of mass is nearly identical for the two finest grids, while the simulation with h = 1 / 32 is more off. Differences between the parameter cases are more pronounced when looking at the rise velocity. Here, one can see more clearly that all curves approach the reference solution with increasing grid resolutions. This behavior is also confirmed in Table 2 which lists the maximum rise velocity and the final center of mass. A comparison with the phase field results from [6] reveals similarly small deviations from the reference solutions in [28] which indicates that these differences stem mostly from the modeling error due to non-zero interface thickness.

5.3.3. Error Norms

Finally, the calculated error norms and the resulting orders of convergence are presented in Table 3. Overall, the previous observations are confirmed, since all the calculated errors become smaller with finer grid resolutions and shorter time step lengths. The ROC values indicate clear second order convergence for all error norms. Note that this implies second order convergence in space and first order in time as time step size is scaled quadratically with the grid size.

5.3.4. Parallelization

Finally, we tested the model for different numbers of cores to examine the parallel efficiency. The resulting time measurements and calculated speedup can be found in Figure 4. Here, the dimensions of the field were 512 × 1024 grid points and the number of time steps was set to 3000. It can be seen that the implementation of the proposed discretization method is highly parallelizable leading to a nearly perfect linear speedup. It is noteworthy that parallelization has been achieved by a few simple OpenMP ’parallel for’ directives. Given the problem size is large enough, a similarly good linear speedup can also be expected for much larger number of cores, for OpenMP as well as MPI parallelization.

6. Implementation

We share the code in the supporting material attached to this publication and additionally on GitHub: https://github.com/soranad-a/parallel-navier-stokes-cahn-hilliard. It contains the discretized Navier–Stokes Cahn–Hilliard system implemented in C++, whereby the variable names were kept analogous to those in the equations above. Furthermore, the code includes OpenMP for parallelization on multiple cores. It consists of the following three files:
  • helpers.h—handles output and data structure of 2 dimensional arrays.
  • config.conf—self explanatory file defining all constants and simulation parameters.
  • main.cc—contains core code of the numerical algorithm, but most of the lines are needed for reading parameters and managing output.
The code can be compiled by: g++ -std=c++17 -fopenmp -O3 main.cc.
To enable the correct output of the simulation files, the program needs a subfolder named paraview/into which it writes its output files, which can be visualized in the open-source data analysis software ParaView (www.paraview.org). Furthermore, during runtime, a file named benchmark.csv is created, which contains the measured benchmark quantities.

7. Conclusions

We have presented a discretization method of the Navier–Stokes Cahn–Hilliard equations. The method offers an impressing simplicity, which is based on an explicit Euler time discretization of a special pressure projection scheme with incomplete pressure iterations. Hence, it is not necessary to solve a linear system of equations as all unknowns decouple, and computations can be done separately for each grid point. Consequently, the method can be easily implemented from scratch and parallelization is straightforward by few lines of OpenMP or MPI routines.
A standard benchmark case of a rising bubble is used to evaluate the method in practice. We find that the arising time step restrictions are not critical as the number of compute instructions per time step is relatively low. We show that the method provides accurate solutions comparable to previous results from finite-element methods [6,28]. The numerical results approach reference values as grid size and interface thickness are decreased. The computed ROC indicates second order convergence. Finally, we measure computation time for up to 24 CPU cores and find a nearly perfect parallel speedup.
We share the (short) code attached to this publication and expect it to be valuable for novices in phase field simulations who want to have an easy-to-understand code basis at hand to solve two-phase flow problems with a fast parallel method. The method is flexible and can easily be augmented to account for additional physical processes. In the future we plan to extend the method to describe flows in complex evolving geometries [29] and fluid-structure interaction using the approach in [30]. We further address the large-scale parallelization by use of GPUs.

Author Contributions

Conceptualization, S.A.; software, N.A., F.F., S.A.; validation, N.A.; writing N.A., S.A.; visualization, N.A.; supervision, S.A.; funding acquisition, S.A. All authors have read and agreed to the published version of the manuscript.

Funding

This article is funded by the Open Access Publication Fund of Hochschule für Technik und Wirtschaft Dresden University of Applied Sciences and the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation)—432908064.

Acknowledgments

S.A. acknowledges support from the German Science Foundation through grant AL 1705/5-1. Simulations were performed at the Center for Information Services and High Performance Computing (ZIH) at TU Dresden.

Conflicts of Interest

The authors declare no conflict of interest.

Appendix A. Boundary Conditions

Boundary conditions can be set by modifying the values of the ghost nodes. This modification is done at the end of each time step to the newly computed field (index n + 1 ).
For cell-centered variables like μ , ϕ , and p homogeneous Neumann boundary conditions can be imposed by setting the values in each ghost node to the values of the neighboring inner point in Ω . For example for ϕ :
ϕ 0 , j : = ϕ 1 , j , ϕ N x + 1 , j : = ϕ N x , j for j = 1 , , N y ,
ϕ i , 0 : = ϕ i , 1 , ϕ i , N y + 1 : = ϕ i , N y for i = 1 , , N x .
Dirichlet boundary conditions (e.g., ϕ = g on Ω ) are set for cell-centered variables by setting the value in the ghost point such that a linear interpolation to the neighboring inner point assumes the Dirichlet value (g) on the domain boundary. For example for ϕ = g is imposed by setting
ϕ 0 , j : = 2 g ϕ 1 , j , ϕ N x + 1 , j : = 2 g ϕ N x , j for j = 1 , , N y ,
ϕ i , 0 : = 2 g ϕ i , 1 , ϕ i , N y + 1 : = 2 g ϕ i , N y for i = 1 , , N x .
The same approach as for cell-centered variables is used to impose Neumann or Dirichlet boundary conditions of face-centered variables that do not sit on the boundary. This holds for u 0 on the lower and upper boundary and for u 1 on the left and right boundary. In the other cases, the velocity variables lie on the boundary and Dirichlet conditions can be imposed directly by specifying their value. For example, a no-slip condition u 0 = 0 on Ω is specified by
u 0 1 , j : = 0 , u 0 N x + 1 , j : = 0 for j = 1 , , N y ,
u 0 i , 0 : = u 0 i , 1 , u 0 i , N y + 1 : = u 0 i , N y for i = 2 , , N x .
In the benchmark example a free slip condition ( u 0 = 0 , x u 1 + y u 0 = 0 ) is used for u 1 on the lateral boundaries. This condition can be met by setting the auxiliary field γ to zero in all boundary nodes
γ 1 , j : = 0 , γ N x + 1 , j : = 0 for j = 1 , , N y + 1 ,
γ i , 1 : = 0 , γ i , N y + 1 : = 0 for i = 1 , , N x + 1 .

References

  1. Aland, S.; Chen, F. An efficient and energy stable scheme for a phase-field model for the moving contact line problem. Int. J. Numer. Methods Fluids 2016, 81, 657–671. [Google Scholar] [CrossRef]
  2. Kim, J. Phase-Field Models for Multi-Component Fluid Flows. Commun. Comput. Phys. 2012, 12, 613–661. [Google Scholar] [CrossRef]
  3. Lee, H.G.; Kim, J. An efficient numerical method for simulating multiphase flows using a diffuse interface model. Phys. A Stat. Mech. Appl. 2015, 423, 33–50. [Google Scholar] [CrossRef]
  4. Aland, S. Phase field models for two-phase flow with surfactants and biomembranes. In Transport Processes at Fluidic Interfaces; Springer: Cham, Switzerland, 2017; pp. 271–290. [Google Scholar]
  5. Aland, S. Time integration for diffuse interface models for two-phase flow. J. Comput. Phys. 2014, 262, 58–71. [Google Scholar] [CrossRef] [Green Version]
  6. Aland, S.; Voigt, A. Benchmark computations of diffuse interface models for two-dimensional bubble dynamics. Int. J. Numer. Methods Fluids 2012, 69, 747–761. [Google Scholar] [CrossRef]
  7. Aland, S.; Boden, S.; Hahn, A.; Klingbeil, F.; Weismann, M.; Weller, S. Quantitative comparison of Taylor flow simulations based on sharp-interface and diffuse-interface models. Int. J. Numer. Methods Fluids 2013, 73, 344–361. [Google Scholar] [CrossRef]
  8. Kay, D.; Welford, R. Efficient Numerical Solution of Cahn-Hilliard-Navier-Stokes Fluids in 2D. SIAM J. Sci. Comput. 2007, 29, 2241–2257. [Google Scholar] [CrossRef]
  9. Han, D.; Wang, X. A second order in time, uniquely solvable, unconditionally stable numerical scheme for Cahn–Hilliard–Navier–Stokes equation. J. Comput. Phys. 2015, 290, 139–156. [Google Scholar] [CrossRef] [Green Version]
  10. Shen, J.; Yang, X. Decoupled, energy stable schemes for phase-field models of two-phase incompressible flows. SIAM J. Numer. Anal. 2015, 53, 279–296. [Google Scholar] [CrossRef]
  11. Guo, Z.; Lin, P.; Lowengrub, J.; Wise, S.M. Mass conservative and energy stable finite difference methods for the quasi-incompressible Navier–Stokes–Cahn–Hilliard system: Primitive variable and projection-type schemes. Comput. Methods Appl. Mech. Eng. 2017, 326, 144–174. [Google Scholar] [CrossRef] [Green Version]
  12. Anderson, D.; McFadden, G.; Wheeler, A. Diffuse interface methods in fluid mechanics. Ann. Rev. Fluid Mech. 1998, 30, 139–165. [Google Scholar] [CrossRef] [Green Version]
  13. Emmerich, H. Advances of and by phase-field modeling in condensed-matter physics. Adv. Phys. 2008, 57, 1–87. [Google Scholar] [CrossRef]
  14. Singer-Loginova, I.; Singer, H. The phase field technique for modeling multiphase materials. Rep. Prog. Phys. 2008, 71, 106501. [Google Scholar] [CrossRef] [Green Version]
  15. Jaqmin, D. Calculation of two-phase Navier-Stokes flows using phase-field modelling. J. Comput. Phys. 1999, 155, 96–127. [Google Scholar] [CrossRef]
  16. Feng, X. Fully Discrete Finite Element Approximations of the Navier–Stokes–Cahn-Hilliard Diffuse Interface Model for Two-Phase Fluid Flows. SIAM J. Numer. Anal. 2006, 44, 1049–1072. [Google Scholar] [CrossRef]
  17. Ding, H.; Spelt, P.; Shu, C. Diffuse interface model for incompressible two-phase flows with large density ratios. J. Comput. Phys. 2007, 226, 2078–2095. [Google Scholar] [CrossRef]
  18. Boyer, F. A theoretical and numerical model for the study of incompressible mixture flows. Comput. Fluids 2002, 31, 41–68. [Google Scholar] [CrossRef] [Green Version]
  19. Lowengrub, J.; Truskinovsky, L. Quasi-incompressible Cahn-Hilliard fluids and topological changes. Proc. Roy. Soc. Lond. A 1998, 454, 2617–2654. [Google Scholar] [CrossRef]
  20. Abels, H.; Garcke, H.; Grün, G. Thermodynamically consistent, frame indifferent diffuse interface models for incompressible two-phase flows with different densities. Math. Model. Methods Appl. Sci. 2012, 22, 1150013. [Google Scholar] [CrossRef]
  21. Aland, S. Modelling of Two-Phase Flow with Surface Active Particles. Ph.D. Dissertation, TU Dresden, Dresden, Germany, 2012. [Google Scholar]
  22. Shen, J.; Yang, X. A phase-field model and its numerical approximation for two-phase incompressible flows with different densities and viscosities. SIAM J. Sci. Comput. 2010, 32, 1159–1179. [Google Scholar] [CrossRef]
  23. Shang, Y. Resilient multiscale coordination control against adversarial nodes. Energies 2018, 11, 1844. [Google Scholar] [CrossRef] [Green Version]
  24. Chorin, A.J. Numerical solution of the Navier-Stokes equations. Math. Comput. 1968, 22, 745–762. [Google Scholar] [CrossRef]
  25. Temam, R. Navier-Stokes Equations: Theory and Numerical Analysis; American Mathematical Society: Providence, RI, USA, 2001; Volume 343. [Google Scholar]
  26. Guermond, J.L.; Minev, P.; Shen, J. An overview of projection methods for incompressible flows. Comput. Methods Appl. Mech. Eng. 2006, 195, 6011–6045. [Google Scholar] [CrossRef] [Green Version]
  27. Harlow, F.H.; Welch, J.E. Numerical calculation of time-dependent viscous incompressible flow of fluid with free surface. Phys. Fluids 1965, 8, 2182–2189. [Google Scholar] [CrossRef]
  28. Hysing, S.; Turek, S.; Kuzmin, D.; Parlini, N.; Burman, E.; Ganesan, S.; Tobiska, L. Quantitative benchmark computations of two-dimensional bubble dynamics. Int. J. Numer. Meth. Fluids 2009, 60, 1259–1288, Raw Data. Available online: http://www.featflow.de/en/benchmarks/cfdbenchmarking/bubble.html (accessed on 24 July 2020). [CrossRef]
  29. Aland, S.; Lowengrub, J.; Voigt, A. Two-phase flow in complex geometries: A diffuse domain approach. CMES-Comput. Model. Eng. Sci. 2010, 57, 77–107. [Google Scholar]
  30. Mokbel, D.; Abels, H.; Aland, S. A Phase-Field Model for Fluid-Structure-Interaction. J. Comput. Phys. 2018, 372, 823–840. [Google Scholar] [CrossRef] [Green Version]
Figure 1. Staggered grid with quantities at their appropriate position. The grid is surrounded by a layer of ghost points, which are displayed slightly transparent here.
Figure 1. Staggered grid with quantities at their appropriate position. The grid is surrounded by a layer of ghost points, which are displayed slightly transparent here.
Mathematics 08 01224 g001
Figure 2. Bubble shapes at time t = 3 for h = 1 / 32 (red), h = 1 / 64 (yellow), h = 1 / 128 (purple), h = 1 / 256 (green), and reference from group 1 in [28] (blue).
Figure 2. Bubble shapes at time t = 3 for h = 1 / 32 (red), h = 1 / 64 (yellow), h = 1 / 128 (purple), h = 1 / 256 (green), and reference from group 1 in [28] (blue).
Mathematics 08 01224 g002
Figure 3. Center of mass (left) and rise velocity (right) over time in comparison to reference results from group 1 in [28].
Figure 3. Center of mass (left) and rise velocity (right) over time in comparison to reference results from group 1 in [28].
Mathematics 08 01224 g003
Figure 4. Parallel scaling: Time measurements in seconds (left) and calculated speedup (right) of simulations with grid size 512 × 1024 and a total time step number of 3000. The scales of the right plot are logarithmic and the speedup is calculated from mean execution time of three distinct simulation runs.
Figure 4. Parallel scaling: Time measurements in seconds (left) and calculated speedup (right) of simulations with grid size 512 × 1024 and a total time step number of 3000. The scales of the right plot are logarithmic and the speedup is calculated from mean execution time of three distinct simulation runs.
Mathematics 08 01224 g004
Table 1. Numerical parameters: grid resolution h, diffuse interface width ε , and time step size d t and the resulting total degrees of freedom NDOF per time step and average CPU time of each parameter case.
Table 1. Numerical parameters: grid resolution h, diffuse interface width ε , and time step size d t and the resulting total degrees of freedom NDOF per time step and average CPU time of each parameter case.
h ε dt NDOFCPU Time [s]
1/320.0464 × 10−510,24037.18
1/640.0216 × 10−540,960132.93
1/1280.014 × 10−5163,840717.62
1/2560.0051 × 10−5655,3605904.87
Table 2. Benchmark quantities: Maximum rise velocity V c , m a x with corresponding time t | V c = V c , m a x and final position of the center of mass y c ( t = 3 ) with reference results from group 1 in [28].
Table 2. Benchmark quantities: Maximum rise velocity V c , m a x with corresponding time t | V c = V c , m a x and final position of the center of mass y c ( t = 3 ) with reference results from group 1 in [28].
(h) V c , max t | V c = V c , max y c ( t = 3 )
1/320.20811.06301.0329
1/640.22950.97301.0654
1/1280.23720.94201.0753
1/2560.23950.92701.0776
ref0.24170.92131.0813
Table 3. Error norms and orders of convergence.
Table 3. Error norms and orders of convergence.
h | | e | | 1 ROC 1 | | e | | 2 ROC 2 | | e | | ROC 3
Center of mass
1/320.0387 0.0423 0.0415
1/640.01161.74350.01251.75250.01191.8090
1/1280.00252.19300.00272.20390.00252.2164
Rise velocity
1/320.1121 0.1173 0.1609
1/640.03511.67650.03701.66550.05311.5998
1/1280.00812.11430.00872.09400.01302.0256

Share and Cite

MDPI and ACS Style

Adam, N.; Franke, F.; Aland, S. A Simple Parallel Solution Method for the Navier–Stokes Cahn–Hilliard Equations. Mathematics 2020, 8, 1224. https://doi.org/10.3390/math8081224

AMA Style

Adam N, Franke F, Aland S. A Simple Parallel Solution Method for the Navier–Stokes Cahn–Hilliard Equations. Mathematics. 2020; 8(8):1224. https://doi.org/10.3390/math8081224

Chicago/Turabian Style

Adam, Nadja, Florian Franke, and Sebastian Aland. 2020. "A Simple Parallel Solution Method for the Navier–Stokes Cahn–Hilliard Equations" Mathematics 8, no. 8: 1224. https://doi.org/10.3390/math8081224

APA Style

Adam, N., Franke, F., & Aland, S. (2020). A Simple Parallel Solution Method for the Navier–Stokes Cahn–Hilliard Equations. Mathematics, 8(8), 1224. https://doi.org/10.3390/math8081224

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop