Professional Documents
Culture Documents
http://openfoamwiki.net/index.php?title=Contrib_groov...
Contrib groovyBC
From OpenFOAMWiki A library that introduces a boundary-condition groovyBC. This boundary condition is basically a mixed-BC where value, gradient and valueFraction are specied as expressions instead as elds. It can be used to set non-uniform boundary-conditions without programming. Valid versions: Note: Active development of groovyBC now takes place in swak4Foam so please have a look there for more up-to-date versions. Support for this version of groovyBC is discontinued with 2.0.
Contents
1 About 1.1 Words of warning 1.2 Pre-requisites 2 Usage 2.1 Compilation and installation 2.2 Older versions of bison 2.3 Additions to controlDict 2.4 Usage of the boundary condition 2.5 Parameters in the patch 3 Expression syntax 3.1 These C++ operators are implemented: 3.2 These pseudo-variables are dened: 3.3 These pseudo-functions are dened: 3.4 Advanced functions you're probably not going to need are: 3.5 Functions that need another eld are: 3.6 Accessing elds from other patches 4 Usage Examples 4.1 Demo-Cases 4.1.1 pulsedPitzDaily 4.1.2 wobbler 4.1.3 circulatingSplash 4.1.4 average-t-junction 4.2 User-Cases 4.2.1 groovyWaveTank 4.2.2 Swirl on inlet 4.2.3 Simple 2-Way coupling of patches 5 Technical 5.1 Other 5.2 Known Bugs
1 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
1 About
This library is provided as-is and is a permanent Beta-Version (but it works ne for me, if it doesn't for you: tell me about it and I'll see what the problem is)
1.2 Pre-requisites
To compile this utility Bison (http://www.gnu.org/software/bison/) has to be installed. The compilation is known to work with version 2.4.1. It may probably work with older versions. Check with
bison -V
on the command line before trying to compile it and report the version number when reporting a problem.
2 Usage
2.1 Compilation and installation
First, download all of the source les from the bottom of this page (see section six) Then, just do
wmake libso
in the directory of the sources. The library will be compiled and installed in a place (%FOAM_USER_LIBBIN) where it is usable
2 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
bypass could be implemented as follows: 1. rst compile the library (as described above) on a machine with the correct version of bison (call this machine A) 2. copy the entire directory of the generated les to the machine with the old version of bison (call this machine B) 3. On machine B, edit the Make/les by changing PatchValueExpressionParser.yy to PatchValueExpressionParser.C PatchValueExpressionLexer.ll to PatchValueExpressionLexer.C 4. go back to the parent directory on machine B and execute the command:
wmake libso
2.3 Additions to
controlDict
system/controlDict
of a case:
of a patch to
groovyBC
3 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
3 Expression syntax
The most complete documentation of the expression syntax is the source le for the Bisongrammar (*.yy and *.ll). Sorry.
mag dened for scalars and vectors min,max minimum and maximum of a scalar eld sum sum of the values for a scalar eld
4 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
toPoint Takes a scalar (or vector) eld dened on the faces and interpolates it to the points toFace Takes a scalar (or vector) eld dened on the points and interpolates it to the faces pos Vector eld with the face-centers pts Vector eld with the vertices normal Vector eld with the face normals Sf eld with the surface vectors (mag will give you the area) rand Scalars-eld with random numbers from [0,1] randNormal Random-number scalar eld that is Gauss-distributed deltaT a eld that returns the time-step time a eld that returns the current time
Note: Any eld names used within the which the variable is being dened.
<expression>
Note: New versions of groovyBC included with swak4Foam replace the syntax <variable
5 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
name>@<patch name> = <expression> with <variable name>{<patch name>} = <expression> A variable dened as specied above can then be utilised like an ordinary variable within other groovyBC expressions dened for the local patch.
Example: outlet1 { type groovyBC; valueExpression "0.5*(pInlet+pOutlet2)"; variables "pInlet@inlet=sum(p*mag(Sf()))/sum(mag(Sf()));pOutlet2@outlet2=p;"; value uniform 100010; }
In the above example, the variable pInlet has been dened on the remote patch inlet, and accesses the pressure and surface normal elds of the inlet patch. Likewise, the variable pOutlet2 has been dened on the remote patch outlet2, and accesses the pressure eld of the outlet2 patch. Both these remote variables are then used within the valueExpression of the local patch to determine the pressure eld to be imposed on this patch.
outlet1
It is very important to note, that no form of patch-to-patch interpolation of the elds is performed. If the number of faces on the local and remote patches are not identical, entire elds cannot be mirrored from remote patches to local patches. In the example above, the number of faces on the patch inlet is not identical to the number of faces on the local patch outlet1, and hence an area weighted average of the pressure eld is used. On the other hand, the number of faces on the remote patch outlet2 matches that of the local patch. In this case, the remote pressure eld can be directly mapped onto the local patch.
4 Usage Examples
4.1 Demo-Cases
There are four demo-cases included in the repository in a folder require a blockMesh.
Demos.
Don't try to nd experimental results for these cases. They are what the name of the folder says: Demos The three cases are 4.1.1 pulsedPitzDaily To be run with oodles. Runs the pitzDaily-case with a parabolic inlet condition that pulsates
inlet { type groovyBC; variables "yp=pts().y;minY=min(yp);maxY=max(yp);para=-(maxY-pos().y)*(pos().y-minY)/(0.25*pow(maxY-minY,2))*normal();"; valueExpression "10*(1+0.5*sin(500*time()))*para"; value uniform (10 0 0); }
6 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
inletOutlet-BC
outlet { type groovyBC; valueExpression "vector(0,0,0)"; gradientExpression "vector(0,0,0)"; fractionExpression "(phi > 0) ? 0 : 1"; value uniform (0 0 0); }
4.1.2 wobbler A solidDisplacementFoam case where a bar that is xed on one side is pushed according to a predened timeline on a fraction of the boundary (the rest is zero gradient). On the relevant patch the boundary conditon for D is
forced { type groovyBC; value uniform (0 0 0); // valueExpression "vector(0,0.1*sin(time()),0)"; timelines ( { name impulse; outOfBounds clamp; fileName "$FOAM_CASE/impulse.data"; } ); valueExpression "-impulse*normal()"; gradientExpression "vector(0,0,0)"; fractionExpression "(time()<5) ? ((pos().x>0.45 && pos().x<0.55) ? 1 : 0) : 0"; }
4.1.3 circulatingSplash A interDyMFoam-case that crashes halfway through the calculation (but looks quite nice until then). Whoever wants to x that case is welcome to do so
gamma
is set on top on a small circular part that moves around during time:
atmosphere { type groovyBC; variables "r1=0.25*(max(pts().x)-min(pts().x));r2=r1*0.2*(1-0.5*cos(54*time()));"; valueExpression "(sqrt(pow(pos().x-r1*sin(10*time()),2)+pow(pos().z-r1*cos(15*time()),2))<r2) ? 1 : 0"; value uniform 0; }
gamma:
4.1.4 average-t-junction
7 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
This is a turbFoam case, which showcases the ability of groovyBC to evaluate and access elds from remote patches (other patches present within the simulation case). The case consists of a T-junction, with one inlet and two outlets. The total-pressure at the patch inlet is varied as a function of time. The patch outlet2 has a xed pressure, whereas the pressure at the patch outlet1 is set using groovyBC to always be the average of the pressures at the inlet at outlet2 patches. The corresponding boundary conditions for
boundaryField { inlet { type timeVaryingTotalPressure; p0 100040; // only used for restarts outOfBounds clamp; fileName "$FOAM_CASE/constant/p0vsTime"; U U; phi phi; rho none; psi none; gamma 1; value uniform 100040; } outlet1 { type groovyBC; valueExpression "0.5*(pInlet+pOutlet2)"; variables "pInlet@inlet=sum(p*mag(Sf()))/sum(mag(Sf()));pOutlet2@outlet2=p;"; value uniform 100010; } outlet2 { type fixedValue; value uniform 100000; } defaultFaces { type zeroGradient; } }
are:
4.2 User-Cases
4.2.1 groovyWaveTank An example of using groovyBC to generate 2nd-order Stokes waves. It is designed to run with interFoam. For a wave with amplitude = 0.1, and wavelength = 5, gamma is set on the inlet:
inlet { type valueExpression variables timelines }
8 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
is set using:
A test case can be downloaded from: groovyWaveTank.tgz (http://idisk.mac.com/egpatersonPublic/groovyWaveTank.tgz) . As usual, run blockMesh, setFields, and interFoam. 4.2.2 Swirl on inlet Here's an example of how you can specify a swirl on the inlet. You only need to specify 2 parameters, Un and rpm, where Un is the normal velocity and rpm is the rotational speed.
inlet { type groovyBC; variables "rpm=8000.0;Un=55.8;c=sum(pos()*mag(Sf()))/sum(mag(Sf()));n=sum(normal())/mag(sum(normal()));p=pos()-c; valueExpression "-Un*normal() + (rpm*pi/30)*((p & yT)*xT - (p & xT)*yT)"; }
c is the centre of the patch, n is the averaged patch normal. You can easily extend it to have a variation on the patch normal component, for instance a parabolic inlet would only require the addition of *(1-pow(r/R,2)) to Un*normal(). The only time this will not work is when n is equal to (0,0,1), then you need another transformation, for instance this one (which will not work when swirl is around (1,0,0))
inlet { type groovyBC; variables "rpm=8000.0;Un=55.8;c=sum(pos()*mag(Sf()))/sum(mag(Sf()));n=sum(normal())/mag(sum(normal()));p=pos()-c; valueExpression "-Un*normal() + (rpm*pi/30)*((p & yT)*xT - (p & xT)*yT)"; }
4.2.3 Simple 2-Way coupling of patches This is an example of using groovyBC for creating a simple 2-Way coupling between two patches, such that it acts as more or less, one continuously connected mesh during the simulation. As the title species, it is a very limited and simplistic approach to the complex concept of full 2-Way patch to patch coupling, but is sucient in a lot of situations. Some applications where this approach would make sense (feel free to add or detract from this list): Cases where only the mean values of the variables at the respective patches are of importance, and not the actual spatial distribution (unless both patches have exactly the same number of faces of course). Cases where physically connecting up the two patches would add on an unnecessarily large number of cells resulting in a bloated up mesh.
9 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
Situations where eld values need to be modied by a simple mathematical model of some device connected between the two patches which does not necessarily need to be simulated using CFD. A way of showing o some of the cool features of groovyBC ;-) and so on... The example uses the simpleFoam solver, and consists of three completely unconnected mesh regions say, A, B and C. Each mesh region contains two patches as listed below:
Region A: inlet ; interface11 Region B: interface12 ; interface21 Region C: interface22 ; outlet
The pressure (p) and velocity (U) elds of the following sets of patches are coupled to each other using groovyBC, with the aim of emulating a continuous mesh without any breaks:
interface11 :: interface12 interface21 :: interface22
The system uses pressure driven ow, and the pressure at the patch inlet is ramped up from 10 bar to 35 bar over 50 iterations (the ramp is used for a softer start), and held constant thereafter. The pressure at the patch outlet is held constant at 10 bar. The case uses the k-epsilon turbulence model. Here is an excerpt of the
interface11 { type variables valueExpression value } interface12 { type } interface21 { type variables valueExpression value } interface22 { type }
pressure
boundary conditions:
zeroGradient;
zeroGradient;
At patch interface11, the area weighted average of the pressure eld on patch interface12 is used. However, instead of directly imposing the value of the pressure, it is introduced through a relaxation factor which was required to ensure stability of the simulation. A similar set up can be seen also for the patch interface21. The corresponding
interface11
velocity
10 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
type zeroGradient; } interface12 { type groovyBC; variables "Q_int11@interface11=-1*sum(phi);Q_int12=sum(phi);U_relax=0.3;"; valueExpression "(Q_int12 + U_relax*(Q_int11 - Q_int12))/sum(mag(Sf()))*normal()"; fractionExpression "(phi > 0) ? 0 : 1" value $internalField; } interface21 { type zeroGradient; } interface22 { type groovyBC; variables "Q_int21@interface21=-1*sum(phi);Q_int22=sum(phi);U_relax=0.3;"; valueExpression "(Q_int22 + U_relax*(Q_int21 - Q_int22))/sum(mag(Sf()))*normal()"; fractionExpression "(phi > 0) ? 0 : 1" value $internalField; }
Here, the coupling is done in the opposite direction, with the total ow at the patch interface11 being imposed on the patch interface12 again, through a relaxation factor in order to ensure stability as the simulation evolves. A similar set up can be observed also for the patch interface22. In addition, it should be noted, that in this particular case, an inletOutlet boundary condition has been emulated. The complete simulation case can be downloaded from: groovyBC_2Way_coupling_001.tgz (http://docs.google.com /leaf?id=0B0syP1Z1w2s1MWYxMzE4ZTEtODY4Zi00MjBiLTg1YTMtNDk1ODViNGM5NWVj& hl=en_GB) (let me know if the link does not work) This case does not use blockMesh, and the mesh has already been imported and set up. Either use the Allrun script, or simply run simpleFoam from within the case root. As always, feedback (good, bad and ugly) is always welcome :-)
5 Technical
the BC only works for fvPatchFields but can "read" point and face-elds too it also works for pointPatchFields. Please note that constants must be enclosed in otherwise they will be dened as face-values
toPoint,
5.1 Other
The parser-part can be used in other boundary conditions (that are not covered by the mixed-BC). x, X, y, Y, z, Z can NOT be used as variables, since they are symbols for the parser.
11 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
6 Download
Valid versions: - For the very latest version, see swak4Foam.
Valid versions:
7 Plans
allow expressions for tensors allow "permanent" variables implement the BC for face-elds
8 History
2009-02-19: Initial upload
Retrieved from "http://openfoamwiki.net/index.php?title=Contrib_groovyBC&oldid=12481" Categories: OpenFOAM Version 1.5 OpenFOAM Version 1.6 OpenFOAM Version 1.7 FeaturedArticle OpenFOAM Version 2.0 OpenFOAM Version 2.1 This page was last modied on 27 August 2012, at 23:52. This page has been accessed 42,726 times. Content is available under GNU Free Documentation License 1.3.
12 of 13
11/13/2012 11:30 AM
http://openfoamwiki.net/index.php?title=Contrib_groov...
13 of 13
11/13/2012 11:30 AM