Contrib groovyBC - OpenFOAMWikihttp://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 specified as expressions instead as fields. 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 defined: 3.3 These pseudo-functions are defined: 3.4 Advanced functions you're probably not going to need are: 3.5 Functions that need another field are: 3.6 Accessing fields 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 Contrib groovyBC . but not necessarily the best tool for these tasks) 1.1.1 Compilation and installation First.php?title=Contrib_groov. The library will be compiled and installed in a place (%FOAM_USER_LIBBIN) where it is usable 2.org/software/bison/) has to be installed. but you should be familiar with the C++ expression syntax it makes it easier to 'shoot yourself in the foot' (do stupid things) especially for large cases a custom-made library might be more efficient (it's like a Swiss Army Knife: useful for a lot of things.net/index.. It may probably work with older versions. if it doesn't for you: tell me about it and I'll see what the problem is) 1. Check with bison -V on the command line before trying to compile it and report the version number when reporting a problem. just do wmake libso in the directory of the sources. The compilation is known to work with version 2..3 Bug reporting 6 Download 7 Plans 8 History 1 About This library is provided as-is and is a permanent Beta-Version (but it works fine for me. 5. the compilation sometimes fails. A makeshift 2 of 13 11/13/2012 11:30 AM .1 Words of warning This library can save you the work to program your own boundary-conditions.4.OpenFOAMWiki http://openfoamwiki.gnu.2 Older versions of bison For systems with older versions of bison.2 Pre-requisites To compile this utility Bison (http://www. 2 Usage 2. download all of the source files from the bottom of this page (see section six) Then. (might cause a Floating Point Exception) gradientExpression String with the gradient to be used if a Neumann conditon is needed. If "valueExpression" is specified without setting "value".Contrib groovyBC . Currently only scalars are allowed. Defaults to zero fractionExpression Determines whether the face is Dirichlet (1) or Neumann (0).so" ) ..ll to PatchValueExpressionLexer.so" "libgroovyBC.net/index. value is also used for the first timestep/iteration if "valueExpression" is specified. libs ( "libOpenFOAM. copy the entire directory of the generated files to the machine with the old version of bison (call this machine B) 3. See the original timeVaryingUniform-condition.C PatchValueExpressionLexer.yy to PatchValueExpressionParser. May make the writing of expressions shorter. edit the Make/files by changing PatchValueExpressionParser. The name "shadows" fields of the same name 3 of 13 11/13/2012 11:30 AM .php?title=Contrib_groov. On machine B. The parameter name specifies the name under which this may be accessed.C 4. 0 is taken for the first timestep/iteration. Names defined here "shadow" fields of the same name timelines List with subdictionaries that specify interpolation tables over time. 2.. of a case: If you are experiencing problems with paraFoam try this combination.4 Usage of the boundary condition Just set the type of a patch to groovyBC 2. go back to the parent directory on machine B and execute the command: wmake libso 2.3 Additions to controlDict system/controlDict A function object is activated by adding an entry like this to the libs ( "libgroovyBC.so" ) . Defaults to zero value is used if no "valueExpression" is given.OpenFOAMWiki http://openfoamwiki.5 Parameters in the patch valueExpression String with the value to be used if a Dirichlet-condition is needed. Defaults to empty. first compile the library (as described above) on a machine with the correct version of bison (call this machine A) 2. bypass could be implemented as follows: 1. Defaults to 1 variables List with temporary variables separated by a semicolon. sqrt.|| Logical Operators Conditional operator The conditional operator (http://en.2 These pseudo-variables are defined: pi Guess .ll). All the fields that are defined on the patch can be used.*. 3 Expression syntax The most complete documentation of the expression syntax is the source file for the Bisongrammar (*.1 These C++ operators are implemented: +.sin.OpenFOAMWiki http://openfoamwiki. 3.tan Only defined for scalars example: x^y = pow(x.yy and *.== Comparison operators (only defined for scalars) &&.3 These pseudo-functions are defined: 4 of 13 11/13/2012 11:30 AM .wikipedia. 3.cos.-. please test for yourself .exp.Contrib groovyBC .net/index. Can be used for vectors and scalars (only if useful.org/wiki/%3F:#Conditional_assignment) ( test ? val1 : val2) is defined for scalars and vectors Operator precedence should be the same as for C++.>=. If the field is also the field that this is a BC for the old value is used.for most applications of this operator this is in my opinion the more practical implementation) &.log.max minimum and maximum of a scalar field sum sum of the values for a scalar field 3.) These functions are defined: pow.sqr.<=.if you don't understand what I mean.. Sorry. For instance: vectors can't be added to scalars) % A modulo-operator.>.. Somehow differently defined from the standard C++ %-operator: the value of (x − ε) % x is − ε (not x − ε ./ Arithmetic operators.y) mag defined for scalars and vectors min.!=.php?title=Contrib_groov.^ The vector operators as defined by OpenFOAM <. 4 Advanced functions you're probably not going to need are: Cn neighbour cell centers of the patch delta Return cell-centre to face-centre vector weights Return patch weighting factors 3. The syntax for this feature is: <variable name>@<patch name> = <expression> Note: Any field names used within the which the variable is being defined..net/index.6 Accessing fields from other patches groovyBC provides the ability to access fields from remote patches (other patches present within the current simulation).Contrib groovyBC . <expression> refer to fields local to the remote patch on Note: New versions of groovyBC included with swak4Foam replace the syntax <variable 5 of 13 11/13/2012 11:30 AM .5 Functions that need another field are: snGrad Gradient of that field internalField internal values of that field neighbourField neighbour values for a coupled patch 3. toPoint Takes a scalar (or vector) field defined on the faces and interpolates it to the points toFace Takes a scalar (or vector) field defined on the points and interpolates it to the faces pos Vector field with the face-centers pts Vector field with the vertices normal Vector field with the face normals Sf field with the surface vectors (mag will give you the area) rand Scalars-field with random numbers from [0. the state of the fields on the remote patches from the previous time-step or iteration are utilised.php?title=Contrib_groov.1] randNormal Random-number scalar field that is Gauss-distributed deltaT a field that returns the time-step time a field that returns the current time 3..OpenFOAMWiki http://openfoamwiki. When evaluating the expression in run-time. value uniform 100010.2))*normal(). Demos.1 Demo-Cases There are four demo-cases included in the repository in a folder require a blockMesh.minY=min(yp). variables "yp=pts().y)*(pos().1.php?title=Contrib_groov. valueExpression "0. In the example above.net/index. In this case. the number of faces on the remote patch outlet2 matches that of the local patch.para=-(maxY-pos().y. the variable pInlet has been defined on the remote patch inlet. the remote pressure field can be directly mapped onto the local patch.25*pow(maxY-minY. } 6 of 13 11/13/2012 11:30 AM . value uniform (10 0 0).maxY=max(yp).OpenFOAMWiki http://openfoamwiki.". Likewise. On the other hand. outlet1 It is very important to note. entire fields cannot be mirrored from remote patches to local patches.". Runs the pitzDaily-case with a parabolic inlet condition that pulsates inlet { type groovyBC.. They are what the name of the folder says: Demos The three cases are 4. Example: outlet1 { type groovyBC.5*sin(500*time()))*para".pOutlet2@outlet2=p. and accesses the pressure field of the outlet2 patch.Contrib groovyBC . name>@<patch name> = <expression> with <variable name>{<patch name>} = <expression> A variable defined as specified above can then be utilised like an ordinary variable within other groovyBC expressions defined for the local patch. Both these remote variables are then used within the valueExpression of the local patch to determine the pressure field to be imposed on this patch.1 pulsedPitzDaily To be run with oodles. and accesses the pressure and surface normal fields of the inlet patch. 4 Usage Examples 4. the number of faces on the patch inlet is not identical to the number of faces on the local patch outlet1. All of these cases only Don't try to find experimental results for these cases. that no form of patch-to-patch interpolation of the fields is performed. valueExpression "10*(1+0. variables "pInlet@inlet=sum(p*mag(Sf()))/sum(mag(Sf())). and hence an area weighted average of the pressure field is used.y-minY)/(0. the variable pOutlet2 has been defined on the remote patch outlet2. If the number of faces on the local and remote patches are not identical..5*(pInlet+pOutlet2)". } In the above example. r2=r1*0.x)-min(pts().. } 4.x))..data".3 circulatingSplash A interDyMFoam-case that crashes halfway through the calculation (but looks quite nice until then). Whoever wants to fix 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. valueExpression "-impulse*normal()". } ). fractionExpression "(time()<5) ? ((pos(). } 4. timelines ( { name impulse.x-r1*sin(10*time()).x>0.55) ? 1 : 0) : 0".0)".OpenFOAMWiki http://openfoamwiki. gradientExpression "vector(0. // valueExpression "vector(0. valueExpression "vector(0.2 wobbler A solidDisplacementFoam case where a bar that is fixed on one side is pushed according to a predefined timeline on a fraction of the boundary (the rest is zero gradient).0.1*sin(time()). } The Velocity is set depending on gamma: atmosphere { type groovyBC.x<0.". variables "r1=0. On the relevant patch the boundary conditon for D is forced { type groovyBC.net/index.1. value uniform (0 0 0). on the outlet the regular inletOutlet-BC is emulated (just as a demonstration) outlet { type groovyBC. fractionExpression "(phi > 0) ? 0 : 1". fileName "$FOAM_CASE/impulse. gradientExpression "vector(0. value uniform (0 0 0).1.Contrib groovyBC . } 4.0. valueExpression "-(gamma+internalField(gamma))*0.2*(1-0.0)".0.0.4 average-t-junction 7 of 13 11/13/2012 11:30 AM .2)+pow(pos().0)".1.2))<r2) ? 1 : 0".5*normal()".z-r1*cos(15*time()).45 && pos(). value uniform 0. outOfBounds clamp.25*(max(pts().php?title=Contrib_groov. valueExpression "(sqrt(pow(pos().5*cos(54*time())). value uniform (0 0 0).0)". The case consists of a T-junction.2. 8 of 13 11/13/2012 11:30 AM . gamma 1. This is a turbFoam case.". psi none. U U.w=sqrt(k*mag(g)).-9. The patch outlet2 has a fixed pressure. "l=5.0.5*(pInlet+pOutlet2)". (). phi phi. The total-pressure at the patch inlet is varied as a function of time.k=2*pi/l. with one inlet and two outlets.OpenFOAMWiki http://openfoamwiki.1 groovyWaveTank An example of using groovyBC to generate 2nd-order Stokes waves.A=0. and wavelength = 5. The corresponding boundary conditions for boundaryField { inlet { type timeVaryingTotalPressure. } defaultFaces { type zeroGradient. value uniform 100010. "(pos().. valueExpression "0. } outlet1 { type groovyBC.1.php?title=Contrib_groov. } } p are: 4. value uniform 100040. which showcases the ability of groovyBC to evaluate and access fields from remote patches (other patches present within the simulation case). // only used for restarts outOfBounds clamp. variables "pInlet@inlet=sum(p*mag(Sf()))/sum(mag(Sf())). 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.pOutlet2@outlet2=p. p0 100040. rho none.81).1.. For a wave with amplitude = 0.".Contrib groovyBC .2 User-Cases 4. gamma is set on the inlet: inlet { type valueExpression variables timelines } groovyBC.z<=A*cos(-w*time())+0. value uniform 100000.net/index. fileName "$FOAM_CASE/constant/p0vsTime". It is designed to run with interFoam.5*k*A*A*cos(2*(-w*time()))) ? 1 : 0". } outlet2 { type fixedValue.g=vector(0. . then you need another transformation.n=sum(normal())/mag(sum(normal())).A=0.0.p=pos()-c. Cases where physically connecting up the two patches would add on an unnecessarily large number of cells resulting in a bloated up mesh. As the title specifies.8.0)) inlet { type groovyBC. run blockMesh. "(pos(). 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.0. A test case can be downloaded from: groovyWaveTank. valueExpression "-Un*normal() + (rpm*pi/30)*((p & yT)*xT .0. for instance this one (which will not work when swirl is around (1.(p & xT)*yT)".Un=55.z)*cos(-w*time()). As usual. and interFoam. "l=5.mac. You can easily extend it to have a variation on the patch normal component. } 4. it is a very limited and simplistic approach to the complex concept of full 2-Way patch to patch coupling. such that it acts as more or less. where Un is the normal velocity and rpm is the rotational speed.8.0. inlet { type groovyBC. setFields.2 Swirl on inlet Here's an example of how you can specify a swirl on the inlet.p=pos()-c.2)) to Un*normal().0.Un=55.2.OpenFOAMWiki http://openfoamwiki.z<=A*cos(-w*time())+0.php?title=Contrib_groov. Un and rpm. variables "rpm=8000. and not the actual spatial distribution (unless both patches have exactly the same number of faces of course).c=sum(pos()*mag(Sf()))/sum(mag(Sf())).n=sum(normal())/mag(sum(normal())). one continuously connected mesh during the simulation. valueExpression "-Un*normal() + (rpm*pi/30)*((p & yT)*xT . n is the averaged patch normal.(p & xT)*yT)". The only time this will not work is when n is equal to (0. } c is the centre of the patch.tgz (http://idisk.5*k*A*A*cos(2*(-w*time()))) ? vector( A*w*exp(k*pos(). 4. ().com/egpatersonPublic/groovyWaveTank. 9 of 13 11/13/2012 11:30 AM .k=2*pi/l.Contrib groovyBC ..g=vector(0.2. You only need to specify 2 parameters. variables "rpm=8000.-9.".3 Simple 2-Way coupling of patches This is an example of using groovyBC for creating a simple 2-Way coupling between two patches. but is sufficient in a lot of situations.81).net/index.c=sum(pos()*mag(Sf()))/sum(mag(Sf())).w=sqrt(k*mag(g)). for instance a parabolic inlet would only require the addition of *(1-pow(r/R.1.tgz) . The corresponding velocity field inlet { type valueExpression variables timelines } U is set using: groovyBC.1). "p_int12@interface12=sum(p*mag(Sf()))/sum(mag(Sf())).p_relax=0. A. The corresponding interface11 velocity boundary conditions are: 10 of 13 11/13/2012 11:30 AM . and consists of three completely unconnected mesh regions say. The example uses the simpleFoam solver. The case uses the k-epsilon turbulence model. 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). $internalField. and held constant thereafter..p_int11))".p_relax=0. "(p_int21 + p_relax*(p_int22 . Each mesh region contains two patches as listed below: Region A: inlet .p_int21))". $internalField.net/index. Here is an excerpt of the interface11 { type variables valueExpression value } interface12 { type } interface21 { type variables valueExpression value } interface22 { type } pressure boundary conditions: groovyBC.. A way of showing off some of the cool features of groovyBC .Contrib groovyBC . B and C. instead of directly imposing the value of the pressure. However. zeroGradient.p_int11=sum(p*mag(Sf()))/sum(mag(Sf())). the area weighted average of the pressure field on patch interface12 is used.php?title=Contrib_groov. outlet The pressure (p) and velocity (U) fields of the following sets of patches are coupled to each other using groovyBC. The pressure at the patch outlet is held constant at 10 bar. groovyBC.. it is introduced through a relaxation factor which was required to ensure stability of the simulation. interface11 Region B: interface12 . A similar set up can be seen also for the patch interface21. "(p_int11 + p_relax*(p_int12 .. zeroGradient. Situations where field values need to be modified by a simple mathematical model of some device connected between the two patches which does not necessarily need to be simulated using CFD.-) and so on. interface21 Region C: interface22 . "p_int22@interface22=sum(p*mag(Sf()))/sum(mag(Sf())). with the aim of emulating a continuous mesh without any breaks: interface11 :: interface12 interface21 :: interface22 The system uses pressure driven flow.OpenFOAMWiki http://openfoamwiki. At patch interface11.p_int21=sum(p*mag(Sf()))/sum(mag(Sf())). an inletOutlet boundary condition has been emulated.google. variables "Q_int21@interface21=-1*sum(phi). feedback (good. that in this particular case. with the total flow at the patch interface11 being imposed on the patch interface12 again. through a relaxation factor in order to ensure stability as the simulation evolves.. Currently there are no known known bugs (but propably some unknown ones) 11 of 13 11/13/2012 11:30 AM .php?title=Contrib_groov. } interface21 { type zeroGradient. valueExpression "(Q_int22 + U_relax*(Q_int21 .Q_int12))/sum(mag(Sf()))*normal()".". the coupling is done in the opposite direction. X. type zeroGradient. } interface12 { type groovyBC.2 Known Bugs This utility is still under development. valueExpression "(Q_int12 + U_relax*(Q_int11 .com /leaf?id=0B0syP1Z1w2s1MWYxMzE4ZTEtODY4Zi00MjBiLTg1YTMtNDk1ODViNGM5NWVj& hl=en_GB) (let me know if the link does not work) This case does not use blockMesh. fractionExpression "(phi > 0) ? 0 : 1" value $internalField. y.1 Other The parser-part can be used in other boundary conditions (that are not covered by the mixed-BC).tgz (http://docs. In addition. Either use the Allrun script. since they are symbols for the parser. As always.Q_int22))/sum(mag(Sf()))*normal()".net/index. Y. A similar set up can be observed also for the patch interface22.Contrib groovyBC .Q_int22=sum(phi). 5.OpenFOAMWiki { http://openfoamwiki.3. it should be noted. x. } interface22 { type groovyBC. 5. } Here.".. Please note that constants must be enclosed in otherwise they will be defined as face-values toPoint. bad and ugly) is always welcome :-) 5 Technical the BC only works for fvPatchFields but can "read" point and face-fields too it also works for pointPatchFields.Q_int12=sum(phi). Z can NOT be used as variables. or simply run simpleFoam from within the case root.U_relax=0. The complete simulation case can be downloaded from: groovyBC_2Way_coupling_001. fractionExpression "(phi > 0) ? 0 : 1" value $internalField.U_relax=0. and the mesh has already been imported and set up. z. variables "Q_int11@interface11=-1*sum(phi).3. 3 Bug reporting Bugs can be reported with the Mantis Bug-Tracker on openfoam-extend. Content is available under GNU Free Documentation License 1. 19 February 2009 (CET) Retrieved from "http://openfoamwiki.svn.php?project_id=3& sticky_issues=off&sortby=last_updated&dir=DESC&hide_status_id=-2) or on the message board.5/libraries/groovyBC 7 Plans allow expressions for tensors allow "permanent" variables implement the BC for face-fields 8 History 2009-02-19: Initial upload --Bgschaid 23:50. but the bug-tracker is preferred 6 Download Valid versions: .3.6 OpenFOAM Version 1.net/apps/mantisbt/openfoam-extend/search. see swak4Foam.sourceforge. Valid versions: Subversion: .5 OpenFOAM Version 1.7 FeaturedArticle OpenFOAM Version 2.sourceforge.For the very latest version.6/libraries/groovyBC Valid versions: .0 OpenFOAM Version 2.php?title=Contrib_groov.php?title=Contrib_groovyBC&oldid=12481" Categories: OpenFOAM Version 1.Contrib groovyBC . at 23:52.net/index.726 times.sourceforge.1 This page was last modified on 27 August 2012.net/svnroot/openfoam-extend/trunk/Breeder_1.Older sources are also available via Subversion: svn checkout https://openfoam-extend..net/index.OpenFOAMWiki http://openfoamwiki.svn. 12 of 13 11/13/2012 11:30 AM .. 5. This page has been accessed 42.net (http://sourceforge.The latest independent sources can always be downloaded via svn checkout https://openfoam-extend.net/svnroot/openfoam-extend/trunk/Breeder_1. OpenFOAMWiki http://openfoamwiki. 13 of 13 11/13/2012 11:30 AM .Contrib groovyBC ..net/index..php?title=Contrib_groov.