Sie sind auf Seite 1von 51

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen
ngmaduc@gmail.com
March 22, 2014

Tutorial Overview

This tutorial presents two major topics: the introduction to OpenFOAM, a well-known opensource 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].

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

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Today, OpenFOAM is a proven player in commercial CFD and academic research [12], said
Hrvoje Jasak, main creator of OpenFOAM and also Director of Wikki Ltd., a UK-based OpenFOAM Consultancy said in the 6th International OpenFOAM Workshop [9], Penn State University
in 2011. The OpenFoam workshop has been annually held since 2006 visting 6 countries in 3 continents. Main users of OpenFOAM include industrial CFD consultancies, academic institution,
community. According to extend-project.de [3], the major OpenFOAM community, around 50
groups are active around the world using and developing OpenFOAM as the main research and/or
services. Several groups with details information are listed in Appendix A of this tutorial. The
contributions of users from these vibrant community such as creating and sharpening solvers for
OpenFOAM 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. OpenFOAM
core 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 including
also 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 and
choose some of those as the tools to solve the problem in this tutorial and to detail the instruction. SALOME [11], a well-known CAE platform, is used for pre-processing, ParaView [10], also
a well-known visualization program for post-processing, matplotlib [7] for plotting, built-in OpenFOAM utilites and Python program such as PyFoam [4] and swak4Foam [5] for manipulating the
OpenFOAM solver. Appendix B provides a description of several notable tools to work within
OpenFOAM framework. This tutorial opens the door for users to open-source code world and
learning opportunities of UNIX, python, C programming, and code development. It also fosters
users understanding of the underlying algorithms and computation for numerical simulation.

Figure 2: OpenFOAM Framework Structure

2 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

The Capillary Race Overview

This subject of this tutorial is simulation of sudden capillary rise in families of cylindrical tubes
in micro- gravity environment during drop tower experiments. Such experiments typically consist
of a fluid filled chamber mounted to an experiment rig which is then dropped while a high-speed
cameras captures the response of the fluid. The experiment corresponding to this tutorials is part of
the 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 each
partially submerging width depth of 10mm in PDMS that fills a reservoir. These four cylinders
then experience 2s drop test in which the capillary forces dominate driving the rise. The rate of
the rise is different so that synchronization the video of these rises looks like a Capillary Race as
shown 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 by
Wollman [16]. In this tutorial, the same experiment will be set up in OpenFOAM framework
aiming to produce the corresponding CFD simulation. The simulation produces animation which
could be directly compared with experimental video; it is also can be extracted for plotting against
experimental 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 ID
circular 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 length
within 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 of
67mmin (d) 10.8mm ID tube. The arrow highlights the optimal tube used to achieve maximumflow
length within the freefall time. [16]

3 of 51

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 rise
in circular tubes height l (t) is plotted against t and t 1/2 for 0.65cS (solid symbols) and 5cS
PDMS (open symbols). Predicting the flow that travels the farthest in the 2.1s drop time available
is an optimization problem between capillary, inertial, and viscous forces as functions of tube
dimensions. [16]

The Overall Workflow

The tutorial presents step-by-step instruction to solve the Capillary Race problem based on the
OpenFOAM framework. The following list outlines the steps from initial setup to the simulation
result:
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 Parameters
and 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 results
with matplotlib

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 which
it runs. In this tutorial, the choosen method is to build Ubuntu, a free operating system on a
virtual machine, VMware Player, also a free and popular virtual machine software. VMware
Player software is installed on a host computer installed with Windows 7 (64-bit).
4 of 51

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 a


free version of VMware Player compatible with Windows 7 (64-bit)
Installation of VMware Player is similiar to other Windows 7 software. After installation, the
start screen of VMware Player looks like below:

