OpenFOAM tutorial
OpenFOAM tutorial Discover it, tame it, use it
by Victor Pozzobon (
[email protected]) 26th December 2016
Version 1.03
Disclaimer “This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”
26th December 2016
Pozzobon Victor
2
Introduction ●
● ●
●
This tutorial is a brief introduction to OpenFOAM This document is a step by step guide It was done to be used on its own, there should be no need for a presenter (myself) It was designed for OpenFOAM 3.0.1 and validated with 16.06+ version (changes may appear in superior versions)
26th December 2016
Pozzobon Victor
3
OpenFOAM ●
●
OpenFOAM (Open Field Operation And Manipulation) is a versatile equations solver Why do I use OpenFOAM ? - free - powerful - opensource - allows a lot of freedom - no GUI (helps to focus on the equations)
26th December 2016
Pozzobon Victor
4
How to use this tutorial ●
●
Almost every command will passed through the terminal. For example, when you see: gedit system/controlDict you type it in the terminal As OpenFOAM has no GUI, we will modify files. For example, when you see this kind of picture: modify the file so that its content is the same before you save it
26th December 2016
Pozzobon Victor
5
Battle plan ●
Ex. 1: Cavity
●
- getting started ●
- solver modifying (1/2)
Ex. 2: Square tube - mesh manipulation - steady state
●
- solver modifying (2/2) ●
●
Ex. 4: 2D flat plate
Ex. 8: Heating pipe Ex. 9: Cake backing - field affectation
●
Ex. 5: 2D pipe - axisymmetric problem
26th December 2016
Ex. 7: Tubular reactor - custom boundary condition
- 2D problem ●
●
Ex. 3: 1D beam - 1D problem - transient
●
Ex. 6: Tubular reactor
Pozzobon Victor
Ex. 10: Tank filling - importing a mesh - run in parallel 6
Ex. 1: Cavity - Objectives ●
Accessing your work directory
●
Accessing OpenFOAM tutorials
●
Understanding case architecture
●
Running your first OpenFOAM case
●
Postprocessing with ParaFoam (Paraview with OpenFOAM reader module): data modifying, line date / point data extraction
26th December 2016
Pozzobon Victor
7
Ex. 1: Cavity - Run ●
To access your directory type in a terminal: run
●
●
To get the full path type: pwd You will see: /home/YourName/OpenFOAM/YourName-OpenFOAMVersion/run
26th December 2016
Pozzobon Victor
8
Ex. 1: Cavity - Tutorials ●
To copy official tutorials to your run: cp -r $FOAM_TUTORIALS Tutorials
●
Go to the case directory: cd Tutorials/incompressible/icoFoam/cavity/cavity
26th December 2016
Pozzobon Victor
9
Ex. 1: Cavity - Architecture Case directory Initial conditions directory Pressure / Velocity initial conditions Mesh directory
Physical properties values Solving parameters directory Mesh instructions Parameters file 26th December 2016
Pozzobon Victor
10
Ex. 1: Cavity – Run the case ●
●
●
Once in 'cavity' directory, create the mesh: blockMesh Call the solver: icoFoam (you can note that the solver created several directories e.g. '0.1'. These directories contain data for a given time) Watch the results: paraFoam
26th December 2016
Pozzobon Victor
11
Ex. 1: Cavity – Postprocessing Data analysis pipeline
Load the case
Load geometric fields Load the fields 26th December 2016
Pozzobon Victor
12
Ex. 1: Cavity – Postprocessing Current time step Plotted data Plot Rescale legend legend
Observation tools Time step tool Legend
Scene
26th December 2016
Pozzobon Victor
13
Ex. 1: Cavity – Postprocessing ●
●
●
●
Make it look shinier: Filters / Alphabetical / Cell data to point data Calculate something: Filters / Common / Calculator OR Extract profiles: Filters / Data Analysis / Plot Over Line Extract histories: Filters / Data Analysis / Plot Selection Over Time
26th December 2016
Pozzobon Victor
14
Battle plan ●
●
●
From Ex. 2 to Ex. 5, we are going to learn how to use existing solvers in different configurations. We are going to set 3D, 2D planar, 2D axisymmetrical and 1D cases We are going to explore postprocessor basic functions
26th December 2016
Pozzobon Victor
15
Ex. 2: Square tube - Objectives ●
Creating your own case
●
Creating a mesh
●
Specifying initial / boundary conditions
●
Specifying physical properties values
●
Solving a steady state problem
●
Postprocessing with ParaFoam: integrating variable / checking mass conservation
26th December 2016
Pozzobon Victor
16
Ex. 2: Square tube – Case setup ●
Solving steady state incompressible Navier-Stokes equation, in a fourth of a square pipe ⃗ dU p 2 ⃗ ⃗ ⃗ + U ∇ . U =−∇ ρ +η ∇ U dt
2 cm
26th December 2016
20 cm
Pozzobon Victor
17
Ex. 2: Square tube – A new case ●
●
●
●
Go to your 'run' directory: run Copy an existing case: cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily/ Ex2 Move to the case directory: cd Ex2 Open the mesh file: gedit system/blockMeshDict
26th December 2016
Pozzobon Victor
18
Ex. 2: Square tube – A new mesh ● ●
A fourth of a square tube with symmetry plane Points have to be prescribed in order to bluid a 5 6 mesh (consider doing a sketch)
x
z 2
Wall 4
7
1
Inlet
Outlet y
Symmetry plane 26th December 2016
0 Pozzobon Victor
3
19
Ex. 2: Square tube – A new mesh ●
●
Beware, the points are to be prescribed in order not to back cross a line Do (0 4 7 3) 4
7
0
3
26th December 2016
Scaling factor Block division along axis Points locations Division grading
Points needed to Pozzobon Victor build a block
20
Ex. 2: Square tube – A new mesh ●
Face name
Avoid (0 3 4 7) 4
7 Face type
0
3
Point sequence delimiting the face Wall
Inlet
26th December 2016
Outlet
Pozzobon Victor
21
Ex. 2: Square tube – A new mesh ●
●
Compile your mesh: blockMesh Check its quality: checkMesh
26th December 2016
Pozzobon Victor
22
Ex. 2: Square tube – Turbulence model and parameters ●
●
Choose the turbulence model. In this case, there is no turbulence: gedit constant/turbulenceProperties Because we disabled the turbulence, there will be no need to specify: epsilon, k, nut and nuTilda fields: rm 0/epsilon 0/k 0/nut 0/nuTilda 0/f 0/omega 0/v2
26th December 2016
Pozzobon Victor
23
Ex. 2: Square tube – IC / BC ●
Open initial / boundary conditions files in the '0' directory: gedit 0/p gedit 0/U Physical field
Physical field unit [ kg m s K mol A Cd] Initial condition Boundary condition on 'inlet' patch 26th December 2016
Pozzobon Victor
24
Ex. 2: Square tube – IC / BC, p ●
Open initial / boundary conditions for the pressure field
Field type, here scalar
26th December 2016
Pozzobon Victor
25
Ex. 2: Square tube – IC / BC, U ●
Open initial / boundary conditions for the velocity field
Field type, here vector
26th December 2016
Pozzobon Victor
26
Ex. 2: Square tube – Setting values ●
Open transportProperties file, this is where physical properties value (e.g. viscosity) are specified: gedit constant/transportProperties
Property name Property dimension [ kg m s K mol A Cd] Property value Subdictionaries for some viscosity laws, can be removed in our case 26th December 2016
Pozzobon Victor
27
Ex. 2: Square tube – Control values ●
●
Open case control file: gedit system/controlDict Erase the “functions” and below End time = maximum number of iteration
Constant “time step” equals to 1 26th December 2016
Pozzobon Victor
28
Ex. 2: Square tube – Control values ●
In steady state, the maximum number of iteration is prescribed using “endTime”. Yet, there is no variation in time. It is a “trick”, nothing more
Data are extracted every 5 iterations
26th December 2016
Pozzobon Victor
29
Ex. 2: Square tube – Run the case ●
●
The mesh has already been built, so let's run the case: simpleFoam (it should converge in about 20 iterations) Have a look at the results: paraFoam
26th December 2016
Pozzobon Victor
30
Ex. 2: Square tube – Postprocessing ●
●
Check mass conservation: Filters / Common / Slice Filters / Data Analysis / Integrate Variables Check velocity profile: Filters / Data Analysis / Plot Over Line
26th December 2016
Pozzobon Victor
31
Ex. 3: 1D beam - Objectives ●
Setting a 1D case
●
Solving a transient problem
●
Postprocessing with ParaFOAM: importing variables (other than p and U)
26th December 2016
Pozzobon Victor
32
Ex. 3: 1D beam – Case setup ●
Solving transient heat conduction in a 1D beam dT 2 =α ∇ T dt
Symmetry planes Cold side
Hot side
20 cm
26th December 2016
Pozzobon Victor
33
Ex. 3: 1D beam – Case creation ●
●
●
●
Reach 'run' directory: run Copy an existing heat transfer case: cp -r $FOAM_TUTORIALS/basic/laplacianFoam/flange Ex3 cd Ex3 Clean the case directory: rm Allclean Allrun flange.ans Copy Ex2 mesh: cp ../Ex2/system/blockMeshDict system/.
26th December 2016
Pozzobon Victor
34
Ex. 3: 1D beam – Modifying mesh ●
●
Modify file: gedit system/blockMeshDict Build mesh: blockMesh
26th December 2016
Pozzobon Victor
35
Ex. 3: 1D beam – IC / BC ●
Modify temperature file: gedit 0/T
26th December 2016
Pozzobon Victor
36
Ex. 3: 1D beam – Diffusivity ●
Modify transport property file: gedit constant/transportProperties
26th December 2016
Pozzobon Victor
37
Ex. 3: 1D beam – Control value ●
●
●
Modify control dictionary: gedit system/controlDict Run the case: laplacianFoam Postprocess the case: paraFoam
26th December 2016
Pozzobon Victor
38
Ex. 3: 1D beam – Postprocessing ●
Check T, as a 'Volume field' when loading data
26th December 2016
Pozzobon Victor
39
Ex. 4: 2D flat plate - Objectives ●
Setting a 2D case
●
Building a 2 block mesh
●
Changing convergence criterion
●
Postprocessing with ParaFoam: plotting streamlines
26th December 2016
Pozzobon Victor
40
Ex. 4: 2D flat plate – Case setup ●
Solving incompressible air flow above a flat plate, in steady state ⃗ dU p 2 ⃗ ⃗ ⃗ + U ∇ . U =−∇ ρ +η∇ U dt 30 cm
20 cm
20 cm 26th December 2016
Pozzobon Victor
41
Ex. 4: 2D flat plate – Case creation ●
●
●
Reach 'run' directory: run Copy an existing case: cp -r Ex2 Ex4 cd Ex4 Clean the case directory: foamListTimes -rm (this command removes time/iteration folders except the ‘0’ folder)
26th December 2016
Pozzobon Victor
42
Ex. 4: 2D flat plate – Mesh ●
We will create a mesh made of two blocks.
●
Modify file: gedit system/blockMeshDict Top
Inlet
Block 1
Outlet
Symmetry wall Down
Plate Block 2
26th December 2016
Pozzobon Victor
43
Ex. 4: 2D flat plate – Creating mesh ●
●
Create the two blocks blockMesh will merge them
26th December 2016
Pozzobon Victor
44
Ex. 4: 2D flat plate – Creating mesh ●
Set the faces
●
Build mesh: blockMesh
26th December 2016
Pozzobon Victor
45
Ex. 4: 2D flat plate – IC / BC ●
Modify velocity file: gedit 0/U
26th December 2016
Pozzobon Victor
46
Ex. 4: 2D flat plate – IC / BC ●
Modify pressure file: gedit 0/p
26th December 2016
Pozzobon Victor
47
Ex. 4: 2D flat plate – Viscosity ●
Modify the kinematic viscosity: gedit constant/transportProperties
26th December 2016
Pozzobon Victor
48
Ex. 4: 2D flat plate – Convergence ●
Modify pressure / velocity convergence criteria: gedit system/fvSolution
●
In this case, there are a lot of options. Some solvers are much simpler
Solver Solved type and options field 26th December 2016
Pozzobon Victor
49
Ex. 4: 2D flat plate – Convergence ●
●
Simulations can be stopped automatically once residues values have been reached For 2D cases, the unsolved component of the velocity vector prevents the solver from reaching the tolerance most of time. Therefore, a number of iterations has to be prescribed Residues values set for convergence
26th December 2016
Pozzobon Victor
50
Ex. 4: 2D flat plate – Run the case ●
●
●
●
The mesh has already been built The controlDict has not changed from Ex2. The solver will run for 100 iterations. It is enough to get the residues below 10-6 gedit system/controlDict Run the case: simpleFoam Have a look at the results: paraFoam
26th December 2016
Pozzobon Victor
51
Ex. 4: 2D flat plate – Postprocessing ●
Lower the first scene opacity: 'Click on the filter' / Display / Styling / Opacity
●
●
●
Plot the streamline from the inlet: Filters / Common / Stream Tracer Set streamlines' sources as a line, not a point: 'Click on stream tracer' / Properties / Seeds / Seed type => High resolution line source Set the line you want using the coordinates
26th December 2016
Pozzobon Victor
52
Ex. 4: 2D flat plate – Postprocessing
26th December 2016
Pozzobon Victor
53
Ex. 5: 2D pipe - Objectives ●
Creating a 2D axisymmetrical mesh
●
Nothing fancy ...
26th December 2016
Pozzobon Victor
54
Ex. 5: 2D pipe – Case setup ●
Solving incompressible flow in a 2D axisymmetrical pipe, in steady state ⃗ dU p 2 ⃗ ⃗ ⃗ + U ∇ . U =−∇ ρ +η∇ U dt 10 cm
1 cm
26th December 2016
Pozzobon Victor
55
Ex. 5: 2D pipe – Case creation ●
●
●
●
Reach 'run' directory: run Copy an existing case: cp -r Ex2 Ex5 Go to the new case directory: cd Ex5 Clean the case directory: foamListTimes -rm
26th December 2016
Pozzobon Victor
56
Ex. 5: 2D pipe – Mesh ●
Modify file: gedit system/blockMeshDict Axis
5°
Outlet
Inlet Front and Back
26th December 2016
Wall Pozzobon Victor
57
Ex. 5: 2D pipe – Block creation ●
●
Draw a wegde, with a 5° angle (twice 2.5°) Points 1, 2 and 3 are not used to build the geometry. OpenFOAM uses them to define x, y and z directions : - point 0 to point 1 = x - point 1 to point 2 = y - point 0 to point 4 = z
26th December 2016
Pozzobon Victor
cos(2.5°) sin(2.5°)
58
Ex. 5: 2D pipe – Patches creation ●
●
In order to do things by the book, create two 'wedge' patches (here, 'front' and 'back') It would have worked with only one, but checkMesh would have returned an error
26th December 2016
Pozzobon Victor
59
Ex. 5: 2D pipe – IC / BC p ●
Set pressure boundary / initial conditions: gedit 0/p
26th December 2016
Pozzobon Victor
60
Ex. 5: 2D pipe – IC / BC U ●
Set veolicty boundary / initial conditions: gedit 0/U
26th December 2016
Pozzobon Victor
61
Ex. 5: 2D pipe – Run the case ●
●
●
(As usual now) The mesh has already been built, the controlDict has not changed from Ex2. As for Ex4, we have to set the desired number of iterations: gedit system/controlDict So let's run the case: simpleFoam Have a look at the results: paraFoam
26th December 2016
Pozzobon Victor
62
Ex. 5: 2D pipe – Postprocessing ●
E.g. check velocity profile
26th December 2016
Pozzobon Victor
63
Battle plan ●
●
●
●
We have used two different builtin solvers (icoFoam, simpleFoam and laplacianFoam) We have set cases in 3D, 2D planar, 2D axisymmetrical and 1D configurations We have learnt how to process data with Paraview (paraFoam) We are going to learn how to solve our own equations and set fancy cases
26th December 2016
Pozzobon Victor
64
Ex. 6: Tubular reactor – Objectives ●
Create our own solver
●
Use basic operators
●
Create the associated case
26th December 2016
Pozzobon Victor
65
Ex. 6: Tubular reactor – Case setup ●
1D tubular reactor with heterogeneous catalysis on porous media without chemical reaction in steady state / hydrodynamics only ⃗ =0 ∇ .U
⃗ = −κ U μ ∇p
∇ 2 p=0 Symmetry planes
Inlet
Outlet
100 cm 26th December 2016
Pozzobon Victor
66
Ex. 6: Tubular reactor – Solver directory creation ●
●
●
●
Reach 'run' directory: run Create a solver directory: mkdir solvers Copy an existing solver: cp -r $FOAM_APP/solvers/basic/laplacianFoam solvers/. Rename the solver directory: mv solvers/laplacianFoam solvers/tubeFoam
26th December 2016
Pozzobon Victor
67
Ex. 6: Tubular reactor – Solver cleaning up ●
●
Move to solver directory: cd solvers/tubeFoam Clean the directory: wclean rm write.H
●
Rename the file: mv laplacianFoam.C tubeFoam.C
26th December 2016
Pozzobon Victor
68
Ex. 6: Tubular reactor – Solver modification ●
●
Modify compilation file: gedit Make/files You can specify compilation options: gedit Make/options (None need to be applied here)
26th December 2016
Pozzobon Victor
69
Ex. 6: Tubular reactor – Solver modification / createFields.H ●
Modify createFields.H to create the new fields: gedit createFields.H Pressure field (scalar field)
Velocity field (vector field) 26th December 2016
Pozzobon Victor
70
Ex. 6: Tubular reactor – Solver modification / createFields.H ●
Modify createFields.H to read the physical properties: gedit createFields.H
Physical property called 'Mu' 26th December 2016
Pozzobon Victor
71
Ex. 6: Tubular reactor – Solver modification / tubeFoam.C ●
Modify tubeFoam.C to specify the equations that will be solved: gedit tubeFoam.C Time loop Correction loop (not mandatory) Solved equations (implicit '=0')
26th December 2016
Pozzobon Victor
72
Ex. 6: Tubular reactor – Solver compilation ●
●
Clean the directory and compile: wclean; wmake If you get an error, here is what to do: 1. Read the expection message 2. Get error file and line number
Error file and line number
3. Take care of it
26th December 2016
Pozzobon Victor
73
Ex. 6: Tubular reactor – Case creation ●
●
Now that the solver has been compiled, let's create the case we are going to solve. Since it is a 1D case, copy Ex3 (1D thermal beam) case directory: run cp -r Ex3 Ex6 Go to the case directory, clean it: cd Ex6 foamListTimes -rm
26th December 2016
Pozzobon Victor
74
Ex. 6: Tubular reactor – Mesh creation ●
Create the mesh: gedit system /blockMeshDict
26th December 2016
Pozzobon Victor
75
Ex. 6: Tubular reactor – IC / BC ●
●
Build the mesh: blockMesh Create IC / BC files: mv 0/T 0/p cp 0/p 0/U gedit 0/p 0/U
26th December 2016
Pozzobon Victor
76
Ex. 6: Tubular reactor – IC / BC Pressure field (scalar field)
26th December 2016
Velocity field (vector field)
Pozzobon Victor
77
Ex. 6: Tubular reactor – Physical properties ●
Modify physical properties file: gedit constant/transportProperties
26th December 2016
Pozzobon Victor
78
Ex. 6: Tubular reactor – Numerical schemes ●
Modify numerical schemes in order to specify a steady state resolution: gedit system/fvSchemes
26th December 2016
Pozzobon Victor
79
Ex. 6: Tubular reactor – Solver parameters ●
Modify solver parameters: gedit system/fvSolution
Specify tolerance on pressure equation as single iteration stopping criterion Number of correction iteration (used for non orthogonal meshes) Specify tolerance on pressure equation as simulation stopping criterion
26th December 2016
Pozzobon Victor
80
Ex. 6: Tubular reactor – Control parameters ●
●
Modify solver parameters: gedit system/controlDict In this case, the solver is only calculating a Laplacian operator, Thus, a 10-6 residue is reached quite fast (2 iterations) Changing it is not mandatory
26th December 2016
Pozzobon Victor
81
Ex. 6: Tubular reactor – Run it ●
●
Let's run the case: tubeFoam Process it: paraFoam
26th December 2016
Pozzobon Victor
82
Ex. 7: Tubular reactor – Objectives ●
Create our own solver with more complex equations
●
Use common operators
●
Evolving a case
26th December 2016
Pozzobon Victor
83
Ex. 7: Tubular reactor – Case setup ●
1D tubular reactor with chemical reaction, in transient state A +B=C
dA 2 ⃗ ω=v AB + ∇ .( U A)= D ∇ A−ω dt dB 2 ⃗ ⃗ =0 +∇ .( U B)=D ∇ B−ω ∇ .U dt dC 2 ⃗ + ∇ .( U C)=D ∇ C +ω Symmetry dt planes Inlet
2
∇ p=0 ⃗ = −κ U μ ∇p Outlet
100 cm 26th December 2016
Pozzobon Victor
84
Ex. 7: Tubular reactor – Solver directory creation ●
●
●
●
Reach 'run' directory: run Move to solver directory: cd solvers Copy the existing solver: cp -r tubeFoam tubeChemFoam Move to and clean the directory: cd tubeChemFoam wclean
26th December 2016
Pozzobon Victor
85
Ex. 7: Tubular reactor – Solver modification ●
●
Rename the file: mv tubeFoam.C tubeChemFoam.C Modify compilation file: gedit Make/files
26th December 2016
Pozzobon Victor
86
Ex. 7: Tubular reactor – Solver modification / createFields.H ●
Modify createFields.H to create the species fields: gedit createFields.H
26th December 2016
Pozzobon Victor
Defined in the source code
87
Ex. 7: Tubular reactor – Solver modification / createFields.H ●
Modify createFields.H to read the physical properties: gedit createFields.H
26th December 2016
Pozzobon Victor
88
Ex. 7: Tubular reactor – Solver modification / tubeChemFoam.C ●
Modify tubeChemFoam.C to add species fields: gedit tubeChemFoam.C
Interpolates the velocity field on the mesh in order to later calculate the divergence operator 26th December 2016
Pozzobon Victor
89
Ex. 7: Tubular reactor – Solver compilation / Case creation ●
●
●
Clean the directory and compile: wclean; wmake Move to cases directory: run Copy Ex6 directory: cp -r Ex6 Ex7
●
Move to the case directory: cd Ex7
26th December 2016
Pozzobon Victor
90
Ex. 7: Tubular reactor – Case creation ●
●
●
Clean the directory: foamListTimes -rm Build the mesh: blockMesh Modify physical properties: gedit constant/transportPropeties
26th December 2016
Pozzobon Victor
91
Ex. 7: Tubular reactor – IC / BC ●
●
●
Create file for the species fields: cp 0/p 0/A cp 0/p 0/B cp 0/p 0/C
A field
Keep the existing files for pressure and velocity Modify species files: gedit 0/A gedit 0/B gedit 0/C
26th December 2016
Pozzobon Victor
92
Ex. 7: Tubular reactor – IC / BC B field
26th December 2016
C field
Pozzobon Victor
93
Ex. 7: Tubular reactor – Numerical schemes ●
Set numerical schemes: gedit system/fvSchemes
26th December 2016
Pozzobon Victor
94
Ex. 7: Tubular reactor – Solver parameters ●
●
Add solvers: gedit system/fvSolution Due to the use of the divergence, we need to use asymmetric solvers for the species fields
26th December 2016
Pozzobon Victor
95
Ex. 7: Tubular reactor – Control parameters ●
●
●
Add solvers: gedit system/controlDict Run the case: tubeChemFoam Process it: paraFoam
26th December 2016
Pozzobon Victor
96
Ex. 7: Tubular reactor – Nice pics
26th December 2016
Pozzobon Victor
97
Ex. 8: Heating pipe – Objectives ●
Modify an existing solver
●
Create a variating boundary condition
●
Evolve a case
26th December 2016
Pozzobon Victor
98
Ex. 8: Heating pipe – Case setup ●
Solving incompressible flow in a 2D axisymmetrical pipe with heat transfer , in steady state 10 cm
1 cm
⃗ dU p 2 ⃗ ⃗ ⃗ + U ∇ . U =−∇ ρ +η∇ U dt 26th December 2016
Pozzobon Victor
99
Ex. 8: Heating pipe – Case setup ●
Solving incompressible flow in a 2D axisymmetrical pipe with heat transfer, in steady state dT ⃗ T =−∇ .(−k ∇ T ) ρ Cp +ρ Cp ∇ . U dt T inlet = 20 °C
T surrounding = 80 °C
−k ∇ T . ⃗n =−h(T −T sur ) 26th December 2016
Pozzobon Victor
100
Ex. 8: Heating pipe – Solver creation ●
●
●
●
Reach 'run' directory: run Move to solver directory: cd solvers Copy simpleFoam: cp -r $FOAM_APP/solvers/incompressible/simpleFoam . mv simpleFoam simpleThermFoam Move to the new solver directory: cd simpleThermFoam
26th December 2016
Pozzobon Victor
101
Ex. 8: Heating pipe – Solver creation / modification ●
Clean the directory: rm -r porousSimpleFoam/ SRFSimpleFoam/ simpleFoam.dep
●
●
●
Clean the directory: wclean Rename simpleFoam: mv simpleFoam.C simpleThermFoam.C Change compilation file: gedit Make/files
26th December 2016
Pozzobon Victor
102
Ex. 8: Heating pipe – Solver modification / createFields.H ●
Add temperature field and related physical properties to createFields.H: gedit createFields.H
26th December 2016
Pozzobon Victor
103
Ex. 8: Heating pipe – Solver modification / createFields.H ●
Carry on ...
Loading turbulence model (we do not use it in this case)
Add temperature field 26th December 2016
Pozzobon Victor
104
Ex. 8: Heating pipe – Solver modification / createFields.H ●
Carry on ... Loading transportProperties dictionary
Loading physical values
26th December 2016
Pozzobon Victor
105
Ex. 8: Heating pipe – Solver modification / simpleThermFoam.C ●
Modify solver to add temperature equation: gedit simpleThermFoam.C
26th December 2016
Pozzobon Victor
106
Ex. 8: Heating pipe – Solver compilation / boundary condition ●
●
●
Clean the directory and compile: wclean; wmake Move to cases directory: run Create a directory to store boundary condition: mkdir boundaryConditions
●
Move to this directory: cd boundaryConditions
26th December 2016
Pozzobon Victor
107
Ex. 8: Heating pipe – Create boundary condition ●
●
Copy an existing boundary condition: cp -r $FOAM_SRC/finiteVolume/fields/fvPatchFields/derived/tot alTemperature convectiveHeatFlux Move to the convectiveHeatFlux directory and clean it (if need be): cd convectiveHeatFlux rm totalTemperatureFvPatchScalarField.dep
26th December 2016
Pozzobon Victor
108
Ex. 8: Heating pipe – Modify boundary condition ●
Renane the boundary condition files: mv totalTemperatureFvPatchScalarField.C convectiveHeatFluxFvPatchScalarField.C mv totalTemperatureFvPatchScalarField.H convectiveHeatFluxFvPatchScalarField.H
26th December 2016
Pozzobon Victor
109
Ex. 8: Heating pipe – Compilation rules ●
●
Create Make folder: mkdir Make Create rule files: gedit Make/files Make/options files
options
26th December 2016
Pozzobon Victor
110
Ex. 8: Heating pipe – Modify boundary condition .H file ●
●
Modify convectiveHeatFluxFvPatchScalarField.H: gedit convectiveHeatFluxFvPatchScalarField.H Replace all “totalTemperature” occurences by “convectiveHeatFlux” (consider using ctrl + H)
26th December 2016
Pozzobon Victor
111
Ex. 8: Heating pipe – Modify boundary condition .H file
26th December 2016
Pozzobon Victor
112
Ex. 8: Heating pipe – Modify boundary condition .H file
26th December 2016
Pozzobon Victor
113
Ex. 8: Heating pipe – Modify boundary condition .C file ●
●
●
●
Modify convectiveHeatFluxFvPatchScalarField.C: gedit convectiveHeatFluxFvPatchScalarField.C Replace all “totalTemperature” occurences by “convectiveHeatFlux” (consider using ctrl + H) Change scalar affection to a gradient affectation Set thermal gradient equation
26th December 2016
Pozzobon Victor
114
Ex. 8: Heating pipe – Modify boundary condition .C file
26th December 2016
Pozzobon Victor
115
Ex. 8: Heating pipe – Modify boundary condition .C file
26th December 2016
Pozzobon Victor
116
Ex. 8: Heating pipe – Modify boundary condition .C file
26th December 2016
Pozzobon Victor
117
Ex. 8: Heating pipe – Modify boundary condition .C file
●
Compile the boundary condition: wclean; wmake OR wclean; wmake libso
26th December 2016
Pozzobon Victor
118
Ex. 8: Heating pipe – Create case directory ●
●
Move to cases directory: run Copy Ex5 directory: cp -r Ex5 Ex8
●
Move to the case directory: cd Ex8
26th December 2016
Pozzobon Victor
119
Ex. 8: Heating pipe – Create case directory ●
●
Clean the case directory: foamListTimes -rm Modify physical properties: gedit constant/transportPropeties
26th December 2016
Pozzobon Victor
120
Ex. 8: Heating pipe – IC / BC ●
●
Create temperature field: cp 0/p 0/T Edit the field: gedit 0/T
26th December 2016
Pozzobon Victor
121
Ex. 8: Heating pipe – Solver ●
Pick a solver for the temperature field: gedit system/fvSolution Deliberately high to prevent the problem with the unsolved component of the velocity field (cf. Ex 4)
26th December 2016
Pozzobon Victor
122
Ex. 8: Heating pipe – Schemes ●
●
Choose numerical scheme for temperature divergence: gedit system/fvSchemes Keep the default Laplacian scheme
26th December 2016
Pozzobon Victor
123
Ex. 8: Heating pipe – Specify library use ●
●
Modify controlDict to specify the use of convectiveHeatFlux boundary condition: gedit system/controlDict 1000 iterations maximum should be enough (mine converged after 402 iterations)
26th December 2016
Pozzobon Victor
124
Ex. 8: Heating pipe – Run the case ●
●
●
Create the mesh: blockMesh Run the case: simpleThermFoam Open paraFoam: paraFoam
26th December 2016
Pozzobon Victor
125
Ex. 8: Heating pipe – Process the case ●
Have a look at the temperature field:
26th December 2016
Pozzobon Victor
126
Ex. 9: Cake baking – Objectives ●
Modify an existing solver
●
Set a field that depend on another field
●
Set custom field
●
Use an existing case as initial condition
●
We are going to simulate the backing of a cake: - heating up with chocolate melting (20 min, 180°C) - cooling down with chocolate solidification (1 hour)
26th December 2016
Pozzobon Victor
127
Ex. 9: Cake baking – Case setup ●
2D cake backing, with chocolate phase change dT ρ Cp =−∇ .(−k ∇ T )+Q dt −Ea dC −Ea T RT =− A 1 e C + A2 e LC dt −Ea d LC −Ea T =−A 2 e LC + A 1 e RT C dt 1
2
1
1 dC dLC Q= ( − )Δ H 2 dt dt T surrounding = 180 °C
−k ∇ T . ⃗n =−h(T −T sur )
2
Chocolate 26th December 2016
Pozzobon Victor
128
Ex. 9: Cake baking – Solver directory creation ●
●
●
●
Reach 'run' directory: run Move to solver directory: cd solvers Copy the existing solver: cp -r tubeFoam cakeFoam Move to and clean the directory: cd cakeFoam wclean
26th December 2016
Pozzobon Victor
129
Ex. 9: Cake baking – Set compilation rules ●
●
Rename tubeFoam: mv tubeFoam.C cakeFoam.C Change compilation file: gedit Make/files
26th December 2016
Pozzobon Victor
130
Ex. 9: Cake baking – Modiy createFields.H ●
Modify fields and physical properties: gedit createFields.H
26th December 2016
Pozzobon Victor
131
Ex. 9: Cake baking – Modiy createFields.H
26th December 2016
Pozzobon Victor
132
Ex. 9: Cake baking – Modify the solver ●
Rename tubeFoam: gedit cakeFoam.C
26th December 2016
Pozzobon Victor
133
Ex. 9: Cake baking – Compile the solver / create case ●
●
●
●
Compile the solver: wclean; wmake Move to 'run': run Create the case directory: cp -r Ex4 Ex9 Move to the case directory: cd Ex9
26th December 2016
Pozzobon Victor
134
Ex. 9: Cake baking – Prepare case ●
●
Clean the case: foamListTimes -rm rm 0/U Create fields files: cp 0/p 0/C cp 0/p 0/LC mv 0/p 0/T
26th December 2016
Pozzobon Victor
135
Ex. 9: Cake baking – Create mesh ●
Boundary name and location: Top
Left Down
26th December 2016
Pozzobon Victor
Right SymmetryWall 136
Ex. 9: Cake baking – Create mesh ●
Modify the mesh: gedit system/blochMeshDict
26th December 2016
Pozzobon Victor
137
Ex. 9: Cake baking – IC / BC ●
Modify the mesh: gedit 0/T
26th December 2016
Pozzobon Victor
138
Ex. 9: Cake baking – IC / BC ●
Modify the mesh: gedit 0/C
26th December 2016
Pozzobon Victor
139
Ex. 9: Cake baking – IC / BC ●
Modify the mesh: gedit 0/LC
26th December 2016
Pozzobon Victor
140
Ex. 9: Cake baking – Chocolate ●
We have to specify the position of every chocolate chip. In this case, only three pieces will be set. First, copy an existing dictionary: cp $FOAM_TUTORIALS/multiphase/interFoam/ras/damBrea k/system/setFieldsDict system/.
26th December 2016
Pozzobon Victor
141
Ex. 9: Cake baking – Chocolate ●
Set the chips location and shape: gedit system/setFieldsDict
26th December 2016
Pozzobon Victor
142
Ex. 9: Cake baking – Set properties for the heating phase ●
●
Set the physical properties for the heating phase Chocolate solidification parameter are set to 0: gedit constant/transportProperties
26th December 2016
Pozzobon Victor
143
Ex. 9: Cake baking – Set properties for the heating phase ●
Set the case to transient and specify solver features: gedit system/fvSchemes gedit system/fvSolution
26th December 2016
Pozzobon Victor
144
Ex. 9: Cake baking – Set control parameters ●
The heating phase lasts 20 min (1800 s): gedit system/controlDict
26th December 2016
Pozzobon Victor
145
Ex. 9: Cake baking – Run the case ●
●
●
Create the mesh: blockMesh Set chocolate field: setFields Solve the case: cakeFoam
26th December 2016
Pozzobon Victor
146
Ex. 9: Cake baking – Modify the case ●
●
Now that the heating phase has been run, modify physical properties value: gedit constant/transportProperties This time, chocolate melting is disabled and chocolate solidification is enabled
26th December 2016
Pozzobon Victor
147
Ex. 9: Cake baking – Reset control parameters ●
The cooling phase lasts 60 min (3600 s): gedit system/controlDict The last iteration will be used as initialization
26th December 2016
Pozzobon Victor
148
Ex. 9: Cake baking – Rerun the case ●
●
Solve the last part of the case: cakeFoam Process the case: paraFoam
26th December 2016
Pozzobon Victor
149
Ex. 9: Cake baking – Process the case Temperature during the cooldown
Chocolate chips location
26th December 2016
Pozzobon Victor
150
Ex. 10: Tank filling - Objectives ●
This case is really basic. Its purpose is only to discuss topics that were left uncovered
●
Import a mesh created with an external tool
●
Run a case in parallel
●
Exporting an animation
26th December 2016
Pozzobon Victor
151
Ex. 10: Tank filling – Case setup ●
Transient filling of a tank. Initially, it is full of air, then, we are going to fill it using the two phases flow solver interFoam Air outlet
Water inlet
Tank walls
26th December 2016
Pozzobon Victor
152
Ex. 10: Tank filling – A new case ●
●
●
Go to your 'run' directory: run Copy 'damBreak': cp -r $FOAM_TUTORIALS/multiphase/interFoam/laminar/dam Break/damBreak/ Ex10 Move to the case directory: cd Ex10
26th December 2016
Pozzobon Victor
153
Ex. 10: Tank filling – Importing the mesh ●
●
●
The mesh is called 'Tank.unv'. It was drawn using salome. It should have already been provided to you, if this is not the case, you can find it here: http://perso.mines-albi.fr/~vpozzobo/dl/Tank.unv Move the mesh file to the case directory: mv 'somewhere'/Tank.unv Ex10/. Import the mesh: ideasUnvToFoam Tank.unv
26th December 2016
Pozzobon Victor
154
Ex. 10: Tank filling – Importing the mesh ●
●
There is no need to build the mesh using blockMesh, is has already been done when importing it. Yet, it has to be resized: atmosphere transformPoints -scale '(0.001 0.001 0.001)' You can check the mesh using paraFoam: paraFoam
inlet fixedWalls
26th December 2016
Pozzobon Victor
155
Ex. 10: Tank filling – IC / BC ●
Modify velocity boundary conditions according to the case setup: gedit 0/U
Negative because of axis orientation 26th December 2016
Pozzobon Victor
156
Ex. 10: Tank filling – IC / BC ●
Modify the pressure boundary conditions: gedit 0/p_rgh
26th December 2016
Pozzobon Victor
157
Ex. 10: Tank filling – IC / BC ●
●
●
Copy the water phase file: cp 0/alpha.water.org 0/alpha.water Keep the '.org' file. It is used as a backup in case you would have modified the initial condition using setFields To prevent any problem, move the '.org' file to the case root mv 0/alpha.water.org .
26th December 2016
Pozzobon Victor
158
Ex. 10: Tank filling – IC / BC ●
Modify the water boundary conditions: gedit 0/alpha.water
26th December 2016
Pozzobon Victor
159
Ex. 10: Tank filling – Setting gravity ●
Modify gravity orientation, so that the tank will be vertical: gedit constant/g
Negative because of axis orientation 26th December 2016
Pozzobon Victor
160
Ex. 10: Tank filling – Running parallel ●
●
OpenFOAM runs in parallel using a decomposition of mesh and fields. You can specify the cut yourself or ask scotch to do it for you (our call here). As a good rule of thumb, each processor should at least have 30000 cells to compute, if you want to see an increase in computational speed. Copy the decomposition dictionary from an existing case: cp $FOAM_TUTORIALS/multiphase/interDyMFoam/ras/damBreakWithO bstacle/system/decomposeParDict system/.
26th December 2016
Pozzobon Victor
161
Ex. 10: Tank filling – Running parallel ●
●
Modify the decomposition dictionary: gedit system/decomposeParDict Once it is done, decompose the case: decomposePar
Number of processors that are going to be used
26th December 2016
Pozzobon Victor
162
Ex. 10: Tank filling – Control values ●
●
Open case control file: gedit system/controlDict The tank takes about 40s to fill up, which represented a cpu time of 2 days for me. So set endTime according to your liking. I would advice 0.30s. It still requires 30 minutes to run
26th December 2016
Pozzobon Victor
163
Ex. 10: Tank filling – Control values ●
Note that interFoam uses an adaptive time step
Maximum Courant number Maximum time step (in second)
26th December 2016
Pozzobon Victor
164
Ex. 10: Tank filling – Run the case ●
The mesh has already been built. The case has been split between processors, so let's run the case: mpirun -np 2 interFoam
Number of processors you want to use (has to be in agreement with decomposeParDict)
26th December 2016
Pozzobon Victor
165
Ex. 10: Tank filling – Post processing the case ●
●
The case can then be processed. First, create a new directory to store the pictures that we will use to build the animation: mkdir Extraction Then launch the post processor: paraFoam
26th December 2016
Pozzobon Victor
166
Ex. 10: Tank filling – Postprocessing ●
●
●
Load all the fields, then set opacity of the base filter to 0.1: Ex10.OpenFOAM / Style / Opacity Add a contour filter, on alpha.water field, with a threshold of 0.1: Filters / Common / Contour Change the background color to white: Edit / View Settings ... / Choose color
26th December 2016
Pozzobon Victor
167
Ex. 10: Tank filling – Postprocessing ●
Set the camera angle to your liking by using the mouse or the 'Adjust Camera' tool:
Adjust Camera button
26th December 2016
Pozzobon Victor
168
Ex. 10: Tank filling – Postprocessing ●
●
●
●
Save the individual picture: File / Save Animation ... Click 'Save Animation' on the prompted form (the settings do not matter here) Pick 'Extraction' folder and choose a name for the pictures (I chose 'Water') Now paraFoam is filling 'Extraction' directory with frames of the animation
26th December 2016
Pozzobon Victor
169
Ex. 10: Tank filling – Postprocessing ●
●
Close paraFoam and go 'Extraction' folder: cd Extraction Create your .gif file: convert -delay 10 -loop 0 Water.*.png Your.gif Time between two frames in milliseconds
26th December 2016
Pozzobon Victor
170
It's over ●
This tutorial is over, thank you for your attention
●
I hope you enjoyed it
●
●
It was just a brief and partial overview of OpenFOAM possibilities Please feel free to contact me:
[email protected]
26th December 2016
Pozzobon Victor
171
The extra mile ●
●
●
The open source software, I use to draw and mesh complex geometries: SALOME: www.salome-platform.org Another open source software which can be used to process high volume results: VisIt: https://visit.llnl.gov Where I ask for help: CFD Online: www.cfd-online.com/Forums/openfoam
26th December 2016
Pozzobon Victor
172
It's over
Again, thank you for your attention.
26th December 2016
Pozzobon Victor
173