GfsDefine

From Gerris

(Difference between revisions)
Jump to: navigation, search
Revision as of 16:34, 9 August 2012
GeordieMcBain (Talk | contribs)
(noted that m4 builtins are accessible not only in Definitions)
← Previous diff
Current revision
GeordieMcBain (Talk | contribs)
(gave an example of using an m4 macro)
Line 22: Line 22:
Note that macro support needs to be turned on explicitly (using the <code>-m</code> or <code>-D</code> options when starting [[gerris]]). Note also that the <code>-m</code> or <code>-D</code> options should not be used when restarting a simulation from a (binary) simulation file (e.g. created using [[GfsOutputSimulation]]). Note that macro support needs to be turned on explicitly (using the <code>-m</code> or <code>-D</code> options when starting [[gerris]]). Note also that the <code>-m</code> or <code>-D</code> options should not be used when restarting a simulation from a (binary) simulation file (e.g. created using [[GfsOutputSimulation]]).
- 
-The builtins from [http://www.gnu.org/savannah-checkouts/gnu/m4/manual/m4-1.4.16/html_node m4] are also available, prefixed with ''m4_''. 
Macros may be used but not defined in external files included via [[GfsInclude]]. Macros may be used but not defined in external files included via [[GfsInclude]].
 +
 +The builtins from [http://www.gnu.org/savannah-checkouts/gnu/m4/manual/m4-1.4.16/html_node m4] are also available, prefixed with ''m4_''; thus for example to defer deciding till run-time whether a uniform mesh refinement were in order, one could write
 +
 + Refine m4_ifelse(UNIFORM, 1, 6, (x>0 ? 6 : 5))
 +
 +and call [[gerris]] with either <code>-DUNIFORM=1</code> or <code>-DUNIFORM=0</code>.
<examples/> <examples/>

Current revision

Define is used to define text macros in parameter files, similar to the macros of the C preprocessor (and still more similar to those of m4).

Examples of valid macros are:

Define PI 3.14159265359
Define SQUARE(x) (x*x)
Define REYNOLDS(U,L,nu) (U*L/nu)

Note that Define macros are more general than the C macros which can be defined using GfsGlobal. They apply to the parameter file as a whole rather than just to the GfsFunctions. For example, this parameter file:

...
Define LEVEL 7
...
Refine LEVEL
...
OutputSimulation { start = end } sim-LEVEL.gfs
...

will result in Gerris generating a simulation file called sim-7.gfs.

Note that macro support needs to be turned on explicitly (using the -m or -D options when starting gerris). Note also that the -m or -D options should not be used when restarting a simulation from a (binary) simulation file (e.g. created using GfsOutputSimulation).

Macros may be used but not defined in external files included via GfsInclude.

The builtins from m4 are also available, prefixed with m4_; thus for example to defer deciding till run-time whether a uniform mesh refinement were in order, one could write

Refine m4_ifelse(UNIFORM, 1, 6, (x>0 ? 6 : 5))

and call gerris with either -DUNIFORM=1 or -DUNIFORM=0.

Examples

Personal tools
communication