introduction to computational fluid dynamics with n europea feder 0682_cloudpyme2_1_e invertimos en...
TRANSCRIPT
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Introduction to Computational
Fluid Dynamics with OpenFOAM
C. Fernandes, L.L. Ferrás, J.M. Nóbrega Institute for Polymers and Composites (i3N), University of Minho
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Schedule Day 1 Day 2 Day 3
9h-13h
Introduction Introduction to OpenFOAM
A simple 1D problem – heat transfer(a)
Introduction to blockMesh
checkMesh utility
Monitoring the residuals evolution
with gnuplot
Problems lid-driven cavity
Mesh generation with blockMesh
How to use the sample utility
Comparison of the results obtained
with the literature (artigo Ghia et
al.)
Mesh refinement study
Hands-on(b)
13h-14h Lunch
14h-18h
Tutorials, post-processing and
parallelization OpenFOAM tutorials
Post-processing with paraview
Parallel computations
Utilities (patchIntegrate,
patchAverage)
Programming a solver Programming a solver for the
temperature distribution
Mesh generation with blockMesh,
and, verification with checkMesh
Mixing materials at different
temperatures
Hands-on(b)
The theoretical sessions will be complemented with practical examples. (a) This introductory problems will allow the introduction of simple (but essential) concepts like the math behind OpenFOAM, such as the discretization of the
equations, systems of equations, residual control. (b) Hands-on each individual will try to implement and solve with OpenFOAM, a problem of interest.
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
What is OpenFOAM (open Field Operation and Manipulation)?
OpenFOAM is a powerful tool that allows the numerical solution of differential equations (usually found in continuum mechanics).
Physical phenomena
Physical phenomena described by a mathematical model (differential equation).
Prediction of the evolution of physical phenomena by numerical solution of the differential equations.
Monday Tuesday Wednesday
OpenFOAM Scientists
pt
uτuu
Mathematical Model Numerical Solution
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
https://www.ipma.pt/
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
• OpenFOAM is an open source C++ library, used primarily to create
executables, known as applications. The applications fall into two categories:
solvers, that are each designed to solve a specific problem in continuum
mechanics; and utilities, that are designed to perform tasks that involve data
manipulation.
• New solvers and utilities can be created by its users with some pre-requisite
knowledge of the underlying method, physics and programming techniques
involved.
What is OpenFOAM (open Field Operation and Manipulation)?
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
• The discretization of the equation is based on the Finite Volume Method;
• Collocated polyhedral unstructured meshes;
• It uses second order schemes for the approximation of the different operators, but,
many schemes are available, including high order schemes;
• Parallel computation are easy to perform (reduction of the computational time);
• You can create simple meshes with the mesh generator that comes with OpenFOAM.
Also, you can convert to the OpenFOAM format, meshes created with another
software (check the user guide for the available formats);
• It comes with several utilities;
• All components implemented in library form for easy re-use.
What is OpenFOAM (open Field Operation and Manipulation)?
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
‘Basic’ CFD codes
laplacianFoam Solves a simple Laplace equation, e.g. for thermal diffusion in a solid;
potentialFoam Simple potential flow solver which can be used to generate starting
fields for full Navier-Stokes codes;
scalarTransportFoam Solves a transport equation for a passive scalar
What is OpenFOAM (open Field Operation and Manipulation)?
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Incompressible flow
Compressible flow
Multiphase flow
Combustion
DNS and LES
Particle-tracking flows
Heat transfer
…
What is OpenFOAM (open Field Operation and Manipulation)?
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
• Users can change the existing solvers, and, use them as the
start point for the creation of a new solver.
• The complete source of the code is available!
• Users can write a complex solver with only few lines.
What is OpenFOAM (open Field Operation and Manipulation)?
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Simulations with OpenFOAM
https://www.youtube.com/watch?v=1PHvJMy45rE&list=PL6BfJWHH53_pLUOzU8uuzXgvrhR6uBAR6
Multiphase flow based on OpenFOAM's volume of fluid method, simulation performed by DHCAE Tools GmbH. For more information, please contact [email protected]
https://www.youtube.com/watch?v=SCQL57wHVq4&index=4&list=PL6BfJWHH53_pNtHuG0JAEGsW7WzteQbsL
CFD simulation of a supersonic jet occuring in a direct injection combustion engine. Computation has been done with OpenFoam at GDTech in Belgium. LES turbulence model has been used.
https://www.youtube.com/watch?v=D6iuVr9V6os
2D CFD simulation of a bullet at Mach number 1.6 done with OpenFoam. GDTech – Belgium. https://www.youtube.com/watch?v=Q6XyTrhaGxc&list=PL6BfJWHH53_pNtHuG0JAEGsW7WzteQbsL&index=6 Multiphase Flow Simulation of Vertical Slot Fishway performed with HELYX® https://www.youtube.com/watch?v=OH0l5CkY_aY
CFD analysis of a planing hull in OpenFOAM. TotalSim.
https://www.youtube.com/watch?v=Ky7Ksdf9ihs
Floating wind turbine platform
https://www.youtube.com/watch?v=UiuX7IwJ3tA&index=31&list=PL6BfJWHH53_pq7o-VCQvBdyDu3yUq7YoT
Flow on the Sharp-Crested Rectangular Weir
https://www.youtube.com/watch?v=FhkGIa8J9b0
Tanker aerodynamics - MkI
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Equation mimicking in OpenFOAM
The equation,
can be written in OpenFOAM as follows,
pt
u uu
solve ( fvm::ddt(rho,U) + fvm::div(phi,U) - fvm::laplacian(mu,U) == - fvc::grad(p) );
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Different versions of OpenFOAM
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
http://openfoamwiki.net/index.php/Forks_and_Variants
Forks • Caelus-CML
• ENGYS' own builds of
OpenFOAM
• foam-extend
• FreeFOAM
• iconCFD
• RapidCFD
Different versions of OpenFOAM
Variants • Windows
• Mac
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Different versions of OpenFOAM
Old Versions of OpenFOAM Version 2.3.0 download Version 2.2.2 download Version 2.2.1 download Version 2.2.0 download . . . Copyright © 2011-2015 OpenFOAM Foundation | OPENFOAM and OpenCFD are registered trademarks of OpenCFD Ltd.
The OpenFOAM Foundation
OpenFOAM Foundation releases OpenFOAM® 2.3.1 10th December 2014
http://www.openfoam.org/
The OpenFOAM® Extend Project
foam-extend-3.1 "Zagreb" is released The Extend Project is proud to announce the next release of the community fork of OpenFOAM®: foam-extend-3.1
http://www.extend-project.de/
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
https://openfoamwiki.net/index.php/Installation
2 Installing OpenFOAM
This is the tree of the categories and respective sub-
categories about installing OpenFOAM: [+] Installing
OpenFOAM on Linux
[+] Installing OpenFOAM on Mac OS
[+] Installing OpenFOAM on Windows
Installation
Installation/Linux
Installation/Mac OS
Installation/Windows
Is this Wiki affiliated with OpenCFD/ESI ? No. This Wiki is a community effort. Its aim is to give people a place where they can collect/publish information about OpenFOAM and related projects.
Different versions of OpenFOAM
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Structure of OpenFOAM
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Structure of OpenFOAM
The OpenFOAM source code comprises of four main components:
src: the core OpenFOAM source code;
applications: collections of library functionality wrapped up into applications, such as
solvers and utilities;
tutorials: a suite of test cases that highlight a broad cross-section of OpenFOAM's
capabilities;
doc: supporting documentation.
»cd $FOAM_INST_DIR
applications
src
tutorials
doc
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Structure of OpenFOAM
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Case directory in OpenFOAM
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Copy the folders basicTut and applications to
your personal area:
(/home/cesga/cursos/SHARED/basicTut)
(/home/cesga/cursos/SHARED/applications)
(cursos/curso???/OpenFOAM/curso???/basicTut)
(cursos/curso???/OpenFOAM/curso???/applications)
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Solvers?
fvSchemes?
polyMesh?
Q: How to understand and get acquainted with all these concepts?
….
A: Lets take a look at a simple 1D problem – heat transfer
Also…
http://www.openfoam.com/ http://openfoamwiki.net/index.php/Main_Page http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2009/ http://sourceforge.net/projects/openfoam-extend/ http://www.openfoamworkshop.org/ OpenFOAM user guide!
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Simple 1D Problem – heat transfer
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Heat conduction in a large plate, thickness L=2 cm, thermal conductivity k= 0.5 W/mK, uniform internal heat generation q=1000 W/m3. Faces A and B are kept at a constant temperature.
A B
200ºBT C
100ºAT C
L x
y
z
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Heat conduction in a large plate, thickness L=2 cm, thermal conductivity k= 0.5 W/mK, uniform internal heat generation q=1E6 W/m3. Faces A and B are kept at a constant temperature.
Physical phenomena
OpenFOAM Scientists
Mathematical Model Numerical Solution
0d dT
k qdx dxA
B 200ºBT C
100ºAT C
L
??!!!T
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
0d dT
k qdx dx
:
2
B A
A
Analytical solution
T T qT L x x T
L k
For this particular case we know the exact solution, meaning that, we know
how temperature varies from A to B.
OpenFOAM does not know that!!!
So, I want the numerical solution for this equation!
How does OpenFOAM operates?!
Theory:
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
0d dT
k dx q dxdx dx
OpenFOAM uses the integral version of governing equations.
Then, Gauss theorem is used to reduce the domain of integration
by one dimension
Theory:
I do not remember Gauss theorem …
Well, in 1D, Gauss theorem is equivalent to the Fundamental theorem of Calculus
'( ) ( ) ( )b
aF x dx F b F a
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Fundamental theorem of Calculus (FTC)
'( ) ( ) ( )b
aF x dx F b F a
0b b
a a
d dTk dx q dx
dx dx
b a
dT dTk k
dx dx
1b
aq dx
( )q b a
( ) 0b a
dT dTk k q b a
dx dx
(FTC)
a b
Theory:
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
A B
200ºBT C
100ºAT C
L
Theory: creating the mesh
AT
BT1 2 3 4 5
0e w
dT dTk k q x
dx dxwest
(w)
east
(e)
x
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
A B
200ºBT C
100ºAT C
L
AT
BT1 2 3 4 5
0e w
dT dTk k q x
dx dxwest
(w)
east
(e)
xTheory: creating the mesh
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
A B
200ºBT C
100ºAT C
L
AT
BT1 2 3 4 5
0e w
dT dTk k q x
dx dxwest
(w)
east
(e)
xTheory: creating the mesh
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
A B
200ºBT C
100ºAT C
L
AT
BT1 2 3 4 5
0e w
dT dTk k q x
dx dxwest
(w)
east
(e)
xTheory: creating the mesh
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
A B
200ºBT C
100ºAT C
L
AT
BT1 2 3 4 5
0e w
dT dTk k q x
dx dx
x2x 2x
west
(w)
east
(e)
xTheory: creating the mesh
0 cell1e w
dT dTk k q x
dx dx
0 cell5e w
dT dTk k q x
dx dx
0 cell4e w
dT dTk k q x
dx dx
0 cell2e w
dT dTk k q x
dx dx
0 cell3e w
dT dTk k q x
dx dxSystem of 5
equations
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
AT
BT1 2 3 4 5
How to
approximate the
derivatives?
How to define the
mesh in
OpenFOAM?
0 cell1e w
dT dTk k q x
dx dx
0 cell5e w
dT dTk k q x
dx dx
0 cell4e w
dT dTk k q x
dx dx
0 cell2e w
dT dTk k q x
dx dx
0 cell3e w
dT dTk k q x
dx dxSystem of 5
equations
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to
approximate the
derivatives?
( )f a
a b
( )f b
'( ) ?f c
c
( ) ( )'( )
f b f af c
b a
2 1 1 0 cell1/ 2
AT T T Tk k q x
x x
5 5 4 0 cell5/ 2
BT T T Tk k q x
x x
5 4 4 3 0 cell 4T T T T
k k q xx x
3 2 2 1 0 cell 2T T T T
k k q xx x
4 3 3 2 0 cell3T T T T
k k q xx x
System of linear equations
2 1
e
T TdTk k
dx x
AT 1 2 3
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to
approximate the
derivatives?
( )f a
a b
( )f b
'( ) ?f c
c
( ) ( )'( )
f b f af c
b a
Is this the only possible
approximation for the derivative?
No!!!
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to
approximate the
derivatives?
( )f a
a b
( )f b
'( ) ?f c
c
( ) ( )'( )
f b f af c
b a
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM Extend Project: Open Source CFD | | \\ / O peration | Version: 1.6-ext | | \\ / A nd | Web: www.extend-project.de | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; object fvSchemes; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ddtSchemes { default Euler; } gradSchemes { default Gauss linear; grad(p) Gauss linear; grad(U) Gauss linear; } divSchemes { default none; div(phi,U) Gauss upwind; div(phi,C) Gauss Gamma01 0.8; } laplacianSchemes { default none; laplacian(etaPEff,U) Gauss linear corrected; laplacian(etaPEff+etaS,U) Gauss linear corrected; laplacian((1|A(U)),p) Gauss linear corrected; } interpolationSchemes { default linear; interpolate(HbyA) linear; } snGradSchemes { default corrected; } fluxRequired { default no; p; }
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
fvSchemes
Remember…
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to
approximate the
derivatives?
( )f a
a b
( )f b
'( ) ?f c
c
( ) ( )'( )
f b f af c
b a
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM Extend Project: Open Source CFD | | \\ / O peration | Version: 1.6-ext | | \\ / A nd | Web: www.extend-project.de | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; object fvSchemes; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
fvSchemes
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to
approximate the
derivatives?
( )f a
a b
( )f b
'( ) ?f c
c
( ) ( )'( )
f b f af c
b a
ddtSchemes { default Euler; } gradSchemes { default Gauss linear; grad(p) Gauss linear; grad(U) Gauss linear; } divSchemes { default none; div(phi,U) Gauss upwind; div(phi,C) Gauss Gamma01 0.8; } laplacianSchemes { default none; laplacian(etaPEff,U) Gauss linear corrected; laplacian(etaPEff+etaS,U) Gauss linear corrected; laplacian((1|A(U)),p) Gauss linear corrected;
fvSchemes
t
u
p
uu
k T
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to
approximate the
derivatives?
( )f a
a b
( )f b
'( ) ?f c
c
( ) ( )'( )
f b f af c
b a
interpolationSchemes { default linear; interpolate(HbyA) linear; } snGradSchemes { default corrected; } fluxRequired { default no; p; }
fvSchemes
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
AT
BT1 2 3 4 5
How to
approximate the
derivatives?
How to define the
mesh in
OpenFOAM?
0 cell1e w
dT dTk k q x
dx dx
0 cell5e w
dT dTk k q x
dx dx
0 cell4e w
dT dTk k q x
dx dx
0 cell2e w
dT dTk k q x
dx dx
0 cell3e w
dT dTk k q x
dx dxSystem of 5
equations
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to define the
mesh in
OpenFOAM?
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
blockMeshDict convertToMeters 1; vertices ( (0 0 0) (1 0 0) (1 1 0) (0 1 0) (0 0 0.1) (1 0 0.1) (1 1 0.1) (0 1 0.1) );
blocks (hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1);
edges ( );
boundary ( tempA { type inlet; faces ( (4 7 3 0) ); } tempB { type outlet; faces ( (1 2 6 5) ); } frontAndBack { type empty; faces ( (0 3 2 1) (4 5 6 7) (2 3 7 6) (0 1 5 4) ); } );
0 1
23
4 5
67
x
y
z
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to define the
mesh in
OpenFOAM?
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
blockMeshDict convertToMeters 1; vertices ( (0 0 0) (1 0 0) (1 1 0) (0 1 0) (0 0 0.1) (1 0 0.1) (1 1 0.1) (0 1 0.1) ); blocks (hex (0 1 2 3 4 5 6 7) (5 1 1) simpleGrading (1 1 1);
0 1
23
4 5
67
x
y
z
//0 //1 //2 //3 //4 //5
//6 //7
AT
BT1 2 3 4 5
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to define the
mesh in
OpenFOAM?
blockMeshDict convertToMeters 1; vertices ( (0 0 0) (0.02 0 0) (0.01 0.001 0) (0 0.001 0) (0 0 0.001) (0.02 0 0.001) (0.01 0.001 0.001) (0 0.001 0.001) );
0 1
23
4 5
67
x
y
z
//0 //1 //2 //3 //4 //5
//6 //7 A
TB
T1 2 3 4 5
0 1
23
4 5
67
x
y
z
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to define the
mesh in
OpenFOAM?
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
blockMeshDict boundary ( tempA { type inlet; faces ( (4 7 3 0) ); } tempB { type outlet; faces ( (1 2 6 5) ); } frontAndBack { type empty; faces ( (0 3 2 1) (4 5 6 7) (2 3 7 6) (0 1 5 4) ); } );
0 1
23
4 5
67
x
y
z
0 4
73
y
z
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How to define the
mesh in
OpenFOAM?
blockMeshDict boundary ( tempA { type patch; faces ( (4 7 3 0) ); } tempB { type patch; faces ( (1 2 6 5) ); } frontAndBack { type empty; faces ( (0 3 2 1) (4 5 6 7) (2 3 7 6) (0 1 5 4) ); } );
0 4
73
y
z
0 1
23
4 5
67
x
y
z
tem
pA
tem
pB
All other boundaries are
empty!!! Why??!
1D
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Boundary
conditions?
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
0 folder
T
T dimensions [0 0 0 1 0 0 0]; internalField uniform 0; boundaryField { tempA { type fixedValue; value uniform 100; } tempB { type fixedValue; value uniform 200; } frontAndBack { type empty; } }
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Boundary
conditions?
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
0 folder
T
T dimensions [0 0 0 1 0 0 0];
No. Property SI unit
1 Mass kilogram (kg)
2 Length metre (m)
3 Time second (s)
4 Temperature Kelvin (K) )
5 Quantity mole (mol)
6 Current ampere (A)
7 Luminous intensity candela (cd)
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Boundary
conditions?
T dimensions [0 0 0 1 0 0 0]; internalField uniform 0; boundaryField { tempA { type fixedValue; value uniform 100; } tempB { type fixedValue; value uniform 200; } frontAndBack { type empty; } }
0 1
23
4 5
67
x
y
z
tem
pA
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Boundary
conditions?
T dimensions [0 0 0 1 0 0 0]; internalField uniform 0; boundaryField { tempA { type fixedValue; value uniform 100; } tempB { type fixedValue; value uniform 200; } frontAndBack { type empty; } }
0 1
23
4 5
67
x
y
z
tem
pB
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Where were we?
2 1 1 0/ 2
A
e w
T T T Tk k q x
x x
5 5 4 0/ 2
B
e w
T T T Tk k q x
x x
5 4 4 3 0e w
T T T Tk k q x
x x
3 2 2 1 0e w
T T T Tk k q x
x x
4 3 3 2 0e w
T T T Tk k q x
x x
We want to solve this system
of linear equations
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How can we solve the
system of equations?
a) Just guess a solution!?
b) Solve with paper & pencil!?
c) Compute the solution directly!?
d) Compute the solution using an iterative procedure!?
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How can we solve the
system of equations?
a) Just guess a solution!?
b) Solve with paper & pencil!?
c) Compute the solution directly!?
d) Compute the solution using an iterative procedure!?
It works for this case!!!
1
2
3
4
5
110
130
150
170
190
T
T
T
T
T
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
How can we solve the
system of equations?
c) Compute the solution directly!?
d) Compute the solution using an iterative procedure!?
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Solution by Cramer's Rule
Compute the solution directly
This method is rather inefficient and relatively difficult
to program!
Requires at least 3n3 operations!!!
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Compute the solution using an
iterative procedure
This methods are more efficient and provide answers
to a linear system of equations in considerably fewer
steps, but at a level of accuracy that will depend on the
number of times the algorithm is applied
Requires O(n2) 0perations for each
iteration
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Compute the solution using an
iterative procedure
For large systems of equations is
better to use iterative methods!!!
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Compute the solution using an
iterative procedure
0T
1T2T
final solution
0
0
0
0
0
0
T1T
Compute
the new
solution
2T
Compute
the new
solution
3T
Compute
the new
solution
4T
Compute
the new
solution
5T
Compute
the new
solution
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Compute the solution using an
iterative procedure
PCG (preconditioned conjugate gradient method)
The CG method reaches the exact solution of Ax=b in at
most n steps for any initial guess!
1
2
3
4
5
4 250375 125 0 0 0
4125 250 125 0 0
40 125 250 125 0
40 0 125 250 125
4 2500 0 0 125 375
A
B
T T
T
T
T
T T
A T B
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
fvSolution object fvSolution; } // * * * * * * * * * * * * * * * * * * // solvers { T { solver PCG; preconditioner DIC tolerance 1e-07; relTol 0; } } SIMPLE { nNonOrthogonalCorrectors 2; }
iterative method
Depending on the structure of your matrix,
this will allow a reduction on the number of iterations
Tolerance for stopping the iterative procedure
0r AT B
0
0
0
0
0
0
T1T
2T 3T4T 5T
3 1 8 1 7r e eAT B
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
fvSolution object fvSolution; } // * * * * * * * * * * * * * * * * * * // solvers { T { solver PCG; preconditioner DIC tolerance 1e-07; relTol 0.1; } } SIMPLE { nNonOrthogonalCorrectors 2; }
iterative method
Depending on the structure of your matrix,
this will allow a reduction on the number of iterations
Tolerance for stopping the iterative procedure
0 0.55r AT B
0
0
0
0
0
0
T1T
2T 3T4T 5T
3 0.032r AT B
relTol is the relative tolerance between the initial
and the final residual
0.1 0.55 0.05
0.032 0 055
5
.
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
fvSolution
BiCGStab: Solving for T, Initial residual = 0.584235, Final residual = 1.0582e-07, No Iterations 3
0r AT B finalr AT B
Terminal:
PCG
solver number of
iterations
In OpenFOAM all residuals are normalized:
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Confused?
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
We want to solve the differential
equation 0
d dTk q
dx dx
Create the mesh
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
Define the approximations
for the operators
Define how to solve
the system of equations
Define boundary
conditions
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
controlDict transportProperties
application laplacianFoamTemp;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 1;
deltaT 1;
writeControl adjustableRunTime;
writeInterval 1;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression uncompressed;
timeFormat general;
timePrecision 6;
graphFormat raw;
runTimeModifiable yes;
adjustTimeStep on;
maxCo 0.8;
maxDeltaT 0.001;
DT DT [ 1 1 -3 -1 0 0 0 ] 0.5;
q q [ 1 -1 -3 0 0 0 0 ] 1000;
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
What to do next?
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Copy the folders basicTut and applications to
your personal area:
(/home/cesga/cursos/SHARED/basicTut)
(/home/cesga/cursos/SHARED/applications)
(cursos/curso???/OpenFOAM/curso???/basicTut)
(cursos/curso???/OpenFOAM/curso???/applications)
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
»cd $WM_PROJECT_USER_DIR
»cd applications
»cd laplacianFoamTemp
»wclean
»wmake
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
»cd $WM_PROJECT_USER_DIR
»cd basicTut
»cd laplacianFoamTemp
»blockMesh
»checkMesh
»laplacianFoamTemp
»paraFoam
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
463.1
450
435
420
405
390
383.1
T [ºC]
100
200
190.04
110.04
130.088 150.104
170.088
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
0
50
100
150
200
250
0 0.005 0.01 0.015 0.02
analytical solution
numerical solution (OpenFOAM)
T [
ºC]
x [m]
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
It is time for you to
do it by yourselves!!
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Consider the same problem with q=1E6 W/m3 use only 4 cells!!! Remember that L=0.02 m k= 0.5 W/mK
A B
200ºBT C
100ºAT C
L
0
50
100
150
200
250
300
0 0.005 0.01 0.015 0.02
analytical solution
T [
ºC]
x [m]
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
blockMeshDict
convertToMeters 1; vertices ( (0 0 0) (0.02 0 0) (0.01 0.001 0) (0 0.001 0) (0 0 0.001) (0.02 0 0.001) (0.01 0.001 0.001) (0 0.001 0.001) ); blocks (hex (0 1 2 3 4 5 6 7) (4 1 1) simpleGrading (1 1 1);
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
blockMeshDict boundary ( tempA { type patch; faces ( (4 7 3 0) ); } tempB { type patch; faces ( (1 2 6 5) ); } frontAndBack { type empty; faces ( (0 3 2 1) (4 5 6 7) (2 3 7 6) (0 1 5 4) ); } );
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
fvSchemes
No need to change (for this case)
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
fvSolution
object fvSolution; } // * * * * * * * * * * * * * * * * * * // solvers { T { solver PCG; preconditioner DIC tolerance 1e-07; relTol 0; } } SIMPLE { nNonOrthogonalCorrectors 0; }
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
T
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
dimensions [0 0 0 1 0 0 0]; internalField uniform 0; boundaryField { tempA { type fixedValue; value uniform 100; } tempB { type fixedValue; value uniform 200; } frontAndBack { type empty; } }
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
transportProperties
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
application laplacianFoamTemp;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 1;
deltaT 1;
writeControl adjustableRunTime;
writeInterval 1;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression uncompressed;
timeFormat general;
timePrecision 6;
graphFormat raw;
runTimeModifiable yes;
adjustTimeStep on;
maxCo 0.8;
maxDeltaT 0.001;
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
transportProperties
DT DT [ 1 1 -3 -1 0 0 0 ] 0.5;
q q [ 1 -1 -3 0 0 0 0 ] 1 000 000;
system
constant
0
0.1
….
0.1
fvSchemes
fvSolution
controlDict
time directories
… Properties
neighbour
boundary
owner
polyMesh
faces
points
blockMeshDict
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
0
50
100
150
200
250
300
0 0.005 0.01 0.015 0.02
analytical solution
numerical solution (OpenFOAM)
T [
ºC]
x [m]
Why the
results are
not so
good??!
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Which case provides a more
accurate solution?
( )f a
a b
( )f b
c
( ) ( )'( )
f b f af c
b a
( )f a
a b
( )f b
c
( ) ( )'( )
f b f af c
b a
AT
BT1 2 3 4
AT
BT1 10
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
0
50
100
150
200
250
300
0 0.005 0.01 0.015 0.02
analytical solution
numerical solution (OpenFOAM)
T [
ºC]
x [m]
Unión Europea FEDER
Invertimos en su futuro 0682_CLOUDPYME2_1_E
Now it is time
to see some
tutorials!!