An image of Ubuntu 13.04 (64-bit) code-name Raring Ringtail is recommended as the operating 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 as
the installer disc image file
The next steps include naming the virtual machine, setting a personal account, specifying
the disk capacity for your virtual machine. It is recommended to have at least 20GB for the
disk size and stored as a single file to enhance the performance of the virtual machine or as
Split for moderate amount of capacity. During installation, other hardware configuration is
also required. Below is an example of configuration for a virtual machine. Click Finish to
start the installation of Ubuntu.

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

5 of 51

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 be


logged 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 recommended for OpenFOAM users to have basic knowledge such as file system, control command,
terminal, application installation in Ubuntu. Some OpenFOAM training course includes good tutorial on the essential Linux for OpenFOAM [14]. Several essential tasks for this tutorial are listed
as below:
Open a terminal which is the main communication tool to connect with OpenFOAM Framework. 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 combination 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/or
directories, 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

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Understand the path and environment variables of files and directories in Ubuntu. For example, / is the home folder which also is a good place to include working directories for
applications 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 OpenFOAM. SALOME also includes many necessary libraries and tools for OpenFOAM Framework 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 binaries version 7.3.0 for Ubuntu 13.04 (64 bits). The downloaded file is a zipped file name
InstallWizard_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 Archive
Manager window, click Extract and choose the destination folder. The result is the installer
folder. 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 like
the following screen-shot.

The graphic SALOME v7.3.0 Installation Wizard opens. The installation is composed of 8
steps. 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 choice
of the products to be installed then the installation progress will begin. Some steps are shown
in the following screen-shots.

7 of 51

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 to
kernel folder of SALOME which is just installed and run the script salome.sh by command
source salome.sh every time opening a new terminal; another better one is to add to it the
end /.bashrc script.

Once the path and environment variables are acknowledged by Ubuntu, SALOME could be
started anywhere. To start SALOME, open a new Terminal and type runSalome. Salome
should start and open the main working window.

8 of 51

ME448

5.4

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Install OpenFOAM core package

Before the installation of OpenFOAM core package, it is recommended to add OpenFOAM


to the application source list and update Ubuntu with the latest package. The step is shown
as the following screen-shot.

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

9 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

The OpenFOAM package installation is completed with the reminder to add the bashrc script
of OpenFOAM the main bashrc script. This is done similiar to the way to configure terminal
for Salome.

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

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

10 of 51

ME448

5.5

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Install PyFoam, swak4Foam

PyFoam is a set Python programs designed to manipulate and enhance the run of OpenFOAM
solver. In this tutorial, PyFoam will be used to run the solver job and monitor the initial residuals
and continutiy. To install PyFoam, follow these steps:
Download the PyFoam tar package at http://openfoamwiki.net/index.php/Contrib/PyFoam
and unzip the tar package using Archive Manager or built-in tar application of Ubuntu. The
destination is suggested to be home folder.
Go inside the PyFoam folder and run the setup python script. Since the requisite libraries
for 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 should
be linked to OpenFOAM.

11 of 51

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 extracting
data from OpenFOAM result and/or setting the boundary and initial conditions. swak4Foam could
be installed using instruction from openfoamwiki.net/index.php/Contrib/swak4Foam. This tutorial 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 lexical
analyser. 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 swak4foam
0.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-e
html
Unzip the swak4Foam package to get the installer folder whose name is swak4foam-OF22x and
move the patch inside this folder. The folder structure of swak4Foam looks like he following
screen-shot.

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

12 of 51

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 such
as funkySetFields. The result should display the swak4Foam version as in the following
screen-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 OpenFOAM 2.2.2 without any configuration. ParaView could process the outputs of OpenFOAM
computation as still images. These images could be combined to make a video to simulate the
13 of 51

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 these
is 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 procedural
state machine resembling MATLAB. Users can easily use syntaxes as simple as ones in MATLAB
to extract then plotting data for example in this tutorial the height of the capillary rise. Installation
of matplotlib is described as following steps.
Download a zip .gz package from http://matplotlib.org/downloads.html. In this tutorials, 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 python
setup script with the prefix referring to SALOME directory where Python is installed. The
command 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
6.1

Prepare and Import Geometry and Mesh with Salome


