|
[Sponsors] |
January 31, 2017, 09:32 |
Passing envars to dictionary's
|
#1 |
Member
Victor Koppejan
Join Date: May 2015
Posts: 40
Rep Power: 11 |
Hi everyone,
I was wondering if there's a way to pass environment variables to OpenFOAM discitonaries. For instance, say I define ndoms = 4 (via export ndoms = 4), could I somehow use $ndoms in the decomposeParDict? I start my runs from slurm so all var's are defined for a single simulation only. Cheers, Victor |
|
January 31, 2017, 09:43 |
|
#2 |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20 |
I use "pyFoamFromTemplate.py" in a "prepareScript.sh" script to substitute variables into dictionaries.
Parameters I specify in a local file called "params.sh", but environmental variables are possible as well, as long as you define what I called "PARAMS_SETFIELD". Minimal example: ./params.sh: Code:
# Geometry Wz=`echo "2*0.005" | bc -l` Gamma=0.5 Wx=`echo "$Wz*$Gamma" | bc -l` Wy=$Wx # Bubble h_b=`echo "0.1*$Wz" | bc -l` # initial bubble height r_b=`echo "0.05*$Wz" | bc -l` # initial bubble radius x_b=`echo "$Wx/2" | bc -l` y_b=$x_b # (...) PARAMS_SETFIELD="{'x_b':$x_b,'y_b':$y_b,'h_b':$h_b,'r_b':$r_b}" Code:
usage() { echo " Usage: $0" echo " A file named \"params.sh\" should be in your cwd. " exit; } #### ####### ##### #### PARAMETERS ##### if [ -f "./params.sh" ]; then . ./params.sh else usage fi # (...) pyFoamFromTemplate.py ./system/setFieldsDict $PARAMS_SETFIELD || exit 1 # (...) # setFields echo "----> setFields" mv "0/alpha.water.org" "0/alpha.water" setFields > ./logs/setFields.log || exit 1 Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 4.0 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object setFieldsDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // defaultFieldValues ( volScalarFieldValue alpha.water 1 ); regions ( sphereToCell { centre ($x_b$ $y_b$ $h_b$); radius $r_b$; fieldValues ( volScalarFieldValue alpha.water 0 ); } ); // ************************************************************************* // |
|
January 31, 2017, 10:42 |
|
#3 |
Member
Victor Koppejan
Join Date: May 2015
Posts: 40
Rep Power: 11 |
Looks nice, I haven't scripted OF with python before but this looks clever.
Cheers, Victor |
|
January 31, 2017, 10:47 |
|
#4 | |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20 |
Quote:
That... Or I like writing code more than typing parameters and running a case. Note though, I did not actually write any python myself here. Of course, pyFoam is a python library, but all I did was write bash. |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CFD by anderson, chp 10.... supersonic flow over flat plate | varunjain89 | Main CFD Forum | 18 | May 11, 2018 07:31 |
Retrieve query point coordonate to create a plane passing through this point. | potofus | EnSight | 2 | April 6, 2016 07:26 |
Finding the number of particles passing through a plane in a transient DPM simulation | tengteng | FLUENT | 2 | February 10, 2016 02:25 |
Inlet passing wake | sherifkadry | OpenFOAM | 0 | June 26, 2012 20:04 |
gambit meshing for the flow passing cylinder | iilw1314 | Main CFD Forum | 5 | April 11, 2010 19:28 |