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

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


The following commit has been merged in the upstream branch:
commit 8c1305f92e7e949c9699fc2eee5004cae13aa65a
Author: Stephane Popinet <popinet at users.sf.net>
Date:   Fri Apr 13 15:46:36 2007 +1000

    New GfsSurface class replaces GtsSurfaceFile and GtsSurface
    
    The GtsSurfaceFile keyword is still supported, however the GtsSurface keyword is
    not and should be replaced by "GfsSurface {}" in old simulation files.
    
    darcs-hash:20070413054636-d4795-42e13848965d3f1b4c1948d4298cad2f8c7a7838.gz

diff --git a/doc/examples/boussinesq/boussinesq.gfs b/doc/examples/boussinesq/boussinesq.gfs
index 9fca19c..401f9fe 100644
--- a/doc/examples/boussinesq/boussinesq.gfs
+++ b/doc/examples/boussinesq/boussinesq.gfs
@@ -36,7 +36,7 @@
   RefineSolid 8
 
   # Insert the solid boundary defined by cylinder.gts
-  GtsSurfaceFile cylinder.gts
+  Surface cylinder.gts
 
   # Add a passive tracer called T
   VariableTracer {} T
diff --git a/doc/examples/cylinder/cylinder.gfs b/doc/examples/cylinder/cylinder.gfs
index 1bc3800..e4905b0 100644
--- a/doc/examples/cylinder/cylinder.gfs
+++ b/doc/examples/cylinder/cylinder.gfs
@@ -48,7 +48,7 @@
   Refine 6
 
   # Insert the solid boundary defined by cylinder.gts
-  GtsSurfaceFile cylinder.gts
+  Surface cylinder.gts
 
   # Add a passive tracer called T
   VariableTracer {} T
diff --git a/doc/examples/cylinder/heated/heated.gfs b/doc/examples/cylinder/heated/heated.gfs
index 6e792d2..6d0a20e 100644
--- a/doc/examples/cylinder/heated/heated.gfs
+++ b/doc/examples/cylinder/heated/heated.gfs
@@ -34,7 +34,7 @@
   Refine 6
 
   # Insert the solid boundary defined by cylinder.gts
-  GtsSurfaceFile cylinder.gts
+  Surface cylinder.gts
 
   # Add a passive tracer called T
   VariableTracer {} T
diff --git a/doc/examples/tangaroa/tangaroa.gfs b/doc/examples/tangaroa/tangaroa.gfs
index bcfa6ce..23fb2f7 100644
--- a/doc/examples/tangaroa/tangaroa.gfs
+++ b/doc/examples/tangaroa/tangaroa.gfs
@@ -22,7 +22,7 @@
 #
 2 1 GfsSimulation GfsBox GfsGEdge {} {
   Time { end = 2 }
-  GtsSurfaceFile tangaroa.gts
+  Surface tangaroa.gts
   Refine 5
   RefineSolid 9
   Init {} { U = 1. }
diff --git a/doc/tutorial/tutorial.tex b/doc/tutorial/tutorial.tex
index 5034953..719711e 100644
--- a/doc/tutorial/tutorial.tex
+++ b/doc/tutorial/tutorial.tex
@@ -897,7 +897,7 @@ We can now insert this object in the simulation domain like this:
 \begin{verbatim}
 4 3 GfsSimulation GfsBox GfsGEdge {} {
   GfsTime { end = 0 }
-  GtsSurfaceFile half-cylinder.gts
+  GfsSurface half-cylinder.gts
 }
 GfsBox { left = GfsBoundaryInflowConstant 1 }
 GfsBox {}
@@ -912,7 +912,7 @@ add what mesh refinement we want and a few things to output:
 4 3 GfsSimulation GfsBox GfsGEdge {} {
   GfsTime { end = 9 }
   GfsRefine 6
-  GtsSurfaceFile half-cylinder.gts
+  GfsSurface half-cylinder.gts
   GfsInit {} { U = 1 }
   GfsOutputBoundaries {} boundaries
   GfsOutputTime { step = 0.02 } stdout
@@ -1012,7 +1012,7 @@ chunks of data.
 The first chunk starts with {\tt GtsSurface} and is
 just the data contained in {\tt half-cylinder.gts} but this time
 embedded directly (by using {\tt GtsSurface} rather than {\tt
-GtsSurfaceFile}) into the simulation file. The goal there is to have
+GfsSurface}) into the simulation file. The goal there is to have
 fully self-contained simulations files which you can just move around
 without having to keep track of twenty different files.
 
