cfd with opensource software - chalmershani/kurser/os_cfd_2011/samfredriks...cfd with opensource...

53
CFD with OpenSource software A course at Chalmers University of Technology Taught by H˚ akan Nilsson Project work: A buoyantBoussinesqSurfactantFoam Tutorial an Introduction to FAM Developed for OpenFOAM-1.6.ext Author: Sam Fredriksson Peer reviewed by: Hamidreza Abedi Martin Andersson Rolf-Erik Keck Ehsan Yasari Disclaimer: This is a student project work, done as part of a course where OpenFOAM and some other OpenSource software are introduced to the students. Any reader should be aware that it might not be free of errors. Still, it might be useful for someone who would like learn some details similar to the ones presented in the report and in the accompanying files. November 3, 2011

Upload: others

Post on 10-Mar-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

CFD with OpenSource software

A course at Chalmers University of TechnologyTaught by Hakan Nilsson

Project work:

A buoyantBoussinesqSurfactantFoam Tutorial

an Introduction to FAM

Developed for OpenFOAM-1.6.ext

Author:Sam Fredriksson

Peer reviewed by:Hamidreza Abedi

Martin AnderssonRolf-Erik Keck

Ehsan Yasari

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

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

November 3, 2011

Page 2: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

Contents

1 Introduction 2

2 Finite area method (FAM) 42.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Tutorial convectiveSurfactantTransport 73.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Brief problem description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 Creation of a solver for a surfactant using the finite area method . . . . . . . . . . . 8

3.3.1 Compilation of new solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.3.2 Adding the interesting FAM equations of surfactantFoam into buoyantBoussi-

nesqPisoSurfactantFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.3.3 Include *.H files in buoyantBoussinesqPisoSurfactantFoam.C . . . . . . . . . 133.3.4 Enable reading of Cs and Ds and defining Us in createFaFields.H . . . . . . . 14

3.4 Pre-processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4.1 Creating an area mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4.2 faSolution and faSchemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4.3 Boundary and initial conditions . . . . . . . . . . . . . . . . . . . . . . . . . . 173.4.4 Physical properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193.4.5 Turbulence models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.5 Running the case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.6 Post-processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.7 Files used for the buoyantBoussinesqSurfactantFoam solver and the convectiveSur-

factantTransport tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.7.1 Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.7.2 Case files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

1

Page 3: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

Chapter 1

Introduction

This project aims at giving a brief introduction to the finite area method of openFoam and applyingthe method to model a surfactant flow at the surface of a convective flow (Figure 1.1).

In Wikipedia a surfactant is defined as ”Surfactants are compounds that lower the surface ten-sion of a liquid, the interfacial tension between two liquids, or that between a liquid and a solid.Surfactants may act as detergents, wetting agents, emulsifiers, foaming agents, and dispersants”1.Surfactants are also interesting when it comes to gas exchange between liquids and gases and mymain interest of modeling surfactants is for its influence of gas transport between lakes/oceans andthe atmosphere. The work of McKenna is a good introduction of how surfactants can influence gastransport2.

Figure 1.1: Example of output from the convectiveSurfactantTransport tutorial, from this project,using buoyantBoussinesqPisoSurfactantFoam.

1http://en.wikipedia.org/wiki/Surfactant2S.P. McKenna, W.R. McGillis, ”The role of free-surface turbulence and surfactants in air-water gas transfer”,

International Journal of Heat and Mass Transfer, 2004

2

Page 4: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

The surfactant solver has thereby been coded as a merge of buoyantBoussinesqPisoFoam andsurfactantFoam into buoyantBoussinesqPisoSurfactantFoam. buoyantBoussinesqPisoFoam isa finite volume solver used for buoyant flow and surfactantFoam is a finite area solver used forsurfactant flows.

My interests of coupling these two methods are to use the functionality of the finite area methodto solve an area based problem and then eventually use more of the functionality of the finite areamethod, i.e. surface tracking and thereby being able to even introduce waves in the analysis.

This report starts with the introduction to the finite area method and then presents a tutorialusing the finite area method. The tutorial comprises first the inclusion of the finite area methodinto the buoyantBoussinesqPisoFoam solver and then the implementation of a surfactant model.

3

Page 5: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

Chapter 2

Finite area method (FAM)

2.1 Introduction

The finite area method (FAM) is implemented in the openFoam Extend Project 1.6 (OF16ext). Thefinite area method is a complement to the finite volume method (FVM) and can be used for exampleto study a surfactant present at the surface of a volume field.

The tutorial $FOAM_TUTORIALS/surfaceTracking/surfactantFoam/sphereTransport included inOF16ext solves the flow of a surfactant at a sphere, see Figure 2.1. In this tutorial there is howeverno coupling between the finite volume and the finite area method more than that the surfactant con-centration field is mapped onto the volume mesh for each time step. The velocities of the surfactant(finite area solution) is constant during the whole sphereTransport case.

Figure 2.1: Example of output of the sphereTransport tutorial case (tutorial supplied with theOF16ext installation).

4

Page 6: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

2.2. ARCHITECTURE

2.2 Architecture

The general architecture of the finite area method follows the finite volume method to a large degreeas can be seen in Figure 2.2. The finiteArea and the finiteVolume directories can be found inthe $FOAM_SRC directory.

finiteArea corresponds to finiteVolume.

faMatrices, faMesh, fields,interpolation, lnInclude and Make in the fa class correspondto the similar ones in the fv class.

areaMesh and edgeMesh correspond to volMesh and surfaceMesh.

faSolution/faSolution.H corresponds to lnInclude/fvSolution.H.

finiteArea/include contains the createFaMesh.H and faCFD.H, where faCFD.H is similar to thefile cfdTools/general/include/fvCFD.H in the finite volume class.

(a) fa directory (b) fv directory

Figure 2.2: Tree of the finiteArea and finiteVolume directories.

2.3 Discretization

The heart of the finite area method is the discretization of the surface integral transport equationson arbitrary polygonal unstructured meshes. The surface and line integrals are aproximated usinga mid-point rule. Face-edge interpolation require special treatment due to surface curvature. Thisinterpolation in an edge based local coordinate system can be seen in Figure 2.3 and is explainedbelow inspired by the excellent work of Z. Tukovic and H. Jasak1.

