Tips and tricks

From Gerris

(Difference between revisions)
Jump to: navigation, search
Revision as of 18:27, 24 March 2009
Dfuster (Talk | contribs)

← Previous diff
Revision as of 18:28, 24 March 2009
Dfuster (Talk | contribs)

Next diff →
Line 89: Line 89:
au! BufNewFile,BufRead *.gfs set filetype=gfs au! BufNewFile,BufRead *.gfs set filetype=gfs
-and to place in .vim/after/ftplugin/gfs.vim all this stuff as well as to load the color scheme of c.vim!!!+and to place all this stuff in .vim/after/ftplugin/gfs.vim (you can also to load the color scheme of c.vim!!!)

Revision as of 18:28, 24 March 2009

Contents

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 script:

#!/bin/sh

movies="wide closeup overview"
rm -f $movies
mkfifo $movies

gerris3D mysimulation.gfs | gfsview-batch3D &
for movie in $movies; do
    ppm2mpeg < $movie > $movie.mpg &
done

the simulation file mysimulation.gfs should also contain lines looking like:

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 }"
  done
}

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.

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>"
 else
   return "\<Tab>"
 endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>

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

where gerris.dic is automatically generated when gerris is compiled in the doc folder.

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 = "http://gfs.sourceforge.net/wiki/index.php/".s:wordUnderCursor
       else
               let s:url = "http://gfs.sourceforge.net/wiki/index.php/Gfs".s:wordUnderCursor
       endif
       let s:cmd = "silent !" . s:browser . " " . s:url
       "echo  s:cmd
       execute  s:cmd
       redraw!
endfunction

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
communication