capillary race in circular tubes using openfoamme448 \capillary race" in circular tubes using...

51
“Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen [email protected] March 22, 2014 1 Tutorial Overview This tutorial presents two major topics: the introduction to OpenFOAM, a well-known open- source CFD code, and the instruction for using it to obtain numerical results and visual simulation to fluid mechanics problems. In the first part, an introduction to OpenFOAM is presented and followed by the instruction to build OpenFOAM framework on a personal computer. Next, the standard steps to achieve simulation are presented from pre-processing, setting up and controlling the solver to post-processing. These tasks are done by a set of open-source tools and utilities such as Salome, Paraview, PyFoam, etc. which are also covered in this tutorial as part of the OpenFOAM Framework. The fluid mechanics problems for simulation in this tutorial is the phenomenon of liquid column rising in square tubes with different side length in micro gravity environment. This problem is inferred in this tutorial as “Capillary Race” problem. Following the tutorials, the numerical results and visual simulation are obtained to compare with the experimental data using drop tower mentioned in [16]. 2 Introduction to OpenFOAM Framework OpenFOAM [8] is an open-source CFD toolbox started in 2004. The code was initially developed late 1980s at Imperial College and now is distributed by OpenFOAM foundation and maintained by ESI group, a French-based CAE software company. OpenFOAM is a set of solvers and utilities primarily for CFD with capabilities of standard tasks of CFD working flow from pre-processing, solving and post-processing. OpenFOAM solves wide-rage of problem from incompressible flow, heat transfer to turbulence modeling and fluid structure interaction; it is also not limited to fluid mechanics and is being developed as general modelling platform including mutltiphysic simulation, numerical analysis and differential solver. For the last decade, OpenFOAM has recently raised its popularity with a vibrant user base as can be shown in Figure 1 showing the OpenFOAM download for countries around the world. Figure 1: OpenFOAM download for countries around the world 1

Upload: others

Post on 29-Jan-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

“Capillary Race” in Circular Tubes using OpenFOAMDuc [email protected] 22, 2014

1 Tutorial Overview

This tutorial presents two major topics: the introduction to OpenFOAM, a well-known open-source CFD code, and the instruction for using it to obtain numerical results and visual simulationto fluid mechanics problems. In the first part, an introduction to OpenFOAM is presented andfollowed by the instruction to build OpenFOAM framework on a personal computer. Next, thestandard steps to achieve simulation are presented from pre-processing, setting up and controllingthe solver to post-processing. These tasks are done by a set of open-source tools and utilities such asSalome, Paraview, PyFoam, etc. which are also covered in this tutorial as part of the OpenFOAMFramework. The fluid mechanics problems for simulation in this tutorial is the phenomenon ofliquid column rising in square tubes with different side length in micro gravity environment. Thisproblem is inferred in this tutorial as “Capillary Race” problem. Following the tutorials, thenumerical results and visual simulation are obtained to compare with the experimental data usingdrop tower mentioned in [16].

2 Introduction to OpenFOAM Framework

OpenFOAM [8] is an open-source CFD toolbox started in 2004. The code was initially developedlate 1980s at Imperial College and now is distributed by OpenFOAM foundation and maintainedby ESI group, a French-based CAE software company. OpenFOAM is a set of solvers and utilitiesprimarily for CFD with capabilities of standard tasks of CFD working flow from pre-processing,solving and post-processing. OpenFOAM solves wide-rage of problem from incompressible flow,heat transfer to turbulence modeling and fluid structure interaction; it is also not limited to fluidmechanics and is being developed as general modelling platform including mutltiphysic simulation,numerical analysis and differential solver. For the last decade, OpenFOAM has recently raised itspopularity with a vibrant user base as can be shown in Figure 1 showing the OpenFOAM downloadfor countries around the world.

Figure 1: OpenFOAM download for countries around the world

1

Page 2: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

“Today, OpenFOAM is a proven player in commercial CFD and academic research” [12], saidHrvoje Jasak, main creator of OpenFOAM and also Director of Wikki Ltd., a UK-based Open-FOAM Consultancy said in the 6th International OpenFOAM Workshop [9], Penn State Universityin 2011. The OpenFoam workshop has been annually held since 2006 visting 6 countries in 3 con-tinents. Main users of OpenFOAM include industrial CFD consultancies, academic institution,community. According to extend-project.de [3], the major OpenFOAM community, around 50groups are active around the world using and developing OpenFOAM as the main research and/orservices. Several groups with details information are listed in Appendix A of this tutorial. Thecontributions of users from these vibrant community such as creating and sharpening solvers forOpenFOAM are frequent, many are on monthly basis; this strengthens the power OpenFOAM.

In this tutorials, an example of using OpenFOAM for CFD purpose is introduced. OpenFOAMcore package is combined with third party tools for enhancing CFD work flow of OpenFOAM.This approach is so-called in this tutorial as OpenFOAM Framework and is described Figure 2.Open-source enables OpenFOAM to couple with numerous third-party enhancing tools includingalso optimization tool such as DAKOTA [6] and high quality rendering tools such as Blender [2]which go beyond the regular scope of CFD work flow. This tutorial introduces several tools andchoose some of those as the tools to solve the problem in this tutorial and to detail the instruc-tion. SALOME [11], a well-known CAE platform, is used for pre-processing, ParaView [10], alsoa well-known visualization program for post-processing, matplotlib [7] for plotting, built-in Open-FOAM utilites and Python program such as PyFoam [4] and swak4Foam [5] for manipulating theOpenFOAM solver. Appendix B provides a description of several notable tools to work withinOpenFOAM framework. This tutorial opens the door for users to open-source code world andlearning opportunities of UNIX, python, C programming, and code development. It also fostersusers understanding of the underlying algorithms and computation for numerical simulation.

Figure 2: OpenFOAM Framework Structure

2 of 51

Page 3: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

3 The “Capillary Race” Overview

This subject of this tutorial is simulation of sudden capillary rise in families of cylindrical tubesin micro- gravity environment during drop tower experiments. Such experiments typically consistof a fluid filled chamber mounted to an experiment rig which is then dropped while a high-speedcameras captures the response of the fluid. The experiment corresponding to this tutorials is part ofthe meticulous and tremendous research by Wollman [16] using novel Dryden Drop Tower at PSU.It features four cylindrical tubes with 2.9, 3.8, 7.1 and 10.8 mm of ID with length of 160 mm eachpartially submerging width depth of 10mm in PDMS that fills a reservoir. These four cylindersthen experience 2s drop test in which the capillary forces dominate driving the rise. The rate ofthe rise is different so that synchronization the video of these rises looks like a “Capillary Race” asshown in Figure 3. The rate of capillary rise has been studied using analytical method by Washburn[15] while digitized values from experiments for the rise height of the bulk meniscus are used byWollman [16]. In this tutorial, the same experiment will be set up in OpenFOAM frameworkaiming to produce the corresponding CFD simulation. The simulation produces animation whichcould be directly compared with experimental video; it is also can be extracted for plotting againstexperimental data for the rise height of the bulk meniscus as shown in Figure 4.