The discretization of the computational domain consists of the discetization of the time domainand the discretization of the space domain. The time domain is discretizized by splitting the so-lution time (solution time is here meant as the real time of interest, not CPU time or clock time)into discrete time steps ∆t. The equations are then solved in each time step, as in the finite volumemethod of OpenFOAM. The computational space domain is splitted into a finite number of flat con-vex polygonal control areas bounded by the straight edges of each control area. The control areas donot overlap and cover the computational space domain completely. The space (finite area) can beof any curved shape, where a flat surface as in the tutorial presented later in this report is a specialcase. Figure 2.3 shows two control areas SP and SN with the computational points P and N in theircentroids and the normal vectors nP and nN (note the similarity with the colocated structure of thefinite volume method of OpenFOAM). The geometry of the control areas and their boundary edges

1Finite area thin liquid film solver, Z. Tukovic, H. Jasak, Preprint submitted to Computer & Fluids, January 14,2011.

5

Page 7: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

2.3. DISCRETIZATION

are fully determined by the position of the vertices, of the mesh, denoted by i (points in OpenFoam).The edge e is shared by the neighbouring control areas SP and SN . The edge has a length, Le,and a unit normal vector ne. In OpenFOAM the definitions of the finite area mesh are found insubdirectories to the constant directory of the case directory as constant/faMesh directory whilethe points needed for the finite area mesh is found in the constant/polyMesh directory also usedfor the finite volume method.

Figure 2.3: Polygonal convex control areas SP and SN .

In order to account for curvature of the discetized surface (area), transformation of the centroidbased values to edge based values is carried out before solving the equations to be solved. The edgebased orthogonal coordinate system as well as the global Cartesian coordinate system can be seen inFigure 2.4. The interpolation is carried out by first transforming the centroid (control area centre)based value from the global Cartesian coordinate system to the edge based local coordinate system.When the edge based (edge centre) value has been calculated, it is transformed back to the globalCartesian coordinate system (centroid based). Linear interpolation of the average film velocity canbe used as an example. The edge based velocity is then interpolated as:

ve = (Te)T · (exTP · vP + (1− ex)TN · vN ) (2.1)

where ex is the interpolation factor which is the ratio of the geodetic distances eN and PeN , seealso Figure 2.4:

ex =eN

PeN(2.2)

and TP , TN and Te are the transformation tensors from the global Cartesian coordinate systemto the edge based local coordinate system as defined in Figure 2.4.

Figure 2.4: Global Cartesian coordinate system and edge based local coordinate system.

6

Page 8: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

Chapter 3

TutorialconvectiveSurfactantTransport

3.1 Introduction

This tutorial describes how to pre-process, run and post-process a case involving natural convectiveflow with a finite area model of the surfactant together with a three-dimensional domain solved withthe finite volume method. It also describes how to merge two solver into one, add the surfactantformulation and then to compile the new solver.

The geometry consists of a block filled with water, with a horizontal dimension twice the verti-cal (0.076x0.076x0.038m)(Figure 3.1). The surface is modeled as a slip boundary with cooling dueto evaporation. The sides of the box is modeled as cyclic boundaries while the bottom is modelledas an thermally isolated slip boundary.

The surfactant is modeled at the surface with a finite area approch using the FAM class avail-able in the extend version of openFoam (OF16ext). The natural convective flow is modeled by useof buoyantBoussinesqPisoFoam. A good introduction to this solver can be found athttp://openfoamwiki.net/index.php/BuoyantBoussinesqPisoFoam.

The simulation is performed without any turbulence model (laminar). This is done since it isintended to be used for direct numerical simulation (DNS). Please note that the mesh must be muchmore refined in an actual direct numerical simulation than in this tutorial to be able to capture theturbulent eddies properly.

7

Page 9: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.2. BRIEF PROBLEM DESCRIPTION

Figure 3.1: Geometry of the buoyantBoussinesqPisoSurfactantFoam tutorial case.

3.2 Brief problem description

The tutorial is describing a system driven by natural convection due to evaporation from the sur-face. It is also of interest to study the effect of different surface condition such as a clean surfaceand surface with a surface film, a surfactant. Up to now it is not fully understood which boundaryconditions to be used for these different surface conditions. It is therefore interesting to study theordinary boundary conditions such as slip and no slip, but it is also interesting to be able to modela surface film or surfactant at the surface, and validate the results against measurements.

The convective flow is calculated under the boussinesq approximation1. The boussinesq approx-imation is valid under the assumption that density differences are sufficiently small to be ne-glected, except where they appear in terms multiplied by g, the acceleration due to gravity. Inthe buoyantBoussinesqPisoFoam solver for incompressible flows the density is calculated as a lin-ear function of temperature as:

ρ(T ) = 1− β(T − Tref ), β = −(

1

ρ0

)∂ρ

∂T

∣∣∣∣ref

(3.1)

where ρ(K) is the effective (driving) kinematic density, β [1/K] is the thermal expansion coeffi-cient, T [K] is the temperature and Tref [K] is the reference temperature.

3.3 Creation of a solver for a surfactant using the finite areamethod

This section covers the necessary steps to create the buoyantBoussinesqPisoSurfactantFoam solverstep by step. The resulting files buoyantBoussinesqPisoSurfactantFoam.C and createFaFields.H

can also be found in Section 3.7. In the files I have noted the editing with //SF and //SF end whereI have edited the files.

1http://en.wikipedia.org/wiki/Boussinesq approximation buoyancy

8

Page 10: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.3. CREATION OF A SOLVER FOR A SURFACTANT USING THE FINITE AREA METHOD

3.3.1 Compilation of new solver

Copy the buoyantBoussinesqPisoFoam solver to where you want to place your own solvers. Then re-name buoyantBoussinesqPisoFoam.C into buoyantBoussinesqPisoSurfactantFoam.C. The nextstep is to edit the files in the Make directory and then compile the new solver without any changesin order to check that it works. This can typically be done as:

mkdir -p $WM_PROJECT_USER_DIR/applications/solvers/heatTransfer

