Difference between revisions of "OpenFOAM/C3/Using-Template-files-in-PyFoam/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 13: Line 13:
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Title
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Title
| style="border:0.25pt solid #000000;padding:0cm;"| Hello and welcome to the Spoken Tutorial on '''Using Template files in PyFoam.'''
+
| style="border:0.25pt solid #000000;padding:0cm;"| Hello and welcome to the spoken tutorial on '''Using Template files in PyFoam.'''
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide : Learning Objective
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide : Learning Objective
 
| style="border:0.25pt solid #000000;padding:0cm;"| In this tutorial we will:
 
| style="border:0.25pt solid #000000;padding:0cm;"| In this tutorial we will:
 +
  
 
* Understand the function of '''PyFoam Utilities'''
 
* Understand the function of '''PyFoam Utilities'''
Line 28: Line 29:
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide : System requirement
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide : System requirement
 
| style="border:0.25pt solid #000000;padding:0cm;"| To record this tutorial I am using
 
| style="border:0.25pt solid #000000;padding:0cm;"| To record this tutorial I am using
 +
  
 
* '''Ubuntu Linux '''Operating System 14.04
 
* '''Ubuntu Linux '''Operating System 14.04
 
* '''OpenFOAM''' 2.3.0
 
* '''OpenFOAM''' 2.3.0
 
* '''PyFoam-0.6.5'''
 
* '''PyFoam-0.6.5'''
 +
 +
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Prerequisite
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Prerequisite
 
| style="border:0.25pt solid #000000;padding:0cm;"| To practice this tutorial the user should have :
 
| style="border:0.25pt solid #000000;padding:0cm;"| To practice this tutorial the user should have :
 +
  
 
* Basic Knowledge of using '''Linux terminal'''
 
* Basic Knowledge of using '''Linux terminal'''
 
* Experience of running and analyzing '''OpenFOAM '''cases
 
* Experience of running and analyzing '''OpenFOAM '''cases
  
If not, please refer to the spoken tutorial series on '''Linux '''and '''OpenFOAM'''.
+
If not, please refer to the spoken tutorial series on '''Linux '''and
 +
 
 +
'''OpenFOAM'''.
  
 
|-
 
|-
Line 49: Line 56:
  
 
'''blockMeshDict or controlDict'''
 
'''blockMeshDict or controlDict'''
 +
  
 
'''Template '''files can be programmed, hence we can procedurally generate data.
 
'''Template '''files can be programmed, hence we can procedurally generate data.
 +
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Syntax of Template files
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Syntax of Template files
Line 78: Line 87:
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type '''run/tutorials/compres sible/rhoCentralFoam'''
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type '''run/tutorials/compres sible/rhoCentralFoam'''
 
| style="border:0.25pt solid #000000;padding:0cm;"| Open the '''terminal'''.
 
| style="border:0.25pt solid #000000;padding:0cm;"| Open the '''terminal'''.
 +
  
 
Type the '''path '''for the '''rhoCentralFoam '''inside '''compressible solvers.'''
 
Type the '''path '''for the '''rhoCentralFoam '''inside '''compressible solvers.'''
Line 87: Line 97:
  
 
'''/home/fossee/OpenFO AM/'''
 
'''/home/fossee/OpenFO AM/'''
| style="border:0.25pt solid #000000;padding:0cm;"| Now copy the '''Wedge5M15 case directory '''into '''OpenFOAM directory'''
+
| style="border:0.25pt solid #000000;padding:0cm;"| Now copy the '''Wedge15Ma5 case directory '''into '''OpenFOAM directory'''
  
 
by typing
 
by typing
  
'''cp -r Wedge5M15 /home/fossee/OpenFOAM/ '''and press '''Enter.'''
+
''' mkdir -p ~/fossee/OpenFOAM/'''
 +
'''cp -r Wedge15Ma5 ~/fossee/OpenFOAM/ '''and press '''Enter.'''
  
 
|-
 
|-
Line 101: Line 112:
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type '''cd constant/polyMesh/bl ockMeshDict'''
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type '''cd constant/polyMesh/bl ockMeshDict'''
| style="border:0.25pt solid #000000;padding:0cm;"| Type the '''path '''for '''blockMeshDict file '''inside '''polyMesh directory '''inside '''constant.'''
+
| style="border:0.25pt solid #000000;padding:0cm;"| Type the '''path '''for '''blockMeshDict file '''inside '''polyMesh directory '''inside
 +
 
 +
'''constant.'''
  
 
|-
 
|-
Line 131: Line 144:
  
 
'''ate'''
 
'''ate'''
| style="border-top:0.25pt solid #000000;border-bottom:none;border-left:0.25pt solid #000000;border-right:0.25pt solid #000000;padding:0cm;"| Switch back to the '''terminal'''.
+
| style="border-top:0.25pt solid #000000;border-bottom:none;border-left:0.25pt solid #000000;border-right:0.25pt solid #000000;padding:0cm;"| Switch back to the terminal
  
Copy your '''blockMeshDict '''file into a file called '''blockMeshDict.template.'''
+
Copy your '''blockMeshDict '''file into a file called
  
Type the following-
+
'''blockMeshDict.template, '''type the following-
  
 
'''cp -r blockMeshDict > blockMeshDict.template'''
 
'''cp -r blockMeshDict > blockMeshDict.template'''
  
 
|-
 
|-
| style="border:0.25pt solid #000000;padding:0cm;"| gedit blockMeshDict.template
+
| style="border:0.25pt solid #000000;padding:0cm;"| gedit blockMeshDict.templat e
| style="border:0.25pt solid #000000;padding:0cm;"| Open the '''blockMeshDict.template''' file using '''gedit'''.
+
| style="border:0.25pt solid #000000;padding:0cm;"| Open the blockMeshDict.template file using gedit
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Template file syntax
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Template file syntax
| style="border:0.25pt solid #000000;padding:0cm;"| Add the following lines above '''convertToMeters'''
+
| style="border:0.25pt solid #000000;padding:0cm;"| '''Add the following lines above convertToMeters'''
 +
 
  
 
'''$$import math'''
 
'''$$import math'''
Line 156: Line 170:
  
  
Any line preceded with '''$$ '''is a '''Python '''line, and will be interpreted and executed by '''Python'''
+
Any line preceded with '''$$ '''is a '''Python '''line, and will be interpreted and
 +
 
 +
|-
 +
| style="border:0.25pt solid #000000;padding:0cm;"|
 +
| style="border:0.25pt solid #000000;padding:0cm;"| executed by '''Python'''
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Template file syntax
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Template file syntax
 
| style="border:0.25pt solid #000000;padding:0cm;"| Modify the '''vertices '''entry as
 
| style="border:0.25pt solid #000000;padding:0cm;"| Modify the '''vertices '''entry as
 +
  
 
'''( 0.3048 |-y_coord-| -0.005)'''
 
'''( 0.3048 |-y_coord-| -0.005)'''
 +
  
 
'''( 0.3048 |-y_coord-| 0.005)'''
 
'''( 0.3048 |-y_coord-| 0.005)'''
Line 179: Line 199:
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"|  
 
| style="border:0.25pt solid #000000;padding:0cm;"|  
| style="border:0.25pt solid #000000;padding:0cm;"| Now, let's create a blank file.
+
| style="border:0.25pt solid #000000;padding:0cm;"| Now, let's create a blank file
  
 
|-
 
|-
Line 188: Line 208:
 
| style="border:0.25pt solid #000000;padding:0cm;"| templateFileConst
 
| style="border:0.25pt solid #000000;padding:0cm;"| templateFileConst
 
| style="border:0.25pt solid #000000;padding:0cm;"| Create a dummy entry inside it by typing
 
| style="border:0.25pt solid #000000;padding:0cm;"| Create a dummy entry inside it by typing
 +
  
 
'''dummy 1.0;'''
 
'''dummy 1.0;'''
 +
  
 
A dummy entry is mandatory.
 
A dummy entry is mandatory.
 +
  
 
An external '''dict '''has to be provided with any '''constant '''that is to be used in the '''template '''file.
 
An external '''dict '''has to be provided with any '''constant '''that is to be used in the '''template '''file.
Line 197: Line 220:
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Press Ctrl+S and close
 
| style="border:0.25pt solid #000000;padding:0cm;"| Press Ctrl+S and close
| style="border:0.25pt solid #000000;padding:0cm;"| Save and close the file.
+
| style="border:0.25pt solid #000000;padding:0cm;"| Save and close the both the files
 +
 
 +
|-
 +
| style="border:0.25pt solid #000000;padding:0cm;"| cd ../../
 +
| style="border:0.25pt solid #000000;padding:0cm;"| Now go 2 levels back to your '''case '''file.
 +
 
 +
|-
 +
| style="border:0.25pt solid #000000;padding:0cm;"| Switch back to slides
 +
| style="border:0.25pt solid #000000;padding:0cm;"| Let me switch back to slides
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Running PyFoam command
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Running PyFoam command
| style="border:0.25pt solid #000000;padding:0cm;"| We have to run the '''template''' command now.
+
| style="border:0.25pt solid #000000;padding:0cm;"| We have to run the template command now.
 +
 
  
 
'''pyFoamFromTemplate.py --template-file<nowiki>=</nowiki>./blockMeshDict.template'''
 
'''pyFoamFromTemplate.py --template-file<nowiki>=</nowiki>./blockMeshDict.template'''
Line 212: Line 244:
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type this command in '''terminal '''>> press '''Enter'''
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type this command in '''terminal '''>> press '''Enter'''
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type this command in '''terminal '''and press '''Enter'''
 
| style="border:0.25pt solid #000000;padding:0cm;"| Type this command in '''terminal '''and press '''Enter'''
 +
 +
|-
 +
| style="border:0.25pt solid #000000;padding:0cm;"| Type '''cd constant/polyMesh'''
 +
| style="border:0.25pt solid #000000;padding:0cm;"| Now again go inisde the '''polyMesh folder '''inside '''constant'''
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Point to '''blockMeshDict '''and a python file
 
| style="border:0.25pt solid #000000;padding:0cm;"| Point to '''blockMeshDict '''and a python file
| style="border:0.25pt solid #000000;padding:0cm;"| We can see that 2 new files are generated.
+
| style="border:0.25pt solid #000000;padding:0cm;"| We can see that
 +
 
 +
* 2 new files are generated
 +
* the '''blockMeshDict.template '''file is replaced by '''blockMeshDict'''
 +
* and '''.py '''file is also generated.
  
  
The '''blockMeshDict ''' and a '''Python '''file is also generated.
 
  
 
|-
 
|-
Line 232: Line 271:
 
| style="border:0.25pt solid #000000;padding:0cm;"| In the '''terminal''', open the '''blockMeshDict '''file by typing -
 
| style="border:0.25pt solid #000000;padding:0cm;"| In the '''terminal''', open the '''blockMeshDict '''file by typing -
  
'''gedit blockMeshDict '''and press '''Enter.'''
+
|-
 +
| style="border:0.25pt solid #000000;padding:0cm;"|
 +
| style="border:0.25pt solid #000000;padding:0cm;"| '''gedit blockMeshDict '''and press '''Enter.'''
  
 
|-
 
|-
Line 249: Line 290:
 
* '''rhoCentralFoam'''
 
* '''rhoCentralFoam'''
 
* visualize the results using '''Paraview.'''
 
* visualize the results using '''Paraview.'''
 +
 +
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Assignment
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Assignment
| style="border:0.25pt solid #000000;padding:0cm;"| As an assignment, use the following '''wedge angles '''and run the '''template''' commands.
+
| style="border:0.25pt solid #000000;padding:0cm;"| As an assignment, use the following '''wedge angles '''and run the '''template'''
 +
 
 +
commands.
 +
 
  
 
- '''0deg, 5 deg, 20 deg, 25 deg'''
 
- '''0deg, 5 deg, 20 deg, 25 deg'''
Line 259: Line 305:
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Summary
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show slide : Summary
 
| style="border:0.25pt solid #000000;padding:0cm;"| Let us summarize.
 
| style="border:0.25pt solid #000000;padding:0cm;"| Let us summarize.
 +
  
 
In this tutorial, we learnt about '''PyFoam Template'''
 
In this tutorial, we learnt about '''PyFoam Template'''
 +
  
 
We also learnt to-
 
We also learnt to-
Line 266: Line 314:
 
# check the installation of '''script for using template'''
 
# check the installation of '''script for using template'''
 
# and using the '''PyFoamFromTemplate.py '''command
 
# and using the '''PyFoamFromTemplate.py '''command
 +
 +
  
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide
 +
  
 
Forum to answer questions
 
Forum to answer questions
Line 275: Line 326:
 
|-
 
|-
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide
 +
  
 
Forum to answer questions
 
Forum to answer questions
Line 286: Line 338:
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide Acknowledgement
 
| style="border:0.25pt solid #000000;padding:0cm;"| Show Slide Acknowledgement
 
| style="border:0.25pt solid #000000;padding:0cm;"| The Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India
 
| style="border:0.25pt solid #000000;padding:0cm;"| The Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India
 +
  
 
For more details , visit this website.
 
For more details , visit this website.

Revision as of 17:29, 8 February 2017

Tutorial 21: C2

Title : Using Template files in PyFoam Script : Anmol Sahoo, Rahul Joshi Narration : Rahul Joshi

Keywords : OpenFOAM, PyFoam, Python, Template, supersonic flow, wedge


Visual Cue
Narration
Show slide : Title Hello and welcome to the spoken tutorial on Using Template files in PyFoam.
Show Slide : Learning Objective In this tutorial we will:


  • Understand the function of PyFoam Utilities
  • Create and use template files
  • Use PyFoamFromTemplate.py for solving the supersonic flow over wedge

We can run this for different wedge angles using template files.

Show Slide : System requirement To record this tutorial I am using


  • Ubuntu Linux Operating System 14.04
  • OpenFOAM 2.3.0
  • PyFoam-0.6.5


Show slide : Prerequisite To practice this tutorial the user should have :


  • Basic Knowledge of using Linux terminal
  • Experience of running and analyzing OpenFOAM cases

If not, please refer to the spoken tutorial series on Linux and

OpenFOAM.

Show slide : Template Files What are template files?

Template files are used to generate OpenFOAM files like

blockMeshDict or controlDict


Template files can be programmed, hence we can procedurally generate data.

Show slide : Syntax of Template files A template file should be an OpenFOAM file, with the following -
  • Any line beginning with $$ is a Python program line.
  • It will be executed by Python
  • Any variable can be substituted in the file by using the syntax

| -varname - |

Show slide : Using a template file The following steps should be followed to use a template file :
  • First copy an existing file
  • After this create a template file
  • Then run PyFoamFromTemplate.py
Show slide : Creating a template file Template file will be created for blockMeshDict.

We will use the supersonic flow over a wedge as an example case. The case file is available in the rhoCentralFoam solver.

Type run/tutorials/compres sible/rhoCentralFoam Open the terminal.


Type the path for the rhoCentralFoam inside compressible solvers.

Type

cp -r Wedge5M15

/home/fossee/OpenFO AM/

Now copy the Wedge15Ma5 case directory into OpenFOAM directory

by typing

mkdir -p ~/fossee/OpenFOAM/ cp -r Wedge15Ma5 ~/fossee/OpenFOAM/ and press Enter.

Cd OpenFOAM/Wedge5 M15 On the terminal, type the path for Wedge5M15 folder inside

OpenFOAM directory.

Type cd constant/polyMesh/bl ockMeshDict Type the path for blockMeshDict file inside polyMesh directory inside

constant.

Type gedit blockMeshDict Open the blockMeshDict file in any editor of your choice.
Point to the vertices section We can see the vertices section.
Show slide : vertices to

be changed

We need to calculate the co-ordinates of the end points of the slope.

Based on the angle, change the following lines

( 0.3048 0.081670913853 -0.005)

( 0.3048 0.081670913853 0.005)

On the terminal type

cp -r blockMeshDict >

blockMeshDict.templ

ate

Switch back to the terminal

Copy your blockMeshDict file into a file called

blockMeshDict.template, type the following-

cp -r blockMeshDict > blockMeshDict.template

gedit blockMeshDict.templat e Open the blockMeshDict.template file using gedit
Show slide : Template file syntax Add the following lines above convertToMeters


$$import math

$$thetaDegrees = 10.0

$$thetaRadians = math . radians ( thetaDegrees )

$$y_coord = 0.3048* math . tan ( thetaRadians )


Any line preceded with $$ is a Python line, and will be interpreted and

executed by Python
Show slide : Template file syntax Modify the vertices entry as


( 0.3048 |-y_coord-| -0.005)


( 0.3048 |-y_coord-| 0.005)

Python variables assigned in the template file, should be substituted at any location in the file.


To do so, use | −varname− | in the file.

Highlight or point to the changes We can see the changes made into this file.
Now, let's create a blank file
Type gedit templateFileConst On the terminal, type gedit templateFileConst and press Enter.
templateFileConst Create a dummy entry inside it by typing


dummy 1.0;


A dummy entry is mandatory.


An external dict has to be provided with any constant that is to be used in the template file.

Press Ctrl+S and close Save and close the both the files
cd ../../ Now go 2 levels back to your case file.
Switch back to slides Let me switch back to slides
Show slide : Running PyFoam command We have to run the template command now.


pyFoamFromTemplate.py --template-file=./blockMeshDict.template

--output=./blockMeshDict --values-dictionary=templateFileConst

--allow-exec-instead-of-assignment

Type this command in terminal >> press Enter Type this command in terminal and press Enter
Type cd constant/polyMesh Now again go inisde the polyMesh folder inside constant
Point to blockMeshDict and a python file We can see that
  • 2 new files are generated
  • the blockMeshDict.template file is replaced by blockMeshDict
  • and .py file is also generated.


Point to the Python

file.

Do not edit the Python file.
On the terminal type

gedit blockMeshDict

In the terminal, open the blockMeshDict file by typing -
gedit blockMeshDict and press Enter.
Point to wedge angle We had changed the wedge angle from 15 deg to 10 deg.
Point to end points The end points of the slope have also changed.
Show slide :Running the case file We can now run the case file by executing the OpenFOAM commands
  • blockMesh
  • rhoCentralFoam
  • visualize the results using Paraview.


Show slide : Assignment As an assignment, use the following wedge angles and run the template

commands.


- 0deg, 5 deg, 20 deg, 25 deg

Show slide : Summary Let us summarize.


In this tutorial, we learnt about PyFoam Template


We also learnt to-

  1. check the installation of script for using template
  2. and using the PyFoamFromTemplate.py command


Show Slide


Forum to answer questions

Please post your timed queries in this forum.
Show Slide


Forum to answer questions

Please post your general queries on OpenFOAM in this forum.
Show Slide Textbook Companion The FOSSEE team coordinates the TBC project.
Show Slide Acknowledgement The Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India


For more details , visit this website.

Thank You This is Rahul Joshi from IIT Bombay signing off. Thanks for watching

Contributors and Content Editors

Nancyvarkey, Viraj20feb