@@ -1191,7 +1191,7 @@ Following this we can modify our simulation file:
 4 3 GfsSimulation GfsBox GfsGEdge {} {
   GfsTime { end = 9 }
   GfsRefine 7
-  GtsSurfaceFile half-cylinder.gts
+  GfsSurface half-cylinder.gts
   GfsInit {} { U = 1 }
 #  GfsOutputBoundaries {} boundaries
   GfsAdaptVorticity { istep = 1 } { maxlevel = 7 cmax = 1e-2 }
@@ -1343,7 +1343,7 @@ file like this:
 4 3 GfsSimulation GfsBox GfsGEdge {} {
   GfsTime { end = 9 }
   GfsRefine 7
-  GtsSurfaceFile half-cylinder.gts
+  GfsSurface half-cylinder.gts
   GfsVariableTracer {} T
   ...
   GfsOutputPPM { step = 0.02 } tracer.ppm {
diff --git a/src/init.c b/src/init.c
index 97d2ecb..8497f11 100644
--- a/src/init.c
+++ b/src/init.c
@@ -38,6 +38,7 @@
 #include "ocean.h"
 #include "levelset.h"
 #include "vof.h"
+#include "solid.h"
 
 #include "modules.h"
 
@@ -99,15 +100,6 @@ GtsObjectClass ** gfs_classes (void)
     gfs_advection_class (),
     gfs_poisson_class (),
 
-  gfs_variable_class (),
-    gfs_variable_tracer_class (),
-      gfs_variable_tracer_vof_class (),
-    gfs_variable_residual_class (),
-    gfs_variable_filtered_class (),
-    gfs_variable_curvature_class (),
-      gfs_variable_position_class (),
-    gfs_variable_distance_class (),
-
   gfs_surface_bc_class (),
 
   gfs_box_class (),
@@ -133,12 +125,24 @@ GtsObjectClass ** gfs_classes (void)
       gfs_refine_height_class (),
 
   gfs_event_class (),
+    gfs_variable_class (),
+      gfs_variable_tracer_class (),
+        gfs_variable_tracer_vof_class (),
+      gfs_variable_residual_class (),
+      gfs_variable_filtered_class (),
+      gfs_variable_curvature_class (),
+        gfs_variable_position_class (),
+      gfs_variable_distance_class (),
+
+    gfs_surface_class (),
+
     gfs_init_class (),
     gfs_init_flow_constant_class (),
     gfs_init_fraction_class (),
 #if FTT_2D
     gfs_init_vorticity_class (),
 #endif /* FTT_2D */
+
     gfs_adapt_class (),
       gfs_adapt_vorticity_class (),
       gfs_adapt_streamline_curvature_class (),
diff --git a/src/refine.c b/src/refine.c
index 18a7bb9..2b72ee1 100644
--- a/src/refine.c
+++ b/src/refine.c
@@ -193,28 +193,33 @@ static void refine_solid_read (GtsObject ** o, GtsFile * fp)
   (* GTS_OBJECT_CLASS (gfs_refine_solid_class ())->parent_class->read) (o, fp);
 }
 
-static void refine_cut_cell (FttCell * cell, GtsSurface * s, gpointer * data)
-{
-  GfsRefine * refine = data[0];
-  GfsDomain * domain = data[1];
+typedef struct {
+  GfsRefine * refine;
+  GfsDomain * domain;
+  GtsSurface * surface;
+} RefineCut;
 
-  GTS_OBJECT (s)->reserved = GFS_SIMULATION (domain)->surface;
-  GFS_REFINE_SOLID (refine)->v->data = s;
-  if (ftt_cell_level (cell) < gfs_function_value (refine->maxlevel, cell))
-    ftt_cell_refine_single (cell, (FttCellInitFunc) gfs_cell_fine_init, domain);
-  GFS_REFINE_SOLID (refine)->v->data = NULL;
+static void refine_cut_cell (FttCell * cell, GtsSurface * s, RefineCut * p)
+{
+  GTS_OBJECT (s)->reserved = p->surface;
+  GFS_REFINE_SOLID (p->refine)->v->data = s;
+  if (ftt_cell_level (cell) < gfs_function_value (p->refine->maxlevel, cell))
+    ftt_cell_refine_single (cell, (FttCellInitFunc) gfs_cell_fine_init, p->domain);
+  GFS_REFINE_SOLID (p->refine)->v->data = NULL;
 }
 
 static void gfs_refine_solid_refine (GfsRefine * refine, GfsSimulation * sim)
 {
-  if (sim->surface) {
-    gpointer data[2];
-
-    data[0] = refine;
-    data[1] = sim;
-    gfs_domain_traverse_cut (GFS_DOMAIN (sim), sim->surface, 
+  GtsSurface * surface = gfs_simulation_get_surface (sim);
+  if (surface) {
+    RefineCut p;
+    p.refine = refine;
+    p.domain = GFS_DOMAIN (sim);
+    p.surface = surface;
+    gfs_domain_traverse_cut (GFS_DOMAIN (sim), surface, 
 			     FTT_PRE_ORDER, FTT_TRAVERSE_LEAFS,
-			     (FttCellTraverseCutFunc) refine_cut_cell, data);
+			     (FttCellTraverseCutFunc) refine_cut_cell, &p);
+    gts_object_destroy (GTS_OBJECT (surface));
   }
 }
 
@@ -333,18 +338,19 @@ static void refine_surface_read (GtsObject ** o, GtsFile * fp)
 
 static void gfs_refine_surface_refine (GfsRefine * refine, GfsSimulation * sim)
 {
-  gpointer data[2];
+  RefineCut p;
 
-  data[0] = refine;
-  data[1] = sim;
+  p.refine = refine;
+  p.domain = GFS_DOMAIN (sim);
+  p.surface = GFS_REFINE_SURFACE (refine)->surface;
   if (GFS_REFINE_SURFACE (refine)->twod)
     gfs_domain_traverse_cut_2D (GFS_DOMAIN (sim), GFS_REFINE_SURFACE (refine)->surface,
 				FTT_PRE_ORDER, FTT_TRAVERSE_LEAFS,
-				(FttCellTraverseCutFunc) refine_cut_cell, data);
+				(FttCellTraverseCutFunc) refine_cut_cell, &p);
   else
     gfs_domain_traverse_cut (GFS_DOMAIN (sim), GFS_REFINE_SURFACE (refine)->surface,
 			     FTT_PRE_ORDER, FTT_TRAVERSE_LEAFS,
-			     (FttCellTraverseCutFunc) refine_cut_cell, data);
+			     (FttCellTraverseCutFunc) refine_cut_cell, &p);
 }
 
 static void gfs_refine_surface_class_init (GfsRefineClass * klass)
diff --git a/src/simulation.c b/src/simulation.c
index 70a25a7..7ce5487 100644
--- a/src/simulation.c
+++ b/src/simulation.c
@@ -37,9 +37,6 @@ static void simulation_destroy (GtsObject * object)
 {
   GfsSimulation * sim = GFS_SIMULATION (object);
 
-  if (sim->surface)
-    gts_object_destroy (GTS_OBJECT (sim->surface));
-
   gts_container_foreach (GTS_CONTAINER (sim->refines),
 			 (GtsFunc) gts_object_destroy, NULL);
   gts_object_destroy (GTS_OBJECT (sim->refines));
@@ -48,6 +45,7 @@ static void simulation_destroy (GtsObject * object)
 			 (GtsFunc) gts_object_destroy, NULL);
   gts_object_destroy (GTS_OBJECT (sim->events));
   gts_object_destroy (GTS_OBJECT (sim->adapts));
+  gts_object_destroy (GTS_OBJECT (sim->surfaces));
 
   g_slist_foreach (sim->modules, (GFunc) g_module_close, NULL);
   g_slist_free (sim->modules);
@@ -138,129 +136,9 @@ static void simulation_write (GtsObject * object, FILE * fp)
     i = i->next;
   }
 
-  if (sim->surface && sim->output_surface) {
-    fputs ("  GtsSurface { ", fp);
-    if (GFS_DOMAIN (sim)->binary) {
-      gboolean binary = GTS_POINT_CLASS (sim->surface->vertex_class)->binary;
-      GTS_POINT_CLASS (sim->surface->vertex_class)->binary = TRUE;
-      gts_surface_write (sim->surface, fp);
-      GTS_POINT_CLASS (sim->surface->vertex_class)->binary = binary;
-    }
-    else
-      gts_surface_write (sim->surface, fp);
-    fputs ("}\n", fp);
-  }
   fputc ('}', fp);
 }
 