cd $WM_PROJECT_USER_DIR/applications/solvers/heatTransfer

cp -r $WM_PROJECT_DIR/applications/solvers/heatTransfer/buoyantBoussinesqPisoFoam .

mv buoyantBoussinesqPisoFoam buoyantBoussinesqPisoSurfactantFoam

cd buoyantBoussinesqPisoSurfactantFoam

mv buoyantBoussinesqPisoFoam.C buoyantBoussinesqPisoSurfactantFoam.C

Then we have to edit the Make/files according to

buoyantBoussinesqPisoSurfactantFoam.C

EXE = $(FOAM_USER_APPBIN)/buoyantBoussinesqPisoSurfactantFoam

and compile with

wclean

wmake

You will then get an error since the Make/options has to be corrected with the correct path tobuoyantBoussinesqSimpleFoam due to that the readTransportProperties.H file is used in thebuoyantBoussinesqPisoFoam as well. The Make/options should therefore be as:

EXE_INC = \

-I$(WM_PROJECT_DIR)/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam \

-I$(LIB_SRC)/finiteVolume/lnInclude \

-I$(LIB_SRC)/turbulenceModels/incompressible/turbulenceModel \

-I$(LIB_SRC)/transportModels \

-I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel

EXE_LIBS = \

-lfiniteVolume \

-lmeshTools \

-lincompressibleTurbulenceModel \

-lincompressibleRASModels \

-lincompressibleLESModels \

-lincompressibleTransportModels \

-llduSolvers

Now try once again to compile and it will go through.

wclean

wmake

In order to make it work for the solver where the finite area method is included we need to add afew lines to the Make/options file as well. It should now look like below.

9

Page 11: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.3. CREATION OF A SOLVER FOR A SURFACTANT USING THE FINITE AREA METHOD

Make/options

EXE_INC = \

-I$(WM_PROJECT_DIR)/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam \

-I$(LIB_SRC)/finiteVolume/lnInclude \

-I$(LIB_SRC)/finiteArea/lnInclude \

-I$(LIB_SRC)/cfdTools/general/lnInclude \

-I$(LIB_SRC)/turbulenceModels/incompressible/turbulenceModel \

-I$(LIB_SRC)/transportModels \

-I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel

EXE_LIBS = \

-lfiniteArea \

-lfiniteVolume \

-lmeshTools \

-lincompressibleTurbulenceModel \

-lincompressibleRASModels \

-lincompressibleLESModels \

-lincompressibleTransportModels \

-llduSolvers

Then you can try to compile your new solver by typing:

wclean

wmake

Now you can check that your ”new” solver works, before editing, by runnning a tutorial forbuoyantBoussinesqPisoFoam but changing the solver to buoyantBoussinesqPisoSurfactantFoam.

Then we merge surfactantFoam and buoyantBoussinesqPisoFoam by copying surfactantFoam.C,createFaFields.H, createFaMesh.H and createVolFields.H from */surfactantFoam into the*/buoyantBoussinesqPisoSurfactantFoam directory. Remember to keep the already edited Makefiles as they are. The files surfactantFoam.C and createVolFields.H are actually not needed inthe solver directory but I think it is good to have them in the same directory if you are to use themlater on. This can typically be done by typing:

cd $WM_PROJECT_USER_DIR/applications/solvers/heatTransfer/buoyantBoussinesqPisoSurfactantFoam

cp -r $WM_PROJECT_DIR/applications/solvers/surfaceTracking/surfactantFoam/create* .

cp -r $WM_PROJECT_DIR/applications/solvers/surfaceTracking/surfactantFoam/surfactantFoam.C .

3.3.2 Adding the interesting FAM equations of surfactantFoam into buoy-antBoussinesqPisoSurfactantFoam

Now we can look into surfactantFoam.C to see what is happening inside the solver. The mostinteresting part for us is where the scalar concentration at the surface is solved as

faScalarMatrix CsEqn

(

fam::ddt(Cs)

+ fam::div(phis, Cs)

- fam::laplacian(Ds, Cs)

);

CsEqn.solve();

10

Page 12: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.3. CREATION OF A SOLVER FOR A SURFACTANT USING THE FINITE AREA METHOD

which equals∂Cs

∂t+∇ · φsCs −∇ ·Ds∇Cs = 0 (3.2)

which equals the transport equation for a scalar due to convection and diffusion. φs is the fluxand Ds is the diffusion coefficient of the surfactant.

This part is now copied into the buoyantBoussinesqPisoSurfactantFoam.C file after the pisoloop and turbulence->correct();but before the runTime call so that the scalar concentration issolved after the volume solver for each time step. Now we have a solver that calculates the scalarconcentration from a given velocity field through fam::div(phis,Cs) where Ds is the diffusion coeffi-cient of the surfactant.

In the sphereTransport tutorial, where the surfactantFoam is used, the velocity field is constantfor all time steps and the resulting scalar concentration is mapped onto the volume solution. Thedefinition of first the area velocity field Us and then the phis has been done in the createFaFields.Has:

areaVectorField Us

(

IOobject

(

"Us",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::NO_WRITE

),

aMesh,

dimensioned<vector>("Us", dimVelocity, vector::zero)

);

dimensioned<scalar> Uinf("Uinf", dimVelocity, 1.0);

forAll (Us, faceI)

{

Us[faceI].x() =

Uinf.value()*(0.25*(3.0 + sqr(R[faceI].x()/mag(R[faceI]))) - 1.0);

Us[faceI].y() =

Uinf.value()*0.25*R[faceI].x()*R[faceI].y()/sqr(mag(R[faceI]));

Us[faceI].z() =

Uinf.value()*0.25*R[faceI].x()*R[faceI].z()/sqr(mag(R[faceI]));

}

Us -= aMesh.faceAreaNormals()*(aMesh.faceAreaNormals() & Us);

edgeScalarField phis

(

IOobject

(

"phis",

runTime.timeName(),

11

Page 13: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.3. CREATION OF A SOLVER FOR A SURFACTANT USING THE FINITE AREA METHOD

mesh,

IOobject::NO_READ,

IOobject::NO_WRITE

),

linearEdgeInterpolate(Us) & aMesh.Le()

);

