OpenFOAMA little User-Manual Gerhard Holzinger CD-Laboratory - Particulate Flow Modelling Johannes Kepler University, Linz, Austria http://www.jku.at/pfm/ 3rd March 2015 Abstract This document is a collection of my own experience on learning and using OpenFOAM. Herein knowledge and background information is assembled that may be useful when learning to use OpenFOAM. WARNING: During the assembly of this manual OpenFOAM and other tools, e.g. pyFoam, have been continuously updated. This manual was started with OpenFOAM-2.0.x installed and at the time being the author works with OpenFOAM-2.2.x. Consequently it is possible that some facts or listings my be outdated by the time you read this. Furthermore, functionalities may have been extended or modied. Nevertheless, this manual is intended to cast some light on the inner workings of OpenFOAM and explain the usage in a rather practical way. All informations contained in this manual can be found in the internet (http://www.openfoam.org, http://www.cfd-online.com/Forums/openfoam/) or they were gathered by trials and error (What happens if ...? ). ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® 1 ® Contents 1 Getting help 11 I Installation 2 Install OpenFOAM 2.1 2.2 2.3 2.4 2.5 2.6 Prerequistes . . . . . . . . . . . . . . . Download the sources . . . . . . . . . Compile the sources . . . . . . . . . . Install paraView . . . . . . . . . . . . Remove OpenFOAM . . . . . . . . . . Install several versions of OpenFOAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Updating the repository release of OpenFOAM 3.1 3.2 3.3 3.4 3.5 Version management . . . . . . . . . . Check for updates . . . . . . . . . . . Check for updates only . . . . . . . . . Install updates . . . . . . . . . . . . . 3.4.1 Workow . . . . . . . . . . . . 3.4.2 Trouble-shooting . . . . . . . . Problems with updates . . . . . . . . . 3.5.1 Missing packages . . . . . . . . 3.5.2 Updated Libraries . . . . . . . 3.5.3 Updated sources fail to compile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 12 12 13 13 13 14 14 14 15 15 16 16 16 16 16 16 17 4 Install third-party software 4.1 4.2 4.3 II General Remarks about OpenFOAM 5 Units and dimensions 5.1 5.2 5.3 5.4 Unit inspection . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1 An important note on the base units . . . . . . . . . . . 5.1.2 Input syntax of units . . . . . . . . . . . . . . . . . . . . Dimensionens . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1 Dimension check . . . . . . . . . . . . . . . . . . . . . . Kinematic viscosity vs. dynamic viscosity . . . . . . . . . . . . Pitfall: pressure vs. pressure . . . . . . . . . . . . . . . . . . . 5.4.1 Incompressible . . . . . . . . . . . . . . . . . . . . . . . 5.4.2 Compressible . . . . . . . . . . . . . . . . . . . . . . . . 5.4.3 Pitfall: Pressure in incompressible multi-phase problems 6 Files and directories 6.1 6.2 6.3 17 Install pyFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Install swak4foam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Compile external libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Required directories . . Supplemental directories 6.2.1 processor * . . . . 6.2.2 functions . . . . 6.2.3 sets . . . . . . . Files in system . . . . . 6.3.1 The main les . 6.3.2 Additional les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ® 17 17 17 ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 18 18 18 19 19 20 20 20 21 21 21 21 21 22 22 22 22 22 22 23 2 7 Control 7.1 7.2 7.3 7.4 7.5 Syntax . . . . . . . . . . . . . . . . . . . 7.1.1 Keywords - the banana test . . . 7.1.2 Mandatory and optional settings 7.1.3 Pitfall: semicolon (;) . . . . . . . 7.1.4 Switches . . . . . . . . . . . . . . controlDict . . . . . . . . . . . . . . . . 7.2.1 Time control . . . . . . . . . . . 7.2.2 Data writing . . . . . . . . . . . 7.2.3 Loading additional Libraries . . . 7.2.4 functions . . . . . . . . . . . . . 7.2.5 Outsourcing a dictionary . . . . Run-time modifcations . . . . . . . . . . fvSolution . . . . . . . . . . . . . . . . . 7.4.1 Solver control . . . . . . . . . . . 7.4.2 Solution algorithm control . . . . Pitfalls . . . . . . . . . . . . . . . . . . . 7.5.1 timePrecision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Usage of OpenFOAM 8.1 8.2 8.3 8.4 8.5 8.6 Use OpenFOAM . . . . . . . . . . . . . . . . . . . . . . . . 8.1.1 Redirect output and save time . . . . . . . . . . . . 8.1.2 Run OpenFOAM in the background, redirect output 8.1.3 Save hard disk space . . . . . . . . . . . . . . . . . . Abort an OpenFOAM simulation . . . . . . . . . . . . . . . Terminate an OpenFOAM simulation . . . . . . . . . . . . 8.3.1 Terminate a process in the foreground . . . . . . . . 8.3.2 Terminate a background process . . . . . . . . . . . Continue a simulation . . . . . . . . . . . . . . . . . . . . . Do parallel simulations with OpenFOAM . . . . . . . . . . 8.5.1 Starting a parallel simulation . . . . . . . . . . . . . 8.5.2 Domain decomposition . . . . . . . . . . . . . . . . . 8.5.3 Domain reconstruction . . . . . . . . . . . . . . . . . 8.5.4 Run large studies on computing clusters . . . . . . . Using tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . and read log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . III Pre-processing 23 23 23 24 24 25 25 25 26 27 27 27 29 29 29 29 29 29 30 30 30 31 31 32 33 33 33 36 36 36 38 39 40 40 41 9 Geometry creation & other pre-processing software 9.1 9.2 9.3 9.4 41 blockMesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 CAD software . . . 9.2.1 OpenSCAD Salome . . . . . . . GMSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . and uent3DMeshToFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Meshing & OpenFOAMs meshing tools 10.1 Basics of the mesh . . . . 10.1.1 Files . . . . . . . . 10.1.2 Denitions . . . . 10.2 Converters . . . . . . . . . 10.2.1 uentMeshToFoam 10.3 Mesh manipulation . . . . 10.3.1 transformPoints . 11 blockMesh 11.1 The block . . . . . . . . 11.2 The blockMeshDict . . 11.2.1 convertToMeters 11.2.2 vertices . . . . 11.2.3 blocks . . . . . . 11.2.4 edges . . . . . . 11.2.5 boundary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 41 41 42 42 42 42 42 43 44 44 44 44 44 44 45 46 46 47 47 48 3 11.2.6 mergePatchPairs . . . . . . . . . . . . . . . . 11.3 Create multiple blocks . . . . . . . . . . . . . . . . . 11.3.1 Connected blocks . . . . . . . . . . . . . . . . 11.3.2 Unconnected blocks . . . . . . . . . . . . . . 11.4 Grading . . . . . . . . . . . . . . . . . . . . . . . . . 11.5 Parametric meshes by the help of m4 and blockMesh 11.5.1 The blockMeshDict prototype . . . . . . . . 11.5.2 The macro programming language m4 . . . . 11.6 Trouble-shooting . . . . . . . . . . . . . . . . . . . . 11.6.1 Viewing the blocks with ParaView . . . . . . 11.6.2 Viewing the blocks with pyFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 50 52 52 53 55 55 56 58 58 58 12 snappyHexMesh 58 12.0.3 Workow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.0.4 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 checkMesh 13.1 Denitions . . . . . . . . . . . . . . . . . . . . . . . . 13.1.1 Face non-orthogonality . . . . . . . . . . . . . 13.1.2 Face skewness . . . . . . . . . . . . . . . . . . 13.1.3 Face concavity . . . . . . . . . . . . . . . . . 13.1.4 Cell concavity . . . . . . . . . . . . . . . . . . 13.2 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2.1 Mesh quality - aspect ratio . . . . . . . . . . 13.2.2 Mesh quality - skewness . . . . . . . . . . . . 13.2.3 Possible non-pitfall: twoInternalFacesCells 13.3 Useful output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.2 setFields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3 mapFields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3.1 Pitfall: Missing les . . . . . . . . . . . . . . . . . . . . . 15.3.2 Pitfall: Unsuitable les . . . . . . . . . . . . . . . . . . . 15.3.3 Pitfall: Mapping data from a 2D to a 3D mesh . . . . . . 15.3.4 The work-around: Mapping data from a 2D to a 3D mesh 15.3.5 The importance of mapping . . . . . . . . . . . . . . . . . 15.3.6 Pitfall: binary les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Other mesh manipulation tools 14.1 topoSet . . . . . . . . . . . . . . . . . . . . . . . . . 14.1.1 Usage . . . . . . . . . . . . . . . . . . . . . . 14.1.2 Pitfall: The denition of the geometric region 14.1.3 Pitfall: renumbered mesh . . . . . . . . . . . 14.2 setsToZones . . . . . . . . . . . . . . . . . . . . . . . 14.3 reneMesh . . . . . . . . . . . . . . . . . . . . . . . 14.3.1 Usage . . . . . . . . . . . . . . . . . . . . . . 14.3.2 Pitfall: no command line parameters . . . . . 14.4 renumberMesh . . . . . . . . . . . . . . . . . . . . . 14.4.1 General information . . . . . . . . . . . . . . 14.4.2 Background . . . . . . . . . . . . . . . . . . . 14.4.3 Pitfall: sets and zones will break my bones . 14.5 subsetMesh . . . . . . . . . . . . . . . . . . . . . . . 14.6 createPatch . . . . . . . . . . . . . . . . . . . . . . . 14.7 stitchMesh . . . . . . . . . . . . . . . . . . . . . . . . 15 Initialize Fields 58 60 60 60 61 62 65 65 65 65 66 67 68 68 68 68 69 69 69 70 70 70 70 70 71 72 73 73 73 73 73 74 76 76 77 78 78 79 79 16 Case manipulation 80 16.1 changeDictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.1.1 A spin-up simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IV Modelling ® 80 81 83 ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 4 . . . . . . . . . . . . . . . . .3. . . . . . . . . . . 20 pimpleFoam 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Laminar simulation with twoPhaseEulerFoam 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ® 92 92 93 93 94 94 94 94 95 96 96 97 99 101 ® 101 102 102 102 102 104 104 106 106 107 This oering is not approved or endorsed by ESI Group. . . .3 Momentum exchange between 21. . . . 18. . . . . . . . . . .3 Virtual mass . . . 21. .1.1 General remarks . . . . . . . . .3. . . . . . . . . . . 17. . . . . . . . . . . . . . . . .1 uniformFixedValue . . . . under the . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . .1 Continuity equation .1 Keywords . . . . . . . . . . . . 18. . . . . . . . . . . . . . . . . . . . . . ESI-OpenCFD or the OpenFOAM Foundation. . . . . . . . . . . .2 The PIMPLE Algorithm or. . . . . . . . . . . . .4. . . . . 18. . . . . . . . . . . . . . . . 17. .3. . . . . . . . . . .1 Categories . . . . . . . . . . . what's . . 18. . . . .1 Geometric boundaries . . 21. . . . . . . . . . . the phases . . . . . . . .2 Primitive types . . . .1 Syntax . . . . . . . . . . . . . . . . . . . 17. . . . . . . . . . . . . V 19 Solution Algorithms 19. .3 Dynamic sub-grid models . . . . . . . . . . . . . . . . . . . . . . . . . . . 17. . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . .2 PISO . . . . . . . . . . . . . . . . . . . . .2 Pitfall: meaningless Parameters . 20. .4 One equation models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18. . 17. . .4 Initial and boundary conditions . . . . . . . . . . . . . . . . . .3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . .2 pimpleControl . . . . . . . . . . . . . . . .3 LES-Models . . . . . . . . . . . . .2. . . . . . . . . . . .2. . .1 Base types . .2 Lift . . . . . . . . . . . . .4. . . . .1 Continuity . . . . . . . . . . . . . . . . . . . . . . . 21. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17. . . . . . .2 Kinetic theory . . . . . . . . . . . . . . . . . . .3 pressureInletOutletVelocity 18. . . . . . . . . . . . . . .1 inletOutlet . . . . . . . . . . . . . . . . 21. . . . . . . . . . . . . . . . . . . . . .1 Keywords . . . . . . . . . . 20. . . . . . . . . 17.4.2 surfaceNormalFixedValue . . . . . . . . . . . . . . . . . . . 92 . . . . . . . . . . . hood? . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . .4 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17. . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . . . . . .6 Spalart-Allmaras . . .5 Additional les . . . . . . . . . . . . . . . . . . . . . . . . . 20.1 Turbulence .2 Corrector 19. . . . . . . . . . . . . .1 Predictor 19.2 Solver algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .H . . . . . . . . . . . . . . . . . . . . . . . . 21. . . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. . . . . . . . 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Algebraic sub-grid models . . . . . . . . . . . . .3. . . . . .1. . . . . . . . . . . . . . . . 18. . . . . . . . .2 Turbulence models in twoPhaseEulerFoam . . . . . . . . . . . . . . . . . . . 21. . . . . . 20. . . . . . . .2. . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18. . . . . . . . . . . . . . . . . . . . . . . . . .17 Turbulence-Models 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . 17. . . . . . 83 83 83 83 84 85 85 85 85 85 86 86 87 87 87 88 88 88 89 89 89 89 89 89 90 90 90 90 91 91 Solver . . . . . . . . . . .2 RAS-Models . . 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 Pitfalls . . . . . . . . . . . . .5 Time-variant boundary conditions 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . .2 Momentum equation . . . . . . . . . . . . . . . . . . . . . . ® . . . 21. . 21. . . . . 18 Boundary conditions 18.2 Complex boundaries . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . 20. . . 19. . . .1 Laminar Simulation . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . .1 readTimeControls. . . . ® ® 5 . . .1 Drag . . . . . . . . . . . . . . . .1.1. . . . . . . . . 18. . 21 twoPhaseEulerFoam 21. .3.3 Derived types . . . . . . . . .1. . . . . . . . . 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 SIMPLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Governing equations . . .3. . . . . . . 17. . . . . . . . . . . . . . . . . . . . . . 17. . . .2. . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . .4 Kinetic Theory . . . . . . . . 17. . . . . . . . 17. . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . 22. . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . 24. . . . . . . . . . . . 25. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Drag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ® . . . . . . . . . ® ® 6 . . . . . . . . . . . . . . . . .3 Pitfall: valueOutput . . 25. . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 22. . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . . . . . . . . . .2 The class multiphaseSystem . . . . . . . . . . .3. . . . .1 Fields . . .8 Interfacial momentum exchange 22. . . .4 IATE . . . 22. . . . . . . . .8. . . . . OpenFOAM-2. 136 ® 136 137 138 138 139 139 139 140 140 141 142 This oering is not approved or endorsed by ESI Group. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . .1 A comparison of the phase models in 24. . . . . . . . . . . . . 24. . . . . . . . . . . . . . . . . . . . . . .1 Physics . . . . . . . . .2 Constant . . . . . . . . . . . . . . . . . . . . 25. .1 alphas . . . . . . . . 24. . . . . . . . . . . . . . . . . . . . . . . . . . . 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Blending . . . . . . . 25. . . . . . . . . .2 Implemented equations 22. . . . . . . .8.3. . . . . . . . .8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6.1 Denition .1 drag . . . . . . . . . . . 23. . . . . . . . . . . . . . . . .5 cellSource . . . . .8. . . .2 virtual mass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 multiphaseEulerFoam 23. . . . . . . . . . . . . . . . . .3. . .2. . . . .7 Interfacial interaction . . . . . .6 Turbulent dispersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22. . . . . . . . . . . . . . . . . . . . .3 . . . . . . . . 22. . .2. . . . . . . . . . . . . . . .6 Execute C++ code as functionObject . . . . . . . . . . . . . . . . . . 24. . . . . . . 25. . . . . . . . . . . . . . . . . . . .2 OpenFOAM-2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . 22. . . . . . . . . . . . . . .5 Wall lubrication . . . . . . . . . . . . . . . . . . . . . . 24. . . . . . .2 Phase system classes . . . . . . . . . . .2 Naming scheme . . . . . . . . . . . . . . . . . . . ESI-OpenCFD or the OpenFOAM Foundation. . . . .4.5 Energy equation . . . . . . . . .4 faceSource . . . 25. . . . . . . 22. . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . 23. . . 23. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Momentum equation . . . 22. . . . . . . . . . . . . .3 eldAverage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22. . . . . . . . . . .1 No model . . . . . . 24 Multiphase modelling 24. . . . . . . . . . . . . . . . 22. . . . . . . . . . . . . . . . . . . . . . . . 22. . . . . . . .8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . .1 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7. . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Governing equations . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . 23. . . .4. . . . . 22. . . . . . . . . . . . . . . 22. . . . . . . . . . . . . . . . . . . . . . . .2 Compute volumetric ow over a boundary 25. . . . . . . . . 25. . 25. . . . . . . . . . . . . . . . . . . . . . 22.2 Temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Pressure . . . . . . . . . . . . . . 22. . . . . . . . . . . . . . . . . . . . .1 Naming scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6. . . . . . . . . . . . . . . . . . . . . . . . .2 probes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 LaheyKEpsilon . . . . . . . .1 Units . . . . . . .4 mixtureKEpsilon . . . . . 107 107 107 107 107 108 108 109 109 110 111 112 113 114 114 115 115 116 116 119 119 121 123 123 124 124 125 125 125 125 126 126 126 126 126 127 130 132 132 133 133 133 134 134 135 136 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25. . . .2 A comparison of the phase models in 24. . . VI Postprocessing 25 functions 25. . . . . . . . . . .2 Lift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24. . . . . . . .7 Execute functions after a simulation has nished ® . . . . . . . . . . . . . . . .8. . 22. . . . . . . . . .1 The class twoPhaseSystem . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. . .3 lift force . . . . . . . . .1 Phase model class . . .2 Momentum exchange 23.4 Turbulence models . . . . . . . . . .1 Average over a plane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Isothermal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24. . 22. . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . .3. . . . . . . . . . . .2 kEpsilon . . . . . . . . . . . . . . .22 twoPhaseEulerFoam-2. . . . . . . . . .4. . . . 22. . . . . . . . . .4 Aspect ratio models . . . 22. . . . . . . . 24. . . . . . . .4. . . . . . . .1. . . . . . . . . . . .3 Virtual mass . . . . . . . . . . . . . . . . . . . . . . . 22.3 Solver capabilities . . . . . 22. . .3 Diameter models . . . 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Pitfall: phase inversion . . . . . . . .x . . . . . . . . . . . . . . . . . . . . . . . .5 pyFoamCloneCase . . . . . . . . . . .3 pyFoamPlotWatcher . .1 twoPhaseEulerFoam . . . . .2. . . . .1. 26. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Naming scheme of two-phase solvers 33. . . . . . . . . . . . .1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28. . . . 30. . . . .7. . . . . . . . . . . . . . . . . . . . . . . . . ® . . . . . . . . . . . . .x . . . . . . . . . . .3 Pitfalls . . 155 30 blockMeshDG 30. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.5 Producing images . . . . . . . . . . . . 147 . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . 165 ® 165 165 165 165 165 165 165 This oering is not approved or endorsed by ESI Group. . . . . . .3. . . . . . . . . . . . . . . . . . . . 33. . . . . . . . . . . . .4 Ignoring stu . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . of cells . . 33. . . . 154 29. . . 33. . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . .1 Extrema of a eld quantity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 31. . . . . . . . . . . . . . . . . . . . . .8 pyFoamCaseReport . . . . . . . . . . . . . . . . . . . . . . . . . . . 26. . . 155 29. . . . . . . . . . . ® ® 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28. . . . . . . . . . . . . .1 Plotting options . . . . .1 Installation . . . . .3 OpenFOAM-2. . . . . . . . . . . . . . . . . . . . . . . . .2. .2 sampleDict . . . . . . .2 Fields . . .3 Special treatment of certain characters 28. . . . . . . . . . . . . . . . . . . . . . . . . 28. . . . . . . . . . . . . . 28. . . . . . . . . . . .3. . . . . . . . 26. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Motivation . . . . . . . . . 28. . . . . . . . . . .7. . . .1 View the mesh . . .1 Custom regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. . . . . . . . . . . . . . . . . . . 29 swak4foam 147 147 147 147 147 148 149 150 151 151 151 151 152 152 152 153 154 154 29. . . . . . . . . . . . . . . . . . . . .3. . . . . 28. . . . . . . . . . . . . . . . . .3. . . . .2.2 simpleSwakFunctionObjects . . . . . . . . . . . . . . . . . .2 OpenFOAM-2. . . . . . . .2 postAverage . . . . . . . . . 28. . . . . . . . 145 VII External Tools 28 pyFoam 28. . .1. . . . . . . . . . . . . . . . . . . . . . . . . .2 Usage . . . .7 Case analysis . . . . . . . . . . . . . . . . . . . . . . . . . .2.6 Writing data . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . ® . . . . . . . . . . . . . . . . . . . . .2 Source code . . . . . . .1 execFlowFunctionObjects . . . . . . . 28. 33. 30. . . . . . . . . . 28. . .1 Uneven number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33. . . . . . . . . . . . . . . . . . . . . . 27 ParaView 143 143 143 143 144 144 144 145 27. . . . . . . . . . . 28. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 26 sample 26. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 OpenFOAM-2.1 Usage . . . . . . . . . . . . .4 pyFoamClearCase . . 142 25. . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Custom regular expression revisited . . . . . . . . . . . . . . . . .6 pyFoamDecompose . 157 VIII Updates 165 32 General remarks 165 33 OpenFOAM 33. . . . . . . . . .x . . . . . . . . . . .2 pyFoamPlotRunner . . . . . . . . . . . . . . . . . . .1 Installation . . . . . .4 Pitfalls . . . . . . . . . . . . .25. . . . . . . . . . . . . . . . . . . . . . . . . . 28.3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . ESI-OpenCFD or the OpenFOAM Foundation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 fvOptions . . . . . . . . . . . . 28. . . . . . .1 Output format . . . . . . . . . . . 26. . . . . . . . . . . . . . . . . . . 30. . . . . . . . . 28. .2. . . . . . 31 postAverage 156 156 156 156 156 157 31. . . . . . . . . . . . . . . .3 Geometric regions 26. . . . . . . . . . . . . . . . . . 28. . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . .7 pyFoamDisplayBlockMesh . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . .2 postProcessing . . . . . . . . . . . . . . . . . . 35. . . . . . .6. . . . . . . . . . . . . . .4 Integrate LES .5 Time management . . . . .1 Mandatory keywords . . . . . . . . . . . . . . . . . . .3 const correctness . . . . . . . . . . . . . . .5 The two-phase Courant number .2 Optional keywords . . 37. . . . . 195 37 twoPhaseLESEulerFoam 37. . . . .5. . 35. . . 35. . . . . . . . . . . . . . . . . . .2 Setting the new time step . . . . . . . . .3. .8 A glance behind the run-time selection and debugging magic 35. . . . . . .6. . . . . 34. . . 37. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Denition vs. . . . . 35. . . . . . 37. . . . . . . . . . . . . . . . . . . .4 The le Make/options . . . . . . . . . . . . . . . . . .4 Function inlining . . . . . . . . . . . . . . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . . . . . . . . . . .1 Time stepping . . . . . . . . . . . . . . . 35. . . . .8. . . .3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . . . . . . . . . . . . . . . 37. .2 The next steps . . . .1 Preparatory tasks . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . .5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 The class RASModel . . . . . . . . . . . . . . 35. . . . . . . . . . . . . 195 36. . . .3 How LES in OpenFOAM is used 37. . . . . . . . .3 Adjust Make/files . . . . . . . . . . . . . . . . . . . .7. . . . . . . . . Declaration . . . . . . . . . . . . . . . .2 Copy-Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Copy the sources . . .2 Namespaces . . . . . . . .1 A classy example . . . . . . 34. . . . . . . . . . . . . . .3. . . ® ® 8 . . . . .3 Keyword lookup from dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34. . . . . . . . . . . 37. . . . . . . . . . . . . . . . . . . . . 34. . . . 34. . . . . . .2 Constants and pointers 34. . . . . . . . . . . . . . 35. . . . . . . .7 Debugging mechanism . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Using the debugging mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ® . . . . . . . . . . . . . . . . . . . . . . . . .6 Object orientation . . . . . . . . . . . . .2 The label datatype . . . . . . . . . . . . .8. . . . . . . . . . . . . ® . . . . . . . .4. . . . . 35. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . . . . . . . . .3 A walk in the park: demonstrate some of this magic . . . . . . . .1 General syntax . . . . . . . . . . . . . . . . . . . . . . . 37. . . . . . .1 Abstract classes . . . . . . . . . . . . . . . . . . . . . .5. . . . . . . . . . . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6. . . . . . . . . . . . .1 The Switch datatype .1. . . . . . . .4 The IOobject datatype . . . . . . . . . . . . . .4 The Courant number . . . . . . . . . . . . . . . . . . . . . .7. . . . . 34. . .3 The tmp<> datatype . . . . . . . . . . . . . . . . . . . . . .5. . . . . . .5. . . . . 35. . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Turbulence models . . . . . .5. . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . .IX Source Code & Programming 34 Understanding some C and C++ 34. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34. . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37. . . . . . . . . . . . .2 Preliminary observations . . . . . . . 35. . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . . 35. . . . . . . . . . . .1. . . . . . . . . . 166 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35. . . . . . . . . . . . .1 Constants . .1 Solver algorithms . .2 Use case: Write intermediate elds . . . . . . . . . . . . . . . . . . .2 Namespaces . . . . . ESI-OpenCFD or the OpenFOAM Foundation. .4. . . . . . . . . . .5. . . . . . .4 The class kEpsilon . . 35. . . . . 35. . . . 35. . . . . . . . . . .1 The abstract base class turbulenceModel . . . . . . . . . . . . . . . . . . . . .1 Include required models . . .4. . . .5 Constructor (de)construction . . . . . . 34. 35 Under the hood of OpenFOAM 36 General remarks on solver modications 166 166 166 166 167 167 167 168 169 169 170 171 171 171 171 171 171 171 172 172 173 174 174 175 175 175 178 178 179 181 183 187 187 188 188 189 189 189 190 190 191 192 193 194 195 36. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Preparatory tasks . . . . . . .2. . . . . . . . . . . . . 196 ® 196 196 196 196 197 197 198 199 199 199 This oering is not approved or endorsed by ESI Group. . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . .3. . 35.TypeName . . . . . . . . .1 Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 RAS turbulence models . . . . . . . . . . . .defineTypeNameAndDebug . . . . .6. . . . . 35. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6. .2 Part 2 . . . . . . . . . . .4 OpenFOAM specic datatypes . . . . . 35. . . .2 Replace the k- model . . . 35. . . . .3 A note on the passing of time . . . . . .1 Constant variables . . . . . . . . . . . . . . . 35. . . . . . . . . . . . . . . . .8.2 Rename les . . . . . . . . . . .3 Initialisation list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34. . . 34. . . . . . . . . . 35. . 2 Derivation of the governing equations . . . . . .2 Continuity error . . . . . . . . . . . . 202 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 The k- turbulence model in bubbleFoam and twoPhaseEulerFoam 40. . . .3 Eddy viscosity . . . . . . .4.1 Number density transport equation . . . . . . . .4 Denitions from literature . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 The question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 Denition of standard k- of OpenFOAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38. . . . . . . . . . 40. . . .3. . . . .2 The source code . . . . . . . . . . . . . . . 40. . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40. . . . . . . . . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. .1 Conserving the form . . 205 40 The incompressible k- turbulence model 40. . . . . . .4 Modelling the production of turbulent kinetic energy . . . . . . . . . . . . . . . . . ESI-OpenCFD or the OpenFOAM Foundation. . . . . . . . . . . . . . . . . . . 201 37. . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Governing equations . . . . . . . . . . . . . . . 42. . . . . . . . . . . . . . . . . . . .1 LES model hierarchy . . .4. . . . .2. . . . . . . . . . .2. . . 43. . 39 Momentum diusion in an incompressible uid 202 202 202 202 202 202 202 202 202 203 205 39. . . . . . . . . . . . . . . . . 40. . . . . . . 43. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . 43. . . . . . .3 Continuity error correction . . . . . . . . . . . . . . . . . .2 Interfacial area transport equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . .2. . . . .2 Dierent use of viscosity . . . . . .4 Make ready for compiling . . . . . . . . . . . . . . . . 38. . 40. . . . . .5 The oneEqEddy LES model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 The use of phi 42. . . . . . . 38. . . . 41.3 Interfacial curvature transport equation . . .5 Denitions of Rusche and bubbleFoam . . . . . . . .3 Create a LES model . . . . . . . . . . . . . . . . .3. .2 Classication .1 The k- turbulence model in literature . . . . . . . . . . . . . . .2 Implementation . . . . . . . . . . . . . . . . . 38. . . . . . . 41 Some theory behind the scenes of LES 41. . . . 43 Derivation of the IATE diameter model ® ® 206 206 207 207 208 209 209 210 210 211 211 211 211 212 212 213 214 214 215 215 215 216 216 218 219 219 219 219 220 221 222 222 ® 222 223 223 225 225 225 This oering is not approved or endorsed by ESI Group. . . . . . . . . .6 Denitions of Ferzinger and bubbleFoam . . . . . . 205 39. . . . . . . . . . . . . . . .5 Compile . . . . . .4 The Smagorinsky LES model 41. . .3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . .2 Spatial discretization . 40. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Class hierarchy . . . . . 40. . . . . . . . . . . . . .2.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40. . . . . 42. . . . . . . . . . . . .3 QUICK scheme . .1 Basic denitions . . . . . . . 41. . . . .4. . . . .3.1 Temporal discretization . .2 Implementation . . . . . . . . . . . . . .1 Denitions from literature and source les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 The k- turbulence model in OpenFOAM . .4. . . . . . . . .4. . . . . . . . . . . . . . 38. . . . . . . . . . . . . . . . . 43. . . . . . . . . . . . . . . . .3 Notation . . . . . . .4 MUSCL scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 linearUpwind scheme 38. . . . . . . . . . . . . . . . . . . . . . . . . .3 The math . . 40. . . . . . . . . . . . 201 X 38 Discretization 38. 200 37. . . . . 41. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38. . . . . . . . . . .2. .4. . . .1 upwind scheme . . . . . . . . . . . . . 40.1 Governing equations . . . . . . . . . . . . . . . . . .2. . 38. . . . . . . . . . . . . 41. . . . . . . . . . . . . . . . 40. 40. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41. . . . . . . . . . . . . . Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . .1 Deriving the governing equations . . . . . . . 42. .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43. . . . . . . . . .2 Source code . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . 43. . . . . . . . . . . . . . . . . . . . . . .37.1 The origin of elds 42. . . . . . . . . . . . . . . . . . . . . . . ® ® 9 . . . . . . . .2 Eddy viscosity models . 40. . . . . . . . .2.1 Governing equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 How phi is dened 42. . . . . . . . .2 Terminating a running script 44. . . . .4. . . . . . . . . . . . . . . . . . . . . (252) . . . . . . . . . . . 44. . . . . . .4. . . . . . . . . . .3 Implemented equations . . .5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Meld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44. . . . . . . . . . . . . .3 Find les and scan them . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43. . . . . . . . .1 The proof for Eqn. . .5 Running in scripts . . . . . . .1 Getting help . . . . . . 43. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Starting a batch of jobs . . . 44. . . 43. . . . . . . . .TI . . . . . . . . . . . . . . . . . . . . . .3 Wake entrainment . . . . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. . . . . . . . . . . . . . 43. . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . .2 Random collision . . . . . . . . . 44. 226 227 227 228 228 228 231 231 233 . . . . . . . . . . . .43. . . . . . . . .4 Implementation details of the IATEsource class 43. . . .RC . . . . . .1. . . . . ® ® 10 . . . . . . . . . . . . . . . . . . . . . . . .2. . 43. . . . . . . 233 233 233 233 233 233 233 234 234 235 235 235 236 236 236 45 Archive data 237 References 238 ® ® ® This oering is not approved or endorsed by ESI Group. . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Turbulent impact . 44. . . . . . . . . . 44. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XI 44 Useful Linux commands 44. . .5. . . 44. . . . .2 Finding les . . . . . .6. . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . .4 Interaction models . . . . . . . . . . . . . . . . . . . . . . 44.7 Miscellaneous . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 man pages .5. . .WE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Display help . . . Appendix . . . .4 Scan a log le . . . . . . . . ESI-OpenCFD or the OpenFOAM Foundation. . . . 44. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . .5 Appendix . . .2 In a certain directory . 44. . . 43. . . . . . . . . . . . . .6 di . . . .1 Searching les system wide . . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . 44. . com/Forums/openfoam/ http://openfoamwiki.cfd-online. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.net/index. Elmer).org/ This is a community driven eort to create a documentation on solvers.org/wiki/index.se/~hani/kurser/OS_CFD/ http://caelinux. Code_Saturne. pyFoam or swak4foam.g. ® ® ® This oering is not approved or endorsed by ESI Group.org/docs/user/ http://www. The materials of the course CFD with open source software of Chalmers University The CAELinux Wiki http://www.php/Doc:OpenFOAM CAELinux is a collection of open source CAE software including several CFD codes (OpenFOAM. ® ® 11 . The OpenFOAM User Guide The CFD Online Forum The OpenFOAM Wiki http://www. utilities and modelling. Gerris.chalmers.cocoons-project. there are lots of resources on the internet to nd help on OpenFOAM.tfd. This wiki covers not only the OpenFOAM but also tools that developed for OpenFOAM. e.php/Main_Page The OpenFOAM Wiki is maintained by a community of developers behind the OpenFOAM-extend project. The CoCoons Project http://www.1 Getting help Apart from this manual. ESI-OpenCFD or the OpenFOAM Foundation.openfoam. x git pull Listing 2: Installation von openFOAM Prior to compiling the sources some environment variables have to be dened. g i t cd OpenFOAM− 2 . 1 .org/ First of all. In order to do that a line (see Listing 3) has to added to the le $HOME/.1 Prerequistes OpenFOAM is easily installed by following the instructions from this website: download/git. ESI-OpenCFD or the OpenFOAM Foundation.openfoam. Before compiling a system check can be made by running foamSystemCheck. ® ® 12 . 1 . Afterwards we change into the new directory and check for updates.bashrc When the command eective. It can also be installed on Mac or Windows plattforms. I ® ® ® This oering is not approved or endorsed by ESI Group. .2 directory. −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− Shell : / b i n / bash Host : host OS : Linux v e r s i o n 2. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. cd $HOME mkdir OpenFOAM cd OpenFOAM g i t c l o n e g i t : / / g i t h u b . OpenFOAM is a software made primarily for Linux systems. 1 .Part I Installation 2 Install OpenFOAM 2. sudo apt −g e t i n s t a l l g i t − c o r e sudo apt −g e t i n s t a l l b u i l d − e s s e n t i a l f l e x b i s o n cmake z l i b 1 g −dev qt4 −dev− t o o l s l i b q t 4 −dev g n u p l o t l i b r e a d l i n e −dev l i b x t −dev sudo apt −g e t i n s t a l l l i b s c o t c h −dev libopenmpi −dev Listing 1: Installation of required packages If OpenFOAM is to be used by a single user. com/OpenFOAM/OpenFOAM− 2 . This is done with the version control software Git. Download the sources First of all the source les need to be downloaded.bashrc. x/ e t c / b a s h r c Listing 3: Addition to . However. therefore this manual will be based on the assumption that a Linux system is used. .32 − 39 − g e n e r i c User : user System check : PASS ================== Continue OpenFOAM i n s t a l l a t i o n . s o u r c e $HOME/OpenFOAM/OpenFOAM− 2 . This is easily done via the package management software. user@ host : ~ /OpenFOAM/OpenFOAM− 2 . All steps to perform the described operations are listed in Listing 2. you need to make sure all required packages are installed on your system. source $HOME/.bashrc is issued or when a new Terminal is opened this change is Now with the dened environment variables OpenFOAM can be installed on the system. x .6. http://www.php. 1 . the authors uses a Ubuntu-Linux system. then the User Manual suggests to install OpenFOAM in the $HOME/OpenFOAM 2. x$ foamSystemCheck Checking b a s i c system . com/Forums/openfoam-installation/57512-completely-remove-openfoam-start-fresh. Listing 7 shows how OpenFOAM can be removed from the system.openfoam. ESI-OpenCFD or the OpenFOAM Foundation. e. provided the 2 installation was done following the installation guidelines of OpenFOAM . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The last line of Listing 7 removes a hidden folder. If there are several versions of OpenFOAM installed.0.1. is used./Allwmake. Subsequently paraView can be compiled by the use of an installation script.0.cfd-online. / Allwmake Listing 5: Parallel kompilieren For working with OpenFOAM a user directory needs to be created.Listing 4: foamSystemCheck 2.openfoam. / Allwmake Listing 6: Installation of paraView 2. ThirdParty-2. This is an installation script that takes care of all required operations. The name of this directory consists of the username and the version number of OpenFOAM. In this example.5 Remove OpenFOAM 1 If OpenFOAM is to be removed from the system. two versions of OpenFOAM are installed.x a folder named correspondingly to the OpenFOAM directory. there is no repository release of third-party tools.4 user-2. ® ® 13 . Listing 5 shows how to compile OpenFOAM using 4 processors./Allwmake. we want to remove an installation of OpenFOAM-2.paraview. This folder contains all les of the OpenFOAM installation. The rst line changes the working directory to the installation directory of OpenFOAM. In order to do this.g.php I ® ® ® This oering is not approved or endorsed by ESI Group. This naming scheme is mandatory because there is an environment variable that points to the location of paraView.1. then a few simple operations do the job . an environment variable needs to be set before invoking .1. The source code can be downloaded from http://www. Afterwards some plug-ins for paraView need to be compiled. This archive has to be unpacked into ThirdParty-2. Compiling OpenFOAM can be done by using more than one processor to save time.x this folder needs to be named like this: 2. 1 http://www. then this folder should not be removed. The OpenFOAM Foundation distributes paraView from its homepage and recommends to use this version. e x p o r t WM_NCOMPPROCS=4 . This is done by executing .org/.org/download/git. / makeParaView cd $FOAM_UTILITIES/ p o s t P r o c e s s i n g / g r a p h i c s / PV3Readers wmSET . cd $WM_THIRD_PARTY_DIR . Listing 8 shows the content of the ~/OpenFOAM.1. As there is no development of paraView by the OpenFOAM developers.g.1. The second line removes all les of OpenFOAM and the third line removes the les of the user related to OpenFOAM. We assume. e.x when OpenFOAM-2.x Install paraView paraView is a post processing tool.html 2 http://www.3 Compile the sources If the system check produced to error messages then OpenFOAM can be compiled.tgz. With version 2. see http://www.org/ in an archive.1./ Allwclean . this hash code gets changed. The version number of the repository release is marked by the appended x.1.g. x OpenFOAM− 2 .1.com/ Forums/blogs/wyldckat/931-advanced-tips-working-openfoam-shell-environment. Changes and updates are released quickly. each installation has an additional information to mark dierent builds of OpenFOAM. There is the repository release that can be downloaded using the Git repository. The most important fact about installing several versions of OpenFOAM is to keep the seperated. 1 . Delete the line shown in Listing 3.1.net/index. Mac OSX high performance computing 3 or even Windows4 ). x ThirdParty − 2 . 2. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.x. Whenever OpenFOAM is updated and compiled anew. 3 Updating the repository release of OpenFOAM 3. The source pack can be installed on any system on which the source codes compile (usually all kinds of Linux running computers. e. OpenFOAM 2.g. e. or even computers running other operation systems.html for detailed information about OpenFOAM and the Linux shell. There are several types of those releases.bashrc ~/OpenFOAM le in the home directory. Therefore. This release is updated regularly and is in some ways a development release. See http://www. 1 .OpenFOAM Listing 7: Removing OpenFOAM cd ~/OpenFOAM l s −1 user −2. x−9d 3 4 4 f 6 a c 6 a f Listing 9: Complete version identication of repository releases Apart from the repository release there are also pack releases. 0 .x on one system may or will be dierent to another installation of version 2. x ThirdParty − 2 .1 − r f ~ / .1. see Listing 9. if the build is equal. x OpenFOAM− 2 . ® ® 14 .x on an other system.cfd-online. 1 .0.1. e.0.6 Install several versions of OpenFOAM It is possible to install several versions of OpenFOAM on the same machine. ESI-OpenCFD or the OpenFOAM Foundation. 1 −r f user −2. Because this release is updated frequently an OpenFOAM installation of version 2.g. 3 See http://openfoamwiki. The version number is accompanied by a hash code to uniquely identify the various builds of the repository release. however. These are upadated periodically in longer intervals than the repository release. x user −2.1 Version management OpenFOAM is distributed in two dierent ways. Due to the longer release cycle the pack release is regarded to be less prone to software bugs. In contrast to the repository release all installations of the same version number are equal. x Listing 8: Content of Another thing to remove is the entry in the . SuSE and Fedora) and also a source pack. e. However due to the fact that Open- FOAM relies on some environment variables some precaution is needed. 0 .cd rm rm cd rm ~/OpenFOAM − r f OpenFOAM− 2 . there is a larger possibility of bugs in this release. clusters. The version number of a pack release contains no x. Build : 2 . Two OpenFOAM installations are on an equal level.net/index.php/Tip_Cross_Compiling_OpenFOAM_in_Linux_For_Windows_with_MinGW I ® ® ® This oering is not approved or endorsed by ESI Group.php/Howto_install_OpenFOAM_v21_Mac 4 See http://openfoamwiki.g. 0 . The are precompiled packages for widely used Linux distributions (Ubuntu.1. OpenFOAM 2. 1 . x user@ host : ~ /OpenFOAM/OpenFOAM− 2 . 2 1 e d 3 7 f master −> o r i g i n / master Updating 72 f 0 0 f 7 . Listing 11: OpenFOAM is up to date 3. x$ Listing 13: Check for updates only up to date 5 git pull calls git fetch to download the remote les and then calls git merge to merge the retrieved les with the local les.3. updating is rather simple. / extrudeToRegionMesh / extrudeToRegionMesh . / b a s e C l a s s e s / k i n e m a t i c C l o u d / k i n e m a t i c C l o u d . 1 . C | . . Change in the Terminal to the root directory of the OpenFOAM installation and execute git pull. r e u s e d 93 ( d e l t a 6 2 ) R e c e i v i n g o b j e c t s : 100% ( 1 2 0 / 1 2 0 ) . . If there are newer les in the repository Git will download them and display a summary of the changed les. . 193 i n s e r t i o n s (+) . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. remote : Compressing o b j e c t s : 100% ( 5 7 / 5 7 ) . x$ Listing 12: Check for updates only updates available user@ host : ~ $ cd OpenFOAM/OpenFOAM− 2 . 1 .2 Check for updates If OpenFOAM was installed from the repository release. From g i t : / / g i t h u b . remote : T o t a l 44 ( d e l t a 3 2 ) . Notice. 0 5 KiB . x/ user@ host : ~ /OpenFOAM/OpenFOAM− 2 . . ESI-OpenCFD or the OpenFOAM Foundation. without actually making an update. 9 7 c f 6 7 d master −> o r i g i n / master user@ host : ~ /OpenFOAM/OpenFOAM− 2 .H | 6 f i l e s changed .3 Check for updates only If you want to check for updates only. 0 . . 1 . user@ host : ~ $ cd $FOAM_INST_DIR user@ host : ~ /OpenFOAM$ cd OpenFOAM− 2 . . . 1 7 . r e u s e d 43 ( d e l t a 3 1 ) Unpacking o b j e c t s : 100% ( 4 4 / 4 4 ) . completed with 56 l o c a l o b j e c t s .H | . In this case Git only checks the repository and displays its ndings without actually making any changes. x = [ up t o d a t e ] master −> o r i g i n / master user@ host : ~ /OpenFOAM/OpenFOAM− 2 . x 72 f 0 0 f 7 . / Templates / KinematicCloud / KinematicCloudI . / Templates / KinematicCloud / KinematicCloud . . 0 . The option responsible for this is instead of git pull 5. 2 1 e d 3 7 f Fast −f o r w a r d . So checking for updates is actually done by git fetch. done .C | . 1 . 1 . . . done . com/OpenFOAM/OpenFOAM− 2 . --dry-run. . then Git will output a corresponding message. To update OpenFOAM simply use Git to check if there are newer source les available. 41 d e l e t i o n s ( − ) 10 7 157 6 7 47 +− +− ++++++++−−−−− +− + ++++++− Listing 10: There are updates available If OpenFOAM is up to date. 0 . 0 . ® ® 15 . remote : Compressing o b j e c t s : 100% ( 1 3 / 1 3 ) . From g i t : / / g i t h u b . 1 . user@ host : ~ /OpenFOAM/OpenFOAM− 2 . x$ g i t f e t c h −−dry −run −v From g i t : / / g i t h u b . done . . remote : T o t a l 120 ( d e l t a 8 9 ) . x$ g i t p u l l Already up−to −d a t e . / e x t r u d e / extrudeToRegionMesh / c r e a t e S h e l l M e s h . that git fetch is called user@ host : ~ $ cd OpenFOAM/OpenFOAM− 2 .H | . x/ user@ host : ~ /OpenFOAM/OpenFOAM− 2 . / e x t r u d e / extrudeToRegionMesh / c r e a t e S h e l l M e s h . x$ g i t f e t c h −−dry −run −v remote : Counting o b j e c t s : 1 8 9 . done . R e s o l v i n g d e l t a s : 100% ( 8 9 / 8 9 ) . Git can be invoked using a special option (see Listings 12 and 13). x$ g i t p u l l remote : Counting o b j e c t s : 6 7 . com/OpenFOAM/OpenFOAM− 2 . . x 5 ae2802 . I ® ® ® This oering is not approved or endorsed by ESI Group. . done . com/OpenFOAM/OpenFOAM− 2 . done .H | . 1 . . 10). I ® ® ® This oering is not approved or endorsed by ESI Group.5. missing packages can be the cause.x). This reduces the output of the successful operations considerably and the actual error messages of the compiler are easier to nd. ® ® 16 .1 Missing packages If there has been an upgrade of the operating system 6 it can happen.0 → OpenFOAM-2.4. wclean a l l Listing 15: Prepare recompilation with wclean The brute force variant would be. This may or will take much longer.2. Then the However if the compilation ends with some errors.4. 3. For simplicity an update of a point release (OpenFOAM-2. OpenFOAM-2. cd $FOAM_INST_DIR cd OpenFOAM− 2 .1.1.1. 6 An upgrade of an OS is indicated by a higher version number of the same (Ubuntu 11.2 Updated Libraries When libraries have been updated.2 Trouble-shooting If compilation reports some errors it is helpful to call . git pull the changed source les need to be compiled in order to This is done the same way as is it done when installing OpenFOAM.g. The complete workow 3. 3. everything is compiled./Allwmake to compile. compiling after an update takes less time than compiling when installing OpenFOAM.04 → Ubuntu 11.4 Install updates After updates have been downloaded by update the executables.1) can be treated like a complete new installation. so unchanged les will not be compiled again.5. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ESI-OpenCFD or the OpenFOAM Foundation. this command usually does the trick. git pull. see Section 2.1 Workow Listing 14 shows the necessary commands to update an existing OpenFOAM installation. x git pull wclean all .g. that some relevant packages have been removed in the course of the update (e. If was not called before.3. then only the les that did change are compiled. The rst two commands in Listing 14 change to the directory of the OpenFOAM installation. then wclean all If wclean all wclean all was invoked then should be called before compiling. The point releases (every version of OpenFOAM without an x in the version number) are not updated in the same sense as the repository releases. The last statement causes the source les to be compiled. to recompile OpenFOAM as a whole. / Allwmake Listing 14: Update an existing OpenFOAM installation. In order to avoid this problem the corresponding library has to be recompiled.6. if these packages are only needed to compile OpenFOAM and the OS 'thinks' that these packages aren't in use). This will in most cases make sure that compilation of the updated sources succeeds. Otherwise solvers would call functions that are not (yet) implemented. An update leaves the version number unchanged. If there is enough time for the update (e. they have to be recompiled.g. Simply call This script recognises changes.5. if recompiling OpenFOAM fails after an OS upgrade. So. Consequently. However this applies only for repository releases (e. instead of recompiling a updated library. see Section 3.5 Problems with updates 3. . 3. latest source les are downloaded by invoking The statement in red can be omitted. overnight). 1 ./Allwmake again. 4. i. Such a library is compiled with wmake libso. These les tell wmake and therefore also the compiler where to is a large eddy turbulence model from code is stored in nd necessary libraries and where to put the executable.2.net/index. See Section 7. To recompile OpenFOAM the sources need to be reset. 4 Install third-party software The software presented in this section is optional. g i t c l e a n −d f x Listing 16: Reset the sources using git The command listed in Listing 16 causes git to erase all les git does not track. if there is any other reason the sources won't compile and the cause is not found. To use an external library the solver needs to be told so.3 Updated sources fail to compile In some cases. Or. e. 4. Although compiling OpenFOAM takes its time.3. However.5. Compile external libraries There is the possibility to extend the functionality of OpenFOAM with additional external libraries.e. 4.php/Contrib_PyFoam#Installation for the instructions on the instal- See lation of pyFoam.g. In this case.3 for instructions on installing swak4foam. ESI-OpenCFD or the OpenFOAM Foundation. That means all les that are not part of the git -repository are deleted. then a complete recompilation of OpenFOAM may be the solution of choice.1.1. This is also the case when libraries of OpenFOAM have been modied. A more detailed description of this two les can be found in Sections 37.net/index.3. this may take less time than tracking down all errors.php/Contrib/swak4Foam See 4. cd OpenFOAM/ AlbertoPa / dynamicSmagorinsky wmake l i b s o Listing 17: Compilation of a library I ® ® ® This oering is not approved or endorsed by ESI Group. the sources have to be compiled as described in Section 2.com/AlbertoPa/dynamicSmagorinsky.3 and 37.1 Install pyFoam http://openfoamwiki. The source OpenFOAM/AlbertoPa/. when there were changes in the organisation of the source les. The option -d means that also untracked folders are removed. the sources fail to compile right away. the software mentioned in this section can be very useful for specic tasks. git clean removes all les that are not under version control recursively starting from the current directory. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. libraries for OpenFOAM from other sources than the developers of OpenFOAM.3. One example of such an external library https://github. this is the ocial git -repository of OpenFOAM. The reason why typing wmake libso is sucient is because all information wmake requieres is stored in the les Make/files and Make/options. there is a simple command that takes care of this. Without this software OpenFOAM is complete and perfectly useable.2 Install swak4foam http://openfoamwiki. Instead of deleting OpenFOAM and installing it again. After the command from Listing 16 is executed. ® ® 17 . 1 . that some physical constant. Therefore. As the list of base units in [4. ESI-OpenCFD or the OpenFOAM Foundation.g. e.1. m/s2 has been OpenFOAM recognises this false denition. Listing 19 shows a corresponding error message produced by two summands having dierent units. ® ® 18 . the universal gas constant. II ® ® ® This oering is not approved or endorsed by ESI Group. c o n s t fvMatrix <Type>&) i n f i l e /home/ u s e r /OpenFOAM/OpenFOAM− 2 . OpenFOAM aborts and displays an error message. like viscosity. fth and sixth base units appear in a dierent position. 3] starts with the metre followed by the kilogram. OpenFOAM uses the International System of Units. Also the fourth.1 An important note on the base units The order in which the base units are specied diers between OpenFOAM and many publications dealing with SI units. short: SI units. (2) is based on the source code of OpenFOAM. 0/U. e. also other units can be used. For elds.g. x/ s r c / f i n i t e V o l u m e / l n I n c l u d e / f v M a t r i x . [Q]OpenFOAM = kgα mβ sγ Kδ mol Aζ cdη α β γ δ ζ [Q]SI = m kg s A K mol cd (2) η (3) Eq. Units in the International System of Units are dened as products of powers of the SI base units. Listing 18: False dimensions for U −−> FOAM FATAL ERROR: incompatible dimensions f o r operation [U[ 0 1 −3 0 0 0 0 ] ] + [U[ 0 1 −4 0 0 0 0 ] ] From f u n c t i o n checkMethod ( c o n s t fvMatrix <Type>&. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. compare (2) and (3). Consequently the values need to be adapted if other units that SI should be used. In that case it is important to remember. like the velocity. are stored in SI units.1 Unit inspection OpenFOAM performs in addition to its calculations also a inspection of the physical units of all involved variables and constants.C a t l i n e 1316. Eq. OpenFOAM reverses this order and begins with the kilogram followed by the metre. 5. see Listing 20. or constants. (3) is based on [4. because mathematical operations do not work out anymore. 5. dimensions [ 0 1 −2 0 0 0 0 ] .Part II General Remarks about OpenFOAM 5 Units and dimensions Basically. [Q] = kgα mβ sγ Kδ mol Aζ cdη (1) A dimension set contains the exponents of (1) that dene the desired unit. The order of the base units as it is used by OpenFOAM swaps the rst two base units. the unit has to be specied. 3]. Nevertheless. in the le dened instead of m/s. FOAM a b o r t i n g Listing 19: incompatible dimensions Listing 18 shows an incorrect denition of the dimension of the velocity. The unit is dened in the dimension set. With the dimension set OpenFOAM is able to perform unit checks. S c a l a r &) in f i l e l n I n c l u d e / S c a l a r .C at l i n e 91. e. e. The unit of units (rho and nu) d is dened by the full set of seven exponents. pressure.g. phaseb { rho nu d } rho [ 1 −3 0 0 0 ] 1 0 0 0 .g. Apparently it is allowed to omit the last two exponents (dening candela and ampere). Reynolds stresses.g. Notice the dierence between the rst two denitions and the third one. volScalarField p volVectorField A vector eld throughout the whole domain. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. second. whereas the other two are dened only by ve exponents. // Ampere A LUMINOUS_INTENSITY // Candela Cd }.1. // k i l o g r a m kg LENGTH. From f u n c t i o n o p e r a t o r >>(I s t r e a m &. found on l i n e 22 t h e p u n c t u a t i o n token '] ' f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 . d [ 0 1 0 0 0 0 0 ] 0. x/ run / twoPhaseEulerFoam / bed / c o n s t a n t / t r a n s p o r t P r o p e r t i e s : : phaseb : : nu a t l i n e 2 2 . 1 . Neither the OpenFOAM User Guide [24] or the OpenFOAM Programmer's Guide [23] mention this behaviour.2 Dimensionens Fields in uid mechanics can be scalars.2 Input syntax of units Listing 21 shows the denition of a phase in a two-phase problem. ® ® 19 . ESI-OpenCFD or the OpenFOAM Foundation. Dening units with ve entries (for kilogram. For uid dynamics involving compressible ows as well as reactive ows and combustion the rst ve units of OpenFOAM's set of base units suce.1 2 3 4 5 6 7 8 9 10 11 //− D e f i n e an enumeration f o r t h e names o f t h e d i m en s i o n e x p o n e n t s enum dimensionType { MASS. volVectorField U volTensorField A tensor eld throughtout the whole domain. // metre m TIME. kelvin and mol) seems to be perfectly appropiate. There are in OpenFOAM dierent data types to distinguish between quantities of dierent dimension. vectors or tensors. nu [ 0 2 −1 0 0 ] 1 e − 06. // mole mol CURRENT. 5. // s e c o n d s TEMPERATURE. volTensorField Rca II ® ® ® This oering is not approved or endorsed by ESI Group.00048. volScalarField A scalar eld throughout the whole computaional domain. metre. Listing 21: Denition of the unit −−> FOAM FATAL IO ERROR: wrong token type − e x p e c t e d S c a l a r . // K e l v i n K MOLES. e. FOAM e x i t i n g Listing 22: Erroneous denition of units 5. velocity.H The reason for changing the order of the base units may be motivated from a CFD based point of view. Dening a unit with an other number of values than ve or seven leads to an error (see Listing 22). Listing 20: The denition of the order of the base units in the le dimensionSet. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. pˆ = For this reason the entries in the 0/p p ρ (4) les dier depending on the solver in use. Compressible solvers work with the pressure itself.g. uniform 0 . 1 . pressure The denition of pressure in OpenFOAM diers between the compressible and incompressible solvers. e.surfaceScalarField A scalar eld. fixedValue . uniform ( 0 0 0 ) .1 Dimension check The data type denes also. The dimension of a quantity denes the syntax how quantities have to be entered. dynamic viscosity To determine if OpenFOAM uses the kinematic viscosity [Ns/m 2 = Pas] or the dynamic viscosity [m 2 /s] one has simply to take a look on the dimension. ® ® 20 . e. ESI-OpenCFD or the OpenFOAM Foundation.g. x/ run / twoPhaseEulerFoam / bed /0/ a l p h a : : i n t e r n a l F i e l d a t l i n e 19. dimensionedScalar nu 5. found on l i n e 19 t h e p u n c t u a t i o n token '( ' f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 . because of ρ = const the incompressible equations are divided by the density and to eliminate density entirely the modied pressure is introduced into the pressure term.4 Pitfall: pressure vs. as described before.2. Listing 23: Erroneous denition of α −−> FOAM FATAL IO ERROR: wrong token type − e x p e c t e d S c a l a r . Listing 24 shows the error message OpenFOAM displays when the value of a scalar quantity is entered as a vector (Listing 23). compressible or incompressible. the dimension of a quantity. The reason for this is. II ® ® ® This oering is not approved or endorsed by ESI Group. nu nu [ 0 2 −1 0 0 0 0 ] 0 . surfaceScalarField phi dimensionedScalar A scalara constant throughout the whole domain (i. 0 1 .3 Kinematic viscosity vs. dimensions internalField boundaryField { inlet { type value } [ 0 0 0 0 0 0 0 ]. From f u n c t i o n o p e r a t o r >>(I s t r e a m &. This is visible by the unit of pressure. 5. no eld quantity). FOAM e x i t i n g Listing 24: Error message caused by invalid dimension 5.C at l i n e 91.e. Listing 25: dimensions of the viscosity The type of viscosity is primarily determined by the used solver. S c a l a r &) in f i l e l n I n c l u d e / S c a l a r . ux. dened on surfaces (surfaces of the niten volumes). Incompressible solvers use a modied pressure. like bubbleFoam. ESI-OpenCFD or the OpenFOAM Foundation. The second command prints the contents of the current folder. Listing 28 shows the output of the commands ls pwd and when they are invoked from a case directory. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.2 Compressible The unit of the pressure in a compressible solver is the physical unit of pressure. In most cases it is assumed that the pressure is equal in all phases. for each phase a momentum equation is solved. Listing 27: Unit of pressure .compressible 5. 1 .incompressible 5. 6 Files and directories OpenFOAM saves its data not in a single le.4. The fact that these three items are directories and not les is indicated by a dierent color. 1 . 1 . constant and system ). The rst command returns the absolute path of the current working directory. it uses several dierent les.4. twoPhaseEulerFoam or multiPhaseEulerFoam.5. 6. 1 .1 Required directories An OpenFOAM case has a minimal set of les and directories. the modied pressure would be diernt for each phase. Depending on its purpose a specic le is located in one of several folders. Listing 26: Unit of pressure . x/ run / icoFoam / c a v i t y $ l s − l i n s g e s a m t 12 drwxrwxr−x 2 u s e r group 4096 Okt 2 1 4 : 5 3 0 drwxrwxr−x 3 u s e r group 4096 Okt 2 1 4 : 5 3 c o n s t a n t drwxrwxr−x 2 u s e r group 4096 Okt 2 1 4 : 5 3 system Listing 28: Case directory II ® ® ® This oering is not approved or endorsed by ESI Group. like Fluent does.4. ® ® 21 . For this reason the incompressible equations can not be divided by the density. To avoid this issue. If ls is called with the option -l are more detailed list is printed. The directory that contains those folders is called the root directory of the case or case directory. x/ run / icoFoam / c a v i t y $ pwd /home/ u s e r /OpenFOAM/ u s e r − 2 . because each phase has a dierent density and therefore. x/ run / icoFoam / c a v i t y $ l s 0 c o n s t a n t system user@ host : ~ /OpenFOAM/ u s e r − 2 . use the physical pressure like compressible solvers do. user@ host : ~ /OpenFOAM/ u s e r − 2 . This detailed list indicates if an entry is a le or a directory. In this case there are three subdirectories (0. incompressible Euler-Euler solvers. When ls is invoked without any options it returns the names of all non-hidden les and folders.3 Pitfall: Pressure in incompressible multi-phase problems When solving a multi-phase problem in an Eulerian-Eulerian fashion. kgm [p] = dimensions N kg 2 = s2 = 2 m m ms2 (6) [ 1 −1 −2 0 0 0 0 ] . x/ run / icoFoam / c a v i t y user@ host : ~ /OpenFOAM/ u s e r − 2 .1 Incompressible The unit of the pressure in an incompressible solver is dened by (4) [ˆ p] = dimensions N m3 m kgm m m2 · =N = 2 · = 2 2 m kg kg s kg s (5) [ 0 2 −2 0 0 0 0 ] . t = 0. The number of les is equal or larger than in the 0 -directory containing the initial conditions. ESI-OpenCFD or the OpenFOAM Foundation. Therefore.2. The tool that is used to decompose the case created the processor *-directories.2 for a brief introduction to some of the more common of them. A new time-directory is created with the number of elapsed seconds in its name.3. This les are necessary to run a simulation. if there is no specic reason for a case to a case will always begin at time t = 0. The system -directory remains in the case folder. Besides them there may also be additional les controlling other tools. 6. then all data generated by sample is stored in a folder named sets. Every one of the parallel *-directories contains a 0 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 6. at dened times all information is written two the harddisk. to divide the problem between the involved parallel processes. etc. 6. Each function creates a folder of the same name to save its data in.1 processor * If a case is solved in parallel.1 The main les This les have to be present in the system folder to be able to run a calculation controlDict This le contains the controls related to time steps. then the domain has to be split into 4 parts.3 Files in system In the directory named system there are three les for controlling the solver. It contains the initial and boundary conditions of all variable quantities. polymesh system This is a subdirectory of constant.e. 6.2. solver algorithms and tolerances. i. See Section 26 for more information about sample. However. the case is computed using more than one processor at the time. if a case is to be solved using 4 parallel processes.5 for more information about conducting parallel calculations. A case does not have to start at time start at another time that t = 0. 6. 6. The name of a time-directory is simply the number of elapsed seconds. See Section 8. First of all. output interval. constant This folder contains all les dealing with constant quantities as well as the mesh.0 This is the rst of the time-directories.2. see Section 6.3 sets If the tool sample has been used. II ® ® ® This oering is not approved or endorsed by ESI Group.and also a constant -directory containing only the mesh. In this folder all kinds of les are saved. In this case the computational domain has to be decomposed into several parts.2 Supplemental directories Directories described in this Section may be created in the course of a computation. In this folder all les dening the mesh reside. So. In this folder all les that control the solver or other tools are located In the course of computing the case two kinds of folders are created. The second category of directory subsumes all kinds of folders created for all kind of reasons or by all kind of tools.2 functions functions or functionObjects perform all kind of operations during the computation. fvSchemes In this le the nite volume discretisation schemes are dened fvSolution This les contains controls related to the mathematical solver. the folders processor0 to processor3 are created. See Section 25 for more information about functions. ® ® 22 . The * stands for a consecutive number starting with 0. a list or a dictionary. a number.g.2. Y or Z found ABC. Then OpenFOAM produces an error message with a list of allowed entries. decomposeParDict Used by decomposePar. See Section 7. in some cases allowed entries are not visible at a glance.1 Keywords . C a t l i n e 80 bad c o m p r e s s i o n s p e c i f i e r ' banana ' . −−> FOAM FATAL IO ERROR: e x p e c t e d startTime . as OpenFOAM aborts all further operations.6.1 Syntax The dictionaries need to comply a certain format. when the banana test is used with the control compression of controlDict.2 for a description of this control. that the dictionaries follow a syntax similar to the C++ syntax. f i r s t T i m e o r l a t e s t T i m e found ' banana ' Listing 29: Wrong keyword. The error message contains a note that is formated in this way: expected X. 7 Control Most of the controls of OpenFOAM are set in so called dictionaries. u s i n g ' uncompressed ' Listing 30: Failed banana test II ® ® ® This oering is not approved or endorsed by ESI Group. e. 7.the banana test As OpenFOAM oers no graphical menus. e. Instead of returning an error message and exiting. ® ® 23 . then the user can enter a value that is denitely not applicable.g. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. −−> FOAM Warning : From f u n c t i o n IOstream : : compressionEnum ( c o n s t word&) i n f i l e db/ IOstreams / IOstreams / IOstream . banana. Listing 30 shows the warning message OpenFOAM returns. or the banana test Listing 29 shows the error message that is displayed when the value banana is assigned to the key startFrom that controls at which time a simulation should start. An important dictionary is the le controlDict. OpenFOAM simply assumes a value in place of the invalid entry. Denitions for the post-processing tool sample.1. probesDict Alternative to the use of the le probesDict. ESI-OpenCFD or the OpenFOAM Foundation.3. The OpenFOAM User Guide states. setFieldsDict sampleDict Necessary for the tool setFields to initialise eld quantities. only the rst one produces an error. Pitfall: assumptions & default values In some cases the banana test behaves dierently than expected. The most basic format to enter data in a dictionary is the key-value pair. The value of a key-value pair can be any sort of data. In this le the number of subdomains and the method of decom- position are dened. probes can also be dened in the le controlDict. In this case. The le format follows some general principles of C++ source code. OpenFOAM does not abort but continues to run the case.2 Additional les This list contains a selection of the most common les to be found in the system-directory. 7. If in a dictionary several key-value pairs are erroneous. If a key expects a value of a nite set of data. Listing 32 shows the provoked error message. There is no error message if a setting was made and that setting is not needed. In this sense. There is no error message if an optional setting (that is necessary) was omitted. Listing 31 shows the content of the le U1 in the 0 - directory. Consequently the denition of a variable time step in controlDict does not necessarily mean. If only the denition. internalField uniform ( 0 0 0 ) . If they are not present. of the BC of the walls is examined. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. that OpenFOAM terminates reading the le after the missing semicolon causes a syntax error. because the BC denition of the walls is perfectly correct. lines are terminated by a semicolon. OpenFOAM will return an error message. boundaryField { inlet { type value } outlet { type } } walls { type value } fixedValue . that the simulation is performed with variable time steps. The line dening the boundary condition (BC) for the outlet was not terminated properly. e.1. About errors There will be an error when mandatory settings were not made. The solver simply ignores it. 0 3 7 0 4 ) . ESI-OpenCFD or the OpenFOAM Foundation. One reason for this may be. and therefore the boundary condition for the walls remain undened.1. a simulation can be run only if all mandatory settings were made. This example demonstrates that the error messages are sometimes not very meaningful if they are taken literally.3. Sometimes an error message points to the setting of a keyword that is actually not faulty. See Section 35.7. the cause for the error message will remain unclear. zeroGradient fixedValue . The error was made at the deniton of the BC for the outlet. The deniton of the boundary condition for the walls comes after the outlet denition. ® ® 24 .3 Pitfall: semicolon (. See Section 7. which is used if the user does not specify a value.1. This error message does not mention outlet. uniform ( 0 0 0 . Other settings have a default value. if icoFoam (a xed time step solver) is used. All optional controls have a default value and will be in place. dimensions [ 0 1 −1 0 0 0 0 ] . 7. Listing 31: Missing semicolon in the denition of the BC II ® ® ® This oering is not approved or endorsed by ESI Group.2 Mandatory and optional settings Some settings are expected by the solver to be made.3 for a detailed discussion including a thorough look at some source code about reading keywords from dictionaries. but rather walls keyword walls is undened. settings can be divided into mandatory and optional ones. uniform ( 0 0 0 ) . As mandatory settings causes an error if they are not set.) Similar to C++.g. nextWrite. 7 If the simulation is set to start from rstTime or latestTime. FOAM e x i t i n g Listing 32: Error message caused by missing semicolon 7. C a t l i n e 4 6 1 . adjustTimeStep controls whether time steps are of xed or variable length. some startFrom and startTime. E. see Section 8. a xed time step is assumed by default. endTime end time for the simulation deltaT time step of the simulation if the simulation uses xed time steps. rstTime the simulation starts from the earliest time step from the set of time directories. 7. Allowed values are: on/o. Otherwise this entry is completely ignored . startTime start time from which the simulation starts.2. this keyword can be omitted or the value of this keyword can be anything startTime banana does not lead to an error. A xed time step solver simply ignores this control without displaying any warning or error message. The settings in the controlDict are not only read by the solvers but also by all kinds of utilities. These enable or disable a function or a feature.g. startFrom controls the start time of the simulation.2 controlDict In this dictionary controls regarding time step. a simulation can be stopped by using setting stopAt to one of these values {nextWrite.1. 8 If this keyword is omitted. stopAt controls the end of the simulation. 1 .1 Time control In this Section the most important controls with respect to time step and simulation time are listed. 8 This keyword is important only for solvers featuring variable time stepping. controlDict ) at the beginning of each time step. In a variable time step simulation this value denes the initial time step. noWriteNow. Possible values are {endTime. true/false or yes/no. From f u n c t i o n d i c t i o n a r y : : s u b D i c t ( c o n s t word& keyword ) c o n s t i n f i l e db/ d i c t i o n a r y / d i c t i o n a r y . II ® ® ® This oering is not approved or endorsed by ESI Group.−−> FOAM FATAL IO ERROR: keyword w a l l s i s u n d e f i n e d i n d i c t i o n a r y "/home/ u s e r /OpenFOAM/ u s e r − 2 . 7. noWriteNow.4 Switches Besides key-value pairs there are switches. writeNow}. what would be the case if the simulation started from a specic start time.g. startTime the simulation starts from the time specied by the startTime keyword entry. endTime the simulation stops when a specied time is reached. they only can have a logical value. See Section 35. ESI-OpenCFD or the OpenFOAM Foundation. 1 . This has to be kept mesh modication utilities obey the settings of the keywords in mind when using a number of utilities for pre-processing. x/ run / twoPhaseEulerFoam / c a s e /0/U1 : : b o u n d a r y F i e l d " f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 . runTimeModiable controls whether or not OpenFOAM should read certain dictionaries (e. There are three possible options for this keyword. ® ® 25 . Only relevant if startFrom startTime has been 7 specied. writeNow}. latestTime the simulation starts from the latest time step from the set of time directories.2. x/ run / twoPhaseEulerFoam / c a s e /0/U1 : : b o u n d a r y F i e l d from l i n e 25 t o l i n e 4 7 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. This list makes no claim of completeness.4. Consequently. simulation time or writing data to hard disk are located. writeNow the simulation stops after the current time step is completed and the current solution is written to disk.1 for a detailed discussion about valid entries. If this option is enabled. time steps. Pitfall: timePrecision OpenFOAM is able to automatically increase the value of 9 timePrecision parameter if need arises. This leads to a automatic increase of time precision after the rst time step is written to disk. I. This is typically the case when a simulation diverges and the (dynamic) time step gets decreased by orders of magnitudes.2 Data writing In controlDict the controls regarding data writing can be found. However.1023 s. runTime when this option is chosen. for a the data is written every 1s interval the data is written at writeInterval t = 1.2. Consequently. adjustableRunTime this option allows the solver to adjust the time step. the options are {ascii. If a simulation that increased its time precision is to be restarted or continued from the latest time step. . due to a reduction in (dynamic) time step size . e. I. It is up to the reader to decide whether this is an easy to spot error. Often. all written les are compressed using gzip.5. writeControl controls the timing of writing data to le. Listing 34 shows the according error message and a directory listing of the case directory. simulations that do not diverge may also create the need for an increase in time precision. binary}. 7 0 8 8 4 Listing 33: Exemplary solver output in the case of an automatic increase of the timePrecision value.0012. if ∆t can't be represented with timePrecision number of digits after the comma. This behaviour is hard to detect for an unaware user. By default compression is disabled. scalar that controls the interval of data writing. timeStep}.e. Thus. a of 3 is not sucient to represent the latest time step at t = 0. writeFormat controls how the data is written to hard disk. The default value is 6. i. timePrecision species the number of digits after the decimal point. which motivated him to elaborate on this issue in this little collection of errors and misbehaviour. OpenFOAM oers several ways to dene how and when the data is to be written to the hard disk. When it is activated. It is possible to write text les or binary les. Allowed values are {adjustableRunTime. ESI-OpenCFD or the OpenFOAM Foundation. 2. This value gets its meaning from the value assigned to writeControl. See Section 35. II ® ® ® This oering is not approved or endorsed by ESI Group. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. it is not necessary to save every time step of a simulation. Consequently.0005. timePrecision OpenFOAM will apply rounding to the reach the selected number of digits behind the comma.e. . The only clue for detection lies in this case in the fourth digit behind the comma. The author took some time. clockTime. . then every writeInterval seconds the data is written. s. timeFormat controls the format that is used to write the time step folders.e.102 s. which is present in only in the name of the time step directory but not in the timeName that is looked up by OpenFOAM. 9 A dynamic increase of the timePrecision value in simulations with xed time steps indicates a setting in which the time precision is not sucient to adequately represent the time step. so that every writeInterval seconds the data can be written. ® ® 26 . writeCompression controls whether to compress the written les or not. runTime. I n c r e a s e d t h e t i m e P r e c i s i o n from 6 t o 7 t o d i s t i n g u i s h between timeNames a t time 4 . OpenFOAM will fail to nd les at time t = 0. writePrecision controls the precision of the values written to the hard disk.7. cpuTime. then t1 + ∆t also can't be represented. Otherwise the times at which data is written does not exactly match the entry in timeStep writeInterval writeInterval. then the chosen time precision may not be sucient to represent the present time step values.g. t1 and t1 + ∆t would get the same time name and would consequently be indistinguishable.3 on more implementation details on this matter. 1 0 2 3 c o n s t a n t system user@ host : ~ /OpenFOAM/ u s e r − 2 . x/ run / icoFoam / c a v i t y $ l s 0 0 . functions can be enabled or disabled at run-time. probing values or run-time post-processing. 3 .com/AlbertoPa/dynamicSmagorinsky/. x/ run / icoFoam / c a v i t y / 0 .−−> FOAM FATAL IO ERROR: cannot f i n d file f i l e : /home/ g e r h a r d /OpenFOAM/ u s e r − 2 . functionObjectLibs (" l i b s a m p l i n g . functions { probes1 { type p r o b e s .g. e. ® ® 27 .3 Loading additional Libraries Additional libraries can be loaded with an instruction in controlDict. ESI-OpenCFD or the OpenFOAM Foundation.4 functions functions. Listing 35: Load additional libraries. This model can be found athttps://github. Listing 35 shows how an external library (in this case a turbulence model that is not included in OpenFOAM) is included. or functionObjects as they are called in OpenFOAM. controlDict entry 7. so ") . fields ( p U ). We fail to restart the simulation as OpenFOAM is not able to nd the correct time step. the denition of a probe -functionObject. oer a wide variety of extra functionality. See Section 25. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.2. e. 3 . 1 0 2 / p a t l i n e 0 . probeLocations ( (0.05) ).2.g. C a t l i n e 7 3 . 7. outputControl outputInterval } } outputTime . s o " ) .5 Outsourcing a dictionary Some denitions can be outsourced in a seperate dictionary. Listing 36: Denition of a probe in controlDict II ® ® ® This oering is not approved or endorsed by ESI Group.2. x/ run / icoFoam / c a v i t y $ Listing 34: Exemple of an error caused by an automatic increase of the timePrecision value in the previous simulation run. 7. 3 .01. All inclusive In this case the probe is dened completely in controlDict.5 0.5 0. 0. FOAM e x i t i n g user@ host : ~ /OpenFOAM/ u s e r − 2 . l i b s ( " libdynamicSmagorinskyModel . From f u n c t i o n r e g I O o b j e c t : : readStream ( ) i n f i l e db/ r e g I O o b j e c t / r e g I O o b j e c t R e a d . 05) ). Listing 38: Denition of probes in the le probesDict Everything external There is also the possibility to move the whole denition of a functionObject into a seperate le.5 0.Seperate probesDict In this case the denition of the probe is done in a seperate le the probesDict. interpolationScheme cellPoint . functions { #i n c l u d e " c u t t i n g P l a n e " } Listing 39: Completely external denition of a functionObject . so ") . II ® ® ® This oering is not approved or endorsed by ESI Group. surfaceFormat fields raw . functions { probes1 { type p r o b e s . Entry in controlDict fields ( p U ). Entry in controlDict cuttingPlane { type surfaces . This macro is similar to the pre-processor macro if C++. In controlDict the name of this dictionary is assigned to the keyword dictionary. surfaces ( yNormal { type cuttingPlane . In this case the macro #include is used. functionObjectLibs (" l i b s a m p l i n g . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. pointAndNormalDict { basePoint (0 0. It is not possible to assign the path of this dictionary to this keyword. This dictionary has be located in the system-directory of the case.1 0) . } } dictionary probesDict . planeType pointAndNormal .01. ( alpha1 ) . so ") . ® ® 28 . ESI-OpenCFD or the OpenFOAM Foundation. functionObjectLibs (" l i b s a m p l i n g . 0. Listing 37: External denition of probes . outputControl outputTime . outputControl outputInterval outputTime . probeLocations ( (20.5 0. 1 Solver control The solvers dictionary contains settings that determine the work of the solvers (e. ESI-OpenCFD or the OpenFOAM Foundation.g.5 Pitfalls 7. ® ® 29 . pRefValue 0. PIMPLE { nOuterCorrectors 1. In this way. controlDict or fvSolution ) are read anew. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.} } ).4. Listing 43 shows such a warning message. } normalVector interpolate (0 1 0) . if a le has changed.).3 cuttingPlane Run-time modifcations If the switch runTimeModiable is set true. certain les (e.1 timePrecision If the time precision is not sucient. e. then OpenFOAM issues a warning message and increases the time precision without aborting a running simulation. solution methods.4 fvSolution The le fvSolution contains all settings controlling the solvers and the solution algorithm.5. See Section 20. on or yes . 7. 7. 1 . the write interval can be changed during the simulation. I.g. If OpenFOAM detects a run-time modication it issues a message on the Terminal. toler- ances. The rst controls the solvers and the second controls the solution algorithm.e. that the name of this dictionary is in upper case letters unlike most other dictionaries. } Listing 42: The PIMPLE dictionary 7. etc. true . This le must contain two dictionaries. nNonOrthogonalCorrectors 0 .g. regIOobject : : readIfModified () : Re− r e a d i n g o b j e c t c o n t r o l D i c t from f i l e "/home/ u s e r /OpenFOAM/ u s e r − 2 . pRefCell 0. x/ run / multiphaseEulerFoam / bubbleColumn / system / c o n t r o l D i c t " Listing 41: Detected modifaction of controlDict at run-time of the solver 7. The simulation time exceeded 100 s and OpenFOAM gured that the time precision was not sucient anymore.2 for a detailed discussion on the PIM- PLE algorithm. Listing 40: Denition of a cuttingPlane functionObject in a seperate le named 7.2 Solution algorithm control The dictionary controlling the solution algorithm is named after the solution algorithm itself. Note.4. the name of the dictionary controlling the PIMPLE algorithm is PIMPLE. nCorrectors 2. II ® ® ® This oering is not approved or endorsed by ESI Group. Listing 42 shows an example of a PIMPLE dictionary. C a t l i n e 1024 I n c r e a s e d t h e t i m e P r e c i s i o n from 6 t o 13 t o d i s t i n g u i s h between timeNames a t time 1 0 0 .001 s and the time steps were written every 0. However. creates the mesh.1. blockMesh checkMesh icoFoam paraFoam Listing 45: Compute a simple simulation case The rst command. II ® ® ® This oering is not approved or endorsed by ESI Group. In some cases this can reduce simulation time drastically.−−> FOAM Warning : From f u n c t i o n Time : : o p e r a t o r ++() i n f i l e db/Time/Time . as the name suggests. The time step of this simulation was 0. it also save the time that is needed to print the output to the Terminal. Listing 46 shows how the solver output is redirected to a le named foamRun. l o g Listing 46: Redirect output to a le Redirecting the solver output does not only create a log le.5 8. the names of the time step folders indicate this oset. There are additional tasks that extend the sequence of commands shown in Listing 45. The third command is also the name of the solver. e. All solvers of OpenFOAM are invoked simply by their name. 101. ESI-OpenCFD or the OpenFOAM Foundation. mpirun −np N icoFoam − p a r a l l e l > foamRun . the automatic increase of time precision was noticed by the author. checkMesh performs. As it is clearly visible in Listing 44. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.5 s. The geometry has to be dened in blockMeshDict. The last command opens the post-processing tool ParaView.1 Redirect output and save time The solver output can be printed to the Terminal or redirected to a le.log. These can be Convert a mesh created by an other meshing tool. ® ® 30 . import a Fluent mesh Initialise elds Set up an parallel simulation.5 Listing 44: Time step folders after increase of time precision 8 Usage of OpenFOAM 8. However. writing to hard disk also takes its time. Listing 45 represents a complete simulation-run. blockMesh. 0 0 1 Listing 43: Warning message: automatic increase of time precision A side eect of this increase in time precision was a slight oset in simulation time.5000000002 100 99. checks on the mesh. see Section 8.g. This eect on the time step folder names was the reason.1 Use OpenFOAM In the most simple case.0000000002 100.5000000002 101.5 99 98. automatic increase of time precision has no negative eect on a simulation. This purpose of this section is to explain the cause for this eect. 54 12 25000 400 32. x/ run / icoFoam / c a v i t y $ Listing 48: Read redirected output from log le while the solver is running 8. /dev/null is a special le on unix-like systems that discards all data written to it. 7 4 s ClockTime = 1 s Time = 1 . 7 0 4 2 7 user@ host : ~ /OpenFOAM/ u s e r − 2 . Listing 47 shows haw this is done. The name of a time directory represents the time of the simulation. To monitor the progress of running calculation the end of the log can be read with the tail command.33 47 22.8 23 11. II ® ® ® This oering is not approved or endorsed by ESI Group. Consequently.83 283 Table 1: Run-time cavity test case executionTime is the time the processor takes to calculate the solution of the case. The second command invoked in Listing 48 prints the last 5 lines of the log le to the Terminal. 1 . mpirun −np N icoFoam − p a r a l l e l > / dev / n u l l Listing 47: Redirect output to nowhere 8. ESI-OpenCFD or the OpenFOAM Foundation. e. 1 . Otherwise the Terminal would be waiting for icoFoam to nish before executing any further commands.74 11 9. the value of the ClockTime depends on external factors. x/ run / icoFoam / c a v i t y $ icoFoam > foamRun . 4 4 4 3 2 9 max : 1 .g. tail returns the last lines of a text le.22 10 12500 400 15. the system load. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.19 283 282. The & at The Terminal remains therefore available. 1 2 Courant Number mean : 0 .3 Save hard disk space OpenFOAM saves the data of the solution in intervals in time directories. user@ host : ~ /OpenFOAM/ u s e r − 2 .Time steps Cells Print to Terminal executionTime Redirect to le clockTime executionTime clockTime 5000 400 6.1.6 6 10000 400 12. l o g & [ 1 ] 10416 user@ host : ~ /OpenFOAM/ u s e r − 2 .3 10 5000 6400 282. Listing 49 shows the content of a case directory after the simulation has nished. 1 .1.99 23 5000 1600 9.1. l o g −n 5 ExecutionTime = 0 .36 9 4. clockTime is the time that elapses between start and end of the simulation.71 18 9. Without the parameter -n tail returns by default the last 10 lines. Listing 48 shows how a simlation with icoFoam is started and the solver output is redirected. Besides the three folders that dene the case (0. the end of the line causes the invoked command to be executed in the background. The value of the clockTime is always larger than the value of the executionTime. constant and system ) there are more time directories and a probes1 -folder present.1 the redirection of the solver output was explained. because computing the solution is not the only task the processor of the system performs. x/ run / icoFoam / c a v i t y $ t a i l foamRun . this is the time the wall clock indicates.2 Run OpenFOAM in the background. redirect output and read log In Section 8. Redirect output to nowhere If the output of a program is of no interest it can be redirected to virtually nowhere to prevent it from being displayed on the Terminal. ® ® 31 . Write settings ascii ascii. 1 . When OpenFOAM detects the change and re-reads controlDict.5 0. 1 . we also need to be able to stop a simulation prematurely. The most reduction is achieved by compressing ascii data les.3 % 33.e.4. compressed Used space reduction 45. compressed binary binary. Not only writing too many time steps to disk can waste space.9 1 constant user@ host : ~ /OpenFOAM/ u s e r − 2 . The time-directories contain the solution data of the whole computational domain.8 MB 11. time-directories generated in the course of the computation contain more data than the 0 -directory dening the initial conditions. i.8 MB -63. For compression alpha1. the simulation will stop at endTime. x/ run / icoFoam / c a v i t y $ l s 0 0. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.2 0. Compressing the binary les shows less eect than compressing the ascii les.4 0.3.7 MB 28.user@ host : ~ /OpenFOAM/ u s e r − 2 . runTimeModifiable ag has to be enabled in controlDict.2 Abort an OpenFOAM simulation An OpenFOAM simulation ends when the simulation time reaches the value specied with the in controlDict. x/ run / icoFoam / c a v i t y B i n a r y $ l s 0 .e. numbers have up to 6 signicant digits.7 MB -36. This is necessary for this method to work. the time step data has full precision.7 % Table 2: Comparison of hard disk space consumption Make sure to avoid unnecessary output Disk space can easily be wasted by writing everything to disk. ESI-OpenCFD or the OpenFOAM Foundation. Another advantage of storing time step data in binary format. 8. Typically. This section explains how to end a simulation in a controlled manner.7 % 28. x/ run / icoFoam / c a v i t y $ probes1 system Listing 49: List folder contents The probes1 -directory contains the data generated by the functionObject named probes1. user@ host : ~ /OpenFOAM/ u s e r − 2 .8 MB 16.and the 0. storing the time step data in ascii has the disadvantage that the numerical precision is limited to the number of digits stated with the writePrecision keyword in the controlDict.e. This keyword controls controlDict is monitored for changes during the run-time of the simulation. the whether its current time step and write the state of the solution to disk before ending the run. OpenFOAM also oers the possibility to compress all les in the time step directories. 1 p p h i U uniform user@ host : ~ /OpenFOAM/ u s e r − 2 . functionObjects can be the culprit too. x/ run / icoFoam / c a v i t y B i n a r y $ Listing 50: List folder contents Using binary les or compressing les In general the time-directories use the majority of the hard disk space a completed case takes. this causes OpenFOAM to nish As a prerequisite. If the time- directories are saved in binary instead of ascii format. this is indicated by the les names in the time step directories.gz instead Table 2 shows a comparison of hard disk use.1 -directory. alpha1. In this case writePrecision was set to 6.5 MB 16. ® ® 32 .7 MB -25.6 0. 1 . To abort a simulation we simply need to change the value of the stopAt entry in controlDict from endTime to writeNow.3 0. i. 1 . these use generally a little less space. OpenFOAM uses gzip. Listing 50 shows the contents of the 0 . x/ run / icoFoam / c a v i t y B i n a r y $ l s 0 p U user@ host : ~ /OpenFOAM/ u s e r − 2 .8 0. However. See 25.1 0. which indicates that the binary les contain less redundant bytes. i. endTime keyword However. Otherwise. 1 .7 0. the current state of the solution is written to the harddisk in order to be able to continue the simulation at a later time. II ® ® ® This oering is not approved or endorsed by ESI Group. user@ host : ~ $ ps PID TTY TIME CMD 13490 p t s /1 0 0 : 0 0 : 0 0 bash 13714 p t s /1 0 0 : 0 0 : 0 0 ps user@ host : ~ $ Listing 52: List processes in a fresh Terminal The output of 52 is rather dull. When a process is running in the foreground it can easily terminated by pressing sleep. Use this approach when you wouldn't use the solution anyway. The rst entry bash is the Terminal itself. there are lots of parameters telling ps what to do.2 Terminate a background process If a process runs in the background. it also displays the parameters with which the processes were called. because you chose incorrect settings. the process identier. CTRL + C . This means the output -l.e. i. The output of such a call can be quite long. ps −eF Listing 53: List all running processes of the system ps displays much information about a process. after a process has nished the PID of this process is available for other. With this command the permature termination of a process can be tried. the background process can not be terminated by pressing CTRL + C because the Operating System can not tell which background process the user wants to terminate. 10 System processes are processes run by the Operating System itself. The PID is listed in the rst column of Listing 52. whereas -F displays not only the full name of the process. because ps lists all processes started by the users as well as all system processes The option -F controls the output format of ps. This option truncates the Another option to display much information is names of the processes to 15 characters. See Section 8.3. To nd out which processes are currently running. saving the current solution and stop the simulation. Without any further parameters only the processes that were executed from the current Terminal are listed. The option -e makes ps list all systemwide running processes. However. e. This section explains how terminate a running simulation immediately and without saving the current solution.g. Identify the process On UNIX based systems every process is identied by a unique number. 8. 10 . II ® ® ® This oering is not approved or endorsed by ESI Group.8. user@ host : ~ $ s l e e p 3 user@ host : ~ $ Listing 51: Keep the Terminal busy 8. invoke the command ps. The Terminal is therefore busy and can not be used until the process is nished. The PID is equivalent to a licence plate for a car. the Terminal is free to be used for further tasks while the process is running. However. In this case -F stands for extra full. For terminating a process only the PID is necessary. This is the PID. The second entry ps is the only other process active at the time ps looks for all running processes. Depending on the parameters passed to ps the output can be formatted dierently. ESI-OpenCFD or the OpenFOAM Foundation. This lists all running processes. later processes. ® ® 33 . Listing 51 features the GNU command The only function of this command is to pause for a specied amount of time. During run-time this number is unique.3. Listing 52 shows the result if a new Terminal is opened and ps is called.1 Terminate a process in the foreground If a command is executed in the Terminal without any additional parameters the process runs in the foreground. contains a lot of information.2 on how to abort a simulation in a controlled manner. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.3 Terminate an OpenFOAM simulation This section describes how to terminate a running OpenFOAM simulation. In this case. Because it would be even more boring to type the list returned by ps we redirect the output of ps to the standard input of grep. grep can be called with one or two arguments. This is achieved by the use of a pipe. In this case a parallel computation is going on. The truncation of the process name in the list does not aect the search if the passed command name is equal or longer than the truncated process name. pdf user@ host : ~ $ 00:00:05 00:40:27 00:40:28 00:40:27 00:40:26 00:00:00 00:00:31 mpirun −np 4 twoPhaseEulerFoam − p a r a l l e l twoPhaseEulerFoam − p a r a l l e l twoPhaseEulerFoam − p a r a l l e l twoPhaseEulerFoam − p a r a l l e l twoPhaseEulerFoam − p a r a l l e l g r e p −− c o l o r=auto Foam e v i n c e /tmp/ lyx_tmpdir . the second argument has to specify the le from which grep has to read. No other results are displayed unlike in Listing 54. The last line of the result is the pdf viewer which displays this document at that time. This is done by the pipe. grep can use a le or the standard input as its input. ps will not display the desired result. Listing 55 shows the output when ps -C twoPhaseEulerFoam is typed into the Terminal. And now for something more detailed. As it is unpractical to redirect the output of ps into a le only for grep to read it. It shows the output of the search for all running processes containing the pattern Foam. Listing 54 shows how this is done. The next four lines are the four instances of the solver. the search may return unexpected results. Both are standard solvers of OpenFOAM. This process controls the parallel running solvers. The option -C of ps makes ps list only those processes that stem from a certain command. The rst line of the result is mpirun. One has to bear in mind. be distinguished. II ® ® ® This oering is not approved or endorsed by ESI Group. To terminate a certain process its PID has to be known. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.5. user@ host : ~ $ ps − e f | g r e p Foam u s e r 11005 5117 0 1 7 : 1 1 p t s /2 u s e r 11006 11005 99 1 7 : 1 1 p t s /2 u s e r 11007 11005 99 1 7 : 1 1 p t s /2 u s e r 11008 11005 99 1 7 : 1 1 p t s /2 u s e r 11009 11005 99 1 7 : 1 1 p t s /2 u s e r 11673 11116 0 1 7 : 5 2 p t s /12 u s e r 32041 1 0 Aug01 ? FoamUserManual_CDLv2 .Search in the list of processes The output of ps is a list which can be quite long. it reads from the standard input.g. How parallel simulation works is explained in Section 8. In this case also there are four parallel processes running. input The second last entry of the result is grep waiting for 11 . If grep is called with two parameters. Therefore it would be handy to search in the list ps has returned for the desired process. e. The character Terminal. Also if there is a typo in the passed argument. ® ® 34 . grep is a program that searches the lines of its input for a certain pattern. the results of ps would be ambiguous. grep does the trick. Notice. ESI-OpenCFD or the OpenFOAM Foundation. that only the processes directly related to the solvers are shown. Searching a number in a list of numbers can be quite painful and errorprone. user@ host : ~ $ ps −C twoPhaseEulerFoam PID TTY TIME CMD 11 On most Unix-like systems processes connected by a pipe are started at the same time. Listing 56 shows the eect of typos in this case. If the passed argument is shorter than the truncated process name the third command ps does not output any results. As grep is called with only one argument. The rst two commands issued in Listing 56 result in a list of all running instances of the solver. This example shows that is important to choose the pattern wisely. The rst part of the command invoked all processes currently running in great detail. If only one argument is passed to grep. The second part of the command invoked in Listing 54 shows the call of grep. J18462 / lyx_tmpbuf0 / open Listing 54: Search for processes List only specied processes You can tell ps directly in which processes you are interested. ps does not nd anything. Before all else. that ps -C does not search for patterns. to tell The option -F buoyantBoussine sqPimpleFoam ps -eF calls ps to list is used to make sure long process names can apart from buoyantBoussine sqSimpleFoam. For this reason grep is already running while ps is listing all running processes. If the command name passed to ps as an argument is misspelled. If the option -F was omitted and both solvers were running. passes its output directly to the command specied right of the Now we can read and interpret Listing 54. we directly redirect the output of ps to the input of grep. grep uses the standard input as input. The command left of the | | marks the connection of two processes in the |. The bold part are the rst 15 characters of the solver's name. The user can also send signals to processes using the command kill. To identify the process to which the signal is to be sent. If the process would not have been terminated 13 the message at the natural end of the process would be like in Listing 58 . When ps was executed the second time.11006 p t s /2 11007 p t s /2 11008 p t s /2 11009 p t s /2 user@ host : ~ $ 00:47:44 00:47:44 00:47:44 00:47:43 twoPhaseEulerFo twoPhaseEulerFo twoPhaseEulerFo twoPhaseEulerFo Listing 55: List all instances of twoPhaseEulerFoam user@ host : ~ $ PID TTY 12741 p t s /0 12742 p t s /0 12743 p t s /0 12744 p t s /0 user@ host : ~ $ PID TTY 12741 p t s /0 12742 p t s /0 12743 p t s /0 12744 p t s /0 user@ host : ~ $ PID TTY user@ host : ~ $ PID TTY ps −C twoPhaseEulerFoa TIME CMD 0 0 : 0 0 : 3 4 twoPhaseEulerFo 0 0 : 0 0 : 3 4 twoPhaseEulerFo 0 0 : 0 0 : 3 4 twoPhaseEulerFo 0 0 : 0 0 : 3 4 twoPhaseEulerFo ps −C twoPhaseEulerFo TIME CMD 0 0 : 0 0 : 3 6 twoPhaseEulerFo 0 0 : 0 0 : 3 6 twoPhaseEulerFo 0 0 : 0 0 : 3 6 twoPhaseEulerFo 0 0 : 0 0 : 3 6 twoPhaseEulerFo ps −C twoPhaseEulerF TIME CMD ps −C twPhaseEulerFoa TIME CMD Listing 56: List all instances of twoPhaseEulerFoam the eect of typos Terminate The operating system interacts with running processes using signals. kill sends by default the termination signal. the PID of this process has to be passed as an argument. Listing 57 shows how the programm sleep is executed. message is displayed stating the process has been terminated user@ host : ~ $ s l e e p 20 & [ 1 ] 13063 user@ host : ~ $ ps PID TTY TIME 12372 p t s /0 00:00:00 13063 p t s /0 00:00:00 13064 p t s /0 00:00:00 user@ host : ~ $ k i l l 13063 user@ host : ~ $ ps PID TTY TIME 12372 p t s /0 00:00:00 13065 p t s /0 00:00:00 [ 1 ] + Beendet user@ host : ~ $ CMD bash sleep ps CMD bash ps s l e e p 20 Listing 57: Terminate a process using kill user@ host : ~ $ s l e e p 1 & [ 1 ] 13126 user@ host : ~ $ ps PID TTY TIME CMD 12372 p t s /0 0 0 : 0 0 : 0 0 bash 13127 p t s /0 0 0 : 0 0 : 0 0 ps [1]+ Fertig user@ host : ~ $ sleep 1 12 On other systems this message is displayed immediately see Listing 59. a 12 . all running processes are listed. 13 A system with English language setting the message would read Terminated if the process would have been terminated and Done if the process would have been allowed to nish. In this case the procedure was tried on the local computing cluster. II ® ® ® This oering is not approved or endorsed by ESI Group. the running instance of sleep is terminated and the running processes are listed again. ESI-OpenCFD or the OpenFOAM Foundation. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 35 . the value of endTime startFrom parameter to latestTime. ESI-OpenCFD or the OpenFOAM Foundation.5. If the parallel simulation is called with too many processes. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. OpenFOAM uses the MPI standard in the implementation of OpenMPI.1. the simulation can be continued by simply invoking the solver in the Terminal. in this case 4.2. These folders are created by decomposePar and their number is dened in decomposeParDict. 8. if needs to be adjusted.5 Do parallel simulations with OpenFOAM OpenFOAM is able to do parallel simulations. user@ host : ~ $ mpirun −np 4 icoFoam − p a r a l l e l > foamRun .2 for information about domain decomposition. Listing 60 shows how a parallel simulation using 4 parallel processes is started. After this changes. the invokation of the solver diers from the single process case. Then.3. OpenMPI ensures that all parallel instances of the solver run synchronously. ® ® 36 . See Section 8.2 for a discussion about running a process in the background. l o g & [ 1 ] 11099 user@ host : ~ $ Listing 60: Run OpenFOAM with 4 processes The number of processes. This PID can be used to terminate the parallel calculation. 8. After the domain is decomposed several instances of the solver are running the case on a subdomain each.log and the simulation runs in the background of the Terminal. like it is explained in Section 8. OpenFOAM issues an error message like in Listing 62. This step is called domain decomposition. The rst example shows. If this numbers the number of processor * folders and the number of parallel processes with which mpirun is invoked are not equal OpenFOAM issues an error message similar to Listing 61. In order to be able to manage all parallel processes the simulation has to started using the command mpirun. So the same Terminal can be used to monitor the progress of the calculation.4 Continue a simulation If a simulation has ended at the end time or if it has been aborted there may be the need to continue the simulation. the keyword startFrom controls from which time the simulation will be started. See Section 8. Otherwise the simulation would generate no meaningful results.Listing 58: The natural end of a process u s e r @ c l u s t e r u s e r > s l e e p 10 & [ 1 ] 31406 u s e r @ c l u s t e r u s e r > k i l l 31406 u s e r @ c l u s t e r user> [1] Terminated u s e r @ c l u s t e r user> s l e e p 10 Listing 59: Terminate a process using kill on a dierent machine 8. Additionally. There. that OpenFOAM reacts dierently whether the parallel job was started with loo little or too many processes. The output message in the Listing shows the PID of the running instance of mpirun. The only obvious additional task is to split the computation domain into several pieces. has to be equal the number of processor* folders. II ® ® ® This oering is not approved or endorsed by ESI Group. redirected into a le called The solver outputs are > foamRun. There is no great dierence between calculating a case with one single process or using many parallel processes.5. In this case the domain was decomposed into 4 subdomains and it was tried to start the parallel simulation with 2 processes. The most important setting to enable a simulation to be continued has to be made in the le controlDict. The easiest way to continue a simulation is to set the necessary.1 Starting a parallel simulation To enable a simulation using several parallel instances of a solver. x | | \\ / A nd | Web : www. x/ run / icoFoam / c a v i t y $ mpirun −np 2 l s 0 c o n s t a n t system 0 c o n s t a n t system user@ host : ~ /OpenFOAM/ u s e r − 2 . o r g | | \\/ M anipulation | | \*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ B u i l d : 2 .1. Listing 63 shows the output of the command ls when it is run with mpirun with two processes. the output on the Terminal is completely disarranged. The output appears on the Terminal in the order as it is generated by the solvers in other words. 1 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. the solver will be executed n times. If the -parallel parameter is missing. user@ host : ~ /OpenFOAM/ u s e r − 2 . x−6e89ba0bcd15 Exec : icoFoam Date : Jan 29 2013 Time : 10:51:12 Host : " host " PID : 25622 /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*\ | ========= | | | \\ / F ield | OpenFOAM: The Open S o u r c e CFD Toolbox | | \\ / O peration | Version : 2. o r g | | \\/ M anipulation | | \*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ B u i l d : 2 . 1 . 1 . Listing 64 shows the rst lines of output of a situation where the parameter was omitted. there is also no check if the processor* folders are present. the same happens as in the case of ls.x | | \\ / A nd | Web : www.OpenFOAM. ESI-OpenCFD or the OpenFOAM Foundation. If the parameter -parallel n -parallel is missing. II ® ® ® This oering is not approved or endorsed by ESI Group. x/ run / icoFoam / c a v i t y / system / decomposeParDict " s p e c i f i e s 4 p r o c e s s o r s but j o b was s t a r t e d with 2 p r o c e s s o r s . x−6e89ba0bcd15 Exec : icoFoam Listing 64: Run icoFoam without the -parallel parameter Pitfall: domain decomposition If there was no domain decompositin prior to starting a parallel simulation. The simulation is run by processes at roughly the same time. If this parameter is omitted. Listing 61: Run OpenFOAM with too little parallel processes [ 0 ] −−> FOAM FATAL ERROR: [ 0 ] number o f p r o c e s s o r d i r e c t o r i e s = 4 i s not e q u a l t o t h e number o f p r o c e s s o r s = 8 Listing 62: Run OpenFOAM with too many parallel processes Pitfall: -parallel The parameter -parallel is important.1. 1 . In this case ls is simply run twice. All solvers start the calculation of the whole case and write their output to the Terminal.OpenFOAM. x/ run / icoFoam / c a v i t y $ Listing 63: Run ls using 2 processes user@ host : ~ /OpenFOAM/ u s e r − 2 . x/ run / icoFoam / c a v i t y $ mpirun −np 4 icoFoam /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*\ | ========= | | | \\ / F ield | OpenFOAM: The Open S o u r c e CFD Toolbox | | \\ / O peration | Version : 2. 1 .[ 0 ] −−> FOAM FATAL ERROR: [ 0 ] "/home/ u s e r /OpenFOAM/ u s e r − 2 . 1 . ® ® 37 . OpenFOAM will issue an corresponding error message. processes with a lower computational load would overtake other processes and they would exchange data from dierent times. The 0 folder contains the initial and boundary conditions of the subdomain and the constant folder contains a polyMesh folder containing the mesh of the subdomain. Inside the processor* folders a 0 and a constant folder are created. because the number of subdomains has been changed or some elds have been reinitialised. decomposePar creates the processor* directories in the case directory. So. The option time lets the user specify a time from which or a time range in which the domain is to be decomposed. Otherwise. 1 .g. ESI-OpenCFD or the OpenFOAM Foundation. II ® ® ® This oering is not approved or endorsed by ESI Group. This le has to contain al least the number of subdomains and the decomposition method. that some installations of OpenFOAM 2. e . g . Such enhancements typically rst appear in the respository release OpenFOAM 2. The resulting error message proposes two possible solutions.x. The user can retype the command or copy and paste it into the Terminal. Also the les in the constant directory are not altered. This enhancement took place between the release of OpenFOAM 2.x contain this feature and some not depending on the time of installation or the time of the last update.0 and OpenFOAM 2. initialising elds using setFields have to take place before the domain decomposition. decomposePar reads from decomposeParDict in the system directory. e. whether the number of subdomains has changes or not.1. The second proposed solution is to manually remove the processor* folders. OpenFOAM issues an error message. In this case the error message contains the proper command to do so.1. rm − r f /home/ u s e r /OpenFOAM/ u s e r − 2 .1. Just before starting the simulation the domain has to be decomposed. In this case the domain has already been decomposed into 2 subdomains and the attempt is made to decompose it again. x/ run / icoFoam / c a v i t y / p r o c e s s o r * Listing 66: Already decomposed domain Time management with decomposePar In the course of an update of OpenFOAM decompose gained the option -time. as the information stored there is not aected by the domain decomposition.[ 0 ] −−> FOAM FATAL ERROR: [ 0 ] twoPhaseEulerFoam : cannot open c a s e d i r e c t o r y "/home/ u s e r /OpenFOAM/ u s e r − 2 .1. Listing 67 shows some examples of how this option works. All parallel processes read from the same system directory. OpenFOAM always issues an error message. e. The tool decompsePar is used for this purpose. 1 . . it may be. x/ run / twoPhaseEulerFoam / testColumn / p r o c e s s o r 0 " [0] [ 0 ] FOAM p a r a l l e l run e x i t i n g Listing 65: Missing domain decomposition Pitfall: domain resonstruction After a parallel simulation has ended. The parallel processes calculate on their own subdomain and exchange data of the border regions at the end of each time step. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. If paraView is started without prior domain reconstruction paraView will only nd the data of the 0 directory. The rst is to invoke decomposePar with the -force option to make decomposePar remove the processor* folders before doing its job. ® ® 38 . u s e t h e − f o r c e o p t i o n o r manually remove p r o c e s s o r d i r e c t o r i e s b e f o r e decomposing . This is also the reason why the parallel processes have to be synchonous.2 Domain decomposition Before a parallel simulation can be started the domain has to be decomposed into the correct number of subdomains one for each parallel process. Other operations. −−> FOAM FATAL ERROR: Case i s a l r e a d y decomposed with 2 domains . Pitfall: Existing decomposition If the domain has already been decomposed and decomposePar is called again. all data is residing in the processor* folders. 8.5. Listing 66 shows an example.1.g. 4 0. 1 .2 0.2 constant user@ host : ~ /OpenFOAM/ u s e r − 2 . The rst command is a simple call of ls to display the contents of the case directory.5 constant user@ host : ~ /OpenFOAM/ u s e r − 2 . ESI-OpenCFD or the OpenFOAM Foundation. 1 . By using this option the proper time span to reconstruct is automatically determined. This is not dierent from the situation before the parallel simulation was started with the exception of the log le. x/ run / icoFoam / c a v i t y $ l s p r o c e s s o r 0 0. 2 − f o r c e > / dev / null user@ host : ~ /OpenFOAM/ u s e r − 2 .The option -latestTime makes decomposePar use the latest time step as starting time step for the subdo- mains. 2 0 .5.1 0.3 Domain reconstruction To be able to look at the results the data has to be reassembled again. So. x/ run / icoFoam / c a v i t y $ l s 0 c o n s t a n t foamRun . 1 . t ≤ 60 s. x/ run / icoFoam / c a v i t y $ l s 0 0 . x/ run / icoFoam / c a v i t y $ r e c o n s t r u c t P a r > f o a m R e c o n s t r u c t .3 0. log user@ host : ~ /OpenFOAM/ u s e r − 2 . x/ run / icoFoam / c a v i t y $ l s 0 0 . II ® ® ® This oering is not approved or endorsed by ESI Group. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. So. the case directory also contains time step data. To prevent the tool from reconstructing already reconstructed time steps the Listing 69 shows how simulation results are reconstructed for -time option can be used. 1 . This job is done by reconstructPar. 1 . This tool collects all data of the processor* folders and reconstructs the original domain using all the generated time step data. x/ run / icoFoam / c a v i t y $ l s p r o c e s s o r 0 0 0. 1 . The third command reconstructs the domain. a nished parallel case stores its time step data twice and therefore uses a lot of space. The second command lists the contents of the processor0 directory. Calling reconstructPar without any options regarding time. After this tool has nished. 1 .1 0. l o g foamRun . 1 . 1 . l o g p r o b e s 1 p r o c e s s o r 0 p r o c e s s o r 1 p r o c e s s o r 2 p r o c e s s o r 3 system user@ host : ~ /OpenFOAM/ u s e r − 2 . In this directory as well as in all other processor* folders there is time step data. this log le could be from a previous run.5 constant user@ host : ~ /OpenFOAM/ u s e r − 2 .2 constant user@ host : ~ /OpenFOAM/ u s e r − 2 . x/ run / icoFoam / c a v i t y $ Listing 68: A nished parallel simulation Time management t = t1 the domain has to be reconstructed for times t > t1 . l o g & [ 1 ] 26269 user@ host : ~ /OpenFOAM/ u s e r − 2 . However. This data has not been removed. x/ run / icoFoam / c a v i t y $ decomposePar − time 0 . 1 0 . The last command lists the contents of the processor0 folder again. x/ run / icoFoam / c a v i t y $ l s p r o c e s s o r 0 0. x/ run / icoFoam / c a v i t y $ l s p r o c e s s o r 0 0 0. user@ host : ~ /OpenFOAM/ u s e r − 2 . 2 c o n s t a n t p r o b e s 1 p r o c e s s o r 0 p r o c e s s o r 1 p r o c e s s o r 2 system user@ host : ~ /OpenFOAM/ u s e r − 2 . 5 c o n s t a n t f o a m R e c o n s t r u c t . 1 . 4 0 . the program starts reconstructing the domain at the earliest If a simulation has been startet from time. 2 − f o r c e > / dev / n u l l user@ host : ~ /OpenFOAM/ u s e r − 2 . After reconstructPar has nished the data of the whole domain resides in the case directory and the data of the subdomains resides in the processor* folders. x/ run / icoFoam / c a v i t y $ decomposePar − time 0 . 3 0 . 1 . user@ host : ~ /OpenFOAM/ u s e r − 2 . Listing 68 shows the content of the case directory after a parallel simulation has nished. listing the contents after a parallel simulation has nished carries no real information. l o g p r o b e s 1 p r o c e s s o r 0 p r o c e s s o r 1 p r o c e s s o r 2 p r o c e s s o r 3 system [1]+ Fertig reconstructPar > foamReconstruct . 1 0 .2 0.4 0. r e c o n s t r u c t P a r − time 6 0 : Listing 69: Zeitparameter für reconstructPar Another option to reconstruct only the new time steps is the command line option -newTimes. 1 . ® ® 39 .1 0.3 0. 1 : 0 . x/ run / icoFoam / c a v i t y $ Listing 67: Time management with decomposePar 8. There the correct path to the case directory two levels upwards is specied using . Therefore. II ® ® ® This oering is not approved or endorsed by ESI Group. Actually. 1 . Then the option -case has to be used to specify this path. x/ run / icoFoam / t e s t C a s e / c o n s t a n t / polyMesh / system / c o n t r o l D i c t at l i n e 0 . If an executable is to be called from another directory the path to the case diretory has to be specied. 15 On most Linux or Unix systems . Run OpenFOAM using a script Section 44. that OpenFOAM runs on a great number of platforms enables the user to do simulations on the workstation as well as on a big cluster with tens or hundreds of processors. However. if the cases is very large.4 Run large studies on computing clusters Simulating parallel on a machine brings some advantages and enables the user to run even large simulations on a workstation. is the proper command. does the job and on MS-DOS or Windows cd. This does not solely imply an invalid path.. −−> FOAM FATAL IO ERROR: cannot f i n d f i l e f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 . The user can follow a two step method.5. ® ® 40 . msh Listing 71: Specify the correct path to the case 14 No exeption known to the author. 1. the producer of the OpenFOAM software and owner of the OpenFOAM trademark..8. x/ run / icoFoam / t e s t C a s e / c o n s t a n t / polyMesh$ fluent3DMeshToFoam − c a s e . Set up the case and run some test simulations.6 Using tools OpenFOAM consists besides of solvers of a great collection of tools.15 user@ host : ~ /OpenFOAM/ u s e r − 2 . All solvers and tools of OpenFOAM These tools are used for all kind of 14 assume that they are called from the case directory. caseMesh . on the workstation to ensure the simulation runs 2. FOAM e x i t i n g Listing 70: Wrong path The correct usage of the -case option is shown in Listung 71. 8. . / . Do the actual simulation on the cluster The fact. 1 .. Also. using the workstation can be counter productive. the error message states that the le could not be found. operations. The le could simply be missing. refers to the current directory and .. refers to the directory above the current one. ESI-OpenCFD or the OpenFOAM Foundation. on Linux systems the tilda refers to the home directory of the current user. To change in the Terminal one directory upwards on Linux cd . This resulted in an invalid path to controlDict as the error message tells the user.. for a small number of time steps. simulating on a computing cluster is the method of choice for large scale calculations. The tool added the relative path system/controlDict to the currect working directory. Listing 70 shows the error message displayed by the tool uentMeshToFoam as it was executed from the polyMesh directory. or parametric studies are to be conducted. From f u n c t i o n r e g I O o b j e c t : : readStream ( ) i n f i l e db/ r e g I O o b j e c t / r e g I O o b j e c t R e a d . C a t l i n e 7 3 .g./.5 explaines how to set up a script that runs multiple cases.. e. . ® ® 41 . If CAD software is used to create the geometry the data has to be exported to be used by a meshing program.Part III Pre-processing 9 Geometry creation & other pre-processing software There are many ways to create a geometry.2 CAD software There is a great number of CAD software around. OpenSCAD produces STL meshes that dene the geometry correctly but the mesh is of a bad quality from a CFD point of view. However most CAD programs support exporting the geometry in dierent formats.1 OpenSCAD OpenSCAD [http://www. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. etc. SAT.2.org/wiki/OpenSCAD_User_ Pitfall: STL mesh quality OpenSCAD is a tool to create CAD models.org/] is an open source CAD tool for creating solid 3D CAD models. STL. All triangles dening the circular area share one vertex. responding mesh. snappyHexMesh can be used with STL 9. This makes it easy to create parametric models. From a CFD point of view the triangular face elements are highly distorted and have a bad aspect ratio. For the reason of simplicity all aspects of blockMesh geometry creation as well as meshing are covered in Section 11. For further information on usage see the documentation Manual. IGES. with GMSH) problems may arise.g. Therefore the term STL mesh or STL surface mesh is also valid. Each CAD program usually uses its own le format. This section is about the dierent ways to generate a geometry for a subsequent CFD simulation. It is able to create the domain geometry and the cor- See Section 11 for a discussion on blockMesh.) or by extruding 2D paths. This vertex is probably the base point for the mesh creation of OpenSCAD. A CAD model is created by using primitve shapes (cubes. there is a number of CFD pre-processors capable of creating geometries and there is the good old blockMeshDict. Figure 1 shows the STL mesh of a circular area. cylinders. 16 STL is infact a surface mesh enclosing the geometry.1 blockMesh blockMesh is OpenFOAMs own pre-processing tool. There is a great number of CAD software. format for this purpose is the STL format. Therefore the requirements on the produced STL mesh are completely dierent than on a mesh for CFD simulations. Models are not created interactively like in other CAD software. e.g. If a nite volume mesh is to be derived from the STL surface mesh (e. The user writes an input script which is interpreted by OpenSCAD. 9. A common le 16 geometry denitions. III ® ® ® This oering is not approved or endorsed by ESI Group. However from a CAD point of view these triangles are prefectly sucient to represent the circular area.openscad. 9.wikibooks. http://en. If the only purpose of the STL mesh is to represent some geometry like it is the case with snappyHexMesh then this quality issues can be ignored. ESI-OpenCFD or the OpenFOAM Foundation. 2) have to be used. Salome serves as the pre.1. snappyHexMesh is.1 Basics of the mesh 10. When Salome is used to create a mesh. A face is dened by the points that form the face. in contrast to blockMesh. Salome comes EDF. ESI-OpenCFD or the OpenFOAM Foundation. ® ® 42 . Salome can be used to create a geometry interactively or by interpreting a python script with a number of internal and external meshing utilities.org/wiki/index. Thus parametric geometry or mesh creation is possible. blockMesh is able to also create the geometry of the simulation domain.1 Files A mesh is dened by OpenFOAM using several les. the rest is explained in the OpenFOAM User Guide [24]. The names of these les are rather self explanatory. Then the mesh can be converted by the ideasUnvToFoam utility of OpenFOAM. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 10 Meshing & OpenFOAMs meshing tools OpenFOAM brings its own meshing utilities: blockMesh and snappyHexMesh. All of these les reside in constant/polyMesh/. neighbour contains a list of the neighbouring cells of the faces 17 Salome can be controlled completely by Python.3 Salome Salome [http://www. Salome has also a post-processing module.org/gmsh/].org/] is a powerful open source pre-processing software developed by 17 .Figure 1: The STL mesh of a circular area generated by OpenSCAD 9. Alternatively there is a number of other meshers that can be used. boundary faces contains a list of all faces forming the boundary patches contains the denition of all faces. this mesh needs to be exported by Salome in the UNV format.and post-processor for Code_Aster (structural analysis) and Code_Saturne (CFD).geuz. checkMesh is a utility to investigate the mesh quality regardless of how the mesh was created. GMSH GMSH is a meshing tool with some pre.salome-platform.php/Doc:Salome for documentation and usage examples of Salome.4 http://caelinux.and post-processing capabilities [http://www. Then. 10. Salome is a part of a collection of open source software developed by EDF. See 9. a meshing tool that uses an external geometry denition in the form of an STL le. III ® ® ® This oering is not approved or endorsed by ESI Group. some conversion utilities (listed in Section 10. Therefore we need to specify the vertices dening the face in counter-clockwise circular order. ® ® 43 . An internal face is. by denition. the two cells connected by a face can be destincted. The direction of rotation is marked in Figure 2 with the + sign. The vertices with the numbers 4. Listing 72 shows a list of all les created with Gambit and converted by uentMeshToFoam. The way faces are dened is the same for cells of the mesh or for blocks of the geometry. These faces make up the boundary patches. However. So. 5. 1 . The face normal vector denoted by points outwards of the block is parallel to the local z n in Figure 2 that axis. a hexahedron has 6 faces. The faces can be divided into two groups. when we look at the block from the top. some ways of creating a mesh produce additional les. owned by one cell and neighboured by the other one. x/ run / twoPhaseEulerFoam / columnCase$ l s c o n s t a n t / polyMesh / boundary c e l l Z o n e s f a c e s f a c e Z o n e s n e i g h b o u r owner p o i n t s p o i n t Z o n e s Listing 72: Content of constant/polyMesh 10. 6 and 7 are part of the face. A face bordering more than two cells is not possible. Each cell is delimited by a number of faces. All other faces can be seen as the connection between two cells and are called internal faces.owner contains a list of the owning cells of the faces points contains a list of the coordinates of all points The description of a mesh is based on the faces. ESI-OpenCFD or the OpenFOAM Foundation. Boundary faces border only one cell.2 Denitions Face A face is dened by the vertices or points that are part of the face. This ve les are absolutely necessary to describe a mesh regardless of how the mesh was created in the rst place. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The starting vertex is arbitrary but it must not appear twice in the list. user@ host : ~ /OpenFOAM/ u s e r − 2 . (4 5 6 7) (7 6 5 4) Correct denitions (7 4 5 6) (6 7 4 5) Wrong direction of rotation (4 7 6 5) (5 4 7 6) (5 6 7 4) (6 5 4 7) Non-circular Starting point repeated (7 5 6 4) (4 5 6 7 4) Table 3: Valid and invalid face denitions III ® ® ® This oering is not approved or endorsed by ESI Group. The geometry is discretised into nite volumes the cells. The points need to be stated in an order which is dened by the face normal vector pointing to the outside of the cell or the block.1. n 7 6 + 4 5 Figure 2: The top face of the generic block of Figure 3 To elaborate this further we look at the top face of the generic block of Figure 3 in Figure 2.g. e. III ® ® ® This oering is not approved or endorsed by ESI Group. From this vertices the blocks are constructed. 10. 19 If we number all vertices in the x − y plane then the local z axis is the axis of revolution. Thus the counter-clockwise direction is the mathematically positive direction of revolution. then the ngers of the right hand point in the positive direction of revolution. whereas 3D meshes can be converted using u- ent3DMeshToFoam. If the mesh was created using an other dimension than in metres. The geometry is dened in blockMeshDict. Then the vertices above the local plane are counter-clockwise numbered starting with the vertex on the local z axis. the command line parameter -scale can be used to correct the scaling. e.4 contains a case in which this tool can be useful. The rst part of the x−y blockMeshDict is generally a list of vertices. ® ® 44 .msh le format into the format of OpenFOAM.6.1 The block The geometry created by blockMesh is based on the generic block. A block is dened by a list of 8 vertices which have to be ordered in a way to match the local vertices. *. 11 blockMesh blockMesh is used to create a mesh.2 Converters To use meshes created by programs other than blockMesh there is a number of converters.1 transformPoints The tool transformPoints can be used to scale. Therefore the rst entry in the list of vertices is the local 0 vertex. Section 15. The User Guide [24] lists the following converters: uentMeshToFoam starToFoam gambitToFoam ideasToFoam cfx4ToFoam The names of the converters are pretty self explanatory.3. Let the thumb of your right hand point in the positive direction of the rotation axis. 11. OpenFOAM expects the mehs data to be expressed in metres. constant/polymesh directory. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.3. 18 In mathematics the positive direction of rotation is generally determined with the right-hand or cork-screw rule.g. This le also contains all necessary parameters needed to create the mesh.10. The local vertex numbers dene the order in which the vertices have to passed when constructing a block. The vertices are numbered counter-clockwise in the local x−y 19 plane starting at the origin of the local coordinates . 18 The blue numbers are the local vertex numbers of the block.1 uentMeshToFoam and uent3DMeshToFoam uentMeshToFoam converts meshes stored in the *.3 Mesh manipulation 10. blockMesh is a combined tool to dene and mesh a geometry in contrast to other meshers that use CAD les to import a geometry created by some other software. 10. the number of cells. Therefore. translate or rotate the points a mesh.msh le as an argument. then the local 1 vertex follows. All other possible option can be displayed with this command line parameter fluentMeshToFoam -help. To be more specic.2. then the path to the case directory has to be specied via an additional argument. The local vertex numbers are important when dening the block. The converter expects the path to the of OpenFOAM in the The converter saves the mesh in the format If converter is invoked from a directory other than the case directory. uentMeshToFoam converts only 2D meshes. ESI-OpenCFD or the OpenFOAM Foundation. See Section 8. Figure 3 shows a generic block. } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // convertToMeters 0 .2. ESI-OpenCFD or the OpenFOAM Foundation. o r g | | \\/ M anipulation | | \*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ FoamFile { version 2. Listing 73 shows a reduced example of the blockMeshDict. The local coordinate axes do not need to be parallel or to coincide with the global coordinate axes. See Section 11.The coordinate system originating from vertex 0 are the local coordinates. Next the edges parallel to the local y axis are numbered and nally the edges parallel to the local z axis. ).1. format ascii .. ® ® 45 . 7 6 2 → % % 7 6 4 5 3 → ↑ ↑ 10 11 ↑ 3 ↑ 8 z 1 → % % 4 5 y 0 2 9 1 0 → x Figure 3: The generic block 11.. III ® ® ® This oering is not approved or endorsed by ESI Group.4).4). class dictionary .OpenFOAM.2 The blockMeshDict The le blockMeshDict denes the geometry and controls the meshing process of blockMesh.x | | \\ / A nd | Web : www. The edges are also numbered and have a direction. 1 . /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*− C++ −*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*\ | ========= | | | \\ / F ield | OpenFOAM: The Open S o u r c e CFD Toolbox | | \\ / O peration | Version : 2. object blockMeshDict . Starting with the edge parallel to the local x axis the edges are numbered counter-clockwise starting with the edge emanating from the origin of the local coordinates. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. This le was taken from the cavity tutorial case.4 on how to dene curved edges. The local coordinates are important when specifying the number of cells or mesh grading (see simpleGrading in Section 11. vertices ( (0 0 0) // 0 ( 0 0 0 . The edge number is important when specifying a grading for each edge individually (see edgeGrading in Section 11. the edges do not need to be parallel or straight. 1 ) // 1 . As it is indicated on Figure 3.0. ESI-OpenCFD or the OpenFOAM Foundation. C r e a t i n g p o i n t s with s c a l e 0 . See Section 10. Listing 74 shows how to set this factor if the vertex coordinates are entered in millimeters.2.3. counting starts from zero. 20 As OpenFOAM treats its dictionaries much in the same way as C/C++ source les are treated by the C/C++ compiler. If the vertex coordinates are entered in an other unit than meters. the default value of 1 is assumed. 11. then no scaling is used.1 is a uniform scaling factor. mergePatchPairs ( ).1 and 15. 1 Listing 75: Output of blockMesh when convertToMeters convertToMeters is set to 0. Listing 74: convertToMeters If the keyword convertToMeters is missing in the blockMeshDict. Therefore comments work the same way as they do in C or C++. the output of blockMesh can be checked. Remember. ). Listing 75 shows the message issued by blockMesh regarding the scaling factor dened with convertToMeters.2 vertices The vertices sub-dictionary contains a list of vertices. By default OpenFOAM treats these coordinates as in metres. convertToMeters 0 .3. The index of a vertex in this list is also the global number of this vertex. A way to keep oneself aware of this fact is to add comments in Listing 73.e. However. boundary ( movingWall { type w a l l .. faces ( (3 7 6 2) ).1 convertToMeters convertToMeters is a scaling factor to convert the vertex coordinates of blockMeshDict into meters. III ® ® ® This oering is not approved or endorsed by ESI Group.. 0 0 1 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. the vertices can be specied in other units. Non-uniform scaling or other operations can be performed with another tool. To make sure if a scaling factor has been used.2.blocks ( hex ( 0 1 2 3 4 5 6 7 ) ( 2 0 20 1 ) s i m p l e G r a d i n g ( 1 1 1 ) ). i. } . which is needed when constructing blocks from the vertices. with the help of the keyword convertToMeters. Each vertexs is denes by its coordinates in the global coordinate system.4. edges ( ). ® ® 46 . // ************************************************************************* // Listing 73: A minimal blockMeshDict 11. Thus the rst vertex is the list of vertices can 20 to the vertex list as be addressed by its index 0. this value has to be chosen accordingly. the rst number is the number of cells in the local x direction. Any other number of entries in this list leads to an error. In OpenFOAM2. Thus. In the case of three numbers. The third entry could even be omitted. Listing 79 shows the denition of a circular arc between the vertices 0 and 3. controls the grading. Such blocks are needed for simulations that make use of axi-symmetry. This sub-dictionary can be omitted.4 edges The edges sub-dictionary contains pairs of vertices that dene an edge. the list of expansion ratio. 11. Listing 76 shows an example of a block denition with the hex keyword. So the author does not advocate to omit this parameter. This numbers dene the expansion ratio of the grading. blockMesh issues a message as in Listing 78 regardless whether curved edges are actually created or only an empty edges sub-dictionary is present.2. C r e a t i n g curved e d g e s Listing 78: Output of blockMesh when edges is present Creating arcs With the keyword arc a circular arc between two vertices can be created. The order of the The only valid entry in the contains a list of After the entries in this list is the same order as the local vertex numbers of the block in Figure 3. hex ( 0 1 2 3 4 5 6 7 ) ( 2 0 20 1 ) s i m p l e G r a d i n g ( 2 4 1 ) Listing 76: The hex command in blockMeshDict Creating a block with 6 faces The hex instruction can also be used to create a prism with a triangular cross-section. Listing 79: Denition of a circular edges in the III ® edges sub-dictionary ® ® This oering is not approved or endorsed by ESI Group. edges ( arc 0 3 (0 0. ESI-OpenCFD or the OpenFOAM Foundation. The blocks section of the blockMeshDict hex commands. Listing 77 shows the message issued by blockMesh when edges is omitted.5 0 . The next entry is a word stating the grading of the edges. However. No non− l i n e a r e d g e s d e f i n e d Listing 77: Output of blockMesh when edges is omitted Otherwise.2. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The last entry of the block denition is a list of either three or twelve positive numbers. curved edges can be created. maybe future versions of OpenFOAM make use of this entry. Therefore the third point follows the indizes of the two vertices dening the edge.11. then edgeGrading is performed. This entry is in fact redundant. simpleGrading is applied.3 blocks blocks sub-dictionary is the hex keyword. By default edges are straight. 0 5 ) ). Then a list of three positive integer numbers follows. then all edges share the same expansion ratio. In order to dene a circular arc three points are necessary.1. If the list contains only one entry. ® ® 47 . word hex a list of eight numbers dening the eight vertices of the block follows. If twelve numbers are stated. See the User Manual [24] for instructions on this topic. by explicitely specifying the shape of the edge.x only the last entry. These numbers tell blockMesh how many cells need to be created in the direction of the local coordinate axes. ® ® 48 . boundary ( inlet { type patch .2. edges ( polyLine 0 3 ((0 0.5 boundary The boundary list contains a dictionary per patch. This dictionary contains the type of the patch and the list of faces composing the patch.C a t l i n e 5 5 . Listing 82: Denition of a poly-line in the edges sub-dictionary Creating a straight line For the sake of completeness there is the keyword line.75 0 . FOAM a b o r t i n g Listing 80: Output of blockMesh when the three points dening an arc are co-linear Creating splines The keyword spline denes a spline. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. faces III ® ® ® This oering is not approved or endorsed by ESI Group. −−> FOAM FATAL ERROR: I n v a l i d a r c d e f i n i t i o n − a r e t h e p o i n t s co − l i n e a r ? Denom =0 From f u n c t i o n c y l i n d r i c a l C S arcEdge : : c a l c A n g l e ( ) i n f i l e curvedEdges / arcEdge . blockMesh will abort issuing an error message as in Listing 80. This keyword takes the two vertices dening the edge as arguments. 0 5 ) ) ). 0 5 ) (0 0. Straight lines are created by blockMesh by default. 0 5 ) (0 0.25 0 . Listing 84 shows an example of how a patch consisting of one face is dened. Listing 83: Denition of a line in the edges sub-dictionary 11.The keyword arc can not be used to dene a straight edge. So there is no need for the user to specify straight lines. 0 5 ) ) ). edges ( s p l i n e 0 3 ((0 0. ESI-OpenCFD or the OpenFOAM Foundation. Listing 81: Denition of a spline in the edges sub-dictionary Creating a poly-line Other than a spline. If the two vertices and the additional interpo- lation point are co-linear. After the two vertices dening the edge a list of interpolation points has to follow.75 0 . edges ( line 0 3 ).25 0 . a poly-line connects several points with straight lines. 6 mergePatchPairs The III mergePatchPairs list contains pairs of patches that need to be connected by the mesher. then blockMesh creates an additional patch named This patch has an empty boundary condition automatically assigned..0/meshing. . ® ® 49 . Listing 86: A warning message of checkMesh caused by an incomplete boundary denition of a 3D mesh. . This. the warn- ing states that there is something wrong with the mesh. . the solver starts running without complaints. does not cause blockMesh to abort mesh generation.( ). In older versions of OpenFOAM. blockMesh quietly creates the mesh with the default patch save the warning message as in Listing 85. in the end checkMesh reports no failed mesh checks. ).. this behaviour might hide the source of error. warning message issued by checkMesh when a 3D mesh contains one empty default patch. defaultFaces. the creation of the default patch with an empty boundary condition can be expected behaviour. . ® ® ® This oering is not approved or endorsed by ESI Group. adding t o d e f a u l t patch . If a 2D mesh is to be created. Listing 85: A warning message of blockMesh caused by an incomplete boundary denition. there was a see f i n d $FOAM_TUTORIALS −name blockMeshDict | x a r g s g r e p p a t c h e s Listing 87: Find cases that still use the patches sub-dictionary in the blockMeshDict to dene the boundaries 11. c o n s t r u c t from s h a p e s . Boundary d e f i n i t i o n OK. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Only running checkMesh is able to give an indication to detect such kind of error. ) i n f i l e meshes / polyMesh / polyMeshFromShapeMesh . Checking t o p o l o g y . } (0 3 2 1) . .2. However. When the case is run with a 3D mesh and one or more empty patches. If faces are forgotten in the creation of a 3D mesh.php.openfoam. C r e a t i n g b l o c k mesh t o p o l o g y −−> FOAM Warning : From f u n c t i o n polyMesh : : polyMesh ( . Listing 86 shows the Although. Listing 85 shows a warning message issued by blockMesh. Hence t h i s mesh i s not 1D o r 2D. U or p). In some tutorial cases the old patches subdictionary can be found. Even the fact that none of the elds have a boundary condition specied for the default patch does not cause the solver to abort. http://www.g. Listing 84: The boundary list of blockMeshDict Pitfall: defaultFaces If faces are forgotten in the boundary denition. however. .0. At some point the solution might run into numerical trouble. it is not advisible to rely this kind of default behaviour when building a case. A patch with an empty boundary condition does not require any further entries in the eld-les (e. In this case some faces were missing in the boundary denition. it is recommended to use the boundary sub-dictionary because in some cases the use of the patches sub-dictionary results in errors.org/version2. Pitfall: patches patches sub-dictionary instead of the boundary sub-dictionary. OpenFOAM knows already all it needs to know about this specic patch and there is no reason to throw an error message. However. To nd out if there are still tutorial cases present that use the patches sub-dictionary the command of Listing 87 searches all les with the name blockMeshDict in the tutorials for the word patches. Running the case with the errorneous mesh denition will not immediately crash the solver. *** T o t a l number o f f a c e s on empty p a t c h e s i s not d i v i s i b l e by t h e number o f c e l l s i n t h e mesh .C a t l i n e 903 Found 6 u n d e f i n e d f a c e s i n mesh . ESI-OpenCFD or the OpenFOAM Foundation. If blocks are constructed in a fashion that III ® ® ® This oering is not approved or endorsed by ESI Group. The face denoted with the red 1 consists of 6 nodes and the face with the red 2 constists of four nodes. Thus. Figure 5 shows the larger of the two blocks. mergePatchPairs ( ( master s l a v e ) ). the merge operation will fail. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ESI-OpenCFD or the OpenFOAM Foundation. There a r e no merge patch p a i r s e d g e s Listing 88: Output of blockMesh when mergePatchPairs is omitted Patches to merge When two patches need to be merged. Listing 90: boundary The patch denitions needed to connect the blocks of Figure 7 with mergePatchPairs in the sub-dictionary blockMesh creates hanging nodes in order to connect the mesh of the blocks. The rst patch of the pair is considered the master patch the second is the slave patch. blockMesh will crash with an error. 11. Thus the patches need to be dened as in Listing 90. Figure 4 shows the mesh of two merged blocks. ® ® 50 . The right image in Figure 5 was edited with an image manipulation program to reect the actual situation of the mesh. During the merging operation the face touching the second block is divided to match the second block. If one of the two patches contains an additional face. The diagonal lines one of them is marked with a red square in Figure 5 are artefacts of the depiction of ParaView.Nothing to merge This entry can be omitted. boundary ( master { type patch . then the patch pair consists only of the face (1 2 6 5) and (12 15 11 8). The reason and consequences of this are described in the ocial User Manual [24]. } slave { type patch ... Listing 88 shows the message issued by blockMesh when mergePatchPairs is omitted. faces ( (1 2 6 5) ). Listing 89: The mergePatchPairs list in the blockMeshDict If the patches that are part of the merging operation contain faces which are unaected by the merging. When the blocks of Figure 7 are to be connected. then the patch pair needs to be stated in the mergePatchPairs list. ). The diagonal line that divides the L-shaped area is not present in the mesh.3 Create multiple blocks A single block is almost never sucient to model the geometry of a CFD problem. blockMesh oers the possibility to create an arbitrary number of blocks which can be connected. faces ( ( 1 2 15 11 8 ) ). } . a quadrangular cell face is divided to two faces. Figure 4: The mesh of two merged blocks Figure 5: The mesh of two merged blocks. Left: screenshot of ParaView. ® ® 51 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ESI-OpenCFD or the OpenFOAM Foundation. Right: edited image to depict the actual faces. III ® ® ® This oering is not approved or endorsed by ESI Group. III ® ® ® This oering is not approved or endorsed by ESI Group. the mergePatchPairs section of the blockMeshDict has to be provided with the two touching patches. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. the blocks are connected automatically.2 Unconnected blocks Figure 7 shows a situation in which two blocks were created that share no vertices. Therefore. The global vertex numbering is arbitrary. 7 6 4 11 5 8 3 10 2 9 0 1 Figure 6: Two connected blocks Listing 91 shows the blocks sub-dictionary to create two connected blocks as they are depicted in Figure 6. Listing 91: The blocks entries in blockMeshDict to create the connected blocks of Figure 6 11. blocks ( hex ( 0 1 2 3 4 5 6 7 ) ( 1 0 10 1 0 ) s i m p l e G r a d i n g ( 1 1 1 ) hex ( 1 9 10 2 5 8 11 6 ) ( 1 0 10 1 0 ) s i m p l e G r a d i n g ( 1 1 1 ) ). However. ® ® 52 . Creating multiple blocks is blocks blockMeshDict.they share vertices. 11. done simply by adding a further entry in the mergePatchPairs section of the Listing 92 shows the list. The blocks are connected by the statements in the blocks sub-dictionary to create two unconnected blocks as they are depicted in Figure 7. blocks ( hex ( 0 1 2 3 4 5 6 7 ) ( 1 0 10 1 0 ) s i m p l e G r a d i n g ( 1 1 1 ) hex ( 8 9 10 11 12 13 14 1 5 ) ( 1 0 10 1 0 ) s i m p l e G r a d i n g ( 1 1 1 ) ).3. Listing 92: The blocks entries in blockMeshDict to create the unconnected blocks of Figure 7 In order to generate a connected mesh of the two blocks.3. then they are connected by blockMesh by default. the order in which the vertex numbers are listed after the hex keyword corresponds with the local vertex numbering of the generic block in Figure 3.1 Connected blocks Figure 6 shows two connected blocks. ESI-OpenCFD or the OpenFOAM Foundation. These blocks share vertices. 4 Grading In the le blockMeshDict the grading can be dened globally for the edges of the block or for all edges individually. The grading is specied by the expansion ratio. The numbering of the edges the list index corresponds to the edge number is dened in the general denition of a block (see OpenFOAM Users Manual [24]). Therefore.e. In Listing 93 axis oy the block is one. the value of this keyword is a list with 12 numbers. The direction of an edge is dened in the general denition of a block (see OpenFOAM Users Manual [24]). Therefore.7 6 4 5 15 12 3 14 13 11 2 8 0 10 9 1 Figure 7: Two unconnected blocks 11. This is the ratio of the widths of the rst and the last cell along an edge. these edges must have the same grading. block 8 is the ninth block. Listing 94 has the same eect as Listing 93. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. then the grading of coincident edges must be consistent. the grading of all edges parallel to the axis is two and the grading of all edges parallel to the local z axis is three. y and z direction of the block. The error message caused by this fault is shown in Listing 96. edgeGrading ( 1 1 1 1 2 2 2 2 3 3 3 3 ) Listing 94: edgeGrading Pitfall: inconsistent grading When a mesh consists of more than one block. ® ® 53 . because OpenFOAM counts like C. ESI-OpenCFD or the OpenFOAM Foundation. III ® ® ® This oering is not approved or endorsed by ESI Group. C++ and many more programming languages from 0. The message mentions the blocks 5 and 8. simpleGrading (1 2 3) Listing 93: simpleGrading edgeGrading With the keyword edgeGrading the grading of each edge of the block is specied individually. This is correct. simpleGrading The global grading is dened for all edges parallel to the local the grading of all edges parallel to the local local y x x. In Listing 95 the grading of the last block is erroneous the grading is set to 2 instead of 3. i. 5 3 ) // 3 hex ( 4 20 24 8 5 21 25 9 ) ( 3 0 2 1 0 ) s i m p l e G r a d i n g ( 1 1 0 . then the number of cells of neighbouring blocks must be consistent. This error message indicates more clearly other than Listing 96 that OpenFOAM counts from 0.C a t l i n e 2 2 1 . three or twelve if-else branching is entered an error is reported. III ® ® ® This oering is not approved or endorsed by ESI Group. Listing 99 prooves this observation in the form of the responsible source code.e. Unfortunately not all parts of OpenFOAMs source code are that easy to read and understand. i. FOAM e x i t i n g Listing 98: Error message caused by inconsistent discretisation Interesting observation The source code also allows to state a list with only one entry. blocks ( hex ( 0 1 5 4 8 9 13 12 ) ( 9 1 44 ) s i m p l e G r a d i n g ( 1 1 1 ) // 1 hex ( 1 2 6 5 9 10 14 13 ) ( 2 1 4 5 ) s i m p l e G r a d i n g ( 1 1 1 ) // 2 hex ( 2 3 7 6 10 11 15 14 ) ( 9 1 4 5 ) s i m p l e G r a d i n g ( 1 1 1 ) // 3 ). 5 1 ) // 2 hex ( 2 18 22 6 3 19 23 7 ) ( 3 0 5 1 5 ) s i m p l e G r a d i n g ( 1 0 . Listing 97: Inconsistent discretisation −−−> FOAM FATAL ERROR: I n c o n s i s t e n t number o f f a c e s between b l o c k p a i r 0 and 1 From f u n c t i o n blockMesh : : c a l c M e r g e I n f o ( ) i n f i l e blockMesh / blockMeshMerge . ® ® 54 . 3 3 ) // 1 hex ( 1 17 21 5 2 18 22 6 ) ( 3 0 5 2 ) s i m p l e G r a d i n g ( 1 0 . entries are handled If This code listing is a beautiful example of deducting the behaviour of a program from its source code. 3 3 ) // 7 hex ( 9 25 29 13 10 26 30 1 4 ) ( 3 0 5 2 ) s i m p l e G r a d i n g ( 1 2 1 ) // 8 hex ( 1 0 26 30 14 11 27 31 1 5 ) ( 3 0 5 1 5 ) s i m p l e G r a d i n g ( 1 2 2 ) // 9 Listing 95: Inconsistent grading −−> FOAM FATAL ERROR: I n c o n s i s t e n t p o i n t l o c a t i o n s between b l o c k p a i r 5 and 8 p r o b a b l y due t o i n c o n s i s t e n t g r a d i n g .blocks ( hex ( 0 16 20 4 1 17 21 5 ) ( 3 0 5 1 0 ) s i m p l e G r a d i n g ( 1 0 .C a t l i n e 2 9 4 . hex ( 8 24 28 12 9 25 29 1 3 ) ( 3 0 5 1 0 ) s i m p l e G r a d i n g ( 1 2 0 . FOAM e x i t i n g Listing 96: Error message caused by inconsistent grading Pitfall: inconsistent discretisation When a mesh consists of more than one block. From f u n c t i o n blockMesh : : c a l c M e r g e I n f o ( ) i n f i l e blockMesh / blockMeshMerge . This is not documented in the ocial User Manual [24]. 3 3 ) // 4 hex ( 5 21 25 9 6 22 26 1 0 ) ( 3 0 2 2 ) s i m p l e G r a d i n g ( 1 1 1 ) // 5 hex ( 6 22 26 10 7 23 27 1 1 ) ( 3 0 2 1 5 ) s i m p l e G r a d i n g ( 1 1 3 ) // 6 ). 5 0 . ESI-OpenCFD or the OpenFOAM Foundation. The error message caused by this faulty denition is shown in Listing 98. The rst command reads a scalar list from the input stream none of the three branches of the is. the blocks must have the same number of cells along coincident axes. Then the three valid cases one. In Listing 97 the number of cells of the rst block is erroneous the number is set to 44 instead of 45 along the local z direction. The message mentions the blocks 0 and 1. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. } Listing 99: Some content of 11. ® ® 55 .1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 s c a l a r L i s t expRatios ( i s ) i f ( e x p R a t i o s . } else { FatalErrorIn ( " blockDescriptor : : blockDescriptor " " ( c o n s t p o i n t F i e l d &. expand_ [ 1 ] = e x p R a t i o s [ 0 ] .e. c o n s t c u r v e d E d g e L i s t &. [1]. i. [1].5 In blockDescriptor.1 The blockMeshDict prototype If the user wants to create parametrised meshes. // z− d i r e c t i o n expand_ [ 8 ] = e x p R a t i o s expand_ [ 9 ] = e x p R a t i o s expand_ [ 1 0 ] = e x p R a t i o s expand_ [ 1 1 ] = e x p R a t i o s [2]. In order to create a parametric mesh a prototype of the le blockMeshDict is needed. s i z e ( ) == 3 ) { // x− d i r e c t i o n expand_ [ 0 ] = e x p R a t i o s [ 0 ] . Also. no calculations can be made by blockMesh with the exception of the keyword convertToMeters. // y− d i r e c t i o n expand_ [ 4 ] = e x p R a t i o s expand_ [ 5 ] = e x p R a t i o s expand_ [ 6 ] = e x p R a t i o s expand_ [ 7 ] = e x p R a t i o s [1]. s i z e ( ) == 1 ) { // i d e n t i c a l i n x/y/ z− d i r e c t i o n s expand_ = e x p R a t i o s [ 0 ] . I s t r e a m &)" ) << "Unknown d e f i n i t i o n o f e x p a n s i o n r a t i o s : " << e x p R a t i o s << e x i t ( F a t a l E r r o r ) . ESI-OpenCFD or the OpenFOAM Foundation. This indicates a 2D problem. an additional working step is necessary.5. Listing 100 shows the block denition of such a prototype. This prototype contains symbols.C Parametric meshes by the help of m4 and blockMesh blockMeshDict only plain text is allowed. 11. only the number of cells is calculated. expand_ [ 2 ] = e x p R a t i o s [ 0 ] . no symbols can be used. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.e. s i z e ( ) == 1 2 ) { expand_ = e x p R a t i o s . [2]. [2]. } e l s e i f ( e x p R a t i o s . // 1 // 2 // 3 Listing 100: Block denition of the prototype III ® ® ® This oering is not approved or endorsed by ESI Group. blocks ( hex ( 0 1 5 4 8 9 13 12 ) ( N1x 1 N1z ) s i m p l e G r a d i n g ( 1 1 1 ) hex ( 1 2 6 5 9 10 14 13 ) ( N2x 1 N1z ) s i m p l e G r a d i n g ( 1 1 1 ) hex ( 2 3 7 6 10 11 15 14 ) ( N1x 1 N1z ) s i m p l e G r a d i n g ( 1 1 1 ) ). properties of the mesh are calculated from certain pa- rameters. This block denition is not fully parametric. i. expand_ [ 3 ] = e x p R a t i o s [ 0 ] . [1]. that in local y direction only one cell is used for discretisation. Note. } e l s e i f ( e x p R a t i o s . [2]. Then by dividing this length by the discretisation length the number of cells is calculated. ` r e l D i f f ( x2 . 0 . x1 . III ® ® ® This oering is not approved or endorsed by ESI Group. direction. 0 . These operations compute rst the length of the block that needs to be descretised. 0 . ` e v a l ( 2 * h ) ' ) d e f i n e ( N1z . a macro has to be dened.gnu. This is the reason for the rather complicated argument of the input of the command bc22 . The interpreter of this language scans the prototype for valid expressions (macros) and replaces them with their result. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // # e n t e r d i s c r e t i z a t i o n l e n g t h d e f i n e ( dx . The direction based on the variable h.0f. 0 5 5 5 ) d e f i n e ( x2 . oating point calculations can be done by an external program. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ` format ( ` % . 0 . the prototype has to be processed by a macro programming language interpreter. 0 f ' . 0 0 5 ) // # e n t e r x c o o r d i n a t e s d e f i n e ( x1 . Consequently. 0 . The output is then formatted by the macro format. ® ® 56 . dz ) ' ) 21 m4 is part of the GNU project. 0 . This step is absolutely necessary. To replace a symbol of the prototype with a meaningful number.2 The macro programming language m4 In order to replace the symbols of the prototype with meaningful numbers. See http://www. a/ $3 " | bc ) ) ' ) d e f i n e ( N1x .11. because only integers are allowed to dene the number of cells. The output of the command echo is operating system via a system call. In line 13 a macro is dened that passes its arguments to the esyscmd gets executed in the command esyscmd. ` r e l D i f f (H1 . Note the formatting string %. esyscmd ( echo " s c a l e =2. As m4 supports system calls. 2 0 ) // # r e l D i f f : ( $1 − $2 ) / $3 # d e c i m a l p l a c e s t r u n c a t e d ( done by format %. dx ) ' ) d e f i n e ( N1z . Listing 101 shows the denition of the symbols used in Listing 100. ` e v a l ( 9 * h ) ' ) d e f i n e ( N2x . a=$1−$2 .5. 0 . Complex math . 0 0 5 ) d e f i n e ( dz . ESI-OpenCFD or the OpenFOAM Foundation.rst shot The builtin mathematic macros of m4 are restricted to integer operations only. It is part of the GNU project. Specifying the discretisation length requires more complex math than integer operations. ` e v a l ( 4 5 * h ) ' ) Listing 101: Block denition of the prototype This kind of parametrisation allows to specify a multiplier for the number of cells. 0 9 4 5 ) // # e n t e r h e i g h t s ( z c o o r d i n a t e s ) d e f i n e (H1 . echo is composed of three successive operations that need to be performed The rst instruction says that two digits after the decimal point should be used. The argument of the command line. In this case the programming language m4 21 is used. The second instruction calculates the dierence between the rst two arguments and the last instruction divides this dierence by the third argument. define (h . 2 ) d e f i n e ( N1x . the symbol is replaced by the result of the system call. This causes the result to loose its digits after the decimal point.html 22 bc is a calculator program.org/software/m4/manual/index.0 f ) d e f i n e ( r e l D i f f . dx ) ' ) d e f i n e ( N2x . Note the use of the pipe. In the rst line a general variable second and the third instruction calculate the number of cells in the local The last instruction calculates the number of cells in the local z x h is dened. In Listing 102 some variables are dened. The discretisation length can not be rened gradually this way. ` r e l D i f f ( x1 . The input of the command by the calculator. the // starts a comment for OpenFOAM and the # starts a comment for m4. Listing 104 shows some examples taken from a m4 script found in the tutorials. As Perl is able to do mathematical operations. c a l c ( 0 . 23 is called. ESI-OpenCFD or the OpenFOAM Foundation. using trigonometric functions is possible. 5 * ( rb + Rb) ) ) d e f i n e ( pi . The instruction print ($1) is a function that prints its argument on the standard output. The macro esyscmd returns the standard output of the command it executed. 1 2 3 4 5 6 7 8 9 10 11 12 changecom ( / / ) changequote ( [ . ® ® 57 . [ esyscmd ( p e r l −e ' p r i n t ( $1 ) ' ) ] ) d e f i n e ( rb . Therefore. 0 . OpenFOAM dictionaries follow the C++ syntax. See the rst line of Listing 102. comments have the same delimiter as C or C++. anything following a // is treated as a comment. The argument of the print function calc macro. In this case the interpreter of the script programming language Perl receives a command line argument and an instruction. The interpreter will interpret this single line and exit. Listing 103 shows the result after the macros from Listings 100 and 102 have been processed. the mathematical operation can be written directly in the code. 0 . ] ) d e f i n e ( c a l c . The second line of Listing 104 redenes the quote delimiter. See line 9 for an example. 5 ) d e f i n e (Rb . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.g. There. 7 ) d e f i n e ( r i . The rst statement changes the delimiter for comments. By changing the delimiter to //. is the argument of the Line 12 of Listing 104 shows that even more complex math e. blocks ( hex ( 0 1 5 4 8 9 13 12 ) ( 1 1 1 4 0 ) s i m p l e G r a d i n g ( 1 1 1 ) hex ( 1 2 6 5 9 10 14 13 ) ( 7 1 4 0 ) s i m p l e G r a d i n g ( 1 1 1 ) hex ( 2 3 7 6 10 11 15 14 ) ( 1 1 1 4 0 ) s i m p l e G r a d i n g ( 1 1 1 ) ). Remember. 3 . therefore. The argument of the calc macro is passed via the system call to the Perl interpreter.the better solution The above described way to do mathematical operations is not very elegant. This macro also uses a system call to outsource the actual math. 1 4 1 5 9 2 6 5 ) d e f i n e ( ca0 . At this place a more elaborate solution is presented. Due to rounding operations the specied discretisation length is not exactly met. commented lines are always treated as comments by m4 as well as OpenFOAM.Listing 102: Block denition of the prototype Listing 102 allows to calculate the number of cells from a specied discretisation length.perl. There. Now. the symbols rb and Rb are replaced my m4 by their denition. the interpreter computes the result of the expression and executes the function print. Setting the delimiter for comments to be the same as in C++ removes an ambiguity and a possible source for errors. // 1 // 2 // 3 Listing 103: Resulting parametric block denition Complex math . Changing this delimiters from the standard to the brackets is probably done to improve readability.org/ III ® ® ® This oering is not approved or endorsed by ESI Group. This interpreter The command line argument -e tells the interpreter that only one line of code will follow. c a l c ( c o s ( ( p i / 1 8 0 ) * a0 ) ) ) Listing 104: Doing complex math with m4 23 See http://www. In line 4 of Listing 104 a macro named calc is dened. 6. III ® ® ® This oering is not approved or endorsed by ESI Group. snappyHexMesh can only be used in conjunction with blockMesh. it is a very useful utility. ParaView only reads the le blockMeshDict. Figure 8 shows the blocks of a parametric mesh. The image shows also the numbers of the vertices.2 Viewing the blocks with pyFoam Troubleshooting can be dicult when blockMesh doesn't create a mesh and displays some error messages instead. snappyHexMesh snappyHexMesh is a meshing tool that is able to mesh the space around an arbitrary object. 12. It consists of nine blocks. This is generally the case in external aerodynamics. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. snappyHexMesh is not a stand alone meshing tool. ® ® 58 .6. ESI-OpenCFD or the OpenFOAM Foundation.6 Trouble-shooting 11. See Section 11. Listing 105 shows how ParaView can be used to visualise the blocks.0. when blockMesh fails due to an errorneous denition in blockMeshDict.6.11. 11.3 Workow The topic of investigation is the drag force on an anvil. Even though. paraFoam − b l o c k Listing 105: Visualising the blocks This way.1 for the discussion of a tool which is able to display the blocks as they are dened in blockMeshDict.1 Viewing the blocks with ParaView A mesh created by blockMesh consists of blocks. Figure 8: The blocks of a parametric mesh consisting of nine blocks. 12 This tool even works. only the blocks are displayed. the object under investigaton in this case the anvil has to be modelled by means of CAD. the space outside of the anvil has to be meshed. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 59 . the anvil has to be subtracted from the background domain. The remainder is our computational domain. ESI-OpenCFD or the OpenFOAM Foundation. The background domain is meshed using blockMesh. Figure 10 shows the background domain (the rectangle) and the object under investigation (the anvil). the computational domain has to be specied. Then. To simulate this case. snappyHexMesh then perfoms several steps Cell splitting III The cells of the background mesh near the objects surface are rened. Mathematically skeaking. snappyHexMesh needs a representation of the object actually only the objects surface is important in STL format. thus creating the background mesh 2. ® ® ® This oering is not approved or endorsed by ESI Group.Figure 9: Problem To solve this problem. Figure 10: Problem geometry The creation of the mesh in this case follows a two step approach: 1. Restricting checkMesh to the nal mesh reduces runtime and avoids the unnecessary examination of an intermediate mesh.1. 13. The value of the convertToMeters blockMeshDict keyword in blockMeshDict 3. Listing 106 shows an error message produced by checkMesh. ESI-OpenCFD or the OpenFOAM Foundation. after a completed run of snappyHexMesh there are the background mesh and the results of the three basic stages of a snappyHexMesh run (castellation. Depending on which of these steps are active up to four meshes may be present. ® ® 60 . checkMesh is simply invoked by its name. Then checkMesh performs some further tests. 12. Like other tools. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. c o n s t word&. In this case the tool can't nd the les specied in Section 10. then something is wrong. snapping and layer addition). The unit of the vertex coordinates in 2. FOAM e x i t i n g Listing 106: No mesh present A more thorough testing is performed when checkMesh is called with two additional options. III ® ® ® This oering is not approved or endorsed by ESI Group. if checkMesh has been called with no mesh present.Cell removal Cells of the background mesh inside the object are removed. C a t l i n e 1 8 8 . Cell snapping The remaining background mesh is modied in order to reconstruct the surface of the object. c o n s t I O o b j e c t : : readOption .1 Denitions In order to understand the output of checkMesh it is necessary to dene some quantities calculated by checkMesh. is not told otherwise. This option is particularly useful when examining meshes created by snappyHexMesh. checkMesh − a l l G e o m e t r y − a l l T o p o l o g y Listing 107: Do more checks checkMesh has also the -latestTime option like many other OpenFOAM tools. Check the following things: 1. −−> FOAM FATAL ERROR: Cannot f i n d f i l e " p o i n t s " i n d i r e c t o r y " polyMesh " i n t i m e s 0 down t o c o n s t a n t From f u n c t i o n Time : : f i n d I n s t a n c e ( c o n s t f i l e N a m e &.0. convertToMeters in blockMeshDict When creating a mesh with snappyHexMesh dierent scales of the background mesh and the STL mesh are a frequent source of error. the path to the case directory has to be specied with the option -case. As snappyHexMesh performs up to three work intensive steps (castellation. Layer addition Additional hexahedral cells are introduced on the boundary surface of the object to ensure a good mesh quality. The unit in which the STL was created 13 checkMesh checkMesh is a tool to perform tests on an existing mesh. When checkMesh is to be called from an other location than the case directory. a run of snappyHexMesh takes a couple of seconds or even longer (tens of seconds). c o n s t word&) i n f i l e db/Time/ f i n d I n s t a n c e . snapping and layer addition). checkMesh assumes to be called from the case directory.4 Pitfalls Run time If snappyHexMesh is nished in less than a second. snappyHexMesh stores intermediate meshes if it By default. Internal faces Each internal face connects two cells. In Figure 11 the vector connecting the cell centres is denoted face normal vector 24 d and the S. 9 can also be found in the sources of OpenFOAM in the function cellQuality. ® ® 61 . s c a l a r magS = mag( s ) . A non-orthogonality of 0 means the mesh is orthogonal and 24 The face normal vector or face area vector is a vector normal to a face.1 Face non-orthogonality Non-orthogonality is a property of the faces of the mesh. Second. Listing 108: A detail of the function faceNonOrthogonality The non-orthogonality reported by checkMesh is the angle θ in the le of Figure 11.C there are two methods dened: nonOrthogonality() and faceNonOrthogonality(). r e s u l t [ f a c e I ] = cosDDotS . f a c e I ) { v e c t o r d = c e n t r e s [ n e i [ f a c e I ] ] − c e n t r e s [ own [ f a c e I ] ] . 0 . The limit of -1 is inherently ensured. } s c a l a r cosDDotS = radToDeg (Foam : : a c o s ( min ( 1 . respectively. The length of this vector is equal to the area of the face. Comparing the code of this two methods reveals. ( d & s ) / (mag( d ) *magS + VSMALL) ) ) ) . (d & s)/(mag(d)*magS + VSMALL)). cellQuality. that they compute the same thing. Note the two precautions that were taken to avoid numerical issues. cell centres. Keeping the argument of the arc-cosine equal or below 1 makes perfectly sense. because the arc-cosine is dened only for values between -1 and 1. ESI-OpenCFD or the OpenFOAM Foundation. the argument of the VSMALL.13. 1 2 3 4 5 6 7 8 9 10 VSMALL is also positive. Listing 108 shows a loop over all faces. This angle can be calculated from d and S by Eq. (8) (9) faceNonOrthogonality in the le For each face the non-orthogonality is computed. S P N θ d f Figure 11: Denition of non-orthogonality for internal faces In a perfectly orthogonal mesh the vectors d and S are parallel. The vectors d and s are the connecting vector between the The scalar cosDDotS is the angle θ of Figure 11. The non-orthogonality is the angle between the vector connecting the cell centres and the face normal vector. First. d · S = ||d|| ||S|| cos(θ) (7) ||d|| ||S|| cos(θ) d·S = = cos(θ) ||d|| ||S|| ||d|| ||S|| d·S ) θ = arccos( ||d|| ||S|| Eq. the method nonOrthogonality() returns the aected cells. III ® ® ® This oering is not approved or endorsed by ESI Group. the denominator is the sum of the product of the magnitudes and zero.C25 . f o r A l l ( nei .0. VSMALL is a number with a very small value to prevent division by acos function is min(1. and the face area vector. 9. If a mesh is non-orthogonal these vectors draw an angle as in Figure 11.C Therefore the reported non- orthogonality lies in the range between 0 and 90. However. whereas faceNonOrthogonality() returns the aected faces. We need to discriminate between internal faces and boundary faces. The inner product of two vectors is always positive. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 25 In the le cellQuality. vector s = areas [ faceI ] .1. 0 . Gambit. 10. From this three vectors the inner product with the face area vector Af do . Internal faces Each internal face connects two cells. Listing 112 shows the output of checkMesh. This connecting I divides the line c into the two parts c1 and c2 . f a c e C e l l s ( ) . which connects the cell center P and the face center S f. f a c e A r e a s ( ) . s c a l a r magS = mag( s ) . ( d & s ) / (mag( d ) *magS + VSMALL) ) ) ) . Therefore these symbols are written in typewriter font.C 13. dn and c dOwn and is computed to obtain 26 dOwn and dNei are actual variable names. Non-orthogonality of boundary faces is dened as the angle in degrees between the face area vector and the vector d. the maximum and average non-orthogonality is 0. F are easily obtained. Figure 12 shows a schematic boundary face with its face center f. The reason for this OpenFOAMspecic denition is that this denition is associated with the denition of a skewness error in [17] as part of mesh induced discretisation errors. Listing 115 indicates that a non-orthogonality of above 70 triggers checkMesh to issue a warning message. In this case the mesh is orthogonal. Skewness is a property of the faces of the mesh. boundaryMesh ( ) [ p a t c h I ] . } Listing 109: A detail of the function faceNonOrthogonality in the le cellQuality. f a c e C e n t r e s ( ) . boundaryMesh ( ) [ p a t c h I ] . r e s u l t [ g l o b a l F a c e I ++] = cosDDotS . Listing 114 shows the output of checkMesh in case of a non-orthogonal mesh. is the face centre of the face line intersects with the face faceP N . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. S d P θ f Figure 12: Denition of non-orthogonality for boundary faces 1 2 3 4 5 6 7 8 9 10 11 12 13 14 c o n s t l a b e l U L i s t& f a c e C e l l s = mesh_ . ® ® 62 .consists of hexahedra (cuboids) or regular tetrahedra.2 Face skewness OpenFOAM denes skewness in a mesh dierent than other tools. ESI-OpenCFD or the OpenFOAM Foundation. do and dn P. The The line This intersection point is of key interest because the skewness is dened in Eq. boundaryMesh ( ) [ p a t c h I ] . faceP N . N c1 and The point F P and N of two adjacent cells. s c a l a r cosDDotS = radToDeg (Foam : : a c o s ( min ( 1 .1. Figure 13 shows the cell centres faceP N is the face connecting these two cells. c = P N connects the cell centres. With dNei26 .g. c o n s t v e c t o r F i e l d : : s u b F i e l d f a c e A r e a s = mesh_ . f a c e I ) { vector d = faceCentres [ faceI ] − centres [ faceCells [ faceI ] ] . vector s = areas [ faceI ] . We need to discriminate between internal faces and boundary faces. c o n s t v e c t o r F i e l d : : s u b F i e l d f a c e C e n t r e s = mesh_ . f o r A l l ( nei . III ® ® ® This oering is not approved or endorsed by ESI Group. face To calculate the location of I the length of The location (the vector to) the points is computed. Boundary faces Non-orthogonality is also dened for boundary faces. e. P in order to There a loop over dOwn and dNei faceIntersection of the type all internal faces is traversed. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 27 In the le cellQuality. The loop body contains the calculation of the skewness. ® ® 63 . the skewness is calculated (compare Eq. III ® ® ® This oering is not approved or endorsed by ESI Group. First are computed. In this case the symbol faceSkewness from the le P~ is prefered to cellQuality. However.C there are two methods dened: skewness() and faceSkewness().C27 . Comparing the code of this two methods reveals. Notice the precaution against a possible division by zero (adding VSMALL to the denominator). ESI-OpenCFD or the OpenFOAM Foundation. 20).F Af do dOwn P dNei X c1 I dn c2 N faceP N Figure 13: Denition of skewness of internal faces |IF | |P N | ~ do = F − P~ ~ dn = F~ − N ~ − P~ c=N skewness = (10) (11) (12) (13) do · Af ||Af || dn · Af dNei = ||Af || dOwn = (14) (15) 6 (XP N ) = α dOwn dOwn + dNei dOwn + dNei cos(α) = = = c1 c1 + c2 ||c|| dOwn c1 = ||c|| dOwn + dNei I~ = P~ + c1 c ~ ||F~ − I|| skewness = ||c|| Note that both notation. The reader hopefully excuses this lack of consistency in mathematical denotes the position vector of the point use symbols that can be found in Figure 13. whereas faceSkewness() returns the aected faces. Then the location of the point point I contains the position vector to the point is determined. Listing 110 shows a detail of the function P. Finally. The variable I the point at which the connection line between the cell centres intersects the face. the method skewness() returns the aected cells. that they compute the same thing. P~ P~ and c (16) (17) (18) (19) (20) are vectors. The normal vector n is easily computed from the face-area vector given by the method III ® ® ® This oering is not approved or endorsed by ESI Group. At the point on the vector n we gain the face-intersection This is the point. } result [ faceI ] = mag( f a c e C t r s [ f a c e I ] − f a c e I n t e r s e c t i o n ) / (mag( c e l l C t r s [ n e i [ f a c e I ] ] − c e l l C t r s [ own [ f a c e I ] ] ) + VSMALL) . ESI-OpenCFD or the OpenFOAM Foundation. f a c e I ) { s c a l a r dOwn = mag ( ( f a c e C t r s [ f a c e I ] − c e l l C t r s [ own [ f a c e I ] ] ) & a r e a s [ f a c e I ] ) /mag( a r e a s [ f a c e I ] ) . Figure 14 shows the sketch of a boundary face with its face center FC FC . and FC .1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 f o r A l l ( nei . P to the face center If we project the vector d FC is depicted in red. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. s c a l a r dNei = mag ( ( cellCtrs [ nei [ faceI ] ] − faceCtrs [ faceI ] ) & areas [ faceI ] ) /mag( a r e a s [ f a c e I ] ) . Listing 111 shows the code that computes the skewness of the boundary faces. point f a c e I n t e r s e c t i o n = c e l l C t r s [ own [ f a c e I ] ] + (dOwn/ (dOwn+dNei ) ) * ( c e l l C t r s [ n e i [ f a c e I ] ] − c e l l C t r s [ own [ f a c e I ] ] ) . faceAreas(). We then compute the vector magnitudes of the vectors f and f . The vector d from the cell center we see the face normal vector point FI . n. Listing 110: A detail of the function faceSkewness cellQuality. as it is the case in Figure 14. The ratio of the The points P and FC are FI P f d FC n Figure 14: Denition of skewness of boundary faces returned by the methods faceCells() and faceCentres(). which is the connection between the points FI d denes the skewness of a boundary face. ® ® 64 .C in the le Boundary faces Skewness is also dened and checked for boundary faces. where the face normal departing from the cell center intersects with the face. The face-intersection does not necessarily need to be part of the face. however.C 13. f a c e C e l l s ( ) . Therefore. checkMesh does only check if a mesh makes a simulation impossible. n I n t e r n a l F a c e s ( ) . ® ® 65 . Listing 112 shows the output of checkMesh when a mesh with high aspect ratio cells is tested. III ® ® ® This oering is not approved or endorsed by ESI Group.cellCtrs[faceCells[faceI]] (22) F~I = cellCtrs[faceCells[faceI]] + ((faceCentres[faceI] .aspect ratio checkMesh performs a number of quality checks. f a c e I ) { v e c t o r n = f a c e A r e a s [ f a c e I ] / mag( f a c e A r e a s [ f a c e I ] ) . Furthermore. However. f o r A l l ( faceCentres .2. There are some situations in which checkMesh does not issue an error or a warning. a mesh can nevertheless be unsuitable for a successful calculation. } } r e s u l t [ g l o b a l F a c e I ++] = mag( f a c e C e n t r e s [ f a c e I ] − f a c e I n t e r s e c t i o n ) /( mag( f a c e C e n t r e s [ f a c e I ] − c e l l C t r s [ f a c e C e l l s [ f a c e I ] ] ) + VSMALL ). p a t c h I ) { c o n s t l a b e l U L i s t& f a c e C e l l s = mesh_ . Listing 111: A detail of the function faceSkewness in the le cellQuality. boundaryMesh ( ) .1 Mesh quality . ESI-OpenCFD or the OpenFOAM Foundation. const vectorField : : subField faceAreas = mesh_ . f o r A l l ( mesh_ .cellCtrs[faceCells[faceI]])&n)*n (23) F~I = P~ + (d · n)n (24) f = faceCentres[faceI] . The tests performed by checkMesh do not necessarily guarantee the mesh to be suitable for simulation.2 Pitfalls The results of checkMesh need to be taken with a grain of salt. boundaryMesh ( ) [ p a t c h I ] . the user has to be careful. f a c e C e n t r e s ( ) .n = faceAreas[faceI]/mag(faceAreas[faceI]) (21) d = faceCentres[faceI] . that does not necessariliy mean that it is unsuitable for calculation. The aspect ratio is the ratio of the largest and the smallest dimension of the cells. 13.1. if a mesh fails a test.1) and also to know about the shortcomings of the tests performed by checkMesh (Section 13. boundaryMesh ( ) [ p a t c h I ] . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.3 Face concavity pending 13. const vectorField : : subField faceCentres = mesh_ . f a c e A r e a s ( ) . For the aspect ratio there are no limits.faceIntersection f = F~C − F~I 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 (25) (26) l a b e l g l o b a l F a c e I = mesh_ .2). it is helpful to know how checkMesh denes the qualitity measures it tests for (Section 13.4 Cell concavity When a cell is concave 13. boundaryMesh ( ) [ p a t c h I ] . point f a c e I n t e r s e c t i o n = c e l l C t r s [ f a c e C e l l s [ f a c e I ] ] + ( ( f a c e C e n t r e s [ f a c e I ] − c e l l C t r s [ f a c e C e l l s [ f a c e I ] ] ) &n ) *n .1. Although checkMesh does not complain, the mesh is not suitable for simulation. Even with extremely small time steps numerical problems appear. Checking geometry . . . O v e r a l l domain bounding box ( 0 0 0 ) ( 0 . 1 0 . 1 0 . 0 1 ) Mesh ( non−empty , non−wedge ) d i r e c t i o n s ( 1 1 1 ) Mesh ( non−empty ) d i r e c t i o n s ( 1 1 1 ) Boundary o p e n n e s s ( − 9.51633 e −17 1 . 1 7 7 9 1 e −18 − 4.51751 e − 17) OK. Max c e l l o p e n n e s s = 1 . 3 5 5 2 5 e −16 OK. Max a s p e c t r a t i o = 100 OK. Minimum f a c e a r e a = 2 . 5 e − 07. Maximum f a c e a r e a = 2 . 5 e − 05. Face a r e a magnitudes OK. Min volume = 1 . 2 5 e − 09. Max volume = 1 . 2 5 e − 09. T o t a l volume = 0 . 0 0 0 1 . C e l l volumes OK. Mesh non− o r t h o g o n a l i t y Max : 0 a v e r a g e : 0 Non− o r t h o g o n a l i t y check OK. Face pyramids OK. Max s k e w n e s s = 2 e −06 OK. Coupled p o i n t l o c a t i o n match ( a v e r a g e 0 ) OK. Mesh OK. End Listing 112: checkMesh output for a mesh with high aspect ratio 13.2.2 Mesh quality - skewness There are dierent ways to calculate the skewness of a nite volume cell. To test whether checkMesh complains about high skewness, a mesh is distorted by the use of edge grading. Figure 15 shows this mesh. Parallel edges are graded alternately alternating between the expand ratio and its reciprocal value. Listing 113 shows the grading settings. The test case for this examination is the cavity case of icoFoam. This case can be found in the tutorials. hex ( 0 1 2 3 4 5 6 7 ) ( 2 0 20 2 ) edgeGrading ( 3 0 . 3 3 3 0 . 3 3 1 1 1 1 1 1 1 1) Listing 113: Block denition in blockMeshDict to achieve high skewness Figure 15: A distorted mesh checkMesh issues no warnings for the value pair 3 and 0.33. The values 4 and 0.25 cause a warning about severly non-orthogonal faces. However, a simulation is impossible for much lower values. The simulation runs for the value pair 0.75. The values 1.4 and 0.714 cause the simulation to crash. 1.33 and The limits of stability of a simulation are therefore reached earlier than the limits of checkMesh. To conclude this section, the user should bear the folling statement in mind. Numerical problems of a simulation may be caused by bad mesh quality. In some cases like the one presented above bad mesh quality is III ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 66 the root of the problem, but checkMesh issues no warnings. However, the values of the quality characteristics may give a hint. Some manuals of CFD software propose numerical ranges for characteristics like aspect ratio to ensure good quality. Checking geometry . . . O v e r a l l domain bounding box ( 0 0 0 ) ( 0 . 1 0 . 1 0 . 0 1 ) Mesh ( non−empty , non−wedge ) d i r e c t i o n s ( 1 1 1 ) Mesh ( non−empty ) d i r e c t i o n s ( 1 1 1 ) Boundary o p e n n e s s ( 4 . 2 3 5 1 6 e −18 9 . 0 3 5 0 2 e −18 1 . 6 0 9 3 6 e − 16) OK. Max c e l l o p e n n e s s = 1 . 6 7 2 5 1 e −16 OK. Max a s p e c t r a t i o = 3 . 6 3 0 5 9 OK. Minimum f a c e a r e a = 1 . 4 2 6 4 8 e − 05. Maximum f a c e a r e a = 7 . 1 6 9 4 e − 05. Face a r e a magnitudes OK. Min volume = 1 . 0 3 8 5 4 e − 07. Max volume = 1 . 6 9 6 7 3 e − 07. T o t a l volume = 0 . 0 0 0 1 . C e l l volumes OK . Mesh non− o r t h o g o n a l i t y Max : 6 9 . 4 7 9 8 a v e r a g e : 3 2 . 8 0 9 2 Non− o r t h o g o n a l i t y check OK. Face pyramids OK. Max s k e w n e s s = 2 . 3 5 4 8 5 OK. Coupled p o i n t l o c a t i o n match ( a v e r a g e 0 ) OK. Mesh OK. End Listing 114: checkMesh output for the distorted mesh; grading ratios 3 and 0.33 Checking geometry . . . O v e r a l l domain bounding box ( 0 0 0 ) ( 0 . 1 0 . 1 0 . 0 1 ) Mesh ( non−empty , non−wedge ) d i r e c t i o n s ( 1 1 1 ) Mesh ( non−empty ) d i r e c t i o n s ( 1 1 1 ) Boundary o p e n n e s s ( 4 . 2 3 5 1 6 e −18 − 6.21157 e −18 1 . 1 8 5 8 5 e − 16) OK. Max c e l l o p e n n e s s = 2 . 3 7 6 6 4 e −16 OK. Max a s p e c t r a t i o = 4 . 2 3 7 0 6 OK. Minimum f a c e a r e a = 1 . 2 3 1 8 1 e − 05. Maximum f a c e a r e a = 8 . 6 7 8 7 4 e − 05. Face a r e a magnitudes OK. Min volume = 1 . 0 0 8 8 2 e − 07. Max volume = 1 . 8 4 0 5 5 e − 07. T o t a l volume = 0 . 0 0 0 1 . C e l l volumes OK . Mesh non− o r t h o g o n a l i t y Max : 7 3 . 1 6 3 5 a v e r a g e : 3 6 . 2 1 3 1 *Number o f s e v e r e l y non− o r t h o g o n a l f a c e s : 8 0 . Non− o r t h o g o n a l i t y check OK. <<Writing 80 non− o r t h o g o n a l f a c e s t o s e t nonOrthoFaces Face pyramids OK. Max s k e w n e s s = 2 . 9 3 9 7 8 OK. Coupled p o i n t l o c a t i o n match ( a v e r a g e 0 ) OK. Mesh OK. End Listing 115: checkMesh output for the distorted mesh; grading ratios 4 and 0.25 13.2.3 Possible non-pitfall: twoInternalFacesCells If a mesh for a two-dimensional simulation is created and checked using checkMesh with the option enabled -allTopology 28 , then checkMesh will issue a message like in Listing 116. This message indicates, that there are cells present with only two internal faces. This message can be ignored when 2D meshes are concerned. The corner cells of a rectangular mesh have by denition only two internal faces. Checking t o p o l o g y . . . Boundary d e f i n i t i o n OK. C e l l t o f a c e a d d r e s s i n g OK. Point u s a g e OK. Upper t r i a n g u l a r o r d e r i n g OK. Face v e r t i c e s OK. T o p o l o g i c a l c e l l z i p −up check OK. Face − f a c e c o n n e c t i v i t y OK. 28 When the -allTopology option is enabled, checkMesh performs two additional topological checks. Checking the face connectivity is one of these checks. III ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 67 <<Writing 4 c e l l s with two non−boundary f a c e s t o s e t t w o I n t e r n a l F a c e s C e l l s Number o f r e g i o n s : 1 (OK) . Listing 116: checkMesh output for a 2D mesh with -allTopology option set. If this message appears when a 3D mesh is examined, then there is probably some error in the denition of the mesh. A cell in a 3D mesh should have at least three internal faces. A message stating the presence of cells with two internal faces in a 3D mesh indicates non-connected regions. 13.3 Useful output The output of checkMesh in Listing 116 also shows another interesting thing to know about checkMesh. The line Writing 4 cells with two non-boundary faces to set twoInternalFacesCells tells the user that checkMesh created a set of cells that are found to have some problems. Figure 16 shows the content of the case which resulted in Figure 15. There we see a directory named inside the polyMesh folder. The sets sets folder was created by checkMesh and inside this folder checkMesh stores any sets it creates. The le names are rather self-explanatory, e.g. the le skewFaces contains all faces which failed the test for skewness. All these cell or face sets can be viewed with paraView. . 0 p U constant polyMesh blockMeshDict boundary faces neighbour owner points sets lowQualityTetFaces nonOrthoFaces skewFaces underdeterminedCells transportProperties system controlDict fvSchemes fvSolution Figure 16: Sets created by checkMesh in the sets directory. 14 Other mesh manipulation tools 14.1 topoSet The tool topoSet creates point, face or cell sets from a geometric denition. There are a number of ways to dene the geometric region containing the intended points, faces or cells. 14.1.1 Usage The dictionary topoSetDict is used to dene the geometric region. Find some examples in the tutorials using the following command. III ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 68 f i n d $FOAM_TUTORIALS −name t o p o S e t D i c t Listing 117: Find examples for the use of topoSet A face or cell set will contain only faces or cells whose centres lie within the specied geometric region. 14.1.2 Pitfall: The denition of the geometric region To demonstrate the function of topoSet a cell set was dened for the cavity tutorial-case. cavity case is The mesh of the 1 × 1 × 0.1 m and the box dening the cell set was chosen to be 0.5 × 0.5 × 0.05 m. The dimensions of this box are simply half the dimensions of the mesh. However, only cells whose cell centre is located in the box are contained in the cell set. As the mesh is one cell in depth and exactly at z = 0.05 m. 0.1 m in depth, all the cell centres are 29 , the numerical errors Due to inevitable numerical errors in calculating the cell centre decided whether a cell was included into the cell set or not. To avoid this error, always make sure the geometric region contains all the intended cells. Figure 17: A faulty cell set denition. The red cells are part of the cell set. All other cells are blue. 14.1.3 Pitfall: renumbered mesh 30 . If renumberMesh is called after At the point of writing the utility renumberMesh does not consider cell sets cell sets were created by topoSet, the cell set is invalid. The reason for this is, that the cell labels of the cell set remain unchanged as renumberMesh completely relabels the mesh. Thus, the cell set still exists and the number of cells is unchanged, however, as other cells bear the labels of the original members of the cell set, the cell set is invalid. To resolve this problem, topoSet needs to be run after renumberMesh. This even works in parallel, when the case has been decomposed. 14.2 setsToZones The utility setsToZones serves the purpose to: Add pointZones/faceZones/cellZones to the mesh from similar named pointSets/faceSets/cellSets [24]. This utility is needed when we create some cellSets which we later want to use e.g. with a functionObject (the cellSource functionObject acts on all cells or on a cellZone ). cellSets can be created with topoSet. After we ran topoSet we simply run setsToZones without any further parameters or providing a dictionary. setsToZones creates cellZones which contain the same cells as the corresponding cellSets. 29 The location of the cell centre is not stored in any le, thus this quantity has to be computed. 30 This behaviour was reported in bug report 1377 (http://openfoam.org/mantisbt/view.php?id=1377). III ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 69 Execution time was reduced by renumberMesh from A simulation with a mesh consisting of 120000 cells dened by 9 blocks was run for with twoPhaseEulerFoam. refineMeshDict the rules for rening a particular cell set can be stated. ® ® 70 . in 1600 cells. resulting 6. then the command line option -dict has to be used. Even though the reduction of execution time is small in this examples. Renumbering the mesh can reduce computation times as it re-arranges the data to benet the numerical solution of the resulting equation system.4.18 s to 6.e. 14.1 General information The tool renumberMesh modies the arrangement of the cells of the mesh in order to create lower bandwidth for the numerical solution. This mesh consists of a single block and it is quasi 2D (i. If you are in doubt about this dierence.08 s. this can be done using the tool topoSet.cfd-online. testing is recommended. ESI-OpenCFD or the OpenFOAM Foundation.81 s 5s to of simulated time 9273. For further information about the role and the inuence of the bandwidth in numerical simulation see books on the numerical solution of large equation systems.3. The mesh resolution was chosen to 40 × 40 × 1. reneMesh to obey the rules set in the the command line option renumberMesh 14. Running renumberMesh takes little time and at run-time of the simulation no additional work has to be done.com/Forums/ openfoam-meshing-utilities/61518-blockmesh-cellset-refinemesh.14. The rened region is marked in red. III ® ® ® This oering is not approved or endorsed by ESI Group. it is only 1 block in depth). the producer of the OpenFOAM software and owner of the OpenFOAM trademark. See this useful post in the CFD-Online Forum http://www.html#post195725 Notice the dierent meaning of the -dict command line option of the tools topoSet and reneMesh. icoFoam was run for 10 s. this reduction comes at no cost.g. e. Renumbering the mesh even has an eect at the simplest possible simulation case the cavity case of the tutorials. 14. However. refineMeshDict .13 s.3 reneMesh The tool reneMesh is used just as the name suggests to rene a mesh.4 refineMeshDict For -dict has to used when calling reneMesh. check the summary of the command line usage printed by the -help option. [16].1 Usage First a cell set has to be dened. With the dictionary have been dened in When rules Figure 18: An example of a rened mesh. Execution time was reduced by renumberMesh from 9383.3. The benet of renumbering the mesh strongly depends on several factors. 14.2 Pitfall: no command line parameters If the tool reneMesh is called without any command line parameters then the whole mesh is rened. the upstream cell is not directly inuenced by the downstream cell. However. we can store the values of a scalar eld into a vector. ® ® 71 . j are adjacent. Figure 21 shows the corresponding matrix structure. An edge between the nodes matrix can be and j from represents the aji . 31 The upwind dierencing scheme causes the downstream cell to depend on the upstream cell. Why the order of execution of certain tools is signicant is explained in Section 14. we label all cells with positive ascending integers. III ® ® ® This oering is not approved or endorsed by ESI Group. A the interaction perspective non-zero elements aij and seen as a graph with N N ×N i nodes. most of the elements of If the cells with the labels i and we focus on the general structure of 31 . Since A we do not care whether aij equals aji . 14. Regardless of our computational mesh being one-. will be zero-entries.4.or three dimensional. as only adjacent cells interact. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. i. ESI-OpenCFD or the OpenFOAM Foundation. Consequently. or if both of them are actually non-zero The arrangement of the cells or. two. for sake of ease.3 on a case which went slightly wrong. The labelling scheme on the right hand side of Figures 19 and 20 results in a matrix with a lower bandwidth. However. then the elements aij and aji of A will be non-zero. the labelling has a strong impact on the structure of the matrix A. This is a consequence of our assumption that only adjacent cells interact. we limit ourselves in this discussion to direct neighbours. A A is of the size N × N. Ax = b The vector x contains the eld values at the cell centers. 0 1 2 3 0 2 4 6 4 5 6 7 1 3 5 7 Figure 19: A simple mesh with 8 cells and dierent cell labelling schemes. Figure 19 shows a simple mesh with 8 cells. 0 1 2 3 0 2 4 6 4 5 6 7 1 3 5 7 Figure 20: The connectivity graph of our mesh. Two dierent cell labelling schemes are indicated by the numbers inside the cells. The number of elements of this vector (N ) is equal to the number of cells in our domain.2 Background The discretized nite volume problem results in a linear equation system. (27) The matrix A contains non-zero elements for each pair of neighbouring cells.4. to be more precise.e. the distribution of the non-zero elements. In Figure 20 we see the connections between the cells depicted as a graph. A simple example Here we examine the eect of cell labelling with a very simple example. the matrix However. If we used some sort of higher order discretisation or interpolation. Thus. we might get into a situation where also second neighbours interact. which is usually expressed in matrixform.Run renumberMesh before any other tools which generate sets or zones. the cell with the label location (xA . zA ) before renumbering. however. The number of zero-entries is equal. The only actual geometric constant/polyMesh/points. the simulation worked nontheless and yielded some unexpected results.g. Pu and Pw dene a face. Notice the lower bandwidth of the matrix on the right hand side. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The same principle applys for the denition information is stored in the list of points in the le of cells. is the way OpenFOAM stores its mesh information. 32 Have a look on the injection tutorial of III twoPhaseEulerFoam -2. all cells within a certain geometrical region we simply store the cell labels of all cells for which the condition is fullled. A * denotes a non-zero element. A run of renumberMesh after the cellZone was on which source terms using the fvOptions mechanism act created caused the cellZone to get scrambled. however. No actual change is applied in the mesh.4. There. the dierent distribution leads to a dierent numerical behaviour.3. 14. This way. then the entry in constant/polyMesh/faces for this very face reads (k m u w).3 Pitfall: sets and zones will break my bones The use of renumberMesh carries a certain risk. In simulation cases which make use of tools like topoSet and renumberMesh. The faces are dened via the point labels of the points dening the mesh. the labels of the faces dening the cell are stored. Pm . we shue the cells A which was at the (xB .x. yA . ® ® ® This oering is not approved or endorsed by ESI Group. If we dene a cellSet with topoSet e. if we now run renumberMesh. However. ESI-OpenCFD or the OpenFOAM Foundation. Thus. no redundant information is stored. ® ® 72 . the order in which those tools are invoked is of importance. Thus. zB ) with B 6= A within the mesh. Figure 22 shows the simulation domain of an aerated stirred tank. yB . if the points Pk .0 1 2 3 4 5 6 7 0 ∗ ∗ 0 0 ∗ ∗ 0 0 1 2 3 4 5 6 7 ∗ 0 0 ∗ ∗ 0 0 ∗ ∗ 0 ∗ ∗ ∗ 0 ∗ ∗ ∗ 0 ∗ ∗ ∗ 0 ∗ ∗ 0 0 ∗ ∗ ∗ 0 0 ∗ ∗ 0 0 ∗ ∗ 0 ∗ ∗ ∗ 0 ∗ ∗ ∗ 0 ∗ ∗ ∗ 0 ∗ ∗ 0 0 ∗ ∗ 0 1 2 3 4 5 6 7 0 ∗ ∗ ∗ ∗ 0 0 0 0 1 ∗ ∗ ∗ ∗ 0 0 0 0 2 ∗ ∗ ∗ ∗ ∗ ∗ 0 0 3 4 ∗ 0 ∗ 0 ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ 0 ∗ 0 ∗ 5 6 0 0 0 0 ∗ 0 ∗ 0 ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ 7 0 0 0 0 ∗ ∗ ∗ ∗ Figure 21: The matrix structure. The red cells are part of a cellZone 32 . The reason behind this. may or most certainly will be at location after renumbering. there are some tools to provide help. o r g | | \\/ M anipulation | | \*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ FoamFile { version 2. ESI-OpenCFD or the OpenFOAM Foundation.3. After decomposing the domain. If a non-uniform initialisation is desired. III ® ® ® This oering is not approved or endorsed by ESI Group.OpenFOAM.6 createPatch 14.1 Basics There are two ways to dene the initial value of a eld quantity.7 stitchMesh 14. format ascii . Entering such a nonuniform list by hand would be very tiresome. although not on their original location. object U. subsetMesh 14. Left: The cut-away of the walls of a stirred tank with the rotor (blue) and the aeration device The aeration device is a cellZone on which source terms are applied via the fvOptions mechanism in OpenFOAM-2. } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [ 0 1 −1 0 0 0 0 ] .25 s into the simulation.x | | \\ / A nd | Web : www. The transparent iso-volume shows the gas-phase volume fraction 0. a parallel renumbering of the mesh was conducted. ® ® 73 . /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*− C++ −*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*\ | ========= | | | \\ / F ield | OpenFOAM: The Open S o u r c e CFD Toolbox | | \\ / O peration | Version : 2. Listing 118 shows the 0/U le of the cavity tutorial. To spare the user of such a painful and exhausting task. Renumbering the subdomains scrambled the cellZone within their respective subdomains. Listing 125 shows some lines of such a denition. The rst is to set the eld to a uniform value. Right: The stirred tank was simulated using parallel processes.Figure 22: (red).1. class volVectorField . The cells of the cellZone act as source for the gas-phase.0.5 15 Initialize Fields 15. then a list of values for all cells is needed instead. There the internal eld is set to a uniform value. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.x. setFields reads this denitions from a le in the system -directory the setFieldsDict. } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // defaultFieldValues ( v o l S c a l a r F i e l d V a l u e alpha1 1 ). // ************************************************************************* // 33 Only the le III neighbour can be missing for setFields not to crash.2 0/U of the cavity tutorial setFields setFields is a utility that allows to dene geometrical regions within the domain and to assign eld values to those regions. boundaryField { movingWall { type value } fixedValue . setFields needs to read all les dening the mesh In Listing 119 a box is dened in which the eld alpha1 is set to a dierent value. ® ® 74 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.1. ESI-OpenCFD or the OpenFOAM Foundation. } ).internalField uniform ( 0 0 0 ) .3 0 ) ( 0 . class dictionary . format ascii . regions ( boxToCell { box ( − 0. uniform ( 0 0 0 ) .0. } // ************************************************************************* // Listing 118: The le 15. 3 0 . frontAndBack { type } empty .OpenFOAM. fieldValues ( v o l S c a l a r F i e l d V a l u e alpha1 0 ).3 − 0.x | | \\ / A nd | Web : www. To initialize the eld quantities 33 . 2 6 ) . fixedWalls { type value } fixedValue . object setFieldsDict . 3 0 . /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*− C++ −*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*\ | ========= | | | \\ / F ield | OpenFOAM: The Open S o u r c e CFD Toolbox | | \\ / O peration | Version : 2. uniform ( 1 0 0 ) . ® ® ® This oering is not approved or endorsed by ESI Group. o r g | | \\/ M anipulation | | \*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ FoamFile { version 2. setFields has to be executed after creating the mesh. convertToMeters 1 e − 3.Listing 119: setFieldsDict Pitfall: Geometric region is not part of the domain If the geometric region.1. vertices ( (0 (50 (50 (0 (0 (50 (50 (0 ). 0 0 . the dictionary contained a denition for the eld alpha which was not present in the 0 -directory. is too large by the factor of 1000. Therefore. Setting f i e l d default values −−> FOAM Warning : From f u n c t i o n v o i d s e t C e l l F i e l d T y p e ( c o n s t fvMesh& mesh . } fieldValues ( v o l S c a l a r F i e l d V a l u e alpha1 0 ). based on the vertex coordinates in millimeters. The denition of the box in the setFieldsDict relies solely on the vertex coordinates ignoring the scaling factor convertToMeters resulting in a way too large box. In this case the le setFieldsDict was copied from a case which uses the old naming scheme of twoPhaseEulerFoam. 0 5 0 . 0 ) ( 5 0 . ). that the geometric region. I s t r e a m& f i e l d V a l u e S t r e a m ) III ® ® ® This oering is not approved or endorsed by ESI Group. See Section 33. The plan is to create a box and initialise it in a way.1 for further information about the naming scheme. When the vertex coordinates are entered in millimeters and convertToMeters is set appropiately then it may happen. setFields does not issue any warning or error message. lies outside the domain. ® ® 75 . Pitfall: Geometric region covers the whole domain This may happen if the geometric region is dened with respect to the vertex coordinates found in blockMeshDict. Listing 121: setFieldsDict entry for a box of 50 × 50 × 125 m Pitfall: Field not found If the setFieldsDict species a eld which is not present. then OpenFOAM issues an error message similar to Listing 122. After executing setFields the domain is completely lled with one phase instead of half lled. 0 ) . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 0 0 0 0 50 50 50 50 0) 0) 250) 250) 0) 0) 250) 250) Listing 120: blockMeshDict entry for a box of 50 × 50 × 250 mm regions ( boxToCell { box ( 0 . Listing 120 and 121 show the root of such a situation. c o n s t l a b e l L i s t& s e l e c t e d C e l l s . that the domain is half lled with one phase. 0 0 . in which to initialise a eld with a specied value. i. 0 1 2 5 . ESI-OpenCFD or the OpenFOAM Foundation. alpha instead of alpha1.e. From f u n c t i o n o p e r a t o r >>(I s t r e a m &.i n f i l e s e t F i e l d s .3 mapFields mapFields is a utility to transfer eld data from a source mesh to target mesh. This may be useful after the mesh of case has been rened and existing solution data is to be used for initialising the case with the rened mesh. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. III ® ® ® This oering is not approved or endorsed by ESI Group. FOAM e x i t i n g Listing 122: Missing eld 15. ® ® 76 . S o u r c e time : 0 .C a t l i n e 103 F i e l d a l p h a not found −−> FOAM FATAL IO ERROR: wrong token type − e x p e c t e d word . mapFields expects as the only mandatory argument the path to the source case. 1 . With lines like interpolating alpha mapFields indicates that it is processing some eld data. S o u r c e time : 0 . Even when source and target meshes are equal and no interpolation is needed. if the source data was stored in binary format. mapFields preserves the format of the data. 3 2 5 Target time : 0 C r e a t e meshes 34 In the most basic case mapFieldsDict contains no other information than the header and empty denitions.C a t l i n e 7 4 . word&) i n f i l e p r i m i t i v e s / s t r i n g s /word/wordIO . the target data will also be binary. 3 2 5 interpolating interpolating interpolating interpolating interpolating interpolating interpolating alpha p k epsilon Theta Ub Ua End Listing 123: Output of mapFields 15.1 Pitfall: Missing les mapFields issues no warning or error message when the source case contains no data. To use mapFields the le mapFieldsDict has to be existent in the system folder of the case 34 . mapFields displays lines like interpolating alpha anyway. Listing 123 shows the last lines of output of mapFields. Although this le may seem of no use. The current directory is assumed to be the case directory of the target case. 3 2 5 Target time : 0 C r e a t e meshes S o u r c e mesh s i z e : 81000 Target mesh s i z e : 273375 Mapping f i e l d s f o r time 0 . the latest time steps of both cases are processes. and it has to contain the header and the empty denitions. found on l i n e 19 t h e l a b e l 1 f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 . That means the latest time step of the source case is mapped to the latest time step of the target case. If there is no specication regarding time. ESI-OpenCFD or the OpenFOAM Foundation. Only the missing lines containing statements like interpolating alpha indicate that something is amiss and no eld data is processed.3. Listing 124 shows the output of mapFields as the target case contained no 0 -directory. x/ run / twoPhaseEulerFoam / bubbleColumn / system / s e t F i e l d s D i c t : : d e f a u l t F i e l d V a l u e s at l i n e 19. it has to exist in the system folder. mapFields will exit with an error message like in Listing 126.000143648 0 ) ( − 0. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. This list is preceded by the number of entries as well as the nature of the value. The target case should always be set up with uniform elds to avoid such errors. x/ run / twoPhaseEulerFoam / Case /0/ a l p h a from l i n e 18 t o l i n e 39. 0 0 0 1 7 4 2 9 1 − 0.00182755 0 . Inhomogeneous eld values have to be entered as a list of values. Missing target 0 -directory 15. 1 .3. ESI-OpenCFD or the OpenFOAM Foundation. mapping the data would make no sense.org le extension can be found. c o n s t l a b e l ) i n f i l e /home/ u s e r /OpenFOAM/OpenFOAM− 2 .S o u r c e mesh s i z e : 81000 Target mesh s i z e : 273375 Mapping f i e l d s f o r time 0 . the source case's data will always be stored as a nonuniform list. 0 0 0 1 7 1 0 2 2 − 0. FOAM e x i t i n g Listing 126: Error message of mapFields . 0 0 0 3 0 5 7 7 2 0 ) ( − 0. x/ s r c /OpenFOAM/ l n I n c l u d e / F i e l d . A wrong value of COUNT leads to reading errors.2 Pitfall: Unsuitable les In the les containing the eld data the values of the boundary elds as well as the values of the internal elds can be entered homogeneously (by the keyword uniform) or inhomogeneously (with the keyword nonuniform). ® ® 77 . internalField nonuniform L i s t <v e c t o r > 1600 ( ( 0 . 3 2 5 End Listing 124: Output of mapFields . If data is to be mapped from a source case. If the data of the target case is nonuniform for whatever reason then it is necessary that the nonuniform lists have the same length.000259297 0 . This is most easily done by removing the denition of the internal eld. Otherwise. 0 0 0 3 7 4 9 3 7 0 ) ( − 0. From f u n c t i o n F i e l d <Type > : : F i e l d ( c o n s t word& keyword . as uniform elds are most easily dened. dimensions [ 0 1 −1 0 0 0 0 ] . 3 2 5 i n t e r p o l a t i n g alpha −−> FOAM FATAL IO ERROR: s i z e 81000 i s not e q u a l t o t h e g i v e n v a l u e o f 10125 f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 .000171512 0 ) ( 0 . The general syntax for such a list is the following: nonuniform List<TYPE> COUNT ( VALUES ) the list.C a t l i n e 2 3 6 . c o n s t d i c t i o n a r y &. This is a way to preserve the uniform eld data in the 0 -directory without causing any trouble. 1 . unequal number of values III ® ® ® This oering is not approved or endorsed by ESI Group. Otherwise.000380671 0 . Listing 125 shows the beginning lines of the denition of a nonuniform vector eld. 0 0 0 9 3 0 7 0 1 0 ) Listing 125: An inhomogeneous internal eld denition in the le 0/U Mapping f i e l d s f o r time 0 . then mapping makes no problems. If the data of the target case is uniform. In the tutorials sometimes les with an . } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // patchMap ( ). ® ® 78 . A 2D mesh that has the same depth as the 3D mesh but is discretised with only 1 cell in depth will have a very bad aspect ratio. redene the 3D domain to its intended size. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. We have nished a simulation on a 2D mesh. Note the dierent dimension in y -direction. Now we want to transfer the 2D data to a 3D mesh to initialise the 3D simulation.x | | \\ / A nd | Web : www. class dictionary . With the tool transformPoints the mesh can be scaled selectively in the three dimensions of space. the 2D mesh has the dimensions 20 cm × 2 cm × 45 cm and the 3D mesh is 20 cm × 5 cm × 45 cm big. After this ® This oering is not approved or endorsed by ESI Group. The geometry of the 2D case is 20 cm × 2 cm × 45 cm.OpenFOAM.5. if the 2D is already nished./*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*− C++ −*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*\ | ========= | | | \\ / F ield | OpenFOAM: The Open S o u r c e CFD Toolbox | | \\ / O peration | Version : 2. Because of the great Listing 127 shows the similarity of the geometry. The part of the 3D domain that lies outside the 2D domain remains unchanged. ESI-OpenCFD or the OpenFOAM Foundation. In our example.3. This behaviour is not satisfactory.0. The geometry of the 3D simulation is 20 cm × 5 cm × 45 cm. no entries are necessary. The problem Figure 23 shows the result of the mapFields run. mapFieldsDict that was used.3. format ascii . cuttingPatches ( ). // ************************************************************************* // Listing 127: The le mapFieldsDict 15. object mapFieldsDict .3 Pitfall: Mapping data from a 2D to a 3D mesh In this section we deal with some diculties of the mapFields utility. 128 shows how transformPoints can be used to scale the 2D mesh in scaling operation the 2D mesh has the desired dimensions of III ® ® factor of 2. without changing the total number of cells 15. A more elegant solution is to transform the mesh after the 2D simulation has nished. The work-around One way to solve this problem would be to choose the 2D domain of a similar size as the 3D domain. Listing y -direction by the 20 cm × 5 cm × 45 cm. dene the 3D domain to be of the same size as the 2D domain 2. However. Only the eld values inside the 2D domain were altered. map the elds 3. location " system " . Another solution is: 1. o r g | | \\/ M anipulation | | \*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ FoamFile { version 2.1.4 The work-around: Mapping data from a 2D to a 3D mesh The work-around to the problem of the previous section is rather unelegant. then it would take some time to re-simulate the case with a redened geometry. this can be done easily only by changing some numbers in the le blockMeshDict. the boundary conditions need to be dened in a suitable ascii le. Therefore. The single blocks of the mesh can be distinguished from the gures. and U1 elds of the new Due to a change in the numbering of the cells.5 1.6 Pitfall: binary les If the source case has binary data les. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. After the user changed the coordinates of some points. after reducing the time step. 15. the alpha simulation proceeded without any further errors.m4.5 for a discussion on creating a parametric mesh. the formerly smooth elds are now completely distorted. III ® ® ® This oering is not approved or endorsed by ESI Group. Because the number of cells did not change.Figure 23: The mapped eld transformPoints −s c a l e '(1. Figure 24 shows the initial simulation. Starting the simulation resulted in a oating point exception. that OpenFOAM numbers the cells block-wise. Editing a binary le with a text editor may render this le defective. the data les from the nished simulation t the new one. The user simply copies the necessary les from the latest time step of the nished simulation to the initial time step of the new simulation. A simulation of the bubble column has been made. See Section 11.0) ' Listing 128: Scaling the 2D mesh in y -direction with transformPoints After the mesh transformation the utility mapFields can be used to map the eld from the scaled 2D mesh to the 3D mesh.5 The importance of mapping The purpose of this example is to highlight the need for the mapFields utility. Then. meshing yields a new mesh with the same number of cells as the old mesh had. the elds can be mapped.3.3. ® ® 79 . However.0 2. the user decides to change the size of the inlet patch. then the boundary conditions need to be dened before mapping the elds. This indicates. Thanks to the parametric mesh. ESI-OpenCFD or the OpenFOAM Foundation. Now. 15. ). In this changeDictionary provides a neat way to change boundary values. Well.1 changeDictionary The utility changeDictionary can be used to modify a dictionary. using a text editor might not be an option anymore. Listing 129 shows a simple example of the dictionaryReplacement { U { boundaryField { inlet { type } } } } value changeDictionaryDict. This reduced inow and continue afterwards with full inow approach might improve the stability of the simulation.Figure 24: The unmapped elds 16 Case manipulation This section contains a discussion on tools for the manipulation of the simulation case which to not create or modify the mesh or are used for initialisation.g. vim. Editing ascii les which measure in the megabytes can be very tiresome with some text editors. 16. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. A possible scenario in which changeDictionary comes in handy is when we do spin-up simulations. III ® ® ® This oering is not approved or endorsed by ESI Group. i. except those residing in system. We can of course manipulate any of our dictionaries using a simple text editor. run the simulation for a certain time with e. even from the command line (emacs. Another case in which changeDictionary proofes to be quite important is when we want to change boundary value of elds we have gained from a previous simulation. etc. nano. ® ® 80 . Utilities for the before mentioned tasks are already disussed in previous sections.e. uniform ( 2 0 0 0 ) . If the les are stored in binary. fixedValue . ESI-OpenCFD or the OpenFOAM Foundation. we can't have everything. Listing 129: A simple changeDictionaryDict used to change an inlet velocity 35 In such a scenario we also would need to manipulate controlDict to increase the endTime. 35 . pimpleFoam02 # −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− end−of − f i l e Listing 130: The The le Allrun script of a spin-up simulation Allrun script was applied to a slightly modied pitzDaily tutorial case. However. This is the step in which. runApplication does not run the specied application. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. This simulation is intended to run without user intervention once the simulation is started. In Line 14 the log-le generated by runApplication is renamed (moving a le within a directory is essentially runApplication checks if there is already a log present. In Line 16 we use the GNU tool sed to edit controlDict37 . This is not necessary in priciple.1. otherwise the tutorial is untouched. execution waits for the command of the current line to nish until the next command is invoked. 36 Such a simple kind of thing could also be achieved with time-dependent boundary conditions. or we want to do something nastier. In Line 15 changeDictionary is called. pimpleFoamRun01 runApplication changeDictionary sed − i ' s /endTime 20/ endTime 40/ g ' system / c o n t r o l D i c t # Run t h e s o l v e r a g a i n r u n A p p l i c a t i o n pimpleFoam mv l o g . Thus. The increased inlet velocity is displayed as well as the established ow from the initial run with an inlet velocity of (10 0 0). pimpleFoam l o g . Here it is crucial that the keyword startAt is set to In Line 20 we apply the same renaming to the solver-log of the second run. In Line 19 we call the solver for the second time. 16. as controlDict will never reach megabytes or be stored in binary format. latestTime in controlDict. However. then a consistent naming scheme might be very helpful. By adding the command line option -constant the dictionaries of the constant folder can be edited. Figure 25 shows the ow eld after changeDictionary was called.1 A spin-up simulation In this section we discuss what is termed a spin-up simulation in this manual. After the ow is established we increase the inow to the desired value. punching the quiescent uid in the domain with full force at the inlet Listing 130 shows the Allrun script for such a kind of simulation. there are solvers which do not support time-variant boundary conditions. 37 We could also do the edit manually with any text editor. Since none of the lines in the script is terminated by the ampersand (&). Thus. the whole idea of the spin-up simulation idea is to avoid manual intervention. if we are to perform to automated processing of the logs. the build-up of the ow within the domain happens in a gentler manner. the ow establishes within the domain in a much gentler regime. A appropriate changeDictionaryDict Listing 129 was added to the system directory. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #! / b i n / sh cd ${0%/*} | | exit 1 # run from t h i s d i r e c t o r y # S o u r c e t u t o r i a l run f u n c t i o n s . we save to assume all commands are run in the stated order. In this case we assume we have set up a simulation with a reduced inow. we avoid 36 . however. Thus. Again. $WM_PROJECT_DIR/ b i n / t o o l s / RunFunctions # C r e a t e t h e mesh u s i n g blockMesh r u n A p p l i c a t i o n blockMesh # Run t h e s o l v e r r u n A p p l i c a t i o n pimpleFoam # p r e p a r e s e c o n d run mv l o g . ESI-OpenCFD or the OpenFOAM Foundation. The reason for this operation is. as there is already a slower ow present through out the domain. ® ® 81 . If renaming). that there is. pimpleFoam l o g . In Line 11 the solver is run for the rst time. we increase the inlet velocity. III ® ® ® This oering is not approved or endorsed by ESI Group.By default changeDictionary operates only on dictionaries living in the time step directories. which can't be achieved with time-variant bounary conditions. in our example. Figure 25: The established ow eld and the increased inlet boundary condition of the pitzDaily tutorial case at III t = 1s ® ® ® This oering is not approved or endorsed by ESI Group. ® ® 82 . ESI-OpenCFD or the OpenFOAM Foundation. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The exact turbulence RASProperties. This le must contain all necessary parameters. ® ® 83 .1. Listing 131: turbulenceProperties 17. ESI-OpenCFD or the OpenFOAM Foundation. In this case a k- model is used and no further parameters The entry in the le model is specied in the le are necessary. 17. Listing 132 shows the content of RASProperties. The banana test (see Section 7.2 RAS-Models turbulenceProperties species only the class of turbulence models.1 Categories The desired category of turbulence models can be specied in the le turbulenceProperties. −−> FOAM FATAL ERROR: Unknown RASModel type banana V a l i d RASModel t y p e s : 17 ( LRR LamBremhorstKE LaunderGibsonRSTM LaunderSharmaKE LienCubicKE LienCubicKELowRe LienLeschzinerLowRe NonlinearKEShih RNGkEpsilon SpalartAllmaras kEpsilon kOmega kOmegaSST IV ® ® ® This oering is not approved or endorsed by ESI Group.Part IV Modelling 17 Turbulence-Models 17. RASModel turbulence printCoeffs kEpsilon . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. In case of a large eddy simulation. on .2. turbulenceProperties simulationType contains only one entry. this entry reads: LESModel . Listing 132: RASProperties Depending on the exact model more parameters can be necessary. There are three possible entries. At this place laminar can also be chosen. laminar The ow is modelled laminar RASModel LESModel The le A Reynolds averaged turbulence model (RAS-model) is used. on .1) delivers a list of available models. Turbulence is modelled by a large-eddy model.1 Keywords RASModel The name of the turbulence model. 8 1 5 . then a laminar simulation is conducted. // O r i g i n a l v a l u e : 1 . then the solver will display the coecients of the selected turbulence model.4. Allowed values are: on/o.33. 1 .2. there is no check whether the dened constants in the dictionary make sense or not.1. − 0.2 Pitfall: meaningless Parameters In the above section it was shown how to override default values of the model constants. This is not an actual error. // O r i g i n a l v a l u e : 1 . kEpsilonCoeffs dictionary of the le RASProperties. kEpsilonCoeffs dictionary. This dictionary is used to override If nonsensical parameters are added to the Listing 135 shows the default values of the model constants.44.44. Even if the switch turbulence is disabled. In this procedure. true/false or yes/no. 1 1 . the solver will display the coecients at the beginning of the simulation. Varying this parameter yields no results. 4 4 0 .09. ® ® 84 .92. 1. 4 4 Listing 134: Denition of model parameters in RASProperties 17.0.92. 1. Listing 136 shows parts of the solver output. It seems as if the constant banana is part of the turbulence model. All constants of the dictionary are read and printed again. The reason for this behaviour is. which is no error. A fake model constant has been added to this dictionary. 1. when this dictionary is used in a simulation. but it can lead to a fruitless search for an error. 1. 1. IV ® ® ® This oering is not approved or endorsed by ESI Group. Some models accept optional parameters to override the default values of the model. 1 . The coecients are not displayed only when optional parameters RASModel laminar is chosen. 1 1 . see Listing 140. printCoes If this switch is enabled. kEpsilonCoeffs { Cmu C1 C2 C3 sigmak sigmaEps banana } 0.) kkLOmega laminar qZeta realizableKE Listing 133: Possible RAS-model entries in RASProperties turbulence This is a switch to activate or deactivate the turbulence modelling.09.09. there is one source of error hidden. these will be read and also printed. see Section 17. ESI-OpenCFD or the OpenFOAM Foundation. kEpsilonCoeffs { Cmu C1 C2 C3 sigmak sigmaEps } 0. This way of choosing a laminar model is not recommended. − 0. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Listing 134 shows how the coecients of the k- model can be overridden. If this switch is deactivated.33.0. // n o n s e n s e parameter Listing 135: Denition of model parameters in RASProperties S e l e c t i n g RAS t u r b u l e n c e model k E p s i l o n kEpsilonCoeffs { Cmu 0. 1. These models add one further equation to the problem.2 Algebraic sub-grid models Algebraic sub-grid models introduce no further transport equation to the simulation.33.1 Keywords The keywords turbulence and printCoeffs have the same meaning with LES models. ® ® 85 . IV ® ® ® This oering is not approved or endorsed by ESI Group. The model dynamicSmagorinsky was loaded from an external library. ESI-OpenCFD or the OpenFOAM Foundation. See Section 7. The way how CS CS from known quantities instead of prescribing a is calculated is determined by the sub-grid model. Usually. 1.1. There is also the possibility depending on the selected model of dening optional parameters. − 0. 1. −−> FOAM FATAL ERROR: Unknown LESModel type banana V a l i d LESModel t y p e s : 16 ( ) DeardorffDiffStress LRRDiffStress Smagorinsky SpalartAllmaras SpalartAllmarasDDES SpalartAllmarasIDDES dynLagrangian dynOneEqEddy dynamicSmagorinsky homogeneousDynOneEqEddy homogeneousDynSmagorinsky kOmegaSSTSAS laminar mixedSmagorinsky oneEqEddy spectEddyVisc Listing 137: Possible LES-model entries in LESProperties 17.92. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.4 One equation models A further class of LES turbulence models are one equation models. At this place laminar can also be chosen.0.11. The turbulent viscosity is calculated from existing quantities.3 Dynamic sub-grid models The dynamic sub-grid models calculate the model constant xed value.1) delivers a list of available models. Listing 137 shows the result of such a banana test. an additional equation for the sub-grid scale turbulent kinetic energy is solved. 17. 17. 1.3.2.3 LES-Models 17.44.3. LESModel The name of the turbulence model. S t a r t i n g time l o o p Listing 136: Solver output 17.815.} C1 C2 C3 sigmak sigmaEps banana 1.3.3 for how to include external libraries. The banana test (see Section 7. 0.3. 4 Pitfalls 17. selects the laminar RAS turbulence model. see Figure 45. simulationType laminar RASProperties: RASModel laminar LESProperties: LESModel laminar In this case.09. This dummy turbulence model is derived from the base class RASModel RASModel laminar but it implements a laminar model. However. the user should use the parameter perform a laminar calculation. The generic turbulence class can take the form of the class. However. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. This may also lead to confusion. In both cases the simulation is laminar. ® ® 86 . See Figure 46. simulationType printCoeffs prints the model constants of the turbulence off is chosen to conduct a model. C2 1.44. This is the most general way to turn turbulence modelling o. dierent ways to conduct a laminar simulation are listed. In the following. a certain turbulence modelling strategy is chosen (RASModel or LESModel). turbulenceProperties: simulationType laminar turbulenceProperties controls the generic laminar. there is the test whether turbulence modelling is active or not.g. S e l e c t i n g t u r b u l e n c e model type RASModel S e l e c t i n g RAS t u r b u l e n c e model l a m i n a r Listing 139: Solver output for 3.1 Laminar Simulation As already mentioned see Section 17. when e. When the calculation is started. IV ® ® ® This oering is not approved or endorsed by ESI Group. This is controlled by the parameter S e l e c t i n g t u r b u l e n c e model type l a m i n a r Listing 138: Solver output for 2.2 turbulence modelling can be deactivated in a some ways. RASModel laminar RASProperties: turbulence off The switch turbulence can be used to enable or disable turbulence modelling.17. This list applys only to solvers that utilize the generic turbulence modelling of OpenFOAM: 1.92. In order to avoid this source of confusion.4. sigmaEps 1. the turbulence model specied is used. In this point RASModel and LESModel behave similar. See Listings 139 and 140. C1 1. Independent from all other settings. in the source code of the solver. there is no rule without its exceptions. ESI-OpenCFD or the OpenFOAM Foundation. turbulence class.3. } Listing 140: Solver output for turbulence off Solver output The last two prossibilities to conduct a laminar simulation can lead to confusion because the solver output contains word like RASmodel or RAS turbulence model. However. to selected turbulence laminar simulation. S e l e c t i n g t u r b u l e n c e model type RASModel S e l e c t i n g RAS t u r b u l e n c e model k E p s i l o n kEpsilonCoeffs { Cmu 0. See Listing 155. Therefore. there is a dummy turbulence model for laminar simulation. RASModel or LESModel simulationType. Exceptions The above explanation only applies to solvers that utilize the generic turbulence models of OpenFOAM. Otherwise there would be the need for all possible les (0/k.simpleFoam This solver uses only RAS turbulence models. there may be the need for additional les in the 0 -directory.) to be present in any case. For this reason.4 Initial and boundary conditions All turbulence models can be divided into classes depending on their mathematical properties. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. which would be utter madness. 0/omega. The only choice the user of twoPhaseEulerFoam has is whether to enable or disable the k- turbulence model.B.1. Therefore. etc. The eddy viscosity is computed from these additional quantities (z. If a simulation is started and the solver is missing les i. twoPhaseEulerFoam This solver has the k- turbulence model hardcoded. From f u n c t i o n r e g I O o b j e c t : : readStream ( ) i n f i l e db/ r e g I O o b j e c t / r e g I O o b j e c t R e a d . Solvers which use the generic turbulence modelling oer three possible ways to disable turbulence modelling. C a t l i n e 7 3 . 17. FOAM e x i t i n g IV ® ® ® This oering is not approved or endorsed by ESI Group. S e l e c t i n g t u r b u l e n c e model type RASModel S e l e c t i n g RAS t u r b u l e n c e model k E p s i l o n −−> FOAM FATAL IO ERROR: cannot f i n d f i l e f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 .e. This le can savely be deleted. The eddy viscosity is computed from this additional quantity (e.g. 17.4. k-ω ) Every eld quantity of a turbulence model needs its initial and boundary conditions.g. Only item 3 of the list above applies to this solver. 0/k or The solver read this les regardless of the fact. ® ® 87 .4. the use of the k- turbulence model is hardcoded. k-. 17. The turbulent viscosity is com- puted from known quantities using an algebraic equation (e. then the presence of the les like 0/epsilon is mandatory.4. This entry is only read if the generic turbulence modelling is used and if there is any choice of which RAS-model to use. 1 . that a laminar simulation is conducted. the Baldwin-Lomax model) One equation models These models introduce an additional transport equation to the problem.3 Laminar simulation with twoPhaseEulerFoam If twoPhaseEulerFoam is used and a laminar simulation is conducted. The This switch is the only way to decide whether to use turbulence modelling or not with twoPhaseEulerFoam. a case may be found which utilises the needed turbulence model. the le constant/turbulenceProperties is not needed any more. Algebraic models These models add an algebraic equation to the problem. One way to nd out which les are needed is to look at the tutorials. Other solvers read this les based on the condition if and which turbulence model is used. the Spalart-Allmaras model) Two equation models These models introduce two additional transport equations to the problem. See Section 17.2 for a detailled discussion. bubbleFoam The same as twoPhaseEulerFoam. ESI-OpenCFD or the OpenFOAM Foundation. the solver tries to read les which are not present then OpenFOAM will issue a corresponding error message. see Section 17.4. Another consequence of the k- turbulence model being hardcoded into twoPhaseEulerFoam is that the keyword turbulenceProperties in the le RASproperties is also not needed any more. Listing 141 shows an error message of a case with a missing 0/k le.2 Turbulence models in twoPhaseEulerFoam In the solver twoPhaseEulerFoam. Items 2 and 3 of the list above apply.4. x/ run / pisoFoam / c a v i t y /0/ k a t l i n e 0 . This is due to the fact that the use of the k- model is hardcoded into twoPhaseEulerFoam. the entries of the le turbulenceProperties are redundant and the only ways to control turbulence modelling are items 2 and 3 of the list above. Consequently. There. This means that the solver does not use the generic turbulence modelling ususally used by OpenFOAMs solvers. 0/epsilon. multiphaseEulerFoam This solver only uses LES turbulence models. only mandatory keyword in RASproperties is the switch turbulence. is created by the solver. the aim of all RAS turbulence models is to calculate the turbulent viscosity. the 0 -directory contains more les. Listing 142 shows the folder contents before and after a simulation with pisoFoam. nut. However.e. the rule one additional transport equation entails one additional data le is not violated.6 Spalart-Allmaras The Spalart-Allmaras is a one-equation turbulence model. o l d nut p U user@ host : ~ /OpenFOAM/ u s e r − 2 . The reason for creating the is not known. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 1 . ESI-OpenCFD or the OpenFOAM Foundation.5/ Listing 142: Folder contents at the begin and the end of a simulation The 0 -directories of some tutorial cases may already contain such additional les.4. 1 . in this case pressure and velocity as well as the turbulent quantities k and After the simulation has nished. Because the viscosity is not constant it has to be dened in a le in the 0 -directory. 5 1 c o n s t a n t system user@ host : ~ /OpenFOAM/ u s e r − 2 . certain quantities. The case has not been run. x/ run / pisoFoam / r a s / c a v i t y $ e p s i l o n e p s i l o n . None of these two les is necessary to run the case with the k- turbulence model. The turbulent viscosity itself is a eld quantity. user@ host : ~ /OpenFOAM/ u s e r − 2 . In some cases the 0-directory may also contain several of such les due to a change in the naming scheme. Listing 143 shows the contents of the 0 -directory of the pitzDaily tutorial case of simpleFoam. Listing 144 shows the content of the 0 -folder of the airFoil2D tutorial case of simpleFoam.Listing 141: Solver error message: missing le 17. Therefore. x/ run / pisoFoam / r a s / c a v i t y $ e p s i l o n k nut p p h i U uniform user@ host : ~ /OpenFOAM/ u s e r − 2 . And. Although it introduces only one additional equation to the problem it needs two additional les in the 0-directory. However. x/ run / pisoFoam / r a s / c a v i t y $ ls l s 0/ pisoFoam > / dev / n u l l ls l s 0/ l s 0.4. nut nuTilda p U Listing 144: The content of the 0 -directory of the airFoil2D tutorial case of simpleFoam 18 Boundary conditions When the geometry of a problem is meshed. epsilon k nut nuTilda p U Listing 143: The content of the 0 -directory of the pitzDaily tutorial case of simpleFoam 17. x/ run / pisoFoam / r a s / c a v i t y $ epsilon k p U user@ host : ~ /OpenFOAM/ u s e r − 2 . IV ® ® ® This oering is not approved or endorsed by ESI Group. x/ run / pisoFoam / r a s / c a v i t y $ 0 c o n s t a n t system user@ host : ~ /OpenFOAM/ u s e r − 2 . then the boundary patches i. so the les nut and nuTilda have not been generated by the solver. because the viscosity is not the transported quantity of the Spalart-Allmaras model another le is added to the 0 -directory.1 the possible types are discussed. The former contains the turbulent viscosity and the latter contains the transported quantity of the turbulence model. x/ run / pisoFoam / r a s / c a v i t y $ 0 0 . 1 . the turbulence model created the le phi The le as well as the folder uniform nut .old les for storing the turbulent viscosity. The 0 -directory contains only the mandatory les.g. Every boundary patch is of a certain type.5 Additional les RAS turbulence models produce additional les. The les nut and nuTilda are both necessary to run the case. *. x/ run / pisoFoam / r a s / c a v i t y $ user@ host : ~ /OpenFOAM/ u s e r − 2 . In Section 18. Most RAS models calculate the turbulent viscositiy from These quantities are usually eld quantities and depend on the used turbulence model. 1 . 1 . ® ® 88 . o l d k k . e. the faces delimiting the geometry need to be specied. 1 . 1 . g. symmetry plane If a problem is symmetric.2 Complex boundaries Some kinds of boundary patches are more than just a geometric boundary of the domain. processor A boundary between sub-domains created during the domain decomposition is of type processor. The boundary conditions of this type can be used to model more complex situations. E. then a zeroGradient boundary condition is applied.1. if none of the following types applies. Listing 146: IV inletOutlet ® boundary condition ® ® This oering is not approved or endorsed by ESI Group. xedGradient zeroGradient type value The gradient of a quantity is prescribed directly. This type is mandatory for using wall models when modelling turbulence.1. then the problem can be simplied. on a wall. If the ow is directed outwards. fixedValue . wall This is a special type for walls. ESI-OpenCFD or the OpenFOAM Foundation. The additional boundaries are of type wedge. The value keyword has to be present. The boundaries that are parallel to the considered plane must be of the type empty to cause the simulation to be two-dimensional. therefore there is need for further modelling. cyclic Cyclic boundary.3 fixedValue boundary condition Derived types The boundary condition of the derived types are derived from the boundary conditions of the primitive types. uniform ( 0 0 0 ) . 18. then the mesh must be one cell in thickness.Base types 18. If a two-dimensional simulation needs to be conducted. These boundaries can have boundary conditions of the primitive or derived types. type inletValue value inletOutlet . then a xed value is prescribed. uniform ( 0 0 0 ) . wedge If a geometry is axisymmetric. In this case. Listing 145: 18. the no-slip condition usually applies. The value of the inowing quantity is provided by the inletvalue keyword. If the ow is inwards.3. patch This is the generic type for all boundaries.1 Geometric boundaries Some kinds of boundary patches can be described purely geometrically. 18. only a part of the geometry a wedge is modelled. empty OpenFOAM creates always three-dimensional meshes. A boundary is of this type. 18. then only half of the domain needs to be modelled.2 Primitive types The most important primitive type boundary conditions are: xedValue The value of a quantity is prescribed directly. uniform ( 0 0 0 ) .1 18. The numerical treatment of this kind of patches is inherently clear to the solver and needs no more modelling.1 inletOutlet The behaviour of the inletOutlet boundary condition depends of the ow direction. The boundary that lies in the symmetry plane is of type symmetry plane. The boundaries of the types patch and wall need to be specied further. ® ® 89 . but it is not relevant. The gradient of a quantity is prescribed to zero. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 4 Pitfalls 18. In this case.org/version2. internalField uniform 1 e − 8. OpenFOAM expects the keyword 0/k.x was used. FoamFile { version format class object } 2. x/ s r c /OpenFOAM/ l n I n c l u d e / F i e l d . volScalarField . ® ® 90 .2 surfaceNormalFixedValue The surfaceNormalFixedValue boundary condition prescribes the norm of a vector eld.1. uniform. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Listing 148: The le 0/k −−> FOAM Warning : From f u n c t i o n F i e l d <Type > : : F i e l d ( c o n s t word& keyword . 1 .1 Syntax When assigning a after the value fixedValue keyword.1 lies in an extension of the possible boundary conditions See the release notes of OpenFOAM-2. The author assumes the reason for this distinction between version 2.1. 1 e − 8. assuming d e p r e c a t e d F i e l d format from Foam version 2.18. A positive value for refValue means.0. The direction is taken from the surface normal vector of the patch.php). c o n s t d i c t i o n a r y &. version is then OpenFOAM will issue an error message like in Listing 150.1. ascii . Listing 148 shows the le uniform boundary condition.0 (http://www. A negative value means the opposite direction.openfoam.3 pressureInletOutletVelocity This boundary condition is a combination of pressureInletVelocity and inletOutlet.0 and 2.0 like in Listing 148. Listing 149 shows the warning message OpenFOAM issues. uniform − 0.4.1. x/ run / twoPhaseEulerFoam / bubblePlume / c a s e /0/ k : : b o u n d a r y F i e l d : : i n l e t " from l i n e 25 t o l i n e 26 e x p e c t e d keyword ' uniform ' o r ' nonuniform ' . ESI-OpenCFD or the OpenFOAM Foundation. In both cases OpenFOAM-2. Note the missing keyword.3.C a t l i n e 262 Reading "/home/ u s e r /OpenFOAM/ u s e r − 2 .0. 1 . type refValue surfaceNormalFixedValue . 18. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [ 0 2 −2 0 0 0 0 ] . Listing 147: surfaceNormalFixedValue boundary condition 18. when the value after the keyword 2. The reaction of OpenFOAM diers from the value after the keyword version. OpenFOAM assumes If the value after the keyword version is 2. that this quantity is directed in the same direction as the surface normal vector.3. boundaryField { inlet { type value } fixedValue .1. uniform or nonuniform There the inlet boundary denition diers from Listing 145.0/boundary-conditions. Listing 149: Warning message: missing keywords IV ® ® ® This oering is not approved or endorsed by ESI Group. c o n s t l a b e l ) i n f i l e /home/ u s e r /OpenFOAM/OpenFOAM− 2 . k. } Listing 151: Denition of a time-variant boundary condition Pitfall: Two-phase solvers This boundary condition does not work with two-phase solvers.5. Listing 151 shows the denition of a time-variant boundary condition with a xed value.0 s and t = 5.0 (0. x/ s r c /OpenFOAM/ l n I n c l u d e / F i e l d . ® ® 91 . FOAM e x i t i n g Listing 150: Warning message: missing keywords 18. See http://www. From f u n c t i o n F i e l d <Type > : : F i e l d ( c o n s t word& keyword .1) ) ). 1 . After this interval has ended. 1 . The most easy initialisation is to prescribe all values to be zero throughout the domain. the value of the boundary condition remains constant.0 s the value of the boundary condition is linearly interpolated between the values for both ends of the interval.0 (0. inlet { type uniformF ixedValue . Another solution would be to prescribe a time-variant boundary condition.0 0.0) ) ( 5. found on l i n e 26 t h e d o u b l e S c a l a r 1 e −08 f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 . see Listing 118 in Section 15. uniformValue table ( ( 0. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 18. One solution would be to choose a very small time step at the beginning. ESI-OpenCFD or the OpenFOAM Foundation. Between the time t = 0.openfoam.C a t l i n e 2 7 8 .0/boundary-conditions.5 Time-variant boundary conditions Time-variant boundary conditions can help to avoid problems from an inept initialisation of the solution data.1 uniformFixedValue This boundary condition is an generalisation of the 1.0 0. IV ® ® ® This oering is not approved or endorsed by ESI Group.0 0. c o n s t l a b e l ) i n f i l e /home/ u s e r /OpenFOAM/OpenFOAM− 2 . the eld-values at the boundary are initially small and grow during a certain time span to their nal value. c o n s t d i c t i o n a r y &.0 0.−−> FOAM FATAL IO ERROR: e x p e c t e d keyword ' uniform ' o r ' nonuniform ' . Thus. At the start of a simulation when the non-zero values of some boundary meet the zero values of the neighbouring cells stability problems may arise due to the large relative velocities. x/ run / twoPhaseEulerFoam / bubblePlume / c a s e /0/ k : : b o u n d a r y F i e l d : : i n l e t from l i n e 25 t o l i n e 2 6 . fixedValue BC.org/version2.php. H turbulence->correct() Figure 26: Flow chart of the SIMPLE algorithm 38 In case of a laminar simulation an empty function is called. The solution procedure can be described as follows 1.H pEqn. Check if convergence is reached simple. 19. ® ® 92 . Solve the transport equations for the turbulence model 38 turbulence->correct() 5. V ® ® ® This oering is not approved or endorsed by ESI Group. Start of time step f alse simple. a laminar simulation uses the laminar turbulence model.Part V Solver 19 Solution Algorithms The solution of the Navier-Stokes equations require the solution of the coupled equations for the velocities and the pressure eld. there are several solution algorithms. Turbulence is modelled in OpenFOAM in a very generic way. This is repeated until a convergence criteria is reached.H pEqn. Correct the pressure and the velocities UEqn. To decouple the computation of velocity and pressure a predictor-corrector strategy is followed. In order to be able to gain a solution. The SIMPLE algorithm predicts the velocity and then corrects both the pressure and the velocity. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Go back to step 1 In OpenFOAM the SIMPLE algorithm is used for steady-state solvers.1 SIMPLE Figure 26 shows the ow chart of the SIMPLE algorithm.loop() 2.H 4. Predict the velocities using the momentum predictor 3.loop() End of time step true UEqn. The labels in Figure 26 are related to the terminology used in the source code of the simpleFoam solver. ESI-OpenCFD or the OpenFOAM Foundation. All of these algorithms try to compute velocities and pressure seperately and therefore decouple the problem. Therefore. U. boundaryField ( ) . Listing 153: Corrector in pEqn. UEqn .1. correctNonOrthogonal ( ) ) { f v S c a l a r M a t r i x pEqn ( fvm : : l a p l a c i a n (rAU .1. c o r r e c t B o u n d a r y C o n d i t i o n s ( ) . c o n s t r a i n (UEqn ( ) ) . s o u r c e s . v o l S c a l a r F i e l d rAU ( 1 .H( ) . UEqn ( ) . pRefValue ) . ® ® 93 .H of simpleFoam V ® ® ® This oering is not approved or endorsed by ESI Group.H of simpleFoam 19.1 Predictor The predictor of simpleFoam is a momentum predictor. s o l v e (UEqn ( ) == − f v c : : grad ( p ) ) . a d j u s t P h i ( phi . pEqn . p ) . ESI-OpenCFD or the OpenFOAM Foundation. } i f ( simple . This corrected pressure is used to correct the velocities by solving the continuity equation. s o l v e ( ) . p .H" // E x p l i c i t l y r e l a x p r e s s u r e f o r momentum c o r r e c t o r p . s o u r c e s . Listing 152: Predictor in UEqn. r e l a x ( ) . finalNonOrthogonalIter () ) { p h i −= pEqn . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // Momentum p r e d i c t o r tmp<f v V e c t o r M a t r i x > UEqn ( fvm : : d i v ( phi . f l u x ( ) . The non-orthogonal pressure corrector loop is necessary only for non-orthogonal meshes [24].19. } #i n c l u d e " c o n t i n u i t y E r r s . U = rAU*UEqn ( ) . updateCoeffs ( ) . " i n t e r p o l a t e (HbyA) " ) & mesh . // Non− o r t h o g o n a l p r e s s u r e c o r r e c t o r l o o p while ( simple . p h i = f v c : : i n t e r p o l a t e (U. 0 / UEqn ( ) . s e t R e f e r e n c e ( p R e f C e l l . S f ( ) . // Momentum c o r r e c t o r U −= rAU* f v c : : grad ( p ) . relax () . U) + t u r b u l e n c e −>d i v D e v R e f f (U) == s o u r c e s (U) ). pEqn .2 Corrector The corrector is used to correct the pressure eld by using the predicted velocity. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. U.A( ) ) . p ) == f v c : : d i v ( p h i ) ). c o r r e c t (U) . c l e a r ( ) . laminar. Turbulence modelling is generic. RAS or LES may be selected.e.1 Continuity equation The general continuity equation reads as follows: ∂ρ + ∇ · (ρu) = 0 ∂t we now assume incompressible uids: (28) ρ = const ∇·u = 0 (29) div(u) = 0 ∂ui =0 ∂xi (30) or in alternative notation V ® (31) ® ® This oering is not approved or endorsed by ESI Group. Start of time step UEqn. the pressure and the velocity Afterwards. The velocity is predicted using the momentum predictor.1. flow using the PIMPLE (merged PISO-SIMPLE) algorithm. Figure 27 shows the ow chart of the PISO algorithm. ESI-OpenCFD or the OpenFOAM Foundation. i.2 PISO The PISO algorithm also follows the predictor-corrector strategy.19. is corrected until a predened number of iterations is reached.1 Governing equations 20.H true PISO loop pEqn. Then. The solver is described in the le pimpleFoam.C as follows: Large time-step transient solver for incompressible. 20.H f alse turbulence->correct() End of time step Figure 27: Flow chart of the PISO algorithm 20 pimpleFoam pimpleFoam is a transient incompressible solver. the transport equations of the turbulence model are solved. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 94 . we use Eq. the momentum equation of pimpleFoam are derived.20. ® ® 95 . we can replace Ref f with the deviatoric part of (39) Ref f 1 Ref f = dev(Ref f ) + tr(Ref f )I | {z } |3 {z } deviatoric part (40) hydrostatic part dev(Ref f ) = Ref f − 1 tr(Ref f ) I 3 | {z } (41) =0 Therefore. the momentum equation can be rewritten ∂u + ∇(uu) + ∇ · dev(Ref f ) = −∇p + Q ∂t | {z } (42) =div(dev(Ref f )) Finally. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Ref f = −ν ef f ∇u + (∇u)T ∂ui ∂uj ef f ef f Rij = −ν + ∂xj ∂xi The trace of τ (36) (37) fullls the continuity equation for incompressible uids ef f tr(Ref f ) = Rii = −2ν ef f ∂ui ∂xi =0 (38) ∂ui = ∇·u = 0 ∂xi Therefore.1.2 Momentum equation Departing from the Navier-Stokes equations. the eective stress tensor. This stress tensor containing shear as well as Reynolds stresses is denoted Ref f . (36) Ref f = −ν ef f ∇u + (∇u)T (36) to gain ∂u + ∇(uu) + ∇ · dev(−ν ef f ∇u + (∇u)T ) = −∇p + Q ∂t V ® ® (43) ® This oering is not approved or endorsed by ESI Group. Both RAS as well as LES turbulence models are based on the Boussinesq hypothesis. ∂ρu + ∇(ρuu) + ∇ · τ = −∇p + g ∂t because we assume a constant density we can divide by (32) ρ ∂u 1 ∇p g + ∇(uu) + ∇ · τ = − + ∂t ρ ρ ρ (33) The last term is dened a general source term ∂u 1 ∇p + ∇(uu) + ∇ · τ = − +Q ∂t ρ ρ the shear stresses and the pressure are denoted by new symbols: τ ρ = Ref f (34) und p ρ =p ∂u + ∇(uu) + ∇ · Ref f = −∇p + Q ∂t (35) The Boussinesq hypothesis allows us to add the Reynolds stresses to the shear stresses. ESI-OpenCFD or the OpenFOAM Foundation. the turbulence model handles this term.1. 0 / UEqn ( ) . work. c o n s t r a i n (UEqn ( ) ) . which also uses the PIMPLE algorithm. Therefore. Therefore. U) div(uu) The third term of Eq. The use of the identier not lead to confusion. what's under the hood? This Section deals with the way pimpleFoam and twoPhaseEulerFoam.3 Implementation The momentum equation is implemented in the le UEqn. −∇p | {z } ⇔ -fvc::grad(p)) ⇔ sources(U) =−grad p Q 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // S o l v e t h e Momentum e q u a t i o n tmp<f v V e c t o r M a t r i x > UEqn ( fvm : : ddt (U) + fvm : : d i v ( phi . ∇ · dev(Ref f ) | {z } turbulence->divDevReff(U) ⇔ =div(dev(Ref f )) The terms on the rhs of Eq. is used in the source code lies in the solution fvm::div(phi.20. r e l a x ( ) .H of pimpleFoam 20. Here. The rst two terms of Eq.A( ) ) . i f ( pimple .2 The PIMPLE Algorithm or. (43) are the pressure gradient and the source term. The rst term is the local derivative of the momentum due to the incompressibility of the uid. changing the meaning of the equations. Listing 155 shows the main loop of pimpleFoam. (43) can easily be identied in the source code in Listing 154. U) + t u r b u l e n c e −>d i v D e v R e f f (U) ). The reason why procedure. } Listing 154: The le UEqn. (43) is the diusive momentum transport term. s o u r c e s . v o l S c a l a r F i e l d rAU ( 1 . the instruction in the source code reads very much the same as the mathematical notation. In order to read the equations from the source code. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.H. ® ® 96 . V ® ® ® This oering is not approved or endorsed by ESI Group. See line 7 of Listing 154. momentumPredictor ( ) ) { s o l v e (UEqn ( ) == − f v c : : grad ( p ) + s o u r c e s (U) ) . we examine the implementation of pimpleFoam. (43) is the convective transport of momentum. ESI-OpenCFD or the OpenFOAM Foundation. ∂u ∂t ⇔ fvm::ddt(U) phi should phi can be replaced with U without The second term of Eq. Diusive momentum transport is caused by the laminar viscosity as well as turbulence. See Section 42 for a detailled discussion about ∇(uu) | {z } ⇔ phi phi. UEqn ( ) . the density was eliminated can be found in line 5 of Listing 154. H" #i n c l u d e " CourantNo . Code which is #include macro. w r i t e ( ) . Listing 155: The main loop of pimpleFoam Figure 28 shows the ow chart of the PIMPLE algorithm. rst the momentum equation is solved (Line 12). So. readTimeControls. This is a very common way to give the code of OpenFOAM structure and order. 39 In case of a k- model. Maintaining this code. If this code was not outsourced into a seperate le. 20. At the end of each time step the data is written.H In line 3 of Listing 155 the le readTimeControls. Inside this loop. If the PIMPLE loop is entered only once. If there is no entry matching the name of the parameter ("adjustTimeStep"). This le is then included with the code duplication is prevented. ® ® 97 . After incrementing the time step (Line 7). Listing 277 shows the contents of readTimeControls. ESI-OpenCFD or the OpenFOAM Foundation. This is a very straight forward example of determining the behaviour of a solver using only the source code. The le use variable time steps. no operation is carried out. then the algorithm is essentially the same as the PISO algorithm. there are two transport equations to be solved.The rst instruction is the loop over all time steps. This algorithm is executed every time step. Listing 162 draws this conclusion from the code itself. 40 In case of a laminar simulation. t u r b C o r r ( ) ) { t u r b u l e n c e −>c o r r e c t ( ) . Thus. Other turbulence models require the solution of less or none transport equation. run ( ) ) { #i n c l u d e " rea dT im eC on tro ls .2. the PIMPLE loop comes (from Line 10 onwards). then a default value is used. c o r r e c t ( ) ) { #i n c l u d e "pEqn . l o o p ( ) ) { #i n c l u d e "UEqn . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. then the pressure correction loop is entered (Line 17). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 w h i l e ( runTime . omitting the parameter adjustTimeStep in controlDict will result in a simulation with a xed time step. In this case the names of the source le as well as variable and function names are rather self explaining. would be tiresome and prone to errors. In other cases one has to dig deeply into the code to learn about what a certain command does.1 readTimeControls.H might be included into every solver that is able to used repeatedly is outsourced into a seperate le.H. Then there are some operations the three #include instructions concerning time step control. // −−− P r e s s u r e − v e l o c i t y PIMPLE c o r r e c t o r l o o p w h i l e ( pimple .H" // −−− P r e s s u r e c o r r e c t o r l o o p w h i l e ( pimple . 39 if there are any present40 are solved (Line At the end of the PIMPLE loop the turbulent equations 22).H" } } } i f ( pimple . this code would be found in every variable time step solver.H is included to the source code using the #include prepro- cessor macro. The rst instruction reads from controlDict the adjustTimeStep parameter.H" #i n c l u d e " s e t D e l t a T . V ® ® ® This oering is not approved or endorsed by ESI Group.H" runTime++. } runTime . Listing 156: The content of V ® readTimeControls. s c a l a r maxCo = runTime .H ® ® This oering is not approved or endorsed by ESI Group. s c a l a r maxDeltaT = runTime . l o o k u p O r D e f a u l t ( " adjustTimeStep " . 1 . c o n t r o l D i c t ( ) . lookupOrDefault <s c a l a r >("maxDeltaT" . f a l s e ) . lookupOrDefault <s c a l a r >("maxCo" .loop() End of time step true UEqn. c o n t r o l D i c t ( ) . ESI-OpenCFD or the OpenFOAM Foundation.Start of time step f alse pimple. GREAT) . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 0 ) . ® ® 98 .correct() pEqn.H f alse f alse turbCorr() true turbulence->correct() Figure 28: Flow chart of the PIMPLE algorithm 1 2 3 4 5 6 c o n s t b o o l adjustTimeStep = runTime .H true pimple. c o n t r o l D i c t ( ) . 4. nCorrPISO_ = p i m p l e D i c t . The connection between keywords and the algorithm The keyword nOuterCorrectors translates with the help of Listing 158 to the variable variable controls how often the PIMPLE loop is traversed. Thus. ® ® 99 . ESI-OpenCFD or the OpenFOAM Foundation. lookupOrDefault <l a b e l >(" n C o r r e c t o r s " . } turbOnFinalIterOnly_ = p i m p l e D i c t .C. 1 ) . This Listing 159 shows parts of the denition of the 41 Most programming languages provide access speciers to specify the visibility of variables.3 for details behind the method lookupOrDefault(). t r u e ) .H and pimpleControl. Solution controls pimpleControl. the user can provide any number in fvSolution as long as it is The two variables the 42 .2 for details on the label datatype.C will generate some knowledge of the inner life of pimpleFoam.2 pimpleControl Examining the les pimpleControl. Three of the protected variables of Listing 157 are assigned in Listing 158.H. Listing 157: Protected data in 1 2 3 4 5 6 7 8 9 10 11 12 13 pimpleControl. //− Flag t o i n d i c a t e whether t o o n l y s o l v e t u r b u l e n c e on f i n a l i t e r b o o l turbOnFinalIterOnly_ . //− Current PISO c o r r e c t o r l a b e l corrPISO_ . 42 See Section 35. then default values are used. lookupOrDefault <Switch >(" t u r b O n F i n a l I t e r O n l y " . If the corresponding entry in PIMPLE dictionary in fvSolution is missing. Listing 158: Read solution controls in Reading the code we can see which keyword in the pimpleControl. //− Converged f l a g b o o l converged_ . lookupOrDefault <l a b e l >(" n O u t e r C o r r e c t o r s " .H v o i d Foam : : p i m p l e C o n t r o l : : r e a d ( ) { s o l u t i o n C o n t r o l : : read ( f a l s e ) . Pitfall: no sanity checks nCorrPimple and nCorrPiso control the solution algorithm. a zero or negative number is a legal entry from the source codes point of view. 1 ) . The keyword protected means. Listings 157 and 158 show parts of of protected 41 data in // P r o t e c t e d data // S o l u t i o n c o n t r o l s //− Maximum number o f PIMPLE c o r r e c t o r s l a b e l nCorrPIMPLE_ . The other two have dierent names. V ® ® ® This oering is not approved or endorsed by ESI Group.4) is connected to which variable in the code. nCorrPIMPLE_. that the variables can be accessed only inside the class pimpleControl and all classes inherited from pimpleControl.C PIMPLE dictionary it is a part of the fvSolution dictionary (see Section 7. Listing 157 shows the declaration pimpleControl.H and pimpleControl.2. One of them has the same name in both the code and the dictionary. However. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. With respect to legal the solution algorithm a zero or negative entry makes no sense at all. // Read s o l u t i o n c o n t r o l s c o n s t d i c t i o n a r y& p i m p l e D i c t = d i c t ( ) . nCorrPIMPLE_ = p i m p l e D i c t .20. see Section 35. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //− Maximum number o f PISO c o r r e c t o r s l a b e l nCorrPISO_ . algorithmName_ ( algorithmName ) . return f a l s e . pimpleControl.C translates with the help of Listing 158 to the variable nCorrPISO_. ® ® 100 . If this loop() returns false. This variable controls how often the PISO loop or the corrector loop is traversed. then the function solutionControl. In line 5 of Listing 159 an internal counter is incremented the ++ operator of C++ adds 1 to the variable the operator is applied to. residualControl_ () . corrNonOrtho_ ( 0 ) {} Listing 160: The constructor of the class The keyword nCorrectors solutionControl in solutionControl. see Listing PISO algorithm. /* code removed f o r t h e s a k e o f b r e v i t y */ i f ( corr_ == nCorrPIMPLE_ + 1 ) { i f ( ( ! r e s i d u a l C o n t r o l _ . There correct() of the class pimpleControl. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. This number tells the solver. Listing 161 shows the denition of the function 162. empty ( ) ) && (nCorrPIMPLE_ != 1 ) ) { I n f o << algorithmName_ << " : not c o n v e r g e d w i t h i n " << nCorrPIMPLE_ << " i t e r a t i o n s " << e n d l . data : : remove ( " f i n a l I t e r a t i o n " ) . In line 10 the value of the counter is compared to the maximum number of corrector loop iterations. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 b o o l Foam : : p i m p l e C o n t r o l : : l o o p ( ) { read ( ) . So.function loop() of the class pimpleControl. every instance of pimpleControl has an intercounter corr_ inherited from solutionControl. corr_ ( 0 ) . Afterwards.C Foam : : s o l u t i o n C o n t r o l : : s o l u t i o n C o n t r o l ( fvMesh& mesh . In line 3 the counter this function is called. Listing 160 shows the constructor of the class The class nal to zero. c o n s t word& algorithmName ) : mesh_ ( mesh ) . the internal counter is compared to the value nCorrPIMPLE_. The return value of corrPISO_ is incremented every time this function controls if the corrector loop is entered. momentumPredictor_ ( t r u e ) . of internal counter is then equal to the sum of nCorrPIMPLE_ + 1. Hence. how many times the corrector loop should be traversed. The return value of this function decides whether the PIMPLE loop is entered or not. transonic_ ( f a l s e ) . 1 i n l i n e b o o l Foam : : p i m p l e C o n t r o l : : c o r r e c t ( ) V ® ® ® This oering is not approved or endorsed by ESI Group. The corrector loop is a feature of the nCorrPISO_. dictionary by the use of the The rst variable is the limit and the nCorrectors keyword. mesh_ . nCorrPISO_ is read from the nCorrPISO_ fvSolution and corrPISO_. Line 9 of Listing 160 how the counter corr_ is initialised The internal counter is initialised to the value of 0. second is the counter. the maximum number of corrector loop iterations is called The variable corrPISO_ is declared in the constructor of the class the variable is initialised to zero. nNonOrthCorr_ ( 0 ) . ESI-OpenCFD or the OpenFOAM Foundation. corr_++. pimpleControl is derived from solutionControl. Listing 157 shows. /* code c o n t i n u e s */ Listing 159: Some content of 1 2 3 4 5 6 7 8 9 10 11 pimpleControl. } } corr_ = 0 . that there are two variables related to the PISO loop. C twoPhaseEulerFoam This section is valid for OpenFOAM-2.1. converged_ ( f a l s e ) { read ( ) . i f ( debug ) { I n f o << algorithmName_ << " c o r r e c t : corrPISO = " << corrPISO_ << e n d l . } Listing 162: Constuctor of 21 pimpleControl in pimpleControl. "PIMPLE" ) . According to the CFD-Online Forum (http://www. turbOnFinalIterOnly_ ( t r u e ) .H PIMPLE or PISO algorithm pimpleControl. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Foam : : p i m p l e C o n t r o l : : p i m p l e C o n t r o l ( fvMesh& mesh ) : s o l u t i o n C o n t r o l ( mesh . V ® ® ® This oering is not approved or endorsed by ESI Group. } } i f ( corrPISO_ <= nCorrPISO_ ) { return true .1 General remarks twoPhaseEulerFoam is a solver for two-phase problems.2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { corrPISO_++. Then the solution controls the variable equates the PISO algorithm. After reading the nCorrPIMPLE_ is tested. } i f (nCorrPIMPLE_ > 1 ) { /* code removed f o r s h o r t n e s s o f l i s t i n g */ } else { I n f o << n l << algorithmName_ << " : O p e r a t i n g s o l v e r i n PISO mode" << n l << e n d l . cfd-online. In the course of an update of OpenFOAM-2. In this case an according message is printed to the Terminal.x in July 2012 the solution algorithm of the continuity equation was changed.0 til OpenFOAM-2. ESI-OpenCFD or the OpenFOAM Foundation. If this value is equal to one. 21. } else { corrPISO_ = 0 . corrPISO_ ( 0 ) . At rst some data elds are read() function is called. then the solution algorithm Listing 162 shows parts of the code of the constructor of the class set to initial values.com/Forums/openfoam/) this solver as well as bubbleFoam is based on the PhD thesis of Henrik Rusche [25]. nCorrPIMPLE_ ( 0 ) .2. this function is shown in Listing 158. } Listing 161: The inline function correct() in pimpleControlI. nCorrPISO_ ( 0 ) . ® ® 101 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. return f a l s e . l o o p ( ) ) { #i n c l u d e " alphaEqn . which is set in a dictionary by the user. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. However. there are some modications necessary for solving two-phase problems. This model can also be turned on or o. After the corrector loop the total time derivatives of the velocities are calculated. 21.H" #i n c l u d e " l i f t D r a g C o e f f s .H" // −−− P r e s s u r e c o r r e c t o r l o o p w h i l e ( pimple . The rst is a boolean variable. The second is generated by the solution control.correct()) the correction of pressure and velocity is computed.H" } #i n c l u d e "DDtU . ESI-OpenCFD or the OpenFOAM Foundation. Inside this loop (pimple.2.g. t u r b C o r r ( ) ) { #i n c l u d e " k E p s i l o n . e. f i n a l I t e r ( ) ) { #i n c l u d e " alphaEqn .H. c o r r e c t ( ) ) { #i n c l u d e "pEqn . After the predictor comes the corrector.1.loop()) dier from pimpleFoam. The corrector is in fact a corrector loop. In the following sections kinetic theory is ignored for the reason of keeping listings and explanations short. 21. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // −−− P r e s s u r e − v e l o c i t y PIMPLE c o r r e c t o r l o o p w h i l e ( pimple . In this case it is the k- model that is called explicitly (line 23).H" } i f ( pimple . comes the momentum predictor It contains the momentum equations for both phases and solves them subsequently.2 Kinetic theory twoPhaseEulerFoam can make use of the kinetic theory for granular simulations.H" } Listing 163: The main loop of twoPhaseEulerFoam Figure 29 shows the ow chart of all operations that are performed during one time step. This model is so to say hardcoded and can only be turned on or o. ® ® ® This oering is not approved or endorsed by ESI Group. air owing through a bed of small particles. ® ® 102 . The rst two lines inside the main loop (pimple. Inside the corrector loop (line 15) there is also a conditional second call of the continuity equation.1 Continuity The continuity equation is implemented in the le V alphaEqn.21.H" } i f ( c o r r e c t A l p h a && ! pimple .H" #i n c l u d e "UEqns . Next.1 Turbulence twoPhaseEulerFoam can only use the k- turbulence model.2 Solver algorithm twoPhaseEulerFoam is based on the PIMPLE algorithm. the turbulent transport equations are solved. Listing 163 shows the main part of this solver. The condition consists of two boolean statements. thus the lename UEqns. These lines deal with the two-phase continuity equation and the inter-phase momentum exchange coecients. 21. in line 6.H.1. Finally. H f alse correctAlpha() & !nalIter() f alse turbCorr() true alphaEqn.loop() f alse End of time step true alphaEqn.Start of time step pimple.correct() true pEqn. ® ® 103 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.H liftDrag.H pimple.H true kEpsilon.H UEqn.H Figure 29: Flow chart of the main loop of twoPhaseEulerFoam V ® ® ® This oering is not approved or endorsed by ESI Group.H f alse DDtU. ESI-OpenCFD or the OpenFOAM Foundation. H alphaEqn. Drag is considered in the governing equations by the use of the so-called drag-function is either computed directly. lookup(). When the corrector loop is not entered anymore. The corrector loop is traversed a nAlphaCorr of the fvSolution dictionary.3 Momentum exchange between the phases 21.Second call In line 15 of Listing 163 the continuity equation is called again inside an if-statement. the value of nOuterCorrectors or Therefore. ® ® This oering is not approved or endorsed by ESI Group. lookup ( " c o r r e c t A l p h a " ) ) . the mixture density is updated. d i c t ( ) . then alphaEqn.H The second boolean expression controlling the second call in line 15 of Listing 163 is controlled by the number of iterations of the PIMPLE loop. The reading operation of this keyword from the dictionary can be found in the source le shown in Listing 164. !pimple. Inside this loop the continuity equation is solved. ESI-OpenCFD or the OpenFOAM Foundation. Three keywords are looked up from the algorithm for the continuity equation. is controlled by the fvSolution dictionary. Listing 164: The content of readTwoPhaseEulerFoamControls.H is not entered a second time.2 for a discussion about the PIMPLE algorithm. d i c t ( ) . #i n c l u d e " re adT im eC on tr ols . there is an iteration other than the nal one. correctAlpha. Switch c o r r e c t A l p h a ( pimple . 21. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. If the PIMPLE loop is traversed only once.3 for a detailed discussion about looking up keywords from dictionaries. lookup ( " nAlphaSubCycles " ) ) ) . In the sources of twoPhaseEulerFoam there are this models Ergun Gibilaro GidaspowErgunWenYu GidaspowSchillerNaumann SchillerNaumann SyamlalOBrien WenYu The equations behind this models can be found in [11] or [29]. The le alphaEqn. The rst. See Section 20.H dictionary. K. This number is set by the keyword nAlphaSubCycles of the fvSolution dictionary. After the sub-cycle the volume fraction of the continuous phase is updated. The condition depends on two boolean expressions. i n t nAlphaSubCycles ( r e a d I n t ( pimple . lookup ( " nAlphaCorr " ) ) ) . and is All of them are related to the solving Those entries are read from the dictionary by invoking the function See Section 35.finalIter() is true if.H results in the ow chart in Figure 30. This number is set by the keyword corrector loop is a simple Inside the corrector loop is a sub-cycle loop. This drag-function The drag force is the product [11].H" i n t nAlphaCorr ( r e a d I n t ( pimple . The examination of the le specied number of times. 1 2 3 4 5 fvSolution readTwoPhaseEulerFoamControls. the expression nCorrPIMPLE_ is greater than one. d i c t ( ) . there is more than one PIMPLE iteration and only then. and only if. or it is computed by the use of the drag coecient of the drag-function and the relative velocity between the phases V ® Ur Cd . The sub-cycle loop is also traversed a specied number of times. Because only then. The expression pimple. Assigning a value to this keyword the keyword has the same name as the boolean variable in the source code is mandatory.finalIter() is true when the last iteration of the PIMPLE algorithm is entered.1 Drag The solver twoPhaseEulerFoam oers a number of drag models.3. The for loop. ® ® 104 . 0 e − 3) ) ) .44 if if Re ≤ 1000 Re > 1000 (44) 3 Ur Cd ρB 4 dA (45) The drag coecient is dimensionless. ® ® 105 . whereas the product of the drag-function K and the relative velocity has the dimension of a force density.H Schiller-Naumann drag We use the Schiller-Naumann drag model as an expample to demonstrate how OpenFOAM calculates the drag force. ESI-OpenCFD or the OpenFOAM Foundation. nu ( ) . Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : SchillerNaumann : : K ( c o n s t v o l S c a l a r F i e l d& Ur ) const { v o l S c a l a r F i e l d Re (max( Ur* phasea_ . d ( ) / phaseb_ . v o l S c a l a r F i e l d Cds V ® ® ® This oering is not approved or endorsed by ESI Group.alpha1 Figure 30: Flow chart of the operations in alphaEqn. This drag model utilizes a drag coecient that is a function of the Reynolds number. ( Cd = K= 24 Re 1 + 0.15Re0.687 0. s c a l a r ( 1 . kg m 1 kg Ur ] = 1· 3 · = 3 dA m s m m s kgm 1 N kg m [K · Ur ] = 3 · = 2 · 3 = 3 m s s s m m [K] = [Cd ] · [ρB ] · [ Listing 165 shows.Start rho = alpha1*rho1 + alpha2*rho2 f alse corrector loop End true true sub-cycle solve continuity f alse alpha2 = scalar(1) . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. how the drag-function is computed by the Schiller-Naumann drag model. rho ( ) *Ur/ phasea_ . [lif tCoef f ] = [CL ] · [ρc ] · [Ur × (∇ × Uc )] = 1 · kg m 1 m kgm 1 N · = 2 · 3 = 3 3 m s m s s m m 21. Listing 166: Berechnung Auftriebskraft. ® ® 106 .H The dimensions of the eld liftCoeff is the dimension of a force density. " d i v ( phia . 0 * ( 1 . 0 + 0 .3. Ua) V ® ® ® This oering is not approved or endorsed by ESI Group. it also needs to accelerate some of the displaced uid is considered in the momentum equation. the other is considered in the lhs.H The drag force contributes to the momentum balance. sphere in shear ow.3 Virtual mass The virtual mass an accelerating bubble needs not only to accelerate its own mass.2 Lift The lift model of twoPhaseEulerFoam is described in [25]. The vector eld liftCoeff contains the lift force density.H. Listing 165: Calculation of the drag-function in the le SchillerNaumann. d ( ) .( neg ( Re − 1 0 0 0 ) * ( 2 4 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ESI-OpenCFD or the OpenFOAM Foundation. Ua) " ) − fvm : : Sp ( f v c : : d i v ( p h i a ) . 6 8 7 ) ) /Re ) + pos ( Re − 1 0 0 0 ) * 0 .V M = β ρB CV M ρA DB UB DA U A − Dt Dt (47) In the source code. FL = CL ρc |Ur × (∇ × Uc )| VB (46) mit Ur = UA − UB Uc = αUA + (1 − α) UB | {z } =β ρc = αρA + βρB The lift force is computed in the le liftDragCoeffs.3. UaEqn = ( ( s c a l a r ( 1 ) + Cvm* rhob * b e t a / rhoa ) * ( fvm : : ddt (Ua) + fvm : : d i v ( phia . 4 4 ). 7 5 * Cds* phaseb_ . 0 . One part is included in the rhs of the momentum equation. MA. liftDragCoes. v o l V e c t o r F i e l d l i f t C o e f f ( Cl * ( b e t a * rhob + a l p h a * rhoa ) * ( Ur ^ f v c : : c u r l (U) ) ) . 1 5 * pow ( Re . } r e t u r n 0 . one part of the drag is considered in the momentum equation and the other part is considered in the pressure equation. The lift model computes the lift force on a rigid The force density is calculated from the relative velocity between the phases and the vorticity of the mixture. 21. the momentum exchange term due to virtual mass is split into two parts. Ua . Probably for numerical reasons. This seperation is probably for numerical reasons. ® ® As the 107 . when using the isothermalDiameter diameter model to determine the diameter of the dispersed phase elements. therefore all simplications when considering a phase incompressible do not hold anymore.). In version 2. 22. In an incompressible simulation the absolute value of the pressure has no meaning.). The volume fraction is an exception. controlDict.air and T. As each phase has a velocity and a temperature.3 phases are modelled using OpenFOAMs thermophysical models.x to 2.EXTENSION There naming scheme applied.2 or lower to 2. U2 vs. In this case FILENAME etc. With the release of OpenFOAM-2.3 the pressure is now a real physical pressure.2. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.water = 1.1.3 is that the solver is based on a completely dierent set of physical models. check the pressure initial condition and the boundary conditions. when migrating a simulation case from OpenFOAM-2.water. A general distinction of data concerning a single phase and data concerning the whole simulation case can be made.0/multiphase.php. the user is required to specify not only the thermo-physical properties of the phases. now stored in les with a lename that consists of two parts. Thus. Data related to a specic phase is The naming scheme follows the well known denotes the type of information and EXTENSION denotes the phase itself.3. we see two les for velocity and temperature. This naming scheme is much more general than other naming schemes that are/were used in OpenFOAM (cf. the volume fraction of water is easily calculated. 22.4 UEqns. Uwater. Case data is named as usual (e.3 the two-phase Eulerian solver twoPhaseEulerFoam has seen some major changes.3 aims for reuseability and generality of the solver code itself as well as of the case data.1.1 http://www.2 Temperature As the new version of the solver uses thermo-physical models for the phases. Uair vs.H Kinetic Theory For the simulation of dense gas-solid particulate ows the particulate phase can be modelled using the kinetic theory model. i.1 Pressure In twoPhaseEulerFoam -2. Thus.org/version2. we see the FILENAME.alpha. the absolute value of the pressure has an eect. g. the user also has to provide initial and boundary conditions for the temperature of both phases.3.air. ® ® This oering is not approved or endorsed by ESI Group.g. U1. U. e. ESI-OpenCFD or the OpenFOAM Foundation. two additional elds are present or need to be present in the time directories.3 This section is valid for OpenFOAM-2.g. fvSchemes. In a compressible model.openfoam. as there are only two phase considered. 22.air. 22 twoPhaseEulerFoam-2. V ® alpha. See the release notes for further details: 22. only pressure dierences count.EXTENSION naming scheme. Physics The most important change in twoPhaseEulerFoam from version ≤ 2.0 . e. ) + /* o t h e r terms */ == /* o t h e r terms */ − b e t a / rhoa * ( l i f t C o e f f − Cvm* rhob *DDtUb) Listing 167: Terms including virtual mass in the le 21. Listing 168 shows the contents of the 0 and constant folders of the bubble column tutorial case.2 T.g.water). FILENAME. U. Naming scheme The overhaul of twoPhaseEulerFoam in version 2. The phases are considered compressible.3.e. water Listing 168: Content of the 0 and constant folders of the bubble column tutorial case of twoPhaseEulerFoam in OpenFOAM-2. air t h e r m o p h y s i c a l P r o p e r t i e s . water user@ host : ~ /OpenFOAM/OpenFOAM− 2 . A number of turbulence models can be used in contrast to earlier versions of twoPhaseEulerFoam that had kEpsilon hard-coded. 3 . org epsilon . The les g and phaseProperties have no extensions because they contain no information specic to one phase. a i r nut . ® ® 108 .3. turbulence model are formulated in their general multi-phase form This limits the choice of turbulence models to a small number of multi-phase turbulence models. a i r . air e p s i l o n .openfoam.php V ® ® ® This oering is not approved or endorsed by ESI Group. water nut . Phase interaction has been extended. The thermophysical properties of the phases air and water are stored in the appropiate les. air k . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. also the governing equations of the 43 .3. water p T. ESI-OpenCFD or the OpenFOAM Foundation.3 is t to create a material data library. Turbulence Turbulence is treated in a more general way. This can not be turned o. x/ t u t o r i a l s / m u l t i p h a s e / twoPhaseEulerFoam /RAS/ bubbleColumn$ l s 0 −1 alpha . air t u r b u l e n c e P r o p e r t i e s .0/multiphase. a i r Theta T.3 uses a whole new class of turbulence models. also the solver itself is more generalized. The was the phases or the phase data is organized within the solver is now independent of the way the phase data is organized within the case.pressure is share by all phases. user@ host : ~ /OpenFOAM/OpenFOAM− 2 .3. 22.3 Solver capabilities Not only the naming scheme is more general in version 2. water U.4 Turbulence models twoPhaseEulerFoam -2. A great number of models specic for gas-liquid systems have been included.org/version2. Energy equation twoPhaseEulerFoam solves an energy equation for all phases.x 22. 43 http://www. Compressibility all phases are treated as compressible. a i r U. water k. the pressure le has no le-extension. Listings 169 and 170 show the list of available turbulence models at the time of writing (May 2014). In the constant folder there is also data that applies to one phase and data that applies to the simulation case. water turbulenceProperties . As the governing equations of twoPhaseEulerFoam namely the momentum equation aren't phase intensive anymore. x/ t u t o r i a l s / m u l t i p h a s e / twoPhaseEulerFoam /RAS/ bubbleColumn$ l s c o n s t a n t −1 g phaseProperties polyMesh thermophysicalProperties . 3 . a i r alpha . The naming scheme that was introduced with twoPhaseEulerFoam-2. In the le thermophysicalProperties the behaviour of a phase can be specied. Furthermore. 22. This is possible. The model. rho ) + f v c : : d i v ( alphaRhoPhi ) . see Lines 11 and 24. there is an additional source term on the RHS. V a l i d LESModel t y p e s : 5 ( NicenoKEqn Smagorinsky SmagorinskyZhang continuousGasKEqn kEqn ) Listing 170: Valid LES turbulence models of twoPhaseEulerFoam.4. k_) − fvm : : Sp ( f v c : : ddt ( alpha . the convective term is corrected with the continuity error. ESI-OpenCFD or the OpenFOAM Foundation. e p s i l o n _ ) − fvm : : Sp (C2_* a l p h a * rho * e p s i l o n _ /k_ . k_) + fvm : : d i v ( alphaRhoPhi . See textbooks on CFD for the theory behind RAS and LES turbulence models and the origin and meaning of νt and νsgs [16]. tmp<f v S c a l a r M a t r i x > epsEqn ( fvm : : ddt ( alpha . e p s i l o n _ ) + fvm : : d i v ( alphaRhoPhi .2 kEpsilon Listing 171 shows the governing equations of the compressible multi-phase formulation of the governing equations are largely equivalent to the compressible formulation of the single-phase k− k− model. ® ® 109 . Sections 40 and 41 cover the incompressible k − model respectively some basics on LES turbulence models.1 Naming scheme One feature of the multi-phase turbulence model framework is that the additional turbulent viscosity is now named nut.V a l i d RASModel t y p e s : 6 ( LaheyKEpsilon continuousGasKEpsilon kEpsilon kineticTheory mixtureKEpsilon phasePressure ) Listing 169: Valid RAS turbulence models of twoPhaseEulerFoam. 22.4. see Lines 5 and 18. e p s i l o n _ ) − fvm : : l a p l a c i a n ( a l p h a * rho * D e p s i l o n E f f ( ) . e p s i l o n _ ) == C1_* a l p h a * rho *G* e p s i l o n _ /k_ − fvm : : SuSp ( ( ( 2 . rho . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. In single-phase simulations an LES turbulence model works with the eld nuSgs. whereas a RAS model uses nut. regardless of whether a RAS or an LES model is used. since both additional viscosities stem from the application of the Boussinesq-hypothesis. rho . e p s i l o n _ ) + epsilonSource () ). First. The formulation deviates from the compressible single-phase formulation in two aspects. k_) − fvm : : l a p l a c i a n ( a l p h a * rho * DkEff ( ) . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 tmp<f v S c a l a r M a t r i x > kEqn ( fvm : : ddt ( alpha . 0 / 3 . k_) == V ® ® ® This oering is not approved or endorsed by ESI Group. e p s i l o n _ ) − fvm : : Sp ( f v c : : ddt ( alpha . rho ) + f v c : : d i v ( alphaRhoPhi ) . 0 ) *C1_ + C3_) * a l p h a * rho *divU . + kSource ( ) Listing 171: Governing equations of the kEpsilon turbulence model. LaheyKEpsilon model for one phase phase. k ( ) . I O o b j e c t : :NO_READ. that the zero return value will cause problems in the 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 phaseTransferCoeff() LaheyKEpsilon turbulence model. t h i s −>mesh_ . s c a l a r ( 0 ) ) * rho *min ( g a s T u r b u l e n c e . 0 / 3 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. c o n s t t u r b u l e n c e M o d e l& g a s T u r b u l e n c e = t h i s −>g a s T u r b u l e n c e ( ) . timeName ( ) . t h i s −>runTime_ . Listing 174 shows the denition of this method. the other phase is not allowed to be modelled phaseTransferCoefficient() of the LaheyKEpsilon turbulence gasTurbulence. If laminar other phase. In Line 13 of Listing 173 we nd the function call is chosen as turbulence model for the called. template <c l a s s BasicTurbulenceModel> Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : laminar <BasicTurbulenceModel > : : k ( ) c o n s t { r e t u r n tmp<v o l S c a l a r F i e l d > ( new v o l S c a l a r F i e l d ( IOobject ( I O o b j e c t : : groupName ( "k" . 1 . ® ® 110 . t h i s −>U_.4. template <c l a s s BasicTurbulenceModel> tmp<v o l S c a l a r F i e l d > LaheyKEpsilon<BasicTurbulenceModel > : : p h a s e T r a n s f e r C o e f f ( ) c o n s t { c o n s t v o l V e c t o r F i e l d& U = t h i s −>U_. then the method k() of the laminar turbulence model is Listing 173 shows the method model. 1 2 3 4 5 6 7 template <c l a s s BasicTurbulenceModel> c l a s s LaheyKEpsilon : p u b l i c k E p s i l o n <BasicTurbulenceModel> { /* c l a s s d e f i n i t i o n */ } Listing 172: The rst lines of the LaheyKEpsilon turbulence model denition. ESI-OpenCFD or the OpenFOAM Foundation. k_) − fvm : : Sp ( a l p h a * rho * e p s i l o n _ /k_ .a l p h a * rho *G 21 22 23 24 25 − fvm : : SuSp ( ( 2 . I O o b j e c t : :NO_WRITE V ® ® ® This oering is not approved or endorsed by ESI Group.k() in the denominator. see Listing 172. We easily see. e p s i l o n ( ) / g a s T u r b u l e n c e . 22. time ( ) . c o n s t a l p h a F i e l d& a l p h a = t h i s −>alpha_ . d e l t a T ( ) ) ). c o n s t r h o F i e l d& rho = t h i s −>rho_ . 0 ) * a l p h a * rho *divU . group ( ) ) . Pitfall: the other phase When using the as laminar. 0 /U. return ( max( a l p h a I n v e r s i o n _ − alpha . k_) ).3 LaheyKEpsilon The LaheyKEpsilon turbulence model is a derivation of the standard kEpsilon turbulence model. } Listing 173: The method 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 method of the phaseTransferCoeff() of the LaheyKEpsilon turbulence model. see Listing 175. i. −−> FOAM FATAL ERROR: lookup o f t u r b u l e n c e P r o p e r t i e s . properties. First. The reason for this is not entirely known to the author. k − model. 0 1 1 4 3 2 5 .e. 7 9 1 1 7 e − 09 . V ® ® ® This oering is not approved or endorsed by ESI Group. x/ s r c /OpenFOAM/ l n I n c l u d e / o b j e c t R e g i s t r y T e m p l a t e s . No I t e r a t i o n s 2 DILUPBiCG : S o l v i n g f o r km. F i n a l r e s i d u a l = 6 . FOAM a b o r t i n g Listing 176: Solver output of twoPhaseEulerFoam when the mixtureKEpsilon turbulence model is specied for only one of the two phases. 0 0 7 8 2 5 2 . see Eqns. mixtureKEpsilon is specied for only one of the phases. C at l i n e 181. 0 . 176 shows the resulting error message when Listing As the turbulence model for the mixture applies to both phases. 1 3 1 7 3 e − 09 . In any case the attempt to do so results in a segmentation fault when rst using the turbulence model at the initialisation of the simulation case. This minor dierence between the formulation of the equation can be resolved in two steps. No Iterations 2 Listing 175: Solver output of twoPhaseEulerFoam using the In order to use the mixture mixtureKEpsilon turbulence model. it needs to be specied for both phases. DILUPBiCG : S o l v i n g f o r epsilonm . water from o b j e c t R e g i s t r y r e g i o n 0 s u c c e s s f u l but i t i s not a mixtureKEpsilon . Pitfall: the dispersed phase It is not possible to assign the LaheyKEpsilon turbulence model to the dispersed phase. (48) to (51). it needs to be specied in both turbulenceProperties les.4 mixtureKEpsilon Usage The k− model is computed for the mixture. we take a look on the rst two terms of the governing equations in [7] (local derivative and convective term). Theory The governing equations of the mixture k− model can be found in the sources at \$FOAM\_SRC/TurbulenceModels/ phaseCompressible/RAS/mixtureKEpsilon and in [7]. ® ® 111 . I n i t i a l r e s i d u a l = 0 . 0 ) Listing 174: The method k() of the laminar turbulence model.16 17 18 19 20 21 ) ). d i m e n s i o n e d S c a l a r ( "k" . the continuity equation of the mixture appears on the of the governing equations. Thus. i t i s a LaheyKEpsilon From f u n c t i o n o b j e c t R e g i s t r y : : lookupObject <Type>( c o n s t word&) c o n s t i n f i l e /home/ u s e r /OpenFOAM/OpenFOAM− 2 . } ). F i n a l r e s i d u a l = 2 . the solution variables are named the transport equations are solved for using the mixture km and epsilonm. s q r ( t h i s −>U_. either to the dispersed phase alone or to both phases. 3 . 22. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.4. d i m e n s i o n s ( ) ) . I n i t i a l r e s i d u a l = 0 . ESI-OpenCFD or the OpenFOAM Foundation. The biggest dierence between the equations stated in [7] and the code of mixtureKEpsilon can be found in the Lines 5 and 18 of Listing 177. t h i s −>mesh_ . There. see Listing 177 or Eq. . . . a probable reason might be a better numerical behaviour. km) + kSource ( ) ). so phase inversion poses no big problem. ∂t (51) ∂ρm m ∂ρm − m + ∇ · (ρm um m ) − m ∇ · (ρm um ) + . . e p s i l o n m ) − fvm : : Sp (C2_*rhom* e p s i l o n m /km. 0 / 3 . ∂t ∂m ∂ρm ρm + m + m ∇ · (ρm um ) + ρm um · ∇m + . The exact reason why this formu- lation was chosen is unknown to the author. . km) − fvm : : Sp ( rhom* e p s i l o n m /km. e p s i l o n m ) == C1_*rhom*Gm* e p s i l o n m /km − fvm : : SuSp ( ( ( 2 . . ∂t ∂t Eq (53) is now equivalent to the rst terms of the (52) (53) equation of Listing 177. ∂t ∂t ∂ρm m ∂ρm + ∇ · (ρm um m ) − m + ∇ · (ρm um ) + . Listing 177: Governing equations of the mixtureKEpsilon turbulence model. The following example demonstrates the problems which may be faced when dealing with phase inversion. km) + fvm : : d i v ( phim . Figure 31 shows the air volume fraction within the bubble column. (48) and (49). . 22. . ∂t ∂t | {z } (48) (49) (50) =0 ∂m ρm + ρm um · ∇m + . ® ® 112 . a vanishing volume fraction can lead to serious numerical problems. km) − fvm : : l a p l a c i a n ( DkEff ( rhom*nutm ) . we begin with Eq. ρm ∂m + ρm um · ∇m + . e p s i l o n m ) + epsilonSource () ). . ∂t (51) In order to derive equations equivalent to the code implemented in OpenFOAM. (53). cf. tmp<f v S c a l a r M a t r i x > epsEqn ( fvm : : ddt ( rhom . (51) and use the product rule of dierentiation. e p s i l o n m ) − fvm : : l a p l a c i a n ( D e p s i l o n E f f ( rhom*nutm ) . ESI-OpenCFD or the OpenFOAM Foundation. Eqns. . the volume fraction is not included in the governing equation. 0 ) *C1_) *rhom*divUm .5 Pitfall: phase inversion Phase inversion is the situation when the volume fraction of the continuous phase vanishes in some regions. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.∂ρm m + ∇ · (ρm um m ) + . e p s i l o n m ) − fvm : : Sp ( f v c : : ddt ( rhom ) + f v c : : d i v ( phim ) . km) == rhom*Gm − fvm : : SuSp ( ( 2 . ∂t ∂t ∂m ∂ρm ρm + m + ∇ · (ρm um ) +ρm um · ∇m + . 0 ) *rhom*divUm . As almost all terms of the governing equations are weighted with the volume fraction alpha. e p s i l o n m ) + fvm : : d i v ( phim . An air-water bubble column is modelled including some of the air above the water surface. When mixtureKEpsilon is selected as turbulence model. . km) − fvm : : Sp ( f v c : : ddt ( rhom ) + f v c : : d i v ( phim ) . 0 / 3 .4. . V ® ® ® This oering is not approved or endorsed by ESI Group. . . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 tmp<f v S c a l a r M a t r i x > kmEqn ( fvm : : ddt ( rhom . The energy equation is formulated in a generic form in terms of he. The solution of the energy equation can not be deactivated. in parts of the domain the solution of the governing equations faces numerical problems. ESI-OpenCFD or the OpenFOAM Foundation. Besides the internal energy or enthalpy the energy equation involves also the kinetic energy K.openfoam. This volume fraction vanishes above the water surface. but preconditioning the resulting matrix equation fails. v o l S c a l a r F i e l d K1( I O o b j e c t : : groupName ( "K" .org/version2. the energy equation will be solved each time step.H of twoPhaseEulerFoam. The solving of the energy equation requires the specication of additional discretisation schemes and a solver in fvSolution. phase2 . Listing 178: Denition of the kinetic energy eld in the le createFields. 5 * magSqr (U1) ) . the volume fraction in the governing equations is the volume fraction of the liquid phase. Preconditioning is a step that is intended to improve the iterative solution of the resulting matrix equation. Initial eld (left) and solution at 22. the only way to avoid crashing the simulation is to use a -solver with no preconditioning. ® ® 113 . In the case of the kEpsilon turbulence model for the liquid phase. 0 .php V ® ® ® This oering is not approved or endorsed by ESI Group. Accounting for compressibility necessitates the solution of the energy equation.5 t = 10 s (right).3 the twoPhaseEulerFoam solver incorporates the functionality of compressibleTwoPhaseEuler- Foam 44 . The -solver and the smooth solver fail completely. name ( ) ) . Thus. This source code translates into the following mathematical relation. fvSchemes and Depending on the simulation parameters the energy equation is solved in terms of the enthalpy or internal energy e. v o l S c a l a r F i e l d K2( I O o b j e c t : : groupName ( "K" . 0 . Energy equation In OpenFOAM-2. 5 * magSqr (U2) ) . Listing 178 shows how this kinetic energy is computed. name ( ) ) . h or h e which is in fact a specic kinetic energy.When kEpsilon is selected for the liquid phase.3. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. phase1 . Figure 31: Air volume fraction of the bubble column.0/multiphase. The governing equations can still be solved in this case. 44 http://www. Even if thermophysical parameters are chosen to represent incompressible phases. The actual decision to solve for is made at run-time after the thermophysical properties of the two phases have been read. Ki = 1 2 |Ui | 2 (54) I n f o << " C r e a t i n g f i e l d k i n e t i c e n e r g y K\n" << e n d l . An implicit source term not only contributes to the system matrix. Exactly. Besides the use of the abstract variable at constant pressure or the heat capacity at constant volume. he. what is happening. Line 19 represents the heat ux between the two phases. he1 ) == h e a t T r a n s f e r C o e f f * ( thermo2 . ESI-OpenCFD or the OpenFOAM Foundation.5. we see that they add up to zero. we need to nd out.3 for a detailed discussion. the use of the Cpv is also a characteristic of this generic formulation. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. fvm::Sp() for a while and add the Adding zero is mathematically allowed.H of twoPhaseEulerFoam. this is achieved by the Lines 20 and 21.e. The term in Line 21 adds to the diagonal of the system matrix. f v S c a l a r M a t r i x he1Eqn ( fvm : : ddt ( alpha1 . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Listing 179: Energy equation in the le 22.22. 45 The most general form of the momentum conservation equation for two-phase ow is as follows X X ∂αq ρq uq + ∇ · (αq ρq uq uq ) − ∇ · τq = Fq. name ( ) == thermo1 . Lines 20 and 21 can be considered a numerical trick. Here we see a conditional expression depending whether the equation is solved for internal energy or enthalpy. K1) − c o n t E r r 1 *K1 + ( he1 . However. rho1 .T( ) − thermo1 . as diagonal dominance is numerically a good thing. he1 ) − fvm : : Sp ( contErr1 . This variable stands for either the heat capacity formulated generically. it is preferable to work on a diagonally dominant system matrix [16]. he1 ) ).i + Kpq. Momentum equation Due to the changes on the modelling side and some restructuring. Lines 12 to 17 contain the diusive heat ux.T( ) ) + h e a t T r a n s f e r C o e f f * he1 /Cpv1 − fvm : : Sp ( h e a t T r a n s f e r C o e f f /Cpv1 . the convergence behaviour was probably improved. mut ( ) ) ) . the contribution of this term goes into the system matrix of the resulting linear equation system. rho1 . he1 ) + f v c : : ddt ( alpha1 . All other terms in the equation are he. As both sides of the equation have been equally treated. V ® ® ® This oering is not approved or endorsed by ESI Group. i. whereas the term of Line 20 adds to the right hand side of the ensuing linear equation system. he1 ) + f v O p t i o n s ( alpha1 . From Lines 8 to 10 we see the term regarding the mechanical work done. the momentum equation has a dierent form compared to previous versions of this solver. If we ignore the terms of the two lines. nothing was done wrong mathematically. In Line 3 we see the local derivative and the convection term of the generic internal energy/ enthalpy the specic kinetic energy K.1 Governing equations Listing 179 shows the energy equation for one phase. See Section 38.6 EEqns. phasePropertyName ( " e " ) ? f v c : : ddt ( a l p h a 1 ) *p + f v c : : d i v ( alphaPhi1 .i (up − uq ) ∂t i i (55) 45 The phase q is the considered phase and phase p denotes the other phase. these terms go into the diagonal entries of the system matrix. rho1 . ® ® 114 . which is internal energy or enthalpy. not ignore the fvm::Sp(). he1 ) + fvm : : d i v ( alphaRhoPhi1 . t u r b u l e n c e ( ) . In Line 5 is the local derivative and the convection term of In the Lines 4 and 6 we see a correction for the continuity error. When solving linear equation systems iteratively. Line 22 contains possible heat sources. a l p h a E f f ( phase1 . K1) + f v c : : d i v ( alphaRhoPhi1 . p ) : − a l p h a 1 * dpdt ) − fvm : : l a p l a c i a n ( fvc : : i n t e r p o l a t e ( alpha1 ) * f v c : : i n t e r p o l a t e ( thermo1 . fvm::Sp() If we do is an implicit source term. On Line 5 we see a term stemming from the MRF approach. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 V ® ® ® This oering is not approved or endorsed by ESI Group. U1) − DDtU2 ) + f v O p t i o n s ( alpha1 . This is consistent with our observation. The origin of the term in Line 4 is explained in 38. On Line we see a part of the drag force. This terms are the product uR = up − uq . The rst kind of source terms Fi can be referred to as body forces. ∂αq ρq uq ∂t = 1 kg m 1 kg m N = 3 2 = 3 3 sm s m | {z s } m (56) N We see that all terms of the momentum equation have the unit of a force density. e.3. r e l a x ( ) .6. U1) − fvm : : Sp ( contErr1 . ! [Fi ] = N kg = 2 2 m3 m s (57) Kpq. Although. divDevRhoReff (U1) == − liftForce − wallLubricationForce − turbulentDispersionForce − virtualMassCoeff *( fvm : : ddt (U1) + fvm : : d i v ( phi1 . On Line 6 is the momentum diusion. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.1 Units Now we shall take a short look on the units of this equation. On the RHS of the momentum equation we have two kinds of source terms. On the RHS there are a number of force terms. they are in fact force density terms.6. U1Eqn = ( fvm : : ddt ( alpha1 . that this terms have the unit of a force density. U1) + mrfZones ( a l p h a 1 * rho1 + v i r t u a l M a s s C o e f f . We take the local derivative to determine the unit of all terms in this equation.i = −Kqp. rho1 .i Kqq.g.with Kpq. ® ® 115 . Such a phase interaction term might be due to the interphase momentum exchange coecient Kpq. The force due to gravity and the other part of the drag are considered in the pressure equation [25]. Now we determine the unit of N 1 kg m = 3 m s m3 s kg [Kpq.2 Implemented equations Listing 180 shows one of the momentum conservation equations.i (up − uq ) are phase interaction terms. they are named *Force. U1) ).i with the relative velocity drag. t u r b u l e n c e ( ) .i . Each term of the equation has to have the same unit. On Line 3 we see the local derivative and the convective term. ESI-OpenCFD or the OpenFOAM Foundation.i (up − uq )] = (58) (59) 22. U1Eqn += fvm : : Sp ( d r a g C o e f f . U1) + phase1 . the gravitational force. The second kind of source terms of a coecient Kpq. U1Eqn . U1) + fvm : : d i v ( alphaRhoPhi1 .i ] = 3 m s ! [Kpq. U1) − fvm : : Sp ( f v c : : d i v ( p h i 1 ) .i = 0 22. rho1 . U1) . H.C. There we also see the explicit specication of the continuous phase. volScalarField volVectorField volVectorField volVectorField virtualMassCoeff ( f l u i d . is quite instructive. linear and hyperbolic. Listing 182: The application of blending. liftForce () ) . f1 and f2 as it is demanded This blending model. turbulentDispersionForce () ) . These range from α1 = 0 to α1 = 1. 22 Listing 180: The code of the momentum conservation equation of phase 1 of twoPhaseEulerFoam in UEqns. v a l i d ( ) ) { x ( ) += model1In2_−>K( ) * ( 1 − f 1 ) . dragCoeff () ) . // c r e a t e x i f ( model_ . wallLubricationForce () ) . In twoPhaseEulerFoam -2. V ® ® ® This oering is not approved or endorsed by ESI Group. } i f ( model1In2_ . which is dened in the les noBlending. ® ® 116 .H and noBlending.7 UEqns. In order to well-posedness of the governing equations special care needs to be taken for the case of phase inversion.7. wallLubricationForce ( f l u i d .f v O p t i o n s . Wee see that the momentum exchange terms are fluid is of the type twoPhaseSystem. v a l i d ( ) ) { x ( ) += model2In1_−>K( ) * f 2 . Listing 181: The denition of the interfacial momentum exchange force terms of the momentum conservation equations of twoPhaseEulerFoam in 22. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.H The interfacial momentum exchange terms are computed prior to the construction of the momentum equa- Ueqns. 1 2 3 4 5 6 volScalarField dragCoeff ( f l u i d .H Interfacial interaction 22. v a l i d ( ) ) { x ( ) += model_−>K( ) * ( f 1 ( ) − f 2 ( ) ) .1 Blending The interfacial momentum exchange models need to work over the whole range of ow situations.1. see Section tion. Thus. the user needs to specify which phase is the contin- uous phase. c o n s t r a i n ( U1Eqn ) . Listing 181 shows the relevant lines of the le provided by some methods. As there is no blending with the none blending model. which is essentially a non-model. We know that the variable ods called to compute the momentum exchange 24. } // o t h e r code return x . ESI-OpenCFD or the OpenFOAM Foundation. virtualMassCoeff () ) . the methterms are methods of the class twoPhaseSystem. liftForce ( fluid .3 there is no implicit assumption on which phase is the dispersed and which is continuous.2. part of the method K() in BlendedInterfacialModel. There are three options for blending available: none. } i f ( model2In1_ .C No Blending The blending model none. turbulentDispersionForce ( fluid . returns the blending factors by the base class of all blending models. Listing 183 shows how the none blending model is selected. e. dimensionedScalar ( "f" . we have a look on the blending factors returned by the the methods f1() and f2().cppreference. } Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : blendingMethods : : noBlending : : f 2 ( c o n s t phaseModel& phase1 . which is the set of values we would expect in this case. we nd the following sentence in the section on Integral promotions : A prvalue of type bool can be converted to a prvalue of type int. mesh ( ) ) . phase2. Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : blendingMethods : : noBlending : : f 1 ( c o n s t phaseModel& phase1 . that is in turn created from a constant expression. return tmp<v o l S c a l a r F i e l d > ( new v o l S c a l a r F i e l d ( I O o b j e c t ( /* arguments removed */ ) . none model. } } Listing 183: Choosing not to use blending as the blending method Now. http://en. If the boolean expressions yield the correct factors can be tried out with a simple pen-and-paper test. with false becoming zero and true becoming one. Implicit type conversions are part of the language's standard. c o n s t phaseModel& phase2 ) const { c o n s t fvMesh& mesh ( phase1 . Choose a continuous phase (i. the corresonding expression is Here. c o n s t phaseModel& phase2 ) const { c o n s t fvMesh& mesh ( phase1 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Listing 184 shows the denition of These methods return a newly created temporary scalar eld (volScalarField) the constant expression is In the case of f2() which also returns a boolean value. f1(). Thus.). phase2 . In the case of boolean value. Thus. determine the values of f1 and f2.name() == continuousPhase\_. ESI-OpenCFD or the OpenFOAM Foundation. mesh . c o n t i n u o u s P h a s e water . we nd that the blending factors returned by none are of the values zero or one.name() != continuousPhase\_ which returns a phase1. ® ® 117 . return tmp<v o l S c a l a r F i e l d > ( new v o l S c a l a r F i e l d ( I O o b j e c t ( /* arguments removed */ ) . dimensionedScalar 46 See e.com/w/cpp/language/implicit_cast V ® ® ® This oering is not approved or endorsed by ESI Group. if we look up the working draft of the C++11standard. mesh ( ) ) .g. we enter the realm of implicit type conversions 46 .e. dimless . mesh . phase2 is the continuous phase) and evaluate all expressions (i.blending { default { type none . name ( ) != continuousPhase_ ) ) ). and apply these values on the expressions found in Listing 182. situations in which one phase is the dispersed phase in only parts of the domain. the blending factors f1 and f2 have two extreme values.0) Listing 186: Computing the linear blending factor V ® f1 in the le ® linear. name ( ) ] ) . word . f1. const dimensionedScalar maxPartAlpha ( maxPartlyDispersedAlpha_ [ phase1 . a clear distinction between dispersed phase and continuous phase is possible. //− Maximum f r a c t i o n o f p h a s e s which can be c o n s i d e r e d p a r t l y d i s p e r s e d HashTable<d i m e n s i o n e d S c a l a r . f1 (α) = 1 if if α ≤ maxFullyDispersedAlpha α ≤ maxPartlyDispersedAlpha 0 if α > maxPartlyDispersedAlpha α − maxFullyDispersedAlpha maxPartlyDispersedAlpha−maxFullyDispersedAlpha (60) //− Maximum f r a c t i o n o f p h a s e s which can be c o n s i d e r e d f u l l y d i s p e r s e d HashTable<d i m e n s i o n e d S c a l a r . name ( ) ] ) . shown in Listing 185. word . We limit the discussion on blending factor is dened analogously. As we saw from the The model name The linear blending model was two model parameters. i. max ( ( phase1 − maxFullAlpha ) / ( maxPartAlpha − maxFullAlpha + SMALL) . Listing 185: Model parameters of the linear blending model. The interested reader is encouraged to analyse f2. word : : hash> maxFullyDispersedAlpha_ .e. These two limits are necessary. word : : hash> maxPartlyDispersedAlpha_ . These represent the limits up to which a phase can be considered to be fully dispersed. scalar (1. as the other The code of Listing 186 can be translated into equation (60). The second parameter is the limit up to which the phases can be considered partly dispersed. The denition of the blending factor f1 is shown in Listing 186.C ® This oering is not approved or endorsed by ESI Group. linear suggests that this models yields a linear variation between these two limiting values. The arguments of the constructor of the IOobject class have been removed to save space. } "f" .( ) ). return min ( } ). the producer of the OpenFOAM software and owner of the OpenFOAM trademark.H Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : blendingMethods : : l i n e a r : : f 1 ( c o n s t phaseModel& phase1 . i. ® ® 118 . ESI-OpenCFD or the OpenFOAM Foundation. dimless .e. c o n s t phaseModel& phase2 ) const { const dimensionedScalar maxFullAlpha ( maxFullyDispersedAlpha_ [ phase1 . declaration in the le linear.0) ). zero and one. as the solver is intended to handle phase inversion. phase1 . scalar (0. name ( ) == continuousPhase_ ) Listing 184: Computing the blending factors. i. Linear none model.e. 8 0. ESI-OpenCFD or the OpenFOAM Foundation. see Figure 33. f2. we analyse only the denition of reader the opportunity to follow the argument made.f1 1. these settings are taken from the bubble column tutorial case of twoPhaseEulerFoam. V ® ® ® This oering is not approved or endorsed by ESI Group. The other two parameters are each phase.8 over α.4 0. f1 and leave the transitionAlphaScale maxDispersedAlpha for The parameter controls how steep the transition between 0 and 1 is.0 0. 0.drag (up − uq ) (62) We nd the same structure in the terms of the implemented equations. Again.2 0.8 1.8 0.6 0.0 α maxFullAlpha = 0.4 0. 22. model 0.6 0.6 model parameters are set to 0.6 parameters 0. The Listing below shows one part of the drag term as the drag term consists of the coecient and a velocity dierence. we can split the term up into two contributing parts. At this parameter the blending function (61) has the value 1/2.0 0.8.4 0.2 Figure 33: The value of f1 transitionAlphaScale = 0.8 are 1.4 0.6 and Interfacial momentum exchange 22.1 Drag Units From viewing the governing equations we saw.0 set to α maxDispersedAlpha = 0. Hyperbolic The hyperbolic blending model oers a continuous function for the blending factor for the whole range of the dispersed phase's volume fraction. that the drag term consists of a coecient and the relative velocity between the phases. f1 (α) = 1 2 1 + tanh 4(α − maxDispersedAlpha transitionAlphaScale ) (61) f1 1.5. ® ® 119 . Fdrag = Kpq.4. with the denition of The hyperbolic blending model needs in total three model parameters. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.2 0.2 Figure 32: The value of f1 over α.3 and maxPartAlpha = 0. see Eqn. There we can see.2 and below). . Returning the output Other than the drag models of prior versions of twoPhaseEulerFoam (version 2. In the header le of the 47 base class for the drag models. all interfacial momentum exchange models have such a member. i. K() and CdRe() in dragModel. the drag models in CD Re. . we determined the unit of the coecient. Thus. This makes perfect sense for common properties such as the unit of the coecient. which is the same for all drag models. Listing 187: The declaration of the methods 1 2 3 4 5 6 7 8 9 dragModel. − 1. CdRe(). we can check the unit of the coecient. K* (U2−U1) const . We only can create instances of one of the derived classes. In fact. . The base class of the drag model has a static data member that carries the information about the unit of the provided coecient. 0 ) . . // ddt ( a l p h a 2 * rho2 *U2) + . 1 2 3 4 5 6 7 //− The drag f u n c t i o n K used i n // ddt ( a l p h a 1 * rho1 *U1) + . − 3. 0 . ® ® 120 . The method //− Drag c o e f f i c i e n t v i r t u a l tmp<v o l S c a l a r F i e l d > CdRe ( ) c o n s t = 0 . a constant static member dimK is declared. In Section 5 we reviewed OpenFOAMs feature to provide physical units. c o n t i n u o u s ( ) . This drag force coecient is provided by the method K() which is a method of the base class dragModel. d i s p e r s e d ( ) . rho ( ) * pair_ . U1) . ! [dragCoeff] = kg m3 s (63) By having a close look on the base class for the drag models. the base class returns the drag force coecient K . ESI-OpenCFD or the OpenFOAM Foundation. c o n t i n u o u s ( ) . . we are guaranteed that these methods actually exist. Consequently. regardless of how many actual objects of this class exist. we see. K* (U1−U2) = . c o n s t Foam : : d i m e n s i o n S e t Foam : : dragModel : : dimK ( 1 . //− C o e f f i c i e n t d i m e n s i o n s s t a t i c c o n s t d i m e n s i o n S e t dimK .3 return the product of drag coecient and the Reynolds number the method returning the output of the individual drag models is named we are unable to create an instance of the base class itself. see Line 5 of Listing 188.e. . nu ( ) 47 A static data member of a class exists only once for all instances of this class. The base class also has a pure virtual method named CdRe(). Thus. (59). . In the implementation le. v i r t u a l tmp<v o l S c a l a r F i e l d > K( ) t h e momentum e q u a t i o n = . the data member exists only once.H Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : dragModel : : K( ) c o n s t { return 0. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. i. that the order of units in a dimensionSet is [kg m s K mol]. The Listings 187 and 188 show the relevant parts of code of the class K() calls the method CdRe(). .e. As we know from our considerations about the units of the terms of the momentum equation. As a derived class must implement all pure virtual methods. the static data member is initialised to the appropriate value. Pure virtual means that derived classes need to implement this method and that twoPhaseEulerFoam -2. The drag model itself. that the drag force coecient has indeed the unit we derived from our earlier considerations. the drag force contribution in general needs to have the unit of a force density.75 *CdRe ( ) *max( pair_ .U1Eqn += fvm : : Sp ( d r a g C o e f f . V ® ® ® This oering is not approved or endorsed by ESI Group. r e s i d u a l A l p h a _ ) * swarmCorrection_ −>Cs ( ) * pair_ . r e s i d u a l R e _ ) . 22.10 11 } / s q r ( pair_ . noSwarm This model simply returns unity when TomiyamaSwarm swarmCorrection_->Cs() is called. ® ® 121 . 0 + 0 . 0 . } return neg ( Re − 1 0 0 0 ) * 2 4 . ESI-OpenCFD or the OpenFOAM Foundation. 1 2 3 4 5 6 7 8 Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : dragModels : : SchillerNaumann : : CdRe ( ) c o n s t { v o l S c a l a r F i e l d Re ( pair_ . Here we show the denition of the method CdRe() from the class SchillerNaumann as an example since the Schiller Naumann drag model is well known. The Tomiyama swarm correction factor depends on the bubble volume fraction α and a model parameter l. since it is observed that swarms of bubbles behave dierent from single bubbles. Listing 189: The relevant lines of code in SchillerNaumann.C If we translate Listing 188 into math we yield K= 3 ρC νC CD Re αCS 2 4 dB (64) Now. d i s p e r s e d ( ) .2 Lift The lift force on a dispersed phase element (DPE) is dened as FL = CL αρC (UR × (∇ × U)) V ® (69) ® ® This oering is not approved or endorsed by ESI Group. At the time of writing (September 2014) there are two choices. Thus the frame- work is ready for future extension of model choice. Listing 188: The denition of the method K() in dragModel. This model computes the swarm correction factor according to [28]. 1 5 * pow ( Re .C Swarm correction The drag models oer swarm correction of the drag force.8. d ( ) ) .T omiyama = (1 − α)3−2l Both swarm correction models are derived from an abstract base class (68) swarmCorrection. CS. we insert the denition of the bubble Reynolds number 3 dB UR ρC νC CD αCS 2 4 νC dB 3 ρC K = αCS CD UR 4 dB K= (65) (66) If we now take a look on the units [K] = kg 1 m kg ρC UR = 3 = 3 dB m m s m s (67) Again. Re ( ) ) . 6 8 7 ) ) + pos ( Re − 1 0 0 0 ) * 0 . we nd the proper physical unit for the drag force coecient. 0 * ( 1 . 4 4 * max( Re . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. There are several choices available to the user: V ® ® ® This oering is not approved or endorsed by ESI Group. Again. ESI-OpenCFD or the OpenFOAM Foundation. The implementation of Cl() is the remaining degree of freedom for the individual lift force models. //− L i f t c o e f f i c i e n t v i r t u a l tmp<v o l S c a l a r F i e l d > Cl ( ) c o n s t = 0 . − 2. 0 .U( ) ) ). The base class calls the method similar to the method classes. This is F() and Cl() in liftModel. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Returning the output The general computation of the lift force is done similar to the drag models within the method base class. } Listing 191: The denition of the method F() in liftModel. //− Force d i m e n s i o n s s t a t i c c o n s t d i m e n s i o n S e t dimF . the existance of the method Cl() Cl(). Note: the order of units in a dimensionSet ! [Fi ] = is [kg m s K mol]. c o n t i n u o u s ( ) .H Foam : : tmp<Foam : : v o l V e c t o r F i e l d > Foam : : l i f t M o d e l : : F ( ) c o n s t { return Cl ( ) * pair_ . N kg = 2 2 3 m m s (57) c o n s t Foam : : d i m e n s i o n S e t Foam : : l i f t M o d e l : : dimF ( 1 . analogue to the drag model classes.C the static data member is initialized and it has indeed the unit of a force density. Listing 190: The declaration of the methods 1 2 3 4 5 6 7 8 9 10 F() of the concrete lift model for the lift force coecient. Ur ( ) ^ f v c : : c u r l ( pair_ . d i s p e r s e d ( ) * pair_ .with CL α ρC UR U lift force coecient volume fraction of the dispersed phase density of the continuous phase relative velocity between the phases mixture velocity Units In contrast to the drag model. the base class for the lift models declares the pure virtual method model derived from the base class has to implement class itself. The method F() K() Cl() of the of the drag model base class calling the method CdRe() of the concrete drag model of the base class returns the force density eld due to the lift force. rho ( ) *( pair_ . 1 2 3 4 5 //− L i f t f o r c e v i r t u a l tmp<v o l V e c t o r F i e l d > F ( ) c o n s t . c o n t i n u o u s ( ) . − 2. In the implementation le liftModel. The base class of the lift models declares a static consant data member dimF for storing the unit of the force term computed by the list model. 0 ) . the lift model provides the actual force term for the governing equations. This means. every lift and we are not able to create an instance of the base Cl() is guaranteed.H The actual lift force coecient is provided by the concrete lift force model. Thus. ® ® 122 . using other approaches. Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : v i r t u a l M a s s M o d e l s : : n oVi rtua lMa ss : : K( ) c o n s t { r e t u r n Cvm( ) * d i m e n s i o n e d S c a l a r ( " z e r o " .e. V ® ® ® This oering is not approved or endorsed by ESI Group.4 Aspect ratio models When dealing with non-spherical bubbles or particles. is provided by the user. liftModel::F() is called. The aspect ratio is used in the However. The inter- ested reader can nd this out by invoking the following commands. 22.8. This model overwrites the method F() with its own implementation returning a zero eld. All other lift force models do not this model is the easiest implementation of a lift force model.e. These compute the aspect ratio of the dispersed phase elements depending on material and possibly ow properties.8. ® ® 123 . dimDensity . the shape has to be considered in the interfacial momentum exchange models. The constant lift force coef- Cl() simply returns this value in the form of the appropriate data type. ESI-OpenCFD or the OpenFOAM Foundation.noLift this model returns a zero eld when either F() F() or Cl() is called. Here. All other classes make use of the base classes implementation of F() which all derived classes inherited. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. constantCoecient cient CL i. The user has the choice between: noVirtualMass this class returns zero when F() is called. The method Cvm() also returns a zero eld. const dimensionedScalar Cl_. Cl() returns a volScalarField. noLift::F(). the aspect ratio models come into play. thus. With the help of aspect ratio models a particle shape dierent from spheres and even shape variation can be modelled within some limits. One way of dealing with this situation is to formulate those models to incorporate the aspect ratio of the dispersed phase elements. the implementation of the class implement F(). the method lift force model X there are several models available that compute the lift force coecient from ow proper- ties. Thus. This class overwrites the method which is inherited from the base class with its own implementation. The force term due to virtual mass if dened as FV M = CV M αρC (70) with CV M virtual mass coecient α volume fraction of the dispersed phase ρC density of the continuous phase The derived classes provide the virtual mass coecient CV M via the method Cvm(). noLift is called. 0 ) . the inuence of shape can also be considered TomiyamaAnalytic drag model and the Lamb virtual mass model.3 Virtual mass The class structure for the virtual mass models follow the example of the drag and lift models. i. 22. when F() is called. } constantVirtualMassCoecient stant virtual mass coecient Lamb this class computes the contribution due to virtual mass based on a con- CV M which is provided by the user. the coecient provided by the user is a dimensionless number (declared as however.). this model computes the virtual mass coecient CV M depending on the aspect ratio of the dispersed phase elements. There is an abstract base class providing a method F() for the force term FV M due to virtual mass. ESI-OpenCFD or the OpenFOAM Foundation.cd $FOAM_APP/ s o l v e r s / m u l t i p h a s e / twoPhaseEulerFoam / i n t e r f a c i a l M o d e l s f i n d −name * .C and grep searches this les for the pattern returns the aspect ratio E pair_. The models are also derived from an abstract base class. 22. FT D = CT D αρC kC ∇α (71) with CT D α turbulent dispersion coecient volume fraction of the dispersed phase ρC density of the continuous phase kC kinetic turbulent energy of the continuous phase Burns The Burns model implements the following model for the force due to turbulent dispersion.6 Turbulent dispersion Turbulent dispersion describes the eect of turbulent motion of the liquid phase on the gas phase. V ® ® ® This oering is not approved or endorsed by ESI Group. nd nds all les with the le extension .t ∇α 1 + = KDrag σ 1−α (72) with KDrag α νC. There is an abstract base class and derived classes implementing a specic model. so there is a net saving of one virtual function call. The base class declares the pure virtual method F() which returns the force term due to wall lubrication. This pattern is the function call which of a phase pair. FT D α νC. K by hand rather than calling dragModel::K() might K() we can save one virtual function call48 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The class structure is similar to the aforementioned models. Listing 192 shows the actual code that computes the force term of the Burns model.E(). The derived class have to implement this method. 22. By not calling to be done anyway. There is a class named noTurbulentDispersion which returns a zero eld for the force term and there are a number of classes implementing individual models. constantTurbulentDispersionCoecient The constant coecient model implements the following model for the force due to turbulent dispersion. ® ® 124 . since the correct function to call has to determined at run-time [9]. There are also three models computing the wall lubrication force. There is a derived class named noWallLubrication which simply implements the method F() in way to return a zero eld.8. 48 Virtual function calls are considered to be more expensive in terms of run-time than direct function calls.C | x a r g s g r e p ' pair_ .8. The operations to compute K have The reason for computing the drag force coecient be the run-time.t σ Note that Kdrag drag force coecient due to drag volume fraction of the dispersed phase turbulent viscosity of the continuous phase surface tension is not evaluated by calling method K() of the class dragModel.5 Wall lubrication The wall lubrication force pushes bubbles away from the walls. E ( ) ' The second command is a combination of a nd command and a grep command. This eld does not represent the volume fraction of a certain phase and is therefore not bounded by 0 and 1. multiphaseEulerFoam directly uses names (e.C Gosman The Gosman model implements the following model for the force due to turbulent dispersion.1. t u r b u l e n c e ( ) . d i s p e r s e d ( ) * pair_ .2 alphas is computed quantity. ESI-OpenCFD or the OpenFOAM Foundation. Uair.75 * drag .).1 alphas A specialty of multiphaseEulerFoam is the eld alphas. return − 0. name ( ) ) ) ). } Listing 192: The denition of the method F() in the le Burns. This solver diers in some points from the solver twoPhaseEulerFoam. the le alphas can be missing in the 0 -directory. c o n t i n u o u s ( ) ) * ( 1 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. d i s p e r s e d ( ) /max( pair_ . 0 + pair_ . c o n t i n u o u s ( ) . 23.1 Fields The naming scheme of the elds diers from other multiphase solvers. alphas is computed by summing up the products of phase index and phase fraction. need to be specied pair-wise. ® ® 125 . d i s p e r s e d ( ) . d ( ) ) ) * pair_ . Uoil. c o n t i n u o u s ( ) . This eld is used to represent all phases in a single scalar eld. nu ( ) * pair_ . mesh ( ) ) . phase1 ( ) . c o n t i n u o u s ( ) . FT D = KDrag 23 νC.g. CdRe ( ) * pair_ . lookupObject <dragModel> ( I O o b j e c t : : groupName ( dragModel : : typeName . Momentum exchange The parameters for the momentum exchange. pair_ . 23. c o n s t dragModel& drag ( mesh . nut ( ) /( sigma_ * s q r ( pair_ .g. alphas = n−1 X i ∗ αi (74) i=0 Because 23.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Foam : : tmp<Foam : : v o l V e c t o r F i e l d > Foam : : t u r b u l e n t D i s p e r s i o n M o d e l s : : Burns : : F ( ) c o n s t { c o n s t fvMesh& mesh ( pair_ . etc. rho ( ) * f v c : : grad ( pair_ . V ® ® ® This oering is not approved or endorsed by ESI Group.t ∇α σ (73) multiphaseEulerFoam multiphaseEulerFoam is an Eulerian solver for n phases. e. c o n t i n u o u s ( ) . r e s i d u a l A l p h a _ ) ) . Uwater. the drag model. 0.5 0. a physically distinctive form of a substance.1 drag drag ( ( a i r water ) { type b l e n d e d . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.5 0.3 lift force Currently (OpenFOAM 2.org/wiki/Phase V ® ® ® This oering is not approved or endorsed by ESI Group. and gaseous states of ordinary matteralso referred to as a "macroscopic state" http://en. /* f u r t h e r d e f i n i t i o n s */ Listing 193: Pair-wise denition of the drag model in the le transportProperties 23. Phase (matter). We now violate the unwritten law of to not cite Wikipedia. residualPhaseFraction 0. liquid. } water { type SchillerNaumann .5 0.wikipedia.and multi-phase solvers of OpenFOAM is one example of how techniques of object oriented programming can be applied.1. residualPhaseFraction 0.2.23. } } r e s i d u a l P h a s e F r a c t i o n 1 e − 2. The phase model class in the various two.2. In terms of a multi-phase problem in uid dynamics we distinguish dierent phases.5 0.1 Phase model class One of the strenghts of object oriented programming is that the class structure in the source code can reect the properties and relations of real-world things. r e s i d u a l S l i p 1 e − 2.2 virtual mass The coecients for considering virtual mass must also be specied pair-wise. such as the solid.5 0.5 Listing 194: Pair-wise denition of Coecients for virtual mass in the le transportProperties 23.1) there is no lift model in multiphaseEulerFoam. 24 Multiphase modelling 24. air { type SchillerNaumann . virtualMass ( ( a i r water ) ( air oil ) ( a i r mercury ) ( water o i l ) ( water mercury ) ( o i l mercury ) ). residualSlip 0.2. ESI-OpenCFD or the OpenFOAM Foundation. residualSlip 0. Listing 194 shows how the coecients for virtual mass are specied in the damBreak tutorial. ® ® 126 . 2 In this section we want to compare the implementation of the phase model class of the two solvers twoPhaseEuler- Foam and multiphaseEulerFoam. The listing is syntactically correct. public : // Member F u n c t i o n s c o n s t word& name ( ) c o n s t { r e t u r n name_ . } ® ® ® This oering is not approved or endorsed by ESI Group.2. velocity. In the single-phase solvers the phase-properties (viscosity. word name_ . etc.1. Object orientation allows us to translate the idea of the phase into programming language. The basic idea is that a phase has a viscosity.htm). #include statements) have been Furthermore. however all pre-processor instruction (e. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 namespace Foam { c l a s s phaseModel { // P r i v a t e data d i c t i o n a r y dict_ . density. We now create a class named phaseModel and this class needs to have a viscosity. velocity. From a programming point of view properties of a phase such as viscosity. V s u r f a c e S c a l a r F i e l d& p h i ( ) { r e t u r n phiPtr_ ( ) . When we intend our code to represent the reality we want to describe as closely as possible we need to introduce the concept of the phase into our source code. } c o n s t v o l V e c t o r F i e l d& U( ) c o n s t { r e t u r n U_. } c o n s t d i m e n s i o n e d S c a l a r& d ( ) c o n s t { r e t u r n d_ . Listing 195 shows the essence of the header le of the phase model class. The viscosity of a phase is simply a eld of values. } c o n s t d i m e n s i o n e d S c a l a r& rho ( ) c o n s t { r e t u r n rho_ . are easy to implement. etc. } c o n s t d i m e n s i o n e d S c a l a r& nu ( ) c o n s t { r e t u r n nu_ . No phases.com/cplusplus/cpp_data_encapsulation. it also has a velocity. d i m e n s i o n e d S c a l a r d_ . the concept of phases is not needed. } c o n s t s u r f a c e S c a l a r F i e l d& p h i ( ) c o n s t { r e t u r n phiPtr_ ( ) . a velocity and everthing else a phase needs to t our needs.x collects the properties of a phase and oers an interface for accessing these properties.1 A comparison of the phase models in OpenFOAM-2. but the concept of a phase is missing. } v o l V e c t o r F i e l d& U( ) { r e t u r n U_. ESI-OpenCFD or the OpenFOAM Foundation. The phase model classes follow the code of best practice in object oriented programming to hide internal data from the outer world and to provide access via the classes methods (data encapsulation. 24. ® ® 127 .g. velocity is another eld of values. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. twoPhaseEulerFoam The phase model class in twoPhaseEulerFoam -2. see tutorialspoint. The purpose of Listing 195 is to present the data members and methods of the class by actual source code. } }. the removed.In uid dynamics phase is a commonly used term. d i m e n s i o n e d S c a l a r nu_ . most of the comments have been removed and the formatting has been adapted to reduce the line number. autoPtr<s u r f a c e S c a l a r F i e l d > phiPtr_ . v o l V e c t o r F i e l d U_. d i m e n s i o n e d S c a l a r rho_ . As there is only one temperature and velocity to deal with. http://www.) are linked according to the physical relations that are taken into account. please In the single-phase solvers of OpenFOAM such as simpleFoam the concept of a phase is not used. alpha1). } c o n s t word& keyword ( ) c o n s t { r e t u r n name ( ) . c o n s t d i m e n s i o n e d S c a l a r& nu ( ) c o n s t { r e t u r n nu_ . The straight-forward way would be to add another reference to the data members. ESI-OpenCFD or the OpenFOAM Foundation. autoPtr<s u r f a c e S c a l a r F i e l d > phiPtr_ . As the volume fraction eld is a scalar eld. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. the volume fraction can be treated seperately from other phase information. When dealing with an arbitrary number of phases. By taking a look on the members of the class we see that there is no volume fraction eld. This also presents the application of another object-oriented programming technique. Thus. } tmp<v o l S c a l a r F i e l d > d ( ) c o n s t .2. Listing 196 shows a stripped version of the header le of multiphaseEulerFoam's phase model class.H The phase model class of twoPhaseEulerFoam -2. the phase model class is among other things its own the volume fraction eld. v o l V e c t o r F i e l d DDtU_. } c o n s t d i m e n s i o n e d S c a l a r& rho ( ) c o n s t { r e t u r n rho_ . In two phase problems one volume fraction eld (alpha1) suces as the volume fraction eld of the other phase is instantly known (alpha2 = 1 . multiphaseEulerFoam One dierence between the phase model class used in twoPhaseEulerFoam and the one used in multiphaseEuler- Foam follows directly from the simplication made in the two-phase case. ® ® 128 . } V ® ® ® This oering is not approved or endorsed by ESI Group. In multiphaseEulerFoam a more subtle approach was chosen. d i c t i o n a r y phaseDict_ . d i m e n s i o n e d S c a l a r Cp_. d i m e n s i o n e d S c a l a r rho_ . s u r f a c e S c a l a r F i e l d phiAlpha_ . } c o n s t v o l V e c t o r F i e l d& U( ) c o n s t { r e t u r n U_. the pressure is independent of the phases and can be treated seperately. Another missing item is the pressure. public : // Member F u n c t i o n s c o n s t word& name ( ) c o n s t { r e t u r n name_ . d i m e n s i o n e d S c a l a r nu_ . each phase must keep track of its own volume fraction. Most two. Thus.x contains all phase properties needed for an incompressible two-phase solver that makes use of an important consequence of being limited to two phase problems. Thus. the volume fraction must be included into the phase model. Again. v o l V e c t o r F i e l d U_. d i m e n s i o n e d S c a l a r kappa_ . autoPtr<diameterModel> dPtr_ . large parts of the le have been removed leaving only the data members and the methods of the class.33 34 } // End namespace Foam Listing 195: A boiled-down version of the le phaseModel. Thus.or multi-phase Eulerian solvers assume/use a common pressure for all phases. this reference would be a reference to a volScalarField. } c o n s t d i m e n s i o n e d S c a l a r& Cp ( ) c o n s t { r e t u r n Cp_. } c o n s t d i m e n s i o n e d S c a l a r& kappa ( ) c o n s t { r e t u r n kappa_ . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 namespace Foam { c l a s s phaseModel : public volScalarField { // P r i v a t e data word name_ . The phase model class of multiphaseEulerFoam is derived from the class volScalarField. c l a s s phaseModel : p u b l i c v o l S c a l a r F i e l d { /* some c++ code */ } This example highlights. fraction eld. c o n s t fvMesh& mesh ) : volScalarField ( IOobject ( " a l p h a " + name .learncpp. b o o l r e a d ( c o n s t d i c t i o n a r y& p h a s e D i c t ) . } s u r f a c e S c a l a r F i e l d& p h i ( ) { r e t u r n phiPtr_ ( ) . c o n s t d i c t i o n a r y& phaseDict . However. line resource that covers the concept of inheritance. In Listing 197 we see. } c o n s t s u r f a c e S c a l a r F i e l d& phiAlpha ( ) c o n s t { r e t u r n phiAlpha_ . V ® ® ® This oering is not approved or endorsed by ESI Group. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. // code c o n t i n u e s * * * * * * * * * * * * * * // Listing 197: The rst few lines of the constructor of the phase model. we see a prototype of a class denition. I O o b j e c t : :AUTO_WRITE ). } // End namespace Foam Listing 196: A boiled-down version of the le phaseModel. // * * * * * * * * * * * * * * * * C o n s t r u c t o r s Foam : : phaseModel : : phaseModel ( c o n s t word& name . mesh . This infor- mation alone does no proof that the phase model is its own volume fraction eld. The name of the base class (volScalarField) is preceded by a visibility specier (public). that the class phaseModel is derived from the class volScalarField. I O o b j e c t : : MUST_READ.39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 v o l V e c t o r F i e l d& U( ) { r e t u r n U_.g. that the rst instruction in the initialisation list of the constructor reads the volume fraction eld of the respective phase. } s u r f a c e S c a l a r F i e l d& phiAlpha ( ) { r e t u r n phiAlpha_ . mesh . timeName ( ) . } c o n s t v o l V e c t o r F i e l d& DDtU( ) c o n s t { r e t u r n DDtU_. Here. } v o l V e c t o r F i e l d& DDtU( ) { r e t u r n DDtU_.com/cpp-tutorial/ 114-constructors-and-initialization-of-derived-classes/ or [27]. The class name (phaseModel) and the name of the class we are deriving from (volScalarField) are separated by a colon (:). } void c o r r e c t ( ) . mesh ). ESI-OpenCFD or the OpenFOAM Foundation. ® ® 129 . } c o n s t s u r f a c e S c a l a r F i e l d& p h i ( ) c o n s t { r e t u r n phiPtr_ ( ) .H The statements following the class keyword and the class name indicates the derivation of a class. This proofes that the phase model is in fact its own volume For an explanation why we come to this conclusion we refer to any C++ textbook or on- http://www. The class we dene (phaseModel) is derived from a base class (volScalarField). }. see e. a glance on the constructor in the implementation le brings clarity. time ( ) . name_( name ) . x. The phase model class of twoPhaseEulerFoam is simply an information carrier.2. x/ a p p l i c a t i o n s / s o l v e r s / m u l t i p h a s e / multiphaseEulerFoam / multiphaseSystem / phaseModel / phaseModel . The phase model class of multiphaseEulerFoam uses a diameter model class for keeping track of the dispersed phase's diameter. 3 .0 the class diameterModel was introduced into multiphaseEulerFoam and compress- ibleTwoPhaseEulerFoam. ESI-OpenCFD or the OpenFOAM Foundation. s u r f a c e S c a l a r F i e l d alphaPhi_ .3.3.H OpenFOAM− 2 . 49 The diff of the implementation le would be too long to be shown at this place.2. ® ® 130 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. However. We can also observe the rudiment of giving the phase model a more active role. Thus.2. 2 .x as of May 2014 51 . s c a l a r alphaMax_ .x-0eb39ebe0f07. The diameter model oers the choice of computing the diameter of the dispersed phase elements from thermodynamic quantities besides using a constant diameter. 51 OpenFOAM Builds compared: 2. Listing 198 shows that the header les of the phaseModel class of multiphaseEulerFoam diers only in the copyright notice. autoPtr<rhoThermo> thermo_ . A comment on multiphaseEulerFoam The phase model class used for multiphaseEulerFoam in OpenFOAM-2. v o l V e c t o r F i e l d U_. word name_ . in multiphaseEulerFoam -2.H 5 c5 < \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation −−− > \\ / A nd | Copyright (C) 2011 − 2013 OpenFOAM Foundation Listing 198: The output of di for the le phaseModel.H OpenFOAM-2. the behaviour of this class can be considered nearly identical in OpenFOAM-2. the data member dimensionedScalar d_ is replaced by a reference to a diameter model (autoPtr<diameterModel> dPtr_).x this method is empty.Besides being its own volume fraction eld the phase model class of multiphaseEulerFoam was extended by several elds bearing information for the simulation of thermodynamics.x and dierences OpenFOAM-2. public transportModel { // P r i v a t e data c o n s t twoPhaseSystem& f l u i d _ .x and OpenFOAM-2. user@ host : ~ /OpenFOAM$ d i f f OpenFOAM− 2 .3. V ® ® ® This oering is not approved or endorsed by ESI Group.3.x diers very little with respect to the class's methods and members. The correct() method is used in many models for actions performed at every time step. d i c t i o n a r y phaseDict_ . 24. The implementation le shows slightly greater 49 . The phase model of multiphaseEulerFoam features a method named correct().6. For general information on diff see Section 44.x and OpenFOAM-2. With OpenFOAM-2. The phase model class is used in conjunction with a class for the two-phase system. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 namespace Foam { c l a s s phaseModel : public volScalarField .x-61b850bc107b and 2.2.3.3 In this section we want to compare the implementation of the phase model class of the two solvers twoPhaseEuler- Foam and multiphaseEulerFoam. x/ a p p l i c a t i o n s / s o l v e r s / m u l t i p h a s e / multiphaseEulerFoam / phaseModel / phaseModel / phaseModel . However. of the solver multiphaseEulerFoam of the versions twoPhaseEulerFoam The two-phase model of twoPhaseEulerFoam -2.2.1.1.x makes heavy use of abstractions.2 A comparison of the phase models in OpenFOAM-2. } tmp<s c a l a r F i e l d > nu ( c o n s t l a b e l p a t c h i ) c o n s t { r e t u r n thermo_−>nu ( p a t c h i ) . } tmp<v o l S c a l a r F i e l d > d ( ) c o n s t . ® ® 131 . } c o n s t phaseModel& o t h e r P h a s e ( ) c o n s t . } tmp<s c a l a r F i e l d > mu( c o n s t l a b e l p a t c h i ) c o n s t { r e t u r n thermo_−>mu( p a t c h i ) . } tmp<v o l S c a l a r F i e l d > Cp ( ) c o n s t { r e t u r n thermo_−>Cp ( ) . } v o l V e c t o r F i e l d& U( ) { r e t u r n U_. } tmp<v o l S c a l a r F i e l d > nu ( ) c o n s t { r e t u r n thermo_−>nu ( ) .3. } c o n s t s u r f a c e S c a l a r F i e l d& p h i ( ) c o n s t { r e t u r n phiPtr_ ( ) . } void c o r r e c t ( ) . autoPtr<s u r f a c e S c a l a r F i e l d > phiPtr_ . v i r t u a l bool read ( ) { return true . } c o n s t twoPhaseSystem& f l u i d ( ) c o n s t { r e t u r n f l u i d _ . c o n s t rhoThermo& thermo ( ) c o n s t { r e t u r n thermo_ ( ) .H The data members of the phase model class in twoPhaseEulerFoam -2. The data members also contain a reference to a turbulence model and a thermophysical model. v i r t u a l b o o l r e a d ( c o n s t d i c t i o n a r y& p h a s e P r o p e r t i e s ) . } tmp<v o l S c a l a r F i e l d > kappa ( ) c o n s t { r e t u r n thermo_−>kappa ( ) . autoPtr<diameterModel> dPtr_ . This makes the phase model class aware of the other phase. } s u r f a c e S c a l a r F i e l d& alphaPhi ( ) { r e t u r n alphaPhi_ . } } // End namespace Foam Listing 199: A boiled-down version of the le phaseModel. public : // Member F u n c t i o n s c o n s t word& name ( ) c o n s t { r e t u r n name_ . autoPtr<PhaseCompressibleTurbulenceModel<phaseModel> > t u r b u l e n c e _ .17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 s u r f a c e S c a l a r F i e l d alphaRhoPhi_ . } s u r f a c e S c a l a r F i e l d& alphaRhoPhi ( ) { r e t u r n alphaRhoPhi_ . c o n s t PhaseCompressibleTurbulenceModel<phaseModel>& turbulence () const . s c a l a r alphaMax ( ) c o n s t { r e t u r n alphaMax_ . } c o n s t s u r f a c e S c a l a r F i e l d& alphaRhoPhi ( ) c o n s t { r e t u r n alphaRhoPhi_ . } rhoThermo& thermo ( ) { r e t u r n thermo_ ( ) . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. } s u r f a c e S c a l a r F i e l d& p h i ( ) { r e t u r n phiPtr_ ( ) . } c o n s t v o l S c a l a r F i e l d& rho ( ) c o n s t { r e t u r n thermo_−>rho ( ) . } tmp<v o l S c a l a r F i e l d > mu( ) c o n s t { r e t u r n thermo_−>mu( ) . This is up to now the greatest generalisation V ® ® ® This oering is not approved or endorsed by ESI Group. ESI-OpenCFD or the OpenFOAM Foundation. } c o n s t v o l V e c t o r F i e l d& U( ) c o n s t { r e t u r n U_. } c o n s t s u r f a c e S c a l a r F i e l d& alphaPhi ( ) c o n s t { r e t u r n alphaPhi_ . PhaseCompressibleTurbulenceModel<phaseModel>& turbulence () .x contain a reference to the twophase model class. }. In twoPhaseEulerFoam -2.solve(). The header and the implementation le are largely identical. As the class name suggests. Thus. 24.g. The phase pair models are used for blending the interfacial momentum exchange models. //− Heat t r a n s f e r model autoPtr<B l e n d e d I n t e r f a c i a l M o d e l <h e a t T r a n s f e r M o d e l > > h e a t T r a n s f e r _ . There is also a method to access the other phase. i. ESI-OpenCFD or the OpenFOAM Foundation. 24. //− V i r t u a l mass model autoPtr<B l e n d e d I n t e r f a c i a l M o d e l <virtualMassModel > > vi rtual Mass _ . Listing 200 shows the members of the class related to momentum exchange models.we could observe in the multi-phase solvers of OpenFOAM. the class twoPhaseSystem provides methods to access the respective force terms or the respec- tive coecients. Phase models Two data members of the class are the two involved phase models phase1_ and phase2_.6. The most obvious purpose of this class is the implementation of the phase continuity equation. We have seen this force terms and coecients in action in Section 22. the entirety of the involved phases.3 and this class seems to be a consequent continuation of ideas introduced in the class focus on the class OpenFOAM-2.3. //− Wall l u b r i c a t i o n model autoPtr<B l e n d e d I n t e r f a c i a l M o d e l <t u r b u l e n t D i s p e r s i o n M o d e l > > t u r b u l e n t D i s p e r s i o n _ . The classes phasePair and orderedPhasePair provide an elegant way to deal with this situation. //− Wall l u b r i c a t i o n model autoPtr<B l e n d e d I n t e r f a c i a l M o d e l <w a l l L u b r i c a t i o n M o d e l > > w a l l L u b r i c a t i o n _ . this operation is possible. //− Drag model autoPtr<B l e n d e d I n t e r f a c i a l M o d e l <dragModel> > drag_ .1 til the release of OpenFOAM-2. The templated class BlendedInterfacialModel<> provides functionality that is needed for all momentum exchange models.2 Phase system classes In a multiphase solver we can not only create an abstraction for the physical phase. As there are only two phases involved. 1 2 3 4 5 6 7 8 9 10 11 12 Listing 200: The twoPhaseSystem. Phase pair models In order to cover all possible ow situations the momentum exchange models are dened in the case pair-wise in a separated fashion.1 The class twoPhaseSystem We now take a detailled look on the class twoPhaseSystem.e. but what we really need are the contribution to the momentum equation. The class provides methods to access this phase models. drag for air dispersed in water (bubbly ow) and drag for water dispersed in air (droplet ow). V ® ® ® This oering is not approved or endorsed by ESI Group. the blending is covered by this class. We can also create an abstraction for the multi-phase system. multi- phaseEulerFoam was the forerunner for this idea. //− L i f t model autoPtr<B l e n d e d I n t e r f a c i a l M o d e l <l i f t M o d e l > > l i f t _ . Again. The template parameter of this class stands for any one of the interfacial momentum exchange models. We twoPhaseSystem.3 the class twoPhaseSystem was introduced. e. This class was introduced with twoPhaseEulerFoam - multiphaseSystem. ® ® 132 .e. Since the introduction of multiphaseEulerFoam there is a class named multiphaseSystem.2. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. i. Momentum exchange models The class has member variables for the interfacial momentum exchange models.H declaration of the momentum exchange members of the class twoPhaseSystem in A momentum exchange model alone is nice. since the class multiphaseSystem has not really evolved from the release of 2. water. In both solvers the solution of the continuity equation(s) hides behind the function call fluid. The multiphaseEulerFoam oered since its introduction in version 2.x x 2.x x multiphaseEulerFoam 2. 1 2 3 4 5 6 7 8 9 10 11 12 Listing 201: The declaration of the accessing methods for the momentum exchange coecients of the class twoPhaseSystem in twoPhaseSystem. V ® ® ® This oering is not approved or endorsed by ESI Group.2. ESI-OpenCFD or the OpenFOAM Foundation.com/infocenter/compbg/v121v141/topic/com. The phase pair class is used to deal with surface tension.xlcpp121.2.2. the nested class is hidden from the outside world 52 .0.x x 2. ® ® 133 . 24.//− Return t h e drag c o e f f i c i e n t tmp<v o l S c a l a r F i e l d > d r a g C o e f f ( ) c o n s t .bg. and drag.0 two diameter models (constant and isothermal).x) use no model for the diameter of the dispersed phase elements (). //− Return t h e l i f t f o r c e tmp<v o l V e c t o r F i e l d > l i f t F o r c e ( ) c o n s t . which is available only in twoPhaseEulerFoam.ibm. no model Constant Isothermal IATE x x twoPhaseEulerFoam 2.3.html for details. //− Return t h e h e a t t r a n s f e r c o e f f i c i e n t tmp<v o l S c a l a r F i e l d > h e a t T r a n s f e r C o e f f ( ) c o n s t .3. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.x x x 2.1. OpenFOAM Constant. multiphaseSystem.1 No model The older versions of twoPhaseEulerFoam (≤ 2. This class seems to be the ancestor of the Phase pair The class multiphaseSystem declares a nested class interfacePair.3.x x x 2. In all of these versions the phase diameter is a scalar of type the transportProperties dimensionedScalar that is read from dictionary.doc/language_ref/cplr061.ibm. With twoPhaseEulerFoam -2.1.H 24. Thus.1.x x 2.dhe. 52 See http://pic. //− Return t h e w a l l l u b r i c a t i o n f o r c e tmp<v o l V e c t o r F i e l d > w a l l L u b r i c a t i o n F o r c e ( ) c o n s t .x x x Table 4: Overview of diameter modelling in Eulerian multiphase solvers 24.2 The class multiphaseSystem The solver multiphaseEulerFoam uses the class class twoPhaseSystem.3 Diameter models As mentioned in the previous Section.3 a further diameter model was introduced. diameter models were introduced at some point in the multiphase models.2. //− Return t h e w a l l l u b r i c a t i o n f o r c e tmp<v o l V e c t o r F i e l d > t u r b u l e n t D i s p e r s i o n F o r c e ( ) c o n s t . A nested class is a class denition within another class. which by denition is a property of a pair of phases. //− Return t h e v i r t u a l mass c o e f f i c i e n t tmp<v o l S c a l a r F i e l d > v i r t u a l M a s s C o e f f ( ) c o n s t . (79) the local diameter is computed (Line 10).html.3 Isothermal Gas bubbles change their diameter as the ambient pressure changes. Generally. the diameter is still a scalar which is read from However. 24. private data members of the class 53 An underscore (_) as sux to the variable name apparently indicates private variables. pV = nRT (75) pV = const (76) under the assumption of an isothermal state Next we introduce the bubble volume d3 π 6 (77) π π = p2 d32 6 6 (78) V = Thus. e. we gain the relation p1 d31 This leads to the isothermal diameter model r d2 = For the 3 d1 p1 p2 (79) isothermalDiameter model the user needs to specify a reference pressure and diameter.24. Listing 202 shows how a is returned. transportProperties respectively from phaseProperties.U( ) . Internally.3.php) do not explicitely say so. ® ® 134 . time ( ) . http://geosoft. phase_ . the phase model returns the diameter as a eld quantity.no/development/cppstyle.g.U( ) .3. the ideal gas law (75) governs the state of a gas. this is recommended style by other communities. Listing d() method of the class isothermalDiameter. phase_ . The reference pressure p0_ and diameter d0_ are 203 shows the 53 . Although the coding style guidelines of OpenFOAM (http://openfoam. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. mesh ( ) . timeName ( ) . volScalarField dimensionedScalar. } Listing 202: Accessing the diameter in constantDiameter. V ® ® ® This oering is not approved or endorsed by ESI Group. mesh ( ) ). The isothermalDiameter model imple- ments this behaviour by assuming the change of state to be isothermal. phase_ . d_ ) ).2 Constant The constantDiameter diameter model is the implementation of a constant diameter in a framework that allows for a variable diameter.U( ) . ESI-OpenCFD or the OpenFOAM Foundation. With Eqn.org/contrib/code-style. The private variable 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 d_ is of the type Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : diameterModels : : c o n s t a n t : : d ( ) const { r e t u r n tmp<Foam : : v o l S c a l a r F i e l d > ( new v o l S c a l a r F i e l d ( IOobject ( "d" . However. Class description in IATE. V ® ® ® This oering is not approved or endorsed by ESI Group. IATE diameter model Solves for the interfacial curvature per unit volume of the phase rather than interfacial area per unit volume to avoid stability issues relating to the consistency requirements between the phase fraction and interfacial area per unit volume. 24.H In Section 43 we cover the derviation of the governing equations implemented in OpenFOAM from the equations in [14]. 0 ) . lookupObject <v o l S c a l a r F i e l d > ( "p" ). ESI-OpenCFD or the OpenFOAM Foundation. } r e t u r n d0_*pow (p0_/p . ® ® 135 .U( ) . This model is based on [14]. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 1 .3.1 2 3 4 5 6 7 8 9 10 11 Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : diameterModels : : i s o t h e r m a l : : d ( ) const { c o n s t v o l S c a l a r F i e l d& p = phase_ . Listing 203: The method d() of the class isothermalDiameter. 0 / 3 . The solves a transport equation for the interfacial curvature kappai_.4 IATE IATE stands for interfacial area transport equation. db ( ) . This name is also the name of the folder OpenFOAM creates in the case directory. The functions objects e. With this keyword function objects can be excluded from execution. that the user has to know the intended post processing steps before starting a simulation. along a line probes save eld values at certain points streamLine 25. compute the time average of a eld quantity. there is run-time post processing. is not a program that is executeable on its own.g. This libraries contain the functions in a machine readable form. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The function objects enable run-time post processing. Every function has a name. There. The keyword enabled is optional. The big disadvantage of this method is. In our case. sample and paraView are two examples for such tools. ESI-OpenCFD or the OpenFOAM Foundation. Listing 204 shows the basic structure of such a denition. The placeholder LIBRARY marks the place where the name of the library needs to entered. run-time post processing allows for a much ner time resolution. There. Therefore. See http://www. lift and momentum sampledSet save the eld values of a certain region. for calculating forces or force coecients are an example for run-time post processing. A function object It is merely a library that is used by other programs.1 compute streamlines Denition function objects are dened in the le controlDict.openfoam. e. the function objects are called by the solvers.Part VI Postprocessing There are two principal possibilities for post processing in OpenFOAM. eldAverage forces compute the time average of eld quantities compute the forces on a body forceCoes compute force coecients.g. e. functions { NAME { type TYPE. for drag. 25 functions The functions are little programs that are part of OpenFOAM. Listing 205 shows the error message that is caused by the banana-trick. Consequently. enabled true . the function objects are not compiled into executeables.g. The compiler creates libraries when the function objects are compiled. a function dictionary is created which contains all necessary informations. This type needs to be specied at the place of the TYPE placeholder. This tools work on the written data of the solution. e. To nd out. This name is stated at the place of the NAME placeholder in Listing 204. f u n c t i o n O b j e c t L i b s ( "LIBRARY" ) . Besides that. Each function object also has a type.php for more information about run-time post processing. ® ® 136 . which functions are available. At this point some function objects are explained. VI ® ® ® This oering is not approved or endorsed by ESI Group. First.g. /* Definition 54 If OpenFOAM expects a keyword from a limited set of allowed keywords. The type needs to be from the list of the available functions.com/features/runtime-postprocessing. all data generated by the function object is stored. Run-time post processing performs certain operations on the solution data as it is generated. A function object serves for one specic purpose. the banana-trick 54 can be used. stating an invalid keyword usually causes OpenFOAM to print the list of allowed entries. there are tools that are executed after a simulation has nished. The function probes is contained in the le libsampling. The data of a specied eld is computed for this locations and written to a le. Listing 206 shows an example of the denition of a probes function object. See Section 44. The 0 folder contains the les p and U. The data generated probes1. ESI-OpenCFD or the OpenFOAM Foundation. They control as their names suggest Figure 34 shows the directory tree after a simulation ended. keywords outputControl and outputInterval are optional. directory named The the way the data is written to the hard drive.so. There.2 The function probes saves the values of certain eld quantities at specic points in space. The name of by this function is stored in the directory this sub-directory corresponds to the time at which the simulation is started. This directory contains a sub-directory. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. applied to the keyword type probes 25. outputControl timeStep . probeLocations contains a set of points. outputInterval 1.3 for more information about how to search the tutorials for specic information. VI ® ® ® This oering is not approved or endorsed by ESI Group. so ") . This function object is of the type probes. the folder probes1 contains a sub0. functions { probes1 { type probes . enabled true . ® ® 137 . Listing 206 will result in two les. The le le U p contains the values of the pressure for all locations. This is the time the simulation started.} } */ Listing 204: Denition of function objects in the le controlDict −−> FOAM FATAL ERROR: Unknown f u n c t i o n type banana Valid f u n c t i o n s are : 13 ( cellSource faceSource fieldAverage fieldCoordinateSystemTransform fieldMinMax nearWallFields patchProbes probes readFields sets streamLine surfaceInterpolateFields surfaces ) Listing 205: Output of the banana-trick . The name of this le is the elds of interest. functionObjectLibs (" l i b s a m p l i n g . fields ( p U ). The name of the function object is probes1. fields contains the names of the elds that are of interest. the will contain the values of the velocity at all locations. This information can be gained from the tutorials. This prevents les from being overwritten in case a simulation is continued at some point in time. S k i p p i n g l o c a t i o n . Listing lst:eldAverageControlDict shows an example of how this function is set up.1 Pitfalls Probe location outside the domain If the probe location is outside of the domain OpenFOAM will issue a warning message and continue with the simulation.0254 0. enabled true .0253 0 ) ). prime2Mean o f f .0508 0. Listing 207: probe location outside of the domain Unknown or non-existent eld If the probes dictionary contains elds that are not present to be probed.0253 0 ) ( 0. OpenFOAM simply continues computation. ® ® 138 . fields ( Ua { mean on . so " ) . Listing 206: The denition of probes in the le controlDict caseDirectory 0 More time steps constant polyMesh probes1 0 p U system Figure 34: A part of the directory tree after the simulation ended 25. 25. then no warning or error message will be issued. functionObjectLibs ( " l i b f i e l d F u n c t i o n O b j e c t s . 4 8 ) i n any c e l l .2.} } probeLocations ( ( 0. If the dictionary contains no valid elds to be probed. outputControl outputTime .3 eldAverage eldAverage computes time-averaged elds. functions { fieldAverage1 { type fieldAverage . VI ® ® ® This oering is not approved or endorsed by ESI Group. then the probe function will not be executed. −−> FOAM Warning : From f u n c t i o n f i n d E l e m e n t s : : f i n d E l e m e n t s ( c o n s t fvMesh&) i n f i l e p r o b e s / p r o b e s . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ESI-OpenCFD or the OpenFOAM Foundation. 0 7 5 0 0 .C a t l i n e 102 Did not f i n d l o c a t i o n ( 0 . Consequently no folder for storing the data will be created. functions { VI ® ® ® This oering is not approved or endorsed by ESI Group.} } ). .4. there is no need to specically an operation such as weightedSum. sampledSurfaceDict { // Sampling on t r i S u r f a c e type cuttingPlane . } base time . fields ( alpha ). The key points for this are the denition of a weight eld and the use of the summation operation. functions { faceObj1 { type faceSource . // Output t o l o g& f i l e ( t r u e ) o r t o f i l e o n l y log true . operation areaAverage .2 Compute volumetric ow over a boundary Listing 210 shows the denition of a function object that is used to compute the volumetric ow over a boundary face. planeType pointAndNormal . enabled true .1 Average over a plane faceSource extracts data from surfaces (faces). no weight eld is used. functionObjectLibs (" l i b f i e l d F u n c t i o n O b j e c t s . If no weight eld is dened. } } } // O p e r a t i o n : a r e a A v e r a g e /sum/ weightedAverage . Listing 209 shows how the average of a eld quantity over a cutting plane is set up. Listing 208: Denition of a eldAverage function object in the le 25.4. ® ® 139 . outputControl outputTime . pointAndNormalDict { basePoint ( 0 0 0. so ") . } interpolate true . ESI-OpenCFD or the OpenFOAM Foundation. // Output f i e l d v a l u e s a s w e l l valueOutput false . Listing 209: Denition of a faceSource function object in the le controlDict 25. normalVector ( 0 0 1 ) . .4 controlDict faceSource 25.3 ) . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. // Type o f s o u r c e : patch / f a c e Z o n e / s a m p l e d S u r f a c e source sampledSurface . The weight eld is automatically applied to the processed eld. functionObjectLibs ( " l i b f i e l d F u n c t i o n O b j e c t s .2 phi_patch_outlet. Listing 211 shows the denition of a cellSource function object. weightField alpha1. s u r f a c e F o r m a t raw . so " ) .raw U_patch_outlet. In this case the eld values are written for every time valueOutput should be disabled unless it is really needed.4. The option postProcessing faceObj1 0 faceSource. This can lead to massive disk outputControl to timeStep. 1 2 3 4 5 6 functions { airContent_left { type cellSource . The keyword valueOutput is set to the value false and marked as evil by the comment for reasons explained in Section 25.raw p_patch_outlet.faceIn { type faceSource . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.1 phi_patch_outlet. The function object calculates the volume-average value of the volume fraction of air.raw Figure 35: The content of the postProcessing folder cellSource 25. enabled true . VI ® ® ® This oering is not approved or endorsed by ESI Group. valueOutput false . Figure 35 shows the contents of the postProcessing folder after two time steps have been written to disk. ® ® 140 .4. outputControl timeStep . a part of the domain is contained in the cellZone left. functionObjectLibs (" l i b f i e l d F u n c t i o n O b j e c t s .5 The cellSource function object acts on all cells of the mesh or on the cells of a cellZone. source patch . log true . ESI-OpenCFD or the OpenFOAM Foundation. sourceName spargerInlet .raw U_patch_outlet. space usage when setting step.3 Pitfall: valueOutput The option valueOutput writes the eld values on the sampled surface to disk. operation sum. For each sampled eld the eld values on the sampled patch are written to disk in les in the surface folder. so ") .raw 0.raw p_patch_outlet. In this case. } fields ( phi1 ).3.dat surface 0. } Listing 210: Denition of a faceSource function object in the le controlDict 25. 7 8 9 10 11 12 13 14 15 16 17 18 19 20 enabled outputControl log valueOutput source sourceName operation } } true ; timeStep ; true ; f a l s e ; // e v i l cellZone ; left ; volAverage ; fields ( alpha . a i r ); Listing 211: A usage example of the cellSource function object 25.6 Execute C++ code as functionObject 55 . This feature is disabled by default. OpenFOAM makes it possible to execute C++ code as a functionObject To activate it a ag has to be changed. This is done for a single user in or system wide in $WM_PROJECT_DIR/etc/controlDict. ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict In one of these les the ag shown in Listing 212 has to be set to one. It can be, that the rst of these les does not exist, i.e. there are no user specic settings. The question of precedence (User setting over system wide setting) has not been pursued by the author. Listing 213 shows an example of this feature. The eld quantities U 1, U 2 and p are read in and some calculated values are printed to the Terminal. // Allow c a s e − s u p p l i e d C++ code (#codeStream , codedFixedValue ) allowSystemOperations 1; Listing 212: Allow case-supplied C++ code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 extraInfo { type coded ; functionObjectLibs ( " l i b u t i l i t y F u n c t i o n O b j e c t s . so " ) ; redirectType average ; code #{ c o n s t v o l V e c t o r F i e l d& U1 = mesh ( ) . lookupObject <v o l V e c t o r F i e l d >("U1" ) ; c o n s t v o l V e c t o r F i e l d& U2 = mesh ( ) . lookupObject <v o l V e c t o r F i e l d >("U2" ) ; I n f o << "max U1 = " << max(mag(U1) ) . v a l u e ( ) << " , U2 = " << max(mag(U2) ) . v a l u e ( ) << e n d l ; c o n s t v o l S c a l a r F i e l d& p = mesh ( ) . lookupObject <v o l S c a l a r F i e l d >("p" ) ; I n f o << "p min/max = " << min ( p ) . v a l u e ( ) << " , " << max( p ) . v a l u e ( ) << e n d l ; #}; } Listing 213: Dene a functionObject using C++ When the solver is invoked, the so called coded functionObject is compiled on the y. Listing 214 shows a portion of the solver output. Between the entry into the time loop and the rst calculations, the code is read from controlDict and pasted into a template of a coded functionObject. S t a r t i n g time l o o p Using dynamicCode f o r f u n c t i o n O b j e c t e x t r a I n f o a t l i n e 69 i n "/home/ u s e r /OpenFOAM/ u s e r − 2 . 1 . x/ run / twoPhaseEulerFoam / bubbleColumn / system / c o n t r o l D i c t : : f u n c t i o n s : : e x t r a I n f o " C r e a t i n g new l i b r a r y i n " dynamicCode / a v e r a g e / p l a t f o r m s / linux64GccDPOpt / l i b / libaverage_731fed868edc5a1d75988808649ac874cf00e044 . so " I n v o k i n g "wmake − s l i b s o /home/ u s e r /OpenFOAM/ u s e r − 2 . 1 . x/ run / twoPhaseEulerFoam / bubbleColumn / dynamicCode / a v e r a g e " wmakeLnInclude : l i n k i n g i n c l u d e f i l e s t o . / l n I n c l u d e Making dependency l i s t f o r s o u r c e f i l e f u n c t i o n O b j e c t T e m p l a t e .C 55 The release notes of OpenFOAM-2.0.0 suggest that this feature was introduced with version 2.0.0. See http://www.openfoam. org/version2.0.0/ VI ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 141 Making dependency l i s t f o r s o u r c e f i l e F i l t e r F u n c t i o n O b j e c t T e m p l a t e .C ' / home/ u s e r /OpenFOAM/ u s e r − 2 . 1 . x/ run / twoPhaseEulerFoam / bubbleColumn / dynamicCode / a v e r a g e / . . / p l a t f o r m s / linux64GccDPOpt / l i b / l i b a v e r a g e _ 7 3 1 f e d 8 6 8 e d c 5 a 1 d 7 5 9 8 8 8 0 8 6 4 9 a c 8 7 4 c f 0 0 e 0 4 4 . so ' i s up t o d a t e . Courant Number mean : 1 . 6 8 5 1 7 e −05 max : 0 . 0 0 3 6 3 Max Ur Courant Number = 0 . 0 0 3 6 3 Time = 0 . 0 0 1 MULES: S o l v i n g f o r a l p h a 1 Listing 214: On the y compilation of C++ coded functionObjects OpenFOAM creates a directory named dynamicCode in the case directory. There, all les related to the coded functionObject can be found, source les as well as binaries. Figure 36 shows the directory tree after OpenFOAM compiled the coded functionObject. caseDirectory 0 constant polyMesh dynamicMesh average lnInclude Make linux64GccDPOpt platforms linux64GccDPOpt libs system Figure 36: Directory tree after compilation of a coded functionObject Execute functions after a simulation has nished 25.7.1 execFlowFunctionObjects 25.7 execFlowFunctionObjects is a post-processing tool of OpenFOAM. This tool allows the user to execute function objects after a simulation is nished. Normally, function objects are executed during the simulation. However, in some cases it is useful to apply a function to the data set of a already completed simulation, e.g. for testing the function. Dening function objects in a seperate le Listing 215 shows a le which contains only the denition of a function object. For the sake of clarity, this functionDict. Dening functions in a seperate le reects the division of labor in some way. The le controlDict is controlling the solver, whereas the le functionDict denes the function objects. The le functionDict can be included into the le controlDict by an #include statement. See Section 7.2.5 for le is named examples. FoamFile { version 2.0; format ascii ; class dictionary ; location " system " ; object functionDict ; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // functions { probes1 VI ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 142 { } type p r o b e s ; functionObjectLibs (" l i b s a m p l i n g . so ") ; dictionary probesDict ; } Listing 215: Dene functions in a seperate dictionary. The le functionDict Run execFlowFunctionObejcts execFlowFunctionObjects has to be told, that the functions are dened in a seperate le. By default, the tool reads the le controlDict. By using the parameter -dict the user can specify an alternative le containing the function dictionary. e x e c F l o w F u n c t i o n O b j e c t s −noFlow − d i c t f u n c t i o n D i c t Listing 216: Invokation of execFlowFunctionObjects 25.7.2 postAverage postAverage is a small tool that is also designed to run functions on a already completed simulation. See Section 31. 26 sample sample is a simple post processor. This tool is controlled by the le sampleDict. sample extracts data from the solution of a specic region. sample can extract data from the following geometric regions: from one or several points in space along a line on a face sample is usually executed after a simulation has nished. 26.1 Usage sample. In this case sample looks for a le -dict an alternative le with a dierent name The simplest way to use sample is to call the command sampleDict located in the system directory. With the named can be specied. However, this le has to reside in the system directory. By default sample operates on all time steps. The option solution data. The option -time -latestTime can be used to sample only the latest can be used to specify a certain time or a time range to operate on. Specifying a limited number of time steps to perform sampling on signicantly reduces the time needed for this operation. The disk space used by the data generated by sample is usually in the order of up to a few megabytes. Therefore saving hard disk space is not an issue when using sample. 26.2 sampleDict The le sampleDict controls what and where data is to be sampled. 26.2.1 Output format There are 6 possible output formats (csv, gnuplot, jplot, raw, vtk, xmgr ). The dierence between the listed formats is the way how the data is organised inside the le. sample creates one le for scalar quantities and one for vector quantities. The names of the data les are built from the names of the sampled elds, the output format and the name of the geometric set. lineXuniform_Ua_Ub.csv, data format of the sampled data is comma seperated values VI Ua (csv). this le contains the velocity elds ® and Ub along the line ® lineXuniform. ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® E.g. The 143 26.2.2 Fields The elds that are to be sampled are listed in the list fields. Invalid entries are ignored, without any warning message. In the example of Listing 217 the list of elds contains the name banana. However, there is no eld named banana, so sample will simply ignore this entry sample will not issue any warning or error message. Thus, a typo in the sampleDict is not that easy to nd. sample reports no warning but the intended eld is not sampled. Always double check the entries in the elds sub-dictionary for typos, especially when sampling elds with composite names, e.g. U2Mean or U2Prime2Mean. // F i e l d s t o sample . fields ( alpha banana Ua Ub ); Listing 217: Fields to sample in the le sampleDict 26.2.3 Geometric regions The geometric regions on which sample can operate are sets A set can contain one or several points or a line. Along a line, points can be distributed in an equidistant fashion. surfaces A surface can be dened in several ways. Possible are, among others, cutting planes or iso-surfaces. 26.2.4 Pitfalls Missing keywords If the keywords sets and surfaces are missing in sampleDict, sample will run without producing any error messages or any data. If in Listing 218 the word banana would be replaced by sets and orange by surfaces, sample would work as expected. If sample is called with a sampleDict like in Listing 218, sample produces no data and issues no warning. setFormat raw ; s u r f a c e F o r m a t vtk ; formatOptions { ensight { format a s c i i ; } } interpolationScheme cellPoint ; fields ( p U ); banana ( lineX1 { type axis start end VI uniform ; distance ; (0.0015 0.5027 0.05) ; (0.0995 0.5027 0.05) ; ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 144 ); } nPoints 20; orange ( ); Listing 218: Not working example of sampleDict Faulty line denition If the data along a line is to be sampled and the denition of the line is errorneous so that the line is outside the domain, sample will issue a warning message. Listing 219 shows an example of such a warning message. However, sample will not report an error and it will nish its run. So, when the output of sample is not checked, this might go unnoticed. −−> FOAM Warning : From f u n c t i o n s a m p l e d S e t s : : combineSampledSets ( . . ) i n f i l e sampledSet / s a m p l e d S e t s / s a m p l e d S e t s .C a t l i n e 102 Sample s e t l i n e X 0 has z e r o p o i n t s . Listing 219: Warning message of sample due to a faulty line denition 27 ParaView ParaView is a graphical post-processor. This program is called by invoking the command paraFoam. paraFoam is a script that calls ParaView with additional OpenFOAM libraries. 27.1 View the mesh Besides viewing and post-processing simulation results, ParaView can be used to view the mesh. When rening a mesh it is important to check neighbouring blocks for the transition of mesh neness. Figure 15 in Section 13 shows an example how ParaView displays a mesh. Pitfall: default selection If a user works on the renement of the mesh and the denition of boundary conditions has not been made, then calling ParaView can crash because of its default selection of the pressure eld. After pressing the Apply button ParaView tries to read in all selected elds. In case of a faulty denition of the boundary elds, this ends in the termination of the program. Listing 220 shows a corresponding error message. −−> FOAM FATAL IO ERROR: keyword bottom i s u n d e f i n e d i n d i c t i o n a r y "/home/ u s e r /OpenFOAM/ u s e r − 2 . 1 . x/ run / icoFoam / c a s e 0 1 /0/p : : b o u n d a r y F i e l d " f i l e : /home/ u s e r /OpenFOAM/ u s e r − 2 . 1 . x/ run / icoFoam / c a s e 0 1 /0/p : : b o u n d a r y F i e l d from l i n e 25 t o li ne 35. From f u n c t i o n d i c t i o n a r y : : s u b D i c t ( c o n s t word& keyword ) c o n s t i n f i l e db/ d i c t i o n a r y / d i c t i o n a r y . C a t l i n e 4 6 1 . FOAM e x i t i n g Listing 220: Reading error due missing boundary eld denition VI ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 145 Viewing the mesh In this case the pressure eld has to be manually unselected. If no elds are selected, paraView only reads the mesh information. Therefore, it is possible to view the mesh without the rest of the case properly set up. After the Apply button has been pressed and paraView has read all the data, the user has to choose from the representation drop-down menu in the toolbar the option Surface with edges . Figure 37: Select the proper representation to view the mesh VI ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 146 Part VII External Tools Besides paraView, there are a number of other useful tools, which do not come from the OpenFOAM Foundation. This section will cover such tools. 28 pyFoam 56 scripts. These scripts are mostly written to serve one specic task. pyFoam is a collection of useful Python Further information can be found at 28.1 http://openfoamwiki.net/index.php/Contrib_PyFoam. Installation The installation of pyFoam is described at http://openfoamwiki.net/index.php/Contrib_PyFoam#Installation. The major prerequisite for the use of pyFoam is, that a Python interpreter is installed. To check if a Python python --version in the Terminal. If a version number is Python 2.7.3, then Python is installed. Otherwise, the operating system would display an error message, stating that the command python can not be found. Further information about Python are found at http://python.org/ and http://docs.python.org/. interpreter is installed on the system, simply type displayed, like 28.2 pyFoamPlotRunner The script pyFoamPlotRunner starts a simulation and plots the residuals like Fluent would do. user@ host : ~ /OpenFOAM/ u s e r − 2 . 1 . x/ run / twoPhaseEulerFoam / columnCase$ pyFoamPlotRunner . py twoPhaseEulerFoam Listing 221: Calling pyFoamPlotRunner 28.2.1 Plotting options Listing 222 shows the plotting options oered by pyFoam. What t o p l o t −−−−−−−−−−−− P r e d e f i n e d q u a n t i t i e s t h a t t h e program l o o k s f o r and p l o t s −−no− d e f a u l t −−no− l i n e a r −−no− c o n t i n u i t y −−no−bound −−with − i t e r a t i o n s −−with −c o u r a n t −−with − e x e c u t i o n −−with − d e l t a t −−with − a l l Switch o f f t h e d e f a u l t p l o t s ( l i n e a r , c o n t i n u i t y and bound ) Don ' t p l o t t h e l i n e a r s o l v e r c o n v e r g e n c e Don ' t p l o t t h e c o n t i n u i t y i n f o Don ' t p l o t t h e bounding o f v a r i a b l e s P l o t t h e number o f i t e r a t i o n s o f t h e l i n e a r s o l v e r P l o t t h e courant −numbers o f t h e f l o w P l o t t h e e x e c u t i o n time o f each time − s t e p ' P l o t t h e t i m e s t e p − s i z e time − s t e p Switch a l l p o s s i b l e p l o t s on Listing 222: Plotting ags of the pyFoamPlot* utilities 28.3 pyFoamPlotWatcher The script pyFoamPlotWatcher is intended to visualize solution data (e.g. residuals, time steps, Courant number, etc.) after the simulation has nished. This requires that the solver output is written into a le, see Section 8.1.1. pyFoamPlotWatcher does essentially the same job as pyFoamPlotRunner with the dierence that the former tool is for nished simulations and the latter monitors a running simulation. So the description of the features of pyFoamPlotWatcher holds also true for pyFoamPlotRunner. 56 Python is an interpreted programming language. VII ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 147 user@ host : ~ /OpenFOAM/ u s e r − 2 . 1 . x/ run / twoPhaseEulerFoam / columnCase$ pyFoamPlotWatcher . py LOGFILE Listing 223: Calling pyFoamPlotWatcher By default pyFoamPlotWatcher plots the curves of the residuals, continuity information and bounded variables. With options several other curves can be plotted (e.g. time step, iterations, Courant number, etc.). With regular expressions user specied data can be extracted from the log le. Listing 224 shows the invokation of pyFoamPlotWatcher to plot additionally to the default selection also the Courant number. The processing of the solver output stored in the le with a specic value 0.1 s in this case. There is also a --start LOGFILE is limited with the option --end option. The plot created by the command in Listing 224 is shown in Figure 38. pyFoamPlotWatcher . py LOGFILE −−end =0.1 −−with −c o u r a n t Listing 224: Calling pyFoamPlotWatcher with some options Figure 38: The Courant number plotted with pyFoamPlotWatcher. 28.3.1 Custom regular expressions With regular expressions pyFoamPlotWatcher can extract arbitrary data from the solver output. This section elaborates this feature by the example of plotting the Courant number based on the relative velocity of a two-phase solver. General information pyFoamPlotWatcher has no option to display the history of the Courant number based on Ur, the relative velocity between the phases. Listing 225 shows some lines of the solver output of the two-phase solver twoPhaseEuler- Foam. The line in red displays the Courant number based on the relative velocity Ur. The line above the red colored line displays the Courant number based on the mixture velocity, see Section 35.5.4 and 35.5.4 for information on the denition of the Courant number and the Courant number of the two-phase solver twoPhaseEulerFoam. DILUPBiCG : S o l v i n g f o r k , I n i t i a l r e s i d u a l = 0 . 0 0 0 8 2 4 9 2 1 , F i n a l r e s i d u a l = 1 . 4 7 5 9 5 e − 06 , No Iterations 2 ExecutionTime = 7 0 8 7 0 . 7 s ClockTime = 71186 s Calculating averages Courant Number mean : 0 . 1 0 3 4 8 5 max : 0 . 4 2 2 5 1 7 Max Ur Courant Number = 0.448791 deltaT = 0.00380929 VII ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 148 The new format looks resembles an OpenFOAM dictionary. ESI-OpenCFD or the OpenFOAM Foundation. The need for plotting the Courant number based on Ur emanated from a trouble-shooting episode. DILUPBiCG : S o l v i n g f o r beta . 5 8 4 8 MULES: S o l v i n g f o r a l p h a 1 MULES: S o l v i n g f o r a l p h a 1 Listing 225: Some lines of the solver output of twoPhaseEulerFoam Extracting the information To extract the information from the log le we need to create a le containing the regular expression. If the le containing the regular expression has another name or is located inanother place the option --regexp-file=REG_EXP_FILE can be used to specify the path to that le. but this entry can be omitted.g. The goal is to draw curves of the quantities of the red line. The plotting utilities of pyFoam oer the --dump-custom-regegexp option to generate the custom regular expression in the new format from the old format. this le will be processed automatically. 28. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. {" expr " : "Max Ur Courant Number = (% f %)" . "name":"UrCoNum").3. Thus this section was written to preserve the gained knowledge. I n i t i a l r e s i d u a l = 0 . Listing 228 shows the corresponding regular expression. 3 6 1 6 2 e − 08 .3. F i n a l r e s i d u a l = 7 . This new format was introduced with version 0.Time = 7 2 . 0 0 0 3 0 7 6 6 6 . Listing 226 contains comma seperated entries ("expr" and from the name of the entries (e.5. " name " : "UrCoNum"} Listing 226: The le If pyFoamPlotWatcher nds a le named customRegexp customRegexp in the case directory. The second provides the name of the extracted data. Listing 229 is the result of this operation. Figure 39: The Courant number based on the relative velocity plotted with pyFoamPlotWatcher The absurdly high value of the Courant number indicates that the simulation did not go well.2 Custom regular expression revisited The plotting utilities of pyFoam (pyFoamPlotRunner and pyFoamPlotWatcher ) accept custom regular expressions also in a dierent format than the format of Listing 226. "name").net/index. No Iterations 2 VII ® ® ® This oering is not approved or endorsed by ESI Group.php/Contrib_PyFoam#Plotting_with_customRegexp-files See for fur- ther information. http://openfoamwiki. ® ® 149 . Listing 227 shows an example of the solver output that will be post-processed. The values are seperated by a colon The rst entry contains the regular expression to extract the data. 218343 Bubble l o a d = 0 . type r e g u l a r . Listing 231 shows the corresponding regular expression.0168317 Min(alpha1) = 3. The parentheses are interpreted by the regular expression. " name " : " C o n c e n t r a t i o n " . ESI-OpenCFD or the OpenFOAM Foundation.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions VII ® ® ® This oering is not approved or endorsed by ESI Group. So the following example is also valid. 57 E. In order to deal with parentheses in the solver output they need to be escaped properly. ® ® 150 . 0 0 6 2 3 1 9 8 Min b e t a = 0 Max b e t a = 0 . x l a b e l "Time [ s ] " .0334048 Listing 230: Some lines of the solver output of twoPhaseEulerFoam {" expr " : " D i s p e r s e d phase volume f r a c t i o n = (% f %) Min\( a l p h a 1 \) = (% f %) " . c u m u l a t i v e = − 0. Listing 230 shows some lines of solver output of twoPhaseEulerFoam. Note the escaped parentheses marked in red. The same is true for brackets. 9 6 Listing 227: Some lines of the solver output to post-process {" expr " : " C o n c e n t r a t i o n = (% f %) " : [ " avg " . p e r s i s t no . " min " . r a i s i t no . 0 0 0 5 1 4 2 7 3 .g. 0 6 7 7 9 0 4 Time = 1 9 . 6 5 7 1 1 e − 06 . "max " ] } Max\( a l p h a 1 \) = (% f %) Listing 231: The regular expression to extract the information about the volume fraction 57 or detailed Not only the parentheses have a special meaning in regular expressions. " min " . t h e T i t l e "Custom 1 − C o n c e n t r a t i o n " . 0 8 8 2 6 e − 05 .2 GAMG: S o l v i n g f o r p . No Iterations 1 Concentration = 0. I n i t i a l r e s i d u a l = 0 . " name " : " Volume f r a c t i o n " .DILUPBiCG : S o l v i n g f o r T. No Iterations 1 time s t e p c o n t i n u i t y e r r o r s : sum l o c a l = 2 . " t i t l e s " : [ " avg " . http://stackoverflow. g l o b a l = 4 . " t i t l e s Listing 228: The custom regular expression in the odl format Custom01 { accumulation f i r s t . when brackets are contained in the solver output that is to be processed with regular expressions. Listing 229: The custom regular expression in the new format 28. In order to post-process these lines with regular expressions these parentheses need to be escaped in the regular epxression. I n i t i a l r e s i d u a l = 9 . titles ( avg min max ). Time = 1 9 . } Max T = (% f %) " .92503e-87 Max(alpha1) = 0. expr " C o n c e n t r a t i o n = (% f %) Min T = (% f %) name Custom01_Concentration . 9 9 5 7 MULES: S o l v i n g f o r a l p h a 1 MULES: S o l v i n g f o r a l p h a 1 Dispersed phase volume fraction = 0.00498731 Max T = 0. "max " ] } Min T = (% f %) Max T = (% f %)" . The line marked in red contains parentheses. F i n a l r e s i d u a l = 1 .3.3 Special treatment of certain characters Note that the solver output we processed so far contained no parentheses. F i n a l r e s i d u a l = 2 . 5 1 5 7 4 e − 08 . enabled yes . An internet search knowledge on regular expressions will yield the knowledge which characters have to be escaped. 4 6 2 6 9 e − 05 . 5 7 2 7 9 e − 07 . with l i n e s .0509085 Min T = 0. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 3. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.Volume fraction 0. ® ® 151 .005 0 0 2 4 6 8 10 12 14 16 18 20 Time [s] Figure 40: The average volume fraction plotted with pyFoamPlotWatcher and a custom regular expression 28. By default a PNG image is produced but with the option --format-of-hardcopy=HARDCOPYFORMAT other formats can be chosen.+ to ignore the second and third number.28. The option --write-files causes pyFoam to write the extracted data to the hard drive. VII ® ® ® This oering is not approved or endorsed by ESI Group. In this special case this seems an overkill we could also delete parts of the expression since we are only interested in the rst number but if we are interested in the rst and the third number.3. Custom 1 .02 0.5 Producing images The Figures 38 and 39 are screenshots of the images plotted by pyFoamPlotWatcher. Figure 40 shows the plot produced by the regular expression of Listing 231.6 Writing data Producing images is often not enough for post-processing.01 0.025 avg 0. ESI-OpenCFD or the OpenFOAM Foundation. there is the that tells the pyFoam plot utilities to save the plots on the disk.7 Case analysis The option --with-all generate a number of plots that can be helpful to examine the performance of simulation case. then we need to ignore the second number. If we are interested in only the rst number the average volume fraction we replace the second and third (%f%) with a . 28.4 Ignoring stu Listing 231 extracts three numbers from the line marked in Listing 230. option --hardcoded However.3.015 0.3. 28. Thus the extracted data can be processed by other programs. Using this regular expression plots all three curves. See Listing 222 for an explanation of the available plots. In Listing 233 the script is called with two arguments. there are various command line arguments to control the operation of the script.6 pyFoamDecompose This script is used to decompose the computational domain. From this arguments. that pyFoamClearCase is an executable script rather than a program on its own. 28. pyFoamClearCase cleans the case directory. The rst argument is the path to the case directory. copy also the latest time step or the processor* directories. It also indicates. pyFoamDecompose creates a decomposeParDict. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. By default the 0. does not need an existing decomposeParDict decomposeParDict. The occasional writing of the data to harddisk are clearly visible as spikes in the execution time. 28. script where to save the newly created le. This ending indicates. py . The options cause pyFoamClearCase to keep the last time directory and to remove all processor* folders. e. that the script is written in Python. Additionally.Figure 41: The execution time plotted over time with pyFoamPlotWatcher. This script deletes all time directories save the 0 directory. VII ® ® ® This oering is not approved or endorsed by ESI Group. pyFoamClearCase . the constant and the system directory are copied. The second argument is the most fundamental information for The rst argument is necessary to tell the domain decomposition the number of sub-domains. generates the and calls decomposePar. Listing 232 shows how this script is executed. ® ® 152 . In this case the dot refers to the currect directory.4 pyFoamClearCase As the name implies.5 pyFoamCloneCase This script is used to copy a case. −−keep − l a s t −−remove− p r o c e s s o r Listing 232: Calling pyFoamClearCase Note the le ending . Some of these options are: keep-last keep the last time step keep-regular after=T keep all time steps delete all time steps for remove-processor t>T delete the processor* directories The script is invoked by typing its name in the Terminal.g. Other than the tool decomposePar. a ner control of the actions of pyFoamClearCase is possible. this script This script receives command line arguments. ESI-OpenCFD or the OpenFOAM Foundation. The second argument is the number of sub-domains. 28.py after the name of the script. By the use of command line options. so blockMesh produces an error message instead of creating a mesh. object nix . format a s c i i . // * * * * * * * * * // FoamFile { version 0.7 Decomposer. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. case "CASE" . pyFoamDisplayBlockMesh is a tool that allows the user to visualise a faulty mesh. py . so vertex number 5 should not be part of this block. pyFoamDisplayBlockMesh does exactly what the name of the tool suggests.6. It reads blockMeshDict and displays the topology of the mesh. that that's exactly what is described in Section 11. One might think. pyFoamDecompose . The blocks shown in Figure 42 have a faulty denition. blockMesh will not create a mesh and paraView is therefore not able to display the blocks. In the main panel the vertices and the edges are displayed. VII ® ® ® This oering is not approved or endorsed by ESI Group. With the two sliders below single blocks as well as patches can be marked and coloured. The marked block should be in the right part of the geometry. r o o t "ROOT" . The local axes of a single block are displayed as tubes labelled with the corresponding names of the axes.g. an error in the block denition. the cause for the error is easily found. pyFoamDisplayBlockMesh If there is a problem with mesh topology and one isn't able to nd the error in the blockMeshDict. numberOfSubdomains 4 . In Figure 42 a screenshot of the GUI of this tool is shown.5. especially when there are more than one blocks.logfile. ® ® 153 . ESI-OpenCFD or the OpenFOAM Foundation. this tool can be of great help. scotchCoeffs { } Listing 234: The le decomposeParDict generated by pyFoamDecompose decomposeParDict The output of pyFoamDecompose is stored in the le 28.There is a large number of additional arguments which allow to exert more control over the way the domain is decomposed. This is of great help to nd e. 4 Listing 233: Invokation of pyFoamDecompose Listing 234 contains the decomposeParDict created by the command of Listing 233.1 (display the blocks with paraView ). if the denition of the mesh is erroneous. class dictionary . However. With the help of this tool. } method s c o t c h . swak4foam evolved from a collection of tools like groovyBC. These utilities can be executed from the menu of this tool.Figure 42: Screenshot of pyFoamDisplayBlockMesh Right of the main panel the output of the standard meshing utilities blockMesh and checkMesh can be displayed (not shown in the picture). py −− f u l l − r e p o r t . ® ® 154 . VII ® ® ® This oering is not approved or endorsed by ESI Group. The second The third command changes the working directory of the terminal to the newly created folder and the last commands actually downloads the source code to the current directory. pyFoamCaseReport . However. the full information lies within the dictionaries of the case. is a version control software to manage software projects. 58 subversion.php/Contrib/swak4Foam. The source code of swak4foam is managed by the use of a subversion 58 repository.8 pyFoamCaseReport The tool pyFoamCaseReport generates a summary of the simulation case. 28. Listing 236 shows how the source code is downloaded by subversion. The documentation of swak4foam is located at //openfoamwiki. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. This tool provides only selected information. abbreviated SVN. The rst command changes the working directory of the terminal to command creates a directory named swak4foam.1 http: Installation To install swak4foam one needs to download the source code and compile them.net/index. Listing 235 shows how to create a full summary of a case. 29. Moreover. funkySetFields and simpleFunctionObjects. the blockMeshDict can be edited with this tool. ESI-OpenCFD or the OpenFOAM Foundation. The amount of information displayed can be controlled by command line ags. Listing 235: Create a summary of the case with pyFoamCaseReport 29 swak4foam The name swak4foam comes from SWiss Army Knife for Foam. ~/OpenFOAM. ESI-OpenCFD or the OpenFOAM Foundation.2. sample ) are of little use. the tools of OpenFOAM (probes. Listing 238 shows how this function is set up as a function object in the le example the minimal value of the eld alpha controlDict. e x p r e s s i o n "min ( a l p h a ) " . The functions of this library are used to post process data and extend functionality of OpenFOAM. verbose true .3 for further information about using external libraries. In Listing 237 some line of the standard output of twoPhaseEulerFoam are shown. DILUPBiCG : S o l v i n g f o r No I t e r a t i o n s 2 D i s p e r s e d phase volume DILUPBiCG : S o l v i n g f o r No I t e r a t i o n s 2 D i s p e r s e d phase volume alpha . so ") . f r a c t i o n = 0. However. 6 Listing 237: Solver-Ausgabe von twoPhaseEulerFoam swakExpression The function to do the job is called swakExpression. 0 / l i b r a r i e s /swak4Foam/ Listing 236: Installation of swak4foam After downloading. simpleSwakFunctionObjects simpleSwakFunctionObjects is an extension of simpleFunctionObjects. 0 0 8 2 4 2 7 6 Min ( a l p h a ) = − 1. s o u r c e f o r g e .31819 e −19 Max( a l p h a ) = 0 . This function is part of the library libsimpleSwakFunc- tionObjects. ® ® 155 . F i n a l r e s i d u a l = 8 . n e t / s v n r o o t / openfoam −extend / trunk / Breeder_2 . I n i t i a l r e s i d u a l = 3 . a c c u m u l a t i o n s ( min ) .00824276 Min ( a l p h a ) = − 3. 29. In this is saved. I n i t i a l r e s i d u a l = 3 . simpleSwakFunctionObjects provide the solution.2. svn . The corresponding lines of source code can serve as a blueprint for a solver modication.2 Allwmake. 4 8 3 9 1 e − 05 .66816 e −19 Max( a l p h a ) = 0 . Listing 238: Denition of the function swakExpression in the le VII ® ® controlDict ® This oering is not approved or endorsed by ESI Group. f r a c t i o n = 0 . 1 6 1 1 5 e − 14 . Notice the statement in last line of the Listing. This library contains the function swakExpression. 6 alpha . the sources need to be compiled by calling 29. 9 4 1 1 1 e − 12 . } } l i b s (" libsimpleSwakFunctionObjects . functions { minAlpha { type s w a k E x p r e s s i o n .1 Extrema of a eld quantity If only the extrema of a eld quantity are of interest.cd ~/OpenFOAM mkdir swak4foam cd swak4foam svn c h e c k o u t h t t p s : / / openfoam −extend . This solver prints the mean value as well as the extrema of the volume fraction of the dispersed phase. One way of solving this problem could be. valueType i n t e r n a l F i e l d . to modify the solver to write the extrema to the standard output. See Section 7. This statement tells the solver to use the specied library. F i n a l r e s i d u a l = 2 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 7 1 5 6 3 e − 07 . if the user is not inclined to modify and compile OpenFOAM solvers. In this case. Also the fact that the minimum and maximum values of face area or cell volume dier by up to three orders of magnitude should lead to the same conclusion. Face a r e a magnitudes OK. 7 9 3 8 Non− o r t h o g o n a l i t y check OK.com/Forums/openfoam/70798-blockmesh-double-grading. However.2 Usage To discern between normal grading and double grading. type species the type the function object verbose a switch that controls whether the generated data is to be printed on the solver output or not. The very high aspect ratio is an indicator that something is wrong with the mesh. Maximum f a c e a r e a = 1 . 8 3 9 5 e − 08. This can be a simple statement or a formula computing a {internalField cellSet faceZone patch faceSet set surface cellZone} Allowed entries: quantity. checkMesh issues not even a warning message. 30. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Mesh non− o r t h o g o n a l i t y Max : 4 2 .cfd-online. There is also a page in the OpenFOAM Wiki (http://openfoamwiki.com/Forums/openfoam/103504-swak4foam-calculating-velocity-transformations.net/index. 30 blockMeshDG blockMeshDG is a modication of the meshing tool blockMesh to allow for double grading. ESI-OpenCFD or the OpenFOAM Foundation. 59 http://www.html). that the ratio between the discretisation length of the middle and the ends of an edge is prescribed. The data is written into a le anyway. C e l l volumes OK.max. This tool was developed by some users of OpenFOAM and is was published in the CFD-Online OpenFOAM Forum (http://www.cfd-online. Unfortunately. ® ® 156 . Double grading means. Figure 43 shows the resulting mesh. Max volume = 4 . A positive entry causes normal grading to be applied just like it is the case with the standard utility. 9 2 2 1 4 e − 05. The make script creates an executable named blockMeshDG.Keywords This section explains the most important keywords of Listing 238.1 Uneven number of cells blockMeshDG obviously has a problem with an uneven number of cells.1 Installation The downloaded source code is ready for compilation after unpacking. Checking geometry . 59 : accumu- For instance if you use a swakExpression-FO to print the maximum and minimum of your eld to the screen.html 60 A negative entry unequal to unity causes blockMesh to crash with a oating point exception. grading 30. Min volume = 9 . 2 1 8 6 4 e − 08.3. expression denes the quantity that is sought for. Therefore. 2 3 0 4 a v e r a g e : 1 1 . 5 9 8 7 5 e − 11. accumulations allowed entries: {min. Listing 239 shows some lines of the output of checkMesh. using negative entries for double grading does not alter the standard behaviour.average. . T o t a l volume = 4 . the output of checkMesh contains some indications that something is not alright. 6 8 7 4 6 e − 05. All necessary entries have already been made to prevent the new utility to collide with the standard utilities of OpenFOAM. although the mesh is of bad quality. the expansion ratio needs to be negative for double 60 . Max a s p e c t r a t i o = 81 OK. Minimum f a c e a r e a = 3 . Quote from the CFD-Online Forum lations is only needed if you need a single number to print to the screen.3 Pitfalls 30.sum}. . when 15 cells are used for the double graded edge. valueType denes the type of the geometric region on which the function is applied. checkMesh reports no error. 30.php/Contrib_blockMeshDG). VII ® ® ® This oering is not approved or endorsed by ESI Group. The idea line and most Forum of the source code for this tool stems from the CFD On- [http://www.2 Source code The Listings 241 and 240 show the source code of this tool.H contains statements that allow the tool to be applied on simulation data following both the old and the new naming convention of twoPhaseEulerFoam. the tool trys to read only if the corresponding le is present. that solves no equations.1 Motivation This utility allows the user to execute functions after a simulation has nished.H.html#post237751]. Listing 239: Some output of checkMesh So far.cfd-online. the elds are read conditionally. This tool iterates Basically. 31. this tool is a solver. Figure 43: Double grading problem 31 postAverage 31. The le responsible for reading the existing elds. 0 7 9 e −05 0 . The le createFields. ESI-OpenCFD or the OpenFOAM Foundation. The source code contains the eld names.e. Otherwise the tool would abort with an error for trying to access a non-existent le. functions are executed during the run-time of the solver.Min/max edge l e n g t h = 3 . 0 0 5 0 8 0 3 5 OK.H contains all statements The functions can only be applied to elds that were created in createFields. the only solution to this problem is to use an even number of cells. Normally. I. over all time steps and executes the functions at run-time. In order to avoid writing a seperate tool for each naming scheme. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. VII ® ® ® This oering is not approved or endorsed by ESI Group.com/Forums/openfoam-programming-development/ 70396-using-fieldaverage-library-average-postprocessing. ® ® 157 . createFields. c h a r * argv [ ] ) { argList : : noParallel () . #i n c l u d e " createMesh . I n f o << " Adding f i e l d s f o r time " << runTime . You s h o u l d have r e c e i v e d a copy o f t h e GNU Ge n er a l P u b l i c L i c e n s e a l o n g with OpenFOAM.H" #i n c l u d e " c r e a t e T i m e .C /* −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− r e a d always −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ 1 2 3 VII ® ® ® This oering is not approved or endorsed by ESI Group. ESI-OpenCFD or the OpenFOAM Foundation. 51 F r a n k l i n St . I n f o << "\nEnd" << e n d l . setTime ( t i m e D i r s [ t i m e I ] .H" } runTime . See t h e GNU G e ne r al P u b l i c L i c e n s e f o r more d e t a i l s . t i m e S e l e c t o r : : addOptions ( ) . f u n c t i o n O b j e c t s ( ) .H" i n s t a n t L i s t t i m e D i r s = t i m e S e l e c t o r : : s e l e c t 0 ( runTime .H" f o r A l l ( timeDirs . w i t h o u t even t h e i m p l i e d warranty o f MERCHANTABILITY o r FITNESS FOR A PARTICULAR PURPOSE. setTime ( t i m e D i r s [ 0 ] . e i t h e r v e r s i o n 2 o f t h e L i c e n s e . timeI ) { runTime . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. F i f t h Floor . #i n c l u d e " setRootCase . i f not . . you can r e d i s t r i b u t e i t and/ o r modify i t under t h e terms o f t h e GNU Ge n er a l P u b l i c L i c e n s e a s p u b l i s h e d by t h e Free S o f t w a r e Foundation . } return 0. #i n c l u d e " c r e a t e F i e l d s .H" i n t main ( i n t argc . MA 02110 − 1301 USA Application p os t A ve r ag e Gerhard H o l z i n g e r based on work by E e l c o van V l i e t Description Post − p r o c e s s e s data from f l o w c a l c u l a t i o n s For each time : c a l c u l a t e s t h e time a v e r a g e o f a s e q u e n c e o f f i e l d s and w r i t e s time time a v e r a g e i n t h e d i r e c t o r y \*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ #i n c l u d e "fvCFD .1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 /*−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*\ ========= | \\ / F ield | OpenFOAM: The Open S o u r c e CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991 − 2009 OpenCFD Ltd . OpenFOAM i s f r e e s o f t w a r e . I n c . OpenFOAM i s d i s t r i b u t e d i n t h e hope t h a t i t w i l l be u s e f u l . timeName ( ) << e n d l . but WITHOUT ANY WARRANTY. // ************************************************************************* // Listing 240: The le postAverage. ® ® 158 . a r g s ) . runTime . 0 ) . Boston . o r ( a t your o p t i o n ) any l a t e r v e r s i o n . e x e c u t e ( ) . t i m e I ) . \\/ M anipulation | −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− License This f i l e i s p a r t o f OpenFOAM. w r i t e t o t h e Free S o f t w a r e Foundation . I O o b j e c t : :NO_WRITE ). runTime . } U. ® ® 159 . timeName ( ) . timeName ( ) . s e t ( new v o l V e c t o r F i e l d ( IOobject ( "Ur" . i f ( UrHeader . I O o b j e c t : :AUTO_WRITE ). runTime . I O o b j e c t : : MUST_READ. runTime . mesh . I O o b j e c t : :NO_READ ). I O o b j e c t UrHeader ( "Ur" . volScalarField p ( IOobject ( "p" . mesh )). the producer of the OpenFOAM software and owner of the OpenFOAM trademark. I O o b j e c t : :NO_READ ). timeName ( ) . timeName ( ) . mesh . mesh . I O o b j e c t : : MUST_READ. i f ( UHeader . Ur . \ n" << e n d l . I O o b j e c t : : READ_IF_PRESENT. mesh VII ® ® ® This oering is not approved or endorsed by ESI Group. mesh . \ n" << e n d l . autoPtr<v o l V e c t o r F i e l d > U. mesh ). s e t ( new v o l V e c t o r F i e l d ( IOobject ( "U" . mesh . runTime . headerOk ( ) ) { I n f o << " Reading Ur . headerOk ( ) ) { I n f o << " Reading U. 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 /* −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− r e a d o n l y i f they e x i s t −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−*/ I O o b j e c t UHeader ( "U" . runTime . I O o b j e c t : :AUTO_WRITE ). timeName ( ) . autoPtr<v o l V e c t o r F i e l d > Ur . ESI-OpenCFD or the OpenFOAM Foundation.I n f o << " Reading f i e l d p\n" << e n d l . a l p h a . autoPtr<v o l V e c t o r F i e l d > Ua . runTime . I O o b j e c t : :NO_READ ). headerOk ( ) ) { I n f o << " Reading f i e l d a l p h a \n" << e n d l . I O o b j e c t : :NO_WRITE ). I O o b j e c t : : READ_IF_PRESENT. mesh . i f ( alphaHeader . mesh )). timeName ( ) . } I O o b j e c t UaHeader ( "Ua" . autoPtr<v o l V e c t o r F i e l d > Ub . runTime . Ua . timeName ( ) . mesh . runTime . runTime . \ n" << e n d l . timeName ( ) . I O o b j e c t : : MUST_READ. mesh . headerOk ( ) ) { I n f o << " Reading Ua . mesh . mesh )).76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 } )). /* o l d naming c o n v e n t i o n f o r two−phase s o l v e r s */ /* alpha . mesh . phia . I O o b j e c t : :NO_READ ). phib */ I O o b j e c t alphaHeader ( " alpha " . I O o b j e c t : :NO_READ ). s e t ( new v o l V e c t o r F i e l d ( IOobject ( "Ua" . } Ua . Ub . ESI-OpenCFD or the OpenFOAM Foundation. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. timeName ( ) . ® ® 160 . s e t ( new v o l S c a l a r F i e l d ( IOobject ( " alpha " . runTime . autoPtr<v o l S c a l a r F i e l d > a l p h a . I O o b j e c t : :AUTO_WRITE ). I O o b j e c t UbHeader ( "Ub" . VII ® ® ® This oering is not approved or endorsed by ESI Group. i f ( UaHeader . timeName ( ) . I O o b j e c t : : MUST_READ. } Ub . I O o b j e c t : :AUTO_WRITE ). I O o b j e c t phiaHeader ( " phia " . I O o b j e c t phibHeader ( " phib " . I O o b j e c t : : MUST_READ. mesh . \ n" << e n d l . ESI-OpenCFD or the OpenFOAM Foundation. } p h i a . I O o b j e c t : :AUTO_WRITE VII ® ® ® This oering is not approved or endorsed by ESI Group. timeName ( ) . I O o b j e c t : :NO_READ ). autoPtr<s u r f a c e S c a l a r F i e l d > phib . runTime . timeName ( ) . mesh . runTime . I O o b j e c t : : MUST_READ. timeName ( ) . runTime . runTime . mesh )). i f ( phibHeader . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. timeName ( ) . \ n" << e n d l . s e t ( new s u r f a c e S c a l a r F i e l d ( IOobject ( " phia " . runTime . s e t ( new s u r f a c e S c a l a r F i e l d ( IOobject ( " phib " . headerOk ( ) ) { I n f o << " Reading phib . phib . s e t ( new v o l V e c t o r F i e l d ( IOobject ( "Ub" . I O o b j e c t : :AUTO_WRITE ). mesh . headerOk ( ) ) { I n f o << " Reading p h i a . autoPtr<s u r f a c e S c a l a r F i e l d > p h i a . headerOk ( ) ) { I n f o << " Reading Ub .148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 i f ( UbHeader . mesh . mesh )). timeName ( ) . ® ® 161 . \ n" << e n d l . I O o b j e c t : :NO_READ ). mesh . i f ( phiaHeader . I O o b j e c t : :AUTO_WRITE ). mesh )). VII ® ® ® This oering is not approved or endorsed by ESI Group. headerOk ( ) ) { I n f o << " Reading U1 . i f ( alpha1Header . I O o b j e c t : :AUTO_WRITE ). p h i 2 */ I O o b j e c t alpha1Header ( " alpha1 " . runTime . I O o b j e c t : : MUST_READ. mesh . timeName ( ) . mesh )). headerOk ( ) ) { I n f o << " Reading a l p h a 1 . \ n" << e n d l . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. I O o b j e c t : :NO_READ ). runTime . mesh . mesh . U1 . I O o b j e c t U1Header ( "U1" . runTime . ® ® 162 . \ n" << e n d l . runTime . } U1 . phi1 . s e t ( new v o l V e c t o r F i e l d ( IOobject ( "U1" . } a l p h a 1 . timeName ( ) . timeName ( ) . I O o b j e c t : :NO_READ ). I O o b j e c t : :NO_READ ). autoPtr<v o l V e c t o r F i e l d > U1 . U2 .220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 } )). timeName ( ) . autoPtr<v o l S c a l a r F i e l d > a l p h a 1 . runTime . ESI-OpenCFD or the OpenFOAM Foundation. I O o b j e c t : : MUST_READ. s e t ( new v o l S c a l a r F i e l d ( IOobject ( " alpha1 " . mesh . mesh /* new naming c o n v e n t i o n f o r two−phase s o l v e r s */ /* alpha1 . ). mesh . I O o b j e c t U2Header ( "U2" . i f ( U1Header . timeName ( ) . mesh . s e t ( new s u r f a c e S c a l a r F i e l d ( IOobject ( " phi1 " . I O o b j e c t : : MUST_READ. timeName ( ) . mesh )). VII ® ® ® This oering is not approved or endorsed by ESI Group. headerOk ( ) ) { I n f o << " Reading p h i 2 . headerOk ( ) ) { I n f o << " Reading p h i 1 . I O o b j e c t : :AUTO_WRITE ). autoPtr<s u r f a c e S c a l a r F i e l d > p h i 1 . autoPtr<s u r f a c e S c a l a r F i e l d > p h i 2 . runTime . s e t ( new v o l V e c t o r F i e l d ( IOobject ( "U2" . \ n" << e n d l . s e t ( new s u r f a c e S c a l a r F i e l d ( IOobject ( " phi2 " . } U2 . runTime . i f ( phi1Header . I O o b j e c t phi1Header ( " phi1 " . I O o b j e c t : :AUTO_WRITE ). mesh )). the producer of the OpenFOAM software and owner of the OpenFOAM trademark. p h i 2 . \ n" << e n d l . mesh . runTime . mesh . \ n" << e n d l . runTime . headerOk ( ) ) { I n f o << " Reading U2 . timeName ( ) . I O o b j e c t : : MUST_READ. I O o b j e c t : : MUST_READ. mesh .autoPtr<v o l V e c t o r F i e l d > U2 . ESI-OpenCFD or the OpenFOAM Foundation. mesh . } p h i 1 . timeName ( ) . I O o b j e c t : :NO_READ ). i f ( phi2Header . ® ® 163 . timeName ( ) . runTime . timeName ( ) . I O o b j e c t : :NO_READ ). 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 i f ( U2Header . I O o b j e c t phi2Header ( " phi2 " . mesh I O o b j e c t : :AUTO_WRITE Listing 241: The le VII ® createFields. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ). ® ® 164 . ESI-OpenCFD or the OpenFOAM Foundation.H ® ® This oering is not approved or endorsed by ESI Group.364 365 366 367 368 } )). also bear the number of the phase (rho1 and rho2 ). 33.org/version2.2 OpenFOAM-2.3.2.1 twoPhaseEulerFoam There have been major changes with the two-phase Eulerian solver twoPhaseEulerFoam. VIII ® ® ® This oering is not approved or endorsed by ESI Group. The bold names are the names of les in the 0 -directory.g.x compared to OpenFOAM-2.2 postProcessing The data generated by a probes function object or by the sample utility is now stored in a folder named postProcessing.1.2 this section lists some major dierences to OpenFOAM-2. Those updates are integrated relatively fast into the Git repository (e. 33.1. The volume fraction is consequently named alpha1. In the course of the creation of this document OpenFOAM evolves as well.1.x Although this manual is based on OpenFOAM-2.1.2 are not directly usable in OpenFOAM-2. ® ® 165 . density.x 33.1 fvOptions The fvOptions mechanism is an abstraction to allow for a generic treatment of physical models. OpenFOAM 2. OpenFOAM-2.1 and OpenFOAM-2.3.x.1.2.x). Table 5 shows a selection of old and new names. Simulation cases of OpenFOAM-2. In larger periods a new release of OpenFOAM is published (e.2.1. See Sections 21 and 22 on details about the twoPhaseEulerFoam solver.2.g.php.x around July 2012. 33. e.3.1 OpenFOAM-2.1 Naming scheme of two-phase solvers The naming scheme of the two-phase solvers of OpenFOAM has been changed after the release of Version 2. In this chapter changes relevant to this manual will be pointed out. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.1.1). OpenFOAM 2.0/fvOptions.3. ESI-OpenCFD or the OpenFOAM Foundation. The velocities used by two-phase solvers are now named U1 and U2 instead of Ua and Ub.1 or OpenFOAM-2. http: 33. This change aected OpenFOAM-2. Other variables.openfoam.Naming scheme Phase old a Velocity alpha Ua Density Flux Volume fraction new b 1 2 Ub alpha1 U1 rhoa rhob rho1 rho2 phia phib phi1 phi2 beta alpha2 U2 Table 5: Naming scheme of quanities of twoPhaseEulerFoam Part VIII Updates 32 General remarks OpenFOAM is like any other open source project continuously updated. 33. 33 OpenFOAM 33.x This section describes changes in behaviour or usage of OpenFOAM-2.1.g. See //www.3 This folder then contains a directory with the same name as the function object.2. declaring a variable only tells the compiler that the variable exists and has a certain type.e. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.cplusplus. via is dened. However. Within the class tell the compiler what the class looks like (data we want to use the class phaseModel. that there is a class named phaseModel.html http://www. Therefore. We tell the compiler. The basic idea behind namespaces put in simple words is to keep things (variables and functions) visible where they need to be visible. information needed by now. ESI-OpenCFD or the OpenFOAM Foundation. namespace Foam { c l a s s phaseModel . phaseModel we need to introduce To be able to use the existing class this class to the compiler. This is sometimes referred to as forward declaration. Further information on that matter can be found in [27.com/tutorial/namespaces. Jasak. When we compile our class we need to make sure that we include the denition of linking to the library in which 1 2 3 4 5 6 7 8 9 10 11 phaseModel that is all the phaseModel. IX ® ® ® This oering is not approved or endorsed by ESI Group.). 34.1 A classy example In Listing 242 we dene the class phaseInterface.1. In Line 4 of Listing 242 we do exactly this. variable is assigned a value. already exists and is dened elsewhere. This class phaseModel. A denition also tells the compiler what exactly a variable is.cprogramming.com/doc/tutorial/namespaces/ http://www. methods. } Listing 242: Declaration and denition of classes 34.1 Denition vs.cprogramming. Declaration In C and C++ there is the destinction between the declaration and the denition of a variable. we phaseInterface members.com/declare_ 34.g. The declaration does not specify what the variable actually is. so there is no need for us to repeatedly dene the class Creating our own denition of phaseModel would be useless and stupid. ® ® 166 . This does not necessarily mean that the http://www.2 Namespaces Namespaces are a feature of C++ to support a logical structure within the program. etc.learncpp. we have a closer look on namespaces in OpenFOAM. General information about the concept of namespaces can be found here: http://www.html. one of the founders of OpenFOAM: OpenFOAM is an example of how to make proper use of C++.com/cpp-tutorial/711-namespaces/ Some OpenFOAM specic aspects related to namespaces are discussed in Section 35. i. e.Part IX Source Code & Programming 34 Understanding some C and C++ In this Section some features of the C++ programming language are discussed. Briey explained. Like any other method of keeping things neat and tidy you could also survive without namespaces. 18] or vs_define. to loosely quote Prof.2. class phaseInterface { // l o t s o f C++ code }. const int l i m i t = 5.2 Constants and pointers Pointing to a constant A pointer can be used to point to a constant variable. Both lines in Listing 243 are correct statements. // change t h e p o i n t e r p o i n t e r = &constVar2 . s t d : : c o u t << "The c o n s t a n t p o i n t e r p o i n t s t o " << * c o n s t P o i n t e r 1 << s t d : : e n d l . int variable = 11. ESI-OpenCFD or the OpenFOAM Foundation. int variable = 11.34. i n t c o n s t answer = 4 2 . So. Any variable can be declared constant by using the const keyword. s t d : : c o u t << "The c o n s t a n t p o i n t e r p o i n t s t o " << * c o n s t P o i n t e r 1 << s t d : : e n d l . However. the pointer will always point to the same variable. Listing 246 shows an example. However. variable = 79.3 The const correctness const keyword has several uses and using const has some implications. the variable itself can be altered. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. // p o i n t t o a non− c o n s t a n t p o i n t e r = &v a r i a b l e . The pointer itself is not constant and therefore changeable. This can precede the datatype or the variable name. the keyword const has to be used when declaring a pointer pointing to a constant variable. c o n s t i n t constVar2 = 1 3 . s t d : : c o u t << "The p o i n t e r p o i n t s t o " << * p o i n t e r << s t d : : e n d l . c o n s t i n t * p o i n t e r = &constVar1 . a pointer pointing to a constant can also point to a non-constant variable. s t d : : c o u t << "The p o i n t e r p o i n t s t o " << * p o i n t e r << s t d : : e n d l . s t d : : c o u t << "The p o i n t e r p o i n t s t o " << * p o i n t e r << s t d : : e n d l . 34. the address stored in the pointer can not be changed.3. i n t c o n s t constVar1 = 4 2 . However. i n t * c o n s t c o n s t P o i n t e r 1 = &v a r i a b l e . ® ® 167 .1 Constant variables This is the most easy part. Listing 244: Pointing to constant variables The p o i n t e r p o i n t s t o 42 The p o i n t e r p o i n t s t o 13 The p o i n t e r p o i n t s t o 11 Listing 245: Output of Listing 244 A constant pointer A pointer can be constant regardless of the variable it points to. Listing 246: Using constant pointers IX ® ® ® This oering is not approved or endorsed by ESI Group.3. Listing 243: Constant variables 34. functions enable the programmer to seperate code in a logical way. the code has to be written only once and the function can be used wherever it is necessary. int variable = 11. the performance of the program suers. This improved readability and maintainability of the code. i. means. This means. However. does not change the nature of the variable variable can be changed. } Listing 249: The denition of an inline function The use of the inline statement does not guarantee that the compiler replaces the function call.The c o n s t a n t p o i n t e r p o i n t s t o 11 The c o n s t a n t p o i n t e r p o i n t s t o 79 Listing 247: Output of Listing 246 A constant pointer to a constant It is also possible to create a constant pointer pointing to a constant variable. This enables the programmer to keep the code tidy without the disadvantage of wasting time for time consuming function calls. Listing 248: A constant pointer to a constant 34. The inline statement precedes the data type of the return value. we need to read the left hand side of the assignment from right to left. writing functions is a good way to keep the code tidy. On the one hand. The inline statement The solution for this conict is function inlining.e. First of all is the name of the new variable. So. Listing 249 shows the denition of an inline function. Especially if such a function is often called. but constPointer4. One the other hand is writing functions a proper way to avoid code redundancy. Tasks that are carried out repeatedly are best put into a function. However. To get the meaning of this line correctly. that the variable the pointer points to can not be changed. ESI-OpenCFD or the OpenFOAM Foundation. So. the operations performed by the function. that the pointer itself the location it points to can not be changed. because the function call might take more time than the execution of all the operations. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.4 Function inlining Motivation Functions that carry out only a small number of operations are not very ecient. The last statement const at the very beginning of the line. c o n s t i n t * c o n s t c o n s t P o i n t e r 2 = &constVar1 . The last line of Listing 248 variable. ® ® 168 . i n t c o n s t constVar1 = 4 2 . Code that is written for a specic task is outsourced into a function with a hopefully meaningful name. The inline statement allowes the compiler to replace the function call with the function body. However. i n l i n e b o o l Foam : : p i m p l e C o n t r o l : : f i n a l I t e r ( ) c o n s t { r e t u r n converged_ | | ( corr_ == nCorrPIMPLE_) . Therefore. int* const constpointer4 tells the compiler that the new variable is a constant pointer to an integer. This depends on the compiler and the compiler settings. variable is not a constant. c o n s t i n t * c o n s t c o n s t P o i n t e r 4 = &v a r i a b l e . The function body contains only two logical operations. but not using it restricts the pointer to read-only operations. the last line of Listing 248 seems a bit unlogical but it isn't. so it can be altered anyway. Secondly. IX ® ® ® This oering is not approved or endorsed by ESI Group. writing inline functions is not dierent than writing ordinary functions. C p i m p l e C o n t r o l . the method indicates the use of object oriented programming.php) demands from programmers to seperate the denition of inline and non-inline functions. This means there can be several functions with the same name diering in the input arguments. i n t yPos . the constructor is bound The constructor is a method of a class like any other function or method to comply some rules. ESI-OpenCFD or the OpenFOAM Foundation. Listing 250 shows the contents of the folder pimpleControl. The *. The second constructor receives two integer variables as arguments and uses this variables to initialize the member variables xPos and yPos. } Point ( i n t x . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 c l a s s Point { i n t xPos . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.5 pimpleControl Constructor (de)construction In object oriented programming (OOP) everything is an object. Writing two or more constructors is possible because C++ supports function overloading.H le is the common way to seperate declarations from the rest of the program. The rst constructor receives no arguments and initialises the member variables with zero. 34. yPos = y . This class has two constructors. The fourth le in the folder is a second header le as demanded by the Code Style Guide.C and the *. public : Point ( ) { /* c o n s t r u c t o r code */ xPos = 0 . p i m p l e C o n t r o l I . All object are created by a constructor and if necessary destroyed by a destructor.org/contrib/code-style. dep p i m p l e C o n t r o l .H.H le. The constructor always has the same name as its class The constructor has no return value Listing 251 shows a simple class describing a point in a two-dimensional domain.openfoam. Dividing the code of a program or a module into *. IX ® ® ® This oering is not approved or endorsed by ESI Group. The term function is also used in procedural programming and does not automatically indicate the use of OOP. yPos = 0 .dep le is generated by the compiler during compilation. However.1 General syntax 61 . Listing 249 is a part of p i m p l e C o n t r o l . ® ® 169 . However. } Listing 251: A class for a 2D point 61 The terms function and method are used interchangeably.H Listing 250: Content of the folder 34. Use inline functions where appropriate in a separate classNameI. }. i n t y ) { xPos = x .OpenFOAM specics The OpenFOAM Code Style Guide (http://www.5.H pimpleControlI. 5. However. /* code c o n t i n u e s */ Listing 255: Hiding the copy constructor IX ® ® ® This oering is not approved or endorsed by ESI Group. i. There. no copying is allowed.Listing 252 demonstrates hot to create new variables of the type the type Point. yPos . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 1 2 3 4 5 6 Point : : Point ( Point & p ) { /* copy c o n s t r u c t o r code */ xPos = p . Therefore the second constructor of Listing 251 is called and the member variables are initialised based on the arguments. Listing 252: Using the class for a 2D point 34. 8 ) . Point p2 ( 3 . Therefore. ESI-OpenCFD or the OpenFOAM Foundation. The rst line creates a variable of Because no arguments are passed in this line. } Listing 253: The copy constructor for the 2D point class Hiding the copy constructor A copy constructor can be hidden. the copy constructor must be dened using a private modier. the default copy constructor has restrictions regarding the handling of complex classes.e. the rst constructor of Listing 251 is called by the compiler. the copy constructor of the class 1 2 3 4 5 turbulenceModel is hidden by declaring it private. The second line creates also a point. }. The C++ compiler will create a default copy constructor if the programmer does not write one. Listing 254: Hiding the copy constructor 1 2 3 4 5 6 7 8 9 10 11 c l a s s turbulenceModel : public regIOobject { private : // P r i v a t e Member F u n c t i o n s //− D i s a l l o w d e f a u l t b i t w i s e copy c o n s t r u c t t u r b u l e n c e M o d e l ( c o n s t t u r b u l e n c e M o d e l &) . Point. 1 2 Point p1 . ® ® 170 . xPos . To do so.2 Copy-Constructor The copy constructor is used to create a copy of an object. only within the class Listing 255 shows an example from within the source code of OpenFOAM. This means the copy Point. yPos = p . c l a s s Point { private : Point ( Point & p ) . The numbers inside the parenthesis are passed to the constructor. Listing 254 shows a simple example of a copy constructor that is declared as private. constructor can only be called from within the class itself. 2 shows an usage example of an initialisation list in the OpenFOAM sources.2. This generic turbulence modelling makes heavy use of abstract classes and inheritance.6 Object orientation 34. In some cases the source code of some applications is examined somewhere else. ® ® 171 . public : Rectangle () { t o p L e f t = Point ( ) . Listing 256 shows a simple example of a constructor with an initialisation list.34. OpenFOAM provides constants within the namespace Foam::constant.the electcial permittivity of vacuum IX physicoChemical ® ® ® This oering is not approved or endorsed by ESI Group.3 Initialisation list A class in C++ can have member variables of any type. } R e c t a n g l e ( Point a . 35. Point b ) : topLeft (a) . such as electromagnetic mu0 . 35 Under the hood of OpenFOAM This section contains short code examples that in some way explain the behaviour of OpenFOAM in certain situations. 20 and 21 in Part V. There the pre-dened constants are divided into the groups. 35.2 Namespaces 35. Point bottomRight . Therefore it would be nice to have a central location in which physical or mathematical constants are dened. When an instance of a class is created by the constructor. Listing 326 in Section 40. bottomRight = Point ( ) .5. All examples in this section are motivated by other parts of this manual.2.6. ESI-OpenCFD or the OpenFOAM Foundation. the initialisation list contains all statements to initialise member variables of the class.1 Solver algorithms See Sections 19.the magnetic permeability of vacuum epsilon0 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 c l a s s Rectangle { Point t o p L e f t . Complex classes may need some kind of initialisation to ensure all variables have a dened state.1 Constants Physics is full of constants.1 Abstract classes See Section 35.6 for a discussion about the implementation of the generic turbulence models in OpenFOAM. bottomRight ( b ) { /* c o n s t r u c t o r code */ } } Listing 256: A constructor with an initialisation list 34. which is the only sane way to dene Also note that OpenFOAM does not dene system library. d i c t ( ) . Further note that the constants are declared with the const specier. There are mandatory keywords and optional ones.the Euler number In Listing 257 it is demonstrated how to access the constant pi within the source code. The error handling routine clearly shows.the universal gas constant mathematical pi . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Listing 259: The content of readTwoPhaseEulerFoamControls. Only the namespace is named mathematicalConstants instead of constant::mathematical. d i c t ( ) . This method also calls another method (lookupEntryPtr()) and does the error handling.3 Keyword lookup from dictionary There are generally two kinds of keywords in a dictionary. 1 2 3 4 5 #i n c l u d e " re adT im eC on tr ols .x. however. Switch c o r r e c t A l p h a ( pimple .g.3. that the function lookup() simply calls value of lookupEntry(). html for the mathematical constants provided by the GNU C library (glibc). 35.5. Listing 258 shows all the mathematical constants dened in OpenFOAM-2. This is due to the fact that FOAM- extend is largely based on OpenFOAM-1.H In the FOAM-extend the access to e. Listing 259 shows the reading operation for three mandatory keywords. it rather uses the constants provided by the http://www.6. p i (M_PI) . Thus e and pi are dened by accessing M_E and M_PI. constants in C and C++. e and π on its own.org/software/libc/manual/html_node/Mathematical-Constants.g. From a computational performance point of view it makes perfect sense to pre-dene often used constants such as two pi.1 Mandatory keywords When a mandatory keyword is not found in a dictionary. 5 * p i ) . R . 2.H" i n t nAlphaCorr ( r e a d I n t ( pimple . i n t nAlphaSubCycles ( r e a d I n t ( pimple .0 Mathematically these operations are equivalent.2. in terms of computational cost the oating point multiplication is to be preferred over the oating point division as it is much faster [2]. piByTwo ( 0 . ESI-OpenCFD or the OpenFOAM Foundation. lookup ( " nAlphaCorr " ) ) ) .H The code Line 32 in Listing 260 shows. IX ® ® ® This oering is not approved or endorsed by ESI Group. lookup ( " c o r r e c t A l p h a " ) ) . See e. Also note that instead of diving pi by it is multiplied with 0. 1 s c a l a r f o o = c o n s t a n t : : mathematical : : p i . OpenFOAM issues an error message and terminates. the mathematical constants works the same way.gnu. Listing 257: A useless code example demonstrating the access to 1 2 3 4 const const const const scalar scalar scalar scalar π with OpenFOAM's source code e (M_E) . Listing 258: The mathematical constants provided by mathematicalConstants. 35. that OpenFOAM will terminate in case the keyword wasn't found (see line 19). lookup ( " nAlphaSubCycles " ) ) ) . twoPi ( 2 * p i ) . d i c t ( ) . ® ® 172 .π e . The function lookup() can be examined further in Listing 260. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 c o n s t Foam : : e n t r y& Foam : : d i c t i o n a r y : : lookupEntry ( c o n s t word& keyword , bool recursive , b o o l patternMatch ) const { c o n s t e n t r y * e n t r y P t r = lookupEntryPtr ( keyword , r e c u r s i v e , patternMatch ) ; i f ( e n t r y P t r == NULL) { FatalIOErrorIn ( " d i c t i o n a r y : : lookupEntry ( c o n s t word&, bool , b o o l ) c o n s t " , * this ) << " keyword " << keyword << " i s u n d e f i n e d i n d i c t i o n a r y " << name ( ) << e x i t ( F a t a l I O E r r o r ) ; } } return * entryPtr ; Foam : : ITstream& Foam : : d i c t i o n a r y : : lookup ( c o n s t word& keyword , bool recursive , b o o l patternMatch ) const { r e t u r n lookupEntry ( keyword , r e c u r s i v e , patternMatch ) . stream ( ) ; } Listing 260: Some content of dictionary.C 35.3.2 Optional keywords A method that is used to read an optional keyword from a dictionary is usually provided with a default value. This default value is used in the case that the keyword is non-existent in the dictionary. Listing 261 shows the reading operation for three optional keywords. The read function is called with two arguments. The rst is the keyword and the second is the default value. If the function lookupOrDefault() nds no entry, then the default value is returned. 1 2 3 4 5 6 c o n s t b o o l adjustTimeStep = runTime . c o n t r o l D i c t ( ) . l o o k u p O r D e f a u l t ( " adjustTimeStep " , f a l s e ) ; s c a l a r maxCo = runTime . c o n t r o l D i c t ( ) . lookupOrDefault <s c a l a r >("maxCo" , 1 . 0 ) ; s c a l a r maxDeltaT = runTime . c o n t r o l D i c t ( ) . lookupOrDefault <s c a l a r >("maxDeltaT" , GREAT) ; Listing 261: The content of readTimeControls.H The code Listing 262 shows the denition of the function lookupOrDefault(). This function also calls another function to lookup the keyword actually it looks for the value assigned to the specied keyword in the dictionary and enters a conditional branch. In case the keyword was found, the corresponding value is returned (line 14). If the keyword was not found, then the default value is returned (line 18). In Listing 262 the function is dened with four input arguments. However, in Listing 261 this function is called with only two arguments. The solution for this contradiction can be found in the le dictionary.H, where this function is declared. This declaration can also be found in Listing 263. There, in lines 6 and 7, default values for two arguments are specied. Therefore, the function can be called with only two arguments with the two arguments that have IX ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 173 62 . If the function is called with all its arguments, the passed argument overrides the default no default value value. When declaring a function that uses default values for its arguments, the arguments without default value must precede the arguments that have a default value. Otherwise, there could be ambiguity. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 template <c l a s s T> T Foam : : d i c t i o n a r y : : l o o k u p O r D e f a u l t ( c o n s t word& keyword , c o n s t T& d e f l t , bool recursive , b o o l patternMatch ) const { c o n s t e n t r y * e n t r y P t r = lookupEntryPtr ( keyword , r e c u r s i v e , patternMatch ) ; } i f ( entryPtr ) { r e t u r n p T r a i t s <T>( e n t r y P t r −>stream ( ) ) ; } else { return d e f l t ; } Listing 262: Some content of 1 2 3 4 5 6 7 8 dictionaryTemplates.C template <c l a s s T> T lookupOrDefault ( c o n s t word&, c o n s t T&, b o o l r e c u r s i v e=f a l s e , b o o l patternMatch=t r u e ) const ; Listing 263: Some content of 35.4 dictionary.H OpenFOAM specic datatypes 35.4.1 The Switch datatype A lot of settings in dictionaries are switches to activate or deactivate a feature. Listing 264 shows the part of the source code dening all valid values. Inside the source code a switch can only be true or false, as the class Switch is used as a boolean data type. However, in the dictionaries a switch can have more values provided they denote a decision. Human languages usually have more ways of answering a yes-no question, this may be the motivation for allowing this range of values for switches. 1 2 3 4 5 6 7 8 9 10 11 12 // NB: v a l u e s c h o s e n such t h a t b i t w i s e '& ' 0 x1 y i e l d s t h e b o o l v a l u e // INVALID i s a l s o e v a l u a t e s t o f a l s e , but don ' t r e l y on t h a t c o n s t c h a r * Foam : : Switch : : names [ Foam : : Switch : : INVALID+1] = { " f a l s e " , " true " , "off" , "on" , "no" , " yes " , "n" , "y" , "f" , "t" , " none " , " t r u e " , // i s t h e r e a r e a s o n a b l e c o u n t e r p a r t t o " none "? " invalid " }; Listing 264: Some content of Switch.C 62 The function could also be called with three argmuents, then the default value of the third argument would be overridden and the fourth argument would have its default value. IX ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 174 Switch datatype can be used in the code. This example reads from transportProperties dictionary. If no valid entry named testSwitch is present, then the value of the switch is set to false. Notice the second argument of the method lookupOrDefault(), it reads Switch(false). This means, that a new object of the type Switch is created with the boolean value false being passed to the constructor of the class Switch. This new object of type Switch is then used if necessary as default value for the switch named testSwitch. Listing 265 shows an example of how the the 1 Switch t e s t S w i t c h ( t r a n s p o r t P r o p e r t i e s . lookupOrDefault <Switch >(" t e s t S w i t c h " , Switch ( f a l s e ) ) ) ; Listing 265: Usage example of the Switch datatype 35.4.2 The label datatype In nearly every program there is sometimes the need for a counter. When examining the solution algorithms, like in Section 20.2, counters can be found. OpenFOAM uses a datatype called label for such counters, e.g. see Listing 157. The most obvious datatype for a counter would be the integer datatype. Listing 266 contains some lines of the le label.H, where this datatype int, long or long long63 . the type Listing 266 shows the denition of 1 2 3 4 5 6 7 8 9 10 11 12 13 is dened. Depending on system or compilation parameters, label in case int label is of is used as the underlying datatype. namespace Foam { typedef int l abel ; s t a t i c c o n s t l a b e l l a b e l M i n = INT_MIN ; s t a t i c c o n s t l a b e l labelMax = INT_MAX; i n l i n e l a b e l r e a d L a b e l ( I s t r e a m& i s ) { return readInt ( i s ) ; } } // End namespace Foam Listing 266: Some content of label.H 35.4.3 The tmp<> datatype There is a special class for all temporary data. Because there is no memory management in C++ the programmer has to delete unused variables. The author assumes that the tmp class for all kinds of temporary data is meant to distinguish temporary variables from other variables. The tmp class uses a technique called generic programming. 35.4.4 The IOobject datatype IOobject handles the behaviour of all kinds of data structures. Although, there are no variables of the IOobject, understanding some parts of this class will help to understand certain aspects of OpenFOAM. The class type Listings 267 and 268 show some examples from the sources of the solver twoPhaseEulerFoam. There, the class IOobject is used in the creation of elds as well as the creation of dictionary objects. In Listing 267 two volScalarField variables are created. receives two arguments. In both cases the rst argument is an Let us read the arguments of the IOobject constructor call. The constructor of the class IOobject. volScalarField The rst argument is the name of the The two last arguments are the read and write ags. In the case of the elds alpha1 and alpha2 the read and write ags are dierent. The eld at the start of the application. The write ag causes the eld alpha1 IOobject. alpha1 is read to be written to disk, whenever the data 63 In C as well as in C++ the domain of long is greater or equal than the domain of int. long long was dened in the C99 standard of C and was later introduced to the C++11 standard. The domain of long long is again larger or equal than the domain of long. The type long long uses at least 64 bit. So it is on 64 bit systems the largest possible datatype. The datatype long can use depending on the compiler 32 or 64 bit. The type long long guarantees the use of 64 bit. IX ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 175 is written. The eld it. The name of the alpha1 IOobject is also the name which the application uses as le name. will be written to disk in a le named to read from the le 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 alpha2 on the contrary is not written to disk and the application also does not try to read alpha1. alpha1. Therefore the eld Also when the application tries to read alpha1, it tries v o l S c a l a r F i e l d alpha1 ( IOobject ( " alpha1 " , runTime . timeName ( ) , mesh , I O o b j e c t : : MUST_READ, I O o b j e c t : :AUTO_WRITE ), mesh ); v o l S c a l a r F i e l d alpha2 ( IOobject ( " alpha2 " , runTime . timeName ( ) , mesh , I O o b j e c t : : NO_READ, I O o b j e c t : : NO_WRITE ), s c a l a r (1) − alpha1 ); Listing 267: Denition of volume fraction elds in Listing 268 shows the denition of an also an IOobject createFields.H IOdictionary. The constructor of the class IOdictionary receives IOobject is also the name of the le the application as argument. Again, the name of the tries to read when reading in the dictionary. Notice also the read ag. This ag causes the application to check if the le has been modied during run-time. If this is the case, the le will be read again. 1 2 3 4 5 6 7 8 9 10 11 IOdictionary ppProperties ( IOobject ( " ppProperties " , runTime . c o n s t a n t ( ) , mesh , I O o b j e c t : : MUST_READ_IF_MODIFIED, I O o b j e c t : :NO_WRITE ) ); Listing 268: Denition of a dictionary in readPPProperties.H Read & write ags In the constructor so called read and write ags are provided as arguments, see e.g. Lines 8 and 9 of Listing 268. Listing 269 shows the available read/write ags. OpenFOAM-2.0.0 The ag MUST_READ_IF_MODIFIED 64 . The available read ags oer quite some exibility. was introduced with //− Enumeration d e f i n i n g t h e v a l i d s t a t e s o f an I O o b j e c t enum o b j e c t S t a t e { 1 2 3 64 http://www.openfoam.org/version2.0.0/runtime-control.php IX ® ® ® This oering is not approved or endorsed by ESI Group, ESI-OpenCFD or the OpenFOAM Foundation, the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 176 Listing 269: Denition of the object states and read/write ags of IOobject IOobject. mesh . IX ® ® ® This oering is not approved or endorsed by ESI Group. If we like to extend an existing solver with a scalar transport equation.H in Pitfall: Solving for a NO_READ eld The author stumbled across an interesting error during modifying a solver. the author wishes to share the experience.4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 GOOD. However. FOAM e x i t i n g Listing 271: Error message of OpenFOAM caused by trying to solve for a no-read eld. Listing 270 shows an example. I O o b j e c t : :AUTO_WRITE ). 0 . //− Enumeration d e f i n i n g t h e w r i t e o p t i o n s enum w r i t e O p t i o n { AUTO_WRITE = 0 . dimensionedScalar ( " zero " . ® ® 177 . BAD }. runTime . 0 . From f u n c t i o n c a l c u l a t e d F v P a t c h F i e l d <Type > : : v a l u e I n t e r n a l C o e f f s ( c o n s t tmp<s c a l a r F i e l d >&) const i n f i l e f i e l d s / f v P a t c h F i e l d s / b a s i c / c a l c u l a t e d / c a l c u l a t e d F v P a t c h F i e l d . NO_WRITE = 1 }. x/ run / f o o / c a s e /0/T" You a r e p r o b a b l y t r y i n g t o s o l v e f o r a f i e l d with a d e f a u l t boundary c o n d i t i o n . NO_READ }. mesh . ESI-OpenCFD or the OpenFOAM Foundation. 0 . we want to solve this transport equation. //− Enumeration d e f i n i n g t h e r e a d o p t i o n s enum readOption { MUST_READ. volScalarField T ( IOobject ( "T" . IOobject::NO_READ read ag. The name of the eld was changed as was the write ag. This falls into the category copy & paste error. There are plenty of les from which we can copy the relevant code. 3 . the call TEqn. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. timeName ( ) .solve() yields some unexpected outcome. no care was taken of the read ag. However. the write ags needs to be set to AUTO_WRITE. we need to create the eld we want to solve for. READ_IF_PRESENT. dimensionSet (0 . and composed the transport equation for this eld (TEqn). 1 2 3 4 5 6 7 8 9 10 11 12 13 Listing 270: Creating a eld with an After we created out eld T. However. I O o b j e c t : :NO_READ. 0 . in our case a volScalarField. 0) . Since we want to create colourful images. Listing 271 shows the error message issued by OpenFOAM. −−> FOAM FATAL ERROR: v a l u e I n t e r n a l C o e f f s cannot be c a l l e d f o r a c a l c u l a t e d F v P a t c h F i e l d on patch i n l e t o f f i e l d T i n f i l e "/home/ u s e r /OpenFOAM/ u s e r − 2 .C a t l i n e 1 5 4 . MUST_READ_IF_MODIFIED. 0 ) ). The developers of OpenFOAM have forseen this case.5.At rst. The error message says. run ( ) ) { #i n c l u d e " rea dT im eC on tro ls . The reason for this are the arguments of the constructor call in Listing 270. timeName ( ) << n l << e n d l . Thus. Continued Problems Changing the read ag in Listing 270 alone does not solve the problem.C pisoFoam Listing 274 shows the beginning of the main loop of pisoFoam.C a t l i n e 108 r e a d o p t i o n I O o b j e c t : :MUST_READ o r MUST_READ_IF_MODIFIED s u g g e s t s t h a t a r e a d c o n s t r u c t o r f o r f i e l d T would be more a p p r o p r i a t e .1 Time stepping Transient solvers solve the governing equations each time step at least once. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Depending on the solution algorithm there are several inner iterations (iterations within a time step) during one outer iteration. I n f o << "Time = " << runTime . This is perfectly true.H" runTime++. Listing 272: Warning message of OpenFOAM caused by inappropriate constructor arguments concerning read ags and initial values. 35. This means. the object is incremented. −−> FOAM Warning : From f u n c t i o n G e o m e t r i c F i e l d <Type . pimpleFoam Listing 273 shows the beginning of the main loop of pimpleFoam. Since.H" #i n c l u d e " CourantNo . /* code c o n t i n u e s */ Listing 273: The beginning of the main loop of pimpleFoam in pimpleFoam. 3 . For our modied solver to work. we need to nd out why. ESI-OpenCFD or the OpenFOAM Foundation. ® ® 178 . If a eld is to be read from disk.5 Time management 35. we created the eld with a NO_READ ag. GeoMesh > : : r e a d I f P r e s e n t ( ) i n f i l e /home/ u s e r /OpenFOAM/OpenFOAM− 2 . we must not pass a value (Line 12 in Listing 270). the message seems counter-intuitive. x/ s r c /OpenFOAM/ l n I n c l u d e / G e o m e t r i c F i e l d .H" #i n c l u d e " s e t D e l t a T . the current time step is incremented to the next time step. Changing the read ag from MUST_READ to NO_READ yields the same error message as in Listing 271. however. This is also the case if we leave patches in the boundaryField dictionary of the les that are read from disk. we wanted to solve for a eld with default boundary conditions. see Listing 272. we need to remove the argument passed in Line 12 in Listing 270. Also changing the boundary conditions does not produce a dierent outcome. w h i l e ( runTime . OpenFOAM assigns default boundary conditions. when a value is passed to a constructor with a MUST_READ or MUST_READ_IF_MODIFIED read ag. since we checked the boundary conditions in the le T over and over. /* code removed f o r t h e s a k e o f b r e v i t y */ I n f o << "\ n S t a r t i n g time l o o p \n" << e n d l . After the three runTime 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 include instructions. P a t c h F i e l d . IX ® ® ® This oering is not approved or endorsed by ESI Group. no boundary conditions were provided. thus OpenFOAM issues a warning message. } Listing 275: The denition of the function 1 2 3 4 5 6 7 8 9 10 11 loop() in Time. in pimpleFoam. 1 2 3 4 5 6 7 8 9 10 11 b o o l Foam : : Time : : l o o p ( ) { b o o l r u n n i n g = run ( ) . There. Listing 275 shows.loop(). Let's have a closer look on runTime. i f ( running ) { o p e r a t o r ++() .5. ESI-OpenCFD or the OpenFOAM Foundation.C Foam : : Time& Foam : : Time : : o p e r a t o r ++() { deltaT0_ = deltaTSave_ . } return running . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The time step inuences the accuracy and stability of the simulation. #i n c l u d e " readPISOControls . the while statement is controlled by the return value of the function call runTime. there is no incrementation of any of the The ++ operator of the Time class Listing 276 shows the rst lines of the denition of the ++ operator of the Time class. the while statement is controlled by the return value of the function call runTime.C runTime object. In pisoFoam. IX ® ® ® This oering is not approved or endorsed by ESI Group. l o o p ( ) ) { I n f o << "Time = " << runTime . timeIndex_ + 1 ) . /* code removed f o r t h e s a k e o f b r e v i t y */ Listing 276: The denition of the operator ++ in Time. lies in the condition while statement.C 35.H" // P r e s s u r e − v e l o c i t y PISO c o r r e c t o r { /* code c o n t i n u e s */ Listing 274: The beginning of the main loop of pisoFoam in pisoFoam. The explanation for this.1 2 3 4 5 6 7 8 9 10 11 12 13 14 /* code removed f o r t h e s a k e o f b r e v i t y */ I n f o << "\ n S t a r t i n g time l o o p \n" << e n d l . timeName ( ) << n l << e n d l . In a simulation with xed time step the time step is constant.2 Setting the new time step Transient simulations can be run with xed and variable time steps. that the function loop() calls the function run() and then increments the runTime object by calling operator++().loop().H" #i n c l u d e " CourantNo . The value of the time step must be set before the simulation is started. setTime ( v a l u e ( ) + deltaT_ . ® ® 179 . deltaTSave_ = deltaT_ .run(). The value of the time step determines the time scales that can be resolved in the simulation. // Save o l d time name c o n s t word oldTimeName = d i m e n s i o n e d S c a l a r : : name ( ) . w h i l e ( runTime . Whereas. Via the Courant-Friedrichs-Lewy (CFL) criterion the time step is linked to the stability of the time integration method. The last instruction of Listing 276 set the time value to the current time value plus the time step. Listing 278 shows how the time step is computed each time step. (81) shows the minimum of the rst two arguments in a mathematical way. The second limit for determining the time steps is the maximum Courant number. 0 ) . The user then provides the limits for the determination of the time steps. This parameters purpose is to maintain stability of the numerical solution. which is the limit for the explicit Euler time integration method.2) maxDeltaTFact = The scalar maxDeltaTFact (Line 3 in Listing 278 and Eq. maxDeltaT ) ).1 ∗ maxDeltaTFact). deltaTValue ( ) << e n d l .Most transient OpenFOAM solvers oer the possibility of transient simulations with variable time steps. This line of code (Line 4 and Eq. In order to prevent oscillations the increase of the time step is damped. (80) (81) (80)) is the relation between the maximum Courant number and the current Courant number (see Section 35. deltaTValue ( ) . 2 ) . The other two instructions read values for the maximum Courant number and the maximum time step. ® ® x 180 . which would cause the solver to crash. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. maxCo Co + SMALL deltaTFact = min( min( maxDeltaTFact. ESI-OpenCFD or the OpenFOAM Foundation. If this value is the smallest. l o o k u p O r D e f a u l t ( " adjustTimeStep " . Listing 277 shows the code that reads the time controls. ® In Figure 44 the values for ® This oering is not approved or endorsed by ESI Group. Eq. The most obvious of these three values is the last argument. f a l s e ) . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 i f ( adjustTimeStep ) { s c a l a r maxDeltaTFact = maxCo/ (CoNum + SMALL) . 1 . This is the upper limit for the value of each new time step. The default value for the maximum Courant number is 1. This code is rather self-explanatory. 1 * maxDeltaTFact ) . 1 . 1 .H Let us have a look on what the code is actually doing.e. 1 2 3 4 5 6 c o n s t b o o l adjustTimeStep = runTime . The nested use of two min() functions role of the constant The scalar the determines the minimum of three values. The SMALL is to prevent division by zero. The most obvious limit is the maximum time step maxDeltaT. If there is not entry in controlDict then a xed time step is used. 0 + 0 . This is the parameter for the user to determine the time scale to be resolved. lookupOrDefault <s c a l a r >("maxCo" .5. c o n t r o l D i c t ( ) . We use the symbol x for the scalar ® maxDeltaTFact. 1.H Determining the new time step The value of the new time step has to obey both limit mentioned above. the maximum time step and the maximum Courant number. Listing 278: The content of the le setDeltaT. (81)) implements damping. deltaTFact is computed from maxDeltaTFact. c o n t r o l D i c t ( ) .4 on how the Courant number is determined). } I n f o << " d e l t a T = " << runTime . Listing 277: The content of the le readTimeControls. GREAT) . IX (81). s c a l a r maxDeltaT = runTime . s c a l a r maxCo = runTime . c o n t r o l D i c t ( ) . s e t D e l t a T ( min ( d e l t a T F a c t * runTime . the rate of increase of the time step is limited. then the next time step is 20 % larger than the last one.0 + 0. s c a l a r d e l t a T F a c t = min ( min ( maxDeltaTFact .0. i. 1. The rst instruction reads the entry in controlDict specifying whether to use variable time steps or not. lookupOrDefault <s c a l a r >("maxDeltaT" . runTime . Figure 44 shows the three arguments of Eq. that the class Time class inherits time.1x) = x= x< x> 10 9 10 9 (82) Comax Comax 1 = = Co f Comax f (83) <1 ⇒x>1 (84) 1.x is the ratio of the maximum Courant numCo. ber Comax and the current Courant number maximum Courant number we replace remains. Mrs.4 2. As the current Courant number is always smaller than the Co with f Comax .2 1. Hyde.8 2 x 2. cpuTime .6 1. TimePaths . the maximum time step. Time. There the minimum of the newly calculated and the maximum time step is passed on. Thus x is always greater than one.5. Listing 279 shows us.H reveals some very interesting information on the nature of Time class. ( x 1 + 0.4 y 1. ® ® 181 .1x min(x.1x y = 1.2 1. the nature of the 65 . (81) plotted over The argument of the function 3 x setDeltaT() contains the abidance of the rst limit. After cancelling Comax the inverse of f are greater than one.2 2. Eq. Jekyll and Mr.2 1. 35. ESI-OpenCFD or the OpenFOAM Foundation.3 A note on the passing of time In this section we will take a closer look at the implementation of the Time class. Class design A quick glance at the le precisely. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.5 y=x y = 1 + 0.3 1. objectRegistry . 1 + 0. the Time class is not only Dr. with f < 1. or more from ve base classes c l a s s Time : public public public public public { /* c l a s s } clock .6 2. it is also Citizen Kane. TimeState d e f i n i t i o n */ 65 Literarily spoken. (83) elaborates why this is the case.8 Figure 44: The three arguments of Eq.4 1.1 1 1 1. IX ® ® ® This oering is not approved or endorsed by ESI Group. Robinson and the Tambourine Man. H. setTime ( v a l u e ( ) + deltaT_ . setTime ( v a l u e ( ) . do { p r e c i s i o n _ ++. Lines 6. t i m e I n d e x ( ) ) .C. i f ( p r e c i s i o n _ == 100 && p r e c i s i o n _ != o l d P r e c i s i o n ) { // Reached l i m i t . " << e n d l . c l a s s TimeState : public dimensionedScalar { /* c l a s s d e f i n i t i o n */ } Listing 280: The information on inheritance of the TimeState class. WarningIn ( "Time : : o p e r a t o r ++()" ) << " I n c r e a s e d t h e t i m e P r e c i s i o n from " << o l d P r e c i s i o n << " t o " << p r e c i s i o n _ << " t o d i s t i n g u i s h between timeNames a t time " << v a l u e ( ) << e n d l . that TimeState is From Listing 279 we see that In Listing 280 we see the information on inheritance of the a dimensionedScalar.H. an extract of ® Time. } } } // some code removed f o r b r e v i t y Listing 281: The increment operator (++) of the IX ® Time class. ESI-OpenCFD or the OpenFOAM Foundation.Listing 279: The information on inheritance of the Time class. an extract of TimeState. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Distinguishing between time steps The fact that Time is a TimeState which in turn is a dimensionedScalar helps to understand the name() method of the dimensionedScalar name space is called. } w h i l e ( p r e c i s i o n _ < 100 && d i m e n s i o n e d S c a l a r : : name ( ) == oldTimeName ) . ® ® 182 . // some code removed f o r b r e v i t y // Check t h a t new time r e p r e s e n t a t i o n d i f f e r s from o l d one i f ( d i m e n s i o n e d S c a l a r : : name ( ) == oldTimeName ) { int oldPrecision = precision_ . The TimeState class Time is a TimeState due to inheritance. 13 and 21 of Listing 281. an extract of Time. There. timeIndex_ + 1 ) . timeState class. ® This oering is not approved or endorsed by ESI Group. There we see. WarningIn ( "Time : : o p e r a t o r ++()" ) << " Current time name " << d i m e n s i o n e d S c a l a r : : name ( ) << " i s t h e o l d a s t h e p r e v i o u s one " << oldTimeName << e n d l << " This might r e s u l t i n o v e r w r i t i n g o l d r e s u l t s . the 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 Foam : : Time& Foam : : Time : : o p e r a t o r ++() { // some code removed f o r b r e v i t y // Save o l d time name c o n s t word oldTimeName = d i m e n s i o n e d S c a l a r : : name ( ) . 4 The Courant number The Courant number Co is the ratio of the time step ∆t and the characteristic convection time scale u/∆x. Eq. which is a string data type of OpenFOAM.2.2. s t r ( ) . (86) shows how Eq.5. an extract of Time.2 we saw that the value of the timePrecision on the actual causes of this error. We will now elaborate timeName(const scalar). engineTime is derived from Time. an extract of Time. This denition seems obvious in some way in the one-dimensional case. For two or three-dimensional cases the choice of how to dene the characteristic ux seems not straight forward. 68 The call of timeToUserTime() can be ignored. Listing 283 shows the denition of this method. e. (the time name) with limited precision 1 2 3 4 5 6 7 8 9 //− Return time name o f g i v e n s c a l a r time Foam : : word Foam : : Time : : timeName ( c o n s t s c a l a r t ) { s t d : : o s t r i n g s t r e a m buf . c o n s t l a b e l newIndex ) { v a l u e ( ) = newTime . that the string representation of the time is dierent than the actual value of the time. using the increment operator of the Time class.102 from the time value 0. buf . i o s _ b a s e : : f l o a t f i e l d ) . (87) shows the extension of Eq. This method simply returns the passed value. Listing 282 shows the denition of the method can be a source of error. timeIndex_ = newIndex . 35. s e t f ( i o s _ b a s e : : f m t f l a g s ( format_ ) .g. The new time value is passed to this method. that the descriptive comment is taken from the header le When the time is advanced. precision_. This method has a non-trivial implementation in the engineTime class.2. In the 68 .H. (85) is expanded with A/A to gain a formulation featuring the ux and the volume of the control volume instead of the velocity and the discretisation length.2. when precision is set to three digits. In Lines 21 and 29 we nd the hard-coded limit for the time precision. d i m e n s i o n e d S c a l a r : : name ( ) = timeName ( timeToUserTime ( newTime ) ) . (86) for a one-dimensional nite volume formulation. However in a practical CFD code the Courant number will be computed in a slightly dierent way. Thus. ® ® 183 . If the time precision reaches a value of 100. 66 The data type of the return value of this method is word. the time name is a string representation of the time.From Line 23 to 27 of Listing 281 we see the code which generates the warning message we saw in Listing 33 in Section 7. (85) shows the denition of the Courant number. which is a static data eld of the Time class with a In this method the time value with high precision is converted to a string representation 67 . The mean of the uxes of the faces E and W denes the convective time scale. r e t u r n buf . buf << t . Eq. then it is no more increased. } Listing 282: The method timeName(const scalar) of the Time. buf . Naming the time with precision In Section 7. } Listing 283: The method setTime() of the class Time. This method is used to create a 66 from a given scalar representing the time. In this method the time precision properly formatted time name comes into play in the form of the data member protected visibility.1023.2. It is important to note. ESI-OpenCFD or the OpenFOAM Foundation.C. class Time. IX ® ® ® This oering is not approved or endorsed by ESI Group. p r e c i s i o n ( p r e c i s i o n _ ) . as it is the case in the example described in Section 7. Eq. second instruction we see how the time name is updated to the new value 1 2 3 4 5 6 v o i d Foam : : Time : : setTime ( c o n s t s c a l a r newTime .C. the method setTime() is called. Note. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. which keeps track of time in terms of engine RPM and crank-shaft angle. 67 It is this method which creates the time name 0. (88) holds for every cell. The factor of 1/2 and the summation of φfi is explained by the author as follows. We base our reections on a two dimensional control volume.e. This equation is then rearranged to yield Eq. In Eq.V( ) . 5 * ( gSum( sumPhi ) /gSum( mesh . 5 * gMax( sumPhi/mesh . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 s c a l a r CoNum = 0 . Eq. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Both variables every cell.u∆t ∆x u∆t u∆t A φ∆t Co = = = ∆x ∆x A ∆V |φE |−|φW | ∆t 1 (|φE | − |φW |)∆t 2 Co = = ∆V 2 ∆V Co = (85) (86) (87) The Courant number in OpenFOAM In OpenFOAM the Courant number is computed for all cells. for each cell the magnitude of the face uxes are summed up. s c a l a r meanCoNum = 0 . Therefore the gMax() sumPhi and mesh. norm is not self-evident. In any case is the norm. So there is no guarantee of validity. i n t e r n a l F i e l d ( ) ). deltaTValue ( ) . (90) represents line 14. 0 . and a mean Courant number. These terms are the arithmetic mean of the face ux in the principal directions summation is then identied as the The reason for choosing the than the Euklidian or IX L2 L1 L1 N −S and W − E. } meanCoNum = 0 . ESI-OpenCFD or the OpenFOAM Foundation. Listing 284: The content of the le sumPhi = CourantNo. Courant number. CoNum = 0 . (93). Eq. i f ( mesh . f i e l d ( ) ) ) * runTime . Eq. However. There the maximum value of the ratio between the values of sumPhi and the cell volume is determined.e. ® ® 184 . the mean Courant number of all cells.e. Listing 284 shows the code responsible for computing the Courant number. (89) is the mathematical representation of line 11. I n f o << " Courant Number mean : " << meanCoNum << " max : " << CoNum << e n d l .V() contain values for function returns the maximum value. This norm of the mean face uxes in the principal directions. deltaTValue ( ) . Eq. i. sumPhi is a scalar eld containing the sum of the magnitudes of all face uxes of every cell. i. In fact OpenFOAM computes a maximum the largest Courant number of all cells. i. n I n t e r n a l F a c e s ( ) ) { s c a l a r F i e l d sumPhi ( f v c : : surfaceSum (mag( p h i ) ) ( ) . the use of the L1 ® L1 norm computationally cheaper norm seems justied since it measures the distance ® ® This oering is not approved or endorsed by ESI Group. (88). (93) the summation is reduced to two terms.H X |φfi | (88) fi sumPhi 1 max ∆t 2 all cells Vcell P 1 sumPhi P meanCoNum = ∆t 2 Vcell CoNum = (89) (90) Discussion The way to compute the Courant number in a three dimensional case is not straight forward as mentioned above. 0 .V( ) . Line 8 of Listing 284 translates to Eq. f i e l d ( ) ) * runTime . This section reects the authors way of understanding. (92) shows the summation written in the long form. (90). P X kΦk1 1 V P cell X= N kΦk1 Vcell P X Vcell 1 kΦk1 P X= kΦk1 Vcell | N {z } (102) (103) =Vcell Vcell X kΦk1 X=P kΦk1 Vcell ! X kΦk1 1 X=P Vcell kΦk1 (104) (105) Vcell IX ® ® ® This oering is not approved or endorsed by ESI Group. 1 X kΦk1 Co = ∆t N Vcell P P V kΦk1 X kΦk1 1 P cell P Co = ∆t N Vcell kΦk1 Vcell | {z } | {z } =1 =1 P P X kΦk1 V kΦk1 1 P cell ∆t Co = P Vcell N kΦk1 Vcell {z } | (99) (100) (101) X Eq. (101) now resembles Eq.org/wiki/Taxicab_geometry. ® ® 185 . Co = The mean value of the quantity x kΦk1 ∆t Vcell (97) is dened as follows x= N 1 X xi N i=1 (98) Next we write the mean value of the Courant number. An unmarked summation is a summation over all cells. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. P 1 fi |φfi | Co = ∆t 2 Vcell 1 |φN | + |φE | + |φS | + |φW | Co = ∆t 2 Vcell Co = (91) (92) |φN |+|φS | 2 W| + |φE |+|φ 2 ∆t Vcell Co = |φ| NS (93) WE + |φ| Vcell ∆t (94) xi Co = k |φ| k1 ∆t Vcell (95) We indroduce the following symbols xi 1X |φfi | = k |φ| k1 = kΦk1 2 (96) fi Co = kΦk1 ∆t Vcell (97) The way the mean Courant number is computed seems incorrect at the rst glance but it isn't.wikipedia.covered by a movement. see http://en. (101) and (90). Now we concentrate on the term X which is the only dierence between Eqns. ESI-OpenCFD or the OpenFOAM Foundation. Depending on the system the oating point division operation can take several times longer than a oating point multiplication. whereas the second formula takes approximately is larger than one. δ δ 2n operations.g. For a uniform grid this assumption would be ideally fullled. The argument made seems not to be applicable on tetrahedral cells.We assume Vcell Vcell ≈1 X kΦk1 1 X=P kΦk1 1 P kΦk1 X=P =1 kΦk1 Thus we have shown that the way the mean Courant number Courant number Co. T1 = n(Td + Ts ) We introduce the factor Next we assume that n n the number of eld values. 2n times additions and one division is to be made. that is the ratio between Td and Ts . ESI-OpenCFD or the OpenFOAM Foundation. Remember. This argument does not consider the memory usage of the operations involved. Secondly. this attempt of a proof is based on some assumptions. This would be the case if the division operation takes more time than the summation operation which is very likely the case. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. (106) (107) meanCoNum is computed is actually the mean However. the compiler and the implementation. In the rst case In the second case n times one division and one addition needs to be made. e. the way the author explains the meaning of the summation of the face uxes relies on hexahedral Vcell ≈1 Vcell is valid for homogeneous grids. (113) is very large T1 = n(1 + δ) Ts So the rst formula takes δ with 1+δ T2 ≈ 2n Ts (114) operations. the assumption the largest and smallest cells diers a lot this assumption is not justied. T2 = 2nTs + Td (110) T1 = n(δTs + Ts ) T2 = 2nTs + δTs (111) T1 = nTs (1 + δ) T1 = n(1 + δ) Ts T2 = Ts (2n + δ) T2 = (2n + δ) Ts (112) δ. If the volume of cells. it only focuses on the number of oating point operations. the second formula will take less time for computation. It is the opinion of the author that this is made for reasons of computational cost. [2] reports a factor of 5 to 6 for single and double precision oating point division. First. Because the Courant number is computed after every time step the time needed to calculate the Courant number has an impact on the simulation time. A unlikelyor even impossible as the addition is a very simple operation. The actual ratio vary according to the system architecture. Two times the summation over all values of a eld plus one division is computationally cheaper than an elementwise division of two elds and one subsequent summation over all elements of the resulting eld. If smaller than one is highly is the ratio between the time a division takes and the time an addition takes. Some thoughts on the computational costs Why the formula for the mean Courant number is rearranged from Co = 1 X kΦk1 ∆t N Vcell (108) to P kΦk1 Co = P ∆t Vcell (109) is unknown to the author. IX ® ® ® This oering is not approved or endorsed by ESI Group. ® ® 186 . 5 The two-phase Courant number In a two-phase simulation there are several choices of how to compute the Courant number. deltaTValue ( ) . The next lines compute the Courant number based on the relative phase ux.4. which happens to be the ux of the mixture. Using a LES turbulence model This statement is reected in the relationship between the classes implementing the turbulence models in OpenFOAM.6 CourantNos. U and Ur).5. the mixture Courant 1 computes the mixture Courant number by including the le 35. Both statements are reected by the class diagram of the turbulence models. Line CourantNo. Also. 1. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. are 4 velocity elds (U1. Each turbulence model is derived from this abstract base class. 5 * gMax ( f v c : : surfaceSum (mag( p h i 1 − p h i 2 ) ) ( ) . IX ® ® ® This oering is not approved or endorsed by ESI Group. On the top is the abstract class turbulenceModel. 1 2 3 4 5 6 7 8 9 10 11 12 #i n c l u d e " CourantNo . } CoNum = max(CoNum. Each turbulence class will implement specic functionality individually. I n f o << "Max Ur Courant Number = " << UrCoNum << e n d l . In total. f i e l d ( ) ) * runTime . Listing 285 shows the content of the le CourantNos. All derived classes will then inherit this functionality. So the variable time steps of the twoPhaseEulerFoam solver are based on the maximum of the mixture and relative velocity Courant number. 2.1 it is stated that the user can choose between three options. The solver twoPhaseEulerFoam computes the Courant number for the mixture and the relative velocities. there These are the velocities of the phases 1 and 2 as well as the mixture and relative velocities.H which is part of the source code of this solver.5. U2.H" { s c a l a r UrCoNum = 0 . This abstract class. All RAS turbulence models are turbulence models. As this code operates on the eld number is computed. but not all turbulence models are RAS turbulence models. both are turbulence models. A RAS turbulence model is not the same as an LES turbulence model.35.H. A laminar simulation 2. Using a RAS turbulence model 3.H Turbulence models In Section 17. all functionality common to all possible turbulence classes can be dened in this class.V( ) . however. Two statements can be made about turbulence models 1. ® ® 187 . At line 11 the maximum of this two Courant numbers is determined and stored into the variable CoNum CoNum. provides the framework for all derived turbulence classes. Listing 285: The content of the le 35. i n t e r n a l F i e l d ( ) /mesh . This is the le described in Section phi. UrCoNum) . is the Courant number used by the time stepping mechanism. ESI-OpenCFD or the OpenFOAM Foundation. Object oriented programming allowes the programmer to translate relationships directly from human language to source code. ESI-OpenCFD or the OpenFOAM Foundation. 35.6. If a class contains only abstract methods. nu ( ) . the implementation of the method nuEff() in the class RASModel. //− Return t h e l a m i n a r v i s c o s i t y i n l i n e tmp<v o l S c a l a r F i e l d > nu ( ) c o n s t { r e t u r n transportModel_ . However. The laminar viscosity is a property of the uid itself and has nothing to do with turbulence. //− Return t h e t u r b u l e n c e v i s c o s i t y v i r t u a l tmp<v o l S c a l a r F i e l d > nut ( ) c o n s t = 0 . //− Return t h e e f f e c t i v e v i s c o s i t y v i r t u a l tmp<v o l S c a l a r F i e l d > nuEff ( ) c o n s t = 0 . Consequently. This function is used to access the laminar or molecular viscosity.H The base class contains not only virtual functions. 35.2 The class RASModel The class RASModel is derived from the abstract class turbulenceModel. then it is sometimes called a pure-abstract class. The = 0 indicates that a method is abstract.turbulence divDevReff(): laminar divDevReff(): RASModel LESModel divDevReff(): divDevReff(): Figure 45: Graphic representation of inheritance of the turbulence model classes. Listing 286 shows the declaration of pure-virtual or abstract methods. ® ® 188 . No matter if a RAS or a LES turbulence model is used. these functions must be overridden by the classes that are derived from the base class. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. It contains several pure-virtual functions.6. RASModel implements all methods that are common to all RAS turbulence models. It is also an abstract class because it does not override all abstract methods inherited from turbulenceModel. A pure-virtual class can not be called. Listing 287 shows the implementation of the function nu(). The non-abstract methods of the base class like nu() from Listing 287 can be used by the derived classes. To be able to call this functions. the class ing 288 shows List- //− Return t h e e f f e c t i v e v i s c o s i t y v i r t u a l tmp<v o l S c a l a r F i e l d > nuEff ( ) c o n s t { r e t u r n tmp<v o l S c a l a r F i e l d > ( 69 A class that contains one or more abstract methods is called an abstract class. It also contains functions that are the same for all derived classes.H Every class derived from an abstract class must at least override the abstract methods. the laminar viscosity will always be the same. Listing 286: Declaration of the virtual methods in turbulenceModel. } Listing 287: Implementation of nu() in turbulenceModel. this functions are implemented by the base class. the turbulence models need to access the laminar viscosity. The class RASModel itself is the base class for all RAS turbulence models. However. IX ® ® ® This oering is not approved or endorsed by ESI Group.1 The abstract base class turbulenceModel turbulenceModel The base class is an abstract class 69 . and the nu() in Listing 288 is implemented in the class turbulenceModel.2. Listing nut_. c l a s s kEpsilon : p u b l i c RASModel { /* c l a s s d e f i n i t i o n */ } Listing 289: Class denition of The function nut() has to be implemented by kEpsilon in kEpsilon. Therefore.H 290 shows how the function nut() is implemented.H is calculated diers between the RAS turbulence models. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. new v o l S c a l a r F i e l d ( " nuEff " . The turbulent viscosity is a property of the turbulence model. This function simply returns the class member //− Return t h e t u r b u l e n c e v i s c o s i t y v i r t u a l tmp<v o l S c a l a r F i e l d > nut ( ) c o n s t { r e t u r n nut_ .6. The function nut() is not implemented by the class RASModel. The OpenFOAM wiki features a section explaining the built-in debug mechanism 70 . See Listing 324 in Section 40. this method must be implemented by the classes derived from RASModel.php/HowTo_debugging#Getting_built-in_feedback_from_OpenFOAM IX ® ® ® This oering is not approved or endorsed by ESI Group.6. ESI-OpenCFD or the OpenFOAM Foundation.7 Debugging mechanism OpenFOAM brings along a handy debugging mechanism.net/index. } Listing 290: Implementation of The way how nut_ nut() in kEpsilon. This mechanism can be used when creating additional model libraries.4 The class kEpsilon The class kEpsilon is derived from RASModel. 35. The function 35. Each derived class must implement all remaining abstract methods.H in nuEff is calculated from the laminar viscosity. kEpsilon. Figure 46 shows a simplied class diagram there is a number of RAS turbulence models available in OpenFOAM.3 RAS turbulence models All RAS turbulence models are derived from the class RASModel. which is a property of the uid. see Listing 287.} ). RASModel divDevReff(): laminar divDevReff(): kEpsilon SpalartAllmaras divDevReff(): divDevReff(): Figure 46: Inheritance of RAS turbulence models 35. ® ® 189 . 70 http://openfoamwiki. The eective viscosity turbulent viscosity.2. nut ( ) + nu ( ) ) nuEff() Listing 288: Implementation of RASModel. 71 http://www.html or http://en.g.001). 74 This behaviour is subsumed under the term automatic variable. However.teamdrive.g. 35. Listing 291 shows the entry in the controlDict to override controlDict. The eld ReB When is by default not written to disk and ceases to exist when the scope leaves the method. debugging also intermediate results may be of interest. then an automatically generated name based on the way the eld was generated would be used. This kind of debugging is sometimes referred to as printf debugging 72 .cppreference. In this very case the le written would be named max(((mag((U1-U2))*d)|nu). See e. The code is amazingly simple. ReB is automatically deleted Note the arguments passed in Line 7. We easily recognize the formula of Line 7. Listing 293 shows how to actually use it. therefore the debig feature for the specic class is disabled. Ea. to disk the rst argument determines the le name. // p r i n t debug i n f o r m a t i o n i f ( debug ) { // debug a c t i o n } Listing 293: Using the debug mechanism in a class.com/CPP/Documents/DebugCPP/Volume/techniques. ESI-OpenCFD or the OpenFOAM Foundation. in the case's As this debugging mechanism relys on internal variables no re-compiling is involved when using this kind of debugging mechanism.0 onwards the global debug ags can be overridden by stating the debug ags of choice controlDict71 .2. We simply use this variable statement. ReB.php 72 See http://oopweb.wikipedia. The magic behind the scenes provides a variable named in an if debug. A le name containing special characters (non-alphanumerical characters) is generally not advisible 75 .org/version2. i. Yoon Luttre llAtta chment 1 .org/wiki/Debugging# Techniques 73 See Section 35. when we write the variable ReB The rst is the name of the eld. We could omit this argument.2 Use case: Write intermediate elds Listing 294 shows the denition of a method named elds to disk. For debugging purposes we want to write intermediate In Line 7 of Listing 294 we compute a Reynolds number and store it in generate the return value of the method.8 on the background of the debugging mechanism. debug switches.com/w/cpp/language/ storage_duration 75 See e. Listing 291: Specifying debug switches in the case's controlDict O v e r r i d i n g DebugSwitches a c c o r d i n g t o c o n t r o l D i c t DefaultStability 0. when the method is reaches its end the variable 74 ./etc/con From OpenFOAM-2. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.1 Using the debugging mechanism If the debugging mechanism is enabled for a class 73 . the global and local entries are checked. http://www. 1.7.html IX ® ® ® This oering is not approved or endorsed by ESI Group.com/Invalid_characters_in_file_and_folder_names. http://en. however.e.0.2.openfoam.The global debug ags controlling the behaviour of the debugging system-wide are specied in \$FOAM_SRC/. ® ® 190 . This is used to In normal operation only the return value is of interest.. By default all debug switches are initialised with a zero value. If this argument was omitted. Listing 292: Solver output when specifying debug switches in the case's controlDict 35. when the solver sets up the case.7. Listing 292 shows the solver output informing us of the local settings in DebugSwitches { DefaultStability Yoon Luttre llAtta chment } 0.0/runtime-control. php/OpenFOAM_guide/runTimeSelection_mechanism for a discussion on the run-time selection mechanism. In fact it can be none at all or any of the available. 1 2 3 4 5 6 7 8 9 10 11 12 namespace Foam { c l a s s SchillerNaumann : p u b l i c dragModel { } public : //− Runtime type i n f o r m a t i o n TypeName ( " SchillerNaumann " ) .php/OpenFOAM_guide/objectRegistry IX ® ® ® This oering is not approved or endorsed by ESI Group. at compile-time of a uid solver nobody knows which turbulence model will be used with the solver. 0 ) . 0 e − 3) ) ) . is more complex than what is pre- SchillerNaumann drag dragModel. The same is true for drag models and the two-phase Eulerian solver with the exception that you can not use no drag law. nu ( ) . time ( ) . w r i t e ( ) . } } // do more s t u f f } Listing 294: Manually writing intermediate elds for debugging. As we construct the local variable method. 35. Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : Y oonLutt rellA ttachme nt : : Ea ( c o n s t v o l S c a l a r F i e l d& Ur . we focus on the macros we can nd in the source les of the model class. s c a l a r ( 1 . // debug i n s t r u c t i o n s i f ( debug ) { i f ( Ur .In Line 14 we manually call the objects ReB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 write() 76 . c o n s t d i m e n s i o n e d S c a l a r& dP ) const { // do s t u f f v o l S c a l a r F i e l d ReB( "ReB" . ® ® 191 . The Listings 295 and 296 (Lines 10 and 3) show the two harmlessly looking lines of code enabling all the magic.php/OpenFOAM_guide/Input_and_Output_operations_using_dictionaries_and_the_ IOobject_class and http://openfoamwiki. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. outputTime ( ) ) { ReB . For the run-time selection See http://openfoamwiki. Here. The entire wisdom behind the run-time selection mechanism. this drag model is derived from the base class mechanism to work. E.net/index. ESI-OpenCFD or the OpenFOAM Foundation. We shall now have a look behind the magic powers of OpenFOAM using the SchillerNaumann drag model as an example. This section hopefully sheds some light into some of the inner workings of the run-time selection mechanism. } Listing 295: The relevant lines of code in 1 2 3 4 SchillerNaumann. } Listing 296: The relevant lines of code in SchillerNaumann.H namespace Foam { defineTypeNameAndDebug ( SchillerNaumann .net/index. We know.net/index. sented in this section.C 76 See http://openfoamwiki.g. the base class also needs to do some preparations.8 A glance behind the run-time selection and debugging magic OpenFOAM oers some amazing features. however. This method is available to all registered input/output ReB from the registered i/o object Ur we can savely assume that will also be of this type. max( Ur*dB/ phase2_ . } s t a t i c c o n s t : : Foam : : word typeName Listing 298: Two macro denitions in Thus. The rst line of the above listing is itself a macro. // Without debug i n f o r m a t i o n #d e f i n e ClassNameNoDebug ( TypeNameString ) s t a t i c c o n s t c h a r * typeName_ ( ) { r e t u r n TypeNameString . } The second line is a function denition. Listing 298 shows the macro denitions that are necessary to expand the 1 2 3 4 5 6 7 8 9 10 11 ClassName macro.TypeName First we will examine Line 10 of Listing 295. s t a t i c i n t debug \ \ //− Add typeName i n f o r m a t i o n from argument \ a TypeNameString t o a c l a s s . ClassName ( " SchillerNaumann " ) . A macro can not cover more than one line. ® ® 192 . //− Add typeName i n f o r m a t i o n from argument \a TypeNameString t o a c l a s s . backslash (\\) the current line is continued with the next line 1 2 3 4 //− D e c l a r e a ClassName ( ) with e x t r a v i r t u a l type i n f o #d e f i n e TypeName ( TypeNameString ) ClassName ( TypeNameString ) . we further expand the TypeName("SchillerNaumann") \ \ className.htm IX ® ® ® This oering is not approved or endorsed by ESI Group.g. As this function denition is made by the macro. 81 . As the macro rameter list in parentheses and at least the replacement token list until the end of the line is expanded by the preprocessor. s t a t i c c o n s t c h a r * typeName_ ( ) { r e t u r n " SchillerNaumann " . TypeName ( " SchillerNaumann " ) . \ \ typeInfo.gnu. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.tutorialspoint.gnu. The macroTypeName Listing 297 shows its denition.html 80 https://gcc.H expands to. the identier (in this case TypeName) is replaced with the replacement tokes (all instructions after the parameter list). macro consists of at least two parts.org/onlinedocs/cpp/The-preprocessing-language. and two static variables (the two center line). } Listing 297: The macro denition in Thus. however. v i r t u a l c o n s t word& type ( ) c o n s t { r e t u r n typeName . the line TypeName("SchillerNaumann"). ESI-OpenCFD or the OpenFOAM Foundation. } As the \ TypeName("SchillerNaumann") macro was put into the class denition of the verb+SchillerNaumann+ class. #d e f i n e ClassName ( TypeNameString ) ClassNameNoDebug ( TypeNameString ) . this function is dened for every class where the TypeName macro is stated in the class denition.1 Part 1 . First comes the identier. 77 with parameters78 . What looks like a function call is actually a preprocesser macro is dened in the le A \#define typeInfo.H macro.8.H. This demonstrates one of the major reasons for using preprocessor macros the ability to write recurring pieces of code just once. one of which is a static method. then comes the optional pa- 79 .com/cplusplus/cpp_static_members.com/doc/tutorial/preprocessor/ 79 https://gcc.org/onlinedocs/cpp/The-preprocessing-language.org/wiki/C_preprocessor 78 See e. by using the 80 . Static elements of class (variables or methods) are elements that exist only once for all instances of a class In the case of a two-phase Eulerian solver two instances of the SchillerNaumann class might exist in the case 77 http://en. } s t a t i c c o n s t : : Foam : : word typeName s t a t i c i n t debug v i r t u a l c o n s t word& type ( ) c o n s t { r e t u r n typeName .cplusplus. v i r t u a l c o n s t word& type ( ) c o n s t { r e t u r n typeName . http://www.wikipedia. // Also d e c l a r e s debug i n f o r m a t i o n .35. the macro added two function denitions (rst and last line).html#The-preprocessing-language 81 http://www. No matter which of the two instances of the class call the method typeName() it is always the same function called. the way this framework is set up allows for dierent names. DebugSwitch ) Listing 299: A macro denition in \ \ className. Listing 300 shows the macro denitions necessary to expand the above two macros.this model was specied for both phases. IX ® ® ® This oering is not approved or endorsed by ESI Group. DebugSwitch ) defineTypeName ( Type ) .8. 0 ) . In this case returning the name of the class the use of a static method makes perfect sense and is the only sensible way to implement this task. The 1 2 3 4 defineTypeNameAndDebug macro is dened the le className. DebugSwitch ) . Type . The variables created by the equivalent when designing OpenFOAM TypeName("SchillerNaumann") macro debug. DebugSwitch ) defineDebugSwitchWithName ( Type . 0 ) . Name) c o n s t : : Foam : : word Type : : typeName (Name) \ //− D e f i n e t h e typeName #d e f i n e defineTypeName ( Type ) defineTypeNameWithName ( Type . 0 ) ) . This has the eect that the class to the static variable name and the type name have an equal value. d e f i n e D e b u g S w i t c h ( Type . 35. 0) assigns the typeName.2 Part 2 . DebugSwitch ) ) \ //− D e f i n e t h e debug i n f o r m a t i o n #d e f i n e d e f i n e D e b u g S w i t c h ( Type . The rst line of the expansion of the macro return value of the function typeName_() defineTypeNameAndDebug(SchillerNaumann. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //− D e f i n e t h e typeName . Type : : typeName_ ( ) . DebugSwitch ) i n t Type : : debug ( : : Foam : : debug : : debugSwitch (Name .defineTypeNameAndDebug Now we will examine Line 3 of Listing 296 which is repeated just below.7. i n t SchillerNaumann : : debug ( : : Foam : : debug : : debugSwitch ( SchillerNaumann . d e f i n e D e b u g S w i t c h ( SchillerNaumann .3 for an example when class name and type name are dierent. Type : : typeName_ ( ) ) \ \ Listing 300: Four macro denitions in debugName. Name . with a l t e r n a t i v e lookup a s \a Name #d e f i n e defineTypeNameWithName ( Type . This debug variable controls are a static variable containing the type name and a static variable named the debug mechanism covered in Section 35. ESI-OpenCFD or the OpenFOAM Foundation. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. However. //− D e f i n e t h e typeName and debug i n f o r m a t i o n #d e f i n e defineTypeNameAndDebug ( Type . defineTypeNameAndDebug ( SchillerNaumann . the class name and the type name were not considered 82 .H. SchillerNaumann . SchillerNaumann : : typeName_ ( ) ) . 82 See Section 35. Type : : typeName_ ( ) ) \ //− D e f i n e t h e debug i n f o r m a t i o n .H Thus. defineTypeName ( SchillerNaumann ) .H Thus our macro expands to two macros. Obviously. registerDebugSwitchWithName ( Type . our macros expand to: c o n s t : : Foam : : word SchillerNaumann : : typeName ( SchillerNaumann : : typeName_ ( ) ) . lookup a s \a Name #d e f i n e defineDebugSwitchWithName ( Type . registerDebugSwitchWithName ( SchillerNaumann . The TypeName("SchillerNaumann") macro is used to create a method that returns the name of the class and a method that return the name of the type.8. ® ® 193 . The more elegant way to solve this problem is to access the information already gathered. The base class turbulenceModel tells the compiler and the solver how a turbulence model works. cares about the actual turbulence model. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. we need to decide at run-time at the time the solver reads all the case information which turbulence model to use. registerDebugSwitchWithName. IX ® ® ® This oering is not approved or endorsed by ESI Group. lookupOrAddDefault ( name .1 and 35. that is all we need to know at compile time. The case data related to turbulence modelling was already read by the constructor of the turbulence model. } v i r t u a l v o i d w r i t e D a t a (Foam : : Ostream& o s ) c o n s t { o s << Type : : debug . 0) The reason why the value is not directly used to assign the value to the static variable is that the called method adds the debug switch to a dictionary. We could achieve this by either reading the case data magic. 83 This would mean re-programming existing functionality. d e f a u l t V a l u e .8. ESI-OpenCFD or the OpenFOAM Foundation.H 35. In order to save us from writing a solver for each turbulence model. Listing 303 shows three lines of code.e. ® ® 194 . c o n s t i n t d e f a u l t V a l u e ) { r e t u r n d e bu gS w it c he s ( ) .The second line assigns the return value of the function call to the static variable SchillerNaumann::debug. what exact turbulence model we want to use for our simulation. add##Tag##ToDebug add##Tag##ToDebug_ (Name) Listing 302: Denition of the registerDebugSwitchWithName macro in \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ debugName. Thus. see Listing 301.8. we would like to know which turbulence model 83 or by making use of the run-time is currently used. f a l s e ). however.3 A walk in the park: demonstrate some of this magic In the above sections we took a look behind two very powerful pre-processor macros. solvers can be written in a generic way. at the time we compile the solver nobody. f a l s e . methods typeName_() and type(). Tag . In some cases. at run-time we need to decide which turbulence model to use. So.C //− D e f i n e t h e debug i n f o r m a t i o n .2.8. Manually reading this information again would result in some kind of code duplication. ::Foam::debug::debugSwitch(SchillerNaumann. I. However. } Listing 301: Adding the debug switch to the dictionary in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 debug. Name) c l a s s add##Tag##ToDebug : p u b l i c : : Foam : : s i m p l e R e g I O o b j e c t { public : add##Tag##ToDebug ( c o n s t c h a r * name ) : : : Foam : : s i m p l e R e g I O o b j e c t (Foam : : debug : : addDebugObject . } }. name ) {} v i r t u a l ~add##Tag##ToDebug ( ) {} v i r t u a l v o i d readData (Foam : : I s t r e a m& i s ) { Type : : debug = r e a d L a b e l ( i s ) . not even the compiler. lookup a s \a Name #d e f i n e registerDebugSwitchWithName ( Type . The intention behind this line is to print the return values of the These two methods were provided by the two macros dissected in Sections 35. At compile-time the time we or the OpenFOAM developers compile a solver nobody knows. The last line of the macro expansion invokes another macro. what is this all for? The turbulence models are very prominent examples for the usefulness of the run-time selection mechanism. 1 2 3 4 5 6 7 Listing 302 shows the macro denition of i n t Foam : : debug : : debugSwitch ( c o n s t c h a r * name . Fortunately. OpenFOAM takes care of that and we do not need to bother. 2 The next steps When modifying a solver. we need to create some folders to place our sources in user-2.g. From the output we see. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. I n f o << t u r b u l e n c e −>typeName_ ( ) << e n d l . of which the source code resides in OpenFOAM-2. ESI-OpenCFD or the OpenFOAM Foundation. Listing 303: Applying some of the magic. Here we also see the sense behind the distinction between the class name and the type name as discussed some paragraphs above. We follow the scheme of the standard solvers. I n f o << t u r b u l e n c e −>type ( ) << e n d l .6 for information about how turbulence models are organized in OpenFOAM.x/applications/solvers.1 2 3 I n f o << "Happy p r i n t f ( ) debugging : " << e n d l . as 84 the class turbulenceModel is an abstract base class. 1 2 3 Happy p r i n t f ( ) debugging : turbulenceModel kOmega Listing 304: Applying some of the magic. Therefore. no solver will ever actually use turbulenceModel itself . In this case.1. For a base class. the output. there are some further steps necessary. a new directory has to be created. x mkdir a p p l i c a t i o n s cd a p p l i c a t i o n s mkdir s o l v e r s Listing 305: Create some directories 36. 1 . These are described in Section 37. In the example of an concrete class those are the same. The code in Listing 303 presumes that turbulence modelling is used in its generic form. the method type() returns the name of the variable is of the type actual turbulence model. However. Open a Terminal and type the commands of the Listing to do the job. 84 See Section 35. ® ® 195 .x/applications/solvers.1. Listing 305 lists the necessary commands. this distinction makes perfect sence. they represent the general steps that are necessary. Although these steps are for a specic example. however. In this example the autoPtr<incompressible::turbulenceModel> turbulence. as it is the case in e. cd $FOAM_INST_DIR cd u s e r − 2 . 36 General remarks on solver modications This section collects and documents solver modications of the author.1 Preparatory tasks In order to be able to distinguish between the standard solvers and the solvers created by the user. turbulence pimpleFoam. 36.1. IX ® ® ® This oering is not approved or endorsed by ESI Group. that the variable turbulence is indeed of type turbulenceModel. the source code. the solver used the kOmega turbulence model. In short these steps are copy the sources you want to base your new solver on make necessary adjustments to ensure that the new solver compiles at all the new solver does not corrupt existing solvers Based on this steps the user can start to modify the sources in order to accomplish the intended function or feature. Listing 304 shows the results of the three lines of code of Listing 303. Thus. C EXE = $ ( FOAM_USER_APPBIN ) /twoPhaseLESEulerFoam Listing 308: Content of Make/les The reason for all these changes lies in the compilation process. /* #i n c l u d e " readTwoPhaseEulerFoamControls . 1 . wmake reads from Make/files which le to compile and where to put the created executable. The aim of this section is to document the necessary modications to create a version of the twoPhaseEulerFoam solver that is capable to use the LES turbulence model.H" Listing 307: Change the include statement 37. In this case.1.C The name of the source le. twoPhaseLESEulerFoam. However. The path to the executeable.2 Rename les Next. all les containing the name of the solver have to be renamed. for the sake of tidiness. FOAM_APPBIN. which is commented. dierent names can lead to confusion and make code maintenance harder.H. To do this via the Terminal cd $FOAM_INST_DIR cp − r OpenFOAM− 2 . The second line is the modied statement. ® ® 196 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. The source of the solver itself The names of these two les change to line is the old statement.C and readTwoPhaseEulerFoamControls. ESI-OpenCFD or the OpenFOAM Foundation. Therefore.C les that dene the solver. we need to copy the OpenFOAM-2. twoPhaseLESEulerFoam.C and readTwoPhaseLESEulerFoamControls. A new solver is compiled by simply typing wmake in the Terminal.3 Adjust Make/files In order not to corrupt the existing solver the le Make/files has to be adapted. This line can also be deleted. Therefore. x/ a p p l i c a t i o n s / s o l v e r s / m u l t i p h a s e / twoPhaseEulerFoam u s e r − 2 .x/applications/solvers.1. These changes are: twoPhaseLESEulerFoam. 37.x/applications/solvers/multiphase/twoPhaseEulerFoam folder to user-2. instead of instead of twoPhaseLESEulerFoam twoPhaseEulerFoam.g. However.e. x/ a p p l i c a t i o n s / s o l v e r s / twoPhaseLESEulerFoam Listing 306: Copy the sources 37. In most cases there is only one such le. Listing 308 shows how the content has to look like. IX ® ® ® This oering is not approved or endorsed by ESI Group.1. the old statement is left in order to show the original statement. This le contains a list of *.1 Copy the sources As the new solver shall be a modication of the existing twoPhaseEulerFoam solver.C. The locations where changes have to be made are marked red in the Listing. twoPhaseEulerFoam. The entry beginning with EXE denes the full path to the executable. 1 . some les have to be renamed.C. i. This may not be mandatory in order to successfully compile the solver.C and the executable SOLVER.H. However.1.1 Preparatory tasks 37. there twoPhaseEulerFoam. The latter of these les is included via an #include statement into the former one.H" */ #i n c l u d e " readTwoPhaseLESEulerFoamControls . instead of twoPhaseEulerFoam. Listing 307 shows the aected lines of code. This new solver is called like this section twoPhaseLESEulerFoam. 85 The executeable does not necessarily have to have the same name as the source le. to name the source le SOLVER. e. The rst are two les. The name of the executeable FOAM_USER_APPBIN 85 . it is strongly recommended to use consistent names.1.C. we need to change the according statement in twoPhaseLESEulerFoam.37 twoPhaseLESEulerFoam The solver twoPhaseEulerFoam can only use the k- turbulence model. g++ −m64 − Dlinux64 −DWM_DP −Wall −Wextra −Wno−unused − parameter −Wold− s t y l e − c a s t −Wnon− v i r t u a l −d t o r −O3 −DNoRepository − f t e m p l a t e −depth −100 − I . IX ® ® ® This oering is not approved or endorsed by ESI Group.H f o r s o u r c e f i l e twoPhaseLESEulerFoam . that twoPhaseEulerFoam is based on the solver bubbleFoam. C c o u l d not open f i l e w a l l F u n c t i o n s .H f o r s o u r c e f i l e twoPhaseLESEulerFoam . the sources of twoPhaseEulerFoam have been copied to a user-2. − I /home/ u s e r /OpenFOAM/OpenFOAM− 2 . The explanation of this le ts best at this location. At this stage. o In f i l e i n c l u d e d from twoPhaseLESEulerFoam .1. Listing 309 shows the content of the le Make/options. This fact becomes important now.H: D a t e i o d e r V e r z e i c h n i s n i c h t gefunden Kompilierung b e e n d e t . o ] F e h l e r 1 86 Compilation of C or C++ programs is usually done in two steps. As you can see in Listing 310.g. x/ s r c /OpenFOAM/ l n I n c l u d e − I / home/ u s e r /OpenFOAM/OpenFOAM− 2 .C c o u l d not open f i l e w a l l V i s c o s i t y . are elsewhere dened. This le is read by wmake to determine some parameters for the compiler. x/ s r c / f i n i t e V o l u m e / l n I n c l u d e − I /home/ u s e r /OpenFOAM/OpenFOAM− 2 . x/ s r c / t r a n s p o r t M o d e l s / i n c o m p r e s s i b l e / l n I n c l u d e − I t u r b u l e n c e M o d e l − I k i n e t i c T h e o r y M o d e l s / l n I n c l u d e − I i n t e r f a c i a l M o d e l s / l n I n c l u d e − IphaseModel / l n I n c l u d e − I a v e r a g i n g − I l n I n c l u d e − I . 1 . which is acutally just a copy of twoPhaseEuler- Foam. the second group of entries.4 The le Make/options At this stage. or the warning level. x/ s r c / O S s p e c i f i c /POSIX/ l n I n c l u d e −fPIC −c $SOURCE −o Make/ linux64GccDPOpt / twoPhaseLESEulerFoam . there is no need to alter this le. / bubbleFoam \ − I $ (LIB_SRC) / f i n i t e V o l u m e / l n I n c l u d e \ − I $ (LIB_SRC) / t r a n s p o r t M o d e l s / i n c o m p r e s s i b l e / l n I n c l u d e \ −I t u r b u l e n c e M o d e l \ −I k i n e t i c T h e o r y M o d e l s / l n I n c l u d e \ −I i n t e r f a c i a l M o d e l s / l n I n c l u d e \ − IphaseModel / l n I n c l u d e \ −I a v e r a g i n g EXE_LIBS = \ −l E u l e r i a n I n t e r f a c i a l M o d e l s \ −l f i n i t e V o l u m e \ − lme shTo ols \ −l i n c o m p r e s s i b l e T r a n s p o r t M o d e l s \ − lphaseModel \ −l k i n e t i c T h e o r y M o d e l Listing 309: Content of Make/options 37. For the sake of completeness. / bubbleFoam − I /home/ u s e r /OpenFOAM/OpenFOAM− 2 . 1 .2 Preliminary observations First of all we have to bear in mind. .1.C c o u l d not open f i l e createRASTurbulence . C SOURCE=twoPhaseLESEulerFoam . However. e. Other options. The le Make/options contains all compiler ags and parameters. First all les are compiled and then the object les generated by the compiler are linked together to form the executable.C .C : 6 0 : 0 : c r e a t e F i e l d s . . which libraries the solver uses. ESI-OpenCFD or the OpenFOAM Foundation. e.x/applications/sol Then all necessary adjustment have been made to prepare compilation.g. all the options listed in Make/options are related to the specic solver. the rst group in Listing 309. if we try to compile our new solver twoPhaseLESEulerFoam. 1 . libraries which have to be linked 86 to the executable of the solver. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. additional directories where included header les are located. Compilation Now.H f o r s o u r c e f i l e twoPhaseLESEulerFoam .37. ® ® 197 . make : *** [ Make/ linux64GccDPOpt / twoPhaseLESEulerFoam . the compiler is called with a lot more options. EXE_INC = \ − I . 1 . e.C c o u l d not open f i l e w a l l D i s s i p a t i o n . + wmake Making dependency l i s t f o r s o u r c e f i l e twoPhaseLESEulerFoam . because there are no real modications yet then compilation fails. Such parameters are. the target platform.H f o r s o u r c e f i l e twoPhaseLESEulerFoam .g.H: 1 3 9 : 3 7 : s c h w e r w i e g e n d e r F e h l e r : createRASTurbulence . C c r e a t e F i e l d s . However. there is no folder called bubbleFoam in the user2. Now.3 How LES in OpenFOAM is used If we want to integrate LES turbulence models into our solver. these The reason The solution to this mystery lies in the rst statement of this section. cp command copies the les wallDissipation.C.C which is included in twoPhaseLESEulerFoam.H. other than the The explanation is this string of characters This can be found in Listing 310 as a parameter in the call of g++. x/ a p p l i c a t i o n s / s o l v e r s / m u l t i p h a s e / bubbleFoam / w a l l * u s e r − 2 .C. 1 .h to the sources of our new solver.H w a l l F u n c t i o n s ./bubbleFoam is specied. x/ a p p l i c a t i o n s / s o l v e r s / m u l t i p h a s e / bubbleFoam / createRAS * u s e r − 2 . However.1. will provide us with some hints. dep c r e a t e P h i 1 .H l i f t D r a g C o e f f s .H UEqns . The les from bubbleFoam all deal with the k- turbulence model.. g++ is on Linux systems usually the standard C++ compiler. g++ is the C++ compiler of the GNU compiler collection.x/applications/solvers directory. In this case . 1 .H c r e a t e P h i 2 .H bubbleFoam . x/ a p p l i c a t i o n s / s o l v e r s / twoPhaseLESEulerFoam / cp OpenFOAM− 2 ..H w a l l D i s s i p a t i o n . This path is valid for the standard solver of OpenFOAM. cd $FOAM_INST_DIR cp OpenFOAM− 2 .Listing 310: Compilation error message The error message says. we have a look at the source code of pimpleFoam. because the included les are now located in the same directory as twoPhaseLESEulerFoam.H w r i t e .H bubbleFoam .. The -I ag tells the compiler where to nd header les. In our case we want to include the LES turbulence model we do not need this les. Because twoPhaseEulerFoam is a solver two incompressible uids which also uses the PIMPLE algorithm. this substitutes for zero or more characters. If we have a look on the source directory of bubbleFoam (Listing 311) we nd all les that are missing when compiling twoPhaseLESEulerFoam.1. les are included in createFields./bubbleFoam. x/ a p p l i c a t i o n s / s o l v e r s / m u l t i p h a s e / bubbleFoam$ Listing 311: The source les of bubbleFoam Now.. in our case. In the However.H and wallFunctions. Notice the use of the wildcard Therefore.H DDtU .H createRASTurbulence . there are no such les.C is the a default location. Looking at the source code of a solver that supports LES models out of the box. that the le createRASTurbulence./bubbleFoam refers to user2. The directory of the main source le of twoPhaseLESEulerFoam. x/ a p p l i c a t i o n s / s o l v e r s / m u l t i p h a s e / bubbleFoam$ l s alphaEqn . the rst the wildcard is used to save typing eort. In this case sary commands for the Terminal.H user@ host : ~ /OpenFOAM/OpenFOAM− 2 . 1 . The second cp command copies the le createRASTurbulence. Listing 312 shows the neces- *. where the bubbleFoam to the sources of twoPhaseLESEulerFoam. ESI-OpenCFD or the OpenFOAM Foundation. -I.H and other could not be user-2.H. x/ a p p l i c a t i o n s / s o l v e r s / twoPhaseLESEulerFoam / Listing 312: Copy the missing le from the sources of bubbleFoam 37.H w a l l V i s c o s i t y .H Make readBubbleFoamControls . IX ® ® ® This oering is not approved or endorsed by ESI Group. In the case of twoPhaseLESEulerFoam. We now can delete the line containing in compiler looks for included les. wallViscosity. The solution In a rst attempt to ensure that our new solver compiles we can copy the missing les from the the sources of -I./bubbleFoam Make/options.1. . standard solver twoPhaseEulerFoam our solver fails to compile. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 198 . if we wanted to use the k- turbulence model.H k E p s i l o n . The twoPhaseEulerFoam solver is based on bubbleFoam. 1 . we should rst have a look at other solvers. user@ host : ~ /OpenFOAM/OpenFOAM− 2 .H pEqn .x/applications/solvers/bubbleFoam which does not exist. there are source les of another solver included in twoPhaseEulerFoam. However. 1 .x/applications/solvers/twoPhaseLESEulerFoam directory. then copying the missing le from the sources of bubbleFoam would be the proper thing to do. pimpleFoam is a solver for an incompressible uid. 1 . found. H" " p i m p l e C o n t r o l .H turbulenceModel.g. see Listing 155.H" " subCycle .H" // f o r u s i n g LES #i n c l u d e " s i n g l e P h a s e T r a n s p o r t M o d e l .4 Integrate LES 37.H" "MULES. Since we want to use the LES models provided by OpenFOAM we simply copied from other solver. we stick to the original code of twoPhaseEulerFoam as far as it is feasible.H" " f i x e d V a l u e F v s P a t c h F i e l d s . The header le provides a transport model and the le turbulenceModel. 25 we update the eld nuEff2.4. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ESI-OpenCFD or the OpenFOAM Foundation. the variable LESModel.4. sgsModel line would In line pimpleFoam.1 Include required models In order to make use of the LES turbulence model we need to include the header le singlePhaseTransportModel. ® ® 199 . which is the eective viscosity of the continuous phase. To keep the number of changes in the source code low. 37.H" #i n c l u d e "OFstream .H. However. Instead of the le we will include the le LESModel.H" " t u r b u l e n c e M o d e l . IX ® ® ® This oering is not approved or endorsed by ESI Group.H because the turbulence models of OpenFOAM make use of the transport model.H singlePhaseTransportMod provides all denitons of the generic turbulence model.comparing twoPhaseEulerFoam with pimpleFoam is not a bad idea. Listing 314 shows the rst group of include statements of the le twoPhaseLESEulerFoam. This le denes the base class for all LES turbulence models.H" #i n c l u d e " IFstream .H. This le contains the k- turbulence model.H" " Switch . 1 2 3 4 5 #i n c l u d e #i n c l u d e #i n c l u d e #i n c l u d e #i n c l u d e "fvCFD .H" " n e a r W a l l D i s t .2 Replace the k- model In the le twoPhaseLESEulerFoam we need to replace the statement that includes the le kEpsilon.H" #i n c l u d e " k i n e t i c T h e o r y M o d e l .H" " s i n g l e P h a s e T r a n s p o r t M o d e l .H" #i n c l u d e "LESModel .H" #i n c l u d e " phaseModel . This in- is of type struction is necessary because twoPhaseEulerFoam uses a distinct eld for the eective viscosity.H" #i n c l u d e "MRFZones .H" " I O b a s i c S o u r c e L i s t .H" #i n c l u d e " dragModel . The last two lines include the transport model and the LES model.H" Listing 313: Including turbulence: pimpleFoam The second and the third line are required for using a generic turbulence model. #i n c l u d e #i n c l u d e #i n c l u d e #i n c l u d e #i n c l u d e #i n c l u d e #i n c l u d e "fvCFD . whereas in the source code of solvers that use generic turbulence modelling this read turbulence->correct(). Other solvers access this quantity via their turbulence model.H" " wallFvPatch . In line 24 of Listing 316 we write a similar instruction like in e.H" Listing 314: The rst group of include statements in twoPhaseLESEulerFoam 37.H" #i n c l u d e " p i m p l e C o n t r o l . we need to create a transport model and a LES model.H I n f o << " C a l c u l a t i n g f i e l d nuEff1 \n" << e n d l . Then. runTime . } Listing 315: The main loop in twoPhaseLESEulerFoam 37. phi2 . The question of how to model turbulence in two-phase ows is completely anNow. ESI-OpenCFD or the OpenFOAM Foundation. I O o b j e c t : : NO_WRITE ). this is just one possibility.H" } #i n c l u d e "DDtU .H" // −−− P r e s s u r e c o r r e c t o r l o o p w h i l e ( pimple . f l u i d ) ). f i n a l I t e r ( ) ) { #i n c l u d e " alphaEqn . v o l S c a l a r F i e l d nuEff1 ( IOobject ( " nuEff1 " .H" sgsModel −>c o r r e c t ( ) .H.H" } i f ( pimple . So. we need to modify the le including the le swered. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. timeName ( ) . autoPtr<i n c o m p r e s s i b l e : : LESModel> sgsModel ( i n c o m p r e s s i b l e : : LESModel : : New(U2 . ® ® 200 . Finally. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 /* l o t s o f code */ //#i n c l u d e " createRASTurbulence . First we need to comment or delete the include statement createRASTurbulence. c o r r e c t ( ) ) { #i n c l u d e "pEqn .4. sgsModel −>nut ( ) + nu1 // nuEff1 w i l l be o v e r w r i t t e n a t t h e end o f t h e f i l e ). t u r b C o r r ( ) ) { //#i n c l u d e " k E p s i l o n .3 for a discussion about turbulence in two-phase solvers. IX ® ® ® This oering is not approved or endorsed by ESI Group.H into the le createFields. we need to copy the instructions that create the elds nuEff1 and nuEff2 from the le createRASTurbulence. See Section 40. I O o b j e c t : : NO_READ. nuEff2 = sgsModel −>nuEff ( ) .H.3 Create a LES model createFields.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 // −−− P r e s s u r e − v e l o c i t y PIMPLE c o r r e c t o r l o o p w h i l e ( pimple . l o o p ( ) ) { #i n c l u d e " alphaEqn .H" #i n c l u d e "UEqns .H. // new from createRASTurbulence .H" #i n c l u d e " l i f t D r a g C o e f f s .H" /* even more code */ // new f o r LES s i n g l e P h a s e T r a n s p o r t M o d e l f l u i d (U2 . mesh .H" } i f ( c o r r e c t A l p h a && ! pimple . p h i 2 ) . ® ® 201 . we need to adjust some more les.31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 I n f o << " C a l c u l a t i n g f i e l d nuEff2 \n" << e n d l . EXE_INC = \ − I $ (LIB_SRC) / f i n i t e V o l u m e / l n I n c l u d e \ − I $ (LIB_SRC) / t r a n s p o r t M o d e l s \ − I $ (LIB_SRC) / t r a n s p o r t M o d e l s / i n c o m p r e s s i b l e / l n I n c l u d e \ − I $ (LIB_SRC) / t r a n s p o r t M o d e l s / i n c o m p r e s s i b l e / s i n g l e P h a s e T r a n s p o r t M o d e l \ −I k i n e t i c T h e o r y M o d e l s / l n I n c l u d e \ −I i n t e r f a c i a l M o d e l s / l n I n c l u d e \ − IphaseModel / l n I n c l u d e \ − I $ (LIB_SRC) / t u r b u l e n c e M o d e l s \ − I $ (LIB_SRC) / t u r b u l e n c e M o d e l s / i n c o m p r e s s i b l e /LES/LESModel \ − I $ (LIB_SRC) / t u r b u l e n c e M o d e l s /LES/ LESdeltas / l n I n c l u d e \ −I a v e r a g i n g EXE_LIBS = \ −l E u l e r i a n I n t e r f a c i a l M o d e l s \ −l f i n i t e V o l u m e \ − lme shTo ols \ −l i n c o m p r e s s i b l e T r a n s p o r t M o d e l s \ − lphaseModel \ −l k i n e t i c T h e o r y M o d e l \ −l i n c o m p r e s s i b l e L E S M o d e l s Listing 317: Content of Make/options 37. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.4 Make ready for compiling In order to be ready to compile the new solver.5 Compile The solver can be compiled by invoking IX wmake. I O o b j e c t : : NO_WRITE ). Listing 316: The main loop in twoPhaseLESEulerFoam 37. Listing 317 shows the necessary modications of the le Make/options. ESI-OpenCFD or the OpenFOAM Foundation. sgsModel −>nut ( ) + nu2 ). mesh . These adjustments are necessary in order to enable the compiler to nd all included les. timeName ( ) . runTime . ® ® ® This oering is not approved or endorsed by ESI Group. I O o b j e c t : : NO_READ. // s e t nuEff1 a c c o r d i n g t o Jakobsen 1997 nuEff1 = rho1 * nuEff2 / rho2 . v o l S c a l a r F i e l d nuEff2 ( IOobject ( " nuEff2 " .4. 1 Temporal discretization 38.2 Spatial discretization The purpose of spatial discretization schemes is to compute the face values of elds whose values are stored at the cell centre.3 Continuity error correction In the governing equations of some solvers in OpenFOAM e.3 QUICK scheme The FLUENT Theory Guide [1] states: For quadrilateral and hexahedral meshes.g.2.1 Conserving the form Before we start our considerations.2 linearUpwind scheme The linearUpwind scheme is equivalent to FLUENTs Second-Order Upwind Scheme.Part X Theory This section covers more detailled topics and tries to look under the hood of OpenFOAM from a non-programming view. for computing the spatial derivatives. 38. The face values are then used e.1 upwind scheme An upwind scheme determines the face value of a quantity simply by choosing the cell centered value of the cell that is located upwind of the face in question.2.x we nd a special correction for the continuity error.g. 38.2. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ESI-OpenCFD or the OpenFOAM Foundation.3. where unique upstream and downstream faces and cells can be identied. 38 Discretization 38. ® ® 202 . ANSYS FLUENT also provides the QUICK scheme for computing a higher-order value of the convected variable at a face. First.3.4 MUSCL scheme 38.2. 38. 38. 38. we take a closer look on the conservation and nonconservation form of a transport equation. we recall the denition of the substantial derivative: For example applied to an arbitrary scalar X D ∂ = + (u · ∇) Dt ∂t (115) DK ∂K = + u · ∇K Dt ∂t (116) K ® ® ® This oering is not approved or endorsed by ESI Group. in twoPhaseEulerFoam of OpenFOAM-2. (125). We now rearrange the equation in order to gain the nonconservation form. This example is motivated by the energy equation of twoPhaseEulerFoam in OpenFOAM-2. Thus. ESI-OpenCFD or the OpenFOAM Foundation. The equation we looked up (Eqn.Continuity equation As a rst example we look up the dierential form of the continuity equation. The term marked with II is the substantial derivative of hk .3. For the sake of brevity. since we can express one equation easily by the other one with the help of some simple mathematical operations. we gain ∂hk ∂αk ρk hk + αk ρk + hk ∇ · (αk ρk uk ) + αk ρk uk · ∇hk = RHS ∂t ∂t ∂αk ρk ∂hk hk + ∇ · (αk ρk uk ) +αk ρk + uk · ∇hk = RHS ∂t ∂t | {z } | {z } I (123) (124) II We now pay attention to the term marked by I. We could also have used the momentum equation. 5]. ∂ρ + ∇ · (ρu) = 0 ∂t Dρ + ρ∇ · u = 0 Dt conservation form: nonconservation form: (117) (118) Both forms are equivalent to each other. the noncon- servation form of the energy equation. ∂ρ + ∇ · (ρu) = 0 ∂t (119) ∂ρ + ∇ρ · u + ρ∇ · u = 0 ∂t ∂ρ + u · ∇ρ +ρ∇ · u = 0 } |∂t {z (120) (121) Dρ Dt Transport equation For the next example we use the right hand side of the transport equation of enthalpy in a multiphase problem. in we do not solve the s we gain from physics. ® ® 203 . We look up the energy equation for multiphase ows from a textbook or other resources [1. However. (122)) happens to be formulated in the conservation form. α k ρk ∂hk + uk · ∇hk = RHS ∂t Dhk αk ρk = RHS Dt (125) (126) All the operations we applied to get from Eqn. ∂αk ρk hk + ∇ · (αk ρk uk hk ) = RHS ∂t (122) by partial derivation of the LHS. however. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.x.2 Continuity error In theory and in the mathematical sense the conservation and nonconservation forms are equivalent. Thus we gain with Eqn. but the linear equation system stemming from discretizing those X ® ® ® This oering is not approved or endorsed by ESI Group. (122) to (125) applied only to the left hand side. we want to avoid confusion by the repeated occurance of the velocity. 38. we state only the left hand side of the equation.3. the distinction in conservation and nonconservation form applies only to the left hand side of the equation. we recognize the phase-continuity equation which equals zero. C. see Line 4 of Listing 319. rho1 . he1 ) + fvm : : d i v ( alphaRhoPhi1 . (128). as the discretised phase continuity equation might not equal zero. the left hand sides of Eqns. ® (129) ® 204 . (129). (129) and name some of the terms. we could also write ∂αk ρk hk + ∇ · (αk ρk uk hk ) − hk ∂t ∂αk ρk + ∇ · (αk ρk uk ) = RHS ∂t (129) Mathematically. he1 ) /* o t h e r s t u f f */ ). The resulting linear equation system we solve is not necessarily a direct representation of our initial PDEs.H of twoPhaseEulerFoam. 1 2 3 4 5 6 Listing 318: The rst terms of the energy equation in the le EEqns. In Listing 319 we see the rst terms of the energy equation of one phase.PDEs. f v S c a l a r M a t r i x he1Eqn ( fvm : : ddt ( alpha1 . Eqns. (125) and (129) might actually be dierent. that the solver considers phase sources. ESI-OpenCFD or the OpenFOAM Foundation. The dierence between the (exact) solution of the system of algebraic equations and the (unknown) solution of the mathematical model (the PDEs) is generally referred to as discretisation error [17]. (125) and (129) are equivalent. ∂αk ρk hk | ∂t {z } fvm::ddt(alpha1. In Lines 3 and 4 of Listing 319 we see the left hand side of Eqn. rho1 )&rho1 ) ). rho1 ) + f v c : : d i v ( alphaRhoPhi1 ) − ( f v O p t i o n s ( alpha1 . In Listing 319 the denition of the continuity error diers slightly from Eqn. For a discussion on the full energy equations see Section 22. For this we choose the nonconservative form (125). the producer of the OpenFOAM software and owner of the OpenFOAM trademark. rho1.5. This is due to the fact. However. We now use Eqns. twoPhaseEulerFoam. 1 2 3 4 5 Listing 319: The denition of the continuity error in the le We can create more resemblance if we repeat Eqn. (129). v o l S c a l a r F i e l d contErr1 ( f v c : : ddt ( alpha1 .3. he1 ) − fvm : : Sp ( contErr1 . We now take a break from math and take a look into the source code of twoPhaseEulerFoam -2. he1) ® −hk ∂αk ρk + ∇ · (αk ρk uk ) = RHS ∂t | {z } contErr1 ® ® This oering is not approved or endorsed by ESI Group. αk ρk ∂hk + uk · ∇hk ∂t = RHS (125) Using Eq. (122) and (125) to to some rearrangement. ∂αk ρk hk ∂hk ∂αk ρk + ∇ · (αk ρk uk hk ) = αk ρk + uk · ∇hk + hk + ∇ · (αk ρk uk ) ∂t ∂t ∂t ∂αk ρk hk ∂αk ρk ∂hk + ∇ · (αk ρk uk hk ) − hk + ∇ · (αk ρk uk ) = αk ρk + uk · ∇hk ∂t ∂t ∂t (127) (128) We now want to solve the energy equation.x. when we now discretize both equations in order to solve them numerically. he1) X + ∇ · (αk ρk uk hk ) | {z } fvm::div(alphaRhoPhi1. ∂u + ∇(uu) + ∇ · dev(Ref f ) = −∇p + Q ∂t {z } | (42) =div(dev(Ref f )) Ref f = −ν ef f ∇u + (∇u)T (36) ∂u + ∇(uu) + ∇ · dev(−ν ef f ∇u + (∇u)T ) = −∇p + Q ∂t (43) The momentum diusion term is handled by the turbulence model. U) + t u r b u l e n c e −>d i v D e v R e f f (U) ). c o n s t r a i n (UEqn ( ) ) . that all RAS turbulence model classes as well as all LES turbulence model classes are derived from the same base class. by the time of writting the source code. that the method 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // S o l v e t h e Momentum e q u a t i o n tmp<f v V e c t o r M a t r i x > UEqn ( fvm : : ddt (U) + fvm : : d i v ( phi . Therefore. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.1 we discussed the governing equations of a solver for incompressible uids.2 Implementation All turbulence model of OpenFOAM are based on a generic turbulence model class. l a m i n a r T r a n s p o r t ) ). nobody could have known. which turbulence exactly will handle the momentum diusion term. 1 2 3 4 5 6 createFields. phi .6 shows a class diagram. s o u r c e s .H of pimpleFoam X ® ® ® This oering is not approved or endorsed by ESI Group. i f ( pimple . Figure 45 in Section 35.A( ) ) . UEqn ( ) . v o l S c a l a r F i e l d rAU ( 1 . Listing 321: The le createFields.1 Governing equations In Section 20. p h i ) . 0 / UEqn ( ) .39 Momentum diusion in an incompressible uid 39. This instruction means. momentumPredictor ( ) ) { s o l v e (UEqn ( ) == − f v c : : grad ( p ) + s o u r c e s (U) ) . diusive term.H tells us. ESI-OpenCFD or the OpenFOAM Foundation. modern programming languages support a technique called polymorphism.H of pimpleFoam The source code of the le turbulenceModel. that the object turbulence is of the data type s i n g l e P h a s e T r a n s p o r t M o d e l l a m i n a r T r a n s p o r t (U. autoPtr<i n c o m p r e s s i b l e : : turbulenceModel > t u r b u l e n c e ( i n c o m p r e s s i b l e : : t u r b u l e n c e M o d e l : : New(U. There. ® ® 205 . To overcome such problems. } Listing 320: The le UEqn. A lot of solvers of OpenFOAM allow the user to choose between laminar simulation as well as RAS or LES turbulence modelling. it is shown. In the source code the instruction turbulence->divDevReff(U) is called to compute the divDevReff() of the object turbulence is called. ∇ · dev(Ref f ) | {z } turbulence->divDevReff(U) ⇔ =div(dev(Ref f )) 39. r e l a x ( ) . will be made at runtime based on the actual type of turbulence. //− Return t h e s o u r c e term f o r t h e momentum e q u a t i o n v i r t u a l tmp<f v V e c t o r M a t r i x > d i v D e v R e f f ( v o l V e c t o r F i e l d& U) c o n s t = 0 . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. k and local derivative X Cµ = 0. U) − f v c : : d i v ( nuEff ( ) * dev (T( f v c : : grad (U) ) ) ) ).1 The k- turbulence model in literature The governing equations for the k- model for a single phase are taken from Wilcox [30]. σk = 1. σ = 1.92.6 for a discussion on virtual methods. It will be of a data type derived from turbulenceModel.3 (133) are reorganized to follow the basic structure + convection + diusion ® = source & sink terms ® ® This oering is not approved or endorsed by ESI Group. The decision which exact method divDevReff() has to be called. The transport equations for C2 = 1. divDevReff = ∇ · dev(−ν ∇U + (∇U)T ) = −∇ · (ν(∇U)) − {z } | laplacian(nu. (43). 40 The incompressible k- turbulence model 40. Eddy viscosity µT = ρCµ k2 (130) Turbulent kinetic energy ∂k ∂k ∂Ui ∂ µT ∂k ρ + ρUj = τij − ρ + (µ + ) ∂t ∂xj ∂xj ∂xj σk ∂xj (131) Dissipation Rate ρ ∂ ∂ ∂Ui 2 ∂ µT ∂ + ρUj = C1 τij − C2 ρ + (µ + ) ∂t ∂xj k ∂xj k ∂xj σ ∂xj (132) Closure coecients C1 = 1. Listing 323 shows how this method is actually implemented by the standard k- turbulence By the time of compilation.09. See Section 35. it is guaranteed that the object However. turbulence will never actually be of the data type turbulenceModel.0.H The calculation of divDevReff() is equivalent to Eq. Listing 322: Declaration of the virtual Method divDevRe in turbulenceModel. models of OpenFOAM. } Listing 323: Implementation of the virtual Method divDevRe in kEpsilon.H tmp<f v V e c t o r M a t r i x > k E p s i l o n : : d i v D e v R e f f ( v o l V e c t o r F i e l d& U) c o n s t { return ( − fvm : : l a p l a c i a n ( nuEff ( ) . ESI-OpenCFD or the OpenFOAM Foundation. ® ® 206 .turbulence is of the data type turbulenceModel. Listing 322 shows the declaration of the virtual method divDevReff().44.U) ∇ · ν(∇U)T | {z } div(nu*dev(T(grad(U)))) The momentum diusion term is most probably split into two parts for numerical reasons. there are some modications to the equations. see Listing 325 ∂k ∂k = U· = U · ∇k ∂xj ∂x ∂k = ∇ · (Uk) − (∇ · U)k U· ∂x Uj (139) ∂k + ∇ · (Uk) − (∇ · U)k − ∇ · (Dk ∇k) = G − ∂t (140) ∂ 1 2 + ∇ · (U) − (∇ · U) − ∇ · (D ∇) = C1 G − C2 ∂t k k (141) Dissipation Rate X ® ® ® This oering is not approved or endorsed by ESI Group. the standard k- model of OpenFOAM has eliminated the model constant σk . The k- turbulence model in OpenFOAM 40.2. µ. See Eqn. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.2 for a discussion and an example. (139). the transport equations for k viscosity contain the kinematic viscosity and ν are divided by the density instead of the dynamic viscosity ρ.2. ESI-OpenCFD or the OpenFOAM Foundation. First. ® ® 207 . However.1. all terms containing Secondly.Turbulent kinetic energy ρ ∂k ∂k ∂ (µ + µT ) ∂k = τij ∂Ui −ρ + ρUj − ∂t ∂xj ∂xj σ ∂x ∂xj | {z k } j | {z } Dk (134) G Dissipation Rate ρ ∂ ∂ ∂ + ρUj − ∂t ∂xj ∂xj µT ∂ (µ + ) σ ∂x | {z } j = C1 D 2 ∂Ui −C2 ρ τij k ∂xj k | {z } (135) G Diusivity constants µT σk µT D = µ + σ Dk = µ + (136) (137) The constant expressions in the diusive terms are combined into the diusivity constants Dk and D . nothing actually happens. The vector notation is used in this section because the syntax OpenFOAM uses strongly resembles the vector notation. See Section 17. if the user tries to change this model constant. the convection term is converted into two term by the product rule of dierentiation. this constant has been elimininated.1 Governing equations The governing equations of the k- model of OpenFOAM are basically the same equations as in Section 40. However.2 G. Finally. see Listing 324 µT = ρ νT νT = Cµ k2 (138) Turbulent kinetic energy. The rst term on the right hand side of the turbulent kinetic energy equation is the production of turbulent kinetic energy 40. Eddy viscosity. Since the value of this constant is one. This does not change the behaviour of the model. Therefore. This list contains also the default values of the model constants. ® ® 208 . σ = 1. Cµ = 0.2 The source code Listing 324 shows the calculation of the eddy viscosity. After the colon (in line 9).Note that σk has been eliminated from the equations Dk = DkEff = ν + νT (142) νT D = DepsilonEff = ν + σ (143) Closure coecients .2. See Section 34. In line 18 the default value of the model constant 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Cµ is dened. A (too) short glimpse on the code may lead to confusion. k) nut_ = Cmu_* s q r (k_) / e p s i l o n _ . c o n s t word& turbulenceModelName . Cmu_ ( dimensioned<s c a l a r > : : lookupOrAddToDict X ® ® ® This oering is not approved or endorsed by ESI Group. turbulenceModelName ) .44. k_) ). as the function sqr() meaning taking a variable to the power of two looks similar to sqrt(). The constructor receives ve argu- ments. k_) − fvm : : Sp ( f v c : : d i v ( phi_ ) . Listing 325 shows the transport equation for the turbulent viscosity. k_) == G − fvm : : Sp ( e p s i l o n _ /k_ . the initialisation list follows.09.92. t r a n s p o r t . The last term on the right hand side is expanded. ESI-OpenCFD or the OpenFOAM Foundation. c o n s t s u r f a c e S c a l a r F i e l d& phi . t r a n s p o r t M o d e l& t r a n s p o r t . Listing 324: Calculation of the eddy viscosity tmp<f v S c a l a r M a t r i x > kEqn ( fvm : : ddt (k_) + fvm : : d i v ( phi_ .3 (144) The default values of the model constants can be found in the constructor of the respective turbulence model class. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. C2 = 1. = k k |{z} (145) fvm::Sp(epsilon/k. which is the square root. phi .Diusivity constants . U. Listing 325: Transport equation for the turbulent kinetic energy Constructor Listing 326 shows the rst lines of the constructor of the kEpsilon class.5 for details about constructors in C++. k_) − fvm : : l a p l a c i a n ( DkEff ( ) . 40. kEpsilon : : kEpsilon ( c o n s t v o l V e c t o r F i e l d& U.default values C1 = 1. c o n s t word& modelName ) : RASModel ( modelName . 3. coeffDict_ . (136.T = Cµ ν2. a value for σk σk is not dropped. This constant connects the turbulent viscosity of the liquid and the gas phase. Compare Eqns. The model constants σk and σ are replaced by their reciprocal values. 40. There are several strategies: Per phase Mixture The turbulence is modelled for both phases individually. 3. Liquid phase Turbulence is modelled based in the quantites of the liquid phase. see Listing 325 Dissipation Rate X ® ® ® This oering is not approved or endorsed by ESI Group. Turbulence modelling in bubbleFoam and twoPhaseEulerFoam is based on the liquid quantities. The turbulence of the dispersed phase is either neglected or considered by a model constant. The question of turbulence modelling in dispersed two-phase ows is not fully answered yet.k = 1/σk .ef f ∇) = C1 G − C2 ∂t k k (150) Turbulent kinetic energy. By setting this constant to zero. This means. Turbulence of the gas phase is considered by the use of the model constant Ct .T ν2. By dening a value for the is assigned. 152) 2. that these solvers do not use the generic turbulence modelling other than most OpenFOAM solvers. ν2. 1. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. 137) and (151. turbulence is ignored in the gas phase. ESI-OpenCFD or the OpenFOAM Foundation.( 15 16 17 18 19 20 21 "Cmu" . Other than in the standard k- model.T (148) ∂k + ∇ · (U2 k) − (∇ · U2 )k − ∇ · (α1.k ν2.ef f (146) (147) ν1.09 ) ). /* code c o n t i n u e s */ Listing 326: The constructor of the 40. the model constant constant α1. Eddy viscosity k2 = ν2 + ν2.ef f = ν1 + Ct2 ν2. ® ® 209 . The diusivity constants are calculated from the eective viscosity.1 Governing equations The k- turbulence model of bubbleFoam and twoPhaseEulerFoam is in some aspects dierent than the standard k- turbulence model of OpenFOAM.3 kEpsilon class The k- turbulence model in bubbleFoam and twoPhaseEulerFoam The k- turbulence model is hardcoded in bubbleFoam and twoPhaseEulerFoam.ef f ∇k) = G − ∂t (149) ∂ 1 2 + ∇ · (U2 ) − (∇ · U2 ) − ∇ · (α1. The turbulence is modelled based on mixture quantities. 0. Cµ = 0.92. Listing 327: The turbulent transport equations of the 40. k ) ).ef f σk ν2.76923 (153) 40. Listing 327 tmp<v o l T e n s o r F i e l d > tgradU2 = f v c : : grad (U2) .Note the dierent denition 1 σk 1 = σ α1.H. epsilon ) " ) == C1*G* e p s i l o n /k − fvm : : Sp (C2* e p s i l o n /k . " l a p l a c i a n ( DkEff . v o l S c a l a r F i e l d G( 2 * nut2 * ( tgradU2 ( ) && dev (symm( tgradU2 ( ) ) ) ) ) .2 Source code The transport equations of bubbleFoam and twoPhaseEulerFoam reside in the le shows the most important lines of 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 kEpsilon. X ® ® ® This oering is not approved or endorsed by ESI Group.44. e p s i l o n ) ).3. ν2.4 bubbleFoam and twoPhaseEulerFoam solver Modelling the production of turbulent kinetic energy When comparing the turbulent equations From literature and the sources. k .default values C1 = 1. // Turbulent k i n e t i c e n e r g y e q u a t i o n f v S c a l a r M a t r i x kEqn ( fvm : : ddt ( k ) + fvm : : d i v ( phi2 . e p s i l o n .ef f = σ Dk = α1.ef f (152) Closure coecients . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ν2. " laplacian ( DepsilonEff . k ) − fvm : : Sp ( f v c : : d i v ( p h i 2 ) .k ν2.k = α1.H. ® ® 210 . ESI-OpenCFD or the OpenFOAM Foundation.09. C2 = 1. α1. e p s i l o n ) − fvm : : Sp ( f v c : : d i v ( p h i 2 ) .ef f = (151) D = α1.Diusivity constants . e p s i l o n ) − fvm : : l a p l a c i a n ( alpha1Eps * nuEff2 . α1. k ) − fvm : : l a p l a c i a n ( alpha1k * nuEff2 .k = 1. = 0. //− Re− c a l c u l a t e t u r b u l e n c e v i s c o s i t y nut2 = Cmu* s q r ( k ) / e p s i l o n . // D i s s i p a t i o n e q u a t i o n f v S c a l a r M a t r i x epsEqn ( fvm : : ddt ( e p s i l o n ) + fvm : : d i v ( phi2 . the denition of the production of turbulent kinetic energy shows great dierences. kEpsilon. k ) " ) == G − fvm : : Sp ( e p s i l o n /k . Therefore. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.4. ® ® 211 . It is not further specied what is meant with high-Reynolds number versions of the k- model. (154) is the only denition that makes use of the [25] eective viscosity instead of the turbulent viscosity.ef f ∇Ub : dev ∇Ub + (∇Ub )T (159) 40. this is no major dierence between the denitions.40. (157) and (158) dier only in the last term.ef f ∇Ub · dev ∇Ub + (∇Ub )T Source code - kEpsilon. the equation should read Pb = 2ν2. (154) The result only has the correct dimension. 40.the basis of bubbleFoam and twoPhaseEulerFoam Pb = 2ν2.4. We now can examine the dierences of the denitions of the production term.1 are written in vector notation.standard k- model.ef f ∇Ub · dev ∇Ub + (∇Ub )T The dot can not denote an inner product. For incompressible uids. However.H (154) of bubbleFoam .See Line 2 Listing 327 G = 2νT (∇U2 : dev(sym(∇U2 ))) Source code . (154). Thesis of H.1 Denitions from literature and source les The production of turbulent kinetic energy seems to be dierently dened. there seems to be a minor aw in Eq.4.4. X ® ® ® This oering is not approved or endorsed by ESI Group. the FLUENT Theory Guide [1] states that the eective viscosity is used to calculate the production term when high-Reynolds number versions of the k- model are used.2 Dierent use of viscosity Eq. the contraction can be replaced by an inner product I : ∇U = tr(∇U) = ∇ · U (160) For incompressible uids the divergence of the velocity must be zero due to the continuity equation ∇·U = 0 G = µT ∇U : ∇Ub + (∇Ub ) (161) T 2 − ρkI : ∇U 3 | {z } (162) =0 Therefore. using Eq.4. The reason for this is not explained. 40. Rusche [25] . if the dot denotes a contraction. However.4 Denitions from literature The denition of the production term in Eq. There Pb = 2ν2. ESI-OpenCFD or the OpenFOAM Foundation.C G = 2νT |sym(∇U)|2 (156) Ferzinger Peric [16] P = µT ∇U : ∇U + (∇U)T (157) Wilcox [30] 2 G = µT ∇U : ∇U + (∇U)T − ρkI : ∇U 3 (158) Some denitions use the dynamic viscosity and some others use the kinematic viscosity. (157) and (158) are identical if the uid is incompressible. (157) as reference equation. Eqns. 2 G = µT ∇U : ∇Ub + (∇Ub )T − ρkI : ∇U 3 (158) Using the following identities.3 Notation The denitions in Section 40. (155) kEpsilon. ESI-OpenCFD or the OpenFOAM Foundation. compare Eqns. However. The question of considering turbulence in two-phase systems is not answered yet. 2. Compare Eq. Rusche [25]. (154) and (155). The use of dierent viscosities. Therefore.4.5 Denitions of Rusche and bubbleFoam The solvers bubbleFoam and twoPhaseEulerFoam are based on the thesis of H. bubbleFoam is a two-phase solver. H. The denition of Ferzinger is like the equations in most other book about turbulence for single-phase systems. (164) and (171) The reason for this dierences is not clear.ef f ∇Ub : dev ∇Ub + (∇Ub )T (154) G = 2νT (∇U2 : dev(sym(∇U2 ))) (155) We ignore the dierent symbols for the velocity of the continuous phase U2 = U b (163) The second operator of the contraction is dierent in both equations. G = 2νT (∇U2 : dev(sym(∇U2 ))) P = µT ∇U : ∇U + (∇U)T X ® (155) (157) ® ® This oering is not approved or endorsed by ESI Group. see Eqns. However.4. Rusche refers to an article which is not available to the author. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. (154) and (155). turbulence model equations of bubbleFoam are quite similar to single-phase turbulence equations. The turbulence of the disperse phase is linked to the continuous phase. A factor of 2. ® ® 212 . bubbleFoam considers turbulence for the continuous phase by the use of a turbulence model.6 Denitions of Ferzinger and bubbleFoam We now compare the denitions of Ferzinger and bubbleFoam. if the following equation holds ? ∇U2 : dev(sym(∇U2 )) = ∇Ub : dev ∇Ub + (∇Ub )T (164) With the following identities the question is easily answered dev(T) = T − 1 tr(T) 3 (165) 1 T + (T)T 2 1 T dev (sym(∇U2 )) = dev ∇U2 + (∇U2 ) 2 1 dev (sym(∇U2 )) = dev ∇U2 + (∇U2 )T 2 1 1 T T (∇U2 + (∇U2 ) ) − tr(∇U2 + (∇U2 ) ) dev (sym(∇U2 )) = 2 3 | {z } sym(T) = (166) (167) (168) (169) =dev(∇U2 +(∇U2 )T ) dev (sym(∇U2 )) = 1 dev ∇U2 + (∇U2 )T 2 (170) 1 ∇Ub : dev ∇Ub + (∇Ub )T 2 (171) This leads to the answer ∇U2 : dev (sym(∇U2 )) = The denition of the production term in the source code diers in two ways from the denition in the source code 1. the production term is dened dierently.40. We ask. 40. Pb = 2ν2. Source code . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. we proofed that the denition of bubbleFoam is equivalent to the denition of Ferzinger ∇U : ∇U + (∇U)T = ∇U : dev ∇U + (∇U)T (180) 40.C G = 2νT |sym(∇U)|2 (156) Ferzinger Peric [16] P = νT ∇U : ∇U + (∇U)T (157) Starting from Eq.We ignore the dierent viscosities and ask ourselves ? ∇U : ∇U + (∇U)T = 2 (∇U2 : dev(sym(∇U2 ))) (172) Inserting Eq. (174) ∇U : ∇U + (∇U)T = ∇U : dev(∇U + (∇U)T ) + 1 tr(∇U + (∇U)T ) 3 (175) Using the following identities and Eq.7 Denition of standard k- of OpenFOAM We now compare the denition of the production term of the standard k- model implemented in OpenFOAM with the denition found in [16]. kEpsilon. Therefore.4. (180) and Eq. (174). ESI-OpenCFD or the OpenFOAM Foundation. (170) ∇U : ∇U + (∇U)T = ∇U : dev ∇U + (∇U)T dev ∇U + (∇U)T = 2 dev (sym(∇U)) (180) ∇U : ∇U + (∇U)T = 2 ∇U : dev (sym(∇U)) (181) (170) to gain We use denition (182) to change Eq.standard k- model. (170) gives ∇U : ∇U + (∇U)T = 2(∇U2 : dev(sym(∇U2 ))) {z } | = 12 ∇U : ∇U + (∇U) T dev(∇U2 +(∇U2 (173) )T ) = ∇U2 : dev ∇U2 + (∇U2 )T (174) Now we insert Eq. (160) tr(A + B) = tr(A) + tr(B) (176) T tr(A ) = tr(A) (177) I : ∇U = tr(∇U) = ∇ · U 2 T T ∇U : ∇U + (∇U) = ∇U : dev(∇U + (∇U) ) + (∇ · U) 3 (160) (178) The second term of the rhs vanishes according to the continuity equation for an incompressible uid ∇U : ∇U + (∇U) T = ∇U : 2 dev(∇U + (∇U) ) + (∇ · U) 3 | {z } ∇ · U=0 T (179) Eq. (156) |sym(∇U)|2 = sym(∇U) : sym(∇U) X ® (182) ® ® This oering is not approved or endorsed by ESI Group. (180) now resembles Eq. (165) into the rhs of Eq. ® ® 213 . (157). we will use Eq. we can eliminate the second term of the rhs of Eq. we proofed that the denition of the standard k- model is equivalent to the denition of Ferzinger. ® ® 214 . we use some identities 1 tr(T) 3 tr(sym(T)) = tr(T) dev(T) = T − (165) (184) to reformulate the rhs of Eq.Now we pose the question ? sym(∇U) : sym(∇U) = ∇U : dev (sym(∇U)) (183) The lhs of Eq. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. (183) corresponds to Eq. (156). the large eddy modelling strategy requires some X ® ® ® This oering is not approved or endorsed by ESI Group. (185) by the use of Eq. The rhs of Eq.1 LES model hierarchy The large eddy simulation is based on the spatial ltering of the governing equations. 41 Some theory behind the scenes of LES 41. Similar to the Reynoldsaveraged modelling strategy (ltering with respect to time). we obtain Therefore. Now. (157). (160) I : ∇U = tr(∇U) = ∇ · U = 0 (160) ∇U : dev (sym(∇U)) = ∇U : sym(∇U) (186) We now have The following equation remains. (183) ∇U : dev (sym(∇U)) = ∇U : sym(∇U) − 1 tr(∇U) 3 (185) As we now concentrate on incompressible single-phase problems. we can write T : sym(T) = sym(T) : sym(T) + skew(T) : sym(T) (191) The following properties of skew tensors let the second contraction vanish skew(T) : sym(T) | {z } | {z } (192) aii = 0 (193) aij = −aji (194) skew(T) : sym(T) = aij sij = 0 (195) T : sym(T) = sym(T) : sym(T) (196) aij sij Finally. (183) was derived from Eq. which is easily proofed by some tensor calculus sym(∇U) : sym(∇U) = ∇U : sym(∇U) (187) Every tensor can be decomposed into a symmetric and a skew part T = sym(T) + skew(T) 1 T + TT sym(T) = 2 1 skew(T) = T − TT 2 (188) (189) (190) Therefore. ESI-OpenCFD or the OpenFOAM Foundation. algebraic model constant coecient dynamic coecient Smagorinsky Smagorinsky2 oneEqEddy homogeneousDynSmagorinsky spectEddyVisc dynOneEqEddy homogeneousDynOneEqEddy dynLagrangian one equation model Table 6: Comparison of the eddy viscosity models of OpenFOAM 87 In a class diagram a class with an italic written name is an abstract class. Similar to the RANS approach. The sub-grid scale portion or the inuence of the sub-grid scale portion on the resolved velocity needs to be modelled. Figure 48 shows the class hierarchy with focus on 41. the velocity is decomposed into a grid-scale and a sub-grid scale portion. the eddy viscosity models make use of the Boussinesq hypothesis.closure models. 41. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. e. but not every LES model is an eddy viscosity model. X ® ® ® This oering is not approved or endorsed by ESI Group. The contribution of the sub-grid scale terms is modelled by an additional viscosity.1 Class hierarchy The base class for all eddy viscosity models is GenEddyVisc. 88 This shows the great advantage of object oriented programming. νef f = ν + νSGS (197) 41. The grid-scale portion is resolved by the governing equations. every eddy viscosity model is an LES model. The class hierarchy of the LES models of OpenFOAM reects the dierent approaches. LESModel may be an abstract class itself and therefore be the base for other classes LESModel DESModel laminar GenSGSStress kOmegaSSTSAS GenEddyVisc scaleSimilarity Figure 47: First layer of the class hierarchy of the LES models of OpenFOAM The classication according to Figure 47 is not the only possible way to divide all existing LES models into categories.2 Eddy viscosity models One of the most common approaches of closing the governing equations when using an LES turbulence modelling strategy are eddy viscosity models. There are several modelling strategies to close the equations. Like the RANS turbulence models. First layer means that a class derived from the abstract class 8788 .2 Classication The eddy viscosity models can be divided further based on the way the sub-grid viscosity is computed and the complexity of the model. ® ® 215 . In principle.2. the closure terms appear in the stress terms of the momentum equations. The eective viscosity is the sum of the laminar viscosity and the sub-grid viscosity. ESI-OpenCFD or the OpenFOAM Foundation. GenEddyVisc.2. A class with an upright written name is an actual class. The class hierarchy of the code reects the relation between the objects in reality. Figure 47 shows the rst layer of the class hierarchy of the LES models in OpenFOAM.g. (204) shows the denition of the sub-grid scale viscosity according to the Samgorinsky model as it can be found in literature [10]. Eq.g. This model was published 1963 [26].4 The Smagorinsky LES model The Smagorinsky eddy viscosity is one of the simplest LES models.LESModel laminar dynLagrangian GenEddyVisc Smagorinsky oneEqEddy dynOneEqEddy spectEddyVisc homogeneousDynOneEqEddy homogeneousDynSmagorinsky Smagorinsky2 mixedSmagorinsky Figure 48: Class hierarchy of the eddy viscosity models in OpenFOAM 41. e. One equation models typically solve a transport equation for the sub-grid scale kinetic energy. ESI-OpenCFD or the OpenFOAM Foundation. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 216 . Eq.3 Eddy viscosity For dimensional reasons. the eddy viscostiy must be a product of a length and a velocity scale [10]. m2 m = ·m s s = CSGS lSGS qSGS [νSGS ] = νSGS (198) (199) A choice that is common to a number of eddy viscosity models in OpenFOAM is to choose the lter width as the length scale and the square root of the sub-grid kinetic energy as teh velocity scale. (199) shows the generic equation for the sub-grid viscosity. An additional model constant is the third term in the product.2. The way the model constant is computed as well as the choice for the length and velocity scales is determined by the model.2. Algebraic models usually calculate the sub-grid kinetic energy from known quantities. From Table 6 we see that this is an algebraic model with a constant model coecient. based on the velocity gradient. lSGS = ∆ (200) [lSGS ] = m p qSGS = kSGS r m2 m [qSGS ] = = s2 s (201) (202) (203) 41. X ® ® ® This oering is not approved or endorsed by ESI Group. √ νSGS = CS2 |{z} ∆ |∆ {z S : S} lSGS qSGS = (205) qSGS p √ kSGS = ∆ S : S (206) 2 ⇒ kSGS = ∆ S : S (207) Implementation The implementation in the source code diers a little from the equations above. 1 2 3 4 5 v o i d Smagorinsky : : u p d a t e S u b G r i d S c a l e F i e l d s ( c o n s t v o l T e n s o r F i e l d& gradU ) { nuSgs_ = ck_* d e l t a ( ) * s q r t ( k ( gradU ) ) .H Listing 328 shows the implementation of how the sub-grid viscosity is computed by the Smagorinsky model in OpenFOAM. ESI-OpenCFD or the OpenFOAM Foundation. (204) is necessary to match the form of Denition (199) and (202). ® ® 217 . 204 shows νSGS = (CS ∆)2 |S| r ck 2 ⇒ CS = ck 2 ce X ® (204) (213) ® ® This oering is not approved or endorsed by ESI Group. Eqns. 0 * ck_/ce_ ) * s q r ( d e l t a ( ) ) *magSqr ( dev (symm( gradU ) ) ) . (205) to (207) show the necessary steps to match the generic denition of νSGS . nuSgs_ . } Listing 328: The function 1 2 3 4 updateSubGridScaleFields() in the le Smagorinsky.νSGS = (CS ∆)2 |S| (204) with S = sym(∇u) = sym(grad(u)) √ |T| = T : T Some rearrangement of Eq. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. c o r r e c t B o u n d a r y C o n d i t i o n s ( ) . √ nuSgs = ck∆ k ck k = 2 ∆2 |dev S|2 ce (208) (209) with S = sym grad(u) (210) it follows r ck nuSgs = ck∆ 2 ∆2 |dev S|2 ce r ck 2 nuSgs = ck 2 ∆ |dev S| ce (211) (212) the comparison with Eq.C tmp<v o l S c a l a r F i e l d > k ( c o n s t tmp<v o l T e n s o r F i e l d >& gradU ) c o n s t { r e t u r n ( 2 . Listing 329 shows how the model calculates the sub-grid kinetic energy. } Listing 329: The function k() in the le Smagorinsky. ck GenEddyVisc This results in a default value fofr in literature depending on the publication from 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 in the le is the only degree of freedom of the Smagorinsky model of OpenFOAM. 22]. (213) shows how the Smagorinsky constant can be calculated from the model constants. I O o b j e c t : :NO_WRITE ). the producer of the OpenFOAM software and owner of the OpenFOAM trademark. //− Return sub− g r i d d i s i p a t i o n r a t e v i r t u a l tmp<v o l S c a l a r F i e l d > e p s i l o n ( ) c o n s t { r e t u r n tmp<v o l S c a l a r F i e l d > ( new v o l S c a l a r F i e l d ( IOobject ( " epsilon " .33 CS of 0. This model is an one equation eddy viscosity model with a constant model coecient. ESI-OpenCFD or the OpenFOAM Foundation. I O o b j e c t : :NO_READ.H 41. This constant is used in the denition of the sub-grid dissipation rate.094. ce_*k ( ) * s q r t ( k ( ) ) / d e l t a ( ) ) ). The value of CS varies [6. X ® ® ® This oering is not approved or endorsed by ESI Group. because it is the only degree of freedom of the Smagorinsky model. 0. the model constant The default value of ck is 0. ® ® 218 . kSGS kSGS .Eq. p kSGS (214) The transport equation for kSGS As this model is an one equation model. ce is 1. Thus. mesh_ . kSGS This is the kinetic energy of is called sub-grid kinetic energy. The Smagorinsky constant is often stated in publications using or investigating the Smagorinsky model. The constant ck has a default value of νSGS = ck∆ 0. ∂kSGS + ∇ · (kSGS u) − ∇ · (Dk ∇kSGS ) = G − SGS ∂t (215) with Dk = ν + νSGS G = νSGS |sym(∇u)|2 √ kSGS SGS = ce kSGS ∆ Eq. The default value of dened in the constructor of the class Therefore. it introduces an additional equation to the set of equations. Therefore. In OpenFOAM the Smagorinsky model has two model constants. } Listing 330: The function epsilon() in the le GenEddyVisc. ce is inherited from the class GenEddyVisc. 215 is similar to the transport equation for k of the k- model.07 to 0. runTime_ .C. additional equation is a transport equation for the sub-grid kinetic energy the unresolved protion of the velocity. 214 shows how the sub-grid viscosity is calculated by the oneEqEddy model. Eq.1995 ≈ 0. This is not very obvious.2.048 and is GenEddyVisc.2. timeName ( ) .094.5 The oneEqEddy LES model The oneEqEddy model is one of the standard LES models of OpenFOAM. Also the denition of the sub-grid viscos- ity is similar to the denition of the turbulent viscosity of the k- model. 1 2 3 4 5 6 7 8 9 i n t main ( i n t argc .1 The origin of elds One way to learn more about phi is to look for its denition in the source code of OpenFOAM. The le 15 the le X ® pimpleFoam.we shall explore this matter further. Implementation 42. which is 42 The use of 42.H" #i n c l u d e " c r e a t e T i m e . 43 are compared with the source code. when this program is executed. the pressure or the velocity eld).1 the governing equations of the solver pimpleFoam are examined. In line ® This oering is not approved or endorsed by ESI Group. In Section 20. 218 is similar to Eq. p νSGS = ck∆ kSGS √ ce kSGS kSGS p √ νSGS = ck ∆ kSGS ce kSGS kSGS √ √ kSGS kSGS kSGS √ νSGS = ck ce ce kSGS ∆kSGS νSGS = ck ce (214) (216) (217) 2 kSGS SGS (218) Eq. phi The question The governing equations of the solvers of OpenFOAM are written in a special notation that makes it easy to compare the source codes with equations from a uid dynamics textbook. The main function of any C or C++ program is entered.H" #i n c l u d e " createMesh .1 ce k2 ck · ce = 0. when the solver is called. Here.H" /* t h e r e s t o f t h e s o l v e r */ Listing 331: The rst few line of the main function of pimpleFoam in createFields.g. the eld phi is created. U) | {z } div(uu) We now examine how 42.2. c h a r * argv [ ] ) { #i n c l u d e " setRootCase .H is included. ® ® 219 . ESI-OpenCFD or the OpenFOAM Foundation.C the velocity eld ® U is created. 138 the denition of the turbulent viscosity of the k- model νT = Cµ The product of default value of Cµ ck and (138) when using their default values gives of the k- model. ∇(uu) ⇔ fvm::div(phi. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. So.H" #i n c l u d e " c r e a t e F i e l d s . createPhi.2 phi is dened and how we can nd phi in the math.0985 which is approximately the Cµ = 0. There. the instructions of Listing 331 are the rst instructions that are executed.H contains the content of Listing 332. the terms of Eq. In line 6 of Listing 331 the le createFields.09.H is included. There. we repeat the comparison of how the convective term is written in the sources and how this term is expressed mathematically. Listing 331 shows the rst lines of the main function of the solver pimpleFoam. This le contains instructions that create the data structures of all elds that are necessary for the solver (e. see Listing 154.H" #i n c l u d e " i n i t C o n t i n u i t y E r r s . There. There. timeName ( ) . I O o b j e c t : : READ_IF_PRESENT. runTime . (cells) of the mesh. that is dened on the faces of the control volumes fvMesh.H ® ® This oering is not approved or endorsed by ESI Group. timeName ( ) << Foam : : n l << Foam : : e n d l . the producer of the OpenFOAM software and owner of the OpenFOAM trademark.H //− Return c e l l f a c e a r e a v e c t o r s c o n s t s u r f a c e V e c t o r F i e l d& S f ( ) c o n s t . I O o b j e c t : :AUTO_WRITE ). Line 13 tells us how This tells us. it is phi is a scalar. S f ( ) ). timeName ( ) . In Listing 335 we see. mesh .H" Listing 332: The creation of U and phi in the le createFields. we nd out. l i n e a r I n t e r p o l a t e (U) & mesh .1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 I n f o << " Reading f i e l d U\n" << e n d l . Foam : : I O o b j e c t : :MUST_READ ) ). Foam : : fvMesh mesh ( Foam : : I O o b j e c t ( Foam : : fvMesh : : d e f a u l t R e g i o n . mesh . mesh ). timeName ( ) . ® ® 220 . Listing 334: The declaration of the method 1 2 3 4 5 6 7 8 9 10 11 12 13 14 phi Sf() of the class fvMesh in the le fvMesh. I n f o << " Reading / c a l c u l a t i n g f a c e f l u x f i e l d p h i \n" << e n d l .2. Listing 335: The creation of the mesh in the le X ® createMesh.H 42. I O o b j e c t : :AUTO_WRITE ). Listing 333: The creation of 1 2 in the le createPhi. that the variable mesh of Listing 333 is is dened. that forget for the moment about the function of the type createPhi. runTime . #i n c l u d e " c r e a t e P h i .H. In Listing Sf(). ESI-OpenCFD or the OpenFOAM Foundation. s u r f a c e S c a l a r F i e l d phi ( IOobject ( " phi " .2 How phi is dened Listing 333 shows the content of the le surfaceScalarField. volVectorField U ( IOobject ( "U" . From this Listing we see the data type of phi. I O o b j e c t : : MUST_READ.H Foam : : I n f o << " C r e a t e mesh f o r time = " << runTime . runTime . that phi 334 we see the declaration of the function 1 2 3 4 5 6 7 8 9 10 11 12 13 14 phi is the inner product of the velocity we linearInterpolate and the face surface area vector. runTime . (43) over a control volume yields: Z V ∂u + ∇(uu) + ∇ · dev(−ν ef f ∇u + (∇u)T ) dV = ∂t Z −∇p + Q dV (219) V Now we will have a closer look on the second term of Eq. XZ (uu) · dSf = Sf f X (uu)f · Sf (223) f (uu)f = 1 Sf Z (uu) dSf (224) Sf (uu)f ≈ (uf uf ) X X (uu)f · Sf ≈ (uf uf ) · Sf f (225) (226) f Eq. Therefore. ® ® 221 .3 The math Now. there is need for some more math to do. let us examine the origin of phi from the mathematical point of view. a ⊗ b · c = (ab) · c X ® (228) ® ® This oering is not approved or endorsed by ESI Group. Eq. We are now nearly nished. Z I (uu) · dS ∇(uu) dV = V (220) ∂V Because our control volume is a polyhedron (in most cases a hexahedron or a tetrahedron). Using Gauss' theorem. this ingredients are not in the order we need. see Eq. the operations averaging and multiplication are not commutative. a velocity and an inner vector product. ∂u + ∇(uu) + ∇ · dev(−ν ef f ∇u + (∇u)T ) = −∇p + Q ∂t (43) This equation is written in diferential form and is valid everywhere in the uid. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. See Listing 333. being the surface normal vector of the face We denote with the subscript f (222) The norm of this vector is equal to the area of the the mean face-value of a quantity. That is the convective term we already saw at the beginning of this section. XZ (uu) · dSf (221) Sf f kSf k = Sf With face f. Sf f. we replace the integration over the volume of our control volume with the integration over the surface of the control volume. that the mean face-value of the product of the velocities is (approximately) equal to the product of the mean face-values of the velocity. (226) contains all ingredients we need for phi. we need the governing equations in the integral form. However. (225).42. It is assumed. We start with the governing equations of a solver for incompressible uids. In general. A general rule of tensor calculus states: a ⊗ b · c = a(b · c) In this document. Therefore. ESI-OpenCFD or the OpenFOAM Foundation. (226) contains the fundamental assumption or approximation of the nite volume method. In order to use the nite volume method. the surface integral reduces to a sum of intergrals over the faces I Sf (uu) · dS = ∂V of the polyhedron. The rhs of Eq. Integrating Eq. (219). we omit the symbol ⊗ (227) for the sake of brevity. A surface area vector. 43 is repeated below. ® ® 222 . t). The second term represents convective transport.1 IATE diameter model from [14].g. (236) is the local rate of change of the bubble number density distribution. Thus. We want to understand this equivalency. U) | {z } div(uu) The math tells use the following identities. Z I (uu) · dS (231) (uu)f · Sf (232) ∇(uu) dV = IV ∂V (uu) · dS = X ∂V f X X (uu)f · Sf ≈ (uf uf ) · Sf f X (233) f (uf uf ) · Sf = X f uf (uf · Sf ) (234) f X uf (uf · Sf ) = X f uf φf (235) f We have shown. we derive a transport equation for the area concentration ai . (226). The third term represents the rate of change due to change of bubble volume. t) simply as f = f (V. phase change On the right hand side of the equation are source terms due to bubble interactions Sj and Sph . The area concentration is a moment of the bubble number density distribution. (uf uf ) · Sf = uf (uf · Sf ) | {z } (229) uf (uf · Sf ) = uf φf (230) = φf 42. 43 Derivation of the IATE diameter model In this section we cover the derivation of OpenFOAMs 43. ∂f ∂ + ∇ · (f u) + ∂t ∂V dV f dt = X Sj + Sph (236) j The equation for the bubble number density distribution is much too detailled for most ow studies [20]. X ® ® ® This oering is not approved or endorsed by ESI Group. (228) looks like the rhs of Eq.Eq. Number density transport equation We start with the transport equation for the bubble number density distribution For sake of readability in most cases we refer to The rst term of Eqn. e. ∇(uu) ⇔ fvm::div(phi. that the integral formulation of the convective term can be reformulated to incorporate and u instead of φ uu. x. we can summarize all thoughts so far. f (V. x. from [14]. ESI-OpenCFD or the OpenFOAM Foundation. Besides the area concentration we can dene further quantities based on the moments of the number density distribution. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. after having dug deep into the sources and after having done some math.4 Summary Now. f. x. (242). X dV f = Ai Sj + Sph dt j (241) Then. b Z f (x)xi dx mi = (237) a We now dene some moments of the bubble number density distribution. (240). we simply apply Leibnitz Ai rule. we can put the u in front of the integral over all bubble sizes. First we multiply Eqn. ESI-OpenCFD or the OpenFOAM Foundation. (236). For the rst term. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. we gain the local derivative of the interfacial area concentration Vmax Z Ai Vmin Z ai . (241) over all bubble sizes Z Vmax Vmin Z Vmax X dV ∂ ∂f + Ai ∇ · (f u) + Ai f dV = Ai Ai Sj + Sph dV ∂t ∂V dt Vmin j (242) Now we will take a closer look on the single terms of Eqn. x. With Eqn. t)V dV (239) f (V. that is constant in space and time. (240) to derive a transport equation for the area concentration from Eqn. ® ® 223 . ∂f ∂ dV = ∂t ∂t Vmax Ai Vmin Z Vmax Ai f dV (243) Vmin ∂f ∂ dV = ai ∂t ∂t (244) The convective term of Eqn. (237) lists the general denition of the i-th moment mi of the probability density function f (x). we integrate Eqn. Thus. Here it is important to note. Z Vmax Ai ∇ · (f u) dV = Vmin Z Vmax Z Vmax Vmin Ai ∇ · (f u) dV = ∇ · Vmin ∇ · (Ai f u) dV ! Z (245) Vmax u Ai f dV (246) Vmin Z Vmax Ai ∇ · (f u) dV = ∇ · (u ai ) (247) Vmin X ® ® ® This oering is not approved or endorsed by ESI Group.1 Deriving the governing equations We will use Eqn.2 Interfacial area transport equation 43. t) = Total number of bubbles per unit volume f (V. If the velocity is independent of the bubble size.2. t) = Volume fraction of bubbles Vmin Z Vmax ai (x. (242) can be treated in a similar fashion. Z Vmax n(x. x. t)Ai (V )dV (240) Vmin Z Vmax α(x. t)dV (238) f (V. t) = Area concentration of bubbles Vmin 43.Eqn. (236) by the average interfacial area Ai (V ) ∂f ∂ Ai + Ai ∇ · (f u) + Ai ∂t ∂V of bubbles with the volume V. we gain the convective term for the interfacial area concentration. In this approach each bubble interaction results in a change of interfacial area Z Vmax Ai Vmin X ∆Ai = 31 Ai .1 we show the proof for (252). ® ® 224 . (242) needs more special treatment. a bubble breaks up into two equalsized daughter bubbles [21]. The latter approach assumes monosized bubble.If the velocity is not independent of the bubble size we can follow a similar strategy to derive a convective term which is formulated in terms of the interfacial area concentration. (242) One can solve the integral equation for these source terms (253) or solve algebraic equations using mean parameters (254).5. Z Vmax Vmin Z Vmax X dV ∂f ∂ Ai + Ai ∇ · (f u) + Ai f dV = Ai Sj + Sph dV ∂t ∂V dt Vmin j There are two approaches to model the source terms due to bubble interaction [21]. i. Sj dV = Φj (253) j Φj = Sj ∆Ai with the interfacial area (254) Ai Ai = and bubble number density n.e. Vmax Z Ai ∇ · (f u) dV = Vmin Z Vmax Z Vmin Vmax Ai ∇ · (f u) dV = ∇ · ai ∇· Ai f u dV ai ! R Vmax Ai f udV Vmin ai Vmin Z Vmax (248) (249) ai Ai ∇ · (f u) dV = ∇ · (ai ui ) (250) Vmin With the average local bubble velocity weighted by the bubble number ui [8] R Vmax Ai f udV ui = RVmin Vmax Ai f dV Vmin (251) The third term of Eqn. Z Vmax Ai Vmin ∂ ∂V f dV dt dV = − 2 α˙ ai 3α (252) The RHS of Eqn. 242 contains the terms due to bubble-bubble interaction and due to phase change. 2 Sj (258) ® ® This oering is not approved or endorsed by ESI Group. This term relates to the gas expansion. but within the framework of this manual we will not consider phase change. In Section 43. Ψ = ai n (255) 1 36π for spherical bubbles a3 n = Ψ i2 α 2 11 α Φj = Sj 3 Ψ ai (256) (257) The phase change term can be modelled directly. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Thus we gained a transport equation for the interfacial area concentration X1 1 ∂ai 2 α˙ + ∇ · (u ai ) = ai + ∂t 3α 3Ψ j X ® α ai ai . ESI-OpenCFD or the OpenFOAM Foundation. Solves for the interfacial curvature per unit volume of the phase rather than interfacial area per unit volume to avoid stability issues relating to the consistency requirements between the phase fraction and interfacial area per unit volume. as the interfacial curvature seems a bit counter-intuitive. Here we will make no further assumptions.3. as the curvature of a sphere is the inverse of its radius. 43. Class description in IATE. 6/dMax_) .H By looking into the sources. 1 2 3 4 5 //− Return t h e i n t e r f a c i a l a r e a tmp<v o l S c a l a r F i e l d > a ( ) c o n s t { r e t u r n phase_ * kappai_ . dsm = 6α ai Listing 336 and 337 show the relevant source code of the (262) IATE diameter model. (259) and (260). ESI-OpenCFD or the OpenFOAM Foundation. We start from the transport equation for the interfacial area concentration ai and OpenFOAMs denition of X1 1 ∂ai 2 α˙ + ∇ · (u ai ) = ai + ∂t 3α 3Ψ j α ai ai .1 Basic denitions The IATE diameter model solves a transport equation for the interfacial curvature kappai_. } Listing 336: Denition of the method 1 2 3 4 a() of the IATE diameter model classin the le IATE. dMin_) . the producer of the OpenFOAM software and owner of the OpenFOAM trademark. we nd the following relations ai = ακ 6 dsm = κ Thus. ® ® 225 . This source code is the basis for Eqns. as we are simply rearranging the equations.43. Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : diameterModels : : IATE : : dsm ( ) c o n s t { r e t u r n max( 6 /max( kappai_ . 2 Sj (258) ai = ακ X ® (259) ® ® This oering is not approved or endorsed by ESI Group. the Sauter mean diameter dsm (259) (260) equals dsm = 6α ai (261) Which corresponds with the denition given in literature [13.H. } Listing 337: Denition of the method The denition of kappai_ dsm() of the IATE diameter model class in the le IATE.3. 15].3 Interfacial curvature transport equation 43.2 Derivation of the governing equations We will now derive the governing equations for the interfacial curvature area concentration ai κ from the equations for the interfacial which we derived from the transport equations for the bubble size distribution.C. kappai_ ) == − fvm : : SuSp (R.3. ESI-OpenCFD or the OpenFOAM Foundation. (269). 43. // C o n s t r u c t t h e i n t e r f a c i a l c u r v a t u r e e q u a t i o n f v S c a l a r M a t r i x kappaiEqn ( fvm : : ddt ( kappai_ ) + fvm : : d i v ( phase_ . // I n i t i a l i s e t h e accumulated s o u r c e term t o t h e d i l a t a t i o n e f f e c t volScalarField R ( ( (1. (268) is implemented. In Line 4 we see the terms marked with of Eqn. p h i ( ) . ® ® 226 . (268) is due to the change of bubble volume (dilatation eect). kappai_ ) //+ Rph ( ) // Omit t h e n u c l e a t i o n / c o n d e n s a t i o n term ). (268) is chosen to match the equations given in [14]. we apply partial derivation of all terms containing (263) κ X 1 1 1 2 ∂κ ∂α 2 +κ + κ∇ · (u α) + αu · ∇κ = ακ ˙ + Sj ∂t ∂t 3 3Ψ κ j X 1 1 1 2 ∂κ ∂α 2 κ + ∇ · (u α) +α + u · ∇κ = ακ ˙ + Sj ∂t ∂t 3 3Ψ κ j {z } | α (264) (265) α ˙ X 1 1 1 2 ∂κ 1 α + u · ∇κ = − ακ ˙ + Sj ∂t 3 3Ψ κ j 2 ∂κ 1 κ X1 1 1 1 Sj + u · ∇κ = − α˙ + ∂t 3 α 3Ψα κ j With 1 κ = (266) (267) α ai ∂κ 1 α˙ 1 · u} = − + ∇ (κu) − κ∇ κ+ | {z |∂t {z } | 3{zα } 3Ψ II I α ai 2 X j Sj α (268) III The form of Eqn. In Line 5 term II I of Eqn. we have derived a transport equation for κ.0/3. However. 1 2 3 4 5 6 7 8 9 Listing 338: Construction of the transport equation in the le IATE. p h i ( ) ) . The second term of the RHS has exactly the same form as the equivalent terms in [14]. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. In Listing 338 we see the main code for the transport equation. The method fvm::SuSp() arguments translate to R * kappai_. kappai_ ) − fvm : : Sp ( f v c : : d i v ( phase_ . we still need to check the equations that are implemented in OpenFOAM. The code in Listing 339 translates to Eqn.3 Implemented equations Thus. kappai_). The right hand side of the equation in Listing 338 combines all term of the RHS of Eqn. The The rst term on the RHS of Eqn. (268) into the term fvm::SuSp(R.0) /max ( 1 2 3 4 5 6 7 X ® ® ® This oering is not approved or endorsed by ESI Group. Therefore. implements a source term for a matrix equation.C.Inserting (259) into (258) yields X 1 1 α 2 ∂ακ 2 α˙ Sj + ∇ · (u ακ) = ακ + ∂t 3α 3 Ψ ακ j Next. (268). we take a look at the source code. Thus we recognize the rst term of the RHS of Eq. bubble Reynolds number Re() or the Weber number We(). 43. 43.f v c : : a v e r a g e ( phase_ + phase_ . } 1 2 3 4 5 Listing 340: The second term of the RMS of Eqn. note the minus sign. For the interaction models the minus of Listing 340 cancels the minus of Listing 338. Coalescence through random collision driven by turbulent eddies (RC . 14] the source term due to turbulent impact is stated as: RT I X a3 n = Ψ i2 √α ut = 2k r nut W ecr W ecr = CT I exp − 1− Db We We ® (274) (275) where W ecr > W e ® (276) ® This oering is not approved or endorsed by ESI Group. Breakage due to impact of turbulent eddies (TI . e. Coalescence due to acceleration of the following bubble in the wake of preceding bubble (WE . ESI-OpenCFD or the OpenFOAM Foundation.TI In [15.turbulent impact ) 2. (268). ® ® 227 . + ∇ · (αu) α multiplies R with (269) kappai_. R( ) .C. Listing 340 shows the loop over all sources. R(). oldTime ( ) ) .g. residualAlpha_ 8 9 10 11 12 13 ). the producer of the OpenFOAM software and owner of the OpenFOAM trademark. There are several interaction mechanisms implemented.random collision ) 3.C. (268) OpenFOAM (270) (271) (272) (273) The other source terms related to the models for bubble-bubble interaction are added to R. j ) { R −= sourc es_ [ j ] . ) ) * ( f v c : : ddt ( phase_ ) + f v c : : d i v ( phase_ . (268) of the transport equation in the le R= The method call fvm::SuSp(R. alphaPhi ( ) ) ) Listing 339: The rst term of the RHS of Eqn. (268) of the transport equation in the le IATE.1 Turbulent impact . Besides R(). 1.4 Interaction models OpenFOAM provides a base class for all models related to bubble-bubble interaction. 1 α˙ κ 3α III = −Rκ 1 α˙ R= 3α 1 α˙ III = − κ 3α III = − Eqn. // Accumulate t h e run −time s e l e c t a b l e s o u r c e s f o r A l l ( sources_ . This means that every the base class provides a number of helper methods that are used in the derived classes.4. kappai_) 1 3 ∂α ∂t IATE.wake entrainment ) The base class is named IATEsource and it denes a pure virtual function named derived class has to provide its implementation of R(). 4. which is also provided by see Listing 341. d ( ) / f l u i d ( ) . 14] the source term due to random collision is stated as: √ ut = " RRC = CRC The model constants CRC . 14] the source term due to wake entrainment is stated as: 1/3 RW E = CW E CD n2 Db2 ur The model constant CW E (280) needs to be provided by the user.75 (1 − α) (281) ® ® This oering is not approved or endorsed by ESI Group. Compare Eqn.2 Random collision . ur = X √ 2 σg∆ρ ρ2L 1/4 ® 1. rho ( ) * s q r ( Ur ( ) ) * phase ( ) . See Section 43. sigma ( ) . 43. ® ® 228 . 43. (281) and Listing 342. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.4. C n2 ut Db2 1/3 1/3 αmax (αmax − α and αmax 1/3 2k #" (278) 1/3 1 − exp −C ) αmax α 1/3 !# (279) 1/3 αmax − α1/3 need to be provided by the user.4. 19]. } Listing 341: The denition of the Weber number We in IATEsource.4.RC In [15. ESI-OpenCFD or the OpenFOAM Foundation.4 Implementation details of the IATEsource class Weber number IATEsource. This denition makes use the Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : diameterModels : : IATEsource : : We( ) const { r e t u r n o t h e r P h a s e ( ) .C Relative velocity The relative velocity between the bubbles and the surrounding uid is given by [12. 43.WE In [15. The Weber number is implemented in the class method 1 2 3 4 5 Ur().4 for implementation details. IATEsource. The critical Weber number W ecr CT I and the model constant must be provided by the user in the appropriate dictionary.3 Wake entrainment .The Weber number We can be seen as the ratio of inertia forces and surface tension forces and is dened as: We = ρu2 d σ (277) with ρ density u characteristic velocity d characteristic length scale σ surface tension The Weber number is provided by the class IATEsource as the base class for all interaction models. } } r e t u r n tR .U( ) .0/3. c o n s t v o l S c a l a r F i e l d& d ( i a t e _ . rho ( ) ) / s q r ( o t h e r P h a s e ( ) . timeName ( ) . If the IATEsource. 0 ) ) ). s c a l a r ( 0 ) ) . rho ( ) − phase ( ) . then Line 11 evaluates to a negative number. mesh ( ) . ® ® 229 . v o l S c a l a r F i e l d R = tR ( ) . i a t e _ . i a t e _ . f o r A l l (R. Comparing the formulations Here we take a closer look on the implementation of the source terms. d ( ) ( ) ) . } return sqrt (2. lookupObject <u n i f o r m D i m e n s i o n e d V e c t o r F i e l d >("g" ) . sigma ( ) *mag( g ) * ( o t h e r P h a s e ( ) . phase ( ) . s c a l a r C t i = Cti_ . d i m e n s i o n e d S c a l a r ( "R" .0) * C t i /d [ c e l l i ] *Ut [ c e l l i ] * s q r t ( 1 − WeCr/We[ c e l l i ] ) * exp(−WeCr/We[ c e l l i ] ) . ESI-OpenCFD or the OpenFOAM Foundation. v a l u e ( ) . v o l S c a l a r F i e l d Ut ( t h i s −>Ut ( ) ) .C IATE model is applied to phase refers to the the denser phase.0) *pow025 ( f l u i d ( ) . mesh ( ) ). time ( ) . 7 5 ) .U( ) . If liquid phase. X ® ® ® This oering is not approved or endorsed by ESI Group. Thus. gas-liquid systems. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. d i m l e s s /dimTime . then Line 11 of Listing 342 leads to a oating-point exception (FPE). v a l u e ( ) . Listing 343 shows the method IATEsource 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 R() of the class.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : diameterModels : : IATEsource : : Ur ( ) c o n s t { c o n s t u n i f o r m D i m e n s i o n e d V e c t o r F i e l d& g = phase ( ) . phase ( ) . i. OpenFOAM will issue an error message due to an oating-point exception. i a t e _ . 1 . phase ( ) . Raising a negative number to a non-integer power is not possible within the domain of the real numbers. Listing 342: The denition of the relative velocity between bubbles and surrounding liquid in The IATE implicitely applies only to bubbly systems. s c a l a r WeCr = WeCr_ .U( ) . Foam : : tmp<Foam : : v o l S c a l a r F i e l d > Foam : : diameterModels : : IATEsources : : turbulentBreakUp : : R( ) c o n s t { tmp<v o l S c a l a r F i e l d > tR ( new v o l S c a l a r F i e l d ( IOobject ( "R" . rho ( ) ) ) *pow (max( 1 − phase ( ) . v o l S c a l a r F i e l d We( t h i s −>We( ) ) . c e l l i ) { i f (We[ c e l l i ] > WeCr) { R[ c e l l i ] = (1.e. db ( ) . we can form the following equation. (276) and (282) reveals some dierences in formulation. α ai 2 1 n=κ α (286) 1 a3i Ψ =κ α α2 (287) see Eq. 1 3Ψ α ai 2 X j X Sj = Rj κ α j (284) We now demand. only rearrangement and variable substitution was performed.C Listing 343 translates to the following mathematical expression: RT I 1 CT I = ut 3 dsm r 1− W ecr W ecr exp − We We W e > W ecr where (282) Comparing Eqns. ® ® 230 . ai We begin with repeating the equations for and κ. note the dierent symbols for the bubble diameter (Db = dsm ) 1 Ψ We now insert the denition of n. we cancel all common symbols and expressions.40 } Listing 343: The denition of the method R() in turbulentBreakUp. As these terms must be equal. The interaction source term Sj can be found in this form in [14]. that Eq. ESI-OpenCFD or the OpenFOAM Foundation. (276) is a source term for the transport equation for the interfacial area concentration source term for the transport equation for the interfacial curvature ai and Eq. Otherwise. (274) 1 Ψ α ai 2 ai =κ α X ® (288) ® ® This oering is not approved or endorsed by ESI Group. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. and we focus on the term for turbulent break-up (TI) 1 3Ψ α ai 2 1 CT I α | nut Db W ecr exp − We {z Sj r r W ecr 1 CT I W ecr W ecr 1− = ut 1 − exp − κ We 3 dsm We We } | {z } (285) Rj Next. X 1 1 α 2 2 α˙ ∂ai + ∇ · (u ai ) = ai + Sj ∂t 3α 3 Ψ ai j 2 X 1 α˙ 1 ∂κ α Sj + ∇ (κu) − κ∇ · u = − κ+ ∂t 3α 3Ψ ai α j {z } | (258) (268) IV The interaction model source terms in the curvature equation of OpenFOAM takes the following form: X 1 α˙ ∂κ + ∇ (κu) − κ∇ · u = − κ+ Rj κ ∂t 3α j | {z } (283) IV We now compare the terms marked with IV of Eqns. This is due to the fact. (282) is a κ. that the summands need to be equal. In the derivation of the curvature equation from the area concentration equation we divided by the volume fraction. (268) and (283). For this term we now have a look on the RHS of the equations for ai and κ and compare the implementation of OpenFOAM with the equations stated in literature. (259) ai = ακ (259) Thus.We now end up with an equation that is fullled. (295) vanishes Z b g(x) a ∂ ∂x Z b dx ∂g(x) dx f (x) dx = − f (x) dx dt ∂x dt a (297) We now take a closer look on the relation between the average interfacial area of a bubble of a bubble Ai and the volume V. when we look at the denition of κ. x=V (289) f (x) = f (V. the rst term of the RHS of Eqn. we have demonstrated on the example of the source term for turbulent break-up of bubbles.1 The proof for Eqn. we apply partial integration Z a As f (x) b ∂ g(x) ∂x dx f (x) dt b Z b ∂g(x) dx dx dx = f (x) g(x) − f (x) dx dt ∂x dt a a (295) is a probability density distribution it has the following properties f (a) = f (b) = 0 (296) Thus.5. that the implementation of OpenFOAM follows exactly the model published in [14]. t) (290) g(x) = Ai (V ) (291) a = Vmin (292) b = Vmax (293) Thus. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. (252) We use the following symbols. (252) becomes Z Vmax Vmin ∂ Ai ∂V dV f dt Z dV = a b ∂ g(x) ∂x dx f (x) dt dx (294) Now. Ai = d2 π d3 π V = 6 r (298) (299) 3 6V ⇒d= π 2/3 6V Ai = π π (300) (301) Returning to our simplied notation for this proof g(x) = X ® 6x π 2/3 π (302) ® ® This oering is not approved or endorsed by ESI Group. x. the LHS of Eqn. see Eqn. ® ® 231 .5 Appendix 43. 43. ESI-OpenCFD or the OpenFOAM Foundation. For any control volume VCV we can state. we can relate V to the void fraction or gas phase volume fraction α. Since x is the volume of the bubbles V . see [15] for a derivation considering evaporation. (289)-(289) Z b Z dx 2 α˙ Vmax dx = − f Ai dV dt 3 α Vmin Z b ∂ dx 2 α˙ g(x) f (x) dx = − ai ∂x dt 3 α a g(x) a ∂ ∂x f (x) (315) (316) And by using (240) on (315) we have proofed (252). Eqns. (308). the producer of the OpenFOAM software and owner of the OpenFOAM trademark. (297) we also need the derivative of g(x) 2/3 6 −1/3 (x) π π 2/3 2/3 2 6 ∂g(x) x = π ∂x 3 π x 2/3 ∂g(x) 2 1 6x = π ∂x 3x π 2 g(x) ∂g(x) = ∂x 3 x ∂g(x) 2 = ∂x 3 (303) (304) (305) (306) We now insert Eqn. ® ® 232 . 19]. (297) into Eqn. we gain b Z a ∂ g(x) ∂x Z dx 2 α˙ b f (x) dx = − f (x)g(x)dx dt 3α a (314) or by using the other notation. V = αVCV V˙ = αV ˙ CV (309) (310) αV ˙ CV V˙ α˙ = = V αVCV α x˙ α˙ = x α (311) (312) We further assume that the rate of change of volume is independent of the volume itself [15. V˙ 6= f (V ) V (313) By using relation (308) and (312) on Eqn. X ® ® ® This oering is not approved or endorsed by ESI Group. ESI-OpenCFD or the OpenFOAM Foundation. that the volume of the bubbles V is equal to the volume fraction times the control volume. (297). Z b Z b dx 2 g(x) dx f (x) dx = − f (x) dx dt dt a 3 x Z b Z ∂ dx 2 b x˙ g(x) f (x) dx = − f (x)g(x)dx ∂x dt 3 a x a g(x) a ∂ ∂x (307) (308) x˙ x .For Eqn. Here we neglect mass transfer by Next. we take a closer look on the term evaporation. If the wrong parameter is used the help message is displayed anyway or an error message naming the correct parameter to display the usage information. simply put the name of the command or program behind the command man. x/ a p p l i c a t i o n s / s o l v e r s / i n c o m p r e s s i b l e / icoFoam / icoFoam .2 In a certain directory To nd a le in a certain directory and its sub-directories nd can be used.C Listing 346: Looking for icoFoam. Listing 347 shows the command to search the le LESProperties in the OpenFOAM tutorials. 1 . 44. 1 . 90 .2. ® ® 233 . ESI-OpenCFD or the OpenFOAM Foundation.C 44.1. user@ host : ~ $ Listing 344: Displaying the help message Apparently all of the tools and solvers of OpenFOAM 89 display such help messages. 44.2.2 man pages Many Linux commands have an additional.C /home/ u s e r /OpenFOAM/OpenFOAM− 2 . user@ host : ~ $ l s − h e l p l s : i n v a l i d o p t i o n −− e Try ` l s −−help ' f o r more i n f o r m a t i o n . 90 As an example: the man pages of gcc are longer than 10000 lines. To display this message the command has to be invoked with one of those parameters: -h. x/ a p p l i c a t i o n s / s o l v e r s / i n c o m p r e s s i b l e / icoFoam / icoFoam . library function of the C standard library and much more.Part XI Appendix 44 Useful Linux commands 44. more detailed documentation (man is short for manual). see Listing 344. system call. 0 . New Linux and Open- FOAM users are strongly encouraged to study the help messages to deepen their understanding and insight. Listing 345 shows how to display the man pages of the Linux command cp.1 Display help Virtually all Linux commands display a summary of the programs purpose and usage.2 Finding les 44. This is written in the man pages To display the man pages of a certain command. On some systems the man pages are only partially or not at all installed by default.1 Searching les system wide Searching for a le on the whole le system can be done by locate. C /home/ u s e r /OpenFOAM/OpenFOAM− 2 . --help. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. Listing 346 shows the result of the search for the source le of icoFoam. XI ® ® ® This oering is not approved or endorsed by ESI Group. x/ run / icoTurb$ l o c a t e icoFoam .1. 89 No exception is known to the author.1 Getting help 44. user@ host : ~ /OpenFOAM/ u s e r − 2 . -help. man cp Listing 345: Displaying the man pages The man pages cover general commands of Linux. To look for maximum values of α greater than unity manually is not an option. We need an one-liner that does that automatically for us. it is easy to scan these les for certain keywords. Otherwise. As an OpenFOAM case consists of a number of text les. The second line comprises a maximum value of above a water surface. the answer to the question above is: nd all controlDicts and scan them for the word probe. l o g −c g r e p 'Max( a l p h a ) = 1 . The second command in Listing 350 will only detect lines in which α is larger than unity. all of the les returned by the search have to be scanned for the denition of probes. e. D i s p e r s e d phase volume f r a c t i o n = 0 . 3 0 2 6 1 e −52 Max( a l p h a ) = 1 Max( a l p h a ) = 1 . ESI-OpenCFD or the OpenFOAM Foundation. but where? To answer this question one has to nd all les in which probes can be dened the controlDict in this case. Instead of perfoming this task manually. For α to be physically meaningful. In some cases. Listing 348 shows how all les named controlDict in the tutorials are located and scanned for the word probes. reasonable. of the two lines of Listings 349. If no le was specied. The solver twoPhaseEulerFoam displays after every time step the minimum and maximum value of the volume fraction α. 44. The rst line has a maximum value of one. So. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. its value has to be of the range 0 ≤ α ≤ 1. f i n d $FOAM_TUTORIALS −name c o n t r o l D i c t | x a r g s g r e p ' probes ' − s l Listing 348: Find and scan les nd looks for respectively nds all les with the name passed with the option -name in the specied folder and its folders. that there were values of than one. α greater In this example a simulation crashed and the main suspicion is. when regions evolve where the continuous phase vanishes. ' foamRun . Listing 349 shows two lines of solver output. xargs executes the passed command line. Due to the fact that simulations often do not crash immediately the log le containing the solver output is hundreds of thousands of lines long. displaying all lines with a match could be unwise. The option -c makes grep display only the number of number of matches. grep would display all lines in which a match was found.f i n d $FOAM_TUTORIALS −name L E S P r o p e r t i e s Listing 347: Search LESProperties in the tutorials 44. 5 2 8 2 6 e −42 Min ( a l p h a ) = 2 . That's where grep comes in. So. this value is perfectly α greater than unity.g. The rst command in Listing 350 would detect a match for both lines of Listings 349. This value is unphysical. The output of nd is passed to grep as input by a pipe. 1 9 4 3 5 1 D i s p e r s e d phase volume f r a c t i o n = 0 . g r e p 'Max( a l p h a ) = 1 ' foamRun . grep expects as rst argument the pattern to look for. l o g −c Listing 350: Scan the log using grep XI ® ® ® This oering is not approved or endorsed by ESI Group. The second argument is optional. only the second one would result in a match.4 Scan a log le grep can scan a text le for a certain pattern. ® ® 234 . In this example we want to scan the solver output for a certain pattern. grep would read from standard input. Additionally.3 Find les and scan them How do I dene probes? I have seen this already. a single one-liner in the Terminal does the magic. because a phase can not occupy a certain amount of space a cell to more than 100%. grep then scans all les for the word probes. it species the le from which to read. 'Max(alpha) = 1' is not useful to nd out whether α So this pattern exceeded unity or not. 0 6 0 5 6 2 Min ( a l p h a ) = 7 . In a situation in which the number of hits could reach hundreds or thousands. 0 0 0 0 3 Listing 349: Example: solver output regarding volume fraction Listing 350 shows how the user can scan the log le for the appropiate pattern. log # f i n e 02 echo ' f i n e 0 2 ' cd ' . This would be unacceptable when simulating overnights. So. l o g echo ' r e c o n s t r u c t i n g ' reconstructPar > foamReconstruct . #! / b i n / bash # f i n e 01 echo ' f i n e 0 1 ' cd ' . To be able to do this.5 Running in scripts 44. Then the script changes to the second case (cd The next commands perform all '. This example assumes that a script with name runCalculations is to be terminated. The rst line comes from the running script and the second line stems from the running parallel calculation. ESI-OpenCFD or the OpenFOAM Foundation. Listing 351 shows how to look for the PID. The rst group of commands changes into a subdirectory of the current directory (cd '.44. user@ host : ~ $ ps − e l | g r e p run 0 S 8553 14913 14517 0 80 0 − 0 S 8553 14917 14913 0 80 0 − user@ host : ~ $ 2687 w a i t 2687 w a i t p t s /11 p t s /11 00:00:00 runCalculations 0 0 : 0 0 : 0 0 mpirun Listing 352: Search for PIDs using ps and grep Terminate the script If the script was terminated using kill. the cluster can calculate a great number of cases without the need for the user to start each job seperately. This is a very basic script. Therefore. Listing 353 shows how the script is terminated and mpirun continues to be running. In Section 8.2 explains this bit in detail. tasks of a parallel simulation.1 Starting a batch of jobs To use the computing power of a computing cluster it is a good idea to let the cluster do the work in batches. l o g mpirun −np 2 twoPhaseEulerFoam − p a r a l l e l > foamRun . The script in Listing 351 starts two parallel simulations inkluding domain decomposition and reconstruction. log Listing 351: Mit einem Shell-Skript mehrere Rechnungen nacheinander starten 44. It contains no checks if a simulation has terminated prematurely or any other useful features.2 Terminating a running script There may be need to stop a script from any further execution without terminating the currently running simulation. XI ® ® ® This oering is not approved or endorsed by ESI Group.3. The script assumes to start from a directory which contains all two cases.5./fullColumn_fineV01'). the producer of the OpenFOAM software and owner of the OpenFOAM trademark./fullColumn_fineV02'). The command in Listing 351 outputs two lines. This is because all running processes matching the pattern run were searched for. First the PID of runCalculations has to be known. then the simulation would continue unaected. / fullColumn_fineV02 ' echo ' decomposing ' decomposePar > foamDecompose .. l o g echo ' r e c o n s t r u c t i n g ' reconstructPar > foamReconstruct . this section explains how to use a script to run a number of simulations sequentially. ® ® 235 . / fullColumn_fineV01 ' echo ' decomposing ' decomposePar > foamDecompose .5. l o g mpirun −np 2 twoPhaseEulerFoam − p a r a l l e l > foamRun . . also the running instance of mpirun was found. 1 Meld Meld is a graphical front-end to di. //meldmerge.6 diff di is a command line tool that analyses two les and prints a summary of the dierences of those les. 44. Terminating only the running simulation only. So. Further information on di can be found in the man-pages or the help-message. will cause the script to execute the next command.2.org/. rst the script and then the simulation need to be terminated. 44. XI ® ® ® This oering is not approved or endorsed by ESI Group.6. gation.7 Miscellaneous This section contains references to useful scripts or commands explained elsewhere in this document. This allows for a side-by-side comparison of both les under investi- Parts of the le that dier are highlighted by colors. Terminate a backround process See Section 8. ESI-OpenCFD or the OpenFOAM Foundation. For more information about Meld see http: Figure 49: A screenshot of Meld 44. ® ® 236 .user@ host : ~ $ ps −e | g r e p run 14913 p t s /11 00:00:00 runCalculations 14917 p t s /11 0 0 : 0 0 : 0 0 mpirun user@ host : ~ $ k i l l −KILL 14913 user@ host : ~ $ ps −e | g r e p run 14917 p t s /11 0 0 : 0 0 : 0 0 mpirun Listing 353: Mit kill ein Skript beenden Terminate the script and the simulation To terminate both the script and the simulation in this example the running simulation has to be terminated also. the producer of the OpenFOAM software and owner of the OpenFOAM trademark.3. In this case the same algorithm achieves an even greater reduction of disk space usage. slow algorithms that result in good compression rates should be prefered. The name tar comes from t ape ar chive. the longer compression takes.bz2 reduction 36. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. the user can afterwards copy the whole case directory to the workstation without transmitting the solution data twice.92.85 GB .3 % Table 8: Comparison of disk space reduction XI ® ® ® This oering is not approved or endorsed by ESI Group.7 GB 21 cases uncompressed compressed: *.2 for how to deal with processor * directories. After the post-processing is done all les could be compressed to save disk space. If space consuming cases are to archived. t for the usage of sequential data storage devices like magnetic tapes. it makes sense so reconstruct the domain on the cluster. Redirect output Redirecting the output of a program is explained in Section 8. The distinction between archiving and compressing is probably for historical as well as practical reasons.5. used disk space 50 GB 13. This step alone is only a reorganisation of the data. ESI-OpenCFD or the OpenFOAM Foundation. 45 Archive data Parametric studies generate a great deal of data.7 MB 16 log les uncompressed compressed: *.tar. On Linux systems the tar archiving utility may be the agent of choice. This example shows that the achieved compression rate strongly depends on the input data. Table 7 lists the achieved compression of a parametric studies with 21 cases totalling in 50 GB of data. ® ® 237 . After reconstructing the domain the processor * directories still contain all the time step data. which is pretty descriptive in terms of the origins of this archiving program. There is one rule of thumb stating: The more data is to be compressed. Compressing the data resulted in a 70+ % reduction of used disk space. A tar archive is a single le which contains all archived les and folders.1. See Section 8. If the processor * folders are deleted on the cluster.0 GB 154. The data was written in ascii format. bzip2 or xz. In a second step the tar archive needs to be compressed. Linux systems usually provide programs like gzip.6 % Table 7: Comparison of disk space reduction Archive log les In this example log les are archived. The compression programs usually dier in the utilised compression algorithms.tar.1.Delete the processor* directories If one or several simulations have been conducted on a computing cluster.bz2 reduction 1. For this task there are many possible choices.72. Otherwise the workstation of the user would be blocked for the time needed to complete reconstruction.3 GB . There is also one paradigm of the UNIX philosophy (Make each program do one thing well ) which supports the segregation in archiving and compression. used disk space 2. Argonne National Laboratory. References [1] FLUENT Theory Guide. Fröhlich. [10] J. Thermo-Fluid Dynamics of Two-Phase Flow. ® ® 238 . Delhaye. [4] The International System of Units (SI). Niceno. 2008.-M. [2] Intel 64 and IA-32 Architectures Optimization Reference Manual. One-dimensional drift-ux-model and constitutive equations for relative motion between pphase in various two-phase ow regimes. [3] The International System of Units. Dhotre. Chemical Engineering Science. Enwald. D. 2008. 59:759770. Large Eddy Simulationen turbulenter Strömungen. Almstedt H. 2011. and H. Rusche. [13] M. R. One. Peirano & A. I. ESI-OpenCFD or the OpenFOAM Foundation. XI ® ® ® This oering is not approved or endorsed by ESI Group.equation sub-grid scale (sgs) modelling for euler-euler large eddy simulation (eeles) of dispersed bubbly ow. 2006. Technical report. Behzadi. Mac OS X. Technical report.Mechanics. e. the conceptual issues. Springer. McGraw-Hill International Editions. Ishii. 63:39233931. ancestor of many modern operating systems. Hibiki. J. 22:2166. [12] M. Int.Nomenclature BC boundary condition OS operating system CAD computer aided design PDE Partial dierential equation CFD Computational uid dynamics Perl An interpreted programming language CG Conjugate gradient PID process identier DPE Dispersed phase element EDF Électricité de France FPE Floating-point exception PISO Pressure Implicit with Split Operator GAMG Geometric algebraic multi-grid RHS Right hand side gcc GNU compiler collection SAT Standard ACIS Text GNU GNU is not Unix SI Le Système Internationale d'Unités GUI graphical user interface SIMPLE Semi-Implicit PIMPLE An algorithm based on PISO and SIMPLE algorithm Method for Pressure- Linked Equations IATE Interfacial area transport equation IGES Initial Graphics Exchange Specication MPI message passing interface OOP object oriented programming STL UNIX Surface Tesselation Language an operating system. Deen B. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. [11] E. Anderson. Issa. Computational Fluid Dynamics. G. Teubner. Some issues related to the modeling of interfacial areas in gas-liquid ows I. Technical University of Denmark. 1977. 329(5):397410. all kinds of Linux.g. Comptes Rendus de l'Académie des Sciences . 2nd edition. 2006. Modelling of dispersed bubble and droplet ow at high phase fractions. 2001. Ishii and T. 1995. Multiphase Flow.Series {IIB} . 1996. Chemical Engineering Science. M. 2014. T.-E. [9] Agner Fog. Eulerian two-phase ow theory applied to uidization. [8] J. 2004. [7] A. [6] N. [5] J. Optimizing software in c++. Inc. [24] OpenFOAM Foundation. PhD thesis. Int. Smagorinsky. PhD thesis. 2. [22] M. A numerical analysis of conned turbulent bubble plumes. Wilcox. 2. 2002. [28] A. Nuclear Engineering and Technology. Beus. 2011. Peric J. Swiss Federal Institute of Technology Zurich. X. Computational Fluid Dynamics of dispersed two-phase ows at high phase fractions. PhD thesis. Liu. Addison-Wesley. Ishii. 219:6175. Ishii. OpenFOAM . implementation and validation of computer simulation models for gas- solid uidized beds. i. Interfacial area transport and evaluation of source and sink terms for conned air-water bubbly ow. Imperial College of Science. Milelli. [27] Bjarne Stroustrup. Fukuda. Heat Mass Transfer... Turbulence Modelling for CFD. Kim. Tomiyama. 2011. Ferzinger. Sun. DCW Industries. The C Programming Language. [16] M. the producer of the OpenFOAM software and owner of the OpenFOAM trademark. ® ® 239 . and M. XI ® ® ® This oering is not approved or endorsed by ESI Group. J. 4th edition. General circulation experiments with the primitive equations. T. the basic experiment. Delft University of Technology. [30] David C. Derivation. Modeling of interfacial area transport in two-phase ows. and J. Kim. S. [19] S. 2013. Bentham Science Publishers. Computational Methods for Fluid Dynamics. Foundation of the interfacial area transport equation and its closure relations. 2nd report. 2nd edition. Interfacial area transport equation: model development and benchmark experiments. 2002. Ishii.User Guide. 1994. M. S. 2012. Inc. 1988. 2002. 61(588):28102817. [29] Berend van Wachem. Error Analysis and Estimation for the Finite Volume Method with Applications to Fluid Flows. I. In Advances in Multiphase Flow and Heat Transfer. [23] OpenFOAM Foundation. Development of interfacial area transport equation. Prentice Hall. S. drag coecient for a swarm of bubbles and its applicability to transient ow. 1963.0 edition. 1996. 2002. G. [18] Brian W. 1995. Kernighan and Dennis M. and F. Springer. International Journal of Heat and Mass Transfer. Kim. Drag coecients of bubbles. Ishii. ESI-OpenCFD or the OpenFOAM Foundation. 2002. chapter 1. Kataoka. and T. Sakaguchi.Programmer's Guide. Technology & Medicine. H. 2000. Uhle. Ishii. [15] M. PhD thesis. [25] Henrik Rusche. Monthly Weather Review.1. Hibiki. Nippon Kikai Gakkai Ronbunshu. [21] Y. volume 4. Nuclear Engineering and Design. 38(3):481493. and J. Kocamustafaogullari and M. OpenFOAM . 1995. Imperial College of Science. 2005. Kelly. [17] Hrvoje Jasak. [26] J.[14] M. Lincoln. The C++ Programming language. Ritchie. Technology & Medicine. T. 91:99.0 edition.1. 45:31113123. [20] G. 37(6):525536. pages 327.