An Introduction to OpenFOAM Solver
buoyantBoussinesqSimpleFoam
CFD 2
Milad Salimi
16 July 2015
1
Outline
Application
 Theoretical background
Governing Equations
Boussinesq Approximation
SIMPLE Algorithm
 Implementation in OF
Pressure Shift
U, T, P Equations Implementation
 hotRoom Tutorial
2
Application
 Steady-state solver for buoyant, turbulent flow of incompressible fluids
including Boussinesq approximation for stratified flow
 Useful for heat transfer cases with low temperature differences like
ventilation problems
 Useful for natural convection problems due to buoyancy like flow around hot
plates, radiators
3
Governing Equations
4
1) 𝛻. 𝑢 = 0 Continuity Equation
2) 𝜌𝛻. 𝑢𝑢 = −𝛻𝑝 + 𝛻. 𝜇𝛻𝑢 + 𝜌𝑔 Momentum Equation
3) 𝛻. Tu = 𝑘 𝑒𝑓𝑓 𝛻2
𝑇 Temperature Equation
where 𝑘 𝑒𝑓𝑓 = 𝑘 + 𝑘 𝑡 =
𝑣 𝑡
𝑃𝑟𝑡
+
𝑣0
𝑃𝑟
𝑃𝑟 =
𝑐 𝑝 𝜇0
𝑘
, 𝑃𝑟𝑡 =
𝑐 𝑝 𝜇 𝑡
𝑘 𝑡
𝑘 𝑡 − turbulent thermal conductivity
5
• Density Variation is only important in the buoyancy term ρg
• 𝜌 = 𝜌0 = 𝑐𝑜𝑛𝑠𝑡 for inertia terms
• 𝜌 ≠ 𝑐𝑜𝑛𝑠𝑡 for gravitational term 𝜌𝑔 = 𝜌0 + ∆𝜌 𝑔
• Valid only when ∆𝜌 ≪ 𝜌0
• The density assumed to vary linearly with temperature
∆𝜌 = −𝜌0 𝛽 𝑇 − 𝑇𝑟𝑒𝑓
𝛽 − Coefficient of thermal expansion 1
𝐾
𝑇𝑟𝑒𝑓 − Reference Temperature 𝐾
Boussinesq Approximation
6
Boussinesq Approximation
• Momentum equation can be rewritten as:
𝜌0 𝛻. 𝑢𝑢 = −𝛻𝑝 + 𝛻. 𝜇𝛻𝑢 + 𝜌0 − 𝜌0 𝛽(𝑇 − 𝑇𝑟𝑒𝑓)
𝛻. 𝑢𝑢 = −𝛻𝑝 + 𝑣 𝑒𝑓𝑓 𝛻2
𝑢 + 𝜌 𝑘 𝑔
where 𝜌 𝑘 = 1 − 𝛽 𝑇 − 𝑇𝑟𝑒𝑓 , 𝜌 𝑘 ≪ 1 𝜌 𝑘 − effective kinematic density
• Allows to solve the equations with methods for incompressible flow
• Less than 1% error for temperature variations of 2K for water or 15K for air
7
SIMPLE Algorithm
• A solution method for Incompressible Steady-State Navier Stokes Equations
• SIMPLE (Semi-Implicit Method for Pressure-Linked Equations)
• In incompressible flows 𝜌 = 𝑐𝑜𝑛𝑠𝑡 and not linked to pressure (no explicit eq. For p)
• Pressure-Velocity coupling algorithms are used to derive equations for pressure
from momentum and continuity equations
• Why Semi-Implicit method?
Because the discretized momentum equation and pressure correction equation are
solved implicitly, where the velocity correction is solved explicitly
8
SIMPLE Algorithm
• aasas
9
SIMPLE Algorithm
C – Coefficient array
r – explicit source terms
A – Diagonal matrix of C
H – off-diagonal matrix of C
10
SIMPLE Algorithm
• In SIMPLE algorithm under-relaxation is required due to the neglect of u*’
• Used to increase the stability of calculations but may slow down speed of convergence
• Too small values of 𝛼 will significantly slow down the convergence
• Improved versions of SIMPLE algorithm are:
SIMPLER (SIMPLE Revised)
SIMPLEC (SIMPLE Consistent)
PISO (Pressure Implicit with Splitting of Operators)
11
Implementation in OpenFOAM
Files can be found in $FOAM_SOLVERS/heatTransfer/buoyantBoussinesqSimpleFoam
 buoyantBoussinesqSimpleFoam.C main source code
 createFields.H creates the fields
 readTransportProperties.H read transport properties: 𝑣, 𝛽, 𝑇𝑟𝑒𝑓, 𝑃𝑟, 𝑃𝑟𝑡
 UEqn.H solve momentum equation
 TEqn.H solve temperature equation
 pEqn.H solves the pressure, corrects the momentum velocities according to the new