In buoyantBoussinesqPisoSurfactantFoam.C we would like a coupling between the volume solverand the area solver. I have chosen to do this by collecting the boundary values of the velocity atthe surface and use them to update the area velocity field Us, with a for loop similar to the one increateFaFields.H above, by:

label patchID = mesh.boundaryMesh().findPatchID("surface");

forAll (Us, faceI)

{

Us[faceI] = U.boundaryField()[patchID][faceI];

}

Now we have a coupling between the volumeVelocityField U and the areaVelocityField Us.The next step is to calclulate phis. Once again we look into createFaFields.H and uses the lastpart of:

edgeScalarField phis

(

IOobject

(

"phis",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::NO_WRITE

),

linearEdgeInterpolate(Us) & aMesh.Le()

);

to find an expression for phis as:

phis = linearEdgeInterpolate(Us) & aMesh.Le();

phis is thereby calculated as the inner product of the edge-interpolated areaVelocityField, see Equa-tion 2.1, and the edge length in space coordinates.

These steps are now added to the above calculation of Cs and inserted before the runTime call,and then an output of the total mass of surfactant as a check is inserted after the runTime call as:

label patchID = mesh.boundaryMesh().findPatchID("surface");

forAll (Us, faceI)

{

Us[faceI] = U.boundaryField()[patchID][faceI];

}

phis = linearEdgeInterpolate(Us) & aMesh.Le();

faScalarMatrix CsEqn

12

Page 14: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.3. CREATION OF A SOLVER FOR A SURFACTANT USING THE FINITE AREA METHOD

(

fam::ddt(Cs)

+ fam::div(phis, Cs)

- fam::laplacian(Ds, Cs)

);

CsEqn.solve();

runTime.write();

Info<< "Total mass of surfactant: "

<< sum(Cs.internalField()*aMesh.S()) << endl;

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"

<< " ClockTime = " << runTime.elapsedClockTime() << " s"

<< nl << endl;

The total mass is calculated as a sum of outer products of the surfactant concentration and thesurface are of each cell (sum(Cs.internalField()*aMesh.S())). It is worth noting that there isa dimension bug2 in aMesh.S (defined as volume rather than area) in the original source code insrc/finiteArea/faMesh/faMeshDemandDrivenData.C. Since aMesh.S only is used as a check of thetotal amount of surfactant and the dimension is trivial I have not corrected the bug in this tutorial.

3.3.3 Include *.H files in buoyantBoussinesqPisoSurfactantFoam.C

The next thing we need to do is to make sure that we include the appropriate *.H files and add thefirst statement of the total mass of surfactant. This is done in the beginning ofbuoyantBoussinesqPisoSurfactantFoam.C as:

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"

#include "singlePhaseTransportModel.H"

#include "turbulenceModel.H"

//SF

#include "faCFD.H"

//SF end

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])

