# GfsFunction

### From Gerris

Revision as of 11:11, 22 November 2007Cedric-penard (Talk | contribs) ← Previous diff |
Revision as of 23:15, 3 December 2007Popinet (Talk | contribs) (Cartesian grids) Next diff → |
||

Line 1: |
Line 1: | ||

+ | __NOTOC__ | ||

+ | |||

Functions can be used in most objects which require a numerical parameter. A function can be a constant or a piece of C code taking coordinates (x,y,z), time t or any of the [[domain variables]] as arguments and returning a floating-point value. | Functions can be used in most objects which require a numerical parameter. A function can be a constant or a piece of C code taking coordinates (x,y,z), time t or any of the [[domain variables]] as arguments and returning a floating-point value. | ||

Line 18: |
Line 20: | ||

40.*(P - 1.) | 40.*(P - 1.) | ||

- | or a GTS file | + | or a GTS/CGD file |

myfunction.gts | myfunction.gts | ||

+ | |||

+ | == GTS files == | ||

The GTS file must be a planar (preferably Delaunay) triangulation of a set of points. The value of the function at a given (x,y) coordinate is then calculated by computing the z-coordinate of the intersection of a vertical line passing through the point at (x,y,0) with the triangulation defined by the GTS file. | The GTS file must be a planar (preferably Delaunay) triangulation of a set of points. The value of the function at a given (x,y) coordinate is then calculated by computing the z-coordinate of the intersection of a vertical line passing through the point at (x,y,0) with the triangulation defined by the GTS file. | ||

+ | |||

+ | == Cartesian Grid Data (CGD) files == | ||

+ | |||

+ | Cartesian Grid Data files can be specified as | ||

+ | |||

+ | mydata.cgd | ||

+ | |||

+ | Note that the extension must be <code>.cgd</code>. | ||

+ | |||

+ | The CGD file contains data defined on a regular Cartesian grid and can be used with 1 to 4 space/time dimensions. | ||

+ | |||

+ | The first line of the file defines the structure of the grid for example : | ||

+ | |||

+ | 3 x y t | ||

+ | |||

+ | Here <code>3</code> is the number of dimensions, <code>x</code>, <code>y</code> and <code>t</code> define the structure of the data: 2 spatial dimensions and 1 temporal dimension. | ||

+ | |||

+ | Then follow 3 lines where the space-separated values define the positions of each Cartesian grid line in each of the dimensions. | ||

+ | |||

+ | The rest of the file contains the values at each grid point. | ||

+ | |||

+ | The value of the function at a given (x,y,t) coordinate is then calculated by tri-linear interpolation on the Cartesian grid. | ||

+ | |||

+ | == Computing gradients == | ||

Gradients of variables can be computed using the <code>dx()</code>, <code>dy()</code> and <code>dz()</code> functions. For example, the z-component of the vorticity would be computed as: | Gradients of variables can be computed using the <code>dx()</code>, <code>dy()</code> and <code>dz()</code> functions. For example, the z-component of the vorticity would be computed as: |

## Revision as of 23:15, 3 December 2007

Functions can be used in most objects which require a numerical parameter. A function can be a constant or a piece of C code taking coordinates (x,y,z), time t or any of the domain variables as arguments and returning a floating-point value.

The syntax in parameter files is as follows:

-1.78e-3

or a C function

{ double a = sin (x + y); double b = cos (x - z); double c = sin (M_PI*t); return a + b + c; }

or a C expression

40.*(P - 1.)

or a GTS/CGD file

myfunction.gts

## GTS files

The GTS file must be a planar (preferably Delaunay) triangulation of a set of points. The value of the function at a given (x,y) coordinate is then calculated by computing the z-coordinate of the intersection of a vertical line passing through the point at (x,y,0) with the triangulation defined by the GTS file.

## Cartesian Grid Data (CGD) files

Cartesian Grid Data files can be specified as

mydata.cgd

Note that the extension must be `.cgd`

.

The CGD file contains data defined on a regular Cartesian grid and can be used with 1 to 4 space/time dimensions.

The first line of the file defines the structure of the grid for example :

3 x y t

Here `3`

is the number of dimensions, `x`

, `y`

and `t`

define the structure of the data: 2 spatial dimensions and 1 temporal dimension.

Then follow 3 lines where the space-separated values define the positions of each Cartesian grid line in each of the dimensions.

The rest of the file contains the values at each grid point.

The value of the function at a given (x,y,t) coordinate is then calculated by tri-linear interpolation on the Cartesian grid.

## Computing gradients

Gradients of variables can be computed using the `dx()`

, `dy()`

and `dz()`

functions. For example, the z-component of the vorticity would be computed as:

(dx("V") - dy("U"))

## More details on C functions

Comments should use the C syntax; i.e. opening `/*`

and closing
`*/`

not necessarily on the same line rather than the usual parameter file syntax of a line beginning with a `#`

. This is to allow the use of C preprocessor directives in C functions in GfsFunctions.

Example:

- Coalescence of a pair of Gaussian vortices (Gerris logo), in the InitVorticity command.