pressure field and adjusts the pressure level to obey overall mass continuity
12
Implementation in OpenFOAM
buoyantBoussinesqSimpleFoam.C
#include "fvCFD.H„ standard file for finite volume method
#include "singlePhaseTransportModel.H„ simple single-phase transport model based on viscosity-Model
#include "RASModel.H„ namespace for incompressible RAS turbulence models
#include "fvIOoptionList.H„ class for external objects or constraints on the case
#include "simpleControl.H„ checks for the simple loop
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
#include "setRootCase.H„ checks folder structure of the case
#include "createTime.H„ checks runtime according to the controlDict and initiates time variables
#include "createMesh.H„ defines mesh in the domain
#include "readGravitationalAcceleration.H„ reads value for g
#include "createFields.H„ creates the fields: T, U, 𝑃𝑟𝑔ℎ, rhok, kappat, gh, turbulence(k, ɛ, nut)
#include "createFvOptions.H„ creates related constraints according to fvOptions
#include "initContinuityErrs.H„ declare and initialise the cumulative continuity error
13
Implementation in OpenFOAM
• In the momentum equation we have in direction of buoyancy, the terms −
𝑑𝑝
𝑑𝑧
+ 𝜌𝑔
• To make sure that in the pressure correction of the simple algorithm also the
buoyancy term 𝜌𝑔ℎ is taken into account, the pressure and the buoyancy are
expressed as one term: 𝑃𝑟𝑔ℎ = 𝑝 − 𝜌𝑔ℎ
• Computing the derivative of 𝑃𝑟𝑔ℎ we have: −
𝑑𝑃 𝑟𝑔ℎ
𝑑𝑧
= −
𝑑𝑝
𝑑𝑧
+ 𝜌𝑔 + 𝑔ℎ
𝑑𝜌
𝑑𝑧
• The term 𝑔ℎ
𝑑𝜌
𝑑𝑧
is extra and substracted via the code - ghf *fvc::snGrad(rhok) in UEqn
Pressure shift due to buoyancy
14
UEqn.H
𝛻. (𝑢𝑢) Incompressible kOmega code
(−𝑔ℎ
𝑑𝜌
𝑑𝑧
− 𝛻𝑃𝑟𝑔ℎ) * surface area over all of cell faces
reconstructs a volume field from a face flux field
applies relaxation factor
15
TEqn.HSetting up 𝑘 𝑡
TEqn.H
Setting up 𝑘 𝑒𝑓𝑓 = 𝑘 + 𝑘 𝑡
𝜌 𝑘 is updated based on the new T
s𝑜𝑙𝑣𝑒𝑠 𝑡ℎ𝑒 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 matrix
16
pEqn.H
Setting up variables
rAU=𝐴−1
invertion of A
rAUf=𝐴−1
𝑓 interpolatation of A to faces
defining a vector field HbyA=𝐴−1
𝐻  contribution to the corrected velocity excluding pressure and gravity
𝑝ℎ𝑖𝑔 = −(𝐴−1
𝑔ℎ
𝑑𝜌
𝑑𝑛
). 𝑆𝑓
𝑝ℎ𝑖𝐻𝑏𝑦𝐴 = 𝐴−1
𝐻 𝑓. 𝑆𝑓
defining a scalar field 𝑝ℎ𝑖𝐻𝑏𝑦𝐴
𝑝ℎ𝑖𝐻𝑏𝑦𝐴 = 𝐴−1
𝐻 𝑓. 𝑆𝑓 −(𝐴−1
𝑔ℎ
𝑑𝜌
𝑑𝑛
). 𝑆𝑓
𝑠𝑒𝑡𝑡𝑖𝑛𝑔 𝑝𝑟𝑒𝑠𝑠𝑢𝑟𝑒 𝑐𝑜𝑟𝑒𝑐𝑡𝑖𝑜𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛
∇2
𝐴−1
𝑃′
𝑟𝑔ℎ = ∇. (𝐴−1
𝐻 − 𝐴−1
𝑔ℎ
𝑑𝜌
𝑑𝑛
). 𝑆𝑓
𝑐𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑒𝑠 𝑃′
𝑟𝑔ℎ
17
pEqn.H
for velocity corrector 𝒖′
𝑢𝑝𝑑𝑎𝑡𝑒𝑠 𝑡ℎ𝑒 𝑝𝑟𝑒𝑠𝑠𝑢𝑟𝑒: 𝑃 𝑛+1
𝑟𝑔ℎ = 𝑃 𝑛
𝑟𝑔ℎ + 𝛼 𝑝 𝑃′
𝑟𝑔ℎ
𝑈 = 𝐴−1
𝐻 − 𝐴−1
𝑔ℎ
𝑑𝜌
𝑑𝑛
− 𝐴−1
∇𝑃 𝑛+1
𝑟𝑔ℎ
18
hotRoom Tutorial
Shows how constant temperature point heat source influences the behavior of a static
volume of air
Natural convection occurs
K-epsilon turbulence model used
19
hotRoom Tutorial
• A cube with size 10 × 5 × 10 𝑚3
• Number of cells in each direction (20 10 20) with no grading  Total 4000 cells
• 6 wall patches (floor, ceiling, 4 fixed walls)
• A heat source with T=600K located at floor patch (setFieldsDict)
20
Boundary Conditions
Field patch type value
U all fixedValue 0
P_rgh All fixedFluxPressure 0
T
floor fixedValue 300
ceiling fixedValue 300
fixedWalls zerogradient -
alphat All alphatJayatillekeWallFunction 0
P All calculated
k All kqRWallFunction 0.1
epsilon All epsilonWallFunction 0.01
Temperature
21
22
Pressure
23
k
24
References
 www.openfoamwiki.net
 www.cfd-online.com
 https://github.com/OpenFOAM/OpenFOAM-2.2.x
 http://freefoam.sourceforge.net
 www.comsol.de/multiphysics/boussinesq-approximation
 www.bakker.org/dartmouth06/engs150/05-solv.ppt
 web.stanford.edu/class/me469b/handouts/incompressible.pdf
 www.training.prace-ri.eu/uploads/tx_pracetmo/OpenFOAMselectedSolver-1.pdf
