[SCM] Gerris Flow Solver branch, upstream, updated. e8f73a07832050124d2b8bf6c6f35b33180e65a8
Stephane Popinet
s.popinet at niwa.co.nz
Tue Nov 24 12:25:27 UTC 2009
The following commit has been merged in the upstream branch:
commit 2dd8a1b4844411af5e63860ffb9e798225fdce3d
Author: Stephane Popinet <s.popinet at niwa.co.nz>
Date: Sun Nov 1 13:18:54 2009 +1100
Metrics descend from GfsVariableMetric
Ignore-this: 5c25bd3c1a1e35a143ba937dcd3b63b
darcs-hash:20091101021854-fbd8f-bd33a7aeda4e94208e6868f65417c96bf15a0957.gz
diff --git a/src/domain.c b/src/domain.c
index ee147ac..186faa6 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -30,6 +30,7 @@
#include "solid.h"
#include "adaptive.h"
#include "mpi_boundary.h"
+#include "metric.h"
#include "version.h"
#include "config.h"
@@ -2705,11 +2706,22 @@ void gfs_cell_fine_init (FttCell * parent, GfsDomain * domain)
if (!GFS_CELL_IS_BOUNDARY (parent) && GFS_IS_MIXED (parent))
gfs_solid_coarse_fine (parent, domain);
+ /* metric is used by gfs_cell_coarse_fine(), make sure it is
+ initialised first */
i = domain->variables;
while (i) {
GfsVariable * v = i->data;
-
- (* v->coarse_fine) (parent, v);
+ if (GFS_IS_VARIABLE_METRIC (v))
+ (* v->coarse_fine) (parent, v);
+ i = i->next;
+ }
+
+ /* initialise remaining variables */
+ i = domain->variables;
+ while (i) {
+ GfsVariable * v = i->data;
+ if (!GFS_IS_VARIABLE_METRIC (v))
+ (* v->coarse_fine) (parent, v);
i = i->next;
}
}
diff --git a/src/fluid.c b/src/fluid.c
index 227c8f7..bb6e8af 100644
--- a/src/fluid.c
+++ b/src/fluid.c
@@ -1702,6 +1702,7 @@ void gfs_cell_coarse_fine (FttCell * parent, GfsVariable * v)
a[n] = (* v->domain->cell_metric) (v->domain, child.c[n]);
sa += a[n];
}
+ g_assert (sa > 0.);
sa *= 2.;
#if FTT_2D
double gx1 = g.x*(a[0] + a[2])/sa, gx2 = - g.x*(a[1] + a[3])/sa;
diff --git a/src/metric.c b/src/metric.c
index 6b5124a..7cf2c53 100644
--- a/src/metric.c
+++ b/src/metric.c
@@ -23,6 +23,31 @@
#include "map.h"
#include "solid.h"
+/* GfsVariableMetric */
+
+GfsVariableClass * gfs_variable_metric_class (void)
+{
+ static GfsVariableClass * klass = NULL;
+
+ if (klass == NULL) {
+ GtsObjectClassInfo gfs_variable_metric_info = {
+ "GfsVariableMetric",
+ sizeof (GfsVariable),
+ sizeof (GfsVariableClass),
+ (GtsObjectClassInitFunc) NULL,
+ (GtsObjectInitFunc) NULL,
+ (GtsArgSetFunc) NULL,
+ (GtsArgGetFunc) NULL
+ };
+ klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_variable_class ()),
+ &gfs_variable_metric_info);
+ }
+
+ return klass;
+}
+
+/* "Expanded spherical cube" metric */
+
#define N 30
#if 0
@@ -353,7 +378,7 @@ static gdouble cubed_face_metric (const GfsDomain * domain, const FttCellFace *
static gdouble cubed_cell_metric (const GfsDomain * domain, const FttCell * cell)
{
- return GFS_VALUE (cell, GFS_METRIC_CUBED (domain->metric_data)->a);
+ return GFS_VALUE (cell, GFS_VARIABLE1 (domain->metric_data));
}
static gdouble cubed_solid_metric (const GfsDomain * domain, const FttCell * cell)
@@ -465,8 +490,7 @@ static void cubed_coarse_fine (FttCell * parent, GfsVariable * a)
if (GFS_CELL_IS_BOUNDARY (parent))
return;
- GfsMetricCubed * cubed = GTS_OBJECT (a)->reserved;
- g_assert (GFS_IS_METRIC_CUBED (cubed));
+ GfsMetricCubed * cubed = GFS_METRIC_CUBED (a);
Point ** r = matrix_from_cell (parent);
r = matrix_refine (r, 2);
int n = 3, level = cubed->level - (ftt_cell_level (parent) + 1);
@@ -507,8 +531,7 @@ static void cubed_coarse_fine (FttCell * parent, GfsVariable * a)
static void cubed_fine_coarse (FttCell * parent, GfsVariable * a)
{
- GfsMetricCubed * cubed = GTS_OBJECT (a)->reserved;
- g_assert (GFS_IS_METRIC_CUBED (cubed));
+ GfsMetricCubed * cubed = GFS_METRIC_CUBED (a);
FttCellChildren child;
guint n;
@@ -547,7 +570,8 @@ static void metric_cubed_read (GtsObject ** o, GtsFile * fp)
return;
}
- GfsMetricCubed * cubed = GFS_METRIC_CUBED (*o);
+ GfsVariable * a = GFS_VARIABLE1 (*o);
+ GfsMetricCubed * cubed = GFS_METRIC_CUBED (a);
if (fp->type == GTS_INT) {
cubed->level = atoi (fp->token->str);
gts_file_next_token (fp);
@@ -555,15 +579,15 @@ static void metric_cubed_read (GtsObject ** o, GtsFile * fp)
FttDirection d;
for (d = 0; d < FTT_NEIGHBORS; d++) {
- gchar * name = g_strdup_printf ("Ch%d", d);
+ gchar * name = g_strdup_printf ("%sh%d", a->name, d);
cubed->h[d] = gfs_domain_get_or_add_variable (domain, name, "Cubed face metric");
cubed->h[d]->fine_coarse = cubed->h[d]->coarse_fine = none;
g_free (name);
}
- cubed->a = gfs_domain_get_or_add_variable (domain, "Ca", "Cubed cell metric");
- GTS_OBJECT (cubed->a)->reserved = cubed;
- cubed->a->coarse_fine = cubed_coarse_fine;
- cubed->a->fine_coarse = cubed_fine_coarse;
+ g_free (a->description);
+ a->description = g_strdup ("Cubed cell metric");
+ a->coarse_fine = cubed_coarse_fine;
+ a->fine_coarse = cubed_fine_coarse;
GtsObject * map = gts_object_new (GTS_OBJECT_CLASS (gfs_map_cubed_class ()));
gfs_object_simulation_set (map, domain);
@@ -582,26 +606,21 @@ static void metric_cubed_class_init (GtsObjectClass * klass)
klass->write = metric_cubed_write;
}
-static void metric_cubed_init (GfsEvent * m)
-{
- m->istep = G_MAXINT/2;
-}
-
-GfsEventClass * gfs_metric_cubed_class (void)
+GfsVariableClass * gfs_metric_cubed_class (void)
{
- static GfsEventClass * klass = NULL;
+ static GfsVariableClass * klass = NULL;
if (klass == NULL) {
GtsObjectClassInfo gfs_metric_cubed_info = {
"GfsMetricCubed",
sizeof (GfsMetricCubed),
- sizeof (GfsEventClass),
+ sizeof (GfsVariableClass),
(GtsObjectClassInitFunc) metric_cubed_class_init,
- (GtsObjectInitFunc) metric_cubed_init,
+ (GtsObjectInitFunc) NULL,
(GtsArgSetFunc) NULL,
(GtsArgGetFunc) NULL
};
- klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_event_class ()),
+ klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_variable_metric_class ()),
&gfs_metric_cubed_info);
}
@@ -706,7 +725,7 @@ static gdouble lon_lat_face_metric (const GfsDomain * domain, const FttCellFace
static gdouble lon_lat_cell_metric (const GfsDomain * domain, const FttCell * cell)
{
- return GFS_VALUE (cell, GFS_METRIC_LON_LAT (domain->metric_data)->a);
+ return GFS_VALUE (cell, GFS_VARIABLE1 (domain->metric_data));
}
static gdouble lon_lat_solid_metric (const GfsDomain * domain, const FttCell * cell)
@@ -720,7 +739,7 @@ static gdouble lon_lat_scale_metric (const GfsDomain * domain, const FttCell * c
{
if (c != FTT_X)
return 1.;
- return GFS_VALUE (cell, GFS_METRIC_LON_LAT (domain->metric_data)->a);
+ return GFS_VALUE (cell, GFS_VARIABLE1 (domain->metric_data));
}
static void lonlat_coarse_fine (FttCell * parent, GfsVariable * a)
@@ -728,8 +747,7 @@ static void lonlat_coarse_fine (FttCell * parent, GfsVariable * a)
if (GFS_CELL_IS_BOUNDARY (parent))
return;
- GfsMetricLonLat * lonlat = GTS_OBJECT (a)->reserved;
- g_assert (GFS_IS_METRIC_LON_LAT (lonlat));
+ GfsMetricLonLat * lonlat = GFS_METRIC_LON_LAT (a);
FttCellChildren child;
ftt_cell_children (parent, &child);
FttVector p;
@@ -754,8 +772,7 @@ static void lonlat_coarse_fine (FttCell * parent, GfsVariable * a)
static void lonlat_fine_coarse (FttCell * parent, GfsVariable * a)
{
- GfsMetricLonLat * lonlat = GTS_OBJECT (a)->reserved;
- g_assert (GFS_IS_METRIC_LON_LAT (lonlat));
+ GfsMetricLonLat * lonlat = GFS_METRIC_LON_LAT (a);
FttCellChildren child;
guint n;
@@ -791,15 +808,20 @@ static void metric_lon_lat_read (GtsObject ** o, GtsFile * fp)
return;
}
- GfsMetricLonLat * lonlat = GFS_METRIC_LON_LAT (*o);
- lonlat->h2 = gfs_domain_get_or_add_variable (domain, "Lh2", "LonLat face metric");
+ GfsVariable * a = GFS_VARIABLE1 (*o);
+ GfsMetricLonLat * lonlat = GFS_METRIC_LON_LAT (a);
+ gchar * name = g_strdup_printf ("%sh2", a->name);
+ lonlat->h2 = gfs_domain_get_or_add_variable (domain, name, "LonLat face metric");
lonlat->h2->coarse_fine = lonlat->h2->fine_coarse = none;
- lonlat->h3 = gfs_domain_get_or_add_variable (domain, "Lh3", "LonLat face metric");
+ g_free (name);
+ name = g_strdup_printf ("%sh3", a->name);
+ lonlat->h3 = gfs_domain_get_or_add_variable (domain, name, "LonLat face metric");
lonlat->h3->coarse_fine = lonlat->h3->fine_coarse = none;
- lonlat->a = gfs_domain_get_or_add_variable (domain, "La", "LonLat cell metric");
- GTS_OBJECT (lonlat->a)->reserved = lonlat;
- lonlat->a->coarse_fine = lonlat_coarse_fine;
- lonlat->a->fine_coarse = lonlat_fine_coarse;
+ g_free (name);
+ g_free (a->description);
+ a->description = g_strdup ("LonLat cell metric");
+ a->coarse_fine = lonlat_coarse_fine;
+ a->fine_coarse = lonlat_fine_coarse;
GtsObject * map = gts_object_new (GTS_OBJECT_CLASS (gfs_map_lonlat_class ()));
gfs_object_simulation_set (map, domain);
@@ -821,25 +843,24 @@ static void metric_lon_lat_class_init (GtsObjectClass * klass)
static void metric_lon_lat_init (GfsMetricLonLat * m)
{
- GFS_EVENT (m)->istep = G_MAXINT/2;
m->r = 1.;
}
-GfsEventClass * gfs_metric_lon_lat_class (void)
+GfsVariableClass * gfs_metric_lon_lat_class (void)
{
- static GfsEventClass * klass = NULL;
+ static GfsVariableClass * klass = NULL;
if (klass == NULL) {
GtsObjectClassInfo gfs_metric_lon_lat_info = {
"GfsMetricLonLat",
sizeof (GfsMetricLonLat),
- sizeof (GfsEventClass),
+ sizeof (GfsVariableClass),
(GtsObjectClassInitFunc) metric_lon_lat_class_init,
(GtsObjectInitFunc) metric_lon_lat_init,
(GtsArgSetFunc) NULL,
(GtsArgGetFunc) NULL
};
- klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_event_class ()),
+ klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_variable_metric_class ()),
&gfs_metric_lon_lat_info);
}
diff --git a/src/metric.h b/src/metric.h
index e839a34..e2d6c36 100644
--- a/src/metric.h
+++ b/src/metric.h
@@ -24,7 +24,14 @@
extern "C" {
#endif /* __cplusplus */
-#include "event.h"
+#include "variable.h"
+
+/* GfsVariableMetric: Header */
+
+#define GFS_IS_VARIABLE_METRIC(obj) (gts_object_is_from_class (obj,\
+ gfs_variable_metric_class ()))
+
+GfsVariableClass * gfs_variable_metric_class (void);
/* GfsMetricCubed: Header */
@@ -32,10 +39,10 @@ typedef struct _GfsMetricCubed GfsMetricCubed;
struct _GfsMetricCubed {
/*< private >*/
- GfsEvent parent;
+ GfsVariable parent;
/*< public >*/
- GfsVariable * h[FTT_NEIGHBORS], * a;
+ GfsVariable * h[FTT_NEIGHBORS];
gint level;
};
@@ -45,7 +52,7 @@ struct _GfsMetricCubed {
#define GFS_IS_METRIC_CUBED(obj) (gts_object_is_from_class (obj,\
gfs_metric_cubed_class ()))
-GfsEventClass * gfs_metric_cubed_class (void);
+GfsVariableClass * gfs_metric_cubed_class (void);
/* GfsMetricLonLat: Header */
@@ -53,10 +60,10 @@ typedef struct _GfsMetricLonLat GfsMetricLonLat;
struct _GfsMetricLonLat {
/*< private >*/
- GfsEvent parent;
+ GfsVariable parent;
/*< public >*/
- GfsVariable * a, * h2, * h3;
+ GfsVariable * h2, * h3;
gdouble r;
};
@@ -66,7 +73,7 @@ struct _GfsMetricLonLat {
#define GFS_IS_METRIC_LON_LAT(obj) (gts_object_is_from_class (obj,\
gfs_metric_lon_lat_class ()))
-GfsEventClass * gfs_metric_lon_lat_class (void);
+GfsVariableClass * gfs_metric_lon_lat_class (void);
#ifdef __cplusplus
}
diff --git a/test/cosine/cosine.gfs b/test/cosine/cosine.gfs
index 4c22221..127de78 100644
--- a/test/cosine/cosine.gfs
+++ b/test/cosine/cosine.gfs
@@ -95,7 +95,7 @@ Define U0 (2.*M_PI)
6 12 GfsAdvection GfsBox GfsGEdge {} {
PhysicalParams { L = 2.*M_PI/4. }
- MetricCubed LEVEL
+ MetricCubed M LEVEL
Time { end = 1 }
Refine LEVEL
VariableTracer T {
diff --git a/test/lonlat/coriolis/coriolis.gfs b/test/lonlat/coriolis/coriolis.gfs
index e334e54..92013a7 100644
--- a/test/lonlat/coriolis/coriolis.gfs
+++ b/test/lonlat/coriolis/coriolis.gfs
@@ -31,7 +31,7 @@ Define LENGTH (150./180.*M_PI)
1 0 GfsRiver GfsBox GfsGEdge {} {
PhysicalParams { L = LENGTH }
- MetricLonLat 1.
+ MetricLonLat M 1.
Refine 8
InitFraction P (0.2 - acos(cos(x*M_PI/180.)*cos(y*M_PI/180.)))
Init {} { P = 0.2 + 1.8*P/LENGTH }
diff --git a/test/lonlat/lonlat.gfs b/test/lonlat/lonlat.gfs
index 06d83ce..ee8a751 100644
--- a/test/lonlat/lonlat.gfs
+++ b/test/lonlat/lonlat.gfs
@@ -51,7 +51,7 @@ Define LENGTH (150./180.*M_PI)
1 0 GfsRiver GfsBox GfsGEdge {} {
PhysicalParams { L = LENGTH }
- MetricLonLat 1.
+ MetricLonLat M 1.
Refine 8
InitFraction P (0.2 - acos(cos(x*M_PI/180.)*cos(y*M_PI/180.)))
Init {} { P = 0.2 + 1.8*P/LENGTH }
@@ -59,6 +59,7 @@ Define LENGTH (150./180.*M_PI)
OutputTime { istep = 10 } stderr
OutputSimulation { step = 0.3 } sim-%g.gfs
OutputSimulation { step = 0.3 } sim-%g.txt { variables = U,V,P format = text }
+ OutputScalarSum { istep = 1 } sp { v = P }
# OutputSimulation { istep = 10 } stdout
EventScript { start = end } {
status=0
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list