Tips and tricks

From Gerris

Revision as of 09:59, 24 July 2009; view current revision
←Older revision | Newer revision→
Jump to: navigation, search


Emacs mode for Gerris files

Well, not really but something approaching. Add the following to your .emacs

(setq auto-mode-alist (cons '("\\.gfs\\'" . shell-script-mode) auto-mode-alist))

Generating several movies on-the-fly

While it is fairly simple to use the scripting mode of gfsview and unix pipes to generate a movie on the fly from a running simulation, how does one generate several movies simultaneously?

Using named unix fifos it is fairly easy too. For example if one has three gfsview files called wide.gfv, closeup.gfv and overview.gfv and want to generate the three corresponding movies wide.mpg, closeup.mpg and overview.mpg in one go, one could use the following command:

% gerris3D mysimulation.gfs | gfsview-batch3D

with a simulation file mysimulation.gfs containing the lines:

EventScript { start = 0 } {
  movies="wide closeup overview"
  rm -f $movies
  mkfifo $movies
  for movie in $movies; do
    ppm2mpeg < $movie > $movie.mpg &
OutputSimulation { step = 0.01 } stdout
EventScript { step = 0.01 } {
  movies="wide closeup overview"
  for movie in $movies; do
    echo "Clear"
    cat $movie.gfv
    echo "Append $movie { width = 1024 height = 768 }"

Compressing simulation files

When it is useful to save simulation results at regular intervals, the size of the files can be reduced by using on-the-fly compression. This can be done like this:

OutputSimulation { istep = 100 } sim-%ld.gfs
EventScript { istep = 100 } { gzip -f -q sim-*.gfs }

GfsView can read compressed GFS files directly.

Adding objects after a simulation has completed

If you want to add and execute Gerris objects after a simulation has completed, you can use something like:

% gerris2D -e "OutputScalarStats { start = end } stderr { v = P }" end.gfs > /dev/null

Another example would be computing a distance function (i.e. a levelset function) from a VOF interface description for visualisation using isosurfaces in GfsView. This is easily done using something like:

% gerris3D -e "VariableDistance D T" end.gfs | gfsview3D -s iso.gfv

VIM features and Gerris

There are plenty of vim features that can be customized to make your life easier when you work with gerris.

Using tab, you can autocomplete the keywords of gerris. To do that, add the following lines to your .vimrc:

function! Tab_Or_Complete()
 if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
   return "\<C-N>"
   return "\<Tab>"
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>

if has("autocmd")
"set complete+=k/etc/dictionaries-common/words isk+=.,(
set complete+=k/usr/share/gerris/gerris.dic isk+=.,(
endif " has("autocmd"

where /usr/share/gerris/gerris.dic may vary according to how gerris was installed on your system.

Another interesting feature is to open in firefox the syntax reference page of the command under the cursor. To do that, you have to add to your .vimrc:

function! OnlineDoc()
       let s:browser = "firefox"
       let s:wordUnderCursor = expand("<cword>")
        if s:wordUnderCursor =~ 'Gfs'
               let s:url = "".s:wordUnderCursor
               let s:url = "".s:wordUnderCursor
       let s:cmd = "silent !" . s:browser . " " . s:url
       "echo  s:cmd
       execute  s:cmd

and then to map this function with some sequence of letters (in my case y use \w )

map <Leader>w :call OnlineDoc()<CR>

Remember that you can create your own vim plugin for gfs files as

au! BufNewFile,BufRead *.gfs set filetype=gfs

and to place all this stuff in .vim/after/ftplugin/gfs.vim (you can also to load the color scheme of c.vim!!!)

Personal tools