Professional Documents
Culture Documents
Swak4FoamTraining OFW8
Swak4FoamTraining OFW8
swak4Foam
Gentle introduction and new developments
Jeju, Korea
11. June 2013
swak4Foam
1/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
2/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
3/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
4/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Contents
swak4Foam
5/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
What is swak4Foam
From http://openfoamwiki.net/index.php/Contrib/swak4Foam
swak4Foam stands for SWiss Army Knife for Foam. Like that knife
it rarely is the best tool for any given task, but sometimes it is
more convenient to get it out of your pocket than going to the
tool-shed to get the chain-saw.
It is the result of the merge of
funkySetFields
groovyBC
simpleFunctionObjects
swak4Foam
6/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
7/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Previous presentations
No C++, please. Were users! Held at the 6th Workshop in
swak4Foam
8/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Sorry Trekies
The two example cases in this presentation are inspired by the
well
swak4Foam
9/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
10/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
11/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
/home/openfoam/training_materials/Track3-2
unpack to home-directory
1
swak4Foam
12/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Added files:
swak4Foam
13/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
zsh
You should see a more colorful prompt with (OF:) on the left
Switch on OpenFOAM 2.2
. /opt/openfoam220/etc/bashrc
Now the prompt should show (OF:2.2.0-Opt)
Create a working directory and go there
swak4Foam
14/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
15/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
PyFoam-presentation before
It is not necessary
We will only use it for running our cases
swak4Foam
16/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
What is PyFoam
PyFoam is a library for
Manipulating OpenFOAM-cases
Controlling OpenFOAM-runs
It is written in Python
Based upon that library there is a number of utilities
For case manipulation
Running simulations
Looking at the results
All utilities start with pyFoam (so TAB-completion gives you an
overview)
Each utility has an online help that is shown when using the
-help-option
swak4Foam
17/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Case setup
Cloning an existing case
pyFoamListCases.py .
Bernhard F.W. Gschaider
swak4Foam
18/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Running
Straight running of a solver
pyFoamRunner.py interFoam
Clear the case beforehand and only show the time
swak4Foam
19/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Generated files
Typically PyFoam generates several files during a run (the
swak4Foam
20/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Plotting
Any logfile can be analyzed and plotted
swak4Foam
21/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
22/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
23/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
24/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
25/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
26/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
27/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
cd $HOME/swak4FoamTraining
Extract the case files
1
cd sandPit.baseCase
Bernhard F.W. Gschaider
swak4Foam
28/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Used solver
modifications
the mesh is made wider (but the lower inlet keeps its width)
viscosity of the sand-phase is made larger to account for the
swak4Foam
29/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
blockMesh
use PyFoam to run the case
swak4Foam
30/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
31/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Sand fraction
swak4Foam
32/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
33/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
34/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
phase
Only if there is sand
swak4Foam
35/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
funkySetFields
funkySetFields is a utility to create or modify
swak4Foam
36/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
37/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Calculating USand
The new velocity is calculated with
1
> f u n k y S e t F i e l d s l a t e s t T i m e c r e a t e f i e l d <brk>
<cont>USand e x p r e s s i o n " a l p h a 1 >=0.58 ? U1 <brk>
<cont> : v e c t o r ( 0 , 0 , 0 ) "
swak4Foam
38/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
39/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
This and the following examples can be tried out (there are no
demo pictures)
1
> f u n k y S e t F i e l d s l a t e s t T i m e c r e a t e f i e l d <brk>
<cont>UrCheck e x p r e s s i o n "Ur(U1U2 ) "
swak4Foam
40/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
> f u n k y S e t F i e l d s l a t e s t T i m e c r e a t e f i e l d <brk>
<cont>UNorm e x p r e s s i o n "U/max ( mag (U) ) "
swak4Foam
41/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
> f u n k y S e t F i e l d s l a t e s t T i m e c r e a t e f i e l d <brk>
<cont> d i v P h i e x p r e s s i o n " d i v ( p h i ) "
swak4Foam
42/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
> f u n k y S e t F i e l d s l a t e s t T i m e c r e a t e f i e l d <brk>
<cont>moveAir e x p r e s s i o n " d e l t a T ( ) U2"
swak4Foam
43/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
> f u n k y S e t F i e l d s l a t e s t T i m e c r e a t e f i e l d <brk>
<cont> p D i s t e x p r e s s i o n " p o s ( )m a x P o s i t i o n ( <brk>
<cont>p ) "
swak4Foam
44/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
> f u n k y S e t F i e l d s l a t e s t T i m e c r e a t e f i e l d <brk>
<cont>normX e x p r e s s i o n " p o s ( ) . x<brk>
<cont> i n t e r p o l a t e T o C e l l ( min ( p t s ( ) . x ) ) /<brk>
<cont> i n t e r p o l a t e T o C e l l ( max ( p t s ( ) . x )min ( <brk>
<cont> p t s ( ) . x ) ) "
swak4Foam
45/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
> f u n k y S e t F i e l d s t i m e 10 c r e a t e f i e l d <brk>
<cont>dAlpha1 o t h e r C a s e . o t h e r T i m e 9 <brk>
<cont> e x p r e s s i o n " a l p h a 1 o t h e r ( a l p h a 1 ) "
swak4Foam
46/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Hands On
swak4Foam
47/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
48/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Until now the case doesnt resemble the real pit at all
Changes to be done
Set inhomogeneous initial conditions
Sand surface with a slight bump
Set the velocity at the bottom to go down
With a parabolic profile
Only start after a certain time
swak4Foam
49/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
cd $HOME/swak4FoamTraining
Extract the case files
1
cd sandPit.groovBCetc
Prepare
blockMesh
cp 0/alpha1Start 0/alpha1
Bernhard F.W. Gschaider
swak4Foam
50/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
-expression-option
Automatically uses the file system/funkySetFieldsDict
different file can be used with -dictExt
Dictionary file has an entry expressions with a list of
dictionaries
Each dictionary acts like a command-line call to FSF
Dictionary entries corresponding to command line options
funkySetFields -time 0
swak4Foam
51/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
The variables-list
of variable declarations
Evaluated before the actual expression and variables can be
swak4Foam
52/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
expressions
(
init
{
11
13
15
17
19
21
);
f i e l d alpha1 ;
e x p r e s s i o n "0.6" ;
c o n d i t i o n "pos ().z<min( idealHeight , levelHeight )" ;
keepPatches true ;
variables (
"minX= interpolateToCell (min(pts ().x));"
"maxX= interpolateToCell (max(pts ().x));"
"minZ= interpolateToCell (min(pts ().z));"
"maxZ= interpolateToCell (max(pts ().z));"
" levelHeight =0.75*( maxZ -minZ)+minZ;"
" lowerHeight = levelHeight -0.25*( maxZ -minZ);"
" width =min (2*( levelHeight - lowerHeight ),maxX -minX)<brk>
<cont> ;"
" middle =0.5*( minX+maxX);"
" idealHeight =pow (( pos ().x- middle )/( width *0.5) ,2)<brk>
<cont> *( levelHeight - lowerHeight )+ lowerHeight ;"
);
swak4Foam
53/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Distribution of alpha1 at t = 0
swak4Foam
54/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Description
Calculation on the internal values of a field
Calculation on a boundary patch
On a faceZone of the mesh
On a faceSet
Calculation on a cellZone
Set of cells
Calculation on a sampledSet
Calculation on a sampledSurface
Internal values of a FAM-field (1.6-ext only)
Boundary patch of a FAM-field (1.6-ext only)
swak4Foam
55/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
system/controlDict
1
libs (
);
swak4Foam
56/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Fields of groovyBC
groovyBC allows setting a mixture of Dirichlet and Neuman
boundary conditions
Default is Dirichlet
Entries are
swak4Foam
57/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
11
13
15
bottom
{
type
groovyBC ;
value
uniform (0 0 0) ;
variables (
"minX=min(pts ().x);"
"maxX=max(pts ().x);"
" middle =0.5*( minX+maxX);"
"vMax =1;"
" profile =vMax *(1- pow (( pos ().x- middle )/( middle -minX)<brk>
<cont> ,2));"
"tOpen =5;"
" tOpening =1;"
" factor =time ()<tOpen?0:(time () >(tOpen+ tOpening )<brk>
<cont> ?1:(time ()-tOpen )/ tOpening );"
);
v a l u e E x p r e s s i o n " normal ()* factor * profile " ;
}
Bernhard F.W. Gschaider
swak4Foam
58/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
59/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
later)
Part of U2
bottom
{
type
groovyBC ;
value
uniform (0 0 0) ;
v a l u e E x p r e s s i o n "1.1* U1" ;
}
swak4Foam
60/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
61/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
62/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
pyFoamClearC ase . py .
rm f 0/ a l p h a 1 0/ a l p h a 1 . gz
blockMesh
cp 0/ a l p h a 1 S t a r t 0/ a l p h a 1
f u n k y S e t F i e l d s t i m e 0
swak4Foam
63/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
64/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Distribution of alpha1 at t = 50
swak4Foam
65/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Function objects
controlDict
swak4Foam
66/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
on expressions
Write data at each timestep
simpleSwakFunctionObjects are based on these but
evaluate expressions
system/controlDict
libs (
" libgroovyBC .so"
" libsimpleFunctionObjects .so"
" libsimpleSwakFunctionObjects .so"
);
swak4Foam
67/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Extremes of fields
functions in controlDict
SimpleFunctionObjects
This writes the minimum
outputControlMode
allows changing that
Bernhard F.W. Gschaider
extremes {
t y p e volumeMinMax ;
verbose true ;
fields (
U1
U2
alpha1
p
);
}
swak4Foam
68/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swakExpression
Evaluates an expression
Based on
simpleFunctionobjects
valueType determines the parser
accumulations reduces the field to
a single value
6
10
12
sandVelocity {
type swakExpression ;
v a l u e T y p e i n t e r n a l F i e l d <brk>
<cont> ;
verbose true ;
variables (
" thres =0.55; "
);
e x p r e s s i o n "alpha1 ><brk>
<cont> thres ?mag(U1<brk>
<cont> ):0" ;
accumulations (
max
weightedAverage
);
}
swak4Foam
69/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
70/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Adding to controlDict
1
a cell
totalSand {
$sandVelocity ;
e x p r e s s i o n "vol<brk>
<cont> ()*<brk>
<cont> alpha1 "<brk>
<cont> ;
accumulations (
sum
);
}
swak4Foam
71/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
72/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Hands On
swak4Foam
73/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
74/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
75/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
cd $HOME/swak4FoamTraining
Extract the case files
1
cd sandPit.withParticles
swak4Foam
76/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
libs (
" libgroovyBC .so"
" libsimpleLagrangianFunctionObjects .so"
" libsimpleFunctionObjects .so"
" libsimpleSwakFunctionObjects .so"
" libswakFunctionObjects .so"
" libswakVelocityFunctionPlugin .so"
);
Bernhard F.W. Gschaider
swak4Foam
77/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Function plugins
This allows adding specialized functions to the parsers
Without modifying them
Just add the library in libs
The parser knows about them and will print information about
the available functions the first time he is called
That way they can also be used from funkySetFields
Application:
Functions that are not needed by everyone
Evaluations that can not be written as a simple expression
A number of plugin-libraries come with swak4Foam:
Related to turbulence, thermophysical models, discretizations
etc
Anyone can write plugin-functions for his special needs
Bernhard F.W. Gschaider
swak4Foam
78/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
expressionField
Creates a new field fieldName from
expression
autowrite determines whether it will be
written
courantIncompressible is plugin
function
argument
10
12
airCourant {
type e x p r e s s i o n F i e l d ;
a u t o w r i t e true ;
fieldName courantU1 ;
e x p r e s s i o n "<brk>
<cont> courantIncompressible<brk>
<cont> (phi1)" ;
}
sandCourant {
type e x p r e s s i o n F i e l d ;
a u t o w r i t e true ;
fieldName courantU2 ;
e x p r e s s i o n "<brk>
<cont> courantIncompressible<brk>
<cont> (phi2)" ;
}
swak4Foam
79/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
totalMu {
type e x p r e s s i o n F i e l d ;
e x p r e s s i o n "mu1+nut2*rho" ;
fieldName totalMu ;
a u t o w r i t e true ;
}
swak4Foam
80/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
balls {
type evolveKinematicCloud ;
cloudName t r a c e r B a l l s ;
rhoName r h o ;
UName U ;
muName t o t a l M u ;
}
swak4Foam
81/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
Particles coming in
swak4Foam
82/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
83/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
customRegexp
1
11
13
15
kineticEnergy {
e x p r " Linear kinetic energy =(%f%)" ;
type s l a v e ;
master NumberOfParticles ;
t i t l e s ( energy ) ;
}
NumberOfParticles {
e x p r " Current number of parcels =(%f%)" ;
t h e T i t l e " Particles andtheir movement " ;
t i t l e s ( nr ) ;
x l a b e l "t[s]" ;
y 2 l a b e l "nr [1]" ;
y l a b e l " energy " ;
a l t e r n a t e A x i s ( nr ) ;
}
swak4Foam
84/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Description
Basic case
groovyBC and funkySetFields
Adding particles
swak4Foam
85/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
86/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
87/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Biggs Darklighter
In A New Hope (also known as the first Star Wars movie but
Since then rumors say that the reason for his death was a
swak4Foam
88/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
89/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Landspeeders in a canyon
swak4Foam
90/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
91/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
cd $HOME/swak4FoamTraining
Extract the case files
1
cd landSpeedersInCanyon
Bernhard F.W. Gschaider
swak4Foam
92/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
with snappyHexMesh
They are added by loading the library
1
libs (
);
This adds
Boolean operations (combining surfaces)
Additional primitives
Coordinate transformations of existing surfaces
All this works of course for STLs too
To mix and match them
Bernhard F.W. Gschaider
swak4Foam
93/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Define a type
union, intersection, difference and exclusive
Define the two surfaces a and b that are combined
Only for difference the results are different if they are
exchanged
swak4Foam
94/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Boolean operations
swak4Foam
95/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
A block
swak4Foam
96/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
11
13
15
17
19
21
23
25
27
29
31
33
speederBody {
t y p e union ;
a {
type i n t e r s e c t ;
a {
type searchableBoxWithDirections ;
max ( 3 2 0 . 2 5 ) ;
min (3 2 0.25) ;
}
b {
t y p e union ;
aName f r o n t ;
a {
type searchableSphereWithFix ;
c e n t r e ( 1.5 0 0 ) ;
radius 1;
}
bName s i d e ;
b {
type s e a r c h a b l e C y l i n d e r ;
p o i n t 1 ( 1.5 0 0 ) ;
p o i n t 2 ( 2.5 0 0) ;
radius 1;
}
}
}
b {
type t r a n s l a t e ;
surface {
$windShield ;
}
t r a n s l a t i o n (1 0 0 . 2 ) ;
}
}
swak4Foam
97/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
98/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
99/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Patch names
Names of the patches are composed from
the patch names of the sub-surfaces
name of the operation
whether they belong to a or b
these names can be modified with aName and bName
different patches
For instance the inlet and outlet of the jets
swak4Foam
100/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Parts of a jet
swak4Foam
101/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
102/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
103/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Solver we use
We use simpleFoam
Case based on the motorCylce-tutorial
Add a function object that adds a passive scalar for the exhaust
swak4Foam
104/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
pyFoamClearC ase . s h .
rm f r 0
rm f c o n s t a n t / polyMesh / . gz
blockMesh
6
snappyHexMesh o v e r w r i t e
8
cp r 0 . o r g / 0
10
p o t e n t i a l F o a m w r i t e p n o F u n c t i o n O b j e c t s
swak4Foam
105/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Remote variables
Entries in variables can be calculated on other entities
This is indicated by an entry of the form {valueTypename}
/regionName
The expression on the right side of the equal sign is evaluated
swak4Foam
106/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
11
13
15
17
19
swak4Foam
107/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
normal OpenFOAM
Well use the swak-variant nevertheless
It allows setting the various coefficients of the transport
equation with arbitrary expressions
swak4Foam
108/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
controlDict
1
exhaustTransport {
type solveTransportPDE ;
solveAt timestep ;
fieldName exhaust ;
steady true ;
d i f f u s i o n " turb_nuEff ()" [ 0 2 1 0 0 0 0 ] ;
s o u r c e "0" [ 0 0 1 0 0 0 0 ] ;
p h i "phi" [ 0 3 1 0 0 0 0 ] ;
}
swak4Foam
109/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
110/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
10
12
14
16
18
20
exhaustDistribution {
type swakExpression ;
verbose true ;
valueType i n t e r n a l F i e l d ;
e x p r e s s i o n " exhaust " ;
accumulations (
min
max
weightedAverage
);
}
exhaustMeasure {
type patchExpression ;
patches (
" landSpeeder .* _inlet "
outlet
);
e x p r e s s i o n "sum(area ())* exhaust /sum(area ())" ;
verbose true ;
accumulations ( average ) ;
}
Bernhard F.W. Gschaider
swak4Foam
111/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
11
startLater {
type executeIfSwakExpression ;
readDuringConstruction true ;
valueType patch ;
patchName i n l e t ;
l o g i c a l E x p r e s s i o n "time () >=10" ;
l o g i c a l A c c u m u l a t i o n and ;
functions {
exhaustDistribution {
...
Bernhard F.W. Gschaider
swak4Foam
112/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
controlDict
11
velocityMagnitude {
type e x p r e s s i o n F i e l d ;
f i e l d N a m e magU ;
e x p r e s s i o n "mag(U)" ;
autowrite false ;
}
stopHighVel {
t y p e panicDump ;
f i e l d N a m e mag (U) ;
minimum 1;
maximum 1 0 0 0 ;
}
swak4Foam
113/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
114/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
115/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Linear convergence
swak4Foam
116/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
117/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
118/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
119/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
120/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
121/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
higher
swak4Foam
122/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
controlDict
Variables declared in
startup
8
10
12
14
16
velocityChangeField {
type e x p r e s s i o n F i e l d ;
f i e l d N a m e changeU ;
a u t o w r i t e true ;
e x p r e s s i o n " changeOfU " ;
variables (
" changeOfU =U-oldU;"
"oldU=U;"
);
storedVariables (
{
name oldU ;
i n i t i a l V a l u e " vector<brk>
<cont> (80 ,0 ,0)" ;
}
);
}
swak4Foam
123/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Change of velocity
swak4Foam
124/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
125/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
126/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Calculating distribution
swak has a function object that allows the calculation of the
distribution of a variable
Three expressions that need to be defined
swak4Foam
127/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
simpleFunctionObjects
New outputControlMode named deltaT
Desired output interval specified by outputDeltaT
Function object is only evaluated if close enough to the next
output time
Time is not manipulated so the intervall is not exactly fulfilled
swak4Foam
128/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
10
12
Cell weighted
velocityChangeDistribution {
t y p e s w a k E x p r e s s i o n D i s t r i b u t i o n <brk>
<cont> ;
outputControlMode deltaT ;
outputDeltaT 10;
valueType i n t e r n a l F i e l d ;
verbose true ;
e x p r e s s i o n " changeU " ;
w e i g h t "vol ()" ;
mask "true" ;
w r i t e T i m e l i n e true ;
w r i t e D i s t r i b u t i o n true ;
distributionBinWidth 0.1;
}
velocityChangeDistributionCell
<cont> {
$velocityChangeDistribution<
<cont> ;
w e i g h t "1" ;
}
swak4Foam
129/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
130/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
controlDict
mqFaceNonOrth is a
velChangeNonOrth {
$velocityChangeDistribution ;
e x p r e s s i o n " lcFaceMaximum (<brk>
<cont> mqFaceNonOrtho ())" ;
mask "mag( changeU ) >5" ;
}
totalNonOrth {
$velChangeNonOrth ;
mask "true" ;
}
swak4Foam
131/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
132/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
133/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
objects
A python-script generates text specifications for additional
function objects
swak4Foam
134/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Further information
Documentation/swak4FoamReference.org
This document is work in progress
swak4Foam
135/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Goodbye to you
swak4Foam
136/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
swak4Foam
137/138
Introduction
Basics: The sand-pits of Carcoon
Advanced: Landspeeders in a canyon
Conclusion
Outline
1
Introduction
About this presentation
Before we start
Overview of PyFoam
Basics: The sand-pits of Carcoon
Description
Basic case
groovyBC and funkySetFields
Adding particles
Advanced: Landspeeders in a
canyon
The case of Biggs Darklighter
Creating the landspeeder
Setting up the case
Investigating the case
Conclusion
swak4Foam
138/138