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

Stephane Popinet popinet at users.sf.net
Fri May 15 02:53:54 UTC 2009


The following commit has been merged in the upstream branch:
commit 4e048954da6b8d56e5045a5d63648dd2435c09ad
Author: Stephane Popinet <popinet at users.sf.net>
Date:   Sat Apr 22 12:07:37 2006 +1000

    New object GfsEventSumDirection
    
    darcs-hash:20060422020737-d4795-cd4647afa426a770eb6abc04fab2cb5f424473c3.gz

diff --git a/src/domain.c b/src/domain.c
index 5cf403e..d43c9d5 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -3193,3 +3193,60 @@ gboolean gfs_domain_remove_derived_variable (GfsDomain * domain, const gchar * n
   return FALSE;
 }
 
+typedef struct {
+  FttDirection d;
+  GfsFunction * f;
+  GfsVariable * v;
+} SumData;
+
+static gdouble product (FttCell * cell, GfsFunction * f)
+{
+  GfsSolidVector * solid = GFS_STATE (cell)->solid;
+  return ftt_cell_volume (cell)*(solid ? solid->a : 1.)*gfs_function_value (f, cell);
+}
+
+static void sum (FttCell * cell, SumData * data)
+{
+  FttCell * n = ftt_cell_neighbor (cell, data->d);
+  GfsSolidVector * solid = GFS_STATE (cell)->solid;
+
+  if (!n || GFS_CELL_IS_BOUNDARY (n) || (solid && solid->s[data->d] == 0.)) {
+    gdouble s = 0.;
+
+    n = cell;
+    do {
+      /* fixme: does not work if the resolution varies along data->d */
+      g_assert (ftt_cell_level (n) == ftt_cell_level (cell));
+      s += product (n, data->f);
+      GFS_VARIABLE (n, data->v->i) = s;
+      n = ftt_cell_neighbor (n, FTT_OPPOSITE_DIRECTION (data->d));
+    } while (n && !GFS_CELL_IS_BOUNDARY (n) && 
+	     (!GFS_IS_MIXED (n) || GFS_STATE (n)->solid->s[data->d] > 0.));
+  }
+}
+
+/**
+ * gfs_domain_sum:
+ * @domain: a #GfsDomain.
+ * @d: the #FttDirection.
+ * @f: a #GfsFunction.
+ * @v: a #GfsVariable.
+ *
+ * Fills variable @v of each cell of @domain with the sum in direction
+ * @d of the volume-weighted function @f.
+ */
+void gfs_domain_sum (GfsDomain * domain, FttDirection d, GfsFunction * f, GfsVariable * v)
+{
+  SumData data;
+
+  g_return_if_fail (domain != NULL);
+  g_return_if_fail (d >= 0 && d < FTT_NEIGHBORS);
+  g_return_if_fail (f != NULL);
+  g_return_if_fail (v != NULL);
+
+  data.d = d;
+  data.f = f;
+  data.v = v;
+  gfs_domain_cell_traverse (domain, FTT_PRE_ORDER, FTT_TRAVERSE_LEAFS, -1,
+			    (FttCellTraverseFunc) sum, &data);
+}
diff --git a/src/domain.h b/src/domain.h
index 06088fd..5484803 100644
--- a/src/domain.h
+++ b/src/domain.h
@@ -271,9 +271,13 @@ GfsDerivedVariable * gfs_domain_add_derived_variable  (GfsDomain * domain,
 						       GfsDerivedVariableInfo info);
 gboolean     gfs_domain_remove_derived_variable (GfsDomain * domain, 
 						 const gchar * name);
+void         gfs_domain_sum                     (GfsDomain * domain, 
+						 FttDirection d, 
+						 GfsFunction * f, 
+						 GfsVariable * v);
 
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
 
-#endif /* __DOMAINGRAPH_H__ */
+#endif /* __DOMAIN_H__ */
diff --git a/src/event.c b/src/event.c
index d50e83f..5a88ee2 100644
--- a/src/event.c
+++ b/src/event.c
@@ -930,6 +930,78 @@ GfsEventClass * gfs_event_sum_class (void)
   return klass;
 }
 