Figure 3: “(C) Dynamic rise heights of the menisci in (a)2.9, (b)3.8, (c)7.1, and (d)10.8mm IDcircular tubes are shown after 2s of flow where 0.65cS PDMS rises a maximum length of 143mmin(b) 3.8mm ID tube. The arrow highlights the optimal tube used to achieve maximum flow lengthwithin the freefall time. (D) Dynamic rise heights of the menisci in (a)2.9, (b)3.8, (c)7.1,and(d)10.8mm ID circular tubes are shown after 2s of flow where 5cS PDMS rises a maximum length of67mmin (d) 10.8mm ID tube. The arrow highlights the optimal tube used to achieve maximumflowlength within the freefall time.” [16]

3 of 51

Page 4: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

Figure 4: “Sample of reduced data from tests performed in Fig. 2.1b, where the capillary risein circular tubes height l (t) is plotted against t and t 1/2 for 0.65cS (solid symbols) and 5cSPDMS (open symbols). Predicting the flow that travels the farthest in the 2.1s drop time availableis an optimization problem between capillary, inertial, and viscous forces as functions of tubedimensions.” [16]

4 The Overall Workflow

The tutorial presents step-by-step instruction to solve the “Capillary Race” problem based on theOpenFOAM framework. The following list outlines the steps from initial setup to the simulationresult:

1. Building OpenFOAM Framework on a Personal Computer

2. Prepare Geometry, Mesh with SALOME

3. Introduction to OpenFOAM directory structure

4. Prepare an OpenFOAM case directory and importing the mesh

5. Setting Transport Properties, Initial and Boundary Conditons. Setting Solver Parametersand Stopping Criteria for Transient Solution

6. Running the solver and Extracting Data with PyFoam and swak4Foam

7. Visualization with ParaView, Video encoding the results with avconv, Plotting the resultswith matplotlib

5 Building OpenFOAM Framework on a Personal Computer

5.1 Building a Ubuntu on VMware

• The first step of buidling OpenFOAM Framework is to install an operating system on whichit runs. In this tutorial, the choosen method is to build Ubuntu, a free operating system on avirtual machine, VMware Player, also a free and popular virtual machine software. VMwarePlayer software is installed on a host computer installed with Windows 7 (64-bit).

4 of 51

Page 5: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Go to https://my.vmware.com/web/vmware/free and create a free account to download afree version of VMware Player compatible with Windows 7 (64-bit)

• Installation of VMware Player is similiar to other Windows 7 software. After installation, thestart screen of VMware Player looks like below:

• An image of Ubuntu 13.04 (64-bit) code-name Raring Ringtail is recommended as the operat-ing system for OpenFOAM framework to run on. Go to http://www.ubuntu.com/download/

desktop to download a copy. The file should be ubuntu-13.04-desktop-amd64.iso

• Click on Create a new Virtual Machine and choose the file downloaded on the above step asthe installer disc image file

• The next steps include naming the virtual machine, setting a personal account, specifyingthe disk capacity for your virtual machine. It is recommended to have at least 20GB for thedisk size and stored as a single file to enhance the performance of the virtual machine or asSplit for moderate amount of capacity. During installation, other hardware configuration isalso required. Below is an example of configuration for a virtual machine. Click Finish tostart the installation of Ubuntu.

• Internet connection is mandatory since the VMware Player needs to download the VMWareTools for Linux. The installation of Ubuntu comes shortly after.

5 of 51

Page 6: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The installation takes around 30 to 40 minutes. Once it is finished, Ubuntu is ready to belogged in by the personal account set up above.

5.2 Essential Linux for this tutorial

OpenFOAM Framework runs on Ubuntu, a Linux-based operating system. It is highly recom-mended for OpenFOAM users to have basic knowledge such as file system, control command,terminal, application installation in Ubuntu. Some OpenFOAM training course includes good tu-torial on the essential Linux for OpenFOAM [14]. Several essential tasks for this tutorial are listedas below:

• Open a terminal which is the main communication tool to connect with OpenFOAM Frame-work. The combination key is Ctrl+Alt+T.

• Using sudo apt-get install to get the necessary packages

• Manipulating the terminal. An important command is to terminate it by using the combina-tion Ctrl+C.

• Basic commands for files and directories in Ubuntu which are frequently used such as copy,move, delete. File listing, check current path, change permission, change owner of files and/ordirectories, use source to run a simple script are also important

• Use text editor such as gedit or vim to edit and save a script

6 of 51

Page 7: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Understand the path and environment variables of files and directories in Ubuntu. For ex-ample, ∼/ is the home folder which also is a good place to include working directories forapplications of OpenFOAM Framework; / is the root folder; ./ is the root current folder

5.3 SALOME Installation

• SALOME is a set of applications producing geometries and meshes as inputs for Open-FOAM. SALOME also includes many necessary libraries and tools for OpenFOAM Frame-work such as Python, Numpy, VTK, etc. Inside the virtual machine, go to http://www.

salome-platform.org/downloads/, register for a free user and download SALOME bina-ries version 7.3.0 for Ubuntu 13.04 (64 bits). The downloaded file is a zipped file nameInstallWizard_7.3.0_Ubuntu

_13.04_64bit.tar.gz/

• Right click on the file and choose Open with Archive Manager to open the file. In the ArchiveManager window, click Extract and choose the destination folder. The result is the installerfolder. The README file inside the folder includes the installation instruction for SALOME.

• Open a Terminal and go to the installer folder. Type in the command ./runInstall -g likethe following screen-shot.

• The graphic SALOME v7.3.0 Installation Wizard opens. The installation is composed of 8steps. Choose Install binaries as Installation Type. Choose the Installation directory folder.The Installation directory folder is ∼/salome_7.3.0. Choose all the products for the choiceof the products to be installed then the installation progress will begin. Some steps are shownin the following screen-shots.

7 of 51

Page 8: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• During the installation, absence of some libraries might cause issues. Using the sudo apt-get

install in terminal to get the required libraries.

• After the installation finishes, path and environment variables should be added to Ubuntu.This task is very common when installing softwares in Ubuntu. To do this, one is to go tokernel folder of SALOME which is just installed and run the script salome.sh by commandsource salome.sh every time opening a new terminal; another better one is to add to it theend ∼/.bashrc script.

• Once the path and environment variables are acknowledged by Ubuntu, SALOME could bestarted anywhere. To start SALOME, open a new Terminal and type runSalome. Salomeshould start and open the main working window.

8 of 51

Page 9: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

5.4 Install OpenFOAM core package

• Before the installation of OpenFOAM core package, it is recommended to add OpenFOAMto the application source list and update Ubuntu with the latest package. The step is shownas the following screen-shot.

• In this tutorial, openfoam222 will be installed by sudo apt-get install method. Installa-tion of OpenFOAM requires many libraries to be updated.

9 of 51

Page 10: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The OpenFOAM package installation is completed with the reminder to add the bashrc scriptof OpenFOAM the main bashrc script. This is done similiar to the way to configure terminalfor Salome.

• Testing the installation successful of OpenFOAM could be done by testing if Ubuntu termi-nal could realize the OpenFOAM command like icoFOAM --help or OpenFOAM path andenviroment variables as shown the following screen-shot.

• The case in this tutorial and many others inherit from the OpenFOAM tutorial cases. Copythe tutorial from $FOAM_TUTORIALS directory to $FOAM_RUN which is the main working direc-tory to run OpenFOAM cases later. To view the full path of these directories, echo commandcould be used.

10 of 51

Page 11: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

5.5 Install PyFoam, swak4Foam

PyFoam is a set Python programs designed to manipulate and enhance the run of OpenFOAMsolver. In this tutorial, PyFoam will be used to run the solver job and monitor the initial residualsand continutiy. To install PyFoam, follow these steps:

