[SCM] Gerris Flow Solver branch, upstream, updated. e8f73a07832050124d2b8bf6c6f35b33180e65a8

Stephane Popinet popinet at users.sf.net
Tue Nov 24 12:24:35 UTC 2009


The following commit has been merged in the upstream branch:
commit f1a5c6789dfa68b04cd0ba9a21de14a9da8b3077
Author: Stephane Popinet <popinet at users.sf.net>
Date:   Wed Jul 15 14:31:22 2009 +1000

    New option '--event' for gerris2D/3D
    
    darcs-hash:20090715043122-d4795-ab135195e96409605e3de3ada9b8cf0cb0a95b26.gz

diff --git a/doc/manpages/gerris2D.1 b/doc/manpages/gerris2D.1
index bb134ed..46472bc 100644
--- a/doc/manpages/gerris2D.1
+++ b/doc/manpages/gerris2D.1
@@ -37,6 +37,9 @@ Turn macros support on.
 .B \-DNAME, \-DNAME=VALUE, \-\-define=NAME, \-\-define=NAME=VALUE
 Defines NAME as a macro expanding to VALUE (macro support is implicitly turned on).
 .TP
+.B \-eEV, \-\-event=EV
+Evaluates the GfsEvent EV and returns the simulation.
+.TP
 .B \-V, \-\-version
 Output version information and exit.
 .TP
diff --git a/src/gerris.c b/src/gerris.c
index 3cfa39b..0644779 100644
--- a/src/gerris.c
+++ b/src/gerris.c
@@ -33,6 +33,7 @@
 #include "refine.h"
 #include "output.h"
 #include "adaptive.h"
+#include "solid.h"
 #include "version.h"
 
 static void set_box_pid (GfsBox * box, gint * pid)
@@ -40,6 +41,20 @@ static void set_box_pid (GfsBox * box, gint * pid)
   box->pid = *pid;
 }
 
+static void setup_binary_IO (GfsDomain * domain)
+{
+  /* make sure that all the variables are sent */
+  g_slist_free (domain->variables_io);
+  domain->variables_io = NULL;
+  GSList * i = domain->variables;
+  while (i) {
+    if (GFS_VARIABLE1 (i->data)->name)
+      domain->variables_io = g_slist_append (domain->variables_io, i->data);
+    i = i->next;
+  }
+  domain->binary = TRUE;	
+}
+
 int main (int argc, char * argv[])
 {
   GfsSimulation * simulation;
@@ -51,6 +66,7 @@ int main (int argc, char * argv[])
   guint npart = 0;
   gboolean profile = FALSE, macros = FALSE, one_box_per_pe = TRUE;
   gchar * m4_options = g_strdup ("-P");
+  GPtrArray * events = g_ptr_array_new ();
   gint maxlevel = -2;
 
   gfs_init (&argc, &argv);
@@ -66,15 +82,16 @@ int main (int argc, char * argv[])
       {"define", required_argument, NULL, 'D'},
       {"macros", no_argument, NULL, 'm'},
       {"data", no_argument, NULL, 'd'},
+      {"event", required_argument, NULL, 'e'},
       {"help", no_argument, NULL, 'h'},
       {"version", no_argument, NULL, 'V'},
       { NULL }
     };
     int option_index = 0;
-    switch ((c = getopt_long (argc, argv, "hVs:ip:PD:md",
+    switch ((c = getopt_long (argc, argv, "hVs:ip:PD:mde:",
 			      long_options, &option_index))) {
 #else /* not HAVE_GETOPT_LONG */
-    switch ((c = getopt (argc, argv, "hVs:ip:PD:md"))) {
+    switch ((c = getopt (argc, argv, "hVs:ip:PD:mde:"))) {
 #endif /* not HAVE_GETOPT_LONG */
     case 'P': /* profile */
       profile = TRUE;
@@ -100,6 +117,9 @@ int main (int argc, char * argv[])
     case 'd': /* data */
       maxlevel = -1;
       break;
+    case 'e': /* event */
+      g_ptr_array_add (events, g_strdup (optarg));
+      break;
     case 'h': /* help */
       gfs_error (0,
              "Usage: gerris [OPTION] FILE\n"
@@ -119,8 +139,9 @@ int main (int argc, char * argv[])
 	     "         --define=NAME\n"
              "         --define=NAME=VALUE\n"
 #endif /* have m4 */
-	     "  -h    --help        display this help and exit\n"
-	     "  -V    --version     output version information and exit\n"
+	     "  -eEV   --event=EV    Evaluates GfsEvent EV and returns the simulation\n"
+	     "  -h     --help        display this help and exit\n"
+	     "  -V     --version     output version information and exit\n"
 	     "\n"
 	     "Reports bugs to %s\n",
 	     FTT_MAINTAINER);
@@ -258,6 +279,55 @@ int main (int argc, char * argv[])
     return 0;
   }
 
+  if (events->len > 0) {
+    GSList * l = NULL;
+    guint i;
+    for (i = 0; i < events->len; i++) {
+      GtsFile * fp = gts_file_new_from_string (g_ptr_array_index (events, i));
+      if (fp->type != GTS_STRING) {
+	gfs_error (-1, 
+		   "gerris: invalid event: '%s'\n"
+		   "expecting a GfsEvent name\n",
+		   (char *) g_ptr_array_index (events, i));
+	return 1;
+      }
+      GtsObjectClass * klass = gfs_object_class_from_name (fp->token->str);
+      if (klass == NULL) {
+	gfs_error (-1, "gerris: unknown event class `%s'\n", fp->token->str);
+	return 1;
+      }
+      if (!gts_object_class_is_from_class (klass, gfs_event_class ())) {
+	gfs_error (-1, "gerris: class `%s' is not a GfsEvent\n", fp->token->str);
+	return 1;
+      }
+      GtsObject * object = gts_object_new (klass);
+      gfs_object_simulation_set (object, simulation);
+      g_assert (klass->read);
+      (* klass->read) (&object, fp);
+      if (fp->type == GTS_ERROR) {
+	gfs_error (-1,
+		   "gerris: invalid event: '%s'\n"
+		   "%d:%d: %s\n",
+		   (char *) g_ptr_array_index (events, i),
+		   fp->line, fp->pos, fp->error);
+	return 1;
+      }
+      if (GFS_IS_ADAPT (object))
+	gts_container_add (GTS_CONTAINER (simulation->adapts), GTS_CONTAINEE (object));
+      else if (GFS_IS_SOLID (object))
+	gts_container_add (GTS_CONTAINER (simulation->solids), GTS_CONTAINEE (object));
+      gts_container_add (GTS_CONTAINER (simulation->events), GTS_CONTAINEE (object));
+      l = g_slist_append (l, object);
+      gts_file_destroy (fp);
+    }
+    gfs_clock_start (domain->timer);
+    g_slist_foreach (l, (GFunc) gfs_event_do, simulation);    
+    gfs_clock_stop (domain->timer);
+    setup_binary_IO (domain);
+    gfs_simulation_write (simulation, -1, stdout);
+    return 0;
+  }
+
   domain->profile_bc = profile;
 
   gfs_simulation_run (simulation);

-- 
Gerris Flow Solver



More information about the debian-science-commits mailing list