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

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


The following commit has been merged in the upstream branch:
commit 54cf9f9e4063c34e281be7129dd59ae3039819a5
Author: Stephane Popinet <popinet at users.sf.net>
Date:   Sun Jun 11 14:35:55 2006 +1000

    DerivedVariable is now a proper object
    
    ... and also has a new "description" field.
    
    darcs-hash:20060611043555-d4795-ee463d202fed8100c1fbb69262f379f547f79690.gz

diff --git a/src/domain.c b/src/domain.c
index 43883ab..67596ef 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -239,8 +239,13 @@ static void domain_destroy (GtsObject * o)
   }
   g_assert (domain->variables == NULL);
 
-  g_slist_foreach (domain->derived_variables, (GFunc) g_free, NULL);
-  g_slist_free (domain->derived_variables);
+  i = domain->derived_variables;
+  while (i) {
+    GSList * next = i->next;
+    gts_object_destroy (i->data);
+    i = next;
+  }
+  g_assert (domain->derived_variables == NULL);
 
   g_array_free (domain->allocated, TRUE);
 
@@ -3087,26 +3092,31 @@ void gfs_domain_combine_traverse (GfsDomain * domain1,
 /**
  * gfs_domain_add_derived_variable:
  * @domain: a #GfsDomain.
- * @v: the #GfsDerivedVariable.
+ * @info: the #GfsDerivedVariableInfo.
  *
- * Adds @v to @domain.
+ * Adds a derived variable described by @info to @domain.
  *
  * Returns: the #GfsDerivedVariable if the variable was successfully
  * added to @domain or %NULL if a variable with the same name already
  * exists.
  */
-GfsDerivedVariable * gfs_domain_add_derived_variable (GfsDomain * domain, GfsDerivedVariable v)
+GfsDerivedVariable * gfs_domain_add_derived_variable (GfsDomain * domain, 
+						      GfsDerivedVariableInfo info)
 {
-  GfsDerivedVariable * v1;
+  GfsDerivedVariable * v;
 
   g_return_val_if_fail (domain != NULL, NULL);
 
-  if (gfs_variable_from_name (domain->variables, v.name) ||
-      gfs_derived_variable_from_name (domain->derived_variables, v.name))
+  if (gfs_variable_from_name (domain->variables, info.name) ||
+      gfs_derived_variable_from_name (domain->derived_variables, info.name))
     return NULL;
-  v1 = g_memdup (&v, sizeof (GfsDerivedVariable));
-  domain->derived_variables = g_slist_prepend (domain->derived_variables, v1);
-  return v1;
+  v = GFS_DERIVED_VARIABLE (gts_object_new (GTS_OBJECT_CLASS (gfs_derived_variable_class ())));
+  v->name = g_strdup (info.name);
+  v->description = info.description ? g_strdup (info.description) : NULL;
+  v->func = info.func;
+  v->data = info.data;
+  domain->derived_variables = g_slist_prepend (domain->derived_variables, v);
+  return v;
 }
 
 /**
@@ -3131,7 +3141,7 @@ gboolean gfs_domain_remove_derived_variable (GfsDomain * domain, const gchar * n
     GfsDerivedVariable * u = i->data;
 
     if (!strcmp (u->name, name)) {
-      g_free (u);
+      gts_object_destroy (GTS_OBJECT (u));
       domain->derived_variables = g_slist_remove_link (domain->derived_variables, i);
       g_slist_free (i);
       return TRUE;
diff --git a/src/domain.h b/src/domain.h
index ac08e0b..9707c44 100644
--- a/src/domain.h
+++ b/src/domain.h
@@ -257,8 +257,14 @@ void         gfs_domain_combine_traverse      (GfsDomain * domain1,
 					       gpointer idata,
 					       FttCellTraverseFunc outside,
 					       gpointer odata);
+
+typedef struct {
+  gchar * name, * description;
+  gpointer func, data;
+} GfsDerivedVariableInfo;
+
 GfsDerivedVariable * gfs_domain_add_derived_variable  (GfsDomain * domain, 
-						       GfsDerivedVariable v);
+						       GfsDerivedVariableInfo info);
 gboolean     gfs_domain_remove_derived_variable (GfsDomain * domain, 
 						 const gchar * name);
 
diff --git a/src/fluid.h b/src/fluid.h
index d65b8b4..cec581a 100644
--- a/src/fluid.h
+++ b/src/fluid.h
@@ -29,7 +29,8 @@ extern "C" {
 
 #include "ftt.h"
 
-typedef struct _GfsVariable        GfsVariable;
+typedef struct _GfsVariable               GfsVariable;
+typedef struct _GfsDerivedVariable        GfsDerivedVariable;
 
 typedef struct _GfsStateVector     GfsStateVector;
 typedef struct _GfsSolidVector     GfsSolidVector;
diff --git a/src/refine.c b/src/refine.c
index 5958059..5f923e9 100644
--- a/src/refine.c
+++ b/src/refine.c
@@ -180,7 +180,8 @@ static gdouble solid_curvature (FttCell * cell, FttCellFace * face,
 
 static void refine_solid_read (GtsObject ** o, GtsFile * fp)
 {
-  GfsDerivedVariable v = { "SolidCurvature", solid_curvature };
+  GfsDerivedVariableInfo v = { "SolidCurvature", "curvature of the solid boundary",
+			       solid_curvature };
   GfsRefineSolid * refine = GFS_REFINE_SOLID (*o);
 
   refine->v = gfs_domain_add_derived_variable (GFS_DOMAIN (gfs_object_simulation (*o)), v);
@@ -398,7 +399,8 @@ static gdouble cell_distance (FttCell * cell,
 
 static void refine_distance_read (GtsObject ** o, GtsFile * fp)
 {
-  GfsDerivedVariable v = { "Distance", cell_distance };
+  GfsDerivedVariableInfo v = { "Distance", "distance to the surface", 
+			       cell_distance };
 
   v.data = *o;
   if (!gfs_domain_add_derived_variable (GFS_DOMAIN (gfs_object_simulation (*o)), v)) {
@@ -478,7 +480,8 @@ static gdouble cell_height (FttCell * cell,
 
 static void refine_height_read (GtsObject ** o, GtsFile * fp)
 {
-  GfsDerivedVariable v = { "Height", cell_height };
+  GfsDerivedVariableInfo v = { "Height", "vertical distance to the surface", 
+			       cell_height };
 
   v.data = *o;
   if (!gfs_domain_add_derived_variable (GFS_DOMAIN (gfs_object_simulation (*o)), v)) {
diff --git a/src/simulation.c b/src/simulation.c
index 5bfbe84..a34cdb7 100644
--- a/src/simulation.c
+++ b/src/simulation.c
@@ -716,30 +716,30 @@ static gdouble cell_2nd_principal_invariant (FttCell * cell, FttCellFace * face,
 static void gfs_simulation_init (GfsSimulation * object)
 {
   GfsDomain * domain = GFS_DOMAIN (object);
-  static GfsDerivedVariable derived_variable[] = {
-    { "x",          cell_x },
-    { "y",          cell_y },
-    { "z",          cell_z },
-    { "ax",         cell_ax },
-    { "ay",         cell_ay },
-    { "az",         cell_az },
-    { "cx",         cell_cx },
-    { "cy",         cell_cy },
-    { "cz",         cell_cz },
-    { "t",          cell_t },
-    { "Vorticity",  cell_vorticity },
-    { "Divergence", cell_divergence },
-    { "Velocity",   cell_velocity_norm },
-    { "Velocity2",  cell_velocity_norm2 },
-    { "Level",      cell_level },
-    { "A",          cell_fraction },
-    { "S",          cell_solid_area },
-    { "Lambda2",    cell_velocity_lambda2 },
-    { "Curvature",  cell_streamline_curvature },
-    { "D2",         cell_2nd_principal_invariant },
-    { NULL, NULL}
+  static GfsDerivedVariableInfo derived_variable[] = {
+    { "x", "x-coordinate of the center of mass of the cell", cell_x },
+    { "y", "y-coordinate of the center of mass of the cell", cell_y },
+    { "z", "z-coordinate of the center of mass of the cell", cell_z },
+    { "ax", "x-coordinate of the center of area of the solid surface", cell_ax },
+    { "ay", "y-coordinate of the center of area of the solid surface", cell_ay },
+    { "az", "z-coordinate of the center of area of the solid surface", cell_az },
+    { "cx", "x-coordinate of the center of the cell", cell_cx },
+    { "cy", "y-coordinate of the center of the cell", cell_cy },
+    { "cz", "z-coordinate of the center of the cell", cell_cz },
+    { "t",  "Physical time", cell_t },
+    { "Vorticity", "Norm of the vorticity vector of the velocity field", cell_vorticity },
+    { "Divergence", "Divergence of the velocity field", cell_divergence },
+    { "Velocity", "Norm of the velocity vector", cell_velocity_norm },
+    { "Velocity2", "Squared norm of the velocity vector", cell_velocity_norm2 },
+    { "Level", "Quad/octree level of the cell", cell_level },
+    { "A", "Fluid fraction of the cell", cell_fraction },
+    { "S", "Area of the solid contained in the cell", cell_solid_area },
+    { "Lambda2", "Vortex-detection criterion of Jeong & Hussein", cell_velocity_lambda2 },
+    { "Curvature",  "Curvature of the local streamline", cell_streamline_curvature },
+    { "D2", "Second principal invariant of the deformation tensor", cell_2nd_principal_invariant },
+    { NULL, NULL, NULL}
   };
-  GfsDerivedVariable * v = derived_variable;
+  GfsDerivedVariableInfo * v = derived_variable;
 
   gfs_domain_add_variable (domain, "P")->centered = TRUE;
   gfs_domain_add_variable (domain, "Pmac")->centered = TRUE;
diff --git a/src/utils.c b/src/utils.c
index e63866b..d324ff5 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -769,26 +769,6 @@ void gfs_function_write (GfsFunction * f, FILE * fp)
 }
 
 /**
- * gfs_derived_variable_from_name:
- * @i: a list of #GfsDerivedVariable.
- * @name: a name.
- *
- * Returns: the #GfsDerivedVariable @name of @list or %NULL.
- */
-GfsDerivedVariable * gfs_derived_variable_from_name (GSList * i, const gchar * name)
-{
-  g_return_val_if_fail (name != NULL, NULL);
-
-  while (i) {
-    GfsDerivedVariable * v = i->data;
-    if (!strcmp (v->name, name))
-      return v;
-    i = i->next;
-  }
-  return NULL;
-}
-
-/**
  * gfs_object_class_from_name:
  * @name: the name of the class.
  *
diff --git a/src/utils.h b/src/utils.h
index 1e8e067..d287327 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -31,16 +31,6 @@ extern "C" {
 
 gboolean gfs_char_in_string (char c, const char * s);
 
-/* Derived variables */
-
-typedef struct {
-  gchar * name;
-  gpointer func;
-  gpointer data;
-} GfsDerivedVariable;
-
-GfsDerivedVariable * gfs_derived_variable_from_name (GSList * i, const gchar * name);
-
 /* GfsFunction: Header */
 
 typedef struct _GfsFunction         GfsFunction;
diff --git a/src/variable.c b/src/variable.c
index 891cba6..0fa054c 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -588,3 +588,60 @@ GfsVariableClass * gfs_variable_curvature_class (void)
 
   return klass;
 }
+
+/* GfsDerivedVariable: object */
+
+static void gfs_derived_variable_destroy (GtsObject * object)
+{
+  g_free (GFS_DERIVED_VARIABLE (object)->name);
+  g_free (GFS_DERIVED_VARIABLE (object)->description);
+
+  (* GTS_OBJECT_CLASS (gfs_derived_variable_class ())->parent_class->destroy) (object);
+}
+
+static void gfs_derived_variable_class_init (GtsObjectClass * klass)
+{
+  klass->destroy = gfs_derived_variable_destroy;
+}
+
+GtsObjectClass * gfs_derived_variable_class (void)
+{
+  static GtsObjectClass * klass = NULL;
+
+  if (klass == NULL) {
+    GtsObjectClassInfo gfs_derived_variable_info = {
+      "GfsDerivedVariable",
+      sizeof (GfsDerivedVariable),
+      sizeof (GtsObjectClass),
+      (GtsObjectClassInitFunc) gfs_derived_variable_class_init,
+      (GtsObjectInitFunc) NULL,
+      (GtsArgSetFunc) NULL,
+      (GtsArgGetFunc) NULL
+    };
+    klass = gts_object_class_new (GTS_OBJECT_CLASS (gts_object_class ()), 
+				  &gfs_derived_variable_info);
+  }
+
+  return klass;
+}
+
+/**
+ * gfs_derived_variable_from_name:
+ * @i: a list of #GfsDerivedVariable.
+ * @name: a name.
+ *
+ * Returns: the #GfsDerivedVariable @name of @list or %NULL.
+ */
+GfsDerivedVariable * gfs_derived_variable_from_name (GSList * i, const gchar * name)
+{
+  g_return_val_if_fail (name != NULL, NULL);
+
+  while (i) {
+    GfsDerivedVariable * v = i->data;
+    if (!strcmp (v->name, name))
+      return v;
+    i = i->next;
+  }
+  return NULL;
+}
+
diff --git a/src/variable.h b/src/variable.h
index 05bba70..5ddb35f 100644
--- a/src/variable.h
+++ b/src/variable.h
@@ -151,6 +151,27 @@ struct _GfsVariableCurvature {
 
 GfsVariableClass * gfs_variable_curvature_class  (void);
 
+/* GfsDerivedVariable: Header */
+
+struct _GfsDerivedVariable {
+  /*< private >*/
+  GtsObject parent;
+
+  /*< public >*/
+  gchar * name, * description;
+  gpointer func, data;
+};
+
+#define GFS_DERIVED_VARIABLE(obj)            GTS_OBJECT_CAST (obj,\
+					         GfsDerivedVariable,\
+					         gfs_derived_variable_class ())
+#define GFS_IS_DERIVED_VARIABLE(obj)         (gts_object_is_from_class (obj,\
+						 gfs_derived_variable_class ()))
+
+GtsObjectClass *     gfs_derived_variable_class            (void);
+GfsDerivedVariable * gfs_derived_variable_from_name        (GSList * i, 
+							    const gchar * name);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

-- 
Gerris Flow Solver



More information about the debian-science-commits mailing list