Documente Academic
Documente Profesional
Documente Cultură
CFD @ STCE
me (discrete OpenFOAM)
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
2/ 35
Outline
STCE
OpenFOAM Introduction
Discrete OpenFOAM
Improvements
Verification and Results
Work in Progress - PISO Foam
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
3/ 35
Outline
STCE
OpenFOAM Introduction
Discrete OpenFOAM
Improvements
Verification and Results
Work in Progress - PISO Foam
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
4/ 35
OpenFOAM
STCE
rising adoption in industry and academia due to lack of licence costs well suited for parallel
architectures
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
5/ 35
STCE
CFD Basics
I
v=0
v v = 2 v
momentum conservation
mass conservation
Or in three Dimensions:
vx
vx
vx
vx
x
vy
x
vz
x
+ vy
+ vy
+ vy
vx
y
vy
y
vz
y
+ vz
+ vz
+ vz
v
+
x
vx
z
vy
p0
x
p0
vz
p0
2 vx
x2
2 vy
x2
2 vz
x2
2 vx
y 2
2 vy
y 2
2 vz
y 2
2 vx
z 2
2 vy
z 2
2 vz
z 2
w
+
= 0
z
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
6/ 35
CFD Basics
STCE
obtained velocity field fulfills momentum equation but not mass conservation equation as the
pressure field was guessed and not correct
Loop...
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
7/ 35
STCE
Topology Optimization
no optimization
added material
reconstruction
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
8/ 35
STCE
Define Cost Function J, e.g. total pressure loss between inlet and outlet:
Z
J=
p+
1 2
vn d
2
J n
,
in
while insuring
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
9/ 35
Outline
STCE
OpenFOAM Introduction
Discrete OpenFOAM
Improvements
Verification and Results
Work in Progress - PISO Foam
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
10/ 35
Motivation for AD
in Context of Shape Optimization
AD promises:
I
I
I
I
STCE
Problems:
I
I
memory requirements
how to retain parallelism?
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
11/ 35
How to implement
STCE
I
I
I
due to complexity of OpenFOAM code (templates, massively object oriented) the only suitable
option
operator overloading tool dco/c++
every floating point value in OpenFOAM is replaced with custom adjoint datatype dco::a1s::type
needed intermediate values are stored in a structure called tape
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
12/ 35
How to implement
include dco.hpp
I
I
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
13/ 35
STCE
in src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.h: replace:
namespace Foam
{
typedef double doubleScalar;
...
}
with:
#include dco.hpp
namespace Foam
{
typedef dco::a1s::type doubleScalar;
...
}
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
14/ 35
STCE
in src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.h: replace:
namespace Foam
{
typedef double doubleScalar;
...
}
with:
#include dco.hpp
namespace Foam
{
typedef dco::t1s::type doubleScalar;
...
}
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
15/ 35
in Reality
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
16/ 35
STCE
J
i :
double sens = 0;
dco::t1s::set(alpha[i],1,1);
for (runTime++; !runTime.end(); runTime++)
{
... // solve for U,p
}
// Sum pressure over inlet faces scaled with face area
doubleScalar J = gSum( p.boundaryField()patch.magSf() );
dco::t1s::get(J,sens,1);
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
17/ 35
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
18/ 35
Outline
STCE
OpenFOAM Introduction
Discrete OpenFOAM
Improvements
Verification and Results
Work in Progress - PISO Foam
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
19/ 35
First Results
I
I
STCE
Black-Box approach severely bound by memory bandwith! (Need to allocate around 20 GB)
By doing Checkpointing we can actually get faster...
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
20/ 35
STCE
How to improve?
I
Knowledge and Profiling reveals that most of calculation time and tape memory is spent in
(iterative) linear solvers
Lemma
For a Linear Equation Sytem Ax = b we can calculate the adjoints for A and b by:
b = AT x
AT b = x
A = b xT
I
This gives us an additional Linear Equation System which we have to solve during the gathering
of the adjoints
2 M. Giles, Collected Matrix Derivative Results for Forward and Reverse Mode Algorithmic Differentiation, Advances
in Automatic Differentiation 2008
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
21/ 35
STCE
when we encounter an linear solver during the augmented forward run we can stop taping
when we encounter the gap in the tape during the interpretation we have to fill in the gap by
hand
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
22/ 35
Application to OpenFOAM
STCE
Abstract Base Class for all Linear Solvers exists can tackle all implemented solvers at once
Discretization matrices are stored in a coordinate sparse matrix format transposing matrix
straightforward
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
23/ 35
Outline
STCE
OpenFOAM Introduction
Discrete OpenFOAM
Improvements
Verification and Results
Work in Progress - PISO Foam
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
24/ 35
Results
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
25/ 35
STCE
Verification
I
I
I
We calculate a reference solution with solvers GAMG for U and smoothSolver for p, both with
tolerance 1e 10
After that we calculate solutions with different tolerances for the forward and adjoint linear
solvers and compare to the reference solution
11k Cells in mesh
Velocity
Sensitivity
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
26/ 35
STCE
Verification
Runtime
Tape-Memory
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
27/ 35
Error
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
28/ 35
Runtime
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
29/ 35
Outline
STCE
OpenFOAM Introduction
Discrete OpenFOAM
Improvements
Verification and Results
Work in Progress - PISO Foam
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
30/ 35
STCE
Unsteady PISO solver with unsteady cost function (potentially depends on every timestep)
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
31/ 35
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
32/ 35
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
33/ 35
STCE
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
34/ 35
STCE
Thank you!
Questions?
,
STCE RWTH-Aachen, Discrete OpenFOAM, EuroAD 2013
35/ 35