• Download the PyFoam tar package at http://openfoamwiki.net/index.php/Contrib/PyFoamand unzip the tar package using Archive Manager or built-in tar application of Ubuntu. Thedestination is suggested to be home folder.

• Go inside the PyFoam folder and run the setup python script. Since the requisite librariesfor PyFoam such as python, numpy, scipy are already included in the SALOME directory,the setup of PyFoam will refer to those libraries.

• To test the installation of PyFoam, use the simple python program below. PyFOAM shouldbe linked to OpenFOAM.

11 of 51

Page 12: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

swak4Foam which stands for Swiss Army Knife for OpenFOAM is a set of useful tool for extractingdata from OpenFOAM result and/or setting the boundary and initial conditions. swak4Foam couldbe installed using instruction from openfoamwiki.net/index.php/Contrib/swak4Foam. This tu-torial introduces another method which is successfully installed with OpenFOAM 2.2.2.

• swak4Foam requires 2 packages which are Bison, a parser generator and Flex, a lexicalanalyser. Installation of the two package are done by sudo apt-get install

• Go to https://github.com/wyldckat/swak4foam and download a zip sourcode of swak4foam0.2.4

• Go to this CFD-online thread and download the patch so swak4foam 0.2.4 http://www.

cfd-online.com/Forums/openfoam-installation/118194-swak4foam-0-2-3-of2-2-x-installation-error.

html

• Unzip the swak4Foam package to get the installer folder whose name is swak4foam-OF22x andmove the patch inside this folder. The folder structure of swak4Foam looks like he followingscreen-shot.

• Unzip and run the patch inside the installer folder as in the following screen-shot.

12 of 51

Page 13: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Compile the source. It takes up to 1 hour.

• Once the installation is completed, it could be tested by enter a command of swak4Foam suchas funkySetFields. The result should display the swak4Foam version as in the followingscreen-shot.

5.6 Install Paraview, matplotlib, gnuplot, avconv, ffmpeg

ParaView, the visualization program for displaying result of OpenFOAM is installed by sudo

apt-get install method. The version paraviewopenfoam3120 matches natively with Open-FOAM 2.2.2 without any configuration. ParaView could process the outputs of OpenFOAMcomputation as still images. These images could be combined to make a video to simulate the

13 of 51

Page 14: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

“Capillary Race”. This is done by video encoder such as avconv or ffmpeg. Installation of theseis also done by the use of sudo apt-get install method.

matplotlib is a set of Python plotting libraries and also includes pylab which is a proceduralstate machine resembling MATLAB. Users can easily use syntaxes as simple as ones in MATLABto extract then plotting data for example in this tutorial the height of the capillary rise. Installationof matplotlib is described as following steps.

• Download a zip .gz package from http://matplotlib.org/downloads.html. In this tu-torials, the version downloaded is matplotlib 1.2.0 from the following location: http://

sourceforge.net/projects/matplotlib/files/

• Unzip the downloaded package to a destination folder. Go to the folder and run the pythonsetup script with the prefix referring to SALOME directory where Python is installed. Thecommand is python setup.py install --prefix=∼/salome_7.3.0/Python-2.7.3/

In this tutorial, gnuplot will be used for plotting the residuals of the numerical computation.Installation could be also done by by sudo apt-get install method.

6 Prepare and Import Geometry and Mesh with Salome

6.1 Create Geometry for four capillary tubes

The section describes the steps using SALOME to prepare geometry and mesh for the four tubeswith 2.9, 3.8, 7.1 and 10.8 mm of ID with length of 160 mm.

Start up SALOME by running start command runSalome in a bash terminal. Click on the Geometrybutton or choose from the environment drop-down list to activate Geometry module. A window inthe following screen-shot appears, click on New to create a new Geometry.

The dimension is configured default to mm regarding the tubes in this problems are in mm. To dothis, Click File > Properties and change Length units to mm as shown in the following screen-shot.

14 of 51

Page 15: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

Firstly, the following steps will create the four tubes using cylinder tool in Geometry module.Again, the inner diameters of the four tubes are 2.9, 3.8, 7.1 and 10.8 mm and the location of thesetubes are at the origin, 8, 20 and 36 mm respectively in y-axis of YZ-plane.

• Select New Entity>Primitive>Cylinder.

• The default option allows the construction with the center of the base at the origin. Enterthe radius of 1.45 and the height of 160 for the first cylinder then click on Apply and Closeas the following screen-shot. The cylinder is shown on the OCC viewer screen.

• Next steps are to create the points at which the next three tubes are placed. Select NewEntity>Basic>Point. Enter the coordinate (0,8,0) for x,y,z coordinates for the position ofsecond tube as the following screen-shot. Do the same thing to create the position for thethird and the fourth tubes at 20 and 36 mm respectively in y-axis of YZ-plane.

15 of 51

Page 16: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The other tubes are created using cylinder function of Geometry module. However, this timethe base point and the vector will be used for the construction of the tubes. Choose theoption as as the following screen-shot. Enter the points created above as base point and Ozas the vector then enter the radii 1.9, 3.55 and 5.4 and the height of 160. Click Apply afterentering the set of parameters for the second and the third tubes, click Apply and close forthe fourth tubes. By default, the tubes are named Cylinder 1 to Cylinder 4 and could bereplaced by appropriate name if necessary. All the four cylinders should be displayed in theOCC viewer screen as below.

6.2 Prepare Geometry for Meshing

The geometry should be prepared with necessary bodies, sub-bodies, faces and edges which will beused in the meshing process.

• The main mesh later is on a single domain; therefore, four cylinders will be combinedtogether to become only one subject. This could be done using Fuse function. SelectOperations>Boolean>Fuse. The Fuse Objects window opens, click on the arrow buttonand choose the 4 cylinders in the Object Browser. Four objects should be updated in the

16 of 51

Page 17: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

Fuse Object window as shown in the screen-shot below. Click Apply and Close, the Fuseobject named Fuse 1 will be created and added to Object Browser.

• Once the fuse is created, it is ready for prepare the necessary faces, edges which are inlet,outlet, wall and side edges. For each tubes, two faces on the bottom and on the tops areneeded as inlet and outlet. One curved face represents the wall and one side edge representsthe height. SALOME has the Create Group function to select and create those objects. SelectNew Entity>Group>Create Group. Choose Face as Shape Type, Fuse 1 as the Main Shapeas shown in the following screen-shot. Give the name for the desired object.

• In the OCC viewer screen, rotating and panning the 4 tubes to choose the desired object. Forexample, choose the inlet of the first cylinder, this should be highlighted in white as shownin the following screen-shot. Name it Inlet1 also.

17 of 51

Page 18: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Click Add for the object selection and Apply. The face will be added in the box of the CreateGroup Window as in following screen-shot. The face object Inlet will be created and addedunder the Fuse object Fuse 1 in Object Browser.

• The Apply button keeps the Create Group Window open to select new objects. Repeat theprocess to select all necessary inlet, outlet, wall and side edges of four tubes. For the sideedges, the Shape Type option is line. For the combined inlet, outlet, wall and side edges,the shape selection box could be added by choosing directly from OCC viewer screen or bychoosing from the single corresponding objects in the object browser. Click Apply and Closewhen finishing create all desired objects. The final list of objects under the Fuse 1 object isshown in following screen-shot.

18 of 51