{

# include "setRootCase.H"

# include "createTime.H"

# include "createMesh.H"

# include "readGravitationalAcceleration.H"

# include "createFields.H"

# include "initContinuityErrs.H"

# include "readTimeControls.H"

# include "CourantNo.H"

# include "setInitialDeltaT.H"

2http://sourceforge.net/apps/mantisbt/openfoam-extend/view.php?id=85

13

Page 15: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.3. CREATION OF A SOLVER FOR A SURFACTANT USING THE FINITE AREA METHOD

//SF

# include "createFaMesh.H"

# include "createFaFields.H"

//# include "createVolFields.H"

//SF end

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

//SF

Info<< "Total mass of surfactant: "

<< sum(Cs.internalField()*aMesh.S()) << endl;

//SF end

3.3.4 Enable reading of Cs and Ds and defining Us in createFaFields.H

Then we look into the createFaFields.H once again. This file seems to have been originally createdto suite specifically the sphereTransport tutorial and needs therefore to be edited to suite us andbe more general. This is done by first noting that here is where the Cs actually is set. I have chosento change this so that Cs and Ds is set in the case files rather than in the solver. The coding increateFaFields.H to enable this is:

Info << "Reading field Cs" << endl;

areaScalarField Cs

(

IOobject

(

"Cs",

runTime.timeName(),

aMesh.thisDb(),

IOobject::MUST_READ,

IOobject::AUTO_WRITE

),

aMesh

);

// SF

Info << "End reading field Cs" << endl;

Info << "Reading Ds" << endl;

IOdictionary transportProperties

(

IOobject

(

"transportProperties",

runTime.constant(),

mesh,

IOobject::MUST_READ,

IOobject::NO_WRITE

)

);

dimensionedScalar Ds

(

14

Page 16: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.3. CREATION OF A SOLVER FOR A SURFACTANT USING THE FINITE AREA METHOD

transportProperties.lookup("Ds")

);

//dimensioned<scalar> Cs0

//(

// "Cs0",

// dimensionSet(1, -2, 0, 0, 0, 0, 0),

// 1.0

//);

//const areaVectorField& R = aMesh.areaCentres();

//Cs = Cs0*(1.0 + R.component(vector::X)/mag(R));

//dimensioned<scalar> Ds

//(

// "Ds",

// dimensionSet(0, 2, -1, 0, 0, 0, 0),

// 1.0e-5

//);

//SF end

where appropriate files of case/0/Cs and case/constant/transportProperties can be seen inSection 3.4.3 and 3.4.4. I have chosen for the time beeing to specifiy Cs to initially be uniformly 1.0and to set Ds to 1.0e-05, to make the diffusion slower. Finally I have chosen to use the same way todefine Us in createFaFields.H as in buoyantBoussinesqPisoSurfactantFoam.C.

//dimensioned<scalar> Uinf("Uinf", dimVelocity, 1.0e-6);

label patchID = mesh.boundaryMesh().findPatchID("surface");

forAll (Us, faceI)

{

Us[faceI] = U.boundaryField()[patchID][faceI];

// Us[faceI].x() =

// Uinf.value()*1;

//

// Us[faceI].y() =

// Uinf.value()*0.5;

//

// Us[faceI].z() =

// Uinf.value()*0.25;

}

Now it is time for the compilation as before:

wclean

wmake

and then move on to the pre-processing.

15

Page 17: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.4. PRE-PROCESSING

3.4 Pre-processing

This section covers the creation of an area mesh as well as doing the necessary setup needed to getthe convectiveSurfactantTransport case running with boundary and intitial conditions.

The file structure of this case is similar to other OpenFOAM tutorials where the case directoryhas a /0, /constant and /system directory. This case however, also has a /contant/faMesh di-rectory where the definition of the area mesh is placed. As usual in OpenFOAM tutorials, thesolver-, write- and time-control can be found in the /system directory and the ordinary mesh setupin /constant/polyMesh.

3.4.1 Creating an area mesh

The area mesh is created with the makeFaMesh utility. The makeFaMesh utility reeds the faMeshDefinitionfile which is placed under contant/faMesh dictionary. The most interesting part of that file in ourcase is as follows:

polyMeshPatches 1( surface );

boundary

{

faFrontAndBack

{

type symmetryPlane;

ownerPolyPatch surface;

neighbourPolyPatch frontAndBack;

}

faSide

{

type symmetryPlane;

ownerPolyPatch surface;

neighbourPolyPatch side;

}

}

where the number of patches to be covered by an area mesh is given along with their names. Thenthe boundaries of the area mesh (aMesh) is given. I have chosen symmetryPlane since I, so far, havenot mananged to get the cyclic type to work together with the 0/Cs file. As long as the polyMesh

is in place, by running blockMesh or if it is imported, the makeFaMesh utilitity is launched fromthe case directory level. The faBoundary and the faceLabels files are then created in the faMesh

directory.

ownerPolyPatch in the faMeshDefinition file refers to on which patch the polyMeshPatch (surface)

is to be attached to. neighbourPolyPatch in the faMeshDefinition file refers to on which patchthe boundary of the polyMeshPatch (surface) is to be attached to.

3.4.2 faSolution and faSchemes

The /system directory differs from an ordinary case since there are a faSchemes as well as afaSolution file beside the ordinary fvSchemes and fvSolution files. I have used the same setup offaSchemes and faSolutions as in the sphereTransport tutorial and for the fvScheme and fvSolutions

I have used a setup that can be used for direct numerical simulations.

Both the lapacianSchemes and the snGradSchemes ”contain surface normal gradient terms. A

16

Page 18: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.4. PRE-PROCESSING

surface normal gradient is evaluated at a cell face; it is the component, normal to the face, of thegradient of values at the centres of the 2 cells that the face connects”3. The surface gradient schemesfor the lapacianSchemes and the snGradSchemes are therefore chosen as uncorrected since the calu-lation does not need to be corrected due to non-orthogonality. The files can be found in Section3.7.

3.4.3 Boundary and initial conditions

Since there are neither outlets nor inlets the boundary conditions for this tutorial are quite simple.

VelocityThe velocity boundary condition constists of two different conditions. The upper and lower bound-aries are wall slip conditions whereas the sides are cyclic boundaries. The initial value is set to0.

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

internalField uniform (0 0 0);

boundaryField

{

frontAndBack

{

type cyclic;

}

side

{

type cyclic;

}

bottom

{

type slip;

}

surface

{

type slip;

}

}

Pressure boundary conditionThe pressure boundary condition also constists of two different conditions. The upper and lowerboundaries are bouyantPressure conditions whereas the sides are cyclic boundaries. The bouyantPressurecondition is a modified fixedGradient boundary conditions where the gradient is calclulated fromthe hydrostatic pressure with the density rhok calculated as Equation 3.1. The initial value is setto 0.

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

internalField uniform 0;

boundaryField

3OpenFOAM User Guide

17

Page 19: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.4. PRE-PROCESSING

{

frontAndBack

{

type cyclic;

}

side

{

type cyclic;

}

bottom

{

type buoyantPressure;

rho rhok;

value uniform 0;

}

surface

{

type buoyantPressure;

rho rhok;

value uniform 0;

}

}

Temperature boundary conditionThe temperature boundary condition constists of three different conditions. The upper boundaryis a fixedGradient boundary used to simulate the cooling of the surface due to evaporation andradiation. The lower boundary is chosen as a zeroGradient boundary. This will mean that thetemperature slowly will decrease in the volume. This can be altered by either adding a source termin the temperature equation or change the lower boundary condition to a fixedGradient boundarycondition as well. In this case where the simulation time is rather short the decrease of the maintemperature does not influence the dynamics of the flow significantly. The main emphasis of thistutorial is also not to study the temperature field but rather to study the use of the finite areamethod. The sides are modeled with cyclic boundaries. The initial value is set to 293.15 K.

dimensions [0 0 0 1 0 0 0];

internalField uniform 293.15;

boundaryField

{

frontAndBack

{

type cyclic;

}

side

{

type cyclic;

}

bottom

18

Page 20: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.4. PRE-PROCESSING

{

type zeroGradient;

}

surface

{

type fixedGradient;

gradient uniform -166; // 100 W/m-2 and k as 0.6 (Wikipedia for water)

}

}

Surfactant boundary conditionThe surfactant boundary condition is defined in the file Cs. It has only boundary conditions at thesides of the area mesh and in this case they are set as symmetryPlane. They should preferably havebeen set to cyclic as for the finite volume boundary conditions but I did not manange to get thatto work. It is possible to define the cyclic boundary within the faMeshDefinition file and also runmakeFaMesh but when I read in the Cs file during the analysis there will be an error message reading”Floating point exception”.

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

internalField uniform 0;

referenceLevel 0;

boundaryField

{

faFrontAndBack

{

type symmetryPlane;

}

faSide

{

type symmetryPlane;

}

}

3.4.4 Physical properties

The physical properties of the finite volume solver is given in /constant directory. In this tu-torial I have choosen properties typically for water in the /constant/transportProperties filetogether with the only physical properties of the surfactant which is the diffusion coefficient of thesurfactant(Ds):

transportModel Newtonian;

// Laminar viscosity

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

// Thermal expansion coefficient

beta beta [0 0 0 -1 0 0 0] 207e-06;

// Reference temperature

TRef TRef [0 0 0 1 0 0 0] 293.15;

19

Page 21: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.5. RUNNING THE CASE

// Laminar Prandtl number

Pr Pr [0 0 0 0 0 0 0] 6.97;

// Turbulent Prandtl number

Prt Prt [0 0 0 0 0 0 0] 0.9;

// Surfactant diffusion coefficient

Ds Ds [0 2 -1 0 0 0 0] 1.0e-5;

3.4.5 Turbulence models

As said above, this tutorial is made under the assumption that the case will be run as a directnumerial simulation and therefore no turbulence model is used and therefore the turbulence modelsetup is as follows in the /constant/turbulenceProperties:

simulationType RASModel;

and in /constant/RASProperties:

RASModel laminar;

turbulence off;

printCoeffs off;

3.5 Running the case

In the tutorial directory there is a Allrun file as:

#!/bin/sh

# Source tutorial run functions

. $WM_PROJECT_DIR/bin/tools/RunFunctions

application="buoyantBoussinesqPisoSurfactantFoam"

runApplication blockMesh

runApplication makeFaMesh

runApplication $application

foamToVTK -faMesh

First the general code for setting up tutorials are sourced and then the application is set. The nextstep is to create the actual volume mesh and then the area mesh and finally run the simulation.After the simulation has been run the data is postprocessed to VTK-format (note the -faMesh flag).

To run the tutorial automatically you can go to your case directory and type:

./Allrun

If you rather run the case from the prompt (including the creation of the volume mesh) you typicallytype:

blockMesh

makeFaMesh

buoyantBoussinesqPisoSurfactantFoam

foamToVTK -faMesh

20

Page 22: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.6. POST-PROCESSING

3.6 Post-processing

In the tutorial directory there is a Allrun file as seen above. This file ends with the transformationof the area based result files into VTK format. This is necessary in order to visualize the resultsin paraView. Depending on how you have set up your environment it is usually possible to typeparaFoam & and then open the volume mesh as usually. If you then also want to display your areabased results you open the ../VTK/faMesh directory by using the File/Open or simply Ctrl-O, seeFigure 3.2.

Figure 3.2: Open the area based results in paraView with Ctrl-O and then open the directory../VTK/faMesh.

If you want to plot the volume based and the area based results in the same plot it is useful touse the VTK format for the volume based results as well in order to get the time settings in par-aView correct. An example of an output can be seen in Figure 1.1 where I have used two plots andthen put them together in the report to show the volume based results together with the area basedresults. In the first plot I have plotted the temperature field using the internalMesh mesh region,and the velocities using the surface mesh region with the glyph filter. In the second plot I have usedthe area based results (VTK) for the plotting of the surfactant concentration.

The black and white plot of the temperature field is achieved byEdit Color Map.../Choose Preset/Grayscale under the diplay panel in paraView, see Figure3.3.

21

Page 23: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

Figure 3.3: Choose the color scale as gray by ”Edit Color Map.../Choose Preset/Grayscale” underthe diplay panel in paraView.

3.7 Files used for the buoyantBoussinesqSurfactantFoam solverand the convectiveSurfactantTransport tutorial

3.7.1 Solver

In this section you will find the files that have been edited compared to the original ones. The filestructure can be seen in Figure 3.4.

Figure 3.4: Directory structure of the solver files.

22

Page 24: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

buoyantBoussinesqPisoSurfactantFoam.C

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | Copyright held by original author

\\/ M anipulation |

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software; you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by the

Free Software Foundation; either version 2 of the License, or (at your

option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM; if not, write to the Free Software Foundation,

Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Application

buoyantBoussinesqPisoSourceSurfactantFoam

Description

Transient solver for buoyant, turbulent flow of incompressible fluids

Uses the Boussinesq approximation:

\f[

rho_{k} = 1 - beta(T - T_{ref})

\f]

where:

\f$ rho_{k} \f$ = the effective (driving) kinematic density

beta = thermal expansion coefficient [1/K]

T = temperature [K]

\f$ T_{ref} \f$ = reference temperature [K]

Valid when:

\f[

rho_{k} << 1

\f]

//SF

A surfactant is added by use of finiteAreaFoam

//SF end

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"

23

Page 25: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

#include "singlePhaseTransportModel.H"

#include "turbulenceModel.H"

//SF

#include "faCFD.H"

//SF end

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])

