Contrib/funkySetFields

From OpenFOAMWiki
< Contrib
Revision as of 22:42, 26 March 2006 by Bgschaid (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Valid versions: OF version 12.png

1 Short description

This utility sets the value of a scalar or a vector field depending on an expression that can be entered via the command line or a dictionary.

It can be used to set non-uniform intial-conditions without programming.

This utility is still under development and should only be considered as a Beta-Version

2 Pre-requisites

To compile this utility at least version 2.1 of Bison has to be installed. Check with

bison -v

on the command line before trying to compile it.

3 Usage

The utility can be used from the command line or with a dictionary. In both forms an option -time is needed to select the time step.

3.1 Command line usage

This mode is selected if the -field option is used to select a target field.

In addition an option -expression is needed with the expression that is to be written to the target field (Syntax see below).

An optional option is -condition: only cells for which this expression evaluates to true are overwritten with the expression. For all other cells the old value is kept.

expression and condition should be enclosed in quotes to keep the shell from interpreting special characters.

An example of the usage would be:

funkySetFields . cavity -field U -expression '(grad(dist())^vector(0,0,-1))*mag(pos()-vector(0.05,0.05,0))/0.05'  -time 0 

This sets the velocity field to a 'circle' around the center. In the most simple case the velocity field can be set to zero

funkySetFields . cavity -field U -expression 'vector(0,0,0)' -time 0

Same vor the pressure field:

funkySetFields . cavity -field p -expression '0' -time 0

3.2 Dictionary usage

In the dictionary funkySetFieldsDict a list of dictionaries named expressions is read and one dictionary is evaluated after another. The title of the dictionaries is only used for documentation. In each dictionary there can be 3 entries:

field
the target field
expression
the expression to write to the field
condition
select a subset of the cells (this is optional)

An example dictionary would be:

 
 expressions
 (
	circleVel
	{
		field U;
		expression "(grad(dist())^vector(0,0,-1))*mag(pos()-vector(0.05,0.05,0))/0.05";
        }
	pressure1
    	{
		field p;
		expression "10.*(0.1-pos().y)";
	}
	pressure2
	{
		field p;
		expression "p+U&U";
		condition "pos().x > (max(pos().x)-min(pos().x))/2";
	}
 );

This sets the velocity field as in the command-line example and then sets the pressure field to a rather strange value.

4 Expression syntax

The most complete documentation of the expression syntax is the source file for the Bison-grammar (*.yy and *.ll). Sorry.

These C++ operators are implemented:

+,-,*,/ 
Arithmetic operators. Can be used for vectors and scalars (only if useful. For instance: vectors can't be added to scalars)
&,^ 
The vector operators as defined by OpenFOAM
<,>,<=,>=,!=,== 
Comparison operators (only defined for scalars)
&&,|| 
Logical Operators
Conditional operator
The conditional operator ( test ? val1 : val2) is defined for scalars and vectors

All the fields in the current time-step can be used. If the field is also the target field the old value is used. Then the field is written using the new value.

These pseudo-variables are defined:

pi 
Gues :)

These functions are defined:

pow,log,exp,sqr,sqrt,sin,cos,tan 
Only defined for scalars
mag 
defined for scalars and vectors
grad 
gradient of a scalar-field
div 
divergence of a vector-field

These pseudo-functions are defined:

pos 
Vector field with the cell-centers
rand 
Scalars-field with random numbers from [0,1]
randNormal 
Random-number scalar field that is Gauss-distributed

5 Technical

  • the utility only works on volScalar- and volVectorFields.
  • no dimension checking is done (but the dimension of the target field is preserved)

5.1 Known Bugs

This utility is still under development. Therefore there is a number of known bugs (and also some unknown ones)

  • Numbers without a decimal point are not correctly recognized
  • Subtracting two numbers does not work (but subtracting fields does)

6 Download

The tar file with the sources

7 Plans

  • create a new field from an expression
  • factor out the parsing in a library to make it usable from other utilities

8 History

  • 2006-03-26: First upload of the utility