Partitioned Flow Simulations With PreCICE and OpenFOAM
Partitioned Flow Simulations With PreCICE and OpenFOAM
Master’s Thesis
Markus Mühlhäußer
Computational Science and Engineering
(International Master’s Program)
Technical University of Munich
Master’s Thesis
Furthermore, I would like to thank all of my dear friends who always believed in my
academic abilities and helped me clear my head in stressful times. I greatly appreciate
them being there for me whenever I reach out to them even when I neglected the friend-
ships at times.
I also want to deeply thank my family, who always supported me in my studies. Finally,
words cannot express my gratitude to my parents for their unconditional emotional and
financial support, for always being there for me when I need them the most.
vii
Abstract
Flow simulations are becoming increasingly complex and require dedicated solution strate-
gies to solve large and complex scenarios. Example applications are found in hemodynam-
ics, nuclear reactor simulations and, wind modeling. It can be beneficial to divide such
complex flow domains into smaller subdomains, which can be simulated by solvers that
best resolve the flow characteristics of the respective region. However, these subdomains
need to be coupled. The coupling library preCICE allows to couple various popular fluid
solvers with a black-box approach.
This thesis serves as validation for the fluid-fluid module of the preCICE OpenFOAM
adapter. Before coupling multiple fluid solvers with varying features, the possibilities and
limitations of coupling two similar fluid solvers should be assessed. I investigate incom-
pressible laminar flow partitioned in two domains. The investigation is done using the
OpenFOAM solvers icoFoam and pimpleFoam, with a Dirichlet-Neumann surface cou-
pling via preCICE. Fully developed flow can be coupled perfectly using mass-flux aware
boundary conditions. In that case, the maximum relative error for velocity compared to
the monolithic solution is in the order of 10−5 . Coupling of a developing flow profile
on a coarse mesh results in maximum errors in the order of 10−2 at the cells next to the
interface. The error depends linearly on the magnitude of the velocity gradient and the
cell size. In cells further away from the interface, the error is approximately one order
smaller. Higher order of accuracy around the coupling interface can be reached by manip-
ulating OpenFOAM solvers and thereby abandoning the non-invasive plugin approach of
the adapter and the idea of preCICE to treat solvers as black boxes.
Having established a baseline for the error that can be expected in fluid-fluid coupling, I
extend the fluid-fluid module of the OpenFOAM adapter to support more complex flows
and cover a wider range of OpenFOAM solvers. I add temperature to the coupled vari-
ables using a Dirichlet-Neumann coupling approach. The relative error for temperature
obtained in the validation case using buoyantPimpleFoam is in the order of 10−6 . A fur-
ther addition to the fluid-fluid module is custom inlet-outlet boundary conditions, which
allow backflow across the coupling interface. They incorporate the flux-aware behavior
that I established for uni-directional flow coupling and they can be set on both sides of the
interface, regardless of the flow direction.
Overall, this thesis provides an understanding for the capabilities and limitations of
coupling laminar flows with the fluid-fluid module of the preCICE OpenFOAM adapter
and paves the path towards coupling more complex fluid flows in the future.
ix
Contents
Acknowledgements vii
Abstract ix
1 Introduction 1
1.1 Goal of this thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Previous work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Structure of the thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Theory 5
2.1 The governing equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 The Finite Volume Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 The OpenFOAM solution algorithms . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.1 The SIMPLE algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.2 The PISO algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3.3 The PIMPLE algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.5 Heat transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 Tools 17
3.1 OpenFOAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1.1 The OpenFOAM case structure . . . . . . . . . . . . . . . . . . . . . . 18
3.1.2 The flow of an OpenFOAM solver . . . . . . . . . . . . . . . . . . . . 19
3.1.3 OpenFOAM equation language . . . . . . . . . . . . . . . . . . . . . . 19
3.1.4 OpenFOAM function objects . . . . . . . . . . . . . . . . . . . . . . . 21
3.1.5 The OpenFOAM object registry . . . . . . . . . . . . . . . . . . . . . . 22
3.1.6 Boundary conditions in OpenFOAM . . . . . . . . . . . . . . . . . . . 22
3.2 preCICE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.2.1 The OpenFOAM adapter . . . . . . . . . . . . . . . . . . . . . . . . . 28
4 Investigation 33
4.1 Basic fluid coupling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.2 The standard pipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.2.1 Simplifying the pipe problem . . . . . . . . . . . . . . . . . . . . . . . 35
4.2.2 Decoupling of the coupled simulation . . . . . . . . . . . . . . . . . . 37
4.2.3 The left half . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
xi
Contents
6 Recommendations 75
7 Conclusion 77
7.1 Outlook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Bibliography 78
xii
1 Introduction
Simulation of systems where different regions are best described by different mathemati-
cal models are called multiphysics simulations and are becoming increasingly interesting
to computational engineers and researchers. Some examples of multiphysics simulations
include fluid-structure interaction and conjugate heat transfer problems. Both problems
usually involve a fluid and a solid, both of which are described by different equations,
which interact with each other in a certain way. Simulating the fluid-solid system can be
done by combining all relevant equations into a big coupled system that is solved mono-
lithically. This approach has proven to be efficient and robust for certain applications,
however it is usually very specific to one application and its involved physics.
In contrast to the monolithic approach, a new focus has been set on solving multiphysics
simulations by partitioning the system into multiple regions, each of them being modeled
by only the equations that best describe that region. This on one hand reduces the math-
ematical complexity of the equations that need to be solved on each subdomain, but on
the other hand raises new challenges when it comes to the question of how these sub-
domains can be coupled in a numerically stable manner. Benjamin Uekermann goes into
great detail about this partitioned approach in his dissertation [16]. There, he also outlines
the major advantage of the partitioned simulation approach, which is the great flexibility
and reusability of physics solvers. Therefore, optimizing the partitioned approach will be
much more sustainable in the future and reduce the cost of development drastically.
All flow problems can, in theory, be described by the full Navier-Stokes equations.
The Navier-Stokes equations are a set of three-dimensional, non-linear, partial-differential
equations. They include variables such as velocity, pressure, temperature, density, and
flow phenomena such as convection, diffusion, and turbulence. This set of equations is in-
herently complex and cannot be solved analytically. Instead, the equations are discretized
in space and time, resulting in a finite linear system that can be solved numerically. Still,
depending on the resolution of the discretization, computing fluid motion is extremely
computationally intensive. As a result, we usually use simplified models that are suffi-
cient to describe the expected flow characteristics. For example, a fluid flow may be mod-
eled as turbulent or laminar, as compressible or incompressible, as three-dimensional or
two-dimensional.
Nowadays, flow simulations are becoming increasingly large and complex. In a mono-
lithic simulation approach, we need to solve the Navier-Stokes model that includes all
flow characteristics that are present anywhere in the whole domain. However, analo-
gously to the above-mentioned multiphysics simulations, a partitioned approach could
be utilized, where each subdomain is modeled differently. Thus, we can utilize the most
1
1 Introduction
efficient solvers for the underlying flow phenomena inside each subdomain and we can
even couple solvers of different discretization methods, such as finite volume, finite ele-
ment, or even lattice Boltzmann methods.
2
1.3 Structure of the thesis
Again with parallelization and scalability in mind, Grinberg et al. implement a Dirichlet-
Neumann coupling between multiple fluid domains [9]. The coupling is done for a spectral
element method by exchanging values of pressure, velocity and velocity gradients. They
identify the coupling interface as an error source that needs to be revised.
Fernández et al. developed an explicit scheme for coupling two fluid domains, both
solved by 3-dimensional Navier-Stokes equations [6]. Utilizing the Nitsche’s interface
method, they successfully couple fluid domains via a Robin-Robin coupling scheme for
the finite element discretization. They identified an imbalance of static powers that arises
in the Dirichlet-Neumann coupling of [9] and address it by specific total pressure formu-
lations. However, the resulting expressions are specific to the finite element method and
difficult to translate to a finite volume implementation.
As it was mentioned in Section 1.1, ultimately, we are also interested in coupling fluid
solvers based on different mathematical models. As an example, Wittenberg and Neu-
mann coupled an OpenFOAM finite volume solver with a molecular dynamics simulation
using their framework MaMiCo [21]. In her dissertation on urban wind flow simulations,
Camps Santasmasas used a setup where she coupled OpenFOAM with a lattice Boltzmann
method using a modified fork of the preCICE OpenFOAM adapter [15]. Instead of using
the suggested interface coupling, she created an overlap region from where the coupling
data is obtained.
3
1 Introduction
4
2 Theory
In this chapter, we want to go over the fundamentals of the mathematical equations that
describe the flow of fluids and then discuss the methods which are used by OpenFOAM
to solve these equations. We will go over the basics of the finite volume method and
explain some algorithms that are used by OpenFOAM to implement this method. This
chapter will only scratch the surface of what lies behind these methods and should be
used as a reference throughout this thesis. For a deeper understanding and more complete
derivations, I recommend textbooks that cover the finite volume method in completeness
([5] [18]).
Fluid motion in general is described by the Navier-Stokes equations, a set of partial differ-
ential equations that are solved for the solution variables pressure p and the vector quan-
tity velocity U . The first equation describes the conservation of mass and is also called the
continuity equation, with ρ being the fluid density:
∂
ρ = −∇ · (ρU ) (2.1)
∂t
The second equation is the momentum equation which represents the conservation of
momentum. It is a three-dimensional vector equation and a typical transport equation
containing a time derivative on the left-hand side and convective, diffusive and source
terms on the right-hand side:
∂
ρU = − ∇ · (ρU ⊗ U ) + ∇ · τ} − ∇p + ρg (2.2)
|∂t{z } | {z } | {z | {z }
convective term diffusive term source terms
time derivative
τ is the viscous stress tensor and g the gravitational force as an example of a common
external force. Equation 2.1 and Equation 2.2 are the main equations that need to be solved
to model the movement of fluids. The energy equation is the third equation and describes
the conservation of total energy. The complete energy equation is quite complex and is
often simplified by only solving for the internal energy. The transport equation for internal
5
2 Theory
∂ ∂p
ρh = − ∇ · (ρhU ) + ∇ · (k∇T ) − +S , (2.3)
|∂t{z } | {z } | {z } |∂t{z }
convective term diffusive term
time derivative source/sink terms
In Equation 2.3, k is the thermal conductivity of the fluid. From the internal enthalpy,
the temperature can be deducted when the material’s physical properties, such as specific
heat capacity, are known. When the fluid’s temperature is considered to be constant or
not relevant to the fluid’s flow profile, the energy equation can be neglected. Furthermore,
most solution methods can’t resolve the Navier-Stokes equations for highly turbulent flow.
In these cases, various simplified turbulent models can be used, many of which require
additional transport equations to be solved.
For the most part of this thesis, we will work with laminar flow of constant temperature,
neglecting energy and turbulence equations. Moreover, we consider incompressible fluids,
meaning the density ρ stays constant in both time and space. This simplifies the continuity
Equation 2.1 to:
∇U = 0 (2.5)
In the incompressible momentum equation, we get rid of ρ by dividing through the con-
stant density. The stress tensor τ in the diffusive term can be described by the laplacian of
the velocity multiplied with the kinematic viscosity ν. This leads to the following equation:
∂
U = −∇ · (U ⊗ U ) + ν∇2 U − ∇p̂ + g (2.6)
∂t
The pressure quantity p̂ in Equation 2.6 is the pressure divided by density p/ρ and has the
dimensions of m2 /s2 . When speaking of pressure in an incompressible context, we refer
to p̂ simply as p.
6
2.2 The Finite Volume Method
Figure 2.1: Tetrahedra made of four triangles and hexahedra made of six quadrilaterals are
the most common cell shapes for finite volume meshes[5].
In the finite volume method, the simulated domain is divided into many smaller control
volumes (cells), for each of which the conservation of mass, momentum and energy is en-
sured by balancing the fluxes at each cell’s surface. The whole system of smaller cells that
are connected by their faces is called the mesh. In theory, a mesh can consist of any poly-
hedral cells with polygonal faces. In practice, most meshes use hexahedral or tetrahedral
cells or a mix of both, depicted in Figure 2.1.
OpenFOAM uses a cell-centered domain discretization and a face-addressing mesh stor-
age. Being cell-centered means that all quantities, such as velocity or pressure, are stored
in the center of the cell and the value can be seen as an average that applies in the whole
control volume. All cells are described by their surrounding faces, which are shared by
neighboring cells. Each face is part of exactly two cells, where the cell with lower index
is assigned as the face owner and the other cell is called neighbor. Boundary faces, which
build up the surface of the domain, do not have a neigbour cell.
Having set up the finite volume mesh, the differential equations can be discretized by
using the values stored in the cell center. The general transport equation for an incom-
pressible flow for an arbitrary quantity φ can be expressed as:
∂
φ = − ∇ · (U φ) + ∇ · (D∇φ) + Sφ (2.7)
∂t
|{z} | {z } | {z } |{z}
convective term diffusive term source term
time derivative
7
2 Theory
The surface integrals as well as the source term integral of Equation 2.9 can be approxi-
mated by summations as:
Z
∂ X X
φdV = − Sf · (U φ)f + Sf · (D∇φ)f +Sc V + Sp V φ (2.10)
∂t V | {z } | {z }
f f
convective flux diffusive flux
The source term in Equation 2.10 is divided into a constant part Sc and a non-linear part
Sp [10]. The surface integrals are expressed as summations of the respective fluxes over
all faces f of the polyhedral control volume. Fluxes in general describe how much of a
quantity flows through a surface and are calculated by multiplying the quantity with the
surface area. For a vector quantity, this is done by taking the dot product with the face
vector Sf . In OpenFOAM, the convective flux (Sf · U ) from Equation 2.10 is stored in a
separate field called phi. Later on, the equation which is now discretized in space needs to
also be discretized in time. For this and more detailed explanations of the Gauss theorem,
I refer to further literature such as the extensive book about the finite volume method by
Moukalled et al. [5].
Looking at Equation 2.10, we can see that we need several quantities at the face centers.
These are calculated by interpolating between the values of the adjacent cell centers. In the
case of boundary faces, we need to be able to deduct the values from the given boundary
conditions. In the end, we can assemble a linear system of equations Aφ = b, where φ is
the solution vector of all φ at the cell centers, b is the source vector and A the coefficient
matrix. All discretized terms can be divided into implicit contributions that are part of A
and explicit contributions that are added to b. Having built the linear system of equations,
we can choose from many numerical methods for solving such. The next chapter describes
the general algorithms used by OpenFOAM which decide what matrices we need to as-
semble and how we solve for each of the solution variables.
8
2.3 The OpenFOAM solution algorithms
These algorithms all belong to the family of segregated solvers, meaning that we solve two
individual equations for velocity and pressure instead of one large system. The original
formulations of these algorithms as well as the derivations found in most textbooks work
on a staggered grid and solve the equations for the variable corrections only (see e.g. [5]).
For this thesis, we will look into the adaptations by OpenFOAM which work directly on
the solution variables stored in the finite volume mesh.
M U − b = −∇p, (2.11)
where b contains the source terms of the discretization. In a first momentum predictor step,
Equation 2.11 is solved to obtain an intermediate predicted velocity field. Next, the solver
splits the coefficient matrix M into a diagonal matrix A and a matrix H(U ), containing
all the off-diagonal components and the source term b:
H(U ) ∇p
U= − (2.13)
A A
Because A is a diagonal matrix, it can be inverted very easily. Finally, we can use the
expression for U from Equation 2.13 and substitute it into the continuity Equation 2.5 to
get
H ∇p
∇· − = 0, (2.14)
A A
which, on the next turn, can be rearranged to form the pressure Poisson equation:
H ∇p
∇· =∇· (2.15)
A A
The next step of the SIMPLE algorithm involves solving Equation 2.15 for pressure p.
9
2 Theory
In a final momentum corrector step, we correct the velocity as in Equation 2.13 with the
newly calculated, corrected pressure values. Doing so, we ensure that the corrected veloc-
ity values satisfy the continuity equation. However, unless we have reached the converged
steady-state solution, the corrected velocity values no longer satisfy the momentum equa-
tions. Thus, the SIMPLE algorithm proceeds to the next iteration by setting the pressure
corrected values as the initial guesses of the next time step. Figure 2.2 shows the flow chart
for the full SIMPLE algorithm as it is used by OpenFOAM. It also shows the optional steps
for solving the energy equation, which is usually done between the momentum predic-
tor step and the pressure solving step. If turbulence modeling is added to the solver, any
additional equations are solved in the end of each time step.
10
2.5 Heat transfer
• They must be compatible across multiple coupled equations, which applies in par-
ticular to pressure and velocity.
φb = φref (2.16)
The second type is the Neumann boundary condition which fixes the gradient normal
to the boundary ∇n φref for that variable.
∇n φb = ∇n φref (2.17)
Having set the value or gradient explicitly, the respective other value can be calculated
implicitly with the help of the discretization parameters. Subsection 3.1.6 will go into more
detail about the boundary conditions and their implementations in OpenFOAM.
∂h
cp = (2.18)
∂T
Instead of deriving a complete transport equation for temperature, we will look at the
general concepts of heat transfer.
Heat is transferred in fluids in mainly three different mechanisms: Conduction, convec-
tion and radiation [17]. We will only look into heat transfer by conduction and convection.
Conduction is the heat transfer on a molecular scale. Through vibrations and direct con-
tact, internal energy is transferred from molecules of higher energy to molecules of lower
energy. Thermal conduction is explained by the Fourier law of heat conduction:
q = −k∇T (2.19)
q is the heat flux density, which describes the amount of heat that is transferred through
1m2 per second. ∇T is the temperature gradient and k is the thermal conductivity of the
11
2 Theory
material.
Convection describes the heat transfer caused by the movement of the fluid. The fluid
movement can occur naturally in the presence of gravity due to the fluid density gradient
between locations of different temperature. Forced convection on the other hand describes
the process of transporting heat through an externally generated flow, e.g. by a fan. The
basic relationship for heat transfer by convection is described by Newton’s law for convec-
tion:
q = h(T − T∞ ), (2.20)
where h is the heat transfer coefficient, T is the temperature at the interface and T∞ is the
fluid temperature far away from the coupling interface. The heat transfer coefficient h is
a variable parameter that depends on the physical parameters of the fluid and the general
physical situation.
12
2.5 Heat transfer
Start
Initial guess p∗ , U ∗
Set
Correct face flux φf and veloc-
p* = p
ity U with updated pressure p
U* = U
no
Convergence?
yes
Stop
13
2 Theory
Start
Initial guess p∗ , U ∗
PISO loop
Set
Correct face flux φf and veloc-
p∗ = p
ity U with updated pressure p
U∗ = U
no
Convergence?
yes
Stop
14
2.5 Heat transfer
Start
Initial guess p∗ , U ∗
PIMPLE loop
Solve pressure poisson
equation for pressure p
PISO loop
Set
Correct face flux φf and veloc-
p∗ = p
ity U with updated pressure p
U∗ = U
no
Convergence?
yes
Stop
15
3 Tools
The investigations on in this thesis are done using of OpenFOAM and preCICE. We look
at OpenFOAM first, the program that I am going to use for the fluid simulations. I go over
its basic functionality and take a closer look into its boundary condition implementation,
which will be relevant during Chapter 4 and Chapter 5. Afterwards, I present preCICE,
the tool which allows coupling multiple OpenFOAM instances. I show the fundamental
concepts of preCICE and how to use it in combination with OpenFOAM.
3.1 OpenFOAM
OpenFOAM (Open-source Field Operation And Manipulation) is a C++ library designed
primarily for three-dimensional continuum mechanics [20]. It offers a wide variety of ap-
plications for solving complex fluid flow computations including chemical reactions, heat
transfer, and turbulence1 . Further solvers for problems in e.g. solid dynamics, electro-
magnetics, molecular dynamics or finance are also available. Accompanying the solver
applications, OpenFOAM provides a range of utilities for pre- and post-processing.
OpenFOAM is, as its name suggests, open source and freely available under the GNU
General Public License. There are multiple forks and variations of OpenFOAM, the main
three being:
In the context of this thesis, OpenFOAM refers to version v2112 by ESI-OpenCDF, which
we will use throughout this thesis. New releases of this variant are scheduled every six
months and the source code can be retrieved from GitLab2 . Users of OpenFOAM have the
possibility to easily modify existing solvers or add new ones, provided they have the re-
quired knowledge about the involved physics and programming techniques. Each solver
1
List of standard OpenFOAM solvers:
https://www.openfoam.com/documentation/user-guide/a-reference/a.
1-standard-solvers
2
OpenFOAM by ESI-OpenCFD source code:
https://develop.openfoam.com/Development/openfoam
17
3 Tools
and utility is its own application that can be executed in the system’s command line in-
terface. Since OpenFOAM has no native graphical user interface, the results, which are
stored as plain text files, must be visualized by external programs such as ParaView.
case folder
0
p
U
constant
polyMesh/
transportProperties
system
controlDict
fvSchemes
fvSolution
1
p
phi
2
...
...
Figure 3.1: Basic folder structure of an OpenFOAM case for the icoFoam solver. It contains
the time directories 0, 1, 2, ... as well as the configuration directories
constant and system
Most solvers require the three directories 0/, system/, and constant/ at the start
18
3.1 OpenFOAM
of the simulation, as they contain the simulation settings and case configuration. The 0/
folder is the initial time directory and contains the initial and boundary conditions for all
of the solver’s required fields. In the case of icoFoam, these are the pressure and velocity
fields. The constant/ directory contains the mesh information inside polyMesh/, as
well as all the variables that stay constant throughout the simulation. Because icoFoam
is an incompressible solver, the viscosity nu is specified in the transportProperties
dictionary. In OpenFOAM terminology, all input text files are called dictionaries. The
dictionaries inside the system/ folder contain all the necessary settings for the solver
to run, such as runtime and output information in controlDict, numerical schemes in
fvSchemes or algorithm controls in fvSolution. The additional time directories are cre-
ated by OpenFOAM during the execution of the solver, depending on the output controls
that are set in the controlDict.
Each OpenFOAM solver is a separate C++ application and thus defines its own main()
function. In the beginning, most applications include the fundamental finite volume code
from OpenFOAM, containing all the necessary data structures, discretization schemes and
so on. Listing 3.1 shows the source code for icoFoam, which is a very basic solver for
incompressible, laminar flow.
At the start of the program, the solver sets up the scenario by reading in all the configu-
ration dictionaries found in the case folder. This is done by inlining the header files such as
createTime.H, createMesh, or createFields.H, which contain routines for creating
the time object and the mesh or initializing the required physical fields. These files are
often defined globally, but some solvers have their locally defined versions with necessary
adaptations specific to the application. After the case has been set up, the general time
loop is entered to execute the solver-dependent algorithm. In the case of icoFoam, it is the
PISO algorithm, which is explained in Subsection 2.3.2. In general, this means assembling
the equations and the matrices that arise from the discretization schemes. These matrix
equations are solved numerically and the results are written to the disk after each time
step by runTime.write().
The OpenFOAM source code is a heavily templated C++ framework, that can easily over-
whelm users of moderate programming knowledge. Therefore, it is goal of OpenFOAM
to abstract the code details and implement the partial differential equations that need to
be solved, in a descriptive way [20]. Listing 3.2 shows how the basic momentum equation
∂ρU
+ ∇ · φU − ∇ · µ∇U = −∇p (3.1)
∂t
19
3 Tools
1 #include "fvCFD.H"
2 #include "pisoControl.H"
3
13 while (runTime.loop())
14 {
15 // Momentum predictor
16 fvVectorMatrix UEqn
17 (
18 fvm::ddt(U)
19 + fvm::div(phi, U)
20 - fvm::laplacian(nu, U)
21 );
22
23 if (piso.momentumPredictor())
24 {
25 solve(UEqn == -fvc::grad(p));
26 }
27
34 runTime.write();
35 }
36
37 return 0;
38 }
20
3.1 OpenFOAM
would be represented in OpenFOAM source code. It can be seen that each term of Equa-
tion 3.1 can be matched directly to a function in the code. This allows the user to quickly
understand what equations are solved in each application and makes it easy for him to
assemble his own additional equations. Further operators that might be needed for differ-
ential equations can be found in the OpenFOAM programming guide [13].
1 solve
2 (
3 fvm::ddt(rho, U)
4 + fvm::div(phi, U)
5 - fvm::laplacian(mu, U)
6 ==
7 - fvc::grad(p)
8 );
21
3 Tools
22
3.1 OpenFOAM
side the 0/ directory. OpenFOAM offers a wide range of different boundary conditions,
ranging from simple Dirichlet and Neumann conditions to more specialized ones, such as
periodic boundary conditions. A full list of available boundary conditions can be found in
the OpenFOAM user guide [12]. The functionality of these boundary conditions is imple-
mented in individual classes that all inherit from fvPatchField5 .
All boundary conditions need an implementation of the functions evaluate() and
snGrad(), which return the boundary face value and the normal gradient respectively.
Both functions evaluate the results in an explicit manner based on the current variable
fields. However, when the transport equations are discretized into a finite volume matrix
equation of the form Aφ = b, there are two terms to which boundary faces contribute
implicitly. For the discretized advection term we need an expression for the boundary face
values φbf and for the diffusion term we need an expression for the boundary face nor-
mal gradients ∇n φbf . For many boundary conditions, the expressions for face value and
gradient can be split into an explicit part and an implicit part that is multiplied with the ad-
jacent cell value φc . The implicit part contributes to the coefficient matrix A, whereas the
explicit part will be added to the source term b. The respective contributions are evaluated
by the following four functions that the fvPatchField class implements:
• Foam::Field valueInternalCoeffs()
• Foam::Field valueBoundaryCoeffs()
• Foam::Field gradientInternalCoeffs()
• Foam::Field gradientBoundaryCoeffs()
With φc being the value at the adjacent internal cell, the patch face values are expressed
in the following way:
Similarly, the gradient at the boundary faces is expressed with the gradient coefficients as:
The internal coefficients in Equation 3.2 and Equation 3.3 represent the implicit part that is
multiplied with φc and as such is added to the finite volume matrix. The boundary coeffi-
cients, on the other hand, are the explicit part that is added to the source term b. Listing 3.3
shows the declarations for all above-mentioned methods in the file fvPatchField.H.
5
OpenFOAM API Guide v2112, fvPatchField class reference:
https://www.openfoam.com/documentation/guides/v2112/api/classFoam_1_
1fvPatchField.html
23
3 Tools
fixedValue
The face normal gradients can then be expressed by using a forward difference approxi-
mation:
φref − φc
∇n (φ)bf = = −C∆ φc + C∆ φref (3.5)
∆
∆ is the distance from the cell center to the boundary face center. However, OpenFOAM
does not store the distances directly but instead uses the inverse of the distance C∆ = 1/∆.
Therefore, we will find the expression to the right of Equation 3.5 in the source code.
fixedGradient
Classic Neumann conditions are realized with the fixedGradient boundary condition
implemented in fixedGradientFvPatchField7 . In this case, the boundary face values
are not given explicitly, but are extrapolated from the neighboring internal cell values φc ,
with the help of the provided gradient ∇n (φ)ref and the delta coefficients C∆ .
∇n (φ)ref
φbf = φc + (3.6)
C∆
However, the boundary face gradient can simply be set to the given reference gradient:
As a special case, there also exists the zeroGradient boundary condition, which can
be used when the gradient of a variable is assumed to be zero at the boundary. The
6
OpenFOAM API Guide v2112, fixedValueFvPatchField class reference:
https://www.openfoam.com/documentation/guides/v2112/api/classFoam_1_
1fixedValueFvPatchField.html
7
OpenFOAM API Guide v2112, fixedGradientFvPatchField class reference:
https://www.openfoam.com/documentation/guides/v2112/api/classFoam_1_
1fixedGradientFvPatchField.html
24
3.1 OpenFOAM
zeroGradient boundary condition is evaluated by simply setting the boundary face val-
ues to the internal cell values, which is the result of setting ∇(φ)ref to zero in Equation 3.6.
This boundary condition is used for most quantities other than pressure at domain outlets,
where a fully developed flow is assumed.
inletOutlet
∇(φ)ref
φbf = (1 − v)φc + vφref + (1 − v) (3.8)
C∆
The face gradient is evaluated as
The value fraction parameter v operates as a blending factor between 0 and 1, where v = 0
corresponds to the fixedGradient condition and v = 1 is equal to the fixedValue
boundary condition.
The inletOutlet condition is meant for open boundary patches, where we do not
know if there will be an outflow or inflow at the boundary faces. The parameter v is
used as a switch between fixedValue and fixedGradient based on the flow direction
at the patch. The flow direction is automatically evaluated from the sign of the bound-
ary face flux phi. The user only needs to set the reference value φref for inflow, ∇n (φ)ref
is set to zero during the initialization. The outflow condition is therefore evaluated as
zeroGradient.
fixedFluxExtrapolatedPressure
25
3 Tools
3.2 preCICE
preCICE10 (Precise Code Interaction Coupling Environment) is a C++ library for parti-
tioned multi-physics simulations. It couples multiple single-physics solvers, each of which
simulates only a designated subpart of the whole multiphysics scenario. This approach
offers high flexibility, as no case-specific solvers need to be developed. Instead, multi-
ple existing solvers, also called participants, can be combined to solve a complex system.
Common multiphysics problems that can be solved with the help of preCICE include con-
jugate heat transfer (CHT) and fluid-structure interaction (FSI) [3]. Besides its core library,
preCICE offers adapters for a multitude of existing solvers such as OpenFOAM, FEniCS,
CalculiX, and many more. Furthermore, it provides a high-level application programming
interface (API) with C++, C, Fortran, Python and Matlab bindings, that allows the users to
add their own solvers to the coupled simulations. Next to the official adapters, the com-
munity provides a wide variety of additional unofficial ones. A full list can be found on the
preCICE website11 . Figure 3.2 shows an overview of how the preCICE library, its adapters
and the respective solvers interact with each other.
The external solvers are treated as “black boxes”, which means that preCICE has no
knowledge about each participant’s internal numerics. It only reads the output of each
solver and modifies their input, but does not interfere during a simulation iteration. While
also partially supporting volume coupling, most preCICE adapters are designed for sur-
face coupling, where two coupling participants share a common interface. In that case,
solvers are only modified by setting boundary conditions at the common interface, de-
pending on the boundary values of the other participant. Doing so, preCICE is kept mini-
mally invasive and flexible.
The communication between the individual solvers, involving the exchange of interface
data, is done by either MPI or TCP/IP sockets. The exchanged data must be mapped
to match the grid of each participant, which might not be consistent across two solvers.
preCICE provides multiple advanced data mapping schemes that allow a heterogeneous
coupling interface, where solvers can use meshes of different refinements and even dif-
ferent discretization methods such as finite volume or finite elements. Furthermore, the
solvers are allowed to run with different time step sizes, since preCICE handles the syn-
chronization of all participants.
10
preCICE website: https://precice.org/
11
Overview of available preCICE adapters: https://precice.org/adapters-overview.html
26
3.2 preCICE
The coupling scheme can be chosen to be either serial or parallel and either explicit or
implicit. For serial coupling, both solvers take alternating turns and wait for the other
solver to finish so they can use their latest output data. During parallel coupling, both
solvers run at the same time and use the other solver’s output data from the last time
step. When explicit coupling is specified, each solver is running chronologically, one time
step after another, with updated boundary values whenever preCICE interferes. However,
for a meaningful multiphysics simulation, the physical fields at the interface must be in
agreement for both solvers. This requires an iterative, fixed-point method that checks for
convergence of the interface values at each time step. Therefore, when implicit coupling is
specified, preCICE repeats each time step of the simulation multiple times until the output
values from both solvers match at the interface up to a specified convergence limit. Plain
implicit coupling however corresponds to a mathematical fixed-point iteration, which can
be unstable and slow. That is why preCICE provides multiple acceleration methods, such
as under-relaxation or quasi-Newton, that can reduce the number of iterations for the im-
plicit coupling.
In the end, the user specifies the coupled solver, the exchanged data, and the coupling
configuration in an XML file that is read by preCICE. Listing 3.4 shows an example of such
configuration file for fluid-fluid coupling. More information on the XML parameters can
be found on the preCICE website12 .
12
preCICE configuration file reference:
https://precice.org/configuration-xml-reference.html
27
3 Tools
28
3.2 preCICE
29
3 Tools
1 <precice-configuration>
2 <solver-interface dimensions="3">
3 ...
4 <participant name="Fluid1">
5 <write-data name="Velocity" mesh="Fluid1-Mesh" />
6 <read-data name="Pressure" mesh="Fluid1-Mesh" />
7 <mapping:nearest-neighbor constraint="consistent"/>
8 </participant>
9
10 <participant name="Fluid2">
11 <read-data name="Velocity" mesh="Fluid2-Mesh" />
12 <write-data name="Pressure" mesh="Fluid2-Mesh" />
13 <mapping:nearest-neighbor constraint="consistent" />
14 </participant>
15
16 <coupling-scheme:serial-implicit>
17 <time-window-size value="0.01" />
18 <max-time value="1.0" />
19 <participants first="Fluid1" second="Fluid2" />
20 <exchange data="Velocity" mesh="Fluid1-Mesh"
21 from="Fluid1" to="Fluid2" />
22 <exchange data="Pressure" mesh="Fluid2-Mesh"
23 from="Fluid2" to="Fluid1" />
24
33 </solver-interface>
34 </precice-configuration>
Listing 3.4: Excerpt of a preCICE v2 configuration file for a fluid-fluid coupling case: The
configuration defines the participants Fluid1 and Fluid2 with their respec-
tive meshes and the exchanged data Velocity and Pressure. Both par-
ticipants use a consistent nearest-neighbor data mapping scheme. The cou-
pling scheme is set to serial-implicit with the Quasi-Newton accelerator
IQN-ILS.
30
3.2 preCICE
1 preciceConfig "../precice-config.xml";
2
3 participant Fluid1;
4
5 modules(FF);
6
7 interfaces
8 {
9 Interface1
10 {
11 mesh Fluid1-Mesh;
12 patches (couplingOutlet);
13
14 readData
15 (
16 Pressure
17 );
18
19 writeData
20 (
21 Velocity
22 );
23 };
24 }
Listing 3.5: Example of a preciceDict that is placed in the case’s system directory. The
name of the participant, mesh, and data match the preCICE configuration file
from Listing 3.4.
31
4 Investigation
During the 14th OpenFOAM workshop Chourdakis et al. [2] showed that the fluid-fluid
coupling in principle works for coupling fluid solvers of different dimensionality. How-
ever, they also noted that the validation case of two coupled three-dimensional solvers did
not generate the desired accuracy, especially around the coupling interface.
This chapter describes the investigative process in which I attempt to find a better so-
lution and to understand the sources of error. In Section 4.1, we look at the validation
case from [2], which is a coupled case of laminar flow through a three-dimensional pipe.
We look into the equations involved at the coupling interface and find adequate boundary
conditions that improve the coupling results. In Section 4.3 we proceed to investigate a
more complex pipe, where I place the coupling interface into non-developed flow. We are
going to discover why this limits the accuracy that we can expect from fluid-fluid cou-
pling via preCICE. As a last validation case, I am going to present a widening pipe case
in Section 4.4, which is constructed by a non-orthogonal mesh. We investigate how the
non-orthogonality of the finite volume cells impact the coupling results. Lastly, I present
ideas in Section 4.5 on other coupling approaches that violate the preCICE concept of non-
invasive black-box coupling.
33
4 Investigation
Figure 4.1: General case setup for the unidirectional, partitioned simulations with preCICE
compared to a monolithic simulation.
34
4.2 The standard pipe
35
4 Investigation
(c) Velocity magnitude along the center of the (d) Velocity magnitude along the center of the
3D pipe for various preCICE coupling con- 2D pipe for various preCICE coupling con-
figurations figurations
Figure 4.2: Comparison of the meshes and steady state solutions for several preCICE se-
tups between the 3D pipe and the simplified 2D pipe.
36
4.2 The standard pipe
20m of the monolithic solution. Adding the communication of the gradients in preCICE
and using non-zero Neumann conditions would be the intuitive solution. Though it can
be seen from the graphs in Figure 4.2 that this always leads to unphysical increases or
decreases in the velocity, which violates the mass conservation law of the pipe domain.
As it was shown above for the coupled pipe scenario, there is always an error at the cou-
pling interface, regardless of the communicated quantities via preCICE. When coupling
the two OpenFOAM parts, only the values at the boundary faces are exchanged and the
two solvers do not interact with each other further. Therefore, it is a requirement for a
correctly converged coupled simulation that both parts converge to the correct solution
by their own if the face values from the monolithic solution are set as fixed values for the
boundary faces. This procedure is illustrated in Figure 4.3.
Figure 4.3: Decoupling the pipe scenario: Both coupling participants are simulated indi-
vidually without preCICE interaction. The reference values (Uif , pif , ...) for
the coupling boundaries are taken from the face values in the fully converged
monolithic solution that correspond to the coupling interface
37
4 Investigation
38
4.2 The standard pipe
Figure 4.4: Velocity graphs of the isolated right half and the coupled case with
fixedValue velocity and fixedGradient pressure boundary conditions at
the coupling inlet.
specifically, this is done by the function constrainHbyA(), which is shown in Listing 4.1.
In line 7 of Listing 4.1, the code checks for boundary patches at which the velocity is
not assignable. This evaluates to true for boundaries where the velocity is fixed, such as
no-slip walls or a fixed velocity inlet. Additionally, it checks that the pressure boundary
condition is not of the type fixedFluxExtrapolatedPressure at the same patch. If
both conditions are fulfilled, then the HbyA boundary values are set to the velocity bound-
ary values of the same patch as shown in Equation 4.2.
H
= Ubf (4.2)
A bf
By doing so, the momentum equations will be fulfilled at all patches where we have a fixed
zero pressure gradient, which usually is the case at walls and inlets. This becomes clear
when we compare Equation 4.2 with the momentum Equation 4.1 solved for HbyA:
H ∇p
= Ubf + (4.3)
A bf A bf
Since the coupling inlet differs from a normal inlet in the way that its pressure gradi-
ent is not zero, the momentum equation will be violated at the patch after setting the
HbyA values to the velocity values. A closer look at Listing 4.1 indicates that we can
39
4 Investigation
3 forAll(U.boundaryField(), patchi)
4 {
5 if
6 ( // True for fixedValue velocity patches
7 !U.boundaryField()[patchi].assignable()
8 && !isA<fixedFluxExtrapolatedPressureFvPatchScalarField>
9 (
10 p.boundaryField()[patchi]
11 )
12 )
13 {
14 HbyAbf[patchi] = U.boundaryField()[patchi];
15 }
16 }
40
4.2 The standard pipe
The constrainPressure() function is defined globally and called by almost all fluid
solvers. For the incompressible case, ρ is defined as uniformly one and can be dropped
from the equation. M RF in Equation 4.4 stands for Moving Reference Frame and is a
method that is used in rotational fluid scenarios. The pipe is not a rotating case and this
means that the term M RF.relative() evaluates to 1 and therefore can be dropped as well.
The field S is the surface vector field, which is obtained by multiplying the face normal
vectors with the face area magnitudes: S = n · |S|. With these simplifications, we can turn
Equation 4.4 to: " ! ! ! #
H 1
n · ∇pbf = n · − Ubf (4.5)
A A
bf bf
This is exactly the momentum Equation 4.1 solved for the pressure gradient multiplied by
the surface normal n. With that, we can conclude that at the coupling inlet, we need a
fixedFluxExtrapolatedPressure boundary condition. Looking through the solver
implementation of OpenFOAM shows, that this is the only possible pressure boundary
condition to go along with a fixedValue velocity and an effective non-zero pressure
gradient.
The blue, dashed graph in Figure 4.5 shows the results for the isolated right half af-
ter specifying the fixedFluxExtrapolatedPressure boundary condition. A minimal
relative error in the order of 10−4 can be identified behind the inlet. However, this issue is
most likely the result of manually interpolating the boundary velocity values rather than
due to the chosen boundary conditions.
41
4 Investigation
16 forAll(pBf, patchi) {
17 // fixedFluxExtrapolatedPressure patch is an updateableSnGrad type
18 typedef updateablePatchTypes::updateableSnGrad snGradType;
19 const auto* snGradPtr = isA<snGradType>(pBf[patchi]);
20
21 if (snGradPtr)
22 { // Calculate pressure gradient
23 const_cast<snGradType&>(*snGradPtr).updateSnGrad(
24 ( phiHbyABf[patchi]
25 - rho.boundaryField()[patchi]
26 *MRF.relative(SfBf[patchi] & UBf[patchi], patchi))
27 /(magSfBf[patchi]*rhorAUBf[patchi] )
28 );
29 }
30 }
42
4.2 The standard pipe
Figure 4.5: Velocity graphs of the isolated right half and the coupled scenario with
fixedValue velocity and fixedFluxExtrapolatedPressure (ffep) pres-
sure boundary conditions at the coupling inlet. The isolated simulation of the
right half produces a slightly larger error because the boundary values for ve-
locity are entered manually, whereas the coupled simulation self-corrects the
velocity values.
The coupled simulation with the new coupling inlet boundary conditions converges to a
solution that is almost exactly the same as the monolithic solution. Figure 4.5 shows the
result, and it can be seen that the error from the isolated right half is further reduced in the
coupled scenario. Figure 4.6a shows the relative error, as compared with the monolithic
solution, along the pipe’s center as well as close to the wall. It can be seen that the relative
error is almost twice as large in the cells next to the no-slip walls. However, the maximum
relative error is still very small with approximately 2.4 × 10−5 .
In the beginning of this chapter, I simplify the original pipe problem by downscal-
ing to a coarser two-dimensional mesh and switching the solver from pimpleFoam to
icoFoam. In the end, I also run the coupled simulation on the original pipe problem
with the fixedFluxExtrapolatedPressure boundary condition. The resulting error
graphs for the three-dimensional pipe are shown in Figure 4.6b. The relative errors are in
the order of 10−6 and the discrete values are a good indicator that the resulting errors are
purely numerical.
43
4 Investigation
(a) Relative coupling errors for the velocity in (b) Relative coupling errors for the velocity in
the two-dimensional pipe. the three-dimensional pipe.
Figure 4.6: Relative error of velocity magnitude for the coupled pipe cases with the
fixedFluxExtrapolatedPressure boundary condition and communi-
cated values of U and p. The graphs are sampled along the z-axis in the center
of the pipe and in the cells next to the pipe wall.
4.2.6 Conclusion
As a result of the first part of the investigation on fluid-fluid coupling, we can successfully
couple the laminar flow through a pipe, independent of the mesh size. This is done by
setting the fixedFluxExtrapolatedPressure (ffep) boundary condition at the cou-
pling inlet and communicate velocity and pressure values via preCICE. The ffep bound-
ary condition ensures flux consistency across the interface by ensuring that the momentum
Equation 4.1 is fulfilled at the coupling inlet. Due to the implementation of OpenFOAM’s
solvers this is not the case, when a non-zero gradient is set at an inlet patch.
44
4.3 The half-inlet pipe
(a) Mesh and dimensions of the half-inlet pipe (b) Velocity field with streamlines
case.
test case. The fluid has a viscosity of ν = 10m2 /s and an inlet velocity of Uin = 0.1m/s.
Because the inlet is smaller than the outlet, we can expect a decreasing velocity following
the flow streamlines (see Figure 4.7b). The coupling interface is placed at z = 5m, close
enough to the inlet to have a significant velocity gradient, but far enough away from any
potential vortices that might emerge in the cavity beneath the inlet.
I run the case as a coupled simulation with the coupling setup from the standard pipe
Section 4.2. At the coupling inlet the boundary conditions are set to fixedValue for ve-
locity and fixedFluxExtrapolatedPressure for pressure. At the coupling outlet I
use zeroGradient for velocity together with fixedValue for pressure. preCICE com-
municates U and p. The violet velocity graph in Figure 4.8a shows that, as expected, we do
not get a correctly converged solution with this setup. The non-physical zeroGradient
boundary condition at the coupling outlet causes a far-reaching error in the velocity curve.
Logically, I add ∇U to the communicated quantities in preCICE and send the values from
the coupling inlet stream upwards to the fixedValue boundary condition at the cou-
pling outlet. This configuration will be called “ffep” coupling. The ffep coupling, gives
an overall good result as shown by the green graph in Figure 4.8, though still, an error is
introduced in the cells close to the coupling interface.
45
4 Investigation
(a) Comparison of coupling with and without (b) Detailed graph around the interface for cou-
velocity gradient. pling with velocity gradient.
Figure 4.8: a) Velocity graphs for two coupling configurations of the half-inlet pipe. Both
setups use a fixedValue velocity and fixedFluxExtrapolatedPressure
(ffep) boundary conditions at the coupling inlet. At the coupling outlet is
a fixedValue pressure boundary condition with a zeroGradient (violet)
or fixedValue (green) velocity boundary condition. b) Zoomed in velocity
graph of the ffep coupling including velocity gradient, showing the typical er-
ror characteristic around the interface.
standard pipe scenario we know that we should make sure the momentum Equation 4.1 is
fulfilled at the boundaries. Usually, we assume a fully developed flow at the outlet of our
domain, which means that the velocity does not change along the flow direction, which is
the equivalent of a zeroGradient condition. Furthermore, in a fully developed flow the
other terms belonging to the momentum equation (such as H/A and 1/A) do not change
either. The intermediate fields HbyA and rAU, which correspond to the mentioned terms,
are initialized with zeroGradient boundary conditions. Therefore, assuming a fully de-
veloped flow at the outlet, no further adjustments of their boundary fields are necessary.
However, we do not always have a fully developed flow at the coupling outlet and
this means the zeroGradient boundary condition for the intermediate fields from the
momentum equation is not correct. Looking through the source code of OpenFOAM’s
icoFoam solver, there seems to be no adequate boundary condition that leads to an ad-
justment of the boundary field values for any terms involved in the momentum equa-
tion. This means that we cannot constrain the momentum equation at an outflow patch
where the velocity gradient is non-zero. Therefore, I violate the idea of preCICE being a
non-invasive coupling tool and modify the function constrainHbyA() to set the HbyA
boundary values at the coupling outlet according to Equation 4.3. Lines 26 to 32 of List-
ing 4.3 show the modified code in OpenFOAM, that calculates the boundary values for
HbyA at the coupling outlet patch.
46
4.3 The half-inlet pipe
Running the simulation for the isolated left half with the HbyA correction at the cou-
pling outlet returns the correct solution when compared to the monolithic results (see Fig-
ure 4.9b).
For the standard pipe scenario we established the fixedValue velocity boundary condi-
tion and the fixedFluxExtrapolatedPressure pressure boundary condition for the
coupling inlet. Figure 4.9a shows that simulating only the right half of the new half-inlet
pipe case leads to a noticeable error in the cells next to the inlet. Comparing the pres-
sure gradients that are calculated by the constrainPressure() function as explained
in Subsection 4.2.4 with the pressure gradients at the same location in the monolithic so-
lution confirms the problem. OpenFOAM calculates the pressure gradient according to
Equation 4.5. However, we do not know the real boundary values of the terms H/A and
1/A, but instead these are just the wrongly extrapolated values from the adjacent cell cen-
ters. As an alternative, I try to copy the approach from the coupling outlet and also adjust
the correction of HbyA at the coupling inlet to the full momentum equation. This implies
that the pressure boundary condition needs to be switched back to fixedGradient. Sim-
ulating the right half with the code changes in Listing 4.3 again produces correct results by
the look of it.
(a) Left half with fixed pressure and velocity (b) Both halves are simulated with the modi-
gradient at the outlet. Right half with fixed fied constrainHbyA() function from List-
velocity and ffep at the inlet. ing 4.3.
Figure 4.9: Velocity graphs of individually simulated halves of the half-inlet pipe scenario.
The boundary condition values are taken from the full monolithic solution.
47
4 Investigation
6 forAll(U.boundaryField(), patchi) {
7 if (
8 !U.boundaryField()[patchi].assignable()
9 && !isA<fixedFluxExtrapolatedPressureFvPatchScalarField>
10 (
11 p.boundaryField()[patchi]
12 )
13 )
14 {
15 if (isA<fixedGradientFvPatchScalarField>
16 (p.boundaryField()[patchi]))
17 {
18 // At coupling inlet
19 HbyAbf[patchi] = U.boundaryField()[patchi]
20 + gradpbyAbf[patchi];
21 }
22 else {
23 HbyAbf[patchi] = U.boundaryField()[patchi];
24 }
25 }
26 if (isA<fixedGradientFvPatchVectorField>
27 (U.boundaryField()[patchi]))
28 {
29 // At coupling outlet
30 HbyAbf[patchi] = U.boundaryField()[patchi]
31 + gradpbyAbf[patchi];
32 }
33 }
48
4.3 The half-inlet pipe
Figure 4.10: Velocity graph of the perfectly converged coupled simulation for the half-inlet
pipe. preCICE communicates all quantities U, p, ∇U, ∇p and the interface val-
ues of the field HbyA are adjusted to fulfil the momentum equation.
The first results of the invasive coupling approach are very promising. However, further
tests reveal that this configuration does not always perform this good. For example, if
the fluid viscosity is decreased, we find a significant error at the coupling interface. This
phenomenon is shown in Figure 4.11.
Changing the solver to pimpleFoam also limits the improvement obtained by the inva-
sive approach. Figure 4.12 shows the mean relative error of velocity magnitude over time
for both icoFoam and pimpleFoam. In Figure 4.12a we can see how the invasive cou-
pling error keeps decreasing until it reaches around 5 × 10−5 at the end of the simulation
at t = 2s. This error is significantly lower than what is achieved with the ffep coupling,
which is around 4 × 10−3 . Figure 4.12b shows the error graphs when trying those cases
with the pimpleFoam solver. As with icoFoam, the invasive coupling gives improved re-
sults compared to the ffep coupling. This time however, the invasive coupling error settles
49
4 Investigation
1 <coupling-scheme:serial-implicit>
2 <time-window-size value="0.01" />
3 <max-time value="2.0" />
4 <participants first="Fluid1" second="Fluid2" />
5 <exchange data="Pressure" />
6 <!--exchange data="PressureGradient" /-->
7 <exchange data="Velocity" />
8 <exchange data="VelocityGradient" />
9 <max-iterations value="25" />
10 <relative-convergence-measure
11 limit="1.0e-5" data="Pressure" mesh="Fluid2-Mesh" />
12 <!--relative-convergence-measure
13 limit="1.0e-5" data="PressureGradient" mesh="Fluid2-Mesh" /-->
14 <relative-convergence-measure
15 limit="1.0e-5" data="Velocity" mesh="Fluid1-Mesh" />
16 <relative-convergence-measure
17 limit="1.0e-5" data="VelocityGradient" mesh="Fluid2-Mesh" />
18 <acceleration:IQN-ILS>
19 <data mesh="Fluid2-Mesh" name="Pressure" />
20 <data mesh="Fluid2-Mesh" name="VelocityGradient" />
21 <initial-relaxation value="0.01" />
22 <max-used-iterations value="10" />
23 <time-windows-reused value="2" />
24 <filter type="QR1" limit="1e-7" />
25 </acceleration:IQN-ILS>
26 </coupling-scheme:serial-implicit>
Listing 4.4: Simplified excerpt of precice-config.xml for the half-inlet pipe case.
Configuration corresponds to the ffep coupling configuration. (fixedFluxEx-
trapolatedPressure boundary condition at coupling inlet). Configuration in-
cluding PressureGradient lines corresponds to the invasive coupling op-
tion.
50
4.3 The half-inlet pipe
at around 3 × 10−3 compared to 5 × 10−3 for the ffep coupling, and with that gives only a
slight improvement.
Figure 4.11: Coupled half-inlet pipe case with different viscosity values. For lower vis-
cosity values the error at the coupling interface increases as the flow becomes
more convective.
(a) Mean relative error of velocity magnitude (b) Mean relative error of velocity magni-
over time for coupled cases using icoFoam. tude over time for coupled cases using
pimpleFoam.
Figure 4.12: Mean relative error of velocity magnitude over simulation time for coupled
half-inlet pipe cases using a) icoFoam or b) pimpleFoam
Comparing the invasive coupling to the ffep coupling shows that it is the correct idea
to constrain the involved fields to the momentum equation at the coupling boundary. It
makes sense, however, that perfect results cannot be achieved for most cases, because in
the calculations of the HbyA boundary values, I still use the wrongly extrapolated values
from the field rAU.
Furthermore, Figure 4.12 reveals another problem of the invasive coupling approach.
51
4 Investigation
The invasive coupling results are a lot worse in the first time steps, compared to the ffep
coupling. In the icoFoam case, it takes 72 time steps until the invasive approach is superior
at t = 0.72s, in the case of pimpleFoam still 10 time steps. This can prove problematic for
highly transient simulations where we want our coupled simulation to be converged at all
time steps immediately.
Table 4.1 gives a comparison of total iterations and mean errors at the end of the sim-
ulation time t = 2s for the invasive and ffep coupling variants. We can see that the re-
duced errors for the invasive variants come with the cost of more than double the amount
of implicit iterations. The drawbacks of the invasive coupling method make its usefulness
questionable. Therefore, Table 4.1 shows two additional configurations that can reduce the
error of the ffep coupling scheme. The first option decreases the discretization error at the
interface by halving the grid size in z-direction (∆z1/2 = 0.5∆z). The other option is hav-
ing a lower velocity gradient ∇U1/2 at the coupling interface. By modifying the half-inlet
pipe case such that the inlet-outlet ratio is increased from 0.5 to 0.75, the velocity gradient
at the interface is approximately halved. Figure 4.13 shows the effect on the relative error
of velocity. Both, grid resolution and velocity gradient seem to be linearly correlated to
the error. From Figure 4.13 it can also be seen that the largest errors for the ffep coupling
usually appear in the cells next to the interface. The interface adjacent values are closer
together than their corresponding monolithic cell values as it is seen in Figure 4.8b. This
lets us define the expected maximum absolute coupling error as:
where UN and UP are the cell values on both sides of the interface. In cells further away
from the interface, the error quickly reduces by one order in magnitude.
Table 4.1: Statistics for various coupled simulation for the half-inlet pipe scenarios. Shown
are the total number of implicit preCICE iterations, the mean relative error for
velocity magnitude and pressure compared to the monolithic solution at t = 2.0s.
Simulation time step size is ∆t = 0.01s and maximum amount of iterations per
preCICE time window is 25.
52
4.3 The half-inlet pipe
Figure 4.13: Relative velocity errors for coupling of the half-inlet pipe with the ffep setup.
Comparison of the standard mesh to a refined mesh and a modified geometry
with lower velocity gradient at the interface.
4.3.4 Conclusion
53
4 Investigation
The last scenario that shall be presented in the context of this investigation chapter, is an
irregularly widening pipe. The fluid flows through a two-dimensional pipe that steadily
opens up. The number of cells in y-direction stay the same throughout, which leads to
a non-orthogonality of the cells as can be seen in Figure 4.14. The opening angle of the
pipe increases at the center of the pipe, where I place the coupling interface. This mesh
setup results in different magnitudes of non-orthogonality on both sides of the coupling
interface. The impact on the coupling results of this mesh will be investigated during this
chapter. The steadily increasing cross-area of the pipe leads to decreasing velocity along
the z-axis, which is shown in the sampled graph in Figure 4.15.
I run this case in a coupled setup by splitting the domain at the center of the z-axis.
Like in the previous chapter, there is a non-zero velocity gradient across the interface.
Additionally, the velocity decreases faster on the right side of the interface than to its left
due to the increased opening angle. Furthermore, this leads to the adjacent cells having a
different magnitude of non-orthogonality, which adds to the complexity of this scenario.
54
4.4 The irregularly widening pipe
Figure 4.15: Velocity graphs for the widening pipe case with fixedValue velocity and
fixedFluxExtrapolatedPressure boundary conditions at the coupling
inlet and fixedGradient velocity and fixedValue pressure boundary con-
ditions at the coupling outlet. The violet graph shows the result, when the
communicated velocity is corrected by the mass flux.
interface is, of course, a common problem for interface coupling procedures. In the case of
flow coupling however, it can prove especially troublesome if the interface interpolation
introduces a non-physical source or sink. In a closed pipe system for example, such an
error can cumulate and increase or decrease the velocities until the simulation breaks.
Therefore, I adjust the velocity that is sent from the coupling inlet to the coupling outlet
by a face flux correction. The formula for flux correction is taken from the OpenFOAM
boundary condition fluxCorrectedVelocity1 :
nφbf
Unew = Ubf − n(n · Ubf ) + (4.7)
|Sf |
Ubf is in this case the wrongly calculated velocity at the boundary, n are the patch nor-
mal vectors, |Sf | the face area, and φbf the boundary flux values that are obtained from the
1
OpenFOAM API Guide v2112, fluxCorrectedVelocity class reference:
https://www.openfoam.com/documentation/guides/v2112/api/classFoam_1_
1fluxCorrectedVelocityFvPatchVectorField.html
55
4 Investigation
field phi. First, the velocity component orthogonal to the boundary face is subtracted and
then, the flux divided by the face area is added. Listing 4.5 shows the code implementation
of Equation 4.7. Correcting the velocity values with this formula before sending them to
the coupling inlet assures that mass is conserved and that the mass flux is the same in the
right domain. Figure 4.15 shows the result for this implementation. The maximum error
in the cells next to the interface is increased, but further away from the coupling boundary,
the results match the monolithic solution very closely and most importantly, the mass is
conserved.
φN − φP
(∇n φ)f = + k · (∇φ)f (4.8)
n·∆
When specifying the scheme Gauss linear corrected instead, OpenFOAM adds a
non-orthogonal correction term k · (∇φ)f to the face gradient calculation. The correction
vector k, which is needed in the second term of Equation 4.8 is calculated as
∆
k =n− (4.9)
n·∆
where ∆ is simply the distance vector between the adjacent cell centers: ∆ = CN − CP
and n the normalized face vector S. Figure Figure 4.16 gives a visualization of the involved
vectors.
Inherently, there are no neighboring cells next to the boundary faces of the mesh. There-
fore, the distance vector ∆ and consequently kbf cannot be calculated properly. This prob-
lem is resolved by simply setting the correction vectors to zero and thereby does not apply
any non-orthogonal corrections at the boundary faces, including the coupling interface.
In the current implementation state, this error is overshadowed by larger error and has
only a minimal impact. Comparing the mean relative error of velocity magnitude and
pressure of the coupled simulations to the corresponding monolithic ones confirms that
there is an impact (see Table 4.2). While this is only a minor error source compared to
the previously described problems, it should be kept in mind, when a perfect coupling
solution should be required. This might be resolved by exchanging additional geometric
56
4.4 The irregularly widening pipe
9 vectorField Up = U_->boundaryFieldRef()[patchID];
10 scalarField phip = phi_->boundaryFieldRef()[patchID];
11 vectorField n =
12 U_->boundaryField()[patchID].patch().nf();
13 scalarField magS =
14 U_->boundaryField()[patchID].patch().magSf();
15 // Calculate flux corrected velocity values
16 vectorField U_corrected =
17 Up - n*(n & Up) + n*phip/magS;
18
26 // y-dimension
27 buffer[bufferIndex++] =
28 U_corrected[i].y();
29
30 // z-dimension
31 buffer[bufferIndex++] =
32 U_corrected[i].z();
33 }
34 }
35 }
57
4 Investigation
Figure 4.16: Visualization for the terms involved at the corrected gradient calculation. The
face f is not perpendicular to the vector ∆ that connects the neighboring cell
centers P and N
data, such as the cell center coordinates, between the coupling participants.
Table 4.2: The mean relative error of velocity magnitude over all cells. The coupled simu-
lation using uncorrected snGradSchemes is compared to the monolithic solution
using the uncorrected snGradSchemes. The coupled simulation with corrected
snGradSchemes is compared to the monolithic solution using corrected snGrad-
Schemes.
58
4.5 The domain decomposition approach
and the patchNeighbourField is the equivalent of a halo layer that is added next to the
internal subdomain which is visualized in Figure 4.17.
59
4 Investigation
the solutions for each subdomain. These can be combined again by using OpenFOAM’s
reconstructPar utility or opened separately in post-processing tools such as ParaView.
Flow partitioning with preCICE is essentially very similar to running parallel simula-
tions in OpenFOAM. In the same way as OpenFOAM uses domain decomposition for
parallelization, we divide the full fluid domain into two or more subdomains which we
call participants. Instead of using MPI calls directly, we call the preCICE library to commu-
nicate values between the coupled boundaries. This raises the following question: Why
do we not copy the domain decomposition methods and boundary conditions used by
OpenFOAM and utilize them for our preCICE partitioning?
60
4.5 The domain decomposition approach
ual solver.
Assuming we can incorporate such custom boundary conditions with corresponding
patch types, we would soon reach another problem, which is the communication fre-
quency. The preCICE OpenFOAM adapter is a function object and as such is called only
at certain points of the solver’s algorithm. Importantly, this is only once per time step at
most. Neighboring field values that are needed by our coupled boundary condition would
be updated only at the end of each time step. Problematically, intermediate fields such as
HbyA do no longer exist at the end of the solver’s time step and therefore, we cannot ac-
cess these fields’ values at all. OpenFOAM’s processor boundaries on the other hand are
updated every time a field’s correctBoundaryConditions() method is called. Gener-
ally speaking, this is happening every time after a field is newly created or the values have
been altered. When the HbyA field is initialized, its correctBoundaryConditions()
method is called which in turn calls the evaluate function of each boundary patch. The
processor boundary then handles the MPI communication to send the neighboring values
to these patches. To imitate this behavior in our custom preCICE-coupled boundary con-
ditions we would have to provide communication calls to preCICE in the evaluate()
method. Figure 4.18 shows the code flow when evaluating a field’s boundary conditions
with the proposed functionality of a custom coupled boundary condition.
Figure 4.18: OpenFOAM boundary flow for proposed custom boundary condition
While all of this could be feasible and potentially provide the most accurate coupling
interface, it is quite complex and out of scope of this thesis. Additionally, some concerns
about the usability of above method should be mentioned as well. This approach can
provide great results when coupling two OpenFOAM solvers, potentially from different
61
4 Investigation
OpenFOAM versions. It will probably not be useful, however, when one preCICE par-
ticipant is run by a different CFD program. Another program might not use the finite
volume method, might not use intra-time step hooks or use any of the intermediate fields
like above-mentioned HbyA. For these cases, the above explained construct is most likely
not usable at all.
62
5 Coupling of advanced flows
In Chapter 4, I established a basic functionality for coupling incompressible, laminar flow
scenarios, where the fluid has a consistent flow direction at the coupling interface. In
Chapter 2 however, we discussed that the complete Navier-Stokes equations include more
advanced flow characteristics such as the energy equation and turbulence modeling. Even-
tually, the goal is to extend the preCICE OpenFOAM adapter to support all standard
OpenFOAM fluid solvers.
During this chapter, I will first look into adding temperature to the coupled variables,
which is needed when we couple two solvers that include the energy equation, e.g. the
buoyantPimpleFoam solver. I present the implementation and one validation case in
Section 5.1. The full PIMPLE algorithm also includes the calculation of specified turbu-
lence models (see Subsection 2.3.3). However, analysis of turbulence flows often comes
with flow vortices of different sizes. Thus, before adding turbulence parameters to the
coupling, I develop a custom inlet-outlet boundary condition in Section 5.2 that can be
used at the coupling interface. The extension of actual turbulence will be left for develop-
ment outside the context of this thesis.
63
5 Coupling of advanced flows
(a) Boundary conditions for the flow over heated wall segment scenario.
Figure 5.1: Mesh and geometry of the two-dimensional pipe with a heated wall segment
at the bottom between x = 1.25m and x = 1.75m.
side of the coupling interface and a fixedGradient boundary condition on the other.
Setup
The case geometry and the temperature boundary conditions are shown in Figure 5.1. All
walls use a no-slip boundary condition for velocity and an adiabatic temperature bound-
ary condition except for the heated wall segment, where a fixed temperature of 310K is
prescribed. The incoming flow at the pipe inlet has a temperature of 300K. The fluid’s ther-
mal properties are taken from the preCICE tutorial case with a Prandtl number P r = 0.01
and a thermal conductivity of k = 1W/(mK). The fluid is modelled as a perfect gas.
I test two partitioning scenarios where I place the coupling interface downstream of the
heated wall segment for the first scenario and then upstream for the second. Figure 5.1
also shows where the pipe was partitioned for both cases. By this, I test that we can couple
64
5.2 Custom inlet-outlet boundary conditions
the heat flux independent of the flow direction. For velocity and pressure, it was clear in
which way the Dirichlet and Neumann boundary conditions are set to the coupling inlet
and coupling outlet. For temperature, it seems not inherently obvious in what direction
the Dirichlet-Neumann coupling should take place. Therefore, I test both partitioning vari-
ants, with fixedValue at the coupling inlet and fixedGradient at the coupling inlet
as well as the other way around.
The boundary conditions used for pressure and velocity correspond to the ffep coupling
that I established in Section 4.3. At the coupling outlet I use fixedValue for pressure
for velocity and fixedGradient and at the coupling inlet fixedValue for velocity and
fixedFluxExtrapolatedPressure for pressure.
The preCICE coupling setup in precice-config.xml is the same as in Listing 4.4 with
the addition of Temperature and TemperatureGradient as exchanged variables, both
with a relative convergence measure of 1 × 10−5 . The temperature variable that is sent
upstream is additionally added to the Quasi-Newton acceleration.
Results
Figure 5.2 shows the temperature graphs along the center of the pipe close to the coupling
interface. For both locations of the coupling interface it does not matter in which direction
I do the Dirichlet-Neumann coupling. The solutions converge to almost the same results.
As we can see from the total number of iterations at t = 40s in Table 5.1, the solutions con-
verged faster when I had a fixedValue at the coupling outlet and a fixedGradient at
the coupling inlet. However, experience shows that these iteration numbers are quite sen-
sitive to the coupling scheme setup, which should be optimized for each particular case.
From Table 5.1 we can also see that the overall solutions show a slightly lower average rel-
ative error of temperature for the setups where I place the coupling interface downstream
of the heat segment. This corresponds to the error differences of velocity and because
velocity and temperature are tightly coupled, it is hard to predict the errors’ origin. Gener-
ally, we can assume that it is preferable to place the coupling interface somewhere where
we expect a low velocity gradient. This should lead to a lower error in the general flow
and therefore to the coupled quantities such as temperature which are also advected by
the velocity of the flow.
65
5 Coupling of advanced flows
(a) Temperature graphs across the coupling in- (b) Temperature graphs across the coupling in-
terface downstream from the heated wall terface upstream from the heated wall seg-
segment at x = 1.75m. Both coupling vari- ment at x = 1.25m. Both coupling vari-
ants give the same results, which are close to ants give the same results, which close to the
the monolithic solution. monolithic solution.
Figure 5.2: Temperature graphs across the coupling interface downstream and upstream
from the heated wall segment. Two temperature coupling variants are shown,
once with fixedValue at the coupling Inlet and fixedGradient at the cou-
pling Outlet (green) and once with fixedGradient at the coupling Inlet and
fixedValue at the coupling Outlet (violet).
a coupled simulation with preCICE, it might be difficult to find sections where the flow
is steady throughout the simulation. Instead, we have to expect recirculations across the
interface, meaning that the flow direction at the coupling interface might vary from cell
to cell. This is especially important, when we want to couple turbulent flow, as turbulent
flow is expected to create vortices on different length scales.
So far, I only looked at unidirectional flow, where we can clearly define a coupling outlet
and a coupling inlet. These definitions will no longer hold, when both coupling boundaries
might act as an outlet, inlet, or both, depending on the flow characteristics. Furthermore,
we can no longer predict in what direction the Dirichlet-Neumann coupling should take
place for velocity and pressure. We need special boundary conditions that can act as both
a Dirichlet or Neumann boundary condition, depending on the flow direction.
OpenFOAM provides such functionality in boundary conditions named inletOutlet
and outletInlet. These are recommended to be used at outlets, where a backflow
might be expected. They can switch between acting as a fixedValue and zeroGradi-
ent boundary conditions depending on the direction of the face flux phi. However, during
the investigation in Chapter 4, I established that we cannot use zeroGradient bound-
ary conditions for either velocity or pressure at the coupling interface. Instead, we need
a fixedFluxExtrapolatedPressure pressure boundary conditions for inflow and a
66
5.2 Custom inlet-outlet boundary conditions
Table 5.1: Comparison of coupling iterations and relative errors for different coupling se-
tups at t = 40s (∆t = 0.1s). The coupling setup is either downstream or upstream
relative to the heated wall segment. The temperature T and temperature gradi-
ent ∇T are communicated downstream from the coupling outlet to the coupling
inlet (↓) or upstream from the coupling inlet to the coupling outlet (↑).
fixedGradient velocity boundary condition for outflow. These features cannot be used
when we set OpenFOAM’s native inletOutlet and outletInlet boundary condi-
tions.
5.2.1 Implementation
To combine the desired functionalities into inlet-outlet style boundary conditions, I imple-
ment custom classes for both, velocity and pressure. These boundary conditions inherit
from the base class fvPatchField from OpenFOAM. The respective C++ and header
files are placed inside the fluid-fluid module of the preCICE OpenFOAM adapter and are
part of the libpreciceAdapterFunctionObject.so library. Because the boundary
conditions need to be available before the function objects are loaded, the usage of the
preCICE function object changes slightly. Listing 5.1 shows the lines that need to be added
to each solver’s controlDict.
67
5 Coupling of advanced flows
1 functions
2 {
3 preCICE_Adapter
4 {
5 type preciceAdapterFunctionObject;
6 }
7 }
8
9 libs ("libpreciceAdapterFunctionObject.so");
Listing 5.1: Required setup in the controlDict file inside the OpenFOAM fluid solver
directory, if the custom inlet-outlet boundary conditions are to be used.
from another boundary class. Therefore, I copy the logic of the mixed boundary con-
dition to the coupledPressureFvPatchField class. Similar to OpenFOAM’s mixed
boundary condition, the refValue, refGrad and valueFraction are stored as private
class members. Listing 5.2 shows the implementation for the evaluate() and snGrad()
functions which return the face value and normal gradient respectively. The evaluate()
function calls updateCoeffs(), which sets the value fraction parameter according to
flux direction. The refValue will be set by preCICE while the gradient is calculated by
OpenFOAM in the constrainPressure() function (see Listing 4.2).
68
5.2 Custom inlet-outlet boundary conditions
1 void Foam::coupledPressureFvPatchField::updateCoeffs() {
2 const surfaceScalarField& phi =
3 db().lookupObject<surfaceScalarField>(phiName_);
4 const fvsPatchField<scalar>& phip =
5 patch().patchField<surfaceScalarField, scalar>(phi);
6
7 this->valueFraction() = pos0(phip);
8 fixedFluxExtrapolatedPressureFvPatchScalarField::updateCoeffs();
9 }
10
11 void Foam::coupledPressureFvPatchField::evaluate() {
12 updateCoeffs();
13
14 scalarField::operator=
15 (
16 valueFraction_*refValue_
17 + (1.0 - valueFraction_)
18 *(
19 this->patchInternalField()
20 + refGrad_/this->patch().deltaCoeffs()
21 )
22 );
23 fvPatchScalarField::evaluate();
24 }
25
26 Foam::tmp<scalarField>
27 Foam::coupledPressureFvPatchField::snGrad() const {
28 return
29 valueFraction_
30 *(refValue_ - this->patchInternalField())
31 * this->patch().deltaCoeffs()
32 + (1.0 - valueFraction_)*refGrad_;
33 }
69
5 Coupling of advanced flows
1 void Foam::coupledVelocityFvPatchField::updateCoeffs()
2 {
3 const surfaceScalarField& phi =
4 db().lookupObject<surfaceScalarField>(phiName_);
5 const fvsPatchField<scalar>& phip =
6 patch().patchField<surfaceScalarField, scalar>(phi);
7
10 int t0 = patch().boundaryMesh().mesh().time().startTimeIndex();
11 int t = patch().boundaryMesh().mesh().time().timeIndex();
12
24 fvPatchVectorField::updateCoeffs();
25 }
70
5.2 Custom inlet-outlet boundary conditions
1 // in file 0/p
2 boundaryField
3 {
4 interface
5 {
6 type coupledPressure;
7 refValue uniform 0;
8 refGradient uniform 0;
9 }
10 }
11
12 // in file 0/U
13 boundaryField
14 {
15 interface
16 {
17 type coupledVelocity;
18 refValue uniform (0 0 0);
19 refGradient uniform (0 0 0);
20 }
21 }
71
5 Coupling of advanced flows
Figure 5.3: Setup and solution for the flow over a backwards facing step scenario.
72
5.2 Custom inlet-outlet boundary conditions
Figure 5.4: Mean relative error of velocity magnitude over time for the backwards facing
step case. The error spikes occur when the flow direction across coupled faces
changes.
73
6 Recommendations
In this chapter I want to summarize some concrete tips to fluid-fluid coupling users and
developers, based on my discoveries:
When coupling unidirectional flow, the pressure boundary condition at the coupling in-
let should be set to fixedFluxExtrapolatedPressure. In Subsection 4.2.4 I figured
out that OpenFOAM assumes a zero Neumann condition for pressure when we specify
an inlet velocity. However, that is physically not true at most coupling interfaces and
the fixedFluxExtrapolatedPressure boundary condition turned out to be the only
available pressure condition that sets a non-zero gradient and doesn’t violate mass con-
servation at the inlet. Using this boundary condition comes with the additional advantage
that the pressure gradient does not need to be part of the exchanged coupling variables.
Mass conservation is one of the most important aspects when it comes to fluid-fluid cou-
pling. In Subsection 4.4.1, we have seen how that can become problematic when we have
non-orthogonal cells at the coupling interface. Fortunately, OpenFOAM handles mass con-
servation on each subdomain for the face flux field phi. Listing 4.5 shows the corrections
that can be applied to the exchanged velocity values using the boundary values of phi.
This correction term should be considered when coupling OpenFOAM fluid solvers on
skewed meshes.
75
6 Recommendations
76
7 Conclusion
In this thesis, I validated the accuracy of the fluid-fluid coupling module of the preCICE
OpenFOAM adapter for laminar flows. I explored several validation cases that helped
to understand the challenges that arise from a common surface coupling. Additionally,
I extended the adapter functionality for flows that transport heat and for reverse flow,
which paves the path towards a versatile adapter that supports most major OpenFOAM
fluid solvers.
The first validation case was a partitioned laminar flow through a straight pipe. The cou-
pling interface was set in a region where the pipe flow was already fully developed. The
standard Dirichlet-Neumann coupling introduced mass flux differences at the coupling
interfaces. I discovered that the only viable pressure boundary condition that sets a non-
zero gradient without violating the momentum equation at the coupling inlet boundary is
fixedFluxExtrapolatedPressure (ffep). The ffep boundary condition automatically
calculates the pressure gradient according to the inlet velocity and as a result, I needed to
exchange only velocity and pressure values via preCICE to obtain coupled results without
significant errors compared to the monolithic solution.
The next validation case was designed to have a changing velocity across the interface.
Thus, I had to add the velocity gradient to the communicated variables to match the gra-
dient at the interface. The coupled simulation returned average relative errors in the order
of 10−3 and maximum errors of 10−2 in the cells next to the interface. The error depends
on the mesh size and the velocity gradient magnitude at the interface. The velocity error
(U ) can generally be quantified as (U ) < abs(UN − UP ), where UN and UP are the ve-
locity values in the cells adjacent to the interface in the monolithic solution. I also tried
to improve the coupled solutions by manipulating OpenFOAM source code such that the
correctness of the momentum equations is enforced at both sides of the coupling interface.
This improved the converged coupled solutions, but gave worse results for the first time
steps. Ultimately, I realized, that a perfectly coupled simulation needs additional commu-
nication hooks that are specific to the numerics of OpenFOAM solvers. Such an approach
is not feasible with the adapter implementation as an OpenFOAM function object, but
would have to be more invasive.
Lastly, I looked at a widening pipe scenario with non-orthogonal cells. Due to the
non-orthogonality, the exchanged velocity quantities resulted in an inconsistent mass flux
across the interface. I corrected the velocity values that are read from the coupling outlet
for the face flux, which ensured the conservation of mass across the coupling interface.
I further noticed that the non-orthogonal correction terms for laplacian schemes are not
applied at boundaries, which is another error source in the case of skewed meshes.
77
7 Conclusion
After gaining significant knowledge on fluid coupling, I extended the existing fluid-
fluid module. I added classes for temperature and temperature gradient coupling and val-
idated those with a laminar, heat-transporting flow. I used Dirichlet-Neumann coupling
for temperature on top of the velocity and pressure coupling. The direction of temperature
coupling did not affect the accuracy, which was of the order 10−6 for the mean temperature
error.
Finally, I implemented custom inlet-outlet boundary conditions for velocity and pres-
sure. These combine the flexibility to be used on both sides of the coupling interface and
their behavior changes in respect to the flow direction. I validated the boundary conditions
with a backwards facing step scenario. The coupling interface was placed in a recirculation
area and the boundary conditions switched their functionality for each face according to
the flow direction.
7.1 Outlook
Regarding the fluid-fluid coupling module of the preCICE OpenFOAM adapter, it is the
goal to support most, if not all, OpenFOAM fluid solvers. For that, the adapter needs
to be further extended to support the exchange of all fluid parameters in more complex
flows. The next step will be the coupling of turbulent flows. For this, it seems desirable to
communicate all variables that are used by the considered turbulence model.
Another important aspect to make fluid-fluid coupling practical is the optimization of im-
plicit coupling. So far, the implicit coupling takes too many iteration to converge, resulting
in total runtimes around twenty times higher compared to the monolithic simulation. Of
course, this number will be lower when the size of each subdomain is larger compared to
the coupling interface. Still, this is an important issue for future research, which not only
concerns fluid-fluid coupling, but all partitioned multiphysics simulations.
The investigation results in this thesis let us conclude that Dirichlet-Neumann coupling
is a valid approach for flow partitioning. The remaining errors were not due to the cou-
pling, but rather due to how OpenFOAM solvers handle the boundaries for fields that are
created as intermediate steps of the solution algorithms. Instead of zeroth order extrapo-
lation, it might be possible to use a higher order extrapolation for those boundary field values. It
is possible, however, that such an implementation results in other problems.
Lastly, OpenFOAM is an extremely versatile toolbox for fluid simulations and users
have already expressed wishes to couple solvers from different OpenFOAM versions.
Therefore, it might be worth to look into a specific OpenFOAM-to-OpenFOAM preCICE
adapter. Such an adapter would need to be more invasive than the current function object
implementation and utilize additional communication hooks to exchange finite volume
related variables at several points during each time step, but would enable flow coupling
with significantly higher accuracy.
78
Bibliography
[1] Gerasimos Chourdakis. A general OpenFOAM adapter for the coupling library
preCICE. Master’s thesis, Technical University of Munich, Oct 2017.
[2] Gerasimos Chourdakis, Benjamin Uekermann, Gertjan van Zwieten, and Harald van
Brummelen. Coupling openfoam to different solvers, physics, models, and dimen-
sions using precice. In 14th OpenFOAM Workshop, Duisburg, Germany, Jul 2019.
[3] Gerasimos Chourdakis, Kyle Davis, Benjamin Rodenberg, Miriam Schulte, Fré déric
Simonis, Benjamin Uekermann, Georg Abrams, Hans-Joachim Bungartz, Lucia Che-
ung Yau, Ishaan Desai, Konrad Eder, Richard Hertrich, Florian Lindner, Alexander
Rusch, Dmytro Sashko, David Schneider, Amin Totounferoush, Dominik Volland, Pe-
ter Vollmer, and Oguz Ziya Koseomur. preCICE v2: A sustainable and user-friendly
coupling library. Open Research Europe, 2:51, Apr 2022. doi: 10.12688/openreseurope.
14445.1.
[6] Miguel A. Fernández, Jean-Frédéric Gerbeau, and Saverio Smaldone. Explicit cou-
pling schemes for a fluid-fluid interaction problem arising in hemodynamics. SIAM
Journal on Scientific Computing, 36(6):A2557–A2583, 2014. doi: 10.1137/130948653.
[8] Christopher Greenshields and Henry Weller. Notes on Computational Fluid Dynamics:
General Principles. CFD Direct Ltd, Reading, UK, 2022. URL https://doc.cfd.
direct/notes/cfd-general-principles/.
[9] Leopold Grinberg and George Em. Karniadakis. A scalable domain decomposition
method for ultra-parallel arterial flow simulations. Communications in Computational
Physics, 4(5):1151–1169, 2008.
79
Bibliography
[10] Joel Guerrero. A crash introduction to the finite volume method and discretization
schemes in openfoam®. 15th OpenFOAM Workshop, 2020. URL http://www.
wolfdynamics.com/training/OF_WS2020/traning_session2020.pdf.
[11] Hrvoje Jasak. Handling parallelisation in OpenFOAM. In Cyprus Advanced HPC Work-
shop. FSB Basel, Switzerland, 2012.
[13] OpenCFD Limited. OpenFOAM v2112 programmer’s guide, Dec 2021. https://
sourceforge.net/projects/openfoam/files/v2112/.
[14] Göran Florian Mintgen. Coupling of Shallow and Non-Shallow Flow Solvers – An Open
Source Framework. Dissertation, Technische Universität München, München, 2018.
[15] Marta Camps Santasmasas. Hybrid GPU/CPU Navier-Stokes lattice Boltzmann method
for urban wind flow. The University of Manchester (United Kingdom), 2021.
[17] S.P. Venkateshan. Heat Transfer. Springer International Publishing, 2021. ISBN
9783030583378.
[19] Tom Verstraete and Sebastian Scholl. Stability analysis of partitioned methods for
predicting conjugate heat transfer. International Journal of Heat and Mass Transfer, 101:
852–869, 2016. ISSN 0017-9310. doi: 10.1016/j.ijheatmasstransfer.2016.05.041.
80