{

# include "setRootCase.H"

# include "createTime.H"

# include "createMesh.H"

# include "readGravitationalAcceleration.H"

# include "createFields.H"

# include "initContinuityErrs.H"

# include "readTimeControls.H"

# include "CourantNo.H"

# include "setInitialDeltaT.H"

//SF

# include "createFaMesh.H"

# include "createFaFields.H"

//# include "createVolFields.H"

//SF end

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

//SF

Info<< "Total mass of surfactant: "

<< sum(Cs.internalField()*aMesh.S()) << endl;

//SF end

Info<< "\nStarting time loop\n" << endl;

while (runTime.loop())

{

Info<< "Time = " << runTime.timeName() << nl << endl;

# include "readTimeControls.H"

# include "readPISOControls.H"

# include "CourantNo.H"

# include "setDeltaT.H"

# include "UEqn.H"

# include "TEqn.H"

// --- PISO loop

for (int corr=0; corr<nCorr; corr++)

{

# include "pEqn.H"

}

24

Page 26: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

turbulence->correct();

//SF

label patchID = mesh.boundaryMesh().findPatchID("surface");

forAll (Us, faceI)

{

Us[faceI] = U.boundaryField()[patchID][faceI];

}

phis = linearEdgeInterpolate(Us) & aMesh.Le();

faScalarMatrix CsEqn

(

fam::ddt(Cs)

+ fam::div(phis, Cs)

- fam::laplacian(Ds, Cs)

);

CsEqn.solve();

//SF end

runTime.write();

//SF

Info<< "Total mass of surfactant: "

<< sum(Cs.internalField()*aMesh.S()) << endl;

//SF end

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"

<< " ClockTime = " << runTime.elapsedClockTime() << " s"

<< nl << endl;

}

Info<< "End\n" << endl;

return 0;

}

// ************************************************************************* //

25

Page 27: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

createFaFields.H

Info << "Reading field Cs" << endl;

areaScalarField Cs

