wolfson unit openfoam workshop 1 st november 2010 postprocessing & the black art of scripting...
Post on 21-Dec-2015
226 views
TRANSCRIPT
![Page 1: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/1.jpg)
WOLFSON UNIT
OpenFOAM workshop1st November 2010
Postprocessing & the black art of scripting
Sandy Wright
![Page 2: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/2.jpg)
WOLFSON UNIT
Postprocessing
• Paraview– Open source, multi-platform– Based on VTK toolkit– http://www.paraview.org/– Can compile or download exe
• ParaFOAM – Reads native FOAM formats– Can be very difficult to install correctly– NOT installed on Iridis
![Page 3: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/3.jpg)
WOLFSON UNIT
The basics
• Cell centred data v node centred• Filters
– Colour by ..– Slice– Clip– Vectors (Glyphs)– Calculator
• Save Data
![Page 4: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/4.jpg)
WOLFSON UNIT
Customisation
• Custom filters (Tools->create custom filter)
• State files (same can be achieved via python script)
• Background images (Edit->View settings)
• Customised colour maps
![Page 5: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/5.jpg)
WOLFSON UNIT
Adaptability
• Parallelisation (pvbatch can be run via mpi)
• State files & filters platform independent (up to a point)
• Server-client (ie store files on one machine, use graphics processing of the one in front of you)
• Python scripting...
![Page 6: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/6.jpg)
WOLFSON UNIT
Visualisation of cases on iridis1. Run paraview on iridis via X tunnelling/ exceed –
slow for large models2. Tar & Gzip ./VTK & processor*/VTK– large files
(typically 1-2 GB when zipped)3. Lower mesh resolution via mapFields– lose
resolution, but v useful for quick viewing etc (and smooths out hot spots etc !!)
4. Extract and port surfaces only (100’s of MB only)
![Page 7: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/7.jpg)
WOLFSON UNIT
Map fields• Make new run dir (lets call it low_res)• Copy constant & system dirs to low_res dir• Make timestep folder (equiv to last time step of full solution) in
low_res• Create / copy template field data files (eg U, p) in
low_res/timestep• Create blockMeshDict of required density in
low_res/constant/polyMesh• Create mapFieldsDict in low_res/system
• blockMesh >> LOG-map_fields.txt
• mapFields ../full_solution_dir -parallelSource -sourceTime 1803 >> LOG-map_fields.txt
![Page 8: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/8.jpg)
WOLFSON UNIT
Scripting“A scripting language is a programming language
that allows control of applications and the environment etc without requiring compilation.”
• Unix/Linux– Bourne shell (aka Bash)– C shell– Others(Korn, mudsh, fish, scsh, pysh ...)
• Python“Python is an interpreted, object-oriented, high-
level programming language with dynamic semantics”
![Page 9: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/9.jpg)
WOLFSON UNIT
Shell scripts• Basically a copy of what you would type on the
command line, but...– Allows decision making (if/else)– Simple (e.g. arithmetic) operators
• Why – Avoid mistakes in repetitive commands– Incorporation of command line exe’s leads to very powerful tools– Daisy chain different scripts together
• Redirection (< > >>), standard streams (0,1,2...)
• Example of openfoam running script• Example of ‘house keeping’ script
![Page 10: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/10.jpg)
WOLFSON UNIT
Different shells
• Shebang ( #!/bin/bash )• Iridis is run on Bourne/Bash• Good practise• Why Bash
– http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/– Redirecting streams (eg stderr to stdout => 2>&1 )
• Mix ‘n’ match
![Page 11: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/11.jpg)
WOLFSON UNIT
Command line editors
• Why ? Surely this went out with the punch card ....– Template script file– Repetitive searches in LARGE files
• SED– sed 's/yourword/myword/g' infile >outfile
• head – head –n 5 infile > outfile
![Page 12: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/12.jpg)
WOLFSON UNIT
Python• Easy to learn and readable• Object orientated
– Libraries & routines out there to be used!
• Lists – a = ['spam', 'eggs', 100, 1234] – >>> a
• ['spam', 'eggs', 100, 1234]
– >>> a[3] • 1234
• For loops (note indenting)• for i in range(24):
Example of Paraview python script
![Page 13: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/13.jpg)
WOLFSON UNIT
Resources• http://www.paraview.org/Wiki/ParaView
• http://www.cfd-online.com/Forums/
• > paraview -?
• Google !!!
![Page 14: WOLFSON UNIT OpenFOAM workshop 1 st November 2010 Postprocessing & the black art of scripting Sandy Wright](https://reader036.vdocuments.us/reader036/viewer/2022081506/56649d585503460f94a38724/html5/thumbnails/14.jpg)
WOLFSON UNIT
Scripting resources• http://www.python.org/• http://docs.python.org/tutorial/• http://docs.python.org/release/2.5.2/tut/tut.html• http://www.soton.ac.uk/~sesg3020/index.html
• http://www.hypexr.org/bash_tutorial.php• http://tldp.org/LDP/abs/html/
• http://www.eng.cam.ac.uk/help/tpl/unix/sed.html• http://www.grymoire.com/Unix/Sed.html