Create Geometry for four capillary tubes

The section describes the steps using SALOME to prepare geometry and mesh for the four tubes
with 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 Geometry
button or choose from the environment drop-down list to activate Geometry module. A window in
the 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 do
this, Click File > Properties and change Length units to mm as shown in the following screen-shot.

14 of 51

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 these
tubes 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. Enter
the radius of 1.45 and the height of 160 for the first cylinder then click on Apply and Close
as 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 New
Entity>Basic>Point. Enter the coordinate (0,8,0) for x,y,z coordinates for the position of
second tube as the following screen-shot. Do the same thing to create the position for the
third and the fourth tubes at 20 and 36 mm respectively in y-axis of YZ-plane.

15 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

The other tubes are created using cylinder function of Geometry module. However, this time
the base point and the vector will be used for the construction of the tubes. Choose the
option as as the following screen-shot. Enter the points created above as base point and Oz
as the vector then enter the radii 1.9, 3.55 and 5.4 and the height of 160. Click Apply after
entering the set of parameters for the second and the third tubes, click Apply and close for
the fourth tubes. By default, the tubes are named Cylinder 1 to Cylinder 4 and could be
replaced by appropriate name if necessary. All the four cylinders should be displayed in the
OCC 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 be
used in the meshing process.
The main mesh later is on a single domain; therefore, four cylinders will be combined
together to become only one subject. This could be done using Fuse function. Select
Operations>Boolean>Fuse. The Fuse Objects window opens, click on the arrow button
and choose the 4 cylinders in the Object Browser. Four objects should be updated in the
16 of 51

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 Fuse
object 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 are
needed as inlet and outlet. One curved face represents the wall and one side edge represents
the height. SALOME has the Create Group function to select and create those objects. Select
New Entity>Group>Create Group. Choose Face as Shape Type, Fuse 1 as the Main Shape
as 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. For
example, choose the inlet of the first cylinder, this should be highlighted in white as shown
in the following screen-shot. Name it Inlet1 also.
17 of 51

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 Create
Group Window as in following screen-shot. The face object Inlet will be created and added
under the Fuse object Fuse 1 in Object Browser.

The Apply button keeps the Create Group Window open to select new objects. Repeat the
process to select all necessary inlet, outlet, wall and side edges of four tubes. For the side
edges, 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 by
choosing from the single corresponding objects in the object browser. Click Apply and Close
when finishing create all desired objects. The final list of objects under the Fuse 1 object is
shown in following screen-shot.

18 of 51

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 to
double check the object creation. Click View>Hide All then right click or use eye button to
show the desired object. For example, if the Inlet or the Side Edges or the Wall are chosen
to 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 dropdown 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 Discretion. 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 which
is Fuse 1 in this the tutorial.
The Create Mesh window opens. Choose Triangle (Mefisto) as the Algorithm from the Dropdown list. Click on the Gear button to choose Length from Edges 1 as Hypothesis as shown
in the following screenshot.
19 of 51

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 shown
in the following screen-shot.

Click on the Gear button to choose and configure the Hypothesis. Enter 20 as Number of Segments and Equidistant Distribution as Type of Distribution in the Hypothesis Construction
window as in the following screen-shot. Click OK.

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

20 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Click Mesh>Compute Mesh to start meshing. A window appears showing progress and RAM
usage information; after the meshing calculation complete, the meshing information appears
as 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 inlet
and outlet of each tube will be related using Projection 2D function so that the triangular
mesh of the inlet and the outlet will be the same. Click Mesh>Create Sub-Mesh. Name
the Sub-Mesh, choose the overall mesh Mesh 1 as the main Mesh. Choose the geometry by
clicking at the desired object in the Object Browser window, for example Outlet1, the outlet
of the first tube to which the first inlet projecting to. Click on the Gear button to choose
the Hypothesis which is the Source Face. In the Hypothesis construction window, choose the
Inlet1 as the Source Face then click OK. Click Apply on the Create Mesh window.