Page 19: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• To double check the face creation, hide All and use eye button toggling one-by-one object todouble check the object creation. Click View>Hide All then right click or use eye button toshow the desired object. For example, if the Inlet or the Side Edges or the Wall are chosento show ,the OCC viewer screen should display as in following screen-shot.

6.3 Meshing the geometry

To start the meshing process, Click on the Mesh button or choose from the environment drop-down list to activate Mesh module. The meshing process includes the surface mesh using Triangle(Mefisto) and followed by 3D Extrusion for volume mesh and 1D refinement by using Wire Discre-tion. The following steps will help to create the mesh.

• Select Mesh>Create Mesh. Naming the mesh as Mesh 1 and choose the object to mesh whichis Fuse 1 in this the tutorial.

• The Create Mesh window opens. Choose Triangle (Mefisto) as the Algorithm from the Drop-down list. Click on the Gear button to choose Length from Edges 1 as Hypothesis as shownin the following screenshot.

19 of 51

Page 20: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Navigate to 1D tab, choose Wire Discretion from the Drop-down list for Algorithm as shownin the following screen-shot.

• Click on the Gear button to choose and configure the Hypothesis. Enter 20 as Number of Seg-ments and Equidistant Distribution as Type of Distribution in the Hypothesis Constructionwindow as in the following screen-shot. Click OK.

• The Create Mesh Window now should have the definition for 2D and 1D meshing as shownin the following screen-shot. Click Apply and Close.

20 of 51

Page 21: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Click Mesh>Compute Mesh to start meshing. A window appears showing progress and RAMusage information; after the meshing calculation complete, the meshing information appearsas shown in the following screen-shot. At this stage, surface meshing is done.

• The surface meshing will be modified with Sub-mesh to prepare for 3D extrusion. The inletand outlet of each tube will be related using Projection 2D function so that the triangularmesh of the inlet and the outlet will be the same. Click Mesh>Create Sub-Mesh. Namethe Sub-Mesh, choose the overall mesh Mesh 1 as the main Mesh. Choose the geometry byclicking at the desired object in the Object Browser window, for example Outlet1, the outletof the first tube to which the first inlet projecting to. Click on the Gear button to choosethe Hypothesis which is the Source Face. In the Hypothesis construction window, choose theInlet1 as the Source Face then click OK. Click Apply on the Create Mesh window.

21 of 51

Page 22: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The Sub-mesh for lateral wall face is also needed prepare for 3D extrusion. In the sameCreate Mesh window as above, choose the combined wall face under Fuse Object. For theAlgorithm, choose Quadrangle (mapping) from the drop-down list. The Hypothesis could beleft blank as default chosen as standard.

• Click on Mesh>Compute Mesh to start meshing. Once the mesh computation succeed, thesurface meshing is ready for volume meshing.

• Click Mesh>Create Sub-Mesh, on the 3D tab, make sure Mesh 1, Fuse 1 are choosen for Meshand Geometry. Choose 3D extrusion as Algorithm in the Drop-down list. Click Apply andClose, then Click on Mesh>Compute Mesh to start final volume meshing. Once the meshcomputation succeed, the Mesh information should display Volume mesh.

22 of 51

Page 23: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• For this tutorial, it is desired to have 100 elements in the z-axis for a fine mesh. In orderto do that, another Sub-mesh is needed. Click Mesh>Create Sub-Mesh, choose Side edgeas the geometry. Click on the Gear button to choose and configure the Hypothesis. Enter100 as Number of Segments and Equidistant Distribution as Type of Distribution in theHypothesis Construction window. Click OK. Click Apply and Close on the Mesh window.

• The final Mesh structure should look like the following screen-shot.

23 of 51

Page 24: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Click Mesh>Compute Mesh to start meshing. Once the mesh computation succeed, the Meshinformation is the final information for the mesh used in this tutorial. The mesh should alsobe seen in the VTK viewer screen.

6.4 Create Boundaries and Exporting the Mesh

OpenFOAM needs the boundaries information from the mesh. An OpenFOAM-ready mesh ex-ported from SALOME needs to include the boundaries information. This is done by the followingsteps:

• Click on Mesh>Create Group. Choose Mesh 1 for the Mesh and Face as the Element Type.In Group Type, choose Group on Geometry. Click on the arrow close to Geometrical Objectand choose Direct Geometry Selection. From the Object Browser window, choose Inlet whichis the combined Inlet of the Fuse. The Geometrical Object is updated. The name of thisboundary is important since later it should be exactly the same in the OpenFOAM.

• It is also recommended to change the color of the boundaries. To do this, go do to the end ofthe Create Group Window and choose the color. Click Apply to finish creating the boundaryfor Inlet.

24 of 51

Page 25: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Repeating the same tasks of choosing the faces, naming and coloring for the Wall and theOutlet. The boundary is now colored as in the following screen-shot. The group of faces asboundaries are updated in Object Browser under the Mesh.

• The mesh is ready to be exported to .UNV format to used as input for OpenFOAM. To dothis, within the Mesh environment, Click File>Export and choose UNV file. Choose the placeto save this mesh, later it will be moved inside an OpenFOAM folder.

7 Introduction to OpenFOAM directory structure

Before discussion on starting an OpenFOAM study, it is strongly recommended for users to under-stand the organization of OpenFOAM package. A good place for reference is listed in [14]. Thewhole OpenFOAM package is installed in $WM_PROJECT_DIR where all the important informationof the package is stored such as compile scripts, environment variables, source codes and also bi-naries for libraries, solver and utilities, etc. Exploring this folder will help users gaining a deepunderstanding about how OpenFOAM code using theory of physic and CFD to solve many prob-lems numerically. Users are also provided with resource to test, run, modify and further to createsolver or utilities based on OpenFOAM. In the scope of this tutorial, only the directory struc-ture of an OpenFOAM case will be presented. However, always remember that the understandingOpenFOAM package folder is very important since it interacts directly with the case folder.

25 of 51

Page 26: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

Figure 5: OpenFOAM top-level case directory sturcture

The strandard directory structure of an OpenFOAM case is shown in Fig 5 above. The top-leveldirectory of an OpenFOAM case is stored as a folder in the folder run inside the user workingdirectory $WM_PROJECT_DIR. This run folder could be accessed by the using environment variable$FOAM RUN. There are five elementary sub-folders with the required for any OpenFOAM case. Thosesub-folders and their roles are listed below:

1. system: contains the run-time control, solver parameters and utilities definition

2. constant: contains fluid transport properties, turbulence modelling properties and generalphysical properties

3. constant/polyMesh: contains the entire mesh data and information such as points, faces andboundaries.

4. 0: contains the boundary conditions, initial conditions, phase interactions. Both scalar fieldand vector field could be included

5. time_directories: contains the solution both default by solvers or derived fields by users.

The OpenFOAM top-level case directory might include more sub-folders when more utilities areapplied such as PyFoam and swak4Foam. One important thing remember is always to run Open-FOAM solvers and utilities in the top-level case directory.

8 Prepare an OpenFOAM case directory and importing the mesh

An OpenFOAM case directory could be created from scratch following the 5 sub-folders mentionedin Section 7. However it is better to copy a sample case from tutorials which comes with theOpenFOAM package. One step of OpenFOAM core package installation in Section 5.4 has alreadycopied all the tutorial case to the running folder. To create the directory for this tutorial, go inside

26 of 51

Page 27: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