-static void check_solid_surface (GtsSurface * s, 
-				 const gchar * fname,
-				 GtsFile * fp)
-{
-  GString * name = g_string_new ("surface");
-
-  if (fname) {
-    g_string_append (name, " `");
-    g_string_append (name, fname);
-    g_string_append_c (name, '\'');
-  }
-
-  if (!gts_surface_is_orientable (s))
-    gts_file_error (fp, "%s is not orientable", name->str);
-  g_string_free (name, TRUE);
-}
-
-static GtsSurface * read_surface_file (GtsFile * fp, GtsSurface * surface)
-{
-  GtsSurface * s;
-  FILE * fptr;
-  GtsFile * fp1;
-  
-  gts_file_next_token (fp);
-  if (fp->type != GTS_STRING) {
-    gts_file_error (fp, "expecting a string (filename)");
-    return NULL;
-  }
-  s = gts_surface_new (gts_surface_class (),
-		       gts_face_class (),
-		       gts_edge_class (),
-		       surface ? surface->vertex_class : gts_vertex_class ());
-  fptr = fopen (fp->token->str, "rt");
-  if (fptr == NULL) {
-    gts_file_error (fp, "cannot open file `%s'", fp->token->str);
-    return NULL;
-  }
-  fp1 = gts_file_new (fptr);
-  if (gts_surface_read (s, fp1)) {
-    gts_file_error (fp, 
-		    "file `%s' is not a valid GTS file\n"
-		    "%s:%d:%d: %s",
-		    fp->token->str, fp->token->str,
-		    fp1->line, fp1->pos, fp1->error);
-    gts_file_destroy (fp1);
-    fclose (fptr);
-    gts_object_destroy (GTS_OBJECT (s));
-    return NULL;
-  }
-  gts_file_destroy (fp1);
-  fclose (fptr);
-  
-  check_solid_surface (s, fp->token->str, fp);
-  if (fp->type == GTS_ERROR) {
-    gts_object_destroy (GTS_OBJECT (s));
-    return NULL;
-  }
-  
-  if (surface) {
-    gts_surface_merge (surface, s);
-    gts_object_destroy (GTS_OBJECT (s));
-    return surface;
-  }
-  return s;
-}
-
-static GtsSurface * read_surface (GtsFile * fp, GtsSurface * surface)
-{
-  GtsSurface * s;
-
-  gts_file_next_token (fp);
-  if (fp->type != '{') {
-    gts_file_error (fp, "expecting an opening brace");
-    return NULL;
-  }
-  fp->scope_max++;
-  gts_file_next_token (fp);
-  
-  s = gts_surface_new (gts_surface_class (),
-		       gts_face_class (),
-		       gts_edge_class (),
-		       surface ? surface->vertex_class : gts_vertex_class ());
-  
-  if (gts_surface_read (s, fp)) {
-    gts_object_destroy (GTS_OBJECT (s));
-    return NULL;
-  }
-  if (fp->type != '}') {
-    gts_object_destroy (GTS_OBJECT (s));
-    gts_file_error (fp, "expecting a closing brace");
-    return NULL;
-  }
-  fp->scope_max--;
-  
-  check_solid_surface (s, NULL, fp);
-  if (fp->type == GTS_ERROR) {
-    gts_object_destroy (GTS_OBJECT (s));
-    return NULL;
-  }
-  
-  if (surface) {
-    gts_surface_merge (surface, s);
-    gts_object_destroy (GTS_OBJECT (s));
-    return surface;
-  }
-  return s;
-}
-
 static gboolean strmatch (const gchar * s, const gchar * s1)
 {
   gboolean m = !strcmp (s, s1);
@@ -298,28 +176,8 @@ static void simulation_read (GtsObject ** object, GtsFile * fp)
       return;
     }
 
