Difference between revisions of "Contrib/swak4Foam"

From OpenFOAMWiki
m (libs that need to be added to the controlDict file)
(Usage examples)
Line 118: Line 118:
 
* [[Contrib/swak4Foam/Example_calcMassFlow|Calculate the mass flow on patches and faceSets/zones]]
 
* [[Contrib/swak4Foam/Example_calcMassFlow|Calculate the mass flow on patches and faceSets/zones]]
 
* [[Contrib/swak4Foam/Example_calcPressureDifference|Calculate the pressure difference between a patch and other entities]]
 
* [[Contrib/swak4Foam/Example_calcPressureDifference|Calculate the pressure difference between a patch and other entities]]
 +
* [[Contrib/swak4Foam/Example_initRandomVelocity|Initialize a random velocity field]]
  
 
== Downloading ==
 
== Downloading ==

Revision as of 13:05, 10 January 2013

Look. If this works, it'll keep us from getting caught. If it doesn't, it'll keep us from getting old.
MacGyver. Master of the knife

A library that combines the functionality of groovyBC and funkySetFields. Currently this page is incomplete. Please have a look at those 2 pages for further information.

Valid versions: OF version 16.png OF version 17.png OF Version 20.png OF Version 21.png

This page is only a stub. I'll finish it when I find time. If you feel that you can improve it: go ahead

1 About

swak4Foam stands for SWiss Army Knife for Foam. Like that knife it rarely is the best tool for any given task, but sometimes it is more convenient to get it out of your pocket than going to the tool-shed to get the chain-saw.

2 Building

In the directory of the sources just do

wmake all

or

./Allwmake

and everything should be built. It is not possible (at least for a novice) to just build selectively parts (like groovyBC) on their own.

For further information please refer to the the README

2.1 Checking the version

If there is already an installation of swak4Foam you can check the version by simply entering

funkySetFields

This ends with an error message, but blow the usual OpenFOAM-banner you find the version of swak4Foam and the release date. If there is no swak-version then the installation is older than 0.2.0 (the first version to have this banner)

2.2 Preparing the controlDict

The following libs need to be added to the controlDict

/OpenFOAM/name-2.1.0/run/casename/system/controlDict

Insert the following lines near the top of the controlDict file:

libs (
      "libOpenFOAM.so"
      "libsimpleSwakFunctionObjects.so"
      "libswakFunctionObjects.so"
      "libgroovyBC.so"
     );

3 Contents

3.1 Libraries

swak4FoamParsers
The basis of swak4Foam: the expression parsers with the logic to access the OpenFOAM data-structures. None of the other software pieces compile without it
groovyBC
Implements the infamous groovyBC. A boundary condition that allows arbitrary expressions in the field-file
swakFunctionObjects
Function objects that have no additional requirements. Mainly used for manipulating and creating fields with expressions
simpleSwakFunctionObjects
Function objects based on the simpleFunctionObjects-library (which is a prerequisite for compiling it). Evaluate expressions and output the results
swakSourceFields
Field that is calculated from an expression. To be used as source-term or coefficient in some solver
swakTopoSources
topoSources for cellSet and faceSet. Can be used with the cellSet and faceSet-utilities
pythonIntegration
Function object which allows inclusion of Python code directly into an OpenFOAM Simulation run. Various inline code snippets or python script files can be specified to be called once at the start of a run, once at the end of a run and during each time-step during a simulation.

3.2 Utilities

funkySetFields
Utility that allows creation and manipulation of files with expressions
funkySetBoundaryField
Sets any field on a boundary to a non-uniform value based on an expression. Acts without deeper understanding of the underlying boundary condition
replayTransientBC
Utility to quickly test whether a groovyBC gives the expected results. Writes the specified fields with the applied boundary condition but doesn't do anything else. Can be used for other transient BCs as well

3.3 Examples

Have a look at the README and the files to understand how to use things

4 Expression

These are the core of it. Expressions can be used for

  • internalFields (basically the functionality of expressions in funkySetFields.
  • patchFields (basically the functionality of expressions in groovyBC
  • cellSet, faceSet, cellZone, faceZone. Only a subset of the functionality of expressions above is supported
  • surface. Calculations on sampledSurface. Only a subset of the functionality of expressions above is supported

4.1 Accessing external expressions

The syntax for this is slightly different from external expressions in groovyBC (the change of syntax was chosen to avoid clashes with valid patch or zone names).

The destination for an external expression is enclosed in {}. It can consist of three parts

  1. entity type (if none is given, then patch is assumed. Unless no name is given, then internalField is assumed). Valid types are
    • internalField
    • patch
    • cellZone
    • faceZone
    • cellSet
    • faceSet
    • surface
  2. entity name
  3. mesh region (if none is given, then the current mesh is assumed)

Not all three parts have to present. In the general form it is written as {type'name/region}. So

pInlet{inlet}=average(p);

is the average pressure on the inlet.

pControl{faceZone'control/otherMesh}=average(p);

is the average pressure on a faceZone on another mesh.

External values can only be used if they are homogenous (so they should either be a min, max, sum or average)

4.2 Random notes on the expression syntax

Some changes to the original syntax of groovyBC and funkySetFields (these remarks should become obsolete once there is a canonical list of functions here).

  • For faceSet and faceZone a pseudo-function flip() is defined which is either +1 or -1. For faceZone this is the flipMap (-1 if the flipMap is true for a face). For a faceSet named (for instance) foo it is defined if a cellSet of the name fooSlaveCells is defined (this follows the convention of the setsToZones-utility. The main purpose of this function is to get consistent mass-flows on faces (phi*flip() takes into account the orientation of the faces)
  • there is a new pseudo-function cpu() that returns the number of the current CPU for parallel runs
  • the pseudo-function id() returns the cell/face-id

5 Usage examples

Until there is a 'read' documentation this section links to a number short examples how swak4Foam can be used for common tasks:

6 Downloading

The current version that works with 1.x-releases of OpenFOAM can be downloaded using this command

svn checkout https://openfoam-extend.svn.sourceforge.net/svnroot/openfoam-extend/trunk/Breeder_1.7/libraries/swak4Foam/

the version that works with 2.0 (and also 2.1) can be found at

svn checkout https://openfoam-extend.svn.sourceforge.net/svnroot/openfoam-extend/trunk/Breeder_2.0/libraries/swak4Foam/

Further information is found in the README-file.

If you don't have SVN go to this link for 1.7 or 1.6-ext or this link for 2.x and click on Download GNU tarball.

6.1 Development

The above SVN-repository is the current released version. The actual development version can be downloaded with Mercurial:

hg clone http://openfoam-extend.hg.sourceforge.net:8000/hgroot/openfoam-extend/swak4Foam

for the version that works with 2.0 (and also 2.1) you'll have to change to the appropriate branch with

hg update port_2.0.x

If you want to contribute (which is encouraged. Code or examples. Whatever you want) please contact Bgschaid and we'll set something up for write access

An alternate mercurial repository is found at BitBucket. It is only meant as a backup for the repository at Sourceforge and will receive pushes less frequently than the Sourceforge repo

7 Other

7.1 Further information

In addition to the material on this Wiki there are two presentations that show the capabiities of swak4Foma

7.1.1 Documentation with the sources

With the sources comes a README. It is written in org-mode and can easily be converted to PDF. Here on the Wiki are versions of it for the 1.x-branch and the 2.x-branch. Beware: Formatting of these pages is not as good as it should be

PDF-versions of the README can be found here for 1.x and here for 2.x.

7.1.2 Examples at other sites

A nice tutorial on using swak4Foam is found here.

7.2 Bugreports

Please report bugs here: [1]

7.3 History

7.3.1 2010-09-13

First Release

7.3.2 2010-12-18

New release Most important changes:

  • Parser for sampledSurfaces
  • Multiline variables
  • Two maintainance-scripts were added
  • Parsers using 'external variables' are now run-time selectable

7.3.3 2011-01-30

New release Changes (for details see README):

  • Library to deal with finiteArea in 1.6-ext
  • Bug-fixes

7.3.4 2011-04-20

New release

Changes (for details see README):

  • Stored variables
  • New utility funkyDoCalc
  • Calculation on sampled sets

7.3.5 2011-07-26

New release. Major change is support for OpenFOAM 2.0. For details see the README

7.3.6 2011-10-03

New release. Major changes are

  • Support for programmingfunctionObjects (C++ and Python)
  • Global variables
  • Solving of PDEs (Laplacian and Transport equation) in functionObjects

For details see the README and this presentation (held at the Austrian Usertgroup Meeting PFAU)

7.3.7 2012-01-04

New release.Major improvements are:

  • extension of the Field-parser to allow surface-fields and tensors
  • conditional function objects (execute function objects on demand)
  • improved Allwmake (catches common compilation problems)
  • finiteArea now also supports the PDF-functionObjects
  • and several other improvements

for a detailed list have a look at the relevant section of the README: for the 1.x-version or the 2.x-version

7.3.8 2012-04-13 - Version 0.2.0

New release. Improvements are (see README for full list):

  • temporal operators ddt and oldTime. Other operators from fvc are added
  • functions for location of minimum and maximum
  • Field-parser now supports tensors and pointFields
  • New variables for Python-integration
  • boundary conditions groovyBCDirection and groovyBCJump
  • fully parallel compilation

--Bgschaid 01:17, 14 September 2010 (CEST)