[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203
Stephane Popinet
popinet at users.sf.net
Fri May 15 02:56:23 UTC 2009
The following commit has been merged in the upstream branch:
commit 57c0517c790375695b5e44d60eff0ec3392b5d83
Author: Stephane Popinet <popinet at users.sf.net>
Date: Sat May 2 21:16:28 2009 +1000
New 'cleanup' method for GfsVariable
Ignore-this: 1712caa54c750c393346de0c6afa4406
darcs-hash:20090502111628-d4795-2d14361b03ae97d434eb94145db21b6d208a37ce.gz
diff --git a/modules/terrain.mod b/modules/terrain.mod
index f950ea6..5c5a557 100644
--- a/modules/terrain.mod
+++ b/modules/terrain.mod
@@ -846,7 +846,7 @@ static void coarsen_box (GfsBox * box, GfsRefineTerrain * t)
{
ftt_cell_coarsen (box->root,
(FttCellCoarsenFunc) coarsen_boundary, t,
- (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ (FttCellCleanupFunc) gfs_cell_cleanup, gfs_box_domain (box));
}
static void reset_empty_cell (FttCell * cell, GfsRefineTerrain * t)
diff --git a/src/adaptive.c b/src/adaptive.c
index a76d3f8..47ba7e1 100644
--- a/src/adaptive.c
+++ b/src/adaptive.c
@@ -875,7 +875,7 @@ static void fine_cell_cleanup (FttCell * cell, AdaptParams * p)
if ((o = CELL_HFINE (cell)))
gts_eheap_remove (p->hfine, o);
}
- gfs_cell_cleanup (cell);
+ gfs_cell_cleanup (cell, GFS_DOMAIN (p->sim));
}
static void cell_fine_init (FttCell * cell, AdaptParams * p)
@@ -1003,7 +1003,7 @@ static gboolean coarsen_cell (FttCell * cell, AdaptLocalParams * p)
static void cell_cleanup (FttCell * cell, AdaptLocalParams * p)
{
- gfs_cell_cleanup (cell);
+ gfs_cell_cleanup (cell, GFS_DOMAIN (p->sim));
p->s->removed++;
p->nc--;
}
diff --git a/src/boundary.c b/src/boundary.c
index e53b539..18bc70a 100644
--- a/src/boundary.c
+++ b/src/boundary.c
@@ -436,9 +436,13 @@ static void gfs_boundary_destroy (GtsObject * object)
{
GfsBoundary * boundary = GFS_BOUNDARY (object);
- if (boundary->root)
- ftt_cell_destroy (boundary->root,
- (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ if (boundary->root) {
+ GfsDomain * domain = gfs_box_domain (boundary->box);
+ if (domain == NULL) /* domain has been destroyed */
+ ftt_cell_destroy (boundary->root, NULL, NULL);
+ else
+ ftt_cell_destroy (boundary->root, (FttCellCleanupFunc) gfs_cell_cleanup, domain);
+ }
boundary->box->neighbor[FTT_OPPOSITE_DIRECTION (boundary->d)] = NULL;
gts_object_destroy (GTS_OBJECT (boundary->default_bc));
@@ -464,7 +468,7 @@ static void match (FttCell * cell, GfsBoundary * boundary)
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR,
"root cell is entirely outside of the fluid domain\n"
"the solid surface orientation may be incorrect");
- ftt_cell_destroy (cell, (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_destroy (cell, (FttCellCleanupFunc) gfs_cell_cleanup, gfs_box_domain (boundary->box));
boundary->changed = TRUE;
return;
}
@@ -476,7 +480,8 @@ static void match (FttCell * cell, GfsBoundary * boundary)
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR,
"root cell is entirely outside of the fluid domain\n"
"the solid surface orientation may be incorrect");
- ftt_cell_destroy (cell, (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_destroy (cell, (FttCellCleanupFunc) gfs_cell_cleanup,
+ gfs_box_domain (boundary->box));
boundary->changed = TRUE;
return;
}
@@ -538,7 +543,8 @@ static void boundary_match (GfsBoundary * boundary)
l++;
}
if (boundary->changed)
- ftt_cell_flatten (boundary->root, boundary->d, (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_flatten (boundary->root, boundary->d, (FttCellCleanupFunc) gfs_cell_cleanup,
+ gfs_box_domain (boundary->box));
}
static void is_extra (GfsVariable * v, GfsBc * bc, gboolean * extra)
@@ -1202,7 +1208,7 @@ static void match_update (FttCell * cell,
g_assert (boundary->rcvcount < boundary->rcvbuf->len);
is_destroyed[i] = g_array_index (boundary->rcvbuf, gdouble, boundary->rcvcount++);
if (is_destroyed[i] && child.c[i]) {
- ftt_cell_destroy (child.c[i], (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_destroy (child.c[i], (FttCellCleanupFunc) gfs_cell_cleanup, domain);
child.c[i] = NULL;
GFS_BOUNDARY (boundary)->changed = TRUE;
}
@@ -1236,7 +1242,8 @@ static void receive (GfsBoundary * bb,
match_update (GFS_BOUNDARY (boundary)->root, boundary);
ftt_cell_flatten (GFS_BOUNDARY (boundary)->root,
GFS_BOUNDARY (boundary)->d,
- (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ (FttCellCleanupFunc) gfs_cell_cleanup,
+ gfs_box_domain (GFS_BOUNDARY (boundary)->box));
break;
default:
@@ -1458,8 +1465,13 @@ static void gfs_box_destroy (GtsObject * object)
GfsBox * box = GFS_BOX (object);
FttDirection d;
- if (box->root)
- ftt_cell_destroy (box->root, (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ if (box->root) {
+ GfsDomain * domain = gfs_box_domain (box);
+ if (domain == NULL) /* domain has been destroyed */
+ ftt_cell_destroy (box->root, NULL, NULL);
+ else
+ ftt_cell_destroy (box->root, (FttCellCleanupFunc) gfs_cell_cleanup, domain);
+ }
for (d = 0; d < FTT_NEIGHBORS; d++)
if (GFS_IS_BOUNDARY (box->neighbor[d]))
gts_object_destroy (box->neighbor[d]);
@@ -1590,7 +1602,7 @@ static void gfs_box_read (GtsObject ** o, GtsFile * fp)
if (fp->type == '{') {
FttDirection d;
- ftt_cell_destroy (b->root, (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_destroy (b->root, (FttCellCleanupFunc) gfs_cell_cleanup, domain);
fp->scope_max++;
if (domain->binary) {
if (gts_file_getc (fp) != '\n') {
diff --git a/src/boundary.h b/src/boundary.h
index f0c7b4e..73e101c 100644
--- a/src/boundary.h
+++ b/src/boundary.h
@@ -27,7 +27,6 @@
extern "C" {
#endif /* __cplusplus */
-typedef struct _GfsDomain GfsDomain;
typedef struct _GfsBox GfsBox;
typedef struct _GfsBoxClass GfsBoxClass;
typedef struct _GfsBoundary GfsBoundary;
diff --git a/src/domain.c b/src/domain.c
index e4a62ef..a5100ba 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -245,6 +245,18 @@ static void free_pair (gpointer key, gpointer value)
g_free (value);
}
+static void cleanup_each_box (GfsBox * box, GfsDomain * domain)
+{
+ ftt_cell_traverse (box->root, FTT_PRE_ORDER, FTT_TRAVERSE_ALL, -1,
+ (FttCellTraverseFunc) gfs_cell_cleanup, domain);
+ FttDirection d;
+ for (d = 0; d < FTT_NEIGHBORS; d++)
+ if (GFS_IS_BOUNDARY (box->neighbor[d]))
+ ftt_cell_traverse (GFS_BOUNDARY (box->neighbor[d])->root,
+ FTT_PRE_ORDER, FTT_TRAVERSE_ALL, -1,
+ (FttCellTraverseFunc) gfs_cell_cleanup, domain);
+}
+
static void domain_destroy (GtsObject * o)
{
GfsDomain * domain = GFS_DOMAIN (o);
@@ -252,6 +264,8 @@ static void domain_destroy (GtsObject * o)
gfs_clock_destroy (domain->timer);
+ gts_container_foreach (GTS_CONTAINER (domain), (GtsFunc) cleanup_each_box, domain);
+
i = domain->variables;
while (i) {
GSList * next = i->next;
@@ -1773,7 +1787,7 @@ static void box_split (GfsBox * box, SplitPar * p)
for (i = 0; i < FTT_CELLS; i++)
if (child.c[i] && FTT_CELL_IS_LEAF (child.c[i]))
ftt_cell_refine_single (child.c[i], (FttCellInitFunc) gfs_cell_init, domain);
- ftt_cell_destroy_root (boundary->root, &child, (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_destroy_root (boundary->root, &child, (FttCellCleanupFunc) gfs_cell_cleanup, domain);
boundary->root = NULL;
ftt_cell_children_direction (box->root, d, &child);
@@ -1897,7 +1911,8 @@ static void box_destroy (GfsBox * box, GfsVariable * newboxp)
else
newbox[i] = NULL;
- ftt_cell_destroy_root (box->root, &child, (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_destroy_root (box->root, &child, (FttCellCleanupFunc) gfs_cell_cleanup,
+ gfs_box_domain (box));
box->root = NULL;
for (i = 0; i < FTT_CELLS; i++)
if (child.c[i]) {
@@ -2312,7 +2327,7 @@ void gfs_cell_fine_init (FttCell * parent, GfsDomain * domain)
gfs_cell_init (parent, domain);
if (!GFS_CELL_IS_BOUNDARY (parent) && GFS_IS_MIXED (parent))
- gfs_solid_coarse_fine (parent);
+ gfs_solid_coarse_fine (parent, domain);
i = domain->variables;
while (i) {
@@ -2362,7 +2377,7 @@ void gfs_cell_copy (const FttCell * from,
}
}
else if (tos != NULL)
- gfs_cell_cleanup (to);
+ gfs_cell_cleanup (to, domain);
}
/**
diff --git a/src/event.c b/src/event.c
index 37d36c3..71e9291 100644
--- a/src/event.c
+++ b/src/event.c
@@ -1985,7 +1985,7 @@ static gboolean gfs_remove_ponds_event (GfsEvent * event, GfsSimulation * sim)
if ((* GFS_EVENT_CLASS (GTS_OBJECT_CLASS (gfs_remove_ponds_class ())->parent_class)->event)
(event, sim)) {
gfs_domain_remove_ponds (GFS_DOMAIN (sim), GFS_REMOVE_PONDS (event)->min,
- (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ (FttCellCleanupFunc) gfs_cell_cleanup, sim);
return TRUE;
}
return FALSE;
diff --git a/src/fluid.c b/src/fluid.c
index 5770ce6..2e792a5 100644
--- a/src/fluid.c
+++ b/src/fluid.c
@@ -1634,19 +1634,30 @@ void gfs_cell_coarse_fine (FttCell * parent, GfsVariable * v)
/**
* gfs_cell_cleanup:
* @cell: a #FttCell.
+ * @domain: a #GfsDomain.
*
* Frees the memory allocated for extra data associated with @cell.
*
* This function must be used as "cleanup function" when using
* ftt_cell_destroy().
*/
-void gfs_cell_cleanup (FttCell * cell)
+void gfs_cell_cleanup (FttCell * cell, GfsDomain * domain)
{
g_return_if_fail (cell != NULL);
+ g_return_if_fail (domain != NULL);
- if (cell->data && GFS_STATE (cell)->solid) {
- g_free (GFS_STATE (cell)->solid);
- GFS_STATE (cell)->solid = NULL;
+ if (cell->data) {
+ GSList * i = domain->variables;
+ while (i) {
+ GfsVariable * v = i->data;
+ if (v->cleanup)
+ (* v->cleanup) (cell, v);
+ i = i->next;
+ }
+ if (GFS_STATE (cell)->solid) {
+ g_free (GFS_STATE (cell)->solid);
+ GFS_STATE (cell)->solid = NULL;
+ }
}
g_free (cell->data);
cell->data = NULL;
diff --git a/src/fluid.h b/src/fluid.h
index 770eb88..6af8975 100644
--- a/src/fluid.h
+++ b/src/fluid.h
@@ -30,6 +30,7 @@ extern "C" {
typedef struct _GfsVariable GfsVariable;
typedef struct _GfsDerivedVariable GfsDerivedVariable;
+typedef struct _GfsDomain GfsDomain;
typedef struct _GfsStateVector GfsStateVector;
typedef struct _GfsSolidVector GfsSolidVector;
@@ -93,7 +94,8 @@ typedef enum {
FttCellFace gfs_cell_face (FttCell * cell,
FttDirection d);
-void gfs_cell_cleanup (FttCell * cell);
+void gfs_cell_cleanup (FttCell * cell,
+ GfsDomain * domain);
void gfs_cell_reset (FttCell * cell,
GfsVariable * v);
void gfs_get_from_below_intensive (FttCell * cell,
diff --git a/src/simulation.c b/src/simulation.c
index 840a860..22e4e5f 100644
--- a/src/simulation.c
+++ b/src/simulation.c
@@ -1067,7 +1067,7 @@ void gfs_simulation_refine (GfsSimulation * sim)
if (solids) {
gfs_domain_timer_start (domain, "solid_fractions");
sim->thin = gfs_domain_init_solid_fractions (domain, solids, TRUE,
- (FttCellCleanupFunc) gfs_cell_cleanup, NULL,
+ (FttCellCleanupFunc) gfs_cell_cleanup, domain,
NULL);
g_slist_free (solids);
gfs_domain_match (domain);
diff --git a/src/solid.c b/src/solid.c
index 2a7ab16..e215375 100644
--- a/src/solid.c
+++ b/src/solid.c
@@ -1385,16 +1385,18 @@ static void outer_fractions_coarse_fine (FttCell * parent, FttDirection d)
/**
* gfs_solid_coarse_fine:
* @parent: a mixed #FttCell with children.
+ * @domain: a #GfsDomain.
*
* Fills the solid properties of the children of @parent.
* Destroys all children entirely contained in the solid.
*/
-void gfs_solid_coarse_fine (FttCell * parent)
+void gfs_solid_coarse_fine (FttCell * parent, GfsDomain * domain)
{
#if FTT_2D3
g_assert_not_implemented ();
#endif
g_return_if_fail (parent);
+ g_return_if_fail (domain);
g_return_if_fail (GFS_IS_MIXED (parent));
g_return_if_fail (!FTT_CELL_IS_LEAF (parent));
@@ -1481,7 +1483,7 @@ void gfs_solid_coarse_fine (FttCell * parent)
}
}
else if (a == 0.)
- ftt_cell_destroy (child.c[i], (FttCellCleanupFunc) gfs_cell_cleanup, NULL);
+ ftt_cell_destroy (child.c[i], (FttCellCleanupFunc) gfs_cell_cleanup, domain);
}
#if !FTT_2D
diff --git a/src/solid.h b/src/solid.h
index e7d1442..6d47875 100644
--- a/src/solid.h
+++ b/src/solid.h
@@ -65,7 +65,8 @@ void gfs_solid_normal (const FttCell * cell,
FttVector * n);
void gfs_face_ca (const FttCellFace * face,
FttVector * ca);
-void gfs_solid_coarse_fine (FttCell * parent);
+void gfs_solid_coarse_fine (FttCell * parent,
+ GfsDomain * domain);
/* GfsSolid: Header */
diff --git a/src/variable.h b/src/variable.h
index 68eb9d0..933936a 100644
--- a/src/variable.h
+++ b/src/variable.h
@@ -46,6 +46,7 @@ struct _GfsVariable {
GtsContainer * sources;
GfsSurfaceGenericBc * surface_bc;
GfsDomain * domain;
+ FttCellCleanupFunc cleanup;
gdouble units;
};
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list