-    /* ------------ GtsSurface ------------ */
-    if (strmatch (fp->token->str, "GtsSurface")) {
-      GtsSurface * s;
-      
-      if ((s = read_surface (fp, sim->surface)) == NULL)
-	return;
-      sim->surface = s;
-      gts_file_next_token (fp);
-    }
-
-    /* ------------ GtsSurfaceFile ------------ */
-    else if (strmatch (fp->token->str, "GtsSurfaceFile")) {
-      GtsSurface * s;
-
-      if ((s = read_surface_file (fp, sim->surface)) == NULL)
-	return;
-      sim->surface = s;
-      gts_file_next_token (fp);
-    }
-
     /* ------------ GModule ------------ */
-    else if (strmatch (fp->token->str, "GModule")) {
+    if (!strcmp (fp->token->str, "GModule")) {
       gts_file_next_token (fp);
       if (fp->type != GTS_STRING) {
 	gts_file_error (fp, "expecting a string (filename)");
@@ -393,11 +251,7 @@ static void simulation_read (GtsObject ** object, GtsFile * fp)
       GtsObjectClass * klass = gfs_object_class_from_name (fp->token->str);
       GtsObject * object;
 
-      if (klass == NULL ||
-	  (!gts_object_class_is_from_class (klass, gfs_global_class ()) &&
-	   !gts_object_class_is_from_class (klass, gfs_refine_class ()) &&
-	   !gts_object_class_is_from_class (klass, gfs_event_class ()) &&
-	   !gts_object_class_is_from_class (klass, gfs_surface_generic_bc_class ()))) {
+      if (klass == NULL) {
 	gts_file_error (fp, "unknown keyword `%s'", fp->token->str);
 	return;
       }
@@ -420,6 +274,10 @@ static void simulation_read (GtsObject ** object, GtsFile * fp)
 	gts_container_add (GTS_CONTAINER (sim->adapts), GTS_CONTAINEE (object));
 	gts_container_add (GTS_CONTAINER (sim->events), GTS_CONTAINEE (object));
       }
+      else if (GFS_IS_SURFACE (object)) {
+	gts_container_add (GTS_CONTAINER (sim->surfaces), GTS_CONTAINEE (object));
+	gts_container_add (GTS_CONTAINER (sim->events), GTS_CONTAINEE (object));
+      }
       else if (GFS_IS_EVENT (object))
 	gts_container_add (GTS_CONTAINER (sim->events), GTS_CONTAINEE (object));
       else if (GFS_IS_SURFACE_GENERIC_BC (object))
@@ -439,6 +297,7 @@ static void simulation_read (GtsObject ** object, GtsFile * fp)
   sim->refines->items = g_slist_reverse (sim->refines->items);
   sim->adapts->items = g_slist_reverse (sim->adapts->items);
   sim->events->items = g_slist_reverse (sim->events->items);
+  sim->surfaces->items = g_slist_reverse (sim->surfaces->items);
   sim->modules = g_slist_reverse (sim->modules);
 }
 
@@ -824,7 +683,9 @@ static void simulation_init (GfsSimulation * object)
   gfs_multilevel_params_init (&object->projection_params);
   gfs_multilevel_params_init (&object->approx_projection_params);
 
-  object->surface = NULL;
+  object->surfaces = GTS_SLIST_CONTAINER (gts_container_new
+					  (GTS_CONTAINER_CLASS
+					   (gts_slist_container_class ())));
   object->output_surface = TRUE;
 
   object->refines = GTS_SLIST_CONTAINER (gts_container_new
@@ -881,6 +742,34 @@ static void init_non_variable (GfsEvent * event, GfsSimulation * sim)
 }
 
 /**
+ * gfs_simulation_get_surface:
+ * @sim: a #GfsSimulation.
+ *
+ * Returns: a new #GtsSurface containing all the solid surfaces
+ * defined in @sim, or %NULL if @sim does not contain any solid
+ * surface.
+ */
+GtsSurface * gfs_simulation_get_surface (GfsSimulation * sim)
+{
+  g_return_val_if_fail (sim != NULL, NULL);
+
+  if (sim->surfaces->items == NULL)
+    return NULL;
+  else {
+    GtsSurface * s = gts_surface_new (gts_surface_class (), 
+				      gts_face_class (), 
+				      gts_edge_class (), 
+				      gts_vertex_class ());
+    GSList * i = sim->surfaces->items;
+    while (i) {
+      gts_surface_merge (s, GFS_SURFACE (i->data)->s);
+      i = i->next;
+    }
+    return s;
+  }
+}
+
+/**
  * gfs_simulation_init:
  * @sim: a #GfsSimulation.
  *
@@ -979,11 +868,13 @@ void gfs_simulation_refine (GfsSimulation * sim)
   gfs_domain_match (domain);
   gfs_domain_timer_stop (domain, "simulation_refine");
 
-  if (sim->surface) {
+  GtsSurface * surface = gfs_simulation_get_surface (sim);
+  if (surface) {
     gfs_domain_timer_start (domain, "solid_fractions");
-    sim->thin = gfs_domain_init_solid_fractions (domain, sim->surface, TRUE,
-						 (FttCellCleanupFunc) gfs_cell_cleanup, NULL, 
+    sim->thin = gfs_domain_init_solid_fractions (domain, surface, TRUE,
+						 (FttCellCleanupFunc) gfs_cell_cleanup, NULL,  
 						 NULL);
+    gts_object_destroy (GTS_OBJECT (surface));
     gfs_domain_match (domain);
     gfs_domain_traverse_mixed (domain, FTT_PRE_ORDER, FTT_TRAVERSE_LEAFS,
 			       (FttCellTraverseFunc) set_permanent, NULL);
diff --git a/src/simulation.h b/src/simulation.h
index 60096ac..bf9a3a1 100644
--- a/src/simulation.h
+++ b/src/simulation.h
@@ -63,10 +63,6 @@ struct _GfsSimulation {
 
   GfsAdvectionParams advection_params;
 
-  GtsSurface * surface;
-  guint thin;
-  gboolean output_surface;
-
   GtsSListContainer * refines;
 
   GtsSListContainer * adapts;
@@ -75,6 +71,10 @@ struct _GfsSimulation {
   GtsSListContainer * events;
   GSList * modules, * variables, * globals;
 
+  GtsSListContainer * surfaces;
+  guint thin;
+  gboolean output_surface;
+
   gdouble tnext;
 };
 
@@ -95,6 +95,7 @@ struct _GfsSimulationClass {
 
 GfsSimulationClass * gfs_simulation_class        (void);
 GfsSimulation *      gfs_simulation_new          (GfsSimulationClass * klass);
+GtsSurface *         gfs_simulation_get_surface  (GfsSimulation * sim);
 void                 gfs_simulation_init         (GfsSimulation * sim);
 void                 gfs_simulation_write        (GfsSimulation * sim,
 						  gint max_depth,  
diff --git a/src/solid.c b/src/solid.c
index f4309de..1a99ddd 100644
--- a/src/solid.c
+++ b/src/solid.c
@@ -1460,3 +1460,138 @@ void gfs_solid_coarse_fine (FttCell * parent)
       outer_fractions_coarse_fine (parent, d);
 #endif /* 3D */
 }
+
+/* GfsSurface: Object */
+
+static void check_solid_surface (GtsSurface * s, 
+				 const gchar * fname,
+				 GtsFile * fp)
+{
+  GString * name = g_string_new ("surface");
+
+  if (fname) {
+    g_string_append (name, " `");
+    g_string_append (name, fname);
+    g_string_append_c (name, '\'');
+  }
+
+  if (!gts_surface_is_orientable (s))
+    gts_file_error (fp, "%s is not orientable", name->str);
+  g_string_free (name, TRUE);
+}
+
+static void gfs_surface_read (GtsObject ** o, GtsFile * fp)
+{
+  (* GTS_OBJECT_CLASS (gfs_surface_class ())->parent_class->read) (o, fp);
+  if (fp->type == GTS_ERROR)
+    return;
+
+  GtsSurface * s = GFS_SURFACE (*o)->s;
+  if (fp->type == '{') {
+    fp->scope_max++;
+    gts_file_next_token (fp);
+    if (gts_surface_read (s, fp))
+      return;
+    if (fp->type != '}') {
+      gts_file_error (fp, "expecting a closing brace");
+      return;
+    }
+    check_solid_surface (s, NULL, fp);
+    if (fp->type == GTS_ERROR)
+      return;
+    fp->scope_max--;
+  }
+  else {
+    if (fp->type != GTS_STRING) {
+      gts_file_error (fp, "expecting a string (filename)");
+      return;
+    }
+    FILE * fptr = fopen (fp->token->str, "rt");
+    if (fptr == NULL) {
+      gts_file_error (fp, "cannot open file `%s'", fp->token->str);
+      return;
+    }
+    GtsFile * fp1 = gts_file_new (fptr);
+    if (gts_surface_read (s, fp1)) {
+      gts_file_error (fp, 
+		      "file `%s' is not a valid GTS file\n"
+		      "%s:%d:%d: %s",
+		      fp->token->str, fp->token->str,
+		      fp1->line, fp1->pos, fp1->error);
+      gts_file_destroy (fp1);
+      fclose (fptr);
+      return;
+    }
+    gts_file_destroy (fp1);
+    fclose (fptr);
+  
+    check_solid_surface (s, fp->token->str, fp);
+    if (fp->type == GTS_ERROR)
+      return;
+  }
+  gts_file_next_token (fp);
+}
+
+static void gfs_surface_write (GtsObject * o, FILE * fp)
+{
+  GfsSimulation * sim = gfs_object_simulation (o);
+  if (sim->output_surface) {
+    (* GTS_OBJECT_CLASS (gfs_surface_class ())->parent_class->write) (o, fp);
+
+    fputs (" { ", fp);
+    GtsSurface * s = GFS_SURFACE (o)->s;
+    if (GFS_DOMAIN (sim)->binary) {
+      gboolean binary = GTS_POINT_CLASS (s->vertex_class)->binary;
+      GTS_POINT_CLASS (s->vertex_class)->binary = TRUE;
+      gts_surface_write (s, fp);
+      GTS_POINT_CLASS (s->vertex_class)->binary = binary;
+    }
+    else
+      gts_surface_write (s, fp);
+    fputc ('}', fp);
+  }
+}
+
+static void gfs_surface_destroy (GtsObject * object)
+{
+  gts_object_destroy (GTS_OBJECT (GFS_SURFACE (object)->s));
+
+  (* GTS_OBJECT_CLASS (gfs_surface_class ())->parent_class->destroy) (object);
+}
+
+static void gfs_surface_class_init (GtsSurfaceClass * klass)
+{
+  GTS_OBJECT_CLASS (klass)->read = gfs_surface_read;
+  GTS_OBJECT_CLASS (klass)->write = gfs_surface_write;
+  GTS_OBJECT_CLASS (klass)->destroy = gfs_surface_destroy;
+}
+
+static void gfs_surface_init (GfsSurface * object)
+{
+  object->s = gts_surface_new (gts_surface_class (), 
+			       gts_face_class (), 
+			       gts_edge_class (), 
+			       gts_vertex_class ());
+  GFS_EVENT (object)->istep = G_MAXINT/2;
+}
+
+GfsEventClass * gfs_surface_class (void)
+{
+  static GfsEventClass * klass = NULL;
+
+  if (klass == NULL) {
+    GtsObjectClassInfo gfs_surface_info = {
+      "GfsSurface",
+      sizeof (GfsSurface),
+      sizeof (GfsEventClass),
+      (GtsObjectClassInitFunc) gfs_surface_class_init,
+      (GtsObjectInitFunc) gfs_surface_init,
+      (GtsArgSetFunc) NULL,
+      (GtsArgGetFunc) NULL
+    };
+    klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_event_class ()),
+				  &gfs_surface_info);
+  }
+
+  return klass;
+}
diff --git a/src/solid.h b/src/solid.h
index 5230d06..a9c6d61 100644
--- a/src/solid.h
+++ b/src/solid.h
@@ -23,6 +23,7 @@
 #include <gts.h>
 
 #include "domain.h"
