swak4Foam and PyFoam
Introducing them as a pair.
Version 1.1
Bernhard F.W. Gschaider
Ann Arbor, USA
30. June 2015
Outline I
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Outline II
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Outline III
Exporting data
Outline
1Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Outline
1Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
What it’s about
•
Two pieces of software
•
swak4Foam
•
pyFoam
Intended audience and aim
•
Intended audience for this presentation:
•
people who already worked a bit with OpenFOAM
worked a bit
means: been through the tutorials and set up a
case on their own
•
have heard that PyFoam and swak4Foam exist
•
Aim of the presentation
•
Enable user to start using PyFoam and swak4Foam
•
No programming
•
The presentation is designed so that all steps can be
reproduced using the information on the slides
Format of the presentation
•
This is a hands-on tutorial
•
We will use a standard tutorial case
•
Modify it till it doesn’t look like the original
•
No additional files are needed
Limitation
•
In 2 hours we can only give superficial overview of the two
packages
•
It is not sure whether we’ll even be able to complete it
•
For a complete reference of the swak-expressions have a look
at the Incomplete reference guide that comes with swak
•
Expressions are completely described
•
Almost everything else is missing
Outline
1Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
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
•
Additional information can be found
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
and has grown since
•
The goal of swak4Foam is to make the use of C++
unnecessary
The core of swak4Foam
•
At its heart swak4Foam is a collection of parsers (subroutines
that read a string and interpret it) for expressions on
OpenFOAM-types
•
fields
•
boundary fields
•
other (faceSet, cellZone etc)
•
. . . and a bunch of utilities, function-objects and boundary
conditions that are built on it
•
swak4foam tries to reduce the need for throwaway C++
Outline
1Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Command line examples
•
In the following presentation we will enter things on the command
line. Short examples will be a single line (without output but a ">" to
indicate input)
> ls $HOME
•
Long examples will be a white box
•
Input will be prefixed with a > and blue
•
Long lines will be broken up
•
A pair of <brk> and <cont> indicates that this is still the same line in
the input/output
•
«snip» in the middle means: "There is more. But it is boring"
> t h i s is an e x a m p l e for a v e r y l o n g c o m m a n d l i n e t h a t d o e s not fit o n t o one l i n e of <brk><cont> the s l i d e but we h a v e to w r i t e it a n y w a y
f i r s t l i n e of o u t p u t ( s h o r t )
Work environment
•
You will use two programs
•
A terminal
•
A text-editor
•
For the text-editor you have the choice (these should be
installed):
•
Emacs (king of text-editors)
•
VI
•
Kate with KDE
•
Gedit with Gnome
•
nano
•
jedit
•
. . .
Getting onto the same page
•
During the remaining presentation we assume that
•the zsh is used (optional. bash works too)
•we use foam-extend 3.1 (required)
•
Switch to zsh
> zsh
•
You should see a more colorful prompt with (OF:-) on the left
•Only with correct environment set (probably only on the stick)
•
Switch on Foam-Extend-3.1
> foamExtend
•
Now the prompt should show (OF:3.1-Opt)
•
Create a working directory and go there
> mkdir PyFoamAndSwak; cd PyFoamAndSwak
Make sure PyFoam is working
•There is a utility that helps make sure that PyFoam is working•and gives valuable information for support
M a c h i n e i n f o : D a r w i n | bgs - cool - g r e y b o o k | 1 4 . 3 . 0 | D a r w i n K e r n e l V e r s i o n 1 4 . 3 . 0 : Mon Mar 23 1 1 : 5 9 : 0 5 PDT <brk> <cont> 2 0 1 5 ; r o o t : xnu - 2 7 8 2 . 2 0 . 4 8 ~ 5 / R E L E A S E _ X 8 6 _ 6 4 | x 8 6 _ 6 4 | i 3 8 6 P y t h o n v e r s i o n : 3 . 4 . 3 ( default , May 25 2015 , 1 8 : 4 8 : 2 1 ) [ GCC 4 . 2 . 1 C o m p a t i b l e A p p l e L L V M 6.0 ( clang - 6 0 0 . 0 . 5 6 ) ] P y t h o n e x e c u t a b l e : / opt / l o c a l / bin / p y t h o n P y t h o n 3 is s u p p o r t e d w i t h P y F o a m P Y T H O N P A T H : / U s e r s / b g s c h a i d / p r i v a t e _ p y t h o n : L o c a t i o n of t h i s u t i l i t y : / U s e r s / b g s c h a i d / D e v e l o p m e n t / O p e n F O A M / P y t h o n / P y F o a m / bin / p y F o a m V e r s i o n . py V e r s i o n () F o r k o p e n f o a m of the i n s t a l l e d 16 v e r s i o n s : extend - 3 . 0 : / U s e r s / b g s c h a i d / f o a m / foam - extend - 3 . 0 extend - 3 . 1 : / U s e r s / b g s c h a i d / f o a m / foam - extend - 3 . 1 extend -3.1 - c h e c k S c r i p t : / U s e r s / b g s c h a i d / f o a m / foam - extend -3.1 - c h e c k S c r i p t
extend - 3 . 2 : / U s e r s / b g s c h a i d / f o a m / foam - extend - 3 . 2 o p e n f o a m -1.6 - ext : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M -1.6 - ext o p e n f o a m -1.6 - ext - n e x t R e l e a s e : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M -1.6 - ext - n e x t R e l e a s e o p e n f o a m - 1 . 6 . x : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 1 . 6 . x o p e n f o a m - 1 . 7 . x : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 1 . 7 . x o p e n f o a m - 1 . 7 . x - c l e a n : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 1 . 7 . x - c l e a n o p e n f o a m - 1 . 7 . x - v e c t o r N : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 1 . 7 . x - v e c t o r N o p e n f o a m - 2 . 0 . x : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 2 . 0 . x o p e n f o a m - 2 . 1 . x : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 2 . 1 . x o p e n f o a m - 2 . 2 . x : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 2 . 2 . x o p e n f o a m - 2 . 2 . x - v e c t o r N : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 2 . 2 . x - v e c t o r N o p e n f o a m - 2 . 3 . x : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 2 . 3 . x o p e n f o a m - 2 . 4 . x : / U s e r s / b g s c h a i d / O p e n F O A M / O p e n F O A M - 2 . 4 . x T h i s v e r s i o n of O p e n F O A M u s e s the old c a l l i n g c o n v e n t i o n pyFoam - V e r s i o n : 0 . 6 . 5 P a t h w h e r e P y F o a m was f o u n d ( P y F o a m . _ _ p a t h _ _ ) is [ ’/ U s e r s / b g s c h a i d / p r i v a t e _ p y t h o n / PyFoam ’]
C o n f i g u r a t i o n s e a r c h p a t h : [( ’ file ’ , ’/ etc / p y F o a m / p y f o a m r c ’) , ( ’ d i r e c t o r y ’ , ’/ etc / p y F o a m / p y f o a m r c . d ’) , ( ’ file <brk> <cont> ’ , ’/ U s e r s / b g s c h a i d /. p y F o a m / p y f o a m r c ’) , ( ’ d i r e c t o r y ’ , ’/ U s e r s / b g s c h a i d /. p y F o a m / p y f o a m r c . d ’) ] C o n f i g u r a t i o n f i l e s ( u s e d ) : [ ’/ U s e r s / b g s c h a i d /. p y F o a m / p y f o a m r c ’ , ’/ U s e r s / b g s c h a i d /. p y F o a m / p y f o a m r c . d / t e s t i t .<brk>
pyFoamVersion.py
•
Information the utility gives
•
Machine
•
Used python
•
PYTHONPATH (where additional libraries are searched)
•
Information about the used PyFoam
•
Where configuration files are sought
•
Installed libraries relevant for PyFoam
•
With version if possible
•
This information helps diagnosing problems
•
Copy this output when reporting problems that might be
associated with the installation
Make sure swak4Foam is installed
•
Call the most popular utility of swak4Foam
•
swakVersion reported below the usual header
> f u n k y S e t F i e l d s /* - - - -*\ | = = = = = = = = = | | | \\ / F i e l d | foam - e x t e n d : O p e n S o u r c e CFD | | \\ / O p e r a t i o n | V e r s i o n : 3.2 | | \\ / A nd | Web : h t t p :// www . extend - p r o j e c t . de | | \\/ M a n i p u l a t i o n | | \* - - - -*/ B u i l d : 3.2 E x e c : f u n k y S e t F i e l d s D a t e : Jun 05 2 0 1 5 T i m e : 1 7 : 1 9 : 3 1 H o s t : bgs - cool - g r e y b o o k PID : 2 5 4 7 3 C t r l D i c t : "/ V o l u m e s / F o a m / W o r k s h o p 2 0 1 5 / c o u n t e r F l o w F l a m e 2 D / s y s t e m / c o n t r o l D i c t " C a s e : / V o l u m e s / F o a m / W o r k s h o p 2 0 1 5 / c o u n t e r F l o w F l a m e 2 D n P r o c s : 1 S i g F p e : E n a b l i n g f l o a t i n g p o i n t e x c e p t i o n t r a p p i n g ( F O A M _ S I G F P E ) . // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // s w a k V e r s i o n : 0 . 3 . 2 ( R e l e a s e d a t e : 20 15 - 05 - 31 ) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -> F O A M F A T A L E R R O R : f u n k y S e t F i e l d s : t i m e / l a t e s t T i m e o p t i o n is r e q u i r e d F r o m f u n c t i o n m a i n () in f i l e f u n k y S e t F i e l d s . C at l i n e 7 2 3 . F O A M e x i t i n g
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
The case
•
We’re going to use a plain tutorial case
•
Add stuff to it until the original author won’t recognize it
anymore
•
The case is counterFlowFlame2D for the reactingFoam
solver
•
Simple combustion case
•
Plain blockMesh
•
On one side 100% mixture of CH
4comes in
•
On the other side 23% of O
2•
Burns in the middle
•
Products leave on top and bottom
counterFlowFlame2D overview
Cloning
•
First we get us the case
•
But only the things that are important
•
We use the first PyFoam-utility for it
•
And afterwards check the results
> p y F o a m C l o n e C a s e . py $ F O A M _ T U T O R I A L S / c o m b u s t i o n / r e a c t i n g F o a m / ras /<brk> <cont> c o u n t e r F l o w F l a m e 2 D c o u n t e r F l a m e B a s e
P y F o a m W A R N I N G on l i n e 117 of f i l e / U s e r s / b g s c h a i d / O p e n F O A M / foam - extend <brk> <cont> - 3 . 1 / T h i r d P a r t y / p a c k a g e s / PyFoam - 0 . 6 . 3 / p l a t f o r m s / n o a r c h / lib /<brk> <cont> p y t h o n 2 .7/ site - p a c k a g e s / P y F o a m / A p p l i c a t i o n s / C l o n e C a s e . py : <brk> <cont> D i r e c t o r y d o e s not e x i s t . C r e a t i n g
> ls c o u n t e r F l a m e B a s e
0/ P y F o a m H i s t o r y c o u n t e r F l a m e B a s e . f o a m A l l r u n c o n s t a n t / s y s t e m /
What is cloned
•
Files essential for the case
•
Initial directory 0 (but not other times)
•
system
•
constant
•
Files like Allrun
•
Some files are created
PyFoamHistory
PyFoam-commands log their activity here
counterFlameBase.foam
A stub-file for the native
Paraview-reader
What else can pyFoamCloneCase.py do for me
All PyFoam-utilities have a --help-option:
p y F o a m C l o n e C a s e . py - - h e l p U s a g e
= = = = =
p y F o a m C l o n e C a s e . py < s o u r c e> < d e s t i n a t i o n >
C l o n e s a c a s e by c o p y i n g the system , c o n s t a n t and 0 - d i r e c t o r i e s If the <brk> <cont> c a s e is u n d e r VCS t h e n the c l o n i n g m e c h a n i s m of the VCS is u s e d O p t i o n s = = = = = = = - - v e r s i o n s h o w program ’ s v e r s i o n n u m b e r and e x i t - - help , - h s h o w t h i s h e l p m e s s a g e and e x i t D e f a u l t -O p t i o n s c o m m o n to all PyFoam - a p p l i c a t i o n s
- - psyco - a c c e l e r a t e d A c c e l e r a t e the s c r i p t u s i n g the psyco - l i b r a r y ( E X P E R I M E N T A L and r e q u i r e s a s e p a r a t l y i n s t a l l e d p s y c o )
- - profile - p y t h o n P r o f i l e the python - s c r i p t ( not the O p e n F O A M - p r o g r a m <brk> <cont> )
-m o s t l y of use for d e v e l o p e r s
- - profile - c p y t h o n P r o f i l e the python - s c r i p t ( not the O p e n F O A M - p r o g r a m <brk> <cont> )
u s i n g the b e t t e r c P r o f i l e l i b r a r y - m o s t l y of use <brk> <cont> for
d e v e l o p e r s
What we find in help
•
Short description of the utility
•
Options organized in sections
•
Options common to (most) PyFoam-utlities
•
For instance options that help with debugging
•
Options specific to the utility
•
For instance --add-item allows adding files/directories to be
added to the clone
Entering the case
•
Next we enter the case directory
> cd counterFlameBase
•
Prepare the mesh
> blockMesh
•
Check that everything is alright
> checkMesh
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Running the case
The probably most-used PyFoam-utility
> p y F o a m P l o t R u n n e r . py r e a c t i n g F o a m /* - - - -*\ | = = = = = = = = = | | | \\ / F i e l d | foam - e x t e n d : O p e n S o u r c e CFD | | \\ / O p e r a t i o n | V e r s i o n : 3.1 | | \\ / A nd | Web : h t t p :// www . extend - p r o j e c t . de | | \\/ M a n i p u l a t i o n | | \* - - - -*/ B u i l d : 3.1 E x e c : r e a c t i n g F o a m D a t e : Jun 08 2 0 1 4 T i m e : 1 6 : 1 1 : 3 8 H o s t : bgs - cool - g r e y b o o k PID : 8 3 1 6 4C t r l D i c t : / U s e r s / b g s c h a i d / O p e n F O A M / foam - extend - 3 . 1 / etc / c o n t r o l D i c t C a s e : / V o l u m e s / F o a m / C a s e s / c o u n t e r F l a m e B a s e n P r o c s : 1 S i g F p e : E n a b l i n g f l o a t i n g p o i n t e x c e p t i o n t r a p p i n g ( F O A M _ S I G F P E ) . // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // C r e a t e t i m e C r e a t e m e s h for t i m e = 0 R e a d i n g c h e m i s t r y p r o p e r t i e s
Window Nr 1 popping up
The other window
How the directory looks afterwards
•
Apart from the added time-directories there are other things
that were not there before:
> ls 0/ 0 . 1 / A l l r u n G n u p l o t t i n g . a n a l y z e d / P y F o a m H i s t o r y P y F o a m R u n n e r . r e a c t i n g F o a m . l o g f i l e P y F o a m S e r v e r . i n f o P y F o a m S t a t e . C u r r e n t T i m e P y F o a m S t a t e . L a s t O u t p u t S e e n P y F o a m S t a t e . S t a r t e d A t P y F o a m S t a t e . T h e S t a t e c o n s t a n t / c o u n t e r F l a m e B a s e . f o a m s y s t e m /
Added files
•
PyFoam adds a number of files to the directory:
PyFoamRunner.<solvername>.logfile
A complete copy of what was written
to the terminal
PyFoamServer.info
If you’re using the network component of PyFoam this
might help you
PyFoamState.*
Updated during the run and used by pyFoamListCases.py
(another nice utility that you’ve got to find out about yourself)
*.analyzed
A directory with the results of the analysis. Contents usually are
pickledPlots
Information to recreate the plots
pickledData
Data about the run that can be read and processed
by Python (of interest for scripters. Also see
pyFoamEchoPickledApplicationData.py)
pickledStartData, pickledUnfinishedData
Versions of the
above that are written during the run
Log-files
if the user chooses to write them
What did we actually simulate?
In case you forgot:
•
Simple combustion case:
•
CH
4
coming in from the left
•
O
2
coming in from the right
•
Ignition in the middle
•
Outflow on top and bottom
Conventions for utilities
•
Utilities that have a OpenFOAM-application (solver, utility) as
an argument (pyFoamPlotRunner.py for instance):
•
First PyFoam-options (start with --)
•
No arguments ("non-options")
•
Then the OpenFOAM-applications
•
Options and arguments after that belong to OpenFOAM
•
Other Utilities (pyFoamClearCase.py for instance)
•
Arguments and options can be mixed
•
Most
utilities have the case they should work on as an
argument
Getting a 1-page overview
A utility that prints information about a case in an easy-to-read
form
> p y F o a m C a s e R e p o r t . py . - - short - bc T a b l e of b o u n d a r y c o n d i t i o n s for t = 0 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = .. air f r o n t A n d B a c k f u e l o u t l e t -P a t c h T y p e p a t c h e m p t y p a t c h p a t c h L e n g t h 40 8 0 0 0 40 200 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = CH4 f i x e d V a l u e e m p t y f i x e d V a l u e i n l e t O u t l e t N2 f i x e d V a l u e e m p t y f i x e d V a l u e i n l e t O u t l e t O2 f i x e d V a l u e e m p t y f i x e d V a l u e i n l e t O u t l e t T f i x e d V a l u e e m p t y f i x e d V a l u e i n l e t O u t l e t U f i x e d V a l u e e m p t y f i x e d V a l u e z e r o G r a d i e n t Y d e f a u l t f i x e d V a l u e e m p t y f i x e d V a l u e i n l e t O u t l e t a l p h a t f i x e d V a l u e e m p t y f i x e d V a l u e z e r o G r a d i e n t e p s i l o n f i x e d V a l u e e m p t y f i x e d V a l u e z e r o G r a d i e n t k f i x e d V a l u e e m p t y f i x e d V a l u e z e r o G r a d i e n t mut f i x e d V a l u e e m p t y f i x e d V a l u e z e r o G r a d i e n tGetting printed info
•
Output of pyFoamCaseReport.py is ReST (ReStructured
Text)
•
Can be converted with a number of utilities
Exercise: finding information
Clearing the results
•
We can clear the results with one command
•
All timesteps but the first
•
system and constant untouched
> p y F o a m C l e a r C a s e . py . > ls 0/ A l l r u n G n u p l o t t i n g . a n a l y z e d / P y F o a m H i s t o r y P y F o a m R u n n e r . r e a c t i n g F o a m . l o g f i l e P y F o a m S e r v e r . i n f o P y F o a m S t a t e . C u r r e n t T i m e P y F o a m S t a t e . L a s t O u t p u t S e e n P y F o a m S t a t e . S t a r t e d A t P y F o a m S t a t e . T h e S t a t e c o n s t a n t / c o u n t e r F l a m e B a s e . f o a m s y s t e m /Clear the PyFoam-stuff as well
•
PyFoam leaves most of its own stuff untouched
•
Additional data to clear can be specified
> p y F o a m C l e a r C a s e . py . - - remove - a n a l y z e d - - add =" P y F o a m *" > ls 0/ A l l r u n P y F o a m H i s t o r y c o n s t a n t / c o u n t e r F l a m e B a s e . f o a m s y s t e m /
Friends of pyFoamPlotRunner.py
The functionality of pyFoamPlotRunner.py can be found in two
other utilities:
pyFoamRunner.py
Does all the PlotRunner does . . . except
plotting
•
Applications:
•
running on text-only displays
•
long runs
pyFoamPlotWatcher.py
Given a text file it parses it and plots
the results
•
Applications:
•
output of pyFoamPlotRunner.py
•
log files of OpenFOAM-runs (cluster for
Options for Runner and/or Plotter
–clear-case
Clears the case the way pyFoamClearCase.py does
–progress
Swallow output of the solver and only print current
time on terminal
–with-*
Plot additional information like iteration, CPU-time
etc
–hardcopy
Generate PNG-files of the plots (that’s how graphs
for this presentation were made)
–write-files
Write text files with the data from the plots
–write-all-timesteps
modifies controlDict to write
all
data
Exercise: Run. Then Plot
1
Start the simulation with the runner-utility (no plotting)
•
Make sure that data from the previous run is removed
•
only print the progress
2
Open another terminal window
•
Go to the directory
3
Use the plot watcher to plot data from the log file
•
In addition to the defaults plot at least the time-step
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Parallel running
•
Decompose cases in one line
•
Create decomposeParDict
•
Run decomposePar
> pyFoamDecompose.py . 2
•
Runner-utilities know how to handle parallel cases
•
Prepend mpirun (or different utilities if configured)
•
Automatically append -parallel
•
--autosense-parallel checks whether the case is decomposed or
not and acts accordingly
•
Automatically gets the correct number of processors
> pyFoamRunner.py --auto reactingFoam
Instead of
Fast switching of Foam-versions
•
The switch --foamVersion allows fast selection of the used (Open)Foam-version. Just for
the present command
•
Also possible to select Debug-version
Current case incompatible with OpenFOAM 2.3
p y F o a m R u n n e r . py - - f o a m V e r s i o n = 2 . 3 . x - - force - d e b u g r e a c t i n g F o a m /* - - - -*\ | = = = = = = = = = | | | \\ / F i e l d | O p e n F O A M : The O p e n S o u r c e CFD T o o l b o x | | \\ / O p e r a t i o n | V e r s i o n : 2 . 3 . x | | \\ / A nd | Web : www . O p e n F O A M . org | | \\/ M a n i p u l a t i o n | | \* - - - -*/ B u i l d : 2 . 3 . x - 0 8 1 e 9 7 6 0 2 3 a 9 E x e c : r e a c t i n g F o a m < < s n i p> > - -> F O A M F A T A L IO E R R O R : c a n n o t f i n d f i l e f i l e : / V o l u m e s / F o a m / C a s e s / c o u n t e r F l a m e B a s e / c o n s t a n t / c o m b u s t i o n P r o p e r t i e s at l i n e 0. F r o m f u n c t i o n r e g I O o b j e c t :: r e a d S t r e a m () in f i l e db / r e g I O o b j e c t / r e g I O o b j e c t R e a d . C at l i n e 73. F O A M e x i t i n g
"Simple" executing
•
Sometimes things should be executed in a different
OpenFOAM-environment
•
Without log-files
•
Without assuming the Foam calling convention
•
pyFoamExecute.py does that
•
Example: the current Foam-version is experimental and has no
working Paraview
•
Fall back to the paraview of the other Version
Saving away cases
•
Archiving cases with all the things needed to reproduce
> p y F o a m P a c k C a s e . py . - - t a r n a m e =/ tmp / b a s e F l a m e . tgz - - base - n a m e = t h e F l a m e > tar tzf / tmp / b a s e F l a m e . tgz t h e F l a m e / c o n s t a n t / R A S P r o p e r t i e s t h e F l a m e / c o n s t a n t / c h e m i s t r y P r o p e r t i e s t h e F l a m e / c o n s t a n t / g t h e F l a m e / c o n s t a n t / p o l y M e s h / b l o c k M e s h D i c t t h e F l a m e / c o n s t a n t / p o l y M e s h / b o u n d a r y t h e F l a m e / c o n s t a n t / p o l y M e s h / f a c e s t h e F l a m e / c o n s t a n t / p o l y M e s h / n e i g h b o u r t h e F l a m e / c o n s t a n t / p o l y M e s h / o w n e r t h e F l a m e / c o n s t a n t / p o l y M e s h / p o i n t s t h e F l a m e / c o n s t a n t / r e a c t i o n s t h e F l a m e / c o n s t a n t / t h e r m o . c o m p r e s s i b l e G a s t h e F l a m e / c o n s t a n t / t h e r m o p h y s i c a l P r o p e r t i e s t h e F l a m e / c o n s t a n t / t u r b u l e n c e P r o p e r t i e s t h e F l a m e / P y F o a m H i s t o r y
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Temperature extremes
•
Hidden the output of reactingFoam is information about the
temperature range
D I L U P B i C G : S o l v i n g for hs , I n i t i a l r e s i d u a l = 0 . 0 0 5 4 6 7 7 8 , F i n a l r e s i d u a l =<brk> <cont> 8 . 5 5 2 8 e -08 , No I t e r a t i o n s 4
T gas min / max = 2 9 2 . 9 7 7 , 9 8 3 . 0 5 6
D I C P C G : S o l v i n g for p , I n i t i a l r e s i d u a l = 0 . 1 1 8 5 1 , F i n a l r e s i d u a l = <brk> <cont> 8 . 2 2 4 1 1 e -07 , No I t e r a t i o n s 49
•
It would be cool to plot that as well
•
It is easy . . . but we’ve got to learn about something
complicated . . .
Regular expressions
•
Regular expressions are very popular for analyzing textual data
(pattern matching)
•
For instance in OpenFOAM for flexible boundary conditions
•
Python comes with a library for analyzing them
•
There are slightly different dialects
•
For instance there are slight differences between the regular expressions
of Python and OpenFOAM
•
But in 90% of all cases they behave the same
•
The following slide gives a quick glance
•
Usually you won’t need much more for PyFoam
•
There is a number of cool "regular expression tester" (enter that in
Google) applications on the web
Regular expressions in 3 minutes
1Most characters match only themself
•
For instance ’ab’ matches only the string "ab"
2
The dot (’.’) matches
any
character except a newline
•
Pattern ’a..a’ matches (among others) "abba", "aBBa", "ax!a"
3
The plus ’+’ matches the character/pattern before it 1 or more times
•
’a.+a’ matches "aba", "abbbba" but not "aa"
4
’*’ is like ’+’ but allows no match too
•
’a.*a’ matches "aba", "abbbba" and also "aa"
5
Parenthesis ’()’ group characters together. Patterns are numbered. They
receive the number by the opening ’(’
•
’a((b+)a)’ would match "abba" with group 1 being "bba" and group 2 "bb"
6
To match a special character like ’+-().|’ prefix it with a ’\’
•
To match "(aa)" you’ve got to write ’\(aa\)’
Matching the temperature
•
The example string
T gas min/max
= 292.977, 983.056
•
is matched by the regular expression
T gas min\/max
= (.+), (.+)
•
with the groups
1292.977
2
983.056
•
Beware
: The / has to be "escaped"
•
Beware
: Number of spaces has to be correct
•
Beware
: Simpler expression
T gas min\/max
= (.+)
•
Matches with group 292.977, 983.056
Matching floating point numbers
•
The pattern to match
all
floating point numbers with regular
expressions is quite complex:
•
Matching the sign
•
Exponential notation versus "normal"
•
To make life easier PyFoam introduces a shorthand
•
If it finds the string ’%f%’ in a regular expression it replaces it with the
correct regular expression
•
This only works in PyFoam
. Everywhere else this string will match
"%f%"
•
In our example:
The customRegexp-file
•
If a file customRegexp is found in the case by a Plot-utility it is read
•
It is in OpenFOAM-format:
•
a dictionary
•
all entries are dictionaries too
•
The name of the entry is used to identify the data (for instance during writing)
•
Most frequent entry in the dictionaries are:
expr
This is required. A regular expression that a line must match. All
groups (enclosed by ’()’) are interpreted as data and plotted
theTitle
String with the title of the plot
titles
List of words/strings. The names that the data items will get in
the legend
•
customRegexp is important enough for PyFoam to be automatically cloned by
pyFoamCloneCase.py
First customRegexp
•
In the case create with the text-editor of choice a
customRegexp
customRegexp
t e m p e r a t u r e E x t r e m e s {
e x p r " T ␣ gas ␣ min \/ max ␣ ␣ ␣ = ␣ (% f %) , ␣ (% f %) "; t h e T i t l e " T e m p e r a t u r e ␣ E x t r e m e s "; t i t l e s ( min max ) ; }
•
Test by running the watcher (pyFoamWatcher.py
PyFoamRunner.reactingFoam.logfile)
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
Case preparation in OpenFOAM
•
Usually done by executing a number of commands
•
blockMesh
•
other mesh utilities
•
setFields or similar to set up initial conditions
•
Tedious if done by hand
•
but easy to automate with scripts
•
Usually scripted with Allrun-scripts
•
Scripts do a lot of similar work
•
For instance copy 0.org to 0 to get "clean" initial conditions
•
But are not very robust in terms of error handling
Prepare case with PyFoam
•
Create "clean" initial conditions
•
From now on we only edit the files in 0.org
> mv 0 0.org
•
Run the preparation utility
> pyFoamPrepareCase.py .
•
This does
1
clears old data from the case
2
Copies 0.org to 0
3
Runs blockMesh
•
Could do a number of other things
•
evaluate templates
•
execute scripts
Outline
1
Introduction
About this presentation
What are we working with
Before we start
2
Basic case setup
Getting the case
Running
Not so basic uses
Basic plotting
3
Advanced processing
Case preparation
Adding our own evaluations
Evaluations after the fact
Function plugins
4
Manipulating the case
Setting boundary conditions
Boundary conditions with feedback
Inhomogeneous initial conditions
Overriding the solution
Adding particles
5
Data extraction
Distributions
Exporting data
What are function-objects
•
Function objects are "plugins"
•
Loaded and initialized at the start of the simulation
•
Executed at the end of each timestep
•
And at the end of the run
•
OpenFOAM already has a number of functionObjects
Adding function objects to a case
•
Usually no function objects are available
•
2 entries in controlDict:
libs
List with additional libraries to load
•
function objects in the library are available from
then on
functions
Dictionary with function object specification
•
names of the entries are used for output
•
values are sub-dictionaries
•
Mandatory entry type determines type of the
function object
Adding simpleFunctionObjects
•
oldest part of swak4Foam
•
used to be an independent project
controlDict
l i b s ( " l i b s i m p l e F u n c t i o n O b j e c t s . so " ) ; f u n c t i o n s { c a r b o n D i o x i d e { t y p e b a n a n a ; } }From now on if a box is for controlDict it means "add this entry
to functions"
The old banana-trick
•
Getting a full list of function objects is easy
•
Just use banana as type (kiwi would work too)
> r e a c t i n g F o a m < < s n i p> > d e l t a T = 0 . 0 0 0 3 9 8 4 0 6 - -> F O A M F A T A L E R R O R : U n k n o w n f u n c t i o n t y p e b a n a n a V a l i d f u n c t i o n s are : 40 ( c o r r e c t T h e r m o d y n a m i c F u n c t i o n O b j e c t L i s t P r o x y e x e c u t e I f E n v i r o n m e n t V a r i a b l e e x e c u t e I f E x e c u t a b l e F i t s e x e c u t e I f F u n c t i o n O b j e c t P r e s e n t e x e c u t e I f O b j e c t E x i s t s e x e c u t e I f O p e n F O A M V e r s i o n B i g g e r E q u a l e x e c u t e I f P a r a l l e l S e r i a l e x e c u t e I f S t a r t T i m eRange of carbon-dioxide
•
volumeMinMax gets a list of fields
•
Calculates the minimum and maximum value of them and
outputs it
•
To a file in special directory
•
To the terminal . . . sometimes
controlDict
f u n c t i o n s { c a r b o n D i o x i d e { t y p e v o l u m e M i n M a x ; o u t p u t C o n t r o l M o d e t i m e S t e p ; o u t p u t I n t e r v a l 1; v e r b o s e t r u e; f i e l d s ( CO2 ) ; } }Description of the entries
•
Entries common to a lot of function objects:
verbose
print results to the terminal.
•
Otherwise they are "only" written to a file
(PyFoam can’t process them)
outputControlMode
When should output be made.
•
For a list of possible values use banana-trick
outputInterval
specific for timeStep. How many timesteps
between outputs
•
Specific entry for this FO:
Output of CO
2
This is the extra output we now see when running reactingFoam:
D I L U P B i C G : S o l v i n g for k , I n i t i a l r e s i d u a l = 0 . 0 0 5 6 9 8 , F i n a l r e s i d u a l = <brk> <cont> 1 . 5 4 8 7 8 e -07 , No I t e r a t i o n s 3 E x e c u t i o n T i m e = 8.1 s C l o c k T i m e = 11 s C o u r a n t N u m b e r m e a n : 0 . 1 2 4 1 8 7 max : 0 . 3 9 7 0 2 5 v e l o c i t y m a g n i t u d e : 0 . 3 6 2 5 3 8 d e l t a T = 0 . 0 0 0 2 7 5 5 3 6 R a n g e of CO2 [ 0 , 0 . 0 5 0 1 2 5 4 ] [0 0 0 0 0 0 0] T i m e = 0 . 0 1 4 3 0 8 2 S o l v i n g c h e m i s t r y d i a g o n a l : S o l v i n g for rho , I n i t i a l r e s i d u a l = 0 , F i n a l r e s i d u a l = 0 , No <brk> <cont> I t e r a t i o n s 0Exercise: Plot range of CO
2
•
Add expressions to the customRegexp to plot the range
•
Caution
: [ and ] have meaning in regular expressions and
must be escaped with a \
Plotting more information about the species
•
Just plotting the range of the species is pretty limited
information
•
For all we know maximum could be only in one cell (all other
cells are near the minimum)
It is time to go to the heart of swak
•
Expressions are the core functionality of swak4Foam
•
Basically strings which are evaluated at run-time
•
Errors in the expression occur when the expression is evaluated. Not at
start-up
•
Expression syntax is modeled on the C++/C/Java-syntax for
expressions
•
With some exceptions
•
Some additional OpenFOAM-specific things (like & for dot vector
product)
•
Should be easy to understand even if you’re not familiar with these
programming languages
•
Let me repeat myself: a
complete
documentation for them is in the
Incomplete Reference Guide
Adding swak-functionObjects
•
Library simpleSwakFunctionObjects combines
•
simpleFunctionObjects: collect data over time
•
with the expressions of swak
controlDict
l i b s (
" l i b s i m p l e F u n c t i o n O b j e c t s . so " " l i b s i m p l e S w a k F u n c t i o n O b j e c t s . so "
The simplest possible expression
•
Just one field
controlDict
s p e c i e C H 4 { t y p e s w a k E x p r e s s i o n ; v a l u e T y p e i n t e r n a l F i e l d ; o u t p u t C o n t r o l M o d e t i m e S t e p ; o u t p u t I n t e r v a l 1; e x p r e s s i o n " CH4 "; a c c u m u l a t i o n s ( min w e i g h t e d Q u a n t i l e 0 .25 w e i g h t e d A v e r a g e w e i g h t e d Q u a n t i l e 0 .75 max ) ; v e r b o s e t r u e; }What swakExpression does
•
Reads an expression and evaluates it
•
But where?
•
That is what valueType says
•
internalField means "on the field"
•
another example is patch (on a patch specified by patchName)
•
For more see the reference guide
•
Boils it down to one or more single numbers specified in
Values for accumulations
min, max, average, sum
these should be pretty self-explanatory
median
The value for which 50% of the distribution are
smaller than this. More robust alternative to average
quantile
quantile0.25 for instance is the value for which
25% of the distribution are smaller than it
range
The difference of the quantile of
1+f
2
and
1−f
2
. For
instance range0.9 gives the range in which 90% of
the values are (from the quantile 5% to 95%)
smaller
The fraction of the distribution that is smaller than a
given value
weighted accumulations
•
Take a weight of the values into account
•
For the internalField the weights are the cell volume
•
Weighted values are usually physically more meaningful
•
Especially for mesh with large differences in cell sizes
•
For average a tiny cell would contribute as much as a huge cell
•
This is usally not what we mean with "average temperature" as it
depends on the discretization
•
weightedAverage does
P
i
T
iV
iP
i
V
i•
or as we say in swak for a internalField
Expressions. Some general words
•
Expressions are always between ""
•
Syntax is oriented on C++/C/Java
•
Strange things like &&, || etc
•
"Usual" precedence rules
•
* before + for instance
Fields
•
When swak finds an unknown name in an expression then it
assumes that it is a field name
•
Looks for a field of that name in memory
•
Post-processing utilities also look on the disc
•
Inserts the value of the field into the equation
•
With correct type (scalar, vector, tensor)
•
and location (cell-center, face-center)
•
Expressions may fail because types don’t fit
•
"You can’t add a scalar on a surface to a vector at the
cell-center"
•
Of course the error messages aren’t
that
clear
•
Usually something about "Unexpected XYZ"
Hint: Getting a list of the available fields
•
Adding a function object (from simpleFunctionObjects)
w h i c h F i e l d s {
t y p e l i s t R e g i s t e r e d O b j e c t s ; }
•
Prints a list of available fields (and non-fields):
N a m e T y p e A u t o w r i t e = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = CH4 v o l S c a l a r F i e l d Yes C H 4 _ 0 I O o b j e c t No CO2 I O o b j e c t Yes C O 2 _ 0 I O o b j e c t No H2O I O o b j e c t Yes H 2 O _ 0 I O o b j e c t No N2 v o l S c a l a r F i e l d Yes O2 v o l S c a l a r F i e l d Yes O 2 _ 0 I O o b j e c t No R A S P r o p e r t i e s d i c t i o n a r y No S I O o b j e c t No T v o l S c a l a r F i e l d Yes
The other species
•
For the other species we would have to copy everything
•
but if functions is a dictionary we let OpenFOAM do the work
controlDict
s p e c i e O 2 { $ s p e c i e C H 4 ; e x p r e s s i o n " O2 "; } s p e c i e H 2 O { $ s p e c i e C H 4 ; e x p r e s s i o n " H2O "; } s p e c i e C O 2 { $ s p e c i e C H 4 ; e x p r e s s i o n " CO2 "; }The new output
•
Rerunning reactingFoam produces more output
E x e c u t i o n T i m e = 1 9 1 . 3 9 s C l o c k T i m e = 194 s C o u r a n t N u m b e r m e a n : 0 . 1 5 0 4 8 9 max : 0 . 3 9 9 0 3 v e l o c i t y m a g n i t u d e : 0 . 2 7 0 3 4 3 d e l t a T = 0 . 0 0 0 3 6 9 0 0 4 R a n g e of CO2 [ 0 , 0 . 1 8 8 7 4 2 ] [0 0 0 0 0 0 0] E x p r e s s i o n s p e c i e C H 4 : min = 1 . 3 1 1 9 6 e -05 w e i g h t e d Q u a n t i l e 0 . 2 5 = 0 . 0 2 2 6 <brk> <cont> w e i g h t e d A v e r a g e = 0 . 3 4 5 1 9 7 w e i g h t e d Q u a n t i l e 0 . 7 5 = 0 . 6 7 5 max = 0 . 9 9 7 9 2 E x p r e s s i o n s p e c i e O 2 : min = 4 . 2 4 9 7 7 e -06 w e i g h t e d Q u a n t i l e 0 . 2 5 = 0 . 0 1 5 <brk> <cont> w e i g h t e d A v e r a g e = 0 . 0 9 8 6 0 2 3 w e i g h t e d Q u a n t i l e 0 . 7 5 = 0 . 1 7 3 6 max<brk> <cont> = 0 . 2 2 9 4 2 2 E x p r e s s i o n s p e c i e H 2 O : min = 0 . 0 0 0 4 2 4 5 6 w e i g h t e d Q u a n t i l e 0 . 2 5 = 0 . 0 2 4 6 2 5 <brk> <cont> w e i g h t e d A v e r a g e = 0 . 0 7 7 1 5 0 7 w e i g h t e d Q u a n t i l e 0 . 7 5 = 0 . 1 2 9 9 2 3 max<brk> <cont> = 0 . 1 5 4 5 2 2 E x p r e s s i o n s p e c i e C O 2 : min = 0 . 0 0 0 5 1 8 5 8 4 w e i g h t e d Q u a n t i l e 0 . 2 5 = 0 . 0 2 9 9 <brk> <cont> w e i g h t e d A v e r a g e = 0 . 0 9 4 2 3 6 7 w e i g h t e d Q u a n t i l e 0 . 7 5 = 0 . 1 5 8 7 max<brk> <cont> = 0 . 1 8 8 7 4 2 T i m e = 0 . 7 7 9 3 3 6
Plotting the species
•
With our current knowledge we’d need four expressions in
customRegexp
•
This would be tedious
•
We’d get four different plot windows
•
With more complicated chemical reactions the problem gets
worse
•
But as the outputs look quite similar the regular expressions
offer a solution
Dynamic Plotting
•
Add to the dictionary in customRegexp an entry type
•
Value: dynamic
•
Now PyFoam needs another entry: idNr
•
This is the index of the matching group that holds a
name
•
Remember: groups are numbered by the occurrence of the (
•
Counting starts with 1
•
For each name a different data-set is plotted
•
But all in the same graph
•
name is added to the titles
Entry for species-plotting
customRegexp
s p e c i e s { t h e T i t l e " S p e c i e s "; e x p r " E x p r e s s i o n ␣ s p e c i e ( . + ) ␣ : ␣ ␣ min =(% f %) ␣ w e i g h t e d Q u a n t i l e 0 . 2 5 = ( % f %)<brk> <cont> ␣ w e i g h t e d A v e r a g e =(% f %) ␣ w e i g h t e d Q u a n t i l e 0 . 7 5 = ( % f %) ␣ max =(% f<brk> <cont> %) "; t y p e d y n a m i c ; i d N r 1; t i t l e s ( min " 25% " a v e r a g e " 75% " max ) ; }Getting the location of the maximum
•
maxPosition(expr) means: "find the position of the
maximum value of expr"
•
Any accumulation is fine as this is a uniform value
w h e r e M a x T { $ s p e c i e C H 4 ; e x p r e s s i o n " m a x P o s i t i o n ( T ) "; a c c u m u l a t i o n s ( a v e r a g e ) ; }
Produces this output
Plotting the location of the maximum
temperature
customRegexp
m a x T L o c a t i o n { t h e T i t l e " L o c a t i o n ␣ of ␣ t e m p e r a t u r e ␣ m a x i m u m "; e x p r " E x p r e s s i o n ␣ w h e r e M a x T ␣ : ␣ ␣ a v e r a g e = \ ( ( % f %) ␣ (% f %) ␣ % f %\) "; t i t l e s ( x y ) ; a l t e r n a t e A x i s ( y ) ; }•
alternateAxis means "put values in this list on the right
axis"
Setting GnuPlot-options
•
A number of options usually set with the set-keyword in Gnuplot can be set in the
dicts (for details see the GnuPlot-documentation)
logscale
use a logarithmic scale for the y -axis
ylabel
label on the y -axis
y2label
same on the alternate axis
xlabel
Override the usual Time [s]
with
use something different than lines (points, steps)
gnuplotCommands
A list of strings with GnuPlot-commands that are executed
during execution
Addition to customRegexp to get x-axis for y
y l a b e l " x ";y 2 l a b e l" y "; g n u p l o t C o m m a n d s (
" set ␣ x 2 z e r o a x i s ␣ l i n e w i d t h ␣ 3 "
Calculating the stoechiometric ratio
•
The question is "Are there enough O
2
-molecules in the cell to
burn all CH
4
"
•
Or are there too many
•
The fractions that OpenFOAM uses are
mass
-fractions
Variables
•
Optional entry is variables
•
List of strings
•
Each string is of the form <name> = <expression>;
•
The semicolon is important
•
Means: Evaluate the expression and put it into a variable
name
•
The defined variables can be used in
•
subsequent variable-specifications
•
expression
expressionField
The library swakFunctionObjects adds function objects that
"only" use expressions
•
No timeline-recording etc
controlDict
l i b s ( " l i b s i m p l e F u n c t i o n O b j e c t s . so " " l i b s i m p l e S w a k F u n c t i o n O b j e c t s . so " " l i b s w a k F u n c t i o n O b j e c t s . so " ) ;•
expressionField calculates expression and puts it into a
Calculating λ
controlDict
•
The molar masses (12.0107 etc) are hard-coded here
s t o e c h i o m e t r i c { t y p e e x p r e s s i o n F i e l d ; f i e l d N a m e l a m b d a ; a u t o w r i t e t r u e; o u t p u t C o n t r o l t i m e S t e p ; o u t p u t I n t e r v a l 1; v a r i a b l e s ( " M C H 4 = 1 2 . 0 1 0 7 + 4 * 1 . 0 0 7 9 4 ; " " MO2 = 2 * 1 5 . 9 9 9 4 ; " ) ; e x p r e s s i o n " ( 0 . 5 * O2 / MO2 ) /( max ( CH4 ,1 e - 1 0 ) / M C H 4 ) "; }
Exercises: Getting numbers
•
Question: what could autowrite mean?
•
Plot percentage of space where λ > 1
•
Add swakExpression
•
Extend customRegexp
What goes in must come out
•
We want to check whether the mass-flows add up
•
They should
•
After the initial phase
•
Info
: by convention in OpenFOAM phi is the mass flow on
one face
•
Summing it up gives the total mass flow on a patch
•
patchExpression calculates expression on patches
•
Patches specified in a list
First the mass-flows on the patches
controlDict
m a s s F l o w s { t y p e p a t c h E x p r e s s i o n ; v a l u e T y p e i n t e r n a l F i e l d ; o u t p u t C o n t r o l M o d e t i m e S t e p ; o u t p u t I n t e r v a l 1; p a t c h e s ( " .* " ) ; e x p r e s s i o n " phi "; a c c u m u l a t i o n s ( sum ) ; v e r b o s e t r u e; }Picking up the mass-flows
That should be easy by now
customRegexp
m a s s F l o w s { t h e T i t l e " M a s s ␣ f l o w s "; e x p r " E x p r e s s i o n ␣ m a s s F l o w s ␣ on ␣ ( . + ) : ␣ ␣ sum =(% f %) "; t y p e d y n a m i c ; i d N r 1; t i t l e s ( sum ) ; }Getting values from somewhere else
•
swak allows variables calculated "somewhere else"
•
General notation is
<name>{<type>’<ename>}=<expression>;
•
Meaning: Calculate expression on entity ename of type type
and put result into name
•
Limitation
: the result of expression must be uniform
•
For instance a sum, min, max, ..
•
If only ename is given, then it is assumed that type is patch
•
There is an extension to the syntax for multi-region cases
#include for variable lists
•
Entry of the form
"#<name>;"
means "Get variable list from name and insert it here"
One patch sums up
controlDict
m a s s F l o w S u m { t y p e s w a k E x p r e s s i o n ; v a l u e T y p e p a t c h ; p a t c h N a m e o u t l e t ; o u t p u t C o n t r o l M o d e t i m e S t e p ; o u t p u t I n t e r v a l 1; v e r b o s e t r u e; p a t c h M F ( " f u e l M F { f u e l }= sum ( phi ) ; " " a i r M F { p a t c h ’ air }= sum ( phi ) ; ") ; v a r i a b l e s ( " # p a t c h M F ; " ) ; e x p r e s s i o n " sum ( phi ) + f u e l M F + a i r M F "; a c c u m u l a t i o n s ( a v e r a g e ) ; }