the tutorial folder, find the sample case of interFoam solver name capillaryRise and copy to therun folder as shown the following screenshot. After that, rename the folder to CapillaryRace065

for 0.65cS PDMS. Repeat these steps to create another OpenFOAM case folder CapillaryRace500for 5.0cS PDMS.

In Section 6.4, a mesh with .UNV form has already been created by SALOME and now readyto be imported to OpenFOAM. To do this, follow the steps below:

• Copy the .UNV mesh produced by SALOME to the top level OpenFOAM case directory. Makesure the top-level case directory looks like the following screen-shot.

• Open a terminal and direct to the top level OpenFOAM case directory. Use ideasUnvtoFoam

to convert the .UNV file to the mesh format which could be processed by OpenFOAM.

• When the conversion is completed, use the checkMesh to see if the mesh is ready for Open-FOAM.

27 of 51

Page 28: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The Mesh should be reported OK. Another way to check the completeness of this meshconversion task is go directly to the sub-folders at which the OpenFOAM mesh informationis stored. Go inside the constant/polyMesh folder and check the points file, many pointsshould look similar to the radius and the height dimension of the tubes.

• It is recognizable that OpenFOAM will take the number exactly as entered from SALOMEand take them default in meter dimension. OpenFOAM also has the utilities to scale dimen-sion from meter to millimetre. Following the steps below to convert from meter to millimetreand check the points for the effect.

28 of 51

Page 29: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

9 Setting Transport Properties and Contact Angle, Boundary andInitial Conditions. Setting Solver Parameters and Stopping Cri-teria for Transient Solution

9.1 Setting Transport Properties and Contact Angle

• Before setting the transport properties of fluid phases ins this tutorial, one important pa-rameter to remember is to set gravity to 0 since the four capillary tubes are subjected tomicrogravity environment. To do that edit g inside the constant folder with gravity is 0 inall 3 direction.

dimensions [0 1 -2 0 0 0 0];

value ( 0 0 0 );

• All the transport properties of fluid phases are described in the transportProperties insidethe constant folder. This file let users to enter 7 physical dimensions such as mass, length,time, temperature, etc. Find the place in the phase to edit dynamic viscosity, density forboth two phases and surface tension between two phases. Phase 1 is defined as the PDMSand phase 2 is defined as air. The other parameters in transportProperties should be kept.

...

phase1