+/* GfsEventSumDirection: Object */
+
+static void gfs_event_sum_direction_write (GtsObject * o, FILE * fp)
+{
+  GfsEventSumDirection * s = GFS_EVENT_SUM_DIRECTION (o);
+
+  (* GTS_OBJECT_CLASS (gfs_event_sum_direction_class ())->parent_class->write) (o, fp);
+
+  fprintf (fp, " %s", ftt_direction_name [s->d]);
+}
+
+static void gfs_event_sum_direction_read (GtsObject ** o, GtsFile * fp)
+{
+  GfsEventSumDirection * s = GFS_EVENT_SUM_DIRECTION (*o);
+
+  (* GTS_OBJECT_CLASS (gfs_event_sum_direction_class ())->parent_class->read) (o, fp);
+  if (fp->type == GTS_ERROR)
+    return;
+
+  if (fp->type != GTS_STRING) {
+    gts_file_error (fp, "expecting a string (direction)");
+    return;
+  }
+  s->d = ftt_direction_from_name (fp->token->str);
+  if (s->d >= FTT_NEIGHBORS) {
+    gts_file_error (fp, "unknown direction `%s'", fp->token->str);
+    s->d = 0;
+    return;
+  }
+  gts_file_next_token (fp);
+}
+
+static gboolean gfs_event_sum_direction_event (GfsEvent * event, GfsSimulation * sim)
+{
+  if ((* GFS_EVENT_CLASS (GTS_OBJECT_CLASS (gfs_event_sum_class ())->parent_class)->event) 
+      (event, sim)) {
+    GfsEventSumDirection * s = GFS_EVENT_SUM_DIRECTION (event);
+
+    gfs_domain_sum (GFS_DOMAIN (sim), s->d, GFS_EVENT_SUM (event)->v, GFS_EVENT_SUM (event)->sv);
+    return TRUE;
+  }
+  return FALSE;
+}
+
+static void gfs_event_sum_direction_class_init (GfsEventClass * klass)
+{
+  GTS_OBJECT_CLASS (klass)->read = gfs_event_sum_direction_read;
+  GTS_OBJECT_CLASS (klass)->write = gfs_event_sum_direction_write;
+  GFS_EVENT_CLASS (klass)->event = gfs_event_sum_direction_event;
+}
+
+GfsEventClass * gfs_event_sum_direction_class (void)
+{
+  static GfsEventClass * klass = NULL;
+
+  if (klass == NULL) {
+    GtsObjectClassInfo gfs_event_sum_direction_info = {
+      "GfsEventSumDirection",
+      sizeof (GfsEventSumDirection),
+      sizeof (GfsEventClass),
+      (GtsObjectClassInitFunc) gfs_event_sum_direction_class_init,
+      (GtsObjectInitFunc) NULL,
+      (GtsArgSetFunc) NULL,
+      (GtsArgGetFunc) NULL
+    };
+    klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_event_sum_class ()),
+				  &gfs_event_sum_direction_info);
+  }
+
+  return klass;
+}
+
 /* GfsEventHarmonic: Object */
 
 static void gfs_event_harmonic_destroy (GtsObject * o)
diff --git a/src/event.h b/src/event.h
index c1668c9..af1fefc 100644
--- a/src/event.h
+++ b/src/event.h
@@ -165,6 +165,24 @@ struct _GfsEventSum {
 
 GfsEventClass * gfs_event_sum_class  (void);
 
+/* GfsEventSumDirection: Header */
+
+typedef struct _GfsEventSumDirection         GfsEventSumDirection;
+
+struct _GfsEventSumDirection {
+  GfsEventSum parent;
+
+  FttDirection d;
+};
+
+#define GFS_EVENT_SUM_DIRECTION(obj)            GTS_OBJECT_CAST (obj,\
+					         GfsEventSumDirection,\
+					         gfs_event_sum_direction_class ())
+#define GFS_IS_EVENT_SUM_DIRECTION(obj)         (gts_object_is_from_class (obj,\
+						 gfs_event_sum_direction_class ()))
+
+GfsEventClass * gfs_event_sum_direction_class  (void);
+
 /* GfsEventHarmonic: Header */
 
 typedef struct _GfsEventHarmonic         GfsEventHarmonic;

-- 
Gerris Flow Solver



More information about the debian-science-commits mailing list