21 of 51

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 same
Create Mesh window as above, choose the combined wall face under Fuse Object. For the
Algorithm, choose Quadrangle (mapping) from the drop-down list. The Hypothesis could be
left blank as default chosen as standard.

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

22 of 51

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 order
to do that, another Sub-mesh is needed. Click Mesh>Create Sub-Mesh, choose Side edge
as the geometry. Click on the Gear button to choose and configure the Hypothesis. Enter
100 as Number of Segments and Equidistant Distribution as Type of Distribution in the
Hypothesis 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

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Click Mesh>Compute Mesh to start meshing. Once the mesh computation succeed, the Mesh
information is the final information for the mesh used in this tutorial. The mesh should also
be 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 exported from SALOME needs to include the boundaries information. This is done by the following
steps:
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 Object
and choose Direct Geometry Selection. From the Object Browser window, choose Inlet which
is the combined Inlet of the Fuse. The Geometrical Object is updated. The name of this
boundary 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 of
the Create Group Window and choose the color. Click Apply to finish creating the boundary
for Inlet.

24 of 51

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 the
Outlet. The boundary is now colored as in the following screen-shot. The group of faces as
boundaries 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 do
this, within the Mesh environment, Click File>Export and choose UNV file. Choose the place
to save this mesh, later it will be moved inside an OpenFOAM folder.

Introduction to OpenFOAM directory structure

Before discussion on starting an OpenFOAM study, it is strongly recommended for users to understand the organization of OpenFOAM package. A good place for reference is listed in [14]. The
whole OpenFOAM package is installed in $WM_PROJECT_DIR where all the important information
of the package is stored such as compile scripts, environment variables, source codes and also binaries for libraries, solver and utilities, etc. Exploring this folder will help users gaining a deep
understanding about how OpenFOAM code using theory of physic and CFD to solve many problems numerically. Users are also provided with resource to test, run, modify and further to create
solver or utilities based on OpenFOAM. In the scope of this tutorial, only the directory structure of an OpenFOAM case will be presented. However, always remember that the understanding
OpenFOAM package folder is very important since it interacts directly with the case folder.

25 of 51

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-level
directory of an OpenFOAM case is stored as a folder in the folder run inside the user working
directory $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. Those
sub-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 general
physical properties
3. constant/polyMesh: contains the entire mesh data and information such as points, faces and
boundaries.
4. 0: contains the boundary conditions, initial conditions, phase interactions. Both scalar field
and 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 are
applied such as PyFoam and swak4Foam. One important thing remember is always to run OpenFOAM solvers and utilities in the top-level case directory.

Prepare an OpenFOAM case directory and importing the mesh

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

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 the
run 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 CapillaryRace500
for 5.0cS PDMS.
In Section 6.4, a mesh with .UNV form has already been created by SALOME and now ready
to 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. Make
sure 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 OpenFOAM.

27 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

The Mesh should be reported OK. Another way to check the completeness of this mesh
conversion task is go directly to the sub-folders at which the OpenFOAM mesh information
is stored. Go inside the constant/polyMesh folder and check the points file, many points
should 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 SALOME
and take them default in meter dimension. OpenFOAM also has the utilities to scale dimension from meter to millimetre. Following the steps below to convert from meter to millimetre
and check the points for the effect.

28 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Setting Transport Properties and Contact Angle, Boundary and


Initial Conditions. Setting Solver Parameters and Stopping Criteria for Transient Solution

9.1

Setting Transport Properties and Contact Angle

Before setting the transport properties of fluid phases ins this tutorial, one important parameter to remember is to set gravity to 0 since the four capillary tubes are subjected to
microgravity environment. To do that edit g inside the constant folder with gravity is 0 in
all 3 direction.
dimensions
value

[0 1 -2 0 0 0 0];
( 0 0 0 );