(

IOobject

(

"Cs",

runTime.timeName(),

aMesh.thisDb(),

IOobject::MUST_READ,

IOobject::AUTO_WRITE

),

aMesh

);

// SF

Info << "End reading field Cs" << endl;

Info << "Reading Ds" << endl;

IOdictionary transportProperties

(

IOobject

(

"transportProperties",

runTime.constant(),

mesh,

IOobject::MUST_READ,

IOobject::NO_WRITE

)

);

dimensionedScalar Ds

(

transportProperties.lookup("Ds")

);

//dimensioned<scalar> Cs0

//(

// "Cs0",

// dimensionSet(1, -2, 0, 0, 0, 0, 0),

// 1.0

//);

//const areaVectorField& R = aMesh.areaCentres();

//Cs = Cs0*(1.0 + R.component(vector::X)/mag(R));

//dimensioned<scalar> Ds

//(

// "Ds",

// dimensionSet(0, 2, -1, 0, 0, 0, 0),

26

Page 28: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

// 1.0e-5

//);

//SF end

areaVectorField Us

(

IOobject

(

"Us",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::AUTO_WRITE

),

aMesh,

dimensioned<vector>("Us", dimVelocity, vector::zero)

);

//SF

//dimensioned<scalar> Uinf("Uinf", dimVelocity, 1.0e-6);

label patchID = mesh.boundaryMesh().findPatchID("surface");

forAll (Us, faceI)

{

Us[faceI] = U.boundaryField()[patchID][faceI];

// Us[faceI].x() =

// Uinf.value()*1;

//

// Us[faceI].y() =

// Uinf.value()*0.5;

//

// Us[faceI].z() =

// Uinf.value()*0.25;

}

//Us -= aMesh.faceAreaNormals()*(aMesh.faceAreaNormals() & Us);

//SF end

edgeScalarField phis

(

IOobject

(

"phis",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::NO_WRITE

),

linearEdgeInterpolate(Us) & aMesh.Le()

);

27

Page 29: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

Make/files

buoyantBoussinesqPisoSurfactantFoam.C

EXE = $(FOAM_USER_APPBIN)/buoyantBoussinesqPisoSurfactantFoam

28

Page 30: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

Make/options

EXE_INC = \

-I$(WM_PROJECT_DIR)/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam \

-I$(LIB_SRC)/finiteVolume/lnInclude \

-I$(LIB_SRC)/finiteArea/lnInclude \

-I$(LIB_SRC)/cfdTools/general/lnInclude \

-I$(LIB_SRC)/turbulenceModels/incompressible/turbulenceModel \

-I$(LIB_SRC)/transportModels \

-I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel

EXE_LIBS = \

-lfiniteArea \

-lfiniteVolume \

-lmeshTools \

-lincompressibleTurbulenceModel \

-lincompressibleRASModels \

-lincompressibleLESModels \

-lincompressibleTransportModels \

-llduSolvers

3.7.2 Case files

In this section you will find the files needed to build your case. The files should be structuredaccording to Figure 3.5.

Figure 3.5: Case directory.

29

Page 31: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

Cs

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM Extend Project: Open Source CFD |

| \\ / O peration | Version: 1.6-ext |

| \\ / A nd | Web: www.extend-project.de |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class areaScalarField;

location "0";

object Cs;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField uniform 1;

referenceLevel 0;

boundaryField

{

faFrontAndBack

{

type symmetryPlane;

}

faSide

{

type symmetryPlane;

}

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

30

Page 32: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

p

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.x |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class volScalarField;

location "0";

object p;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField uniform 0;

boundaryField

{

frontAndBack

{

type cyclic;

}

side

{

type cyclic;

}

bottom

{

type buoyantPressure;

rho rhok;

value uniform 0;

}

surface

{

type buoyantPressure;

rho rhok;

value uniform 0;

}

}

// ************************************************************************* //

31

Page 33: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

T

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class volScalarField;

location "0";

object T;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 0 0 1 0 0 0];

internalField uniform 293.15;

boundaryField

{

frontAndBack

{

type cyclic;

}

side

{

type cyclic;

}

bottom

{

type zeroGradient;

}

surface

{

type fixedGradient;

gradient uniform -166; // 100 W/m-2 and k as 0.6 (Wikipedia for water)

}

}

// ************************************************************************* //

32

Page 34: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

U

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class volVectorField;

location "0";

object U;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField uniform (0 0 0);

boundaryField

{

frontAndBack

{

type cyclic;

}

side

{

type cyclic;

}

bottom

{

type slip;

}

surface

{

type slip;

}

}

// ************************************************************************* //

33

Page 35: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

Allclean

#!/bin/sh

# Source tutorial clean functions

. $WM_PROJECT_DIR/bin/tools/CleanFunctions

cleanTimeDirectories

cleanFaMesh

rm -r VTK

rm -r probes

34

Page 36: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

Allrun

#!/bin/sh

# Source tutorial run functions

. $WM_PROJECT_DIR/bin/tools/RunFunctions

application="buoyantBoussinesqPisoSurfactantFoam"

runApplication blockMesh

runApplication makeFaMesh

runApplication $application

foamToVTK -faMesh

35

Page 37: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

faMeshDefinition

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM Extend Project: Open Source CFD |

| \\ / O peration | Version: 1.6-ext |

| \\ / A nd | Web: www.extend-project.de |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

object faMeshDefinition;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

polyMeshPatches 1( surface );

boundary

{

faFrontAndBack

{

type symmetryPlane;

ownerPolyPatch surface;

neighbourPolyPatch frontAndBack;

}

faSide

{

type symmetryPlane;

ownerPolyPatch surface;

neighbourPolyPatch side;

}

}

// ************************************************************************** //

36

Page 38: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

g

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class uniformDimensionedVectorField;

location "constant";

object g;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

value ( 0 0 -9.81 );

// ************************************************************************* //

37

Page 39: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

blockMeshDict

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

object blockMeshDict;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 0.038;

vertices

(

(-1 -1 0)

( 1 -1 0)

( 1 1 0)

(-1 1 0)

(-1 -1 1)

( 1 -1 1)

( 1 1 1)

(-1 1 1)

);

blocks

(

hex (0 1 2 3 4 5 6 7) (40 40 45) simpleGrading (1 1 1)

);

edges

(

);

patches

(

cyclic frontAndBack

(

(0 1 5 4)

(3 7 6 2)

)

cyclic side

(

(0 4 7 3)

38

Page 40: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

(5 1 2 6)

)

wall bottom

(

(0 3 2 1)

)

wall surface

(

(4 5 6 7)

)

);

mergePatchPairs

(

);

// ************************************************************************* //

39

Page 41: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

RASProperties

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

object RASProperties;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

RASModel laminar;

//RASModel kEpsilon;

turbulence off;

printCoeffs off;

// ************************************************************************* //

40

Page 42: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

transportProperties

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

object transportProperties;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

//Water//

transportModel Newtonian;

// Laminar viscosity

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

// Thermal expansion coefficient

beta beta [0 0 0 -1 0 0 0] 207e-06;

// Reference temperature

TRef TRef [0 0 0 1 0 0 0] 293.15;

// Laminar Prandtl number

Pr Pr [0 0 0 0 0 0 0] 6.97;

// Turbulent Prandtl number

Prt Prt [0 0 0 0 0 0 0] 0.9;

// Surfactant diffusion coefficient

Ds Ds [0 2 -1 0 0 0 0] 1.0e-5;

// ************************************************************************* //

41

Page 43: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

turbulenceProperties

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM Extend Project: Open Source CFD |

| \\ / O peration | Version: 1.6-ext |

| \\ / A nd | Web: www.extend-project.de |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "constant";

object turbulenceProperties;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

simulationType RASModel;

// ************************************************************************* //

42

Page 44: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

controlDict

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "system";

object controlDict;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application buoyantBoussinesqPisoSurfactantFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

endTime 50;

deltaT 1;

//writeControl timeStep;

writeControl adjustableRunTime;

writeInterval 10;

purgeWrite 0;

writeFormat ascii;

writePrecision 10;

writeCompression uncompressed;

timeFormat general;

timePrecision 6;

runTimeModifiable true;

adjustTimeStep yes;

//adjustTimeStep no;

43

Page 45: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

maxCo 0.85;

functions

{

fieldAverage1

{

type fieldAverage;

functionObjectLibs ( "libfieldFunctionObjects.so" );

enabled true;

outputControl outputTime;

fields

(

U

{

mean on;

prime2Mean on;

base time;

}

// p

// {

// mean on;

// prime2Mean on;

// base time;

// }

T

{

mean on;

prime2Mean on;

base time;

}

);

}

probes

{

type probes;

functionObjectLibs ( "libsampling.so" );

enabled true;

outputControl timeStep;

outputInterval 1;

probeLocations

(

(0. 0. 0.005)

(0. 0. 0.01)

(0. 0. 0.02)

(0. 0. 0.03)

(0. 0. 0.035)

(0. 0. 0.037)

);

fields

(

U

44

Page 46: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

UPrime2Mean

UMean

T

TPrime2Mean

TMean

);

}

}

// ************************************************************************* //

45

Page 47: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

faSchemes

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM Extend Project: Open Source CFD |

| \\ / O peration | Version: 1.6-ext |

| \\ / A nd | Web: www.extend-project.de |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "system";

object faSchemes;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

ddtSchemes

{

default Euler;

}

gradSchemes

{

default Gauss linear;

grad(p) Gauss linear;

}

divSchemes

{

default none;

div(phis,Cs) Gauss linear;

}

laplacianSchemes

{

default none;

laplacian(Ds,Cs) Gauss linear corrected;

}

interpolationSchemes

{

default linear;

}

snGradSchemes

{

default corrected;

}

fluxRequired

{

p;

46

Page 48: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

}

// ************************************************************************* //

47

Page 49: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

faSolution

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM Extend Project: Open Source CFD |

| \\ / O peration | Version: 1.6-ext |

| \\ / A nd | Web: www.extend-project.de |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "system";

object faSolution;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

solvers

{

Cs

{

solver PBiCG;

preconditioner DILU;

minIter 0;

maxIter 2000;

tolerance 1e-06;

relTol 0;

}

}

PISO

{

nCorrectors 2;

nNonOrthogonalCorrectors 0;

}

SIMPLE

{

nTimeCorrectors 6;

nNonOrthogonalCorrectors 1;

}

relaxationFactors

{

p 0.7;

U 0.7;

k 0.7;

epsilon 0.7;

R 0.7;

}

// ************************************************************************* //

48

Page 50: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

fvSchemes

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "system";

object fvSchemes;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

ddtSchemes

{

default CrankNicholson 1;

}

gradSchemes

{

default Gauss linear;

}

divSchemes

{

default Gauss linear;

}

laplacianSchemes

{

default Gauss linear uncorrected;

}

interpolationSchemes

{

default linear;

}

snGradSchemes

{

default uncorrected;

}

fluxRequired

{

default no;

p ;

}

49

Page 51: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

// ************************************************************************* //

50

Page 52: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

fvSolution

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: 1.7.1 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "system";

object fvSolution;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

solvers

{

p

{

solver PCG;

preconditioner DIC;

tolerance 1e-8;

relTol 0.01;

}

pFinal

{

solver PCG;

preconditioner DIC;

tolerance 1e-07;

relTol 0;

}

"(U|T|k|epsilon|R)"

{

solver PBiCG;

preconditioner DILU;

tolerance 1e-6;

relTol 0.1;

}

}

PISO

{

momentumPredictor no;

// nOuterCorrectors 1;

nCorrectors 2;

nNonOrthogonalCorrectors 0;

pRefCell 0;

pRefValue 0;

51

Page 53: CFD with OpenSource software - Chalmershani/kurser/OS_CFD_2011/SamFredriks...CFD with OpenSource software A course at Chalmers University of Technology Taught by H akan Nilsson Project

3.7. FILES USED FOR THE BUOYANTBOUSSINESQSURFACTANTFOAM SOLVER AND THECONVECTIVESURFACTANTTRANSPORT TUTORIAL

}

relaxationFactors

{

"(U|T|k|epsilon|R)" 1;

}

// ************************************************************************* //

52