{

transportModel Newtonian;

nu nu [0 2 -1 0 0 0 0] 0.65e-06;

rho rho [1 -3 0 0 0 0 0] 760;

...

phase2

{

transportModel Newtonian;

nu nu [0 2 -1 0 0 0 0] 1.48e-05;

rho rho [1 -3 0 0 0 0 0] 1.2;

...

sigma sigma [1 0 -2 0 0 0 0] 0.0159;

...

...

29 of 51

Page 30: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

phase1

{

transportModel Newtonian;

nu nu [0 2 -1 0 0 0 0] 5.0e-06;

rho rho [1 -3 0 0 0 0 0] 913;

...

phase2

{

transportModel Newtonian;

nu nu [0 2 -1 0 0 0 0] 1.48e-05;

rho rho [1 -3 0 0 0 0 0] 1.2;

...

sigma sigma [1 0 -2 0 0 0 0] 0.0197;

...

• The contact angle is defined in alpha1.org inside the 0 folder. Find the place below and editfor a static constant contact angle of zero degree.

...

Wall

{

type constantAlphaContactAngle;

theta0 0;

limit gradient;

value uniform 0;

}

...

9.2 Setting Boundary and Initial Conditions

Three boundary types of this tutorial are Inlet, Outlet and Wall as defined by SALOME in Section6.4. Each boundary is the combination of faces from each tube. Since the name boundary face iscopied from the tutorial case, it is an important task to ensure renaming the patch in OpenFOAMto match with the name in SALOME before setting boundary and initial conditions. The boundaryfaces are declared in both alpha1.org, U and p_rgh. Each boundary usually has a name, a type,a value. The boundary type is very important to the solution, those boundary conditions in thistutorial is kept the same as ones in the tutorial case of capillaryRise in a single tube. Followingthe steps below to set the boundary conditions.

• Use gedit to open 0\alpha1.org, 0\U, 0\p_rgh file, change the names, types and values forboundaries as following. The other information should be kept.

• Repeat this edit task for U and p_rgh

...

boundaryField

{

Inlet

{

type inletOutlet;

value uniform 1;

inletValue uniform 1;

}

Outlet

30 of 51

Page 31: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

{

type zeroGradient;

}

Wall

{

type constantAlphaContactAngle;

theta0 0;

limit gradient;

value uniform 0;

}

...

...

boundaryField

{

Inlet

{

type pressureInletOutletVelocity;

value uniform (0 0 0);

}

Outlet

{

type pressureInletOutletVelocity;

value uniform (0 0 0);

}

Wall

{

type fixedValue;

value uniform (0 0 0);

}

...

...

boundaryField

{

Inlet

{

type fixedValue;

value uniform 0;

}

Outlet

{

type fixedValue;

value uniform 0;

}

Wall

{

type fixedFluxPressure;

}

...

The initial condition for the distribution of the two fluids in the continuum is alpha1 which isPDMS is filled at 10mm in height of each tube and air filled the rest of the tube. OpenFOAM has

31 of 51

Page 32: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

setFields utility to do this task. This utility need a dictionary to define the region which alpha1

is filled. The tutorial case of capillaryRise has already defined this dictionary.

• Use gedit to edit a file named setFieldsDict inside the system folder

• Edit the box to cell block to fill the four tubes as following

...

regions

(

boxToCell

{

box (-1.5e-3 -1.5e-3 0) (1.5e-3 1.5e-3 10e-3);

fieldValues

(

volScalarFieldValue alpha1 1

);

}

boxToCell

{

box (-2e-3 6e-3 0) (2e-3 10e-3 10e-3);

fieldValues

(

volScalarFieldValue alpha1 1

);

}

boxToCell

{

box (-3.6e-3 16.4e-3 0) (3.6e-3 23.6e-3 10e-3);

fieldValues

(

volScalarFieldValue alpha1 1

);

}

boxToCell

{

box (-5.4e-3 30.6e-3 0) (5.4e-3 41.4e-3 10e-3);

fieldValues

(

volScalarFieldValue alpha1 1

);

}

...

• One file name alpha1 inside 0 folder is needed to store the information of the filled region.It is also the output of setFields utility. The conventional way to do it is make a copy ofalpha1.org and rename it to alpha1

32 of 51

Page 33: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Go up to the top-level case directory and run setFields utility. The output should look likefollowing:

• Next, use ParaView to check if the boundary and initial conditions are correct. Run paraFoam

in top-level case directory to create a .foam file and enter ParaView program. Sometimes, ifOpenFOAM could not recognize paraFoam, it is necessary to re-run the bash script as shownin the screen-shot below. Rerun the paraFoam command, the ParaView opens up.

• Several options are configured such as select the mesh, the field to display, select the kind ofdisplay. Edit the parameters in Object Inspector window as shown in the following screen-shot and click Apply.

33 of 51

Page 34: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Unclick the center show and set view direction to -X axis. The four tubes and the initialPDMS filled should be shown. At this point, setting Boundary and Initial Conditions arecompleted.

• Note that the default color range display of ParaView is in CIELAB. To change it to HSVcolor range as it this tutorial, click on tab Display of Object Browser and chose Edit ColorMap. The Color Scale Editor opens, choose HSV as Color space and click Make Default.

34 of 51

Page 35: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

9.3 Setting Solver Parameters and Stopping Criteria for Transient Solution

Solver Parameter and Stopping Criteria are important as they define how solver will run to getconverge and reliable results. These are stored at 3 files inside system sub-fodler: fvSchemes forfinite element algorithm, fvSolution for solver algorithm and convergence criteria, controlDictfor stopping criteria. In this tutorial, the settings of the tutorial case are generally kept; onlyresidual control, run time, time step, maximum inner iteration will be modified in this tutorial.

• To set up the run time and time step, use gedit to modify the controlDict file. The fullexplanation for the parameters could be found at OpenFOAM reference such as citeJoel. Inthis tutorial, the run time for 0.65cS PDMS case will be 0.7s and the time step will be 0.001s,the adjust time step option should be set to no. For 5.0cS PDMS the run time will be 1.4sand the time step is still 0.001s. For the first time, the run time may be not known so 2scould be set for the run time but after the first trial run, the time for at least one of the tubehas fluid reaching its top is known so the run time could be modified.

...

stopAt endTime;

endTime 0.7;

deltaT 0.001;

...

runTimeModifiable yes;

adjustTimeStep no;

maxCo 0.2;

maxAlphaCo 0.2;

...

• The “Capillary Race” in this tutorial involves transient problem with each time step itself isconstraint with conditions like for residual and Courant number. Such information of residual,inner iteration, Courant number are known as solver parameters. It is desired that the solveralgorithm will continue to run until it satisfies the known-goood chosen solver parameters. TheCourant number represents Courant-Friedrichs-Lewy (CFL) condition for stability solutionfor solving partial differential equations (PDE) numerically by the method of finite differences[13]. The interFoam solver models the “Capillary Race” by PDE; therefore,the CFL conditionis indispensable. The maximum Courant number in this tutorial is also kept the same as thetutorial case and equal to 0.2. It is stored in controlDict file.

35 of 51

Page 36: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Each time step solution is allowed a specific number of iteration so-called the maximumnumber of iteration to meet both residual and Courant number condition. The Courantnumber condition is already set above. For the maximum number of iteration, use gedit toedit a file named fvsolution inside the system folder. The parameter nOuterCorrectors

inside PIMPLE algorithm is edited to 100 for maximum number of iteration of each timestep and the new block of residual control is added for the final residual of each time step is1e-05.

...

PIMPLE

{

momentumPredictor no;

nOuterCorrectors 100;

// nCorrectors 3;

nNonOrthogonalCorrectors 0;

nAlphaCorr 1;

nAlphaSubCycles 2;

cAlpha 1;

residualControl

{

p_rgh

{

tolerance 1e-05;

relTol 0;

absTol 0;

}

}

}

...

• At this point, the solver is ready to run for simulation

10 Running the solver and Extracting Data with PyFoam andswak4Foam

The conventional way of running a solver is simply use the OpenFOAM command and log to afile. For example, the solver could be started by use the command interFoam>log or interFoam

|tee log at the top-level case directory to see the log on-the-fly. If using the first method, thecommand tail -f log could be used any time to view the log. The good thing with OpenFOAMis its features of accepting customized scripts to manipulate to run. In this tutorial, PyFoam hasalready extracted the information from solution such as Initial Residual and Continuity to plotthem on-the fly. It is recommended to prepare all necessary and/or customized utilities couplingwith the solver before running solver with PyFoam. The simulation time is usually long and it isunfavourable to finish the run and forget to include a script which needs to be couple with the runon-the-fly.

The important data from this simulation to compare with experimental data is the meniscus height,the lowest point of the meniscus. The solver itself only provides the volume fraction of full domaininside the tubes. It is necessary to analyze the data from the solver to attain the meniscus height.The assumption of symmetry is applied which means that the menicus lowest point is along thecenter line of the tubes at each time step. The meniscus height could be achieved by sampling the

36 of 51

Page 37: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

volume fraction of alpha1 which is PDMS along the center line. The volume fraction of alpha1 is1 for the region filled with PDMS while volume fraction of alpha1 is 0 if the region is filled withair. The meniscus is where the volume fraction change from 1 to 0. In this tutorial, the meniscusheight is defined where the volume fraction is 0.5. The task of sampling volume fraction could bedone by using the sample utility of OpenFOAM. This could also be done using a Filter in Paraviewwhich even features plotting function. In this tutorial, script method based on swak4Foam will beused.

• The first step is to prepare a dictionary for sampling using swak4Foam. Since this dictio-nary is not part of the tutorial case, a new file will be created from scratch. Use gedit tocreate four files name sampledSets1, sampledSets2, sampledSets3, sampledSets4 insidesystem folder to sample the meniscus height for 4 tubes. For example the sampledSets1 isshown below.

fillHeight1 {

type swakExpression;

valueType set;

verbose true;

setName lineUp1;

set {

type uniform ;

axis z ;

start (0 0 0) ;

end ( 0 0 0.16) ;

nPoints 200;

}

expression "( alpha1 > 0.5) ? pos().z : 0";

accumulations (

max

);

interpolate true;

interpolationType cellPoint;

}

• The content of sampledSets2, sampledSets3, sampledSets4 is the same as sampledSets1except fillHeight1 will be replaced by fillHeight2, fillHeight3, fillHeight4.

• Those sampledSets and the necessary swak4Foam libraries should be declared in controlDict.Use gedit to add the following to controlDict.

...

libs (

"libOpenFOAM.so"

"libsimpleSwakFunctionObjects.so"

"libswakFunctionObjects.so"

"libsimpleFunctionObjects.so"

);

functions

{

#include "sampledSets1"

#include "sampledSets2"

#include "sampledSets3"

#include "sampledSets4"

}

...

37 of 51

Page 38: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Go to top-level case directory and enter the command pyFoamPlotRunner.py --clear interFoam

> log -case /$FOAM RUN/capillaryRace065 to start running the solver. PyFOAM shouldstart the interFoam and record the initial residuals and continuity.

• Upon completion of the running of the solver, the data for residuals and continuity are shownbelow for the cases of 0.65cS and 5.0cS respectively. The plot of the residual is only the initialresidual of a time step; the final residual is always in order of 1e-05.

38 of 51

Page 39: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The final top-level case directory after the computation completed looks like below.

• swak4Foam records the data for meniscus height to 4 folders inside postprocessing folder;one for each tube. Inside each folder there is only one folder 0 storing the meniscus heightdata in file with name according to swak4Foam dictionary.

39 of 51

Page 40: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The meniscus height data looks like below.

11 Visualization with Paraview, Video encoding the results withavconv, Plotting the results with matplotlib

11.1 Visualization with Paraview

ParaView is a powerful visualization program packing natively with OpenFoam. The mesh data andthe solution are imported to ParaView using the paraFoam command. In this tutorial, ParaViewwill help to visualize solution of each time-step then save these solutions as still images which willbe converted to a video later. ParaView also features many functions to analyze the visual solution.The solution in this tutorial is assumed to be symmetrical, the visual solution will be extracted atthe mid-plane. ParaView will also let users to add text, color scale bar and time annotation.

• First, make sure that the options below are configured such as choose the mesh, the field todisplay, choose the kind of display. Edit the parameters in Object Inspector window as shownin the following screenshot and click Apply.

40 of 51

Page 41: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Choose Filter>Common>Slice, a new slice object named Slice1 added in the Pipeline Browser.Rename it to MidPlane and in the Object Inspector, choose the Origin and Normal as shownin the following screen-shot.

• Choose Source>Annotate Time and Source>Text to add the time and the text to the solution.These objects will be added to Pipeline Browser. Choose each object so it could be definedand formatted in Object Inspector. The Pipeline Browser and the visual result could be likethe following screenshot.

41 of 51

Page 42: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Use the Control toolbar in ParaView, users could visualize the dynamic transient solution orsee the solution at any time step.

11.2 Video encoding the Results with avconv

ParaView features the function of saving still images of visual solutions from numerical result: onestill image per time step. A video encoder program such as avconv or ffmpeg combine all theimages to make a video in standard video codec such as H.264. This tutorial will demonstrate howto use avconv to make the video for the simulation of “Capillary Race”.

• The installation of avconv or ffmpeg is mentioned in Section 5.6.

42 of 51

Page 43: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• Make sure that the steps in Section 11.1 is completed. Click one File>Save Animation.

• The Animation Settings Dialog will appear. Choose Resolution of 1920x1080 pixels as below.Click Save Animation.

• The destination folder the prefix for the image which will be saved. For example, the top-levelcase directory will be used for the destination folder and height will be used for the prefix inthis tutorial. Click OK, ParaView will automatically run and after the process is done, theimage file will appear in the destination folder.

Browser

• Open a terminal and go to top-level case directory where the still images are saved. Manyoptions could be chosen for avconv to work. The reference could be found [1]. The optionsfor avconv shown below could produce a decent HD1080 video. The file is encoded in .mp4format with x264 codec. The name of the file is output.mp4. The file could be played wellwith VLC player or Windows Media Player 11. In window, it is suggested the K-lite codecpackage at http://www.free-codecs.com/k_lite_codec_pack_download.htm is installedwhile gstreamer1.0 is recommended in Ubuntu.

43 of 51

Page 44: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

11.3 Plotting the Results with matplotlib

This last section of this tutorial presents how to use plotting program in Ubuntu such as matplotlibto plot the meniscus height of the capillary rise acquired in Section 10. This Section will also showthe way to plot the residual of the numerical computation. Installation of matplotlib and gnuplotwas done in Section 5.6. Follow the steps below to produce two figures: one is the plot of meniscusheight to the time and the other is the plot of meniscus height to the square root of time.

• Create a Python file as below to open the data file extracted and saved by swak4Foam inSection 10. The file is named fillHeight.py in this tutorial and could be saved anywhere inUbuntu. However, it is recommended to the file in the running directory or the top-level casedirectory. The figures for the plots will be saved as .png format at the same place as thepython file. The pylab and numpy libraries imported in the Python code are included withSALOME and matplotlib.

import pylab , numpy

data1=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace065/postProcessing/swakExpression_fillHeight1 /0/ fillHeight1 ’)

data2=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace065/postProcessing/swakExpression_fillHeight2 /0/ fillHeight2 ’)

data3=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace065/postProcessing/swakExpression_fillHeight3 /0/ fillHeight3 ’)

data4=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace065/postProcessing/swakExpression_fillHeight4 /0/ fillHeight4 ’)

data5=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace500/postProcessing/swakExpression_fillHeight1 /0/ fillHeight1 ’)

data6=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace500/postProcessing/swakExpression_fillHeight2 /0/ fillHeight2 ’)

data7=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace500/postProcessing/swakExpression_fillHeight3 /0/ fillHeight3 ’)

data8=pylab.loadtxt(’/home/ducnguyen/OpenFOAM/ducnguyen -2.2.2/ run/

capillaryRace500/postProcessing/swakExpression_fillHeight4 /0/ fillHeight4 ’)

pylab.figure (0)

pylab.plot( data5[range (0 ,699 ,35) ,0], data5[range (0 ,699 ,35) ,1] * 1000, ’w^’)

pylab.plot( data6[range (0 ,699 ,35) ,0], data6[range (0 ,699 ,35) ,1] * 1000, ’wd’)

pylab.plot( data7[range (0 ,699 ,35) ,0], data7[range (0 ,699 ,35) ,1] * 1000, ’ws’)

pylab.plot( data8[range (0 ,699 ,35) ,0], data8[range (0 ,699 ,35) ,1] * 1000, ’wo’)

pylab.plot( data1[range (0 ,699 ,35) ,0], data1[range (0 ,699 ,35) ,1] * 1000, ’k^’,

label=’2.9mm ID’)

44 of 51

Page 45: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

pylab.plot( data2[range (0 ,699 ,35) ,0], data2[range (0 ,699 ,35) ,1] * 1000, ’kd’,

label=’3.8mm ID’)

pylab.plot( data3[range (0 ,699 ,35) ,0], data3[range (0 ,699 ,35) ,1] * 1000, ’ks’,

label=’7.1mm ID’)

pylab.plot( data4[range (0 ,699 ,35) ,0], data4[range (0 ,699 ,35) ,1] * 1000, ’ko’,

label=’10.8 mmID’)

pylab.legend ()

pylab.xlabel(r’$t[s]$’)

pylab.ylabel(r’$l[mm]$’)

pylab.legend(loc=’upper left’)

pylab.savefig(’lvst.png’)

pylab.figure (1)

pylab.plot( data5[range (0 ,699 ,35) ,0] ** 0.5, data5[range (0 ,699 ,35) ,1] * 1000,

’w^’)

pylab.plot( data6[range (0 ,699 ,35) ,0] ** 0.5, data6[range (0 ,699 ,35) ,1] * 1000,

’wd’)

pylab.plot( data7[range (0 ,699 ,35) ,0] ** 0.5, data7[range (0 ,699 ,35) ,1] * 1000,

’ws’)

pylab.plot( data8[range (0 ,699 ,35) ,0] ** 0.5, data8[range (0 ,699 ,35) ,1] * 1000,

’wo’)

pylab.plot( data1[range (0 ,699 ,35) ,0] ** 0.5, data1[range (0 ,699 ,35) ,1] * 1000,

’k^’,label=’2.9mm ID’)

pylab.plot( data2[range (0 ,699 ,35) ,0] ** 0.5, data2[range (0 ,699 ,35) ,1] * 1000,

’kd’,label=’3.8mm ID’)

pylab.plot( data3[range (0 ,699 ,35) ,0] ** 0.5, data3[range (0 ,699 ,35) ,1] * 1000,

’ks’, label=’7.1mm ID’)

pylab.plot( data4[range (0 ,699 ,35) ,0] ** 0.5, data4[range (0 ,699 ,35) ,1] * 1000,

’ko’, label=’10.8 mmID’)

pylab.legend ()

pylab.xlabel(r’$t ^{1/2}(s)$’)

pylab.ylabel(r’$l[mm]$’)

pylab.legend(loc=’upper left’)

pylab.savefig(’lvst0 .5.png’)

pylab.show()

• The Python script resulted in the two plot below.

• For the case of 5.0cS PDMS, the time for at least one of the top reach the top of the tube is1.4s so the run time is 1.4s which is longer than that of the case of 0.65cS PDMS. The plotof meniscus height to the time and the plot of meniscus height to the square root of time areshown below:

45 of 51

Page 46: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

In this tutorial, gnuplot is used for plotting the residual of the numerical computation rather thanmatplotlib since matplotlib requires more complicated code while using gnuplot is simpler:

• Use gedit to create a script Residuals at the top-level case directory. This script plots theresiduals in log scale and save the plot in .png format also at the top-level case directory for0.65cS and 5.0cS cases.

set term png

set output "reslog065.png"

set autoscale

set logscale y

set ylabel ’Residual ’

set xlabel ’Iteration ’

plot "< cat log | grep ’Solving for p_rgh ’ | cut -d’ ’ -f9 | tr -d ’,’" title

’Residual ’ with lines

set term png

set output "reslog500.png"

set autoscale

set logscale y

set ylabel ’Residual ’

set xlabel ’Iteration ’

plot "< cat log | grep ’Solving for p_rgh ’ | cut -d’ ’ -f9 | tr -d ’,’" title

’Residual ’ with lines

46 of 51

Page 47: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

12 Summary and Conclusion

This tutorial has introduced OpenFOAM framework which is capable of solving fluid mechanicproblems using CFD and also many other general physic problems. In this tutorial, “CapillaryRace” is the subject to study using OpenFOAM. The problem features fluid raising in four tubeswith different diameters under micro-gravity environment. The installation of OpenFOAM Frame-work on any Window 7 personal computer and other necessary software and tools are presented.Next, the tutorial details step-by-step how to use OpenFOAM Framework for preparing Geometryand Meshing using SALOME, preparing OpenFOAM case including initial conditions and bound-ary conditions, solver parameters, then running the solver and extracting data and finally makingthe simulation and plotting the result.

The geometry set-up in this tutorial is simplified than the set up of the experiment. The entranceeffect when the fluid enter the capillary tubes from the reservoir, the drag effect and the movingcontact line from the surrounding air are neglected. The capillary raise in each tube is also con-sider symmetrical. The following conclusions could be made regarding the comparison betweenOpenFOAM simulation results and experimental results.

• The 0.65cS PDMS generally rises faster than do the 5.0cS PDMS especially for the longerorder of time scale.

47 of 51

Page 48: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

• The “Capillary race” by simulation is similar to the “race” in experiment in term of the orderof the meniscus height at “finish time” of 0.7s. From low to high, the order are 10.8mm,7.1mm, 2.9mm, 3.8mm ID for 0.65cS PDMS and 2.9mm, 3.8mm, 10.8 mm, 7.1 mm ID for5.0cS PDMS.

• It tooks shorter or in other word the fluid ascends faster according to the simulation than inthe experiment. It takes only 0.7s for the simulation to reach the state of 2s in the experiment.Recall that the simulation stops when one of the for tube has the fluid reaches it top. Thelonger simulation result for the case of 5.0cS PDMS is also shown. For the case of 5.0cSPDMS, OpenFOAM result for the order of the meniscus height when the simulation stopsat 1.4s is also similar to the experiment stop at 2.0s. The order from low to high is 2.9mm,3.8mm, 7.1 mm and 10.8 mm ID.

• The difference of the time scale of the rate of rise between OpenFOAM results and experi-mental result challenges two things: first is that the entry effect and the moving contact lineactually dampen the rise which are still not included in this tutorial; second, finer mesh andmore accurate numerical method needs to be applied for more numerical converge and reliableresults. Parrallel processing, smart and adaptive meshing, fine-tuning boundary conditionsand numerical algorithm are suggested for further simulation.

• The bright side of the OpenFOAM simulation of “Capillary race” it takes short time forroughly correct simulation of the problem. Only 40 minutes is needed for 1000 data point of1.4s of 5.0 cS fluid raising in each tube and 96 minutes for 0.7s of 0.65cS for the same datapoints.

48 of 51

Page 49: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

Appendix A OpenFOAM Academia, Open-Source Community Com-mercial Groups around the world

Category Company/Institution (Origin) Expertise

Academic University of Genoa, Chalmers Universityof Technology, FSB University of ZagrebXi’an Jiaotong University, University of Mas-sachusetts, Amherst, Pennsylvania State Uni-versity

CFD Research In-stitution

Consultancy/Commercial

ESI-group (France), Engys Open-source BasedEngineering include Helyx-OS

avid OpenFOAMmaintain and de-vlopment

Wikki Ltd., Wikki GmbH. (UK and Germany),TOTALSIM(UK) ICE-sf(Austria), ICON (Ger-many), DHCAE Tools, BlueCape (Portugal)

OpenFOAM-based consultant

FluiDyna Culises (Germany) CommercializeGPU-basedOpenFOAM

Open-SourceCommunity/

Interested groups

openfoamworkshop, extend-project.de includingopenfoamwiki.net(Europe),

major contributorcommunity

The CoCoons Project (Europe) OpenFOAM doc-ument project

OpenCAE.jp(Japan) Japan Veri-fication andValidation Group

49 of 51

Page 50: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

Appendix B List of Open-Source tools for OpenFOAM Framwork

Category Software/Tools/Package Description

PreProcessing OpenCascade, Salome Platform, Code-Saturn CAE platformincluding CADfunction, meshand also solver

Ensight, Gmsh, Netgen OpenFOAM-supported MeshGeneration

CFD Solver/Utility/ Data

Extraction

OpenFOAM, Code-Aster, Gerris, Palabos FlowSolver, Stanford University Unstructured Elmer

native CFD andmultiphysic simu-lation extension

PyFOAM, swak4Foam, setDiscreteFields Solver ParameterControl

Post Processing/Visualization

ParaView, Ensight, Visit, Blender Visualization pro-gram

matplotlib, techplot, gnuplot Plotting program

50 of 51

Page 51: Capillary Race in Circular Tubes using OpenFOAMME448 \Capillary Race" in Circular Tubes using OpenFOAM Duc Nguyen \Today, OpenFOAM is a proven player in commercial CFD and academic

ME448 “Capillary Race” in Circular Tubes using OpenFOAM Duc Nguyen

References

[1] avconv documentation, www.libav.org/avconv.html.

[2] Blender, www.blender.org.

[3] Community-driven releases of openfoam, www.extend-project.de.

[4] Contrib/pyfoam - openfoamwiki, openfoamwiki.net/index.php/Contrib/PyFoam.

[5] Contrib/swak4foam - openfoamwiki, openfoamwiki.net/index.php/Contrib/swak4Foam.

[6] The design analysis kit for optimization and terascale applications (dakota),www.dakota.sandia.gov/software.html.

[7] matplotlib: python plotting, www.matplotlib.org.

[8] Openfoam (open source field operation and manipulation), www.openfoam.com.

[9] Openfoam workshop, www.openfoamworkshop.org.

[10] Paraview - open source scientific visualization, www.paraview.org.

[11] Salome plaform, www.salome-platform.net.

[12] Hrvoje Jasak, Openfoam: a year in review, 2010.

[13] Richard Courant, Kurt Friedrichs, and Hans Lewy, On the partial difference equations of mathematical physics,IBM journal of Research and Development 11 (1967), no. 2, 215–234.

[14] Joel Guerrero, 2014 winter session - dicca, university of genoaintroductory openfoam course-training with anoverview to numericaloptimization using dakota, www.dicat.unige.it/guerrero/OpenFOAMcourse2014a.html.

[15] Edward W Washburn, The dynamics of capillary flow, Physical review 17 (1921), no. 3, 273.

[16] Andrew Paul Wollman, Capillarity-driven droplet ejection, 2012.

51 of 51