All the transport properties of fluid phases are described in the transportProperties inside
the 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 for
both two phases and surface tension between two phases. Phase 1 is defined as the PDMS
and 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.65 e -06;
rho
rho [1 -3 0 0 0 0 0] 760;
...
phase2
{
transportModel Newtonian ;
nu
nu [0 2 -1 0 0 0 0] 1.48 e -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

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

phase1
{
transportModel Newtonian ;
nu
nu [0 2 -1 0 0 0 0] 5.0 e -06;
rho
rho [1 -3 0 0 0 0 0] 913;
...
phase2
{
transportModel Newtonian ;
nu
nu [0 2 -1 0 0 0 0] 1.48 e -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 edit
for a static constant contact angle of zero degree.
...
Wall
{
type
theta0
limit
value

c o n s t a n t A l p ha C o n t a c t A n g l e ;
0;
gradient ;
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 Section
6.4. Each boundary is the combination of faces from each tube. Since the name boundary face is
copied from the tutorial case, it is an important task to ensure renaming the patch in OpenFOAM
to match with the name in SALOME before setting boundary and initial conditions. The boundary
faces 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 this
tutorial is kept the same as ones in the tutorial case of capillaryRise in a single tube. Following
the 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 for
boundaries as following. The other information should be kept.
Repeat this edit task for U and p_rgh
...
boundaryField
{
Inlet
{
type
value
inletValue
}

inletOutlet ;
uniform 1;
uniform 1;

Outlet

30 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

{
type

zeroGradient ;

}
Wall
{
type
theta0
limit
value

c o n s t a n t A l p ha C o n t a c t A n g l e ;
0;
gradient ;
uniform 0;

}
...
...
boundaryField
{
Inlet
{
type
value
}
Outlet
{
type
value
}

pressureInletOutletVelocity ;
uniform (0 0 0);

pressureInletOutletVelocity ;
uniform (0 0 0);

Wall
{
type
value

fixedValue ;
uniform (0 0 0);

}
...
...
boundaryField
{
Inlet
{
type
value
}
Outlet
{
type
value
}

fixedValue ;
uniform 0;

fixedValue ;
uniform 0;

Wall
{
type

fixedFluxPressure ;

}
...

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

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.5 e -3 -1.5 e -3 0) (1.5 e -3 1.5 e -3 10 e -3);
fieldValues
(
volScalarFieldValue alpha1 1
);
}
boxToCell
{
box ( -2e -3 6e -3 0) (2 e -3 10 e -3 10 e -3);
fieldValues
(
volScalarFieldValue alpha1 1
);
}
boxToCell
{
box ( -3.6 e -3 16.4 e -3 0) (3.6 e -3 23.6 e -3 10 e -3);
fieldValues
(
volScalarFieldValue alpha1 1
);
}
boxToCell
{
box ( -5.4 e -3 30.6 e -3 0) (5.4 e -3 41.4 e -3 10 e -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 of
alpha1.org and rename it to alpha1

32 of 51

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 like
following:

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, if
OpenFOAM could not recognize paraFoam, it is necessary to re-run the bash script as shown
in 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 of
display. Edit the parameters in Object Inspector window as shown in the following screenshot and click Apply.
33 of 51

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 initial
PDMS filled should be shown. At this point, setting Boundary and Initial Conditions are
completed.

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

34 of 51

ME448

9.3

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Setting Solver Parameters and Stopping Criteria for Transient Solution

Solver Parameter and Stopping Criteria are important as they define how solver will run to get
converge and reliable results. These are stored at 3 files inside system sub-fodler: fvSchemes for
finite element algorithm, fvSolution for solver algorithm and convergence criteria, controlDict
for stopping criteria. In this tutorial, the settings of the tutorial case are generally kept; only
residual 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 full
explanation for the parameters could be found at OpenFOAM reference such as citeJoel. In
this 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.4s
and the time step is still 0.001s. For the first time, the run time may be not known so 2s
could be set for the run time but after the first trial run, the time for at least one of the tube
has fluid reaching its top is known so the run time could be modified.
...
stopAt
endTime ;
endTime
0.7;
deltaT
0.001;
...
runT imeModifiable yes ;
adjustTimeStep no ;
maxCo
0.2;
maxAlphaCo
0.2;
...

The Capillary Race in this tutorial involves transient problem with each time step itself is
constraint 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 solver
algorithm will continue to run until it satisfies the known-goood chosen solver parameters. The
Courant number represents Courant-Friedrichs-Lewy (CFL) condition for stability solution
for 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 condition
is indispensable. The maximum Courant number in this tutorial is also kept the same as the
tutorial case and equal to 0.2. It is stored in controlDict file.
35 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Each time step solution is allowed a specific number of iteration so-called the maximum
number of iteration to meet both residual and Courant number condition. The Courant
number condition is already set above. For the maximum number of iteration, use gedit to
edit 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 time
step and the new block of residual control is added for the final residual of each time step is
1e-05.
...
PIMPLE
{
momentumPredictor no ;
nOuterCorrectors 100;
// nCorrectors
3;
n N on O r t ho g o n al C o r re c t o rs 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 and


swak4Foam

The conventional way of running a solver is simply use the OpenFOAM command and log to a
file. 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, the
command tail -f log could be used any time to view the log. The good thing with OpenFOAM
is its features of accepting customized scripts to manipulate to run. In this tutorial, PyFoam has
already extracted the information from solution such as Initial Residual and Continuity to plot
them on-the fly. It is recommended to prepare all necessary and/or customized utilities coupling
with the solver before running solver with PyFoam. The simulation time is usually long and it is
unfavourable to finish the run and forget to include a script which needs to be couple with the run
on-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 domain
inside 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 the
center line of the tubes at each time step. The meniscus height could be achieved by sampling the
36 of 51

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 is
1 for the region filled with PDMS while volume fraction of alpha1 is 0 if the region is filled with
air. The meniscus is where the volume fraction change from 1 to 0. In this tutorial, the meniscus
height is defined where the volume fraction is 0.5. The task of sampling volume fraction could be
done by using the sample utility of OpenFOAM. This could also be done using a Filter in Paraview
which even features plotting function. In this tutorial, script method based on swak4Foam will be
used.
The first step is to prepare a dictionary for sampling using swak4Foam. Since this dictionary is not part of the tutorial case, a new file will be created from scratch. Use gedit to
create four files name sampledSets1, sampledSets2, sampledSets3, sampledSets4 inside
system folder to sample the meniscus height for 4 tubes. For example the sampledSets1 is
shown 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 sampledSets1


except 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 "
" l i b s i m p l e S w a k F u n c t i o n O b j e c t s . so "
" li bs wak Fu nc ti onO bj ec ts . so "
" l i b si m p l eF u n c ti o n O bj e c t s . so "
);
functions
{
# include " sampledSets1 "
# include " sampledSets2 "
# include " sampledSets3 "
# include " sampledSets4 "
}
...

37 of 51

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 should
start the interFoam and record the initial residuals and continuity.

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

38 of 51

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 height
data in file with name according to swak4Foam dictionary.

39 of 51

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 with


avconv, Plotting the results with matplotlib

11.1

Visualization with Paraview

ParaView is a powerful visualization program packing natively with OpenFoam. The mesh data and
the solution are imported to ParaView using the paraFoam command. In this tutorial, ParaView
will help to visualize solution of each time-step then save these solutions as still images which will
be 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 at
the 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 to
display, choose the kind of display. Edit the parameters in Object Inspector window as shown
in the following screenshot and click Apply.

40 of 51

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 shown
in 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 defined
and formatted in Object Inspector. The Pipeline Browser and the visual result could be like
the following screenshot.

41 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Use the Control toolbar in ParaView, users could visualize the dynamic transient solution or
see 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: one
still image per time step. A video encoder program such as avconv or ffmpeg combine all the
images to make a video in standard video codec such as H.264. This tutorial will demonstrate how
to 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

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-level
case directory will be used for the destination folder and height will be used for the prefix in
this tutorial. Click OK, ParaView will automatically run and after the process is done, the
image file will appear in the destination folder.

Browser

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

43 of 51

ME448

11.3

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Plotting the Results with matplotlib

This last section of this tutorial presents how to use plotting program in Ubuntu such as matplotlib
to plot the meniscus height of the capillary rise acquired in Section 10. This Section will also show
the way to plot the residual of the numerical computation. Installation of matplotlib and gnuplot
was done in Section 5.6. Follow the steps below to produce two figures: one is the plot of meniscus
height 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 in
Section 10. The file is named fillHeight.py in this tutorial and could be saved anywhere in
Ubuntu. However, it is recommended to the file in the running directory or the top-level case
directory. The figures for the plots will be saved as .png format at the same place as the
python file. The pylab and numpy libraries imported in the Python code are included with
SALOME and matplotlib.
import pylab , numpy
data1 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace065 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 1 /0/ fillHeight1 )
data2 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace065 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 2 /0/ fillHeight2 )
data3 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace065 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 3 /0/ fillHeight3 )
data4 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace065 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 4 /0/ fillHeight4 )
data5 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace500 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 1 /0/ fillHeight1 )
data6 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace500 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 2 /0/ fillHeight2 )
data7 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace500 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 3 /0/ fillHeight3 )
data8 = pylab . loadtxt ( / home / ducnguyen / OpenFOAM / ducnguyen -2.2.2/ run /
capillaryRace500 / postProcessing / s w a k E x p r e s s i o n _ f i l l H e i g h t 4 /0/ fillHeight4 )
pylab . figure (0)
pylab . plot ( data5 [ range (0 ,699 ,35) ,0] ,
pylab . plot ( data6 [ range (0 ,699 ,35) ,0] ,
pylab . plot ( data7 [ range (0 ,699 ,35) ,0] ,
pylab . plot ( data8 [ range (0 ,699 ,35) ,0] ,
pylab . plot ( data1 [ range (0 ,699 ,35) ,0] ,
label = 2.9 mm ID )

data5 [ range (0 ,699 ,35) ,1]


data6 [ range (0 ,699 ,35) ,1]
data7 [ range (0 ,699 ,35) ,1]
data8 [ range (0 ,699 ,35) ,1]
data1 [ range (0 ,699 ,35) ,1]

44 of 51

*
*
*
*
*

1000 ,
1000 ,
1000 ,
1000 ,
1000 ,

w ^ )
wd )
ws )
wo )
k ^ ,

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.8 mm ID )
pylab . plot ( data3 [ range (0 ,699 ,35) ,0] , data3 [ range (0 ,699 ,35) ,1] * 1000 , ks ,
label = 7.1 mm 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.9 mm ID )
pylab . plot ( data2 [ range (0 ,699 ,35) ,0] ** 0.5 , data2 [ range (0 ,699 ,35) ,1] * 1000 ,
kd , label = 3.8 mm ID )
pylab . plot ( data3 [ range (0 ,699 ,35) ,0] ** 0.5 , data3 [ range (0 ,699 ,35) ,1] * 1000 ,
ks , label = 7.1 mm 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 is
1.4s so the run time is 1.4s which is longer than that of the case of 0.65cS PDMS. The plot
of meniscus height to the time and the plot of meniscus height to the square root of time are
shown below:
45 of 51

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 than
matplotlib 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 the
residuals in log scale and save the plot in .png format also at the top-level case directory for
0.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

ME448

12

Capillary Race in Circular Tubes using OpenFOAM

Duc Nguyen

Summary and Conclusion

This tutorial has introduced OpenFOAM framework which is capable of solving fluid mechanic
problems using CFD and also many other general physic problems. In this tutorial, Capillary
Race is the subject to study using OpenFOAM. The problem features fluid raising in four tubes
with different diameters under micro-gravity environment. The installation of OpenFOAM Framework 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 Geometry
and Meshing using SALOME, preparing OpenFOAM case including initial conditions and boundary conditions, solver parameters, then running the solver and extracting data and finally making
the simulation and plotting the result.
The geometry set-up in this tutorial is simplified than the set up of the experiment. The entrance
effect when the fluid enter the capillary tubes from the reservoir, the drag effect and the moving
contact line from the surrounding air are neglected. The capillary raise in each tube is also consider symmetrical. The following conclusions could be made regarding the comparison between
OpenFOAM simulation results and experimental results.
The 0.65cS PDMS generally rises faster than do the 5.0cS PDMS especially for the longer
order of time scale.
47 of 51

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 order
of 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 for
5.0cS PDMS.
It tooks shorter or in other word the fluid ascends faster according to the simulation than in
the 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. The
longer simulation result for the case of 5.0cS PDMS is also shown. For the case of 5.0cS
PDMS, OpenFOAM result for the order of the meniscus height when the simulation stops
at 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 experimental result challenges two things: first is that the entry effect and the moving contact line
actually dampen the rise which are still not included in this tutorial; second, finer mesh and
more accurate numerical method needs to be applied for more numerical converge and reliable
results. Parrallel processing, smart and adaptive meshing, fine-tuning boundary conditions
and numerical algorithm are suggested for further simulation.
The bright side of the OpenFOAM simulation of Capillary race it takes short time for
roughly correct simulation of the problem. Only 40 minutes is needed for 1000 data point of
1.4s of 5.0 cS fluid raising in each tube and 96 minutes for 0.7s of 0.65cS for the same data
points.

48 of 51

ME448

Capillary Race in Circular Tubes using OpenFOAM

Appendix A

Duc Nguyen

OpenFOAM Academia, Open-Source Community Commercial Groups around the world

Category

Company/Institution (Origin)

Expertise

Academic

University of Genoa, Chalmers University


of Technology, FSB University of Zagreb
Xian Jiaotong University, University of Massachusetts, Amherst, Pennsylvania State University

CFD Research Institution

ESI-group (France), Engys Open-source Based


Engineering include Helyx-OS

avid OpenFOAM
maintain and devlopment
OpenFOAMbased consultant

Consultancy/
Commercial

Wikki Ltd., Wikki GmbH. (UK and Germany),


TOTALSIM(UK) ICE-sf(Austria), ICON (Germany), DHCAE Tools, BlueCape (Portugal)
FluiDyna Culises (Germany)

Open-Source
Community/
Interested groups

openfoamworkshop, extend-project.de including


openfoamwiki.net(Europe),
The CoCoons Project (Europe)
OpenCAE.jp(Japan)

49 of 51

Commercialize
GPU-based
OpenFOAM
major contributor
community
OpenFOAM document project
Japan
Verification
and
Validation Group

ME448

Capillary Race in Circular Tubes using OpenFOAM

Appendix B
Category
PreProcessing

List of Open-Source tools for OpenFOAM Framwork


Software/Tools/Package

Description

OpenCascade, Salome Platform, Code-Saturn

CAE
platform
including
CAD
function,
mesh
and also solver
OpenFOAMsupported Mesh
Generation

Ensight, Gmsh, Netgen

CFD Solver/
Utility/ Data
Extraction

OpenFOAM, Code-Aster, Gerris, Palabos Flow


Solver, Stanford University Unstructured Elmer
PyFOAM, swak4Foam, setDiscreteFields
ParaView, Ensight, Visit, Blender

Post Processing/
Visualization

Duc Nguyen

matplotlib, techplot, gnuplot

50 of 51

native CFD and


multiphysic simulation extension
Solver Parameter
Control
Visualization program
Plotting program

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
www.dakota.sandia.gov/software.html.

optimization

and

terascale

applications

(dakota),

[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, 215234.
[14] Joel Guerrero, 2014 winter session - dicca, university of genoaintroductory openfoam course-training with an
overview to numericaloptimization using dakota, www.dicat.unige.it/guerrero/OpenFOAMc ourse2014a.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

Das könnte Ihnen auch gefallen