25

buoyantBousinessqSimpleFoam

  • 1.
    An Introduction toOpenFOAM Solver buoyantBoussinesqSimpleFoam CFD 2 Milad Salimi 16 July 2015 1
  • 2.
    Outline Application  Theoretical background GoverningEquations Boussinesq Approximation SIMPLE Algorithm  Implementation in OF Pressure Shift U, T, P Equations Implementation  hotRoom Tutorial 2
  • 3.
    Application  Steady-state solverfor buoyant, turbulent flow of incompressible fluids including Boussinesq approximation for stratified flow  Useful for heat transfer cases with low temperature differences like ventilation problems  Useful for natural convection problems due to buoyancy like flow around hot plates, radiators 3
  • 4.
    Governing Equations 4 1) 𝛻.𝑢 = 0 Continuity Equation 2) 𝜌𝛻. 𝑢𝑢 = −𝛻𝑝 + 𝛻. 𝜇𝛻𝑢 + 𝜌𝑔 Momentum Equation 3) 𝛻. Tu = 𝑘 𝑒𝑓𝑓 𝛻2 𝑇 Temperature Equation where 𝑘 𝑒𝑓𝑓 = 𝑘 + 𝑘 𝑡 = 𝑣 𝑡 𝑃𝑟𝑡 + 𝑣0 𝑃𝑟 𝑃𝑟 = 𝑐 𝑝 𝜇0 𝑘 , 𝑃𝑟𝑡 = 𝑐 𝑝 𝜇 𝑡 𝑘 𝑡 𝑘 𝑡 − turbulent thermal conductivity
  • 5.
    5 • Density Variationis only important in the buoyancy term ρg • 𝜌 = 𝜌0 = 𝑐𝑜𝑛𝑠𝑡 for inertia terms • 𝜌 ≠ 𝑐𝑜𝑛𝑠𝑡 for gravitational term 𝜌𝑔 = 𝜌0 + ∆𝜌 𝑔 • Valid only when ∆𝜌 ≪ 𝜌0 • The density assumed to vary linearly with temperature ∆𝜌 = −𝜌0 𝛽 𝑇 − 𝑇𝑟𝑒𝑓 𝛽 − Coefficient of thermal expansion 1 𝐾 𝑇𝑟𝑒𝑓 − Reference Temperature 𝐾 Boussinesq Approximation
  • 6.
    6 Boussinesq Approximation • Momentumequation can be rewritten as: 𝜌0 𝛻. 𝑢𝑢 = −𝛻𝑝 + 𝛻. 𝜇𝛻𝑢 + 𝜌0 − 𝜌0 𝛽(𝑇 − 𝑇𝑟𝑒𝑓) 𝛻. 𝑢𝑢 = −𝛻𝑝 + 𝑣 𝑒𝑓𝑓 𝛻2 𝑢 + 𝜌 𝑘 𝑔 where 𝜌 𝑘 = 1 − 𝛽 𝑇 − 𝑇𝑟𝑒𝑓 , 𝜌 𝑘 ≪ 1 𝜌 𝑘 − effective kinematic density • Allows to solve the equations with methods for incompressible flow • Less than 1% error for temperature variations of 2K for water or 15K for air
  • 7.
    7 SIMPLE Algorithm • Asolution method for Incompressible Steady-State Navier Stokes Equations • SIMPLE (Semi-Implicit Method for Pressure-Linked Equations) • In incompressible flows 𝜌 = 𝑐𝑜𝑛𝑠𝑡 and not linked to pressure (no explicit eq. For p) • Pressure-Velocity coupling algorithms are used to derive equations for pressure from momentum and continuity equations • Why Semi-Implicit method? Because the discretized momentum equation and pressure correction equation are solved implicitly, where the velocity correction is solved explicitly
  • 8.
  • 9.
    9 SIMPLE Algorithm C –Coefficient array r – explicit source terms A – Diagonal matrix of C H – off-diagonal matrix of C
  • 10.
    10 SIMPLE Algorithm • InSIMPLE algorithm under-relaxation is required due to the neglect of u*’ • Used to increase the stability of calculations but may slow down speed of convergence • Too small values of 𝛼 will significantly slow down the convergence • Improved versions of SIMPLE algorithm are: SIMPLER (SIMPLE Revised) SIMPLEC (SIMPLE Consistent) PISO (Pressure Implicit with Splitting of Operators)
  • 11.
    11 Implementation in OpenFOAM Filescan be found in $FOAM_SOLVERS/heatTransfer/buoyantBoussinesqSimpleFoam  buoyantBoussinesqSimpleFoam.C main source code  createFields.H creates the fields  readTransportProperties.H read transport properties: 𝑣, 𝛽, 𝑇𝑟𝑒𝑓, 𝑃𝑟, 𝑃𝑟𝑡  UEqn.H solve momentum equation  TEqn.H solve temperature equation  pEqn.H solves the pressure, corrects the momentum velocities according to the new pressure field and adjusts the pressure level to obey overall mass continuity
  • 12.
    12 Implementation in OpenFOAM buoyantBoussinesqSimpleFoam.C #include"fvCFD.H„ standard file for finite volume method #include "singlePhaseTransportModel.H„ simple single-phase transport model based on viscosity-Model #include "RASModel.H„ namespace for incompressible RAS turbulence models #include "fvIOoptionList.H„ class for external objects or constraints on the case #include "simpleControl.H„ checks for the simple loop // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) { #include "setRootCase.H„ checks folder structure of the case #include "createTime.H„ checks runtime according to the controlDict and initiates time variables #include "createMesh.H„ defines mesh in the domain #include "readGravitationalAcceleration.H„ reads value for g #include "createFields.H„ creates the fields: T, U, 𝑃𝑟𝑔ℎ, rhok, kappat, gh, turbulence(k, ɛ, nut) #include "createFvOptions.H„ creates related constraints according to fvOptions #include "initContinuityErrs.H„ declare and initialise the cumulative continuity error
  • 13.
    13 Implementation in OpenFOAM •In the momentum equation we have in direction of buoyancy, the terms − 𝑑𝑝 𝑑𝑧 + 𝜌𝑔 • To make sure that in the pressure correction of the simple algorithm also the buoyancy term 𝜌𝑔ℎ is taken into account, the pressure and the buoyancy are expressed as one term: 𝑃𝑟𝑔ℎ = 𝑝 − 𝜌𝑔ℎ • Computing the derivative of 𝑃𝑟𝑔ℎ we have: − 𝑑𝑃 𝑟𝑔ℎ 𝑑𝑧 = − 𝑑𝑝 𝑑𝑧 + 𝜌𝑔 + 𝑔ℎ 𝑑𝜌 𝑑𝑧 • The term 𝑔ℎ 𝑑𝜌 𝑑𝑧 is extra and substracted via the code - ghf *fvc::snGrad(rhok) in UEqn Pressure shift due to buoyancy
  • 14.
    14 UEqn.H 𝛻. (𝑢𝑢) IncompressiblekOmega code (−𝑔ℎ 𝑑𝜌 𝑑𝑧 − 𝛻𝑃𝑟𝑔ℎ) * surface area over all of cell faces reconstructs a volume field from a face flux field applies relaxation factor
  • 15.
    15 TEqn.HSetting up 𝑘𝑡 TEqn.H Setting up 𝑘 𝑒𝑓𝑓 = 𝑘 + 𝑘 𝑡 𝜌 𝑘 is updated based on the new T s𝑜𝑙𝑣𝑒𝑠 𝑡ℎ𝑒 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 matrix
  • 16.
    16 pEqn.H Setting up variables rAU=𝐴−1 invertionof A rAUf=𝐴−1 𝑓 interpolatation of A to faces defining a vector field HbyA=𝐴−1 𝐻  contribution to the corrected velocity excluding pressure and gravity 𝑝ℎ𝑖𝑔 = −(𝐴−1 𝑔ℎ 𝑑𝜌 𝑑𝑛 ). 𝑆𝑓 𝑝ℎ𝑖𝐻𝑏𝑦𝐴 = 𝐴−1 𝐻 𝑓. 𝑆𝑓 defining a scalar field 𝑝ℎ𝑖𝐻𝑏𝑦𝐴 𝑝ℎ𝑖𝐻𝑏𝑦𝐴 = 𝐴−1 𝐻 𝑓. 𝑆𝑓 −(𝐴−1 𝑔ℎ 𝑑𝜌 𝑑𝑛 ). 𝑆𝑓 𝑠𝑒𝑡𝑡𝑖𝑛𝑔 𝑝𝑟𝑒𝑠𝑠𝑢𝑟𝑒 𝑐𝑜𝑟𝑒𝑐𝑡𝑖𝑜𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 ∇2 𝐴−1 𝑃′ 𝑟𝑔ℎ = ∇. (𝐴−1 𝐻 − 𝐴−1 𝑔ℎ 𝑑𝜌 𝑑𝑛 ). 𝑆𝑓 𝑐𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑒𝑠 𝑃′ 𝑟𝑔ℎ
  • 17.
    17 pEqn.H for velocity corrector𝒖′ 𝑢𝑝𝑑𝑎𝑡𝑒𝑠 𝑡ℎ𝑒 𝑝𝑟𝑒𝑠𝑠𝑢𝑟𝑒: 𝑃 𝑛+1 𝑟𝑔ℎ = 𝑃 𝑛 𝑟𝑔ℎ + 𝛼 𝑝 𝑃′ 𝑟𝑔ℎ 𝑈 = 𝐴−1 𝐻 − 𝐴−1 𝑔ℎ 𝑑𝜌 𝑑𝑛 − 𝐴−1 ∇𝑃 𝑛+1 𝑟𝑔ℎ
  • 18.
    18 hotRoom Tutorial Shows howconstant temperature point heat source influences the behavior of a static volume of air Natural convection occurs K-epsilon turbulence model used
  • 19.
    19 hotRoom Tutorial • Acube with size 10 × 5 × 10 𝑚3 • Number of cells in each direction (20 10 20) with no grading  Total 4000 cells • 6 wall patches (floor, ceiling, 4 fixed walls) • A heat source with T=600K located at floor patch (setFieldsDict)
  • 20.
    20 Boundary Conditions Field patchtype value U all fixedValue 0 P_rgh All fixedFluxPressure 0 T floor fixedValue 300 ceiling fixedValue 300 fixedWalls zerogradient - alphat All alphatJayatillekeWallFunction 0 P All calculated k All kqRWallFunction 0.1 epsilon All epsilonWallFunction 0.01
  • 21.
  • 22.
  • 23.
  • 24.
    24 References  www.openfoamwiki.net  www.cfd-online.com https://github.com/OpenFOAM/OpenFOAM-2.2.x  http://freefoam.sourceforge.net  www.comsol.de/multiphysics/boussinesq-approximation  www.bakker.org/dartmouth06/engs150/05-solv.ppt  web.stanford.edu/class/me469b/handouts/incompressible.pdf  www.training.prace-ri.eu/uploads/tx_pracetmo/OpenFOAMselectedSolver-1.pdf
  • 25.