+#include "event.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -52,6 +53,26 @@ void         gfs_face_ca                                 (const FttCellFace * fa
 							  FttVector * ca);
 void         gfs_solid_coarse_fine                       (FttCell * parent);
 
+/* GfsSurface: Header */
+
+typedef struct _GfsSurface         GfsSurface;
+
+struct _GfsSurface {
+  /*< private >*/
+  GfsEvent parent;
+
+  /*< public >*/
+  GtsSurface * s;
+};
+
+#define GFS_SURFACE(obj)            GTS_OBJECT_CAST (obj,\
+					         GfsSurface,\
+					         gfs_surface_class ())
+#define GFS_IS_SURFACE(obj)         (gts_object_is_from_class (obj,\
+						 gfs_surface_class ()))
+
+GfsEventClass * gfs_surface_class  (void);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/src/utils.c b/src/utils.c
index b5fafdd..6470d72 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1004,12 +1004,14 @@ GtsObjectClass * gfs_object_class_from_name (const gchar * name)
 
   g_return_val_if_fail (name != NULL, NULL);
 
-  klass = gts_object_class_from_name (name);
-  if (klass == NULL) {
-    gchar * ename = g_strconcat ("Gfs", name, NULL);
-    klass = gts_object_class_from_name (ename);
-    g_free (ename);
-  }
+  if ((klass = gts_object_class_from_name (name)))
+    return klass;
+  /* for backward parameter file compatibility */
+  if (!strcmp (name, "GtsSurfaceFile"))
+    return GTS_OBJECT_CLASS (gfs_surface_class ());
+  gchar * ename = g_strconcat ("Gfs", name, NULL);
+  klass = gts_object_class_from_name (ename);
+  g_free (ename);
   return klass;
 }
 
diff --git a/test/boundaries/boundaries.gfs b/test/boundaries/boundaries.gfs
index ec944df..67e2162 100644
--- a/test/boundaries/boundaries.gfs
+++ b/test/boundaries/boundaries.gfs
@@ -34,7 +34,7 @@
   AdvectionParams { scheme = none }
   ApproxProjectionParams { tolerance = 1e-6 }
   Refine LEVEL
-  GtsSurfaceFile boundaries.gts
+  Surface boundaries.gts
   Init {} { U = 1 }
   OutputSimulation { start = end } sim-LEVEL {
     variables = U,V,P
diff --git a/test/channel/channel.gfs b/test/channel/channel.gfs
index 8ea2b8b..ceafa11 100644
--- a/test/channel/channel.gfs
+++ b/test/channel/channel.gfs
@@ -34,7 +34,7 @@
   ProjectionParams { tolerance = 1e-6 }
   ApproxProjectionParams { tolerance = 1e-6 }
   Refine LEVEL
-  GtsSurfaceFile channel.gts
+  Surface channel.gts
   Init {} { U = 1 }
   OutputSimulation { start = end } sim-LEVEL {
     variables = U,V,P
diff --git a/test/circle/circle.gfs b/test/circle/circle.gfs
index 35bc19d..548ba97 100644
--- a/test/circle/circle.gfs
+++ b/test/circle/circle.gfs
@@ -54,7 +54,7 @@
 1 0 GfsPoisson GfsBox GfsGEdge {} {
   Time { iend = 10 }
   Refine LEVEL
-  GtsSurfaceFile shape.gts
+  Surface shape.gts
   ApproxProjectionParams { nrelax = 4 tolerance = 1e-30 erelax = 2 }
   Init {} {
     Div = {
diff --git a/test/circle/refined/refined.gfs b/test/circle/refined/refined.gfs
index c7d9c08..8b627c0 100644
--- a/test/circle/refined/refined.gfs
+++ b/test/circle/refined/refined.gfs
@@ -50,7 +50,7 @@
   Time { iend = 10 }
   Refine LEVEL
   RefineSolid (LEVEL + 2)
-  GtsSurfaceFile shape.gts
+  Surface shape.gts
   ApproxProjectionParams { nrelax = 4 tolerance = 1e-30 }
   Init {} {
     Div = {
diff --git a/test/circle/star/star.gfs b/test/circle/star/star.gfs
index 521e53e..51baa81 100644
--- a/test/circle/star/star.gfs
+++ b/test/circle/star/star.gfs
@@ -56,7 +56,7 @@
 1 0 GfsPoisson GfsBox GfsGEdge {} {
   Time { iend = 10 }
   Refine LEVEL
-  GtsSurfaceFile shape.gts
+  Surface shape.gts
   ApproxProjectionParams { nrelax = 4 tolerance = 1e-30 erelax = 2 }
   Init {} {
     Div = {
diff --git a/test/couette/couette.gfs b/test/couette/couette.gfs
index 2ace70b..1f313d8 100644
--- a/test/couette/couette.gfs
+++ b/test/couette/couette.gfs
@@ -40,8 +40,8 @@
 1 0 GfsSimulation GfsBox GfsGEdge {} {
   Time { iend = 100 dtmax = 1e-2 }
   Refine 6
-  GtsSurfaceFile outer.gts
-  GtsSurfaceFile inner.gts
+  Surface outer.gts
+  Surface inner.gts
   ApproxProjectionParams { tolerance = 1e-6 }
   AdvectionParams { scheme = none }
   SourceViscosity {} {
diff --git a/test/dumbell/dumbell.gfs b/test/dumbell/dumbell.gfs
index 41e649e..f1ccf40 100644
--- a/test/dumbell/dumbell.gfs
+++ b/test/dumbell/dumbell.gfs
@@ -13,7 +13,7 @@
 1 0 GfsPoisson GfsBox GfsGEdge {} {
   Refine 3
   ApproxProjectionParams { nitermax = 1000 minlevel = 1 tolerance = 1e-30 }
-  GtsSurfaceFile dumbell.gts
+  Surface dumbell.gts
   Init {} { Div = y }
   OutputProjectionStats { istep = 1 } stdout
 }
diff --git a/test/nz/nz.gfs b/test/nz/nz.gfs
index 7644e7c..3e710d3 100644
--- a/test/nz/nz.gfs
+++ b/test/nz/nz.gfs
@@ -45,7 +45,7 @@
     AdvectionParams { scheme = none }
     Init {} { P = 1e-2*x }
     # Bathymetry
-    GtsSurfaceFile bath.gts
+    Surface bath.gts
     # Refine the coastline to 7 levels
     RefineSurface 7 bath.gts { twod = 1 }
     # Non-dimensional gravity
diff --git a/test/plate/plate.gfs b/test/plate/plate.gfs
index ec28635..bb25f33 100644
--- a/test/plate/plate.gfs
+++ b/test/plate/plate.gfs
@@ -16,7 +16,7 @@
   Time { iend = 30 dtmax = 1e-2 }
   Refine 5
   RefineSolid 6
-  GtsSurfaceFile square.gts
+  Surface square.gts
   AdvectionParams { scheme = none }
   Init {} { U = 1 }
   OutputScalarNorm { start = end } stdout { v = Velocity } 
diff --git a/test/waves/adaptive/adaptive.gfs b/test/waves/adaptive/adaptive.gfs
index 2ee872b..ecb60c3 100644
--- a/test/waves/adaptive/adaptive.gfs
+++ b/test/waves/adaptive/adaptive.gfs
@@ -81,7 +81,7 @@
   }
   Refine LEVEL
   AdaptVorticity { istep = 1 } { cmax = 5e-2 maxlevel = LEVEL }
-  GtsSurfaceFile basin.gts
+  Surface basin.gts
   AdvectionParams { scheme = none }
   ApproxProjectionParams { tolerance = 1e-9 weighted = 0 }
   SourceCoriolis {} 1.
diff --git a/test/waves/waves.gfs b/test/waves/waves.gfs
index d0f1b82..f198713 100644
--- a/test/waves/waves.gfs
+++ b/test/waves/waves.gfs
@@ -92,7 +92,7 @@
     H = 1
   }
   Refine LEVEL
-  GtsSurfaceFile basin.gts
+  Surface basin.gts
   AdvectionParams { scheme = none }
   ApproxProjectionParams { tolerance = 1e-9 weighted = 0 }
   SourceCoriolis {} 1.
diff --git a/tools/gfs2oogl.c b/tools/gfs2oogl.c
index 6d8eb7e..69f6ab5 100644
--- a/tools/gfs2oogl.c
+++ b/tools/gfs2oogl.c
@@ -1157,7 +1157,7 @@ int main (int argc, char * argv[])
       GtsSurface * s = surface;
 
       if (s == NULL)
-	s = simulation->surface;
+	s = gfs_simulation_get_surface (simulation);
 
       if (s) {
 	if (refine)

-- 
Gerris Flow Solver



More information about the debian-science-commits mailing list