implementation of an air-entrainment model in …hani/kurser/os_cfd_2018/siljekreke...of the mules...

46
Cite as: Almeland, S.K.: Implementation of an air-entrainment model in interFoam. In Proceedings of CFD with OpenSource Software, 2018, Edited by Nilsson. H., http://dx.doi.org/10.17196/OS_CFD#YEAR_2018 CFD with OpenSource software A course at Chalmers University of Technology Taught by H˚ akan Nilsson Implementation of an air-entrainment model in interFoam Developed for OpenFOAM-v1806 Test case available at http://dx.doi.org/10.17196/OS_CFD#YEAR_2018 Author: Silje Kreken Almeland Norwegian University of Science and Technology [email protected] Peer reviewed by: Ebrahim Ghahramani Sarmakeeva Anastasi Licensed under CC-BY-NC-SA, Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Licensehttps://creativecommons.org/licenses/ Disclaimer: This is a student project work, done as part of a course where OpenFOAM and some other OpenSource software are introduced to the students. Any reader should be aware that it might not be free of errors. Still, it might be useful for someone who would like learn some details similar to the ones presented in the report and in the accompanying files. The material has gone through a review process. The role of the reviewer is to go through the tutorial and make sure that it works, that it is possible to follow, and to some extent correct the writing. The reviewer has no responsibility for the contents. January 2, 2019

Upload: others

Post on 16-Aug-2020

18 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Cite as: Almeland, S.K.: Implementation of an air-entrainment model in interFoam. In Proceedings of

CFD with OpenSource Software, 2018, Edited by Nilsson. H.,

http://dx.doi.org/10.17196/OS_CFD#YEAR_2018

CFD with OpenSource software

A course at Chalmers University of TechnologyTaught by Hakan Nilsson

Implementation of an air-entrainmentmodel in interFoam

Developed for OpenFOAM-v1806Test case available at

http://dx.doi.org/10.17196/OS_CFD#YEAR_2018

Author:Silje Kreken AlmelandNorwegian University ofScience and [email protected]

Peer reviewed by:Ebrahim GhahramaniSarmakeeva Anastasi

Licensed under CC-BY-NC-SA, Creative Commons Attribution-NonCommercial-ShareAlike 4.0International Licensehttps://creativecommons.org/licenses/

Disclaimer: This is a student project work, done as part of a course where OpenFOAM and someother OpenSource software are introduced to the students. Any reader should be aware that it

might not be free of errors. Still, it might be useful for someone who would like learn some detailssimilar to the ones presented in the report and in the accompanying files. The material has gone

through a review process. The role of the reviewer is to go through the tutorial and make sure thatit works, that it is possible to follow, and to some extent correct the writing. The reviewer has no

responsibility for the contents.

January 2, 2019

Page 2: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Learning outcomes

The reader will learn:

How to use it:

• How to use the implemented solver interAirEntFoam

• How to apply different solution regimes for solving the α-equation

• How to turn on and off the MULES compression

The theory of it:

• The theory of the solution routine used in interFoam

• The theory of the MULES compression

• The theory of the implemented air entrainment model

How it is implemented:

• About the design of the interFoam solver

• How the solution of the α-equation is implemented

How to modify it:

• How to modify the interFoam solver by implementing the described air entrainment model

• How to modify parts of the model that could improve its performance

1

Page 3: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Prerequisites

The reader is expected to know the following in order to get maximum benefit out of this report:

• Have basic knowledge of coputational fluid dynamics and the equations involved

• Be familiar with running and modification of simulation cases in OpenFOAM

• Be familiar with basic use of paraFoam/paraView

2

Page 4: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Contents

1 Introduction 6

2 Theory 72.1 interFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.1.1 Solution algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.1.2 interAirEntFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.1.3 Mass Continuity and buoyancy . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3 Design of interFoam 113.1 Calculation of αl - alphaEqn.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.1.1 Calculation scheme with MULES . . . . . . . . . . . . . . . . . . . . . . . . . 153.1.2 Calculation scheme without MULES . . . . . . . . . . . . . . . . . . . . . . . 18

4 Implementation of interAirEntFoam 204.1 Preparations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.1.1 Make a local copy of interFoam . . . . . . . . . . . . . . . . . . . . . . . . . 204.1.2 Copy immiscibleIncompressibleTwoPhaseMixture . . . . . . . . . . . . . . 22

4.2 Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.2.1 Pt(k, ρ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264.2.2 Pd(LT , k, g, ε) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.2.3 Cair and As . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.2.4 CalcSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.2.5 Adding the source term to the αl-equation . . . . . . . . . . . . . . . . . . . 354.2.6 Write additional fields for visualization . . . . . . . . . . . . . . . . . . . . . . 38

5 Verification cases 415.1 Vertical plunging jet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.2 Possible improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

3

Page 5: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Listings

3.1 Initialization of transport properties in interFoam. Done in createFields.H . . . . 113.2 The correct-function in immiscibleIncompressibleTwoPhaseMixture.C calls func-

tions from the ancestors classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.3 Initialization of the turbulence model, done in createFields.H . . . . . . . . . . . . 123.4 readGravitationalAcceleration.H . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.5 Calculation of φC (in alphaEqn.H) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.6 Calculation of n, done in interfaceProperties.C . . . . . . . . . . . . . . . . . . . 143.7 Default value for MULESCorr set in alphaControls.H . . . . . . . . . . . . . . . . . . 153.8 Calculation of φUDl in alphaEqn.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.9 φHOl and φCl stored in talphaPhi1Un . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.10 Solution of the α-field is done by explicitSolve if MULESCorr is false . . . . . . . 184.1 Copy the interFoam solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.2 Rename folder and file from interFoam to interAirEntFoam . . . . . . . . . . . . . 214.3 Remove folders that are not needed. . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.4 Change the name of the solver within relevant files. . . . . . . . . . . . . . . . . . . . 214.5 Change the name of the executable path . . . . . . . . . . . . . . . . . . . . . . . . . 214.6 The first two lines in Make/options for the new solver. . . . . . . . . . . . . . . . . . 224.7 Search up the location of immiscibleIncompressibleTwoPhaseMixture . . . . . . . 224.8 Copy the transport model immiscibleIncompressibleTwoPhaseMixture . . . . . . 224.9 Rename the transport model – folder and files . . . . . . . . . . . . . . . . . . . . . . 234.10 Rename function calls in files within interFoam . . . . . . . . . . . . . . . . . . . . . 234.11 Change the library path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.12 Give absolute paths in Make/options in airEntrainmentTwoPhaseMixture . . . . . 234.13 Link the solver to the new user library library airEntrainmentTwoPhaseMixture . . 244.14 Remove linking to immiscibleIncompressibleTwoPhaseMixture in Make/options . 244.15 Link the to the new directory, airEntrainmentTwoPhaseMixture, within Make/options 254.16 Introduce rhomix as a private member variable in airEntrainmentTwoPhaseMixture 264.17 Initiate rhomix in the constructor of airEntrainmentTwoPhaseMixture . . . . . . 264.18 Update function for the mixture density . . . . . . . . . . . . . . . . . . . . . . . . . 264.19 Implementation of updateRhomix() . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.20 Test updateRhomix() from createFields.H . . . . . . . . . . . . . . . . . . . . . . 274.21 Introduce the Pt-function to return a volSclarField . . . . . . . . . . . . . . . . . 284.22 Implementation of the Pt-function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.23 Test the Pt-function from createFields.H . . . . . . . . . . . . . . . . . . . . . . . 284.24 Introduce a LT -function to return a volSclarField . . . . . . . . . . . . . . . . . . 294.25 Implementation of the LT -function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.26 Test the LT -function from createFields.H . . . . . . . . . . . . . . . . . . . . . . . 294.27 Add σ and g as private member variables . . . . . . . . . . . . . . . . . . . . . . . . 304.28 Initialization of σ and g in the constructor . . . . . . . . . . . . . . . . . . . . . . . . 304.29 Add Pd as a member function in airEntrainmentTwoPhaseMixture.H . . . . . . . . 314.30 Implementation of the Pd-function in airEntrainmentTwoPhaseMixture.C . . . . . 314.31 Link to meshtools in Make/options . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.32 Test the Pd-function from createFields.H . . . . . . . . . . . . . . . . . . . . . . . 32

4

Page 6: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

LISTINGS LISTINGS

4.33 Add Cair as a private member variable (airEntrainmentTwoPhaseMixture.H) . . . 324.34 Initiate Cair in the constructor (airEntrainmentTwoPhaseMixture.C) . . . . . . . . 334.35 Add calcSource as a member function in airEntrainmentTwoPhaseMixture.H . . . 334.36 Implementation of calcSource in airEntrainmentTwoPhaseMixture.C . . . . . . . 344.37 Create the source term Su in createFields.H . . . . . . . . . . . . . . . . . . . . . . 364.38 Update the source term in alphaSuSp.H . . . . . . . . . . . . . . . . . . . . . . . . . 364.39 Create additional fields for visualization in createFields.H . . . . . . . . . . . . . . 384.40 Calculate additional fields for visualization . . . . . . . . . . . . . . . . . . . . . . . . 39

5

Page 7: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Chapter 1

Introduction

The aim of this tutorial is to show how a sub-grid model to predict the amount of air entrainmentin an air-water system can be implemented based on interFoam. In the framework of a volume offluid model, the intention of the model is to describe a time-averaging solution for air-concentrationvalues attained from self-aeration of the flow. Hirt (2003) modelled air-entrainment with the VOFmethod, by including an additional air volume to cells in which some criteria for air entrainmentwere satisfied. This code is implemented into Flow3D, which is not open source. Therefore, theexact algorithm of this method is not known. Nevertheless, the expression of the source term isgiven. The implementation shown in this tutorial will represent a try on reproducing this model.Possible implementations of this term into interFoam will be discussed. In addition to the model ofHirt (2003) other models have been published in the literature. An aim for this project will be tomake the code general so that it will be easy to use different air entrainment models on this base.

The implemented air entrainment model is developed based on interFoam. Tutorials describinginterFoam has been written by students in the OSCFD course a couple of times before. By HassanHemida in 2008 (Hemida, 2008), describing general use of the solver, and giving a brief explanationof equations that are solved. In 2017 Elin Olsson (Olsson, 2017) described the theory of the VoFmethod. She also explained the concept of the MULES scheme. Nevertheless, the focus of her projectwas on the solver interIsoFoam. Alessandro Manni described the theory and some implementationsof the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also SuryaKaundinya Oruganti (Oruganti, 2015) touched the theory and implementation of MULES whendescribing the implementation of cavitation models in multiphaseEulerFoam.

In this tutorial the intention is to give an overview of the solution algorithm of interFoam, alongwith a description of the design of the solver. Due to the fact that the implementation of the airentrainment model will affect the solution of the α-field, a description of how the α-equation solvedand how the MULES routine is implemented are included. The theory of MULES is briefly described,while the effect of the user variables on the calculation routine are emphasized. Then the theory ofthe implemented air entrainment model is outlined, and its implementation are described. Finally,some verification cases are given, before some comments are added regarding the performance of theimplemented solver.

6

Page 8: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Chapter 2

Theory

When the turbulence is high enough in free-surface flow, air will be entrained in the water phaseand transported with the water flow. The length scales involved in the air entrainment process arein the range of millimeters. This means that a very fine grid is needed to capture these processes.When the grid is not fine enough, the processes at the surface will not be captured, and the amountof air within the water phase will be underestimated. Therfore, to be able to predict the amount ofair entrained into the water flow using a reasonable grid resolution, a subgrid model will be neededto model the dynamics of the air entrainment process.

As described in Section 1 the aim of this tutorial is to describe how to implement the air en-trainment model by Hirt (2003) into the framework of interFoam. In this tutorial the subgridmodel is implemented in a source term, which is added as an explicit source term to the αl equation.This means that the solution routines of interFoam are used for the new solver as well. To getthese implementations into a the relevant context, a brief explanation of the interFoam solver isgiven next, followed by the theory of the air entrainment model. To supplement the description ofinterFoam given in the following section, the interested reader should consult the tutorials referredto in Chapter 1.

2.1 interFoam

Figure 2.1: Illustration of howan interface is considered in theVOF-mothod. The dark area il-lustrates the liquid. The numberin each cell is the scalar functionα that gives the volumetric frac-tion of liquid in each element.The red lines gives the place-ment of the free surface. n de-notes the normal vector for thefree surface in the interface cells(Wikipedia, 2018).

interFoam is a two-phase solver for incompressible, isothermaland immiscible fluids, using the volume of fluid concept to cap-ture the interface. It solves a single set of mass- and momentumequations

∇·u = 0 (2.1)

∂ρu

∂t+∇· (ρuu) = −∇p∗ + g·x∇ρ+∇· τ + f (2.2)

where u is the velocity vector, ρ the density, p∗ a modifiedpressure adopted by removing the hydrostatic- (ρg·x) fromthe total pressure, τ the shear stress tensor, and f the vol-umetric surface tension force. The velocity vector acts as ashared velocity of the two fluids

u = uair = uwater (2.3)

and the interface is captured by solving the advection equation

7

Page 9: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

2.1. INTERFOAM CHAPTER 2. THEORY

∂αl∂t

+∇· (αlu) +∇· [ucαl(1− αl)] = 0 (2.4)

using the MULES scheme, which will be further outlined below. In Equation (2.4) αl is the volumefraction of water, the corresponding volume fraction of air is

αair = 1− αl (2.5)

uc is a relative velocity that acts as a velocity perpendicular to the interface. This term is meant toestimate the relative velocity between the phases, in interFoam only one velocity field is available,and the relative velocity is estimated according to

uc = Cα|u|∇αl|∇αl|

(2.6)

where Cα is a user variable, which determines the effect of the compression term. ∇αl

|∇αl| is meant to

give the unit vector normal to the interface. The interface is localized at the cells where 0 < αl < 1.An illustration of the calulation of the free surface is given in Figure 2.1. In the interface cells, ρand µ are weighted values given by

ρ = αlρl + (1− αl)ρair (2.7a)

µ = αlµl + (1− αl)µair (2.7b)

where ρl, ρair and µl, µair are the density and viscosity in the water and air phase respectively.The volumetric surface tension force is estimated by the Continuum Surface Force model (Brackbill,Kothe, & Zemach, 1992).

f = σκ∇αl (2.8)

where σ is the surface tension and κ is the surface curvature calculated as

κ =∇αl|∇αl|

(2.9)

interFoam can be run both in laminar and turbulent mode. And the turbulence can be solved usingthe Reynolds average (RAS) framework, or based on large eddy simulations (LES).

2.1.1 Solution algorithm

The basic structure of the solution algorithm in interFoam is as follows:

• Initiate fields

• Starting runtime loop

– Calculating time step

– Iterating over the PIMPLE Loop nOuterCorrectors times

∗ Solving the α-equation (VOF and MULES)

∗ Calculate the mixture properties (ρ, α, surface tension)

∗ Solving the momentum equation

∗ PISO Loop over pressure equation

– Calculate the turbulence properties

8

Page 10: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

2.1. INTERFOAM CHAPTER 2. THEORY

The VOF routine could in principle be used to solve all the scales in the air entrainment process in adirect numerical simulation scheme (DNS). However, it would exceed the computational capacitiesin the forseeable future. The problem with interface capturing methods is that they cannot solvethe dynamics with length scales smaller then the grid size, and this has lead to the development ofsubgrid models for air entrainment. The solver interAirEntFoam, implemented in this tutorial, anddescribed in the following section, constitutes an attempt to implement one such subgrid model.

2.1.2 interAirEntFoam

One of the first attempts on calculating the mean flow characteristics and predict the air-entrainmentwith a sub-grid model was introduced in FLOW-3D (Hirt, 2003). In this model air was entrainedinto the water when turbulent energy per unit volume was larger than the stabilizing forces of gravityand surface tension per unit volume. The expression for this source term is given as

δV

δt= CairAs

√2Pt − Pd

ρ(2.10)

where Cair is a calibration parameter, As the free surface area at each cell, ρ is the fluid density,and Pt is expressed by

Pt = ρk (2.11)

and constitute the turbulent forces. Pd represents the stabilizing forces and is expressed by

Pd = ρgnLT +σ

LT(2.12)

where gn is the gravity component normal to the free surface, σ the liquid-gas surface tension, andthe turbulence characteristic length scale LT is calculated according to

LT = Cµ

√3

2

k3/2

ε(2.13)

where Cµ = 0.09 for the standard kε turbulence model. The length scale LT should be taken as anapproximation to a length scale of perturbations. Pd is an expression for the energy density [J/m3]associated with a disturbed fluid element raised over the free surface to a height LT . Pd represents asurface stabilizing force, while the turbulent kinetic energy per unit volume, Pt, represents the per-turbing component that makes the flow unstable. As given in Equation (2.10), when the perturbingforces Pt exceed the stabilizing forces Pd, an air volume according to Equation (2.10) is added tothe cell in question.

2.1.3 Mass Continuity and buoyancy

The original version of the air entrainment model can be applied in different modes, regarding howthe air is added to the equation system. For small amounts of air, the entrained air does not changethe volume density of the liquid. For larger amounts of entrained air, the volume of entrained airis taken into account as an increase in the total fluid (mixture) volume fraction. In this mode theentrained air volume will affect the total fluid mixture density accordingly

ρ = αlρl + αairρair (2.14)

Further buoyancy effects associated with a variable mixture density are also taken into account,and a relative velocity between the phases is computed and also a drift-flux model is introduced.From the available description of this solver, the details of how the additional air is added to thesystem is not clear. One suggestion is that it is added as a source term to the αl equation. Anotherpossibility is that it is added as a source term to an additional advection equation introduced tomodel the advection of the dispersed phase. And a third guess can be that it is added directly to

9

Page 11: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

2.1. INTERFOAM CHAPTER 2. THEORY

the calculation of the density and the fluxes. Nevertheless, in this tutorial the additional air term isadded to the αl equation as an explicit source term. Boundary effects and relative velocity betweenthe phases are given as features in the original model, these effects are not treated in the modelimplemented in this tutorial.

10

Page 12: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Chapter 3

Design of interFoam

The structure of the solution algorithm in interFoam is as given in Section 2.1. Nevertheless, to beable to implement a general solver according to the structure of OpenFOAM, an inspection into thedesign of the solver is needed. The following tasks has to be done by the solver:

• Parsing of input data

• Treatment of the physical phase properties

• Handling of solver variables

• Solution algorithm

The interFoam solver consists of the following main files:

• createFiles.H

• interFoam.C

• pEqn.H

• UEqn.H

• alphaEqn.H

• alphaEqnSubCycle.H

To start the solution procedure, the input parameters have to be read from the input files, andstored in a proper manner. Also the solution variables, and output variables have to be handled.The phase properties and turbulence properties needed in the calculation, are declared and initializedcreateFields.H.

interFoam as an incompressible, immiscible, two-phase model, utilizes a physical phase modelnamed immiscibleIncompressibleTwoPhaseMixture to initialize the transport properties. This isdone in createFiles.H by code line 35

Listing 3.1: Initialization of transport properties in interFoam. Done in createFields.H

34 Info<< "Reading transportProperties\n" << endl;

35 immiscibleIncompressibleTwoPhaseMixture mixture(U, phi);

11

Page 13: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

CHAPTER 3. DESIGN OF INTERFOAM

The model takes care of parsing and updating of the transport properties, like density and vis-cosity, as well as the interface properties, during the calculation procedure of interFoam. immis-cibleIncompressibleTwoPhaseMixture is a virtual subclass of incompressibleTwoPhaseMixture andinterfaceProperties. This means that the functions implemented in immiscibleIncompressibleT-woPhaseMixture only calls functions in the parents classes with the same name, and apart fromthat, no new function implementations are done for this class. For example the correct functionwithin immiscibleIncompressibleTwoPhaseMixture.H (located in $FOAM SRC/transportModels/immiscibleIncompressibleTwoPhaseMixture) calls the respective correct-functions of incom-pressibleTwoPhaseMixture and interfaceProperties as shown in the code listing

Listing 3.2: The correct-function in immiscibleIncompressibleTwoPhaseMixture.C calls functions fromthe ancestors classes.

75 //- Correct the transport and interface properties

76 virtual void correct()

77 {

78 incompressibleTwoPhaseMixture::correct();

79 interfaceProperties::correct();

80 }

This means that the immiscibleIncompressibleTwoPhaseMixture is introduced most probably toreduce the number of function calls within the solver, or only to simplify the structure of the solver.Also the turbulence model is parsed and initialized in createFields.H, accordingly

Listing 3.3: Initialization of the turbulence model, done in createFields.H

74 // Construct incompressible turbulence model

75 autoPtr<incompressible::turbulenceModel> turbulence

76 (

77 incompressible::turbulenceModel::New(U, phi, mixture)

78 );

here it can be seen that the transport model is needed as an argument to create the turbulencemodel. Towards the end of createFields.H the gravitational force is parsed from the input file,and initiated as a variable. This is done within the file readGravitationalAcceleration.H (locatedin $FOAM SRC/finiteVolume/cfdTools/general/include/).

Listing 3.4: readGravitationalAcceleration.H

1 Info<< "\nReading g" << endl;

2 uniformDimensionedVectorField g

3 (

4 IOobject

5 (

6 "g",

7 runTime.constant(),

8 mesh,

9 IOobject::MUST_READ_IF_MODIFIED,

10 IOobject::NO_WRITE

11 )

12

Page 14: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

3.1. CALCULATION OF αL - ALPHAEQN.H CHAPTER 3. DESIGN OF INTERFOAM

12 );

In addition to the phase- and mixture properties, the solver needs some input on the solver vari-ables. The variables that are connected with the behavior of the solution algorithm are given insystem/fvSolution. These variables are parsed by different files depending on their role. For exam-ple the parsing of the parameters releated to the PIMPLE routine is done in pimpleControl.H andvariables related solution of the αl-equation is parsed in alphaControl.H. These files are executedfrom interFoam.C.

When solution variables, phases, and transport- and turbulence models are initiated, the solu-tion algorithm can proceed. interFoam.C contains the solution algorithm as outlined in Section 2.1.UEqn.H calculates the momentum equation, while the pressure field is solved in pEqn.H. The solutionof the αl equation is taken care of by alphaEqn.H and alphaEqnSubCycle.H. In the current imple-mentation of the air entrainment model, a source term is added to the αl-equation, which makes itssolution routine relevant for the implementation of the air entrainment model, interAirEntFoam.The αl-quation is solved using MULES compression. The solution procedure is described in thefollowing section.

3.1 Calculation of αl - alphaEqn.H

The αl field is calculated through

∂αl∂t

+∇ · (αlu) +∇ · [ucαl(1− αl)] = 0 (3.1)

where the last term on the LHS is the compression term.

The solution algorithm in alphaEqn.H solves Equation (3.1) successively using MULES compression.MULES is an iterative implementation of the Flux Corrected Transport technique (FCT), used toguarantee boundedness in the solution of hyperbolic problems. In this technique a corrected fluxFC , which is the weighted solution between the solution obtained with a high- and a low orderdiscretization scheme, is applied

FC = FL + λA = FL + λ(FH − FL) (3.2)

here FL and FH denote the solution of the numerical equation, obtained with a low- and a highorder discretization scheme respectively. A = FH −FL is the anti-diffusive flux, and λ is a weightingfactor that limits the solution within a defined range. In the framework of interFoam, Equation(3.2) is expressed as

φα,l = φUDα,l + φlim,Corrα,l = φUDα,l + θl · φCorrα,l (3.3)

where φUDα,l is the flux calculated by solving the alpha equation (3.1) without the compression term

∂αl∂t

+∇ · (αlu) = 0 (3.4)

using the first order upwind discretization scheme for the convective term. And

φlim,Corrα,l = θl · φCorrα,l (3.5)

where θl is a weighting factor that limits the solutions within given maximum and minimum values.Further the corrected flux

φCorrα,l = φHOα,l + φCα,l − φUDα,l (3.6)

where φHOα,l is the higher order solution of Equation (3.4), and φCα,l is the correction flux calculated

as a compression term. The first two terms in Equation (3.6), φHOα,l + φCα,l, can be recognized as FH

13

Page 15: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

3.1. CALCULATION OF αL - ALPHAEQN.H CHAPTER 3. DESIGN OF INTERFOAM

in Equation (3.2), while φUDα,l can be identified as FL. As implemented in interFoam, φHOα,l is in factthe solution of Equation (3.4) calculated using the discretization scheme for α given by the user,which is not necessarily of higher order. This means that a more proper notation of this flux will be

φHOα,l = φdiv(phi,alpha)α,l (3.7)

where the superscript div(phi,alpha) denotes the discretization scheme given for div(phi,alpha)in the divSchemes directory in the system/fvSchemes input file.

In the source code (alphaEqn.H, located at $FOAM SOLVERS/multiphase/VoF/) the correctionflux, φCα,l, is denoted phir and written as

Listing 3.5: Calculation of φC (in alphaEqn.H)

58 // Standard face-flux compression coefficient

59 surfaceScalarField phic(mixture.cAlpha()*mag(phi/mesh.magSf()));

154 surfaceScalarField phir(phic*mixture.nHatf());

or in a more readable form:

φC = Cαφ

|Sf |· n = Cα

linearInterpolate(U) & Sf|Sf |

· n = CαuTSf|Sf |

· n (3.8)

where Sf is the face area vector, φc is the compression flux, Cα is a user defined parameter, availablethrough cAlpha in the input file system/fvSolution, and n is the interface normal flux

n =∇αl

|∇αl|+ 10−8

V13

· Sf (3.9)

were ∇αl is the gradient of αl and V is the cell volume. As evident from the notation in the listingsabove, n is calculated within the transport model. For the immiscibleIncompressibleTwoPhaseMix-ture-model this is done within interfaceProperties.C. The relevant code lines are shown in thelisting below

Listing 3.6: Calculation of n, done in interfaceProperties.C

109 // Cell gradient of alpha

110 const volVectorField gradAlpha(fvc::grad(alpha1_, "nHat"));

111

112 // Interpolated face-gradient of alpha

113 surfaceVectorField gradAlphaf(fvc::interpolate(gradAlpha));

119 // Face unit interface normal

120 surfaceVectorField nHatfv(gradAlphaf/(mag(gradAlphaf) + deltaN_));

128 // Face unit interface normal flux

129 nHatf_ = nHatfv & Sf;

14

Page 16: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

3.1. CALCULATION OF αL - ALPHAEQN.H CHAPTER 3. DESIGN OF INTERFOAM

168 deltaN_

169 (

170 "deltaN",

171 1e-8/pow(average(alpha1.mesh().V()), 1.0/3.0)

172 ),

The calculation of the αl fluxes in interFoam is, as mentioned, done successively resulting influxes given by Equation (3.3), (3.5)-(3.6). Written in a more compact form

φα,l = φUDα,l + θl(φHOα,l + φCα,l − φUDα,l ) (3.10)

Nevertheless, different user settings (supplied in system/fvSolutions) make Equation (3.10) lookdifferent. The parameters that decides on the solutions procedure of the αl-equation, are found in thedirectory solvers and alpha.water in system/fvSolution. There is several parameters affectingthe solution of the αl field, the most important regarding the solution procedure, being MULESCorr

and cAlpha. Different combinations of values for these parameter will change the form of Equation(3.10). Through these parameters it is possible to turn on and off the MULES compression, andalso to decide on the the extent of the effects of the compression term. How these parameters canbe set to achieve different behavior for the solution procedure will be given in the following sections.

3.1.1 Calculation scheme with MULES

In alphaEqn.H two different solution paths are executed depending on the values given for MULESCorr.The MULES-correction path is executed as long as MULESCorr is set to true, and the explicitSolvepath is executed if MULESCorr is false. By default MULESCorr is set to false, this is done inalphaControls.H located in $FOAM SRC/finiteVolume/cfdTools/general/include/

Listing 3.7: Default value for MULESCorr set in alphaControls.H

7 bool MULESCorr(alphaControls.lookupOrDefault("MULESCorr", false));

This means that as long as one do not set MULESCorr in system/fvSolution, MULES-correction isnot applied. To apply MULES correction, the user parameter MULESCorr has to be set to true oryes. In this section the possible variants within the MULES-correction path are investigated.

Using the MULES algorithm, the fluxes of αl is calculated according to Equation (3.10)

φα,l = φUDα,l + θl(φHOα,l + φCα,l − φUDα,l )

first the uncompressed αl equation (3.4) is solved by the upwind scheme

Listing 3.8: Calculation of φUDl in alphaEqn.H

99 if (MULESCorr)

100 {

101 #include "alphaSuSp.H"

102

103 fvScalarMatrix alpha1Eqn

104 (

105 (

106 LTS

107 ? fv::localEulerDdtScheme<scalar>(mesh).fvmDdt(alpha1)

108 : fv::EulerDdtScheme<scalar>(mesh).fvmDdt(alpha1)

15

Page 17: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

3.1. CALCULATION OF αL - ALPHAEQN.H CHAPTER 3. DESIGN OF INTERFOAM

109 )

110 + fv::gaussConvectionScheme<scalar>

111 (

112 mesh,

113 phiCN,

114 upwind<scalar>(mesh, phiCN)

115 ).fvmDiv(phiCN, alpha1)

116 // - fvm::Sp(fvc::ddt(dimensionedScalar("1", dimless, 1), mesh)

117 // + fvc::div(phiCN), alpha1)

118 ==

119 Su + fvm::Sp(Sp + divU, alpha1)

120 );

121

122 alpha1Eqn.solve();

resulting in an upwind flux φUDl . In the source code the calculated upwind flux is stored in thevariable alphaPhi10

130 tmp<surfaceScalarField> talphaPhi1UD(alpha1Eqn.flux());

131 alphaPhi10 = talphaPhi1UD();

After solving the αl field by the upwind scheme, the αg-field is updated

144 alpha2 = 1.0 - alpha1;

and the transport models are updated by a function call

146 mixture.correct();

Next the higher order fluxes and the correction fluxes are stored in talphaPhi1Un

Listing 3.9: φHOl and φC

l stored in talphaPhi1Un

156 tmp<surfaceScalarField> talphaPhi1Un

157 (

158 fvc::flux

159 (

160 phiCN(),

161 cnCoeff*alpha1 + (1.0 - cnCoeff)*alpha1.oldTime(),

162 alphaScheme

163 )

164 + fvc::flux

165 (

166 -fvc::flux(-phir, alpha2, alpharScheme),

167 alpha1,

16

Page 18: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

3.1. CALCULATION OF αL - ALPHAEQN.H CHAPTER 3. DESIGN OF INTERFOAM

168 alpharScheme

169 )

170 );

Then we have the following situation before entering the MULESCorr-loop at line 172

alphaPhi10 = φUDl

talphaPhi1Un = φHOl + φCl(3.11)

The MULESCorr-loop starts by calculating

talphaPhi1Corr = φHOl + φCl − φUDl (3.12)

which in the source code looks like

174 tmp<surfaceScalarField> talphaPhi1Corr(talphaPhi1Un() - alphaPhi10);

this resemble the A in Equation (3.2) and φCorrα,l in Equation (3.5). The calculation of the correction

flux, φC , was given in Equation (3.8) as

φC = CαuTSf|Sf |

· n

where Cα equals the user variable cAlpha given in system/fvSolution. According to this expres-sion, the correction flux φC equals zero if cAlpha is set to zero by the user. In this situation φCorrα,l

(Equation 3.6) will look like

φCorrα,l = φHOα,l − φUDα,l (3.13)

where φHOα,l is the user chosen discretization scheme given for αl

φHOα,l = φdiv(phi,alpha)α,l

which can be chosen as the upwind scheme

φdiv(phi,alpha)α,l = φUDα,l

if this is the case, the correction flux φCorrα,l will be zero, and Equation (3.10) will be expressed by

φα,l = φUDα,l (3.14)

To summarize, a simple upwind solution of the uncompressed αl-equation can be obtained by settingMULESCorr to true and cAlpha to 0, while the upwind discretization scheme is chosen for αl. Forevery other discretization scheme, the α-fluxes will be equal to

φα,l = φUDα,l + θ · φCorrα,l

If cAlpha is set to 0, φCα,l will be zero, and φCorrα,l is expressed by Equation (3.13).

Next the αl-equation (3.1) is solved by MULES::correct(...) as

17

Page 19: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

3.1. CALCULATION OF αL - ALPHAEQN.H CHAPTER 3. DESIGN OF INTERFOAM

∂αl∂t

+∇ · (αlu) = Spαnl + Su =⇒ αnl − α0

l

δt+ psiIf = Spα

nl + Su =⇒ αnl =

α0l

δt + Su − psiIf1δt − Sp

(3.15)This calculation are found in CMULESTemplates.C. In Equation (3.15) Su = −Spαl, which meansthat in fact no source term is added to the equation. Probably this is a trick done to ease thenumerical solution of the equation. The terms Su and Sp in this equation are to be set in thealphaSuSp.H-file, and is set to zeroFields by default.

The argument values which are changed in MULES::correct(...) are φ = talphaPhi1Corr andα = αUDl . The solution is limited according to the FCT method. talphaPhi1Corr is limited in(3.5). phiIf in the routine is intergrated from phiCorr (CMULESTemplates.C)

52 fvc::surfaceIntegrate(psiIf, phiCorr);

where phiCorr is the limited version of the input variable talphaPhi1Corr (ref. Equation (3.5)).

3.1.2 Calculation scheme without MULES

The MULES compression, that are included to make the interface sharp, is deactivated by default,and can be adjusted by setting MULESCorr to true/false in system/fvSolution. In this sectionwe will inspect the solution algorithm applied when MULESCorr is set to false.

If MULESCorr is set to false and cAlpha 6= 0, then φα,l is calculated as

φα,l = θl · φCorrα,l = θl · (φHOα,l + φCα,l) = θl · (φdiv(phi,alpha)α,l + φCα,l) (3.16)

this means that the FCT procedure given in Equation (3.2) is not followed. Nevertheless, thecompression term φCα,l is still included, and the solution is limited. In the source code this is writtenas (in alphaEqn.H)

Listing 3.10: Solution of the α-field is done by explicitSolve if MULESCorr is false

202 alphaPhi10 = talphaPhi1Un;

203

204 MULES::explicitSolve

205 (

206 geometricOneField(),

207 alpha1,

208 phiCN,

209 alphaPhi10,

210 Sp,

211 (Su + divU*min(alpha1(), scalar(1)))(),

212 1,

213 0

214 );

where talphaPhi1Un can be recognized from Equation (3.11)

talphaPhi1Un = φHOl + φCl

18

Page 20: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

3.1. CALCULATION OF αL - ALPHAEQN.H CHAPTER 3. DESIGN OF INTERFOAM

If cAlpha is set to 0, φCα,l will be 0, and φα,l equals

φα,l = θ · φHOα,l = θ · φdiv(phi,alpha)α,l (3.17)

which means that the fluxes applied for the αl-field, are the fluxes obtained from a higher order(user chosen div(phi,alpha) scheme) solution of the uncompressed αl equation (3.4).

When MULESCorr is set to false the routine MULES::explicitSolve is used for solving the alphafield. This routine is implemented in MULESTemplates.C and solves the αl equation according to

∂αl∂t

+∇ · (αlu) = Spαnl + Su =⇒ αnl − α0

l

δt+ psiIf = Spα

nl + Su =⇒ αnl =

α0l

δt + Su − psiIf1δt − Sp

(3.18)where Su = Su,input + divU · αl. Here Su,input is the Su-term which is supposed to be given inalphaSuSp.H and is set to a zero-field by default. divU is also to be set in alphaSuSp.H and is azero field by default. psiIf is the net flux, which is integrated from phiPsi (MULESTemplates.C)

55 fvc::surfaceIntegrate(psiIf, phiPsi);

where phiPsi is the limited version of the input variable talphaPhi1Un (ref. Equation (3.5)). Thesolution of αl is limited between 0 and 1.

19

Page 21: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Chapter 4

Implementation of interAirEntFoam

The implementation of the air entrainment model starts by copying the interFoam solver, changeits name to interAirEntFoam, and rename its files and functions accordingly. As described inChapter 3, interFoam uses a class named immiscibleIncompressibleTwoPhaseMixture to han-dle the transport properties. This class takes care of the reading and calculation of the transportproperties and phase properties, like phase fraction, density and viscosity, as well as the interfaceproperties. These properties are also desired to be incorporated within the corresponding trans-port model to be used for the air entraintrainment model. This means that we start by copyingimmiscibleIncompressibleTwoPhaseMixture and change its name to airEntrainmentTwoPhaseMix-ture. In addition to the features of immiscibleIncompressibleTwoPhaseMixture, the new classshould calculate a source term of air, and decide on whether air should be added to the water phaseor not. This calculation is based on Equation (2.10). According to Section 2.1.2, our air-entrainmentmodel requires the knowledge of:

• where the surface is located

• the normal of the surface

• the surface tension

• turbulence variable (k and ε)

• Mesh properties

– Cell volume needed to divide the source term by its cell volume (ref. Equation (2.10)).

– Information about cell size also needed to calculate the variable As in Equation (2.10).

This section will provide the steps in the implementation of the air entrainment model named,interAirEntFoam. The starting point is to make a local copy of interFoam.

4.1 Preparations

4.1.1 Make a local copy of interFoam

Start by copying the interFoam solver from the OpenFOAM installation as

Listing 4.1: Copy the interFoam solver

20

Page 22: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.1. PREPARATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

cd $WM_PROJECT_USER_DIRmkdir -p applications/solvers/multiphase

cd !$cp -r $FOAM_SOLVERS/multiphase/interFoam .

Rename the solver and the files to interAirEntFoam

Listing 4.2: Rename folder and file from interFoam to interAirEntFoam

mv interFoam interAirEntFoam

cd !$mv interFoam.C interAirEntFoam.C

and remove folders that are not needed

Listing 4.3: Remove folders that are not needed.

rm -r interMixingFoam overInterDyMFoam

Rename within the files

Listing 4.4: Change the name of the solver within relevant files.

sed -i s/interFoam/interAirEntFoam/g Make/files

sed -i s/interFoam/interAirEntFoam/g interAirEntFoam.C

Then you have to change the name of the excutable path to the user bin. This is done by runningthe following sed-command on the files as

Listing 4.5: Change the name of the executable path

sed -i s/APPBIN/USER_APPBIN/g Make/files

21

Page 23: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.1. PREPARATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

Then you have to update the Make/options file, to include the desired libraries. In the Make/optionsfile, copied from the interFoam solver, it is linked to the VoF-directory by a relative path. Changethis to the absolute path. Open the Make/options-file by your favorite editor as

emacs Make/options

and change the second line to accordingly

Listing 4.6: The first two lines in Make/options for the new solver.

1 EXE_INC = \

2 -I$(FOAM_SOLVERS)/multiphase/VoF \

by this you link to the volume of fluid solver within the foam solvers path. At this point you havea local version of the interFoam solver. Try to compile it to see that everything works as intended

wmake

4.1.2 Copy immiscibleIncompressibleTwoPhaseMixture

As noted several times interFoam uses the immiscibleIncompressibleTwoPhaseMixture class to cal-culate the transport properties. This transport model is not located within the interFoam solver,but since we want to use this model, and change it for our purpose, we need to copy the model fromwhere it is located and place it in our new solver. Start by a call to find the location of the model as

Listing 4.7: Search up the location of immiscibleIncompressibleTwoPhaseMixture

find $WM_PROJECT_DIR -name immiscibleIncompressibleTwoPhaseMixture

and copy the output from this search into the terminal window as

Listing 4.8: Copy the transport model immiscibleIncompressibleTwoPhaseMixture

cp -r $FOAM_SRC/transportModels/immiscibleIncompressibleTwoPhaseMixture .

22

Page 24: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.1. PREPARATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

Rename the transportmodel – folder and files as

Listing 4.9: Rename the transport model – folder and files

mv immiscibleIncompressibleTwoPhaseMixture airEntrainmentTwoPhaseMixture

cd airEntrainmentTwoPhaseMixture

mv immiscibleIncompressibleTwoPhaseMixture.C airEntrainmentTwoPhaseMixture.C

mv immiscibleIncompressibleTwoPhaseMixture.H airEntrainmentTwoPhaseMixture.H

sed -i s/immiscibleIncompressible/airEntrainment/g Make/files

sed -i s/immiscibleIncompressible/airEntrainment/g airEntrainmentTwoPhaseMixture.*

And rename in the solver to call the new library

Listing 4.10: Rename function calls in files within interFoam

cd ..

sed -i s/immiscibleIncompressible/airEntrainment/g createFields.H

sed -i s/immiscibleIncompressible/airEntrainment/g interAirEntFoam.C

At this point you have a local version of the immiscibleIncompressibleTwoPhaseMixture namedairEntrainmentTwoPhaseMixture. This model is a library, which you want to compile to the userlibraries. Change the name of the library path in Make/files accordingly

Listing 4.11: Change the library path

sed -i s/LIBBIN/USER_LIBBIN/g airEntrainmentTwoPhaseMixture/Make/files

The Make/options copied from immiscibleIncompressibleTwoPhaseMixture, contains some rel-ative paths, which have to be changed to absolute paths. Open the file in your favorite editoras

emacs airEntrainmentTwoPhaseMixture/Make/options

and change the first five lines as

Listing 4.12: Give absolute paths in Make/options in airEntrainmentTwoPhaseMixture

23

Page 25: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.1. PREPARATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

1 EXE_INC = \

2 -I$(LIB_SRC)/transportModels \

3 -I$(LIB_SRC)/transportModels/incompressible/lnInclude \

4 -I$(LIB_SRC)/transportModels/interfaceProperties/lnInclude \

5 -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \

6 -I$(LIB_SRC)/finiteVolume/lnInclude

Then your new library, airEntrainmentTwoPhaseMixture, which at this point is a local version ofimmiscibleIncompressibleTwoPhaseMixture, should be ready to use. Compile it to ensure thatthe name changes and linking has been correctly done

wmake airEntrainmentTwoPhaseMixture

When this compiles with no error messages, you are ready to proceed. Now you want your newsolver interAirEntFoam to use the new library. Then you have to link to it in the Make/options

file within the solver. Open the file in your favorite editor as

emacs Make/options

and do this by adding the following lines at the end of your Make/options file

Listing 4.13: Link the solver to the new user library library airEntrainmentTwoPhaseMixture

25 -L$(FOAM_USER_LIBBIN) \

26 -lairEntrainmentTwoPhaseMixture

also remember to add a backslash to the line that used to be the last line, since it is no longer thelast line in the file. Since you no longer make use of immiscibleIncompressibleTwoPhaseMixture,the linking to this library can be removed in the Make/options file as

Listing 4.14: Remove linking to immiscibleIncompressibleTwoPhaseMixture in Make/options

sed -i '/immisc/d' Make/options

Then a link to the new directory has to be linked to under EXE INC. Open the Make/options file inyour favorite editor

24

Page 26: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

emacs Make/options

and add a new line as

Listing 4.15: Link the to the new directory, airEntrainmentTwoPhaseMixture, within Make/options

2 -IairEntrainmentTwoPhaseMixture \

Then the linking should be in place and you can compile both your library and your solver toensure that it works. Make sure that you are placed in the interAirEntFoam directory, and run thecompiling commands as

wmake airEntrainmentTwoPhaseMixture

wmake

When both the library and the solver compiles, you should copy the damBreak tutorial, and run itwith your new solver as

cp -r $FOAM_TUTORIALS/multiphase/interFoam/RAS/damBreak/damBreak $FOAM_RUNrun

cd damBreak

sed -i s/interFoam/interAirEntFoam/g system/controlDict

./Allrun

when this works, you are ready to start to do the implementations.

4.2 Implementations

The aim of the solver is to calculate and return the output of Equation (2.10). This term is afunction of several terms

δV

δt= f(Pt(k, ρ), Pd(LT , k, g, ε), ρ, Cair, As) (4.1)

The air entrainment model will be implemented within airEntrainmentTwoPhaseMixture

(airEntrainmentTwoPhaseMixture.H, airEntrainmentTwoPhaseMixture.C), which at this pointis a local copy of immiscibleIncompressibleTwoPhaseMixture. We start by calculating the per-turbing forces Pt(k, ρ) according to Equation (2.11).

25

Page 27: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

4.2.1 Pt(k, ρ)

This variable is calculated as a function of k, and ρmix. The densities are available in ourairEntrainmentTwoPhaseMixture model through the incompressibleTwoPhaseMixture class.Nevertheless, we want to calculate a density for the mixture, we do this by introducing a pri-vate member variable in airEntrainmentTwoPhaseMixture. Go to the interAirEntFoam folderand open airEntrainmentTwoPhaseMixture.H in your favorite editor as

ufoam

cd applications/solvers/multiphase/interAirEntFoam

emacs airEntrainmentTwoPhaseMixture/airEntrainmentTwoPhaseMixture.H

and introduce rhomix as a private member variable in the class airEntrainmentTwoPhaseMixtureby introducing the following lines in airEntrainmentTwoPhaseMixture.H

Listing 4.16: Introduce rhomix as a private member variable in airEntrainmentTwoPhaseMixture

57 // Private data

58 volScalarField rhomix_;

we initiate rhomix in the constructor (in airEntrainmentTwoPhaseMixture.C). Let the initializa-tion of rhomix follow after the initialization of interfaceProperties as

Listing 4.17: Initiate rhomix in the constructor of airEntrainmentTwoPhaseMixture

39 interfaceProperties(alpha1(), U, *this),

40

41 rhomix_

42 (

43 min(max(alpha1(), scalar(0)), scalar(1))*rho1_ +

44 (scalar(1) - min(max(alpha1(), scalar(0)), scalar(1)))*rho2_

45 )

and remember to add a comma after the call to interfaceProperties, since this is no longerthe last command in the constructor. The mixture density should be updated each time wecall the source term from the solver. That means that an update function is needed for thisdensity. We implement this as a public member function in our class. Open the header fileairEntrainmentTwoPhaseMixture.H, and implement the update function as

Listing 4.18: Update function for the mixture density

85 //- Update the mixture density

86 void updateRhomix();

We implement the function in airEntrainmentTwoPhaseMixture.C as

26

Page 28: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

Listing 4.19: Implementation of updateRhomix()

59 void Foam::airEntrainmentTwoPhaseMixture::updateRhomix()

60 {

61 rhomix_ = min(max(alpha1(), scalar(0)), scalar(1))*rho1_ +

62 (scalar(1) - min(max(alpha1(), scalar(0)), scalar(1)))*rho2_;

63 }

From the solver directory, compile the library and the solver to check if it works

wmake airEntrainmentTwoPhaseMixture

wmake

To check that our new function works we try to call it from one of the files within the solver, we dothis in createFields.H. Open the file in your favorite editor

emacs createFields.H

and call updateRhomix() after the initiation of the transport model as

Listing 4.20: Test updateRhomix() from createFields.H

37 mixture.updateRhomix();

Then recompile the solver to check that it works

wmake

Run the damBreak tutorial case again as

interAirEntFoam -case $FOAM_RUN/damBreak

When this works, we proceed to the implementation of Pt(ρ, k). As Pt is a function of the total kinetic

27

Page 29: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

energy k, it needs the knowledge of this variable. Our class airEntrainmentTwoPhaseMixture doesnot know about the turbulence variables. A simple (but perhaps not very elegant) way to attain theknowledge of k, is to pass it as an argument to a function. We put the following in the header file(airEntrainmentTwoPhaseMixture.H)

Listing 4.21: Introduce the Pt-function to return a volSclarField

87 // Calculates the pertubing component that makes the flow unstable and

88 // returnes a volumScalarField

89 volScalarField Pt(const volScalarField k);

which means that we implement a public member function that returns a volScalarField. Weplace the implementation of the function in the .C-file as

Listing 4.22: Implementation of the Pt-function

65 Foam::volScalarField Foam::airEntrainmentTwoPhaseMixture::Pt(const

66 volScalarField k)

67 {

68 updateRhomix();

69 volScalarField Pt = k*rhomix_;

70 return Pt;

71 }

Again, make a function call to your function from createFields.H to check whether the functionworks. Since this function use k as an argument, the function call should be made after the initiationof the turbulence model. Open the file in your favorite editor

emacs createFields.H

and call the Pt-function as

Listing 4.23: Test the Pt-function from createFields.H

82 mixture.Pt(turbulence->k());

Then recompile the solver to check that it works

wmake airEntrainmentTwoPhaseMixture

wmake

28

Page 30: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

and by running the damBreak tutorial case again

interAirEntFoam -case $FOAM_RUN/damBreak

Then we proceed to the implementation of Pd(LT , k, g, ε).

4.2.2 Pd(LT , k, g, ε)

Since Pd is a function of the characteristic length, LT (Cµ, k, ε), it is convenient to start by im-plementing the function to calculate LT . We implement this as a member function in our class(airEntrainmentTwoPhaseMixture), returning a volScalarField, similar to what was done forPt. Paste the following in your header file (airEntrainmentTwoPhaseMixture.H)

Listing 4.24: Introduce a LT -function to return a volSclarField

90 // Calculates Lt (the characteristic turbulent length scale)

91 volScalarField Lt(

92 const volScalarField k,

93 const volScalarField epsilon

94 );

We add the function implementation in the .C-file accordingly

Listing 4.25: Implementation of the LT -function

73 Foam::volScalarField Foam::airEntrainmentTwoPhaseMixture::Lt(

74 const volScalarField k,

75 const volScalarField epsilon)

76 {

77 dimensionedScalar dimCorr("dimCorr",dimLength/dimTime,1);

78 volScalarField newepsilon = epsilon +

79 dimensionedScalar("smallEpsilon",dimensionSet(0,2,-3,0,0,0,0),1e-10);

80 // dimensions did not follow the meth operations -> dimCorr

81 volScalarField Lt = 0.09*sqr(1.5)*pow(k,3/2)/newepsilon*dimCorr;

82 return Lt;

83 }

Again, add a function call in createFields.H to test the function

Listing 4.26: Test the LT -function from createFields.H

83 mixture.Lt(turbulence->k(), turbulence->epsilon());

Again, it should be noted that this function call has to be executed after the initialization of the

29

Page 31: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

turbulence model. Then compile airEntrainmentTwoPhaseMixture, interAirEntFoam, and run thedamBreak case to test the solver.

wmake airEntrainmentTwoPhaseMixture

wmake

interAirEntFoam -case $FOAM_RUN/damBreak

Then we can continue implementing the surface stabilizing term Pd(LT , σ, g). In addition to LT , thisvariable is a function of surface tension σ and gravity g. These variables are not directly available inout airEntrainmentTwoPhaseMixture model, but they can be read from the input files. These vari-ables will be constant for a simulation, as long as they are not altered by the user. This means thatit make sense to add them as private member variables in our airEntrainmentTwoPhaseMixture

class. Add the following to airEntrainmentTwoPhaseMixture.H

Listing 4.27: Add σ and g as private member variables

59 const dimensionedScalar sigma_;

60 uniformDimensionedVectorField g_;

Here we introduce a new variable type, which means that the following must be added to the headerfile

40 #include "uniformDimensionedFields.H"

we initiate the variables in the constructor of the class (in airEntrainmentTwoPhaseMixture.C)

Listing 4.28: Initialization of σ and g in the constructor

47 sigma_

48 (

49 "sigma", dimensionSet(1,0,-2,0,0,0,0), lookup("sigma")

50 ),

51

52 g_(

53 IOobject

54 (

55 "g",

56 U.time().constant(),

57 U.mesh(),

58 IOobject::MUST_READ_IF_MODIFIED,

59 IOobject::NO_WRITE

60 )

61 )

30

Page 32: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

and remember to add a comma before this implementation. As private member variables σ and gwill be available for the member functions of the solver. Compile the model to check whether itworks

wmake airEntrainmentTwoPhaseMixture

when this works, we should be ready to start on the implementation of Pd. We declare the functionaccordingly in the header file as

Listing 4.29: Add Pd as a member function in airEntrainmentTwoPhaseMixture.H

98 // Calculates the stabilizing surface force Pd

99 volScalarField Pd(

100 const volScalarField k,

101 const volScalarField epsilon

102 );

and implement it in the .C-file as

Listing 4.30: Implementation of the Pd-function in airEntrainmentTwoPhaseMixture.C

101 Foam::volScalarField Foam::airEntrainmentTwoPhaseMixture::Pd(

102 const volScalarField k,

103 const volScalarField epsilon)

104 {

105 // Calculate surface normal

106 // Cell gradient of alpha

107 const volVectorField gradAlpha(fvc::grad(alpha1(), "nHat"));

108 // Unit interface normal

109 volVectorField nHat(gradAlpha/(mag(gradAlpha) + deltaN()));

110 // Gravitation forces normal to surface

111 volScalarField gn = g_ & nHat;

112 volScalarField lLt = Lt(k,epsilon);

113 // Calculates the stabilizing surface force Pd

114 updateRhomix();

115 volScalarField Pd = rhomix_*mag(gn)*lLt + sigma_/lLt;

116 return Pd;

117 }

At line 107 this function make use of the namespace fvc, which is not declared within this scope.Include the fvCFD.H in airEntrainmentTwoPhaseMixture.H to fix this

41 #include "fvCFD.H"

31

Page 33: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

and link to meshTools in airEntrainmentTwoPhaseMixture/Make/options as

Listing 4.31: Link to meshtools in Make/options

6 -I$(LIB_SRC)/meshTools/lnInclude \

14 -lmeshTools \

Test the new function by adding a function call in createFields.H

Listing 4.32: Test the Pd-function from createFields.H

84 mixture.Pd(turbulence->k(), turbulence->epsilon());

Compile the library, the solver, and run the damBreak case again

wmake airEntrainmentTwoPhaseMixture

wmake

interAirEntFoam -case $FOAM_RUN/damBreak

Then we are approaching the aim of calculating the source term δVδt = f(Cair, As, Pt, Pd, ρ) as

given in Equation (2.10). The remaining tasks are to make Cair and As available to our class(airEntrainmentTwoPhaseMixture), and then to implement a function to calculate a source termfor the air entrainment.

4.2.3 Cair and As

Cair is supposed to be given as a tuning variable available for the user. Then this variable couldbe added, both to the input files, and to our model, in a similar manner as σ. We add it in theconstant/transportProperties file in the damBreak case as

35 Cair 0.5;

Then we add it as a private member variable in our class airEntrainmentTwoPhaseMixture as

Listing 4.33: Add Cair as a private member variable (airEntrainmentTwoPhaseMixture.H)

62 const dimensionedScalar Cair_;

and initiate it in the constructor

32

Page 34: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

Listing 4.34: Initiate Cair in the constructor (airEntrainmentTwoPhaseMixture.C)

51 Cair_

52 (

53 "Cair", dimensionSet(0,0,0,0,0,0,0), lookup("Cair")

54 ),

Compile the library, the solver, and run the damBreak case again

wmake airEntrainmentTwoPhaseMixture

wmake

interAirEntFoam -case $FOAM_RUN/damBreak

As should represent the free surface area in an interface cell. This could be calculated, or at leastestimated based on the gradients of the αl field. Nevertheless, in this model, this calculation wassimplified to be estimated based on the cell volume as

// Estimate cell surface area as V^(2/3)

forAll(Afs, cellI)

{

Afs[cellI] = pow(U.mesh().V()[cellI],0.67);

}

The solver interIsoFoam uses isosurfaces to capture the interface. Perhaps a method for a propercalculation of As can be found from this solver.

4.2.4 CalcSource

Then we are ready to implement our final function that will return an estimate of the amount ofair that should be added to a cell. The source term should only be active at the interface. Thismeans that the model needs to know where the interface is located. A function nearInterface(),which returns a volScalarField, is available in our model (inherited from interfaceProperties).We try to make use of this function to notify the placement of the interface. Our end goal forthe airEntrainmentTwoPhaseMixture model is that it will provide a source term that can beadded as an explicit source term to the αl-equation. We declare the function calcSource() inthe airEntrainmentTwoPhaseMixture.H-file as

Listing 4.35: Add calcSource as a member function in airEntrainmentTwoPhaseMixture.H

105 //- Calculates source term, returned as volum fraction rate

106 // void calcSource(

107 volScalarField calcSource(

108 const volVectorField& U,

109 const volScalarField k,

110 const volScalarField epsilon

111 );

33

Page 35: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

Since we are going to add the source term to the αl-equation, we have to add the volume as avolume fraction relative to the relevant cell. Then this function needs the knowledge of the cellvolume, which is a reason for providing U as a function argument here. Nevertheless, since U isalready an input to the constructor, and the cell volume do not change for this solver, a bettersolution might have been to add U as a member variable to the class. However, we proceed toimplement the function in the .C-file as

Listing 4.36: Implementation of calcSource in airEntrainmentTwoPhaseMixture.C

122 Foam::volScalarField Foam::airEntrainmentTwoPhaseMixture::calcSource(

123 const volVectorField& U,

124 const volScalarField k,

125 const volScalarField epsilon)

126 {

127 Info << "calcSource" << endl;

128 // Initialize the volume fraction rate term, as 0 or 1 for on

129 // interface or not

130 volScalarField dvdt(nearInterface());

131 volScalarField Afs(dvdt);

132 // Estimate cell surface area as V^(2/3), to be calc with isosurfaces

133 // later

134 forAll(Afs, cellI)

135 {

136 Afs[cellI] = pow(U.mesh().V()[cellI],0.67);

137 }

138 volScalarField Pdl = Pd(k,epsilon);

139 volScalarField Ptl = Pt(k);

140 updateRhomix();

141 // Calculate the volume fraction rate term

142 forAll(dvdt, cellI)

143 {

144 if((Ptl[cellI] > Pdl[cellI])){

145 scalar air2cell = dvdt[cellI]*Cair_.value()*Afs[cellI]*

146 sqr(2*(Ptl[cellI]-Pdl[cellI])/rhomix_[cellI])

147 /U.mesh().V()[cellI];

148 dvdt[cellI] = -min(air2cell,0.5);

149 }else{

150 dvdt[cellI] = scalar(0.0);

151 }

152 }

153 forAll(dvdt.boundaryField(), patchI)

154 {

155 forAll(dvdt.boundaryField()[patchI], faceI )

156 {

157 dvdt.boundaryFieldRef()[patchI][faceI] = scalar(0.0);

158 }

159 }

160 dimensionedScalar dimCorr("dimCorr",dimVelocity/dimLength,1);

161 return dvdt*dimCorr;

162 }

34

Page 36: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

The formulation for the source term given in 2.10 gives the volume of air to be added to a cell. Inour solver, it is the water fraction that is calculated in the αl-equation. This means that the amountcalculated has to be subtracted from the αl-equation. This is taken care of in the calculation of thesource term above. Also the possible amount of air should be restricted according to the relevant cellvolume. This is done by line 148 in the listing above. The volume of the source term is restrictedto half of the cell volume, which is more of an arbitrary choice.

Test your model by introducing a function call to calcSource() in createFields.H, as you shouldknow how to do by now. Compile the model, solver, and run the damBreak case accordingly

wmake airEntrainmentTwoPhaseMixture

wmake

interAirEntFoam -case $FOAM_RUN/damBreak

when this works, the next step is to integrate our source term in the calculation of the α-field.

4.2.5 Adding the source term to the αl-equation

The aim is to add the calculated source term to the solution algorithm of the αl-equation as thetemplated explicit source term Su. In the VoF solvers in the interFoam family, the αl-equationis solved by the MULES scheme, as described in Section 3.1. Nevertheless, alphaEqn.H andalphaEqnSubCycle.H, which contains the implementation of this procedure, is placed in a com-mon VoF folder, and not in our solver. If the intention had been to do changes in these files, wewould have to add those files to our solver. Nevertheless, since we are aiming to use the templatedway to apply the source term, these file are not needed. When we add the source term as thetemplated Su-field, the source term will be added in the calculation of the upwind flux. See line 119

in the code snippet

99 if (MULESCorr)

100 {

101 #include "alphaSuSp.H"

102

103 fvScalarMatrix alpha1Eqn

104 (

105 (

106 LTS

107 ? fv::localEulerDdtScheme<scalar>(mesh).fvmDdt(alpha1)

108 : fv::EulerDdtScheme<scalar>(mesh).fvmDdt(alpha1)

109 )

110 + fv::gaussConvectionScheme<scalar>

111 (

112 mesh,

113 phiCN,

114 upwind<scalar>(mesh, phiCN)

115 ).fvmDiv(phiCN, alpha1)

116 // - fvm::Sp(fvc::ddt(dimensionedScalar("1", dimless, 1), mesh)

117 // + fvc::div(phiCN), alpha1)

118 ==

35

Page 37: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

119 Su + fvm::Sp(Sp + divU, alpha1)

120 );

121

122 alpha1Eqn.solve();

At line 101 above there is a call to the file alphaSuSp.H. This is the file where we are supposed toadd our source term. Nevertheless, we also want to visualize our source term, therefore we createthe field in createFields.H as

Listing 4.37: Create the source term Su in createFields.H

148 // Source term for visualization

149 volScalarField Su

150 (

151 IOobject

152 (

153 "Su",

154 runTime.timeName(),

155 mesh,

156 IOobject::READ_IF_PRESENT,

157 IOobject::AUTO_WRITE

158 ),

159 mesh,

160 dimensionedScalar("Su",dimVelocity/dimLength, 0)

161 );

Remove the default value for Su by typing in the command window

sed -i /Su/d alphaSuSp.H

Then we update our source term in alphaSuSp.H by a function call to calcSource, by adding thefollowing

Listing 4.38: Update the source term in alphaSuSp.H

1 Su = mixture.calcSource(U,turbulence->k(),

2 turbulence->epsilon());

3 Info << "Max(Su): " << max(Su).value()

4 << "\t Min(Su): " << min(Su).value() << endl;

Compile the solver, and run the damBreak case to test the implementation of the source term.

36

Page 38: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

wmake

interAirEntFoam -case $FOAM_RUN/damBreak

Open the case in paraFoam and view the Su-field. If this field is not available in paraFoam somethingis wrong.

In alphaSuSp.H the inplicit source term Sp and divU are created. In the interFoam solver thesefields are given as zeroFields, which is the correct way to do it when you don’t have any sourceterms. In our solver we have already made the explicit source term Su unzero. We keep divU andSp as zero fields (in alphaSuSp.H)

6 zeroField Sp;

7 zeroField divU;

Then we have implemented our source term into the αl-equation. As described in Section 3.1, theuser can choose whether to apply MULES correction or not. By setting MULES to false/no in thesystem/fvSolution file

solvers

{

"alpha.water.*"

{

nAlphaCorr 2;

nAlphaSubCycles 1;

cAlpha 1;

MULESCorr no;

The default behavior in the solver is false, which means that you actively have to turn MULES onto apply it. If MULES is not activated, our source term Su is added to the solution algorithm inthe function argument to MULES::explicitSolve as

202 alphaPhi10 = talphaPhi1Un;

203

204 MULES::explicitSolve

205 (

206 geometricOneField(),

207 alpha1,

208 phiCN,

209 alphaPhi10,

210 Sp,

211 (Su + divU*min(alpha1(), scalar(1)))(),

212 1,

37

Page 39: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

213 0

214 );

When MULES is activated, the source term Su is added to the solution of the upwind flux, as shownsome paragraphs above. The source term is then not added to the calculation of the correction fluxor the higher order flux term. Nevertheless, the calculation of the higher order fluxes are based onthe upwind solution of the αl-field. In MULES mode the αl-equation is solved through a functioncall to MULES::Correct as

177 MULES::correct

178 (

179 geometricOneField(),

180 alpha1,

181 talphaPhi1Un(),

182 talphaPhi1Corr.ref(),

183 Sp,

184 (-Sp*alpha1)(),

185 1,

186 0

187 );

here, the source term Su is not explicitly included in this function call. Nevertheless, it is implicitlyincluded in the term talphaPhi1Corr.ref(), which equals φcorrα,l in Equation (3.5).

4.2.6 Write additional fields for visualization

For visualization purposes and verification of the implementation, it is convenient to write somemore variable fields to the results. We write Sg as a positive counterpart to Su, and the difference(Pt−Pd), which decides on the extent of air entrainment. We create these files in createFields.H,by typing the following

Listing 4.39: Create additional fields for visualization in createFields.H

163 // Positive source term for easier visualization

164 volScalarField Sg

165 (

166 IOobject

167 (

168 "Sg",

169 runTime.timeName(),

170 mesh,

171 IOobject::READ_IF_PRESENT, //NO_READ,

172 IOobject::AUTO_WRITE //NO_WRITE

173 ),

174 mesh,

175 dimensionedScalar("Sg",dimVelocity/dimLength, 0)

176 );

178 // perturbing term minus stabilizing term for visualization

179 volScalarField PtmPd

180 (

38

Page 40: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

181 IOobject

182 (

183 "PtmPd",

184 runTime.timeName(),

185 mesh,

186 IOobject::READ_IF_PRESENT, //NO_READ,

187 IOobject::AUTO_WRITE //NO_WRITE

188 ),

189 mesh,

190 dimensionedScalar("PtmPd",dimMass/dimTime/dimTime/dimLength, 0)

191 );

We want to update these fields during the simulation. This seems convenient to do in alphaSuSp.H

after the function call to calcSource as

Listing 4.40: Calculate additional fields for visualization

6 // Set the field Sg to the absolute values of Su for visualization

7 forAll(Su, cellI)

8 {

9 Sg[cellI] = mag(Su[cellI]);

10 }

12 // Calculate (Pt - Pd) for visualization

13 PtmPd = mixture.Pt(turbulence->k()) -

14 mixture.Pd(turbulence->k(),turbulence->epsilon());

15 volScalarField test(PtmPd);

17 forAll(test,cellI)

18 {

19 if(test[cellI] < 0)

20 {

21 PtmPd[cellI] = pos(test[cellI]);

22 }else{

23 PtmPd[cellI] = test[cellI];

24 }

25 }

27 forAll(PtmPd.boundaryField(),patchI)

28 {

29 forAll(PtmPd.boundaryField()[patchI], faceI)

30 {

31 PtmPd.boundaryFieldRef()[patchI][faceI] = scalar(0.0);

32 }

33 }

34 PtmPd.correctBoundaryConditions();

Towards the end here, the boundary fields are set to 0, and corrected. This is perhaps not a decentway to do it, but it seemed to be a problem if they were left without setting some values. Then

39

Page 41: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

4.2. IMPLEMENTATIONS CHAPTER 4. IMPLEMENTATION OF INTERAIRENTFOAM

our intended implementations are done. Nevertheless, during the implementation work, we addedsome functions in createFields.H to test our implementations. Remove these lines using the sed-command, and compile and test the solver by typing the following in the command window

sed -i /Lt/d createFields.H

sed -i /mixture.Pt/d createFields.H

sed -i /mixture.Pd/d createFields.H

sed -i /calcSource/d createFields.H

wmake

interAirEntFoam -case $FOAM_RUN/damBreak

Ensure that the new fields are available in paraFoam. When this works, the implementation of thesolver is complete, and we can start to review its performance by a verification case. This is donein the following chapter.

40

Page 42: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Chapter 5

Verification cases

5.1 Vertical plunging jet

In this section we will review the performance of interAirEntFoam by applying it to a verticalplunging jet in 2D. The emphasis will be on evaluating whether the solver qualitatively behave asexpected. The test case can be found in the supplied material attached to this tutorial, it is namedjetintopool. Download the test case to your user directory. Then go into the case directory andrun the Allrun-script

cd $FOAM_RUN/jetintopool./Allrun &

This will run the case for 10 seconds on a single core. Open the case in paraFoam, and ensure thatthe new fields are available. Then copy the case, to a new folder, and run it with interFoam tocompare the behavior

cd ..

cp -r jetintopool jetintopool_interFoam

sed -i s/interAirEntFoam/interFoam/g system/controlDict

./Allrun &

Open the results side by side in paraFoam, using the buttoms in the upper rigth corner. Apply thefield alpha.waterMean and play the simulation. At the end time step, the results will be as shownin Figure 5.1. From Figure (5.1) you can see that a larger region below the surface has a higher airconcentration compared to the results obtained by interFoam. This means that our air entrainmentmodel at least add some air to some regions of the water phase.

Let us have a closer look into the actual fields calculated by the air entrainment model. Go into theinterAirEntFoam version of the jetintopool case, and open a new paraFoam window. Color thecase by alpha.water, and apply a contour line showing alpha.water = 0.5. Show the contour linein Solid Color and Wirefram. This should give you the view of Figure 5.3 at the last time step.

41

Page 43: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

5.1. VERTICAL PLUNGING JET CHAPTER 5. VERIFICATION CASES

(a) interAirEntFoam (b) interFoam

Figure 5.1: Vertical plunging jet, 2D

Figure 5.2: Contour plot showingαl = 0.5 at t = 10.

Then you apply the positive source term Sg field, together with the countour line. Go back to thefirst time step of the simulation and go through the simulation step by step. This will give you theviews shown in Figure 5.3 for some of the first time steps. This figure indicates that the solver atleast conceptually seems to work as intended for a vertical plunging jet on a coarse grid.

42

Page 44: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

5.2. POSSIBLE IMPROVEMENTS CHAPTER 5. VERIFICATION CASES

(a) t=0.2 sec

(b) t=0.5 sec

(c) t=0.8 sec

Figure 5.3: Indication of where the source term is active

5.2 Possible improvements

Even if interAirEntFoam seemed to show the desired behavior for a simple vertical plunging jettest case, proper testing is needed to evaluate the behavior of the solver. Nevertheless, for a model,there will always be room for improvements. Some ideas are listed below.

• limitation on the source term

• better ways to restrict the interface - in interAirEntFoam the interface detected wheneverα ∈ 〈0, 1〉

• Improve the mass conservation - interAirEntFoam is not mass conservative. Mass will be lostwhen air is added to a cell.

• Alternative ways to add the entrained air to the system

– add it to an additional advection(-diffusion) equation. Then you might avoid smearingof the interface

– directly to the calculation of rho and rhoPhi

43

Page 45: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

Study questions

1. Which parameter(s) do you have to add or change in the input file to run a tutorial interFoamcase with interAirEntFoam?

2. What is the purpose of the implementations done to develop interAirEntFoam

3. Which method is used to compress the interface in interFoam

4. How can you manipulate the input variables to obtain the uncorrected higher order solutionfor the αl-equation?

5. What is the criteria for getting air entrainment on a free water surface?

6. Why will it be convenient to model the air entrainment with a subgrid model?

7. How do you link to a user library in the Make/options file of a solver?

44

Page 46: Implementation of an air-entrainment model in …hani/kurser/OS_CFD_2018/SiljeKreke...of the MULES algorithm in his twoPhaseEulerFoam tutorial from 2014 (Manni, 2014). Also Surya Kaundinya

References

Brackbill, J., Kothe, D., & Zemach, C. (1992). A continuum method for modelingsurface tension. Journal of Computational Physics, 100 (2), 335 - 354. Retrievedfrom http://www.sciencedirect.com/science/article/pii/002199919290240Y doi:http://dx.doi.org/10.1016/0021-9991(92)90240-Y

Hemida, H. (2008). Free surface tutorial using interfoam and rasinterfoam. In Proceedings of CFDwith OpenSource Software, 2008, Edited by Nilsson. H.. doi: http://dx.doi.org/10.17196/OS -CFD#YEAR 2008

Hirt, C. (2003). Modeling turbulent entrainment of air at a free surface. Flow Science, Inc.Manni, A. (2014). An introduction to twophaseeulerfoam with addition of an heat exchange

model. In Proceedings of CFD with OpenSource Software, 2014, Edited by Nilsson. H.. doi:http://dx.doi.org/10.17196/OS CFD#YEAR 2014

Olsson, E. (2017). A description of isoadvector - a numerical method for improved surface sharpnessin two-phase flows. In Proceedings of CFD with OpenSource Software, 2017, Edited by Nilsson.H.. doi: http://dx.doi.org/10.17196/OS CFD#YEAR 2017

Oruganti, S. K. (2015). Coupled level-set with vof interfoam. In Proceedings of CFD with OpenSourceSoftware, 2015, Edited by Nilsson. H.. doi: http://dx.doi.org/10.17196/OS CFD#YEAR -2015

Wikipedia. (2018). Volume of fluid-metoden. https://no.wikipedia.org/wiki/Volume of -

fluid-metoden. (Accessed: 2018.12.28)

45