Gerris Flow Solver Programming Course for Dummies

From Gerris

(Difference between revisions)
Jump to: navigation, search
Revision as of 11:37, 29 October 2007
Zaleski (Talk | contribs)
(Initial copy from the Dokuwiki original)
← Previous diff
Revision as of 17:29, 29 October 2007
Zaleski (Talk | contribs)
(Adapted the formatting to MediaWiki.)
Next diff →
Line 1: Line 1:
- 
This wiki is an unfinished project ! This wiki is an unfinished project !
-===== Preface =====+== Preface ==
Line 12: Line 11:
Gerris is a free, open source code available at [[http://gfs.sf.net]] . Gerris is a free, open source code available at [[http://gfs.sf.net]] .
-===== Course 1 =====+== Course 1 ==
- +=== Introduction ===
- +
-==== Introduction ====+
Line 29: Line 26:
Gerris and Gts are programmed in a style analogous to that of Glib, Gnome and GTK . It is a style of C programming that offers several advantages: Gerris and Gts are programmed in a style analogous to that of Glib, Gnome and GTK . It is a style of C programming that offers several advantages:
- * Most aspects of Object-Oriented Programming (OOP) , such as the existence of classes with their own methods and inheritance.+* Most aspects of Object-Oriented Programming (OOP) , such as the existence of classes with their own methods and inheritance.
- * The ability to interface to other programming languages. (As far as I know, this feature is not used in Gerris/Gts)+* The ability to interface to other programming languages. (As far as I know, this feature is not used in Gerris/Gts)
To implement Object-Oriented Programming, Gerris/Gts uses its own “Object system”. This system is analogous to the Glib object system (Gobject), but not identical to it. Learning more about Gobject can be very useful. To implement Object-Oriented Programming, Gerris/Gts uses its own “Object system”. This system is analogous to the Glib object system (Gobject), but not identical to it. Learning more about Gobject can be very useful.
-==== References ====+=== References ===
References to the Gobject system (in order of ease of reading): References to the Gobject system (in order of ease of reading):
Line 47: Line 44:
[[http://library.gnome.org/devel/gobject/stable/index.html]] [[http://library.gnome.org/devel/gobject/stable/index.html]]
-==== Useful tips ====+=== Useful tips ===
-=== Navigate in emacs using the TAGS file ===+==== Navigate using the TAGS file in emacs or vim ====
- - Create the TAGS file : <code>+ - Create the TAGS file : <pre>
% cd src % cd src
% make tags % make tags
-</code>+</pre>
- - open any *.c or *.h file with emacs.+ 
- - Position the cursor on a function or variable. +# In emacs:
- - do ESC . to find its definition. (or M-. using the emacs Meta key convention ) +## open any *.c or *.h file with emacs.
- - do ESC * to return to the previous location (s) . +## Position the cursor on a function or variable.
 +## do ESC . to find its definition. (or M-. using the emacs Meta key convention )
 +## do ESC * to return to the previous location (s) .
 +# In vim:
 +## to be written ...
-=== No order in which to read the code ===+==== No order in which to read the code ====
There is no good order in which to read the code (I have not found it yet) There is no good order in which to read the code (I have not found it yet)
-=== Keep a C precedence and associativity table nearby ===+==== Keep a C precedence and associativity table nearby ====
A lot of macros and functions such g_assert come from the Glib. A lot of macros and functions such g_assert come from the Glib.
Line 74: Line 75:
-==== C basics ====+=== C basics ===
-=== Structures ===+==== Introduction to Structures ====
-<code>+<pre>
struct Point { struct Point {
char name; char name;
double x, y; double x, y;
}; };
-</code>+</pre>
An example of usage An example of usage
-<code>+<pre>
main() main()
{ {
Line 98: Line 99:
my_point.name = ‘A’; my_point.name = ‘A’;
} }
-</code>+</pre>
name, x and y are members of the structure of type “Point” called my_point. We also give it a name that can be exported (printed, passed to other functions) as a character. This example shows why it is useful to use structures to store several relevant informations or data together. name, x and y are members of the structure of type “Point” called my_point. We also give it a name that can be exported (printed, passed to other functions) as a character. This example shows why it is useful to use structures to store several relevant informations or data together.
-=== An example: the structure GfsNorm in Gerris ===+==== An example: the structure GfsNorm in Gerris ====
-<code>+<pre>
struct _GfsNorm { struct _GfsNorm {
Line 110: Line 111:
}; };
typedef struct _GfsNorm GfsNorm typedef struct _GfsNorm GfsNorm
-</code>+</pre>
From ''domain.h''. From ''domain.h''.
-<code>+<pre>
GfsNorm gfs_domain_norm_residual (GfsDomain * domain, GfsNorm gfs_domain_norm_residual (GfsDomain * domain,
FttTraverseFlags flags, FttTraverseFlags flags,
Line 144: Line 145:
return n; return n;
} }
-</code>+</pre>
From ''domain.c'' From ''domain.c''
Line 150: Line 151:
Notice the use of Notice the use of
- * glib basic types ''gdouble, gpointer''+* glib basic types ''gdouble, gpointer''
- * glib functions ''g_return_val_if_fail''+* glib functions ''g_return_val_if_fail''
-=== Structures are related to each other ===+==== Structures that are related to other structures ====

Revision as of 17:29, 29 October 2007

This wiki is an unfinished project !


Contents

Preface


This course is about Gerris, a general-purpose fluid mechanics code developped by Stephane Popinet at NIWA, Wellington, New Zealand .

The intended audience is typical first year graduate students with very little experience of C or some Fortran knowledge, but willing to work hard and learn.

Gerris is a free, open source code available at [[1]] .

Course 1


Introduction


This course is about how Gerris ([[2]] ) is programmed. It is intended to help in understanding the Gerris source code and learning how to modify it usefully.

This course is not about the numerical methods in Gerris (however it would be good for students of this course to learn about them, for instance in the J. Comput. Phys. article) .

Gerris is closely linked to Gts, the GNU triangulated surface library, also written by Stephane Popinet

Gerris and Gts are programmed in a style analogous to that of Glib, Gnome and GTK . It is a style of C programming that offers several advantages:

  • Most aspects of Object-Oriented Programming (OOP) , such as the existence of classes with their own methods and inheritance.
  • The ability to interface to other programming languages. (As far as I know, this feature is not used in Gerris/Gts)

To implement Object-Oriented Programming, Gerris/Gts uses its own “Object system”. This system is analogous to the Glib object system (Gobject), but not identical to it. Learning more about Gobject can be very useful.

References

References to the Gobject system (in order of ease of reading):


[[3]]

[[4]]

[[5]]

Useful tips


Navigate using the TAGS file in emacs or vim

- Create the TAGS file :
% cd src
% make tags
  1. In emacs:
    1. open any *.c or *.h file with emacs.
    2. Position the cursor on a function or variable.
    3. do ESC . to find its definition. (or M-. using the emacs Meta key convention )
    4. do ESC * to return to the previous location (s) .
  2. In vim:
    1. to be written ...


No order in which to read the code

There is no good order in which to read the code (I have not found it yet)


Keep a C precedence and associativity table nearby

A lot of macros and functions such g_assert come from the Glib. Keep a bookmark to the Glib documentation: [[6]]


C basics

Introduction to Structures


struct Point {
  char  name;
  double  x, y;
};

An example of usage

main()
{

struct Point my_point;    /* declaration */

my_point.x = 0. ; 
my_point.y = 1.;
my_point.name = ‘A’;
}

name, x and y are members of the structure of type “Point” called my_point. We also give it a name that can be exported (printed, passed to other functions) as a character. This example shows why it is useful to use structures to store several relevant informations or data together.

An example: the structure GfsNorm in Gerris


struct _GfsNorm {
  gdouble bias, first, second, infty, w;
};
typedef struct _GfsNorm GfsNorm

From domain.h.

GfsNorm gfs_domain_norm_residual (GfsDomain * domain,
				  FttTraverseFlags flags,
				  gint max_depth,
				  gdouble dt,
				  GfsVariable * res)
{
  GfsNorm n;
  gpointer data[2];

  g_return_val_if_fail (domain != NULL, n);
  g_return_val_if_fail (res != NULL, n);
  
  gfs_norm_init (&n);
  data[0] = res;
  data[1] = &n;
  gfs_domain_cell_traverse (domain, FTT_PRE_ORDER, flags, max_depth, 
			   (FttCellTraverseFunc) add_norm_residual, data);
#ifdef HAVE_MPI
  domain_norm_reduce (domain, &n);
#endif /* HAVE_MPI */
  gfs_norm_update (&n);

  dt *= dt;
  n.bias *= dt;
  n.first *= dt;
  n.second *= dt;
  n.infty *= dt;
  return n;
}

From domain.c

Notice the use of

  • glib basic types gdouble, gpointer
  • glib functions g_return_val_if_fail

Structures that are related to other structures

Personal tools
communication