the openfoam® technology primer - gbv
TRANSCRIPT
The OpenFOAM® Technology Primer
Tomislav Marie Jens Höpken Kyle Mooney
sourceflux
Table of Contents
Preface 1 What is covered in this book 2 Prerequisites 4 Intended audience 4 Conventions 5
I Using O p e n F O A M 7
1 Computational Fluid Dynamics in OpenFOAM 9 1.1 Understanding The Flow Problem 9 1.2 Stages of a Computational Fluid Dynamics (CFD) Analysis 11
1.2.1 Problem Definition 11 1.2.2 Mathematical Modeling 11 1.2.3 Pre-processing and Mesh Generation 12 1.2.4 Solving 13 1.2.5 Post-Processing 13 1.2.6 Discussion and Verification 14
1.3 Introducing the Finite Volume Method in OpenFOAM . . 14 1.3.1 Domain Discretization 16 1.3.2 Equation Discretization 25 1.3.3 Boundary Conditions 30 1.3.4 Solving the System of Algebraic Equations . . . . 32
1.4 Overview of the Organization of the OpenFOAM Toolkit . 34 1.5 Summary 36
2 Geometry Definition, Meshing and Mesh Conversion 39 2.1 Geometry Definition 40
2.1.1 CAD Geometry 47 2.2 Mesh Generation 48
2.2.1 blockMesh 48
Table of Contents
2.2.2 snappyHexMesh 57 2.2.3 cfMesh 67
2.3 Mesh Conversion from other Sources 78 2.3.1 Conversion from Thirdparty Meshing Packages . . 78 2.3.2 Converting from 2D to Axisymmetric Meshes . . . 81
2.4 Mesh Utilities in OpenFOAM 85 2.4.1 Refining the Mesh by a Specified Criterion . . . . 85 2.4.2 transformPoints 87 2.4.3 mirrorMesh 88
2.5 Summary 90
3 OpenFOAM Case Setup 91 3.1 The OpenFOAM Case Structure 91 3.2 Boundary Conditions and Initial Conditions 95
3.2.1 Setting Boundary Conditions 97 3.2.2 Setting Initial Conditions 100
3.3 Discretization Schemes and Solver Control 104 3.3.1 Numerical Schemes (fvSchemes) 104 3.3.2 Solver Control (fvSolution) 117
3.4 Solver Execution and Run Control 120 3.4.1 controlDict Configuration 121 3.4.2 Decomposition and Parallel Execution 122
3.5 Summary 125
4 Post-Processing, Visualization and Data Sampling 127 4.1 Post-processing 127 4.2 Data Sampling 135
4.2.1 Sampling along a Line 136 4.2.2 Sampling on a Plane 138 4.2.3 Generating and Interpolating to an Iso-surface . . . 140 4.2.4 Boundary Patch Sampling 141 4.2.5 Sampling Multiple Sets and Surfaces 143
4.3 Visualization 143
II P rogramming w i t h O p e n F O A M 151
5 Design Overview of the OpenFOAM Library 153 5.1 Generating Local Documentation using Doxygen 155
Table of Contents
5.2 Parts of OpenFOAM encountered during Simulations . . . 156 5.2.1 Applications 157 5.2.2 Configuration System 159 5.2.3 Boundary Conditions 160 5.2.4 Numerical Operations 160 5.2.5 Post-processing 165
5.3 Often Encountered Classes 167 5.3.1 Dictionary 167 5.3.2 Dimensioned Types 169 5.3.3 Smart Pointers 174 5.3.4 Volume Fields 188
6 Productive Programming with OpenFOAM 193 6.1 Code Organization 194
6.1.1 Directory Organization 196 6.1.2 Automating Installation 197 6.1.3 Documenting Code using Doxygen 201
6.2 Debugging and Profiling 202 6.2.1 Debugging with GNU Debugger (gdb) 202 6.2.2 Profiling with valgrind 207
6.3 Using git to Track an OpenFOAM Project 210 6.4 Installing OpenFOAM on an HPC cluster 213
6.4.1 Distributed Memory Computing Systems 213 6.4.2 Compiler Configuration 214 6.4.3 MPI Configuration 215
7 Turbulence Modeling 219 7.1 Introduction 219
7.1.1 Wall Functions 221 7.2 Pre- and Post-processing and Boundary Conditions . . . . 223
7.2.1 Pre-processing 224 7.2.2 Post-processing 225
7.3 Class Design 226
8 Writ ing Pre- and Post-processing Applications 229 8.1 Code Generation Scripts 230 8.2 Custom Pre-processing Applications 232
8.2.1 Decomposing and Starting a Parallel Run 232 8.2.2 Parameter Variation using PyFoam 235
Table of Contents
8.3 Custom Post-processing Applications 240
9 Solver Customization 259 9.1 Solver Design 259
9.1.1 Fields 263 9.1.2 Solution Algorithm 264
9.2 Customizing the Solver 265 9.2.1 Working with Dictionaries 266 9.2.2 The Object Registry and reglOobjects 268
9.3 Implementing a new PDE 271 9.3.1 Additional Model Equation 271 9.3.2 Preparing the Solver for Modification 273 9.3.3 Adding new Entries into createFields.H 274 9.3.4 Programming the Model Equation 274 9.3.5 Setting up the Case 276 9.3.6 Executing the solver 279
10 Boundary Conditions 283 10.1 Numerical Background of a Boundary Condition 283 10.2 Boundary Condition Design 284
10.2.1 Internal, Boundary and Geometric Fields 284 10.2.2 Boundary Conditions 291
10.3 Implementing a new Boundary Condition 298 10.3.1 Recirculation Control Boundary Condition 299 10.3.2 Mesh Motion Boundary Condition 317
11 Transport Models 333 11.1 Numerical Background 333 11.2 Software Design 335 11.3 Implementation of a new Viscosity Model 342
11.3.1 Example Case 344
12 Function Objects 349 12.1 Software Desgin 350
12.1.1 Function Objects in C++ 351 12.1.2 Function Objects in OpenFOAM 356
12.2 Using OpenFOAM Function Objects 360 12.2.1 Function Objects in the Official Release 360 12.2.2 Function Objects in swak4f oam 362
IV
Table of Contents
12.3 Implementation of a Custom Function Object 367 12.3.1 Function Object Generator 367 12.3.2 Implementing the Function Object 370
13 Dynamic Mesh Operations in OpenFOAM 379 13.1 Software Design 381
13.1.1 Mesh Motion 381 13.1.2 Topological Changes 391
13.2 Usage 396 13.2.1 Global Mesh Motion 397 13.2.2 Mesh Deformation 398
13.3 Development 400 13.3.1 Adding Dynamic Mesh to a Solver 400 13.3.2 Combining two Dynamic Mesh Classes 404
13.4 Summary 427
14 Outlook 429 14.1 Numerical Methodology 429 14.2 Coupling to External Simulation Platforms 430 14.3 Workflow Enhancement 431
14.3.1 Graphical User Interfaces 431 14.3.2 Console Interfaces 432
14.4 Unconstrained Mesh Motion 432 14.4.1 Immersed Boundary Method 432 14.4.2 Overset Grid 433
14.5 Summary 434