Tips and tricks

From Gerris

Revision as of 18:13, 29 January 2008; 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 and the tee utility 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:


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

gerris3D mysimulation.gfs | tee $movies > /dev/null &
for movie in $movies; do
    gfsview-batch3D $movie.gfv < $movie | ppm2mpeg > $movie.mpg &
sleep 10
rm -f $movies

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

OutputSimulation { istep = 10 } stdout
EventScript { istep = 10 } { echo "Save stdout { 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.

Writing generic or customized gerris output

Since most of visualization package on the market (or as open-source) do not support quadtree/octree data format, to use benefits of third party visualization packages rather than GFSView we should convert Gerris results to a general unstructured data.

VTK format could be visualized by powerful free package: Paraview.

The function "gfs_write_generic_output" is written for this purpose.

This function could write output data in Tecplot or VTK format. I mean generic output because Tecplot format is almost a general unstructured data type and you could easily modify its (code or resulted file) for your own need. Alternatively you could contact me and I could do its for you (just describe your format). All data are written in ASCII format.

Tecplot format is briefly as follows:

1) Header (include list of field variables, number of vertexes, number of elements and elements type)

2) Spatial coordinates plus filed variables related to listed variables in header

3) Element connectivity

For more details regarding to VTK format refer to VTK file format: PDF or HTML

Brief algorithm

1) Construct mesh connectivity 4/8 vertex per cell.

2) Optimize connectivity by removing repeated vertexes, this considerably reduce data size and improve considerably speed of rendering (very important for 3d or large scale simulation).

3) Interpolation of cell-wise data to vertexes.

4) Writing results on a text file.

Function Prototype

Prototype of this function is as follows (6 input arguments):

void gfs_write_generic_output (gchar *type, 
gint n_filed,
gchar **filed_name,
gint plot_depth,
GtsBBox * box,
GfsDomain * domain);

1. type: type of desired output, "VTK" or "TECPLOT" at the moment are supported.

2. n_filed: number of filed data to be visualized, 0 mean just visualization of mesh.

3. filed_name: string array, each item is correspond to each filed, you should include your desired field name, i.e., "U", "V", "W", "P" and desired tracer, e.g., "T", ..., also you could include "Vorticity" to compute and write vorticity field. If for any field, function can not find data pointer from name of variable (except for vorticity), this field is skiped.

4. plot_depth: depth of cell which are desired to visualize, -1 mean visiting all levels.

5. box: if box=NULL, all domain are considered for visualization, but user could define a box to visualize only portion of domain located in the box, to define box you should specify its two corner (by six coordinate, for 2d simulation define two z-value arbitrary).

6. domain: simulation domain.

At the moment this function could be used to write data on-the-fly but it is easy to write a short code to convert "*.sim" data (result of Gerris) to described format. Since I prefer to analyze results on-the-fly I did not attent to a separate tool. Maybe in future a write such a tool (if you need such tool you could let me know or write its yourself, for this follow instruction same as "gfs2oogl.c", to load simulation object).

How to Use

To call this function on-the-fly it is sufficient to include this file in "simulation.c" file, i.e. add statement

#include "generic_output.c"

after include statements in the "simulation.c" file of your gerris and add its desired function call in time step loop of "simulation_run" function e.g. at a place like this (determined by "######")

static void simulation_run (GfsSimulation * sim)
while (sim->time.t < sim->time.end &&
sim->time.i < sim->time.iend) {
sim->time.t = sim->tnext;
gts_range_add_value (&domain->timestep,
gfs_clock_elapsed(domain->timer) - tstart);
gts_range_update (&domain->timestep);
gts_range_add_value (&domain->size,
gfs_domain_size (domain, FTT_TRAVERSE_LEAFS, -1));
gts_range_update (&domain->size);

assume we like to run "heated.gfs" example

use the following statements at the specified place (writing output file after each 100 time steps):

gint n_field = 5, plot_depth = -1;
gchar *filed_name[5] = {"U", "V", "P", "T", "Vorticity"};
GtsBBox *box= NULL;
if(sim->time.i % 100 == 0)
gfs_write_generic_output ("TECPLOT", n_field,
box, domain);
// or
if(sim->time.i % 100 == 0)
gfs_write_generic_output ("VTK", n_field,
filed_name, plot_depth,
box, domain);

or if you like to limit visulization within a box use this:

gint n_field = 5, plot_depth = -1;
gchar *filed_name[5] = {"U", "V", "P", "T", "Vorticity"};
GtsBBox *box= gts_bbox_new (gts_bbox_class (), NULL,
-.5, -.5, -.5,
.5, .5, .5);
if(sim->time.i % 100 == 0)
gfs_write_generic_output ("TECPLOT", n_field,
filed_name, plot_depth,
box, domain);
// or
if(sim->time.i % 100 == 0)
gfs_write_generic_output ("VTK", n_field,
filed_name, plot_depth,
box, domain);

note that resulted files are names as:

   tecplot%i.plt  or paraview%i.vtk

where %i determine file number, it is automatically incremented after each output

Note that you could write various type or a type with various proberties (e.g. writing both hole data and limited data by a box) simultaneously. For this for this purpose you just include suitable call of function in simulation loop.

After modification of code, you should recompile your gerris code to activate this added feature. Of course it is better to include such data in input "*.gfs", i.e. treat its like an event, but prefarably this job should be performed by Gerris mantainer, if he detect that this feature is useful for a portion of Gerris users.

(in the case of interest, you could announce your interest to this feature in GSF user mailing list).

Tecplot Snapshots



Paraview Snapshots




Personal tools