|
[Sponsors] |
[blockMesh] Writing if else statement in the blockMeshDict file |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 3, 2020, 03:18 |
Writing if else statement in the blockMeshDict file
|
#1 |
New Member
Duc Anh
Join Date: Dec 2018
Posts: 22
Rep Power: 8 |
Hi foamers,
I want to create an if-else statement in my definition of sin alpha and cos alpha in file blockMeshDict, show that lt changes according to a user-defined. I was tried code#{#}; below but it seems not to work( Do Not display line 0.0 and cosAlpha sill constant) Code:
/* *P / || \ / \ |P-2| = innerRadius / \ <P' P 2> = bendingAngle 3 P' 2 |2-1| = |1-0| =R1R2= width/2 / _ _\ / _ _ \ / _23_ \ 4 1 / _ _ \ / _ _ \ / _ 14 _ \ 5 0 _ _ _ _ _ 05 _ */ convertToMeters 1; mesh { bendingAngle 111;// 8.18; // >100 convert to rectangular innerRadius 4; R1R2 1; //inter radius to outer radius nCells_x 10; nCells_y 55; nCells_z 20; length 5; } parameters { width $:mesh.R1R2; innerR $:mesh.innerRadius; outerR #calc "$innerR + $width"; CAD $:mesh.bendingAngle; // channel angle in degree CAR #calc "degToRad($CAD)/2.0"; // channel angle in radian sinAlpha #calc "sin($CAR)"; cosAlpha #calc "cos($CAR)"; code #{ if($:mesh.bendingAngle >= 100) cosAlpha 1; #calc "Info<<0.0<<endl"; #calc "Info<<$cosAlpha << endl"; #}; #calc "Info<<0.1<<endl"; #calc "Info<<$cosAlpha << endl"; Code:
0.1 Using #calcEntry at line 63 in file "/home/anh/ducanhvan/fe40/dev/PNPNSFoam/StudyCases/r_4/r_4_mesh/constant/polyMesh/blockMeshDict.parameters" Using #codeStream with "/home/anh/ducanhvan/fe40/dev/PNPNSFoam/StudyCases/r_4/r_4_mesh/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_c1492ef6f3c1453e058e87865d31757234430ca9.so" 0.566406 |
|
December 3, 2020, 13:43 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
First, remember that the #{ .. #} blocks indicate verbatim text. This is taken directly, without any string expansions or anything. Additionally, you have attempted to embed a #calc with an extra output within something that you already want to have treated as a block of C++ code.
You will need to rework things. You are just trying too many things at once. BTW: if you have OpenFOAM-v1912 or v2006, you will find that the #eval statement is much, much faster that compiling a #calc. Additionally, you can do really weird things with "${{ .. }}" syntax to embed calculations in other strings. If you test the tutorials/combustion/XiDyMFoam/annularCombustorTurbine blockMesh with the #eval vs #calc, you will see the difference. Can also take a look at applications/test/exprEntry/testDict1 for some weird things. https://develop.openfoam.com/Develop...de#expressions https://www.openfoam.com/documentati...on-syntax.html |
|
December 5, 2020, 07:59 |
|
#3 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Have you tried it with changing to #eval?
I think the following should work (only showing the second dictionary) Code:
parameters { width $:mesh.R1R2; innerR $:mesh.innerRadius; outerR #eval{ $innerR + $width }; CAD $:mesh.bendingAngle; // channel angle in degree sinAlpha #eval{ sin(degToRad($CAD)) }; cosAlpha #eval "cos(degToRad($CAD))"; #if #eval{ $:mesh.bendingAngle >= 100 /* upper limit */ } cosAlpha 1; #endif } |
|
December 7, 2020, 04:49 |
|
#4 | |
New Member
Duc Anh
Join Date: Dec 2018
Posts: 22
Rep Power: 8 |
Quote:
Code:
Unknown functionEntry 'eval' in "/home/anh/ducanhvan/fe40/devfe40/StudyCases/r_4_small10_rec/constant/polyMesh/blockMeshDict" near line 80 Valid functionEntries are : 5 ( codeStream include calc includeIfPresent includeEtc ) |
||
December 13, 2020, 06:45 |
|
#5 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
I am clearly biased towards using #eval (which I put into OpenFOAM-v1912). You can possibly do some of this with #calc too (although less efficient) but you may need to be careful with what the #if receives.
|
|
Tags |
blockmeshdict, codestream, if-else statement |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 | Seroga | OpenFOAM Community Contributions | 9 | June 12, 2015 18:18 |
[snappyHexMesh] crash sHM | H25E | OpenFOAM Meshing & Mesh Conversion | 11 | November 10, 2014 12:27 |
centOS 5.6 : paraFoam not working | yossi | OpenFOAM Installation | 2 | October 9, 2013 02:41 |
ParaView Compilation | jakaranda | OpenFOAM Installation | 3 | October 27, 2008 12:46 |
DxFoam reader update | hjasak | OpenFOAM Post-Processing | 69 | April 24, 2008 02:24 |