[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203
Stephane Popinet
popinet at users.sf.net
Fri May 15 02:54:45 UTC 2009
The following commit has been merged in the upstream branch:
commit 99cdea920ee1871460e47e1a7df596f731d17e95
Author: Stephane Popinet <popinet at users.sf.net>
Date: Fri Sep 28 12:59:13 2007 +1000
New "w" option for GfsOutputErrorNorm
darcs-hash:20070928025913-d4795-915ecda5aa4797a600c98051fb6df9ad3c370ee4.gz
diff --git a/src/domain.c b/src/domain.c
index ae550d1..3aef59e 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -1475,6 +1475,15 @@ static void add_norm (const FttCell * cell, gpointer * data)
gfs_norm_add (n, GFS_VARIABLE (cell, v->i), gfs_cell_volume (cell));
}
+static void add_norm_weighted (FttCell * cell, gpointer * data)
+{
+ GfsNorm * n = data[0];
+ GfsVariable * v = data[1];
+ GfsFunction * w = data[2];
+
+ gfs_norm_add (n, GFS_VARIABLE (cell, v->i), gfs_cell_volume (cell)*gfs_function_value (w, cell));
+}
+
#ifdef HAVE_MPI
static void norm_reduce (void * i, void * o,
int * len,
@@ -1514,23 +1523,26 @@ static void domain_norm_reduce (GfsDomain * domain, GfsNorm * n)
* gfs_domain_norm_variable:
* @domain: the domain to obtain norm from.
* @v: a #GfsVariable.
+ * @w: a #GfsFunction or %NULL.
* @flags: which types of cells are to be visited.
* @max_depth: maximum depth of the traversal.
*
* Traverses the domain defined by @domain using gfs_domain_cell_traverse()
* and gathers norm statistics about variable @v.
*
- * The norm is weighted by the volume of each cell.
+ * The norm is weighted by the volume of each cell times the value of
+ * function @w (if @w is not %NULL).
*
* Returns: a #GfsNorm containing the norm statistics about @v.
*/
GfsNorm gfs_domain_norm_variable (GfsDomain * domain,
GfsVariable * v,
+ GfsFunction * w,
FttTraverseFlags flags,
gint max_depth)
{
GfsNorm n;
- gpointer data[2];
+ gpointer data[3];
g_return_val_if_fail (domain != NULL, n);
g_return_val_if_fail (v != NULL, n);
@@ -1538,8 +1550,13 @@ GfsNorm gfs_domain_norm_variable (GfsDomain * domain,
gfs_norm_init (&n);
data[0] = &n;
data[1] = v;
- gfs_domain_cell_traverse (domain, FTT_PRE_ORDER, flags, max_depth,
- (FttCellTraverseFunc) add_norm, data);
+ data[2] = w;
+ if (w)
+ gfs_domain_cell_traverse (domain, FTT_PRE_ORDER, flags, max_depth,
+ (FttCellTraverseFunc) add_norm_weighted, data);
+ else
+ gfs_domain_cell_traverse (domain, FTT_PRE_ORDER, flags, max_depth,
+ (FttCellTraverseFunc) add_norm, data);
#ifdef HAVE_MPI
domain_norm_reduce (domain, &n);
#endif /* HAVE_MPI */
diff --git a/src/domain.h b/src/domain.h
index 0055ee3..166bd5c 100644
--- a/src/domain.h
+++ b/src/domain.h
@@ -174,6 +174,7 @@ void gfs_domain_stats_balance (GfsDomain * domain,
GtsRange * mpiwait);
GfsNorm gfs_domain_norm_variable (GfsDomain * domain,
GfsVariable * v,
+ GfsFunction * w,
FttTraverseFlags flags,
gint max_depth);
GfsNorm gfs_domain_norm_residual (GfsDomain * domain,
diff --git a/src/event.c b/src/event.c
index ff967fb..1078829 100644
--- a/src/event.c
+++ b/src/event.c
@@ -1436,7 +1436,7 @@ static gboolean gfs_event_stop_event (GfsEvent * event, GfsSimulation * sim)
gfs_domain_cell_traverse (domain,
FTT_PRE_ORDER, FTT_TRAVERSE_LEAFS, -1,
(FttCellTraverseFunc) diff, s);
- n = gfs_domain_norm_variable (domain, s->oldv, FTT_TRAVERSE_LEAFS, -1);
+ n = gfs_domain_norm_variable (domain, s->oldv, NULL, FTT_TRAVERSE_LEAFS, -1);
if (n.infty <= s->max)
sim->time.end = sim->time.t;
if (s->diff) {
diff --git a/src/graphic.c b/src/graphic.c
index 9b9df95..4522dec 100644
--- a/src/graphic.c
+++ b/src/graphic.c
@@ -267,7 +267,7 @@ void gfs_write_gts (GfsDomain * domain,
vertex_cell_face_class ());
gts_surface_add_face (s, gts_face_new (gts_face_class (), e1, e2, e3));
- norm = gfs_domain_norm_variable (domain, v, flags, level);
+ norm = gfs_domain_norm_variable (domain, v, NULL, flags, level);
if (norm.infty == 0.)
norm.infty = 1.;
#if FTT_2D
diff --git a/src/output.c b/src/output.c
index 6ab3127..a28829f 100644
--- a/src/output.c
+++ b/src/output.c
@@ -1740,7 +1740,7 @@ static gboolean gfs_output_scalar_norm_event (GfsEvent * event,
(event, sim)) {
GfsOutputScalar * output = GFS_OUTPUT_SCALAR (event);
GfsNorm norm = gfs_domain_norm_variable (GFS_DOMAIN (sim),
- output->v,
+ output->v, NULL,
FTT_TRAVERSE_LEAFS|FTT_TRAVERSE_LEVEL,
output->maxlevel);
@@ -2226,6 +2226,7 @@ GfsOutputClass * gfs_output_scalar_histogram_class (void)
static void output_error_norm_destroy (GtsObject * o)
{
gts_object_destroy (GTS_OBJECT (GFS_OUTPUT_ERROR_NORM (o)->s));
+ gts_object_destroy (GTS_OBJECT (GFS_OUTPUT_ERROR_NORM (o)->w));
(* GTS_OBJECT_CLASS (gfs_output_error_norm_class ())->parent_class->destroy) (o);
}
@@ -2280,6 +2281,17 @@ static void output_error_norm_read (GtsObject ** o, GtsFile * fp)
if (fp->type == GTS_ERROR)
return;
}
+ else if (!strcmp (fp->token->str, "w")) {
+ gts_file_next_token (fp);
+ if (fp->type != '=') {
+ gts_file_error (fp, "expecting `='");
+ return;
+ }
+ gts_file_next_token (fp);
+ gfs_function_read (n->w, gfs_object_simulation (*o), fp);
+ if (fp->type == GTS_ERROR)
+ return;
+ }
else if (!strcmp (fp->token->str, "v")) {
GfsDomain * domain = GFS_DOMAIN (gfs_object_simulation (*o));
@@ -2322,6 +2334,8 @@ static void output_error_norm_write (GtsObject * o, FILE * fp)
(o, fp);
fputs (" { s = ", fp);
gfs_function_write (n->s, fp);
+ fputs (" w = ", fp);
+ gfs_function_write (n->w, fp);
fprintf (fp, " unbiased = %d", n->unbiased);
if (n->v)
fprintf (fp, " v = %s }", n->v->name);
@@ -2358,7 +2372,7 @@ static gboolean gfs_output_error_norm_event (GfsEvent * event,
FTT_TRAVERSE_LEAFS|FTT_TRAVERSE_LEVEL,
output->maxlevel,
(FttCellTraverseFunc) compute_error, output);
- norm = gfs_domain_norm_variable (GFS_DOMAIN (sim), enorm->v,
+ norm = gfs_domain_norm_variable (GFS_DOMAIN (sim), enorm->v, enorm->w,
FTT_TRAVERSE_LEAFS|FTT_TRAVERSE_LEVEL,
output->maxlevel);
if (GFS_OUTPUT_ERROR_NORM (event)->unbiased) {
@@ -2370,7 +2384,7 @@ static gboolean gfs_output_error_norm_event (GfsEvent * event,
FTT_TRAVERSE_LEAFS|FTT_TRAVERSE_LEVEL,
output->maxlevel,
(FttCellTraverseFunc) remove_bias, data);
- norm = gfs_domain_norm_variable (GFS_DOMAIN (sim), enorm->v,
+ norm = gfs_domain_norm_variable (GFS_DOMAIN (sim), enorm->v, enorm->w,
FTT_TRAVERSE_LEAFS|FTT_TRAVERSE_LEVEL,
output->maxlevel);
}
@@ -2398,6 +2412,7 @@ static void gfs_output_error_norm_class_init (GfsOutputClass * klass)
static void output_error_norm_init (GfsOutputErrorNorm * e)
{
e->s = gfs_function_new (gfs_function_class (), 0.);
+ e->w = gfs_function_new (gfs_function_class (), 1.);
}
GfsOutputClass * gfs_output_error_norm_class (void)
@@ -2459,7 +2474,7 @@ static gboolean gfs_output_correlation_event (GfsEvent * event,
FTT_TRAVERSE_LEAFS|FTT_TRAVERSE_LEVEL,
output->maxlevel,
(FttCellTraverseFunc) compute_error, output);
- bias = gfs_domain_norm_variable (GFS_DOMAIN (sim), enorm->v,
+ bias = gfs_domain_norm_variable (GFS_DOMAIN (sim), enorm->v, NULL,
FTT_TRAVERSE_LEAFS|FTT_TRAVERSE_LEVEL,
output->maxlevel).bias;
}
diff --git a/src/output.h b/src/output.h
index 18b014f..a90c7cc 100644
--- a/src/output.h
+++ b/src/output.h
@@ -264,6 +264,7 @@ struct _GfsOutputErrorNorm {
/*< public >*/
GfsFunction * s;
gboolean unbiased;
+ GfsFunction * w;
};
#define GFS_OUTPUT_ERROR_NORM(obj) GTS_OBJECT_CAST (obj,\
diff --git a/src/timestep.c b/src/timestep.c
index 694e961..c75efe4 100644
--- a/src/timestep.c
+++ b/src/timestep.c
@@ -550,12 +550,12 @@ void gfs_diffusion (GfsDomain * domain,
maxlevel = gfs_domain_depth (domain);
gfs_diffusion_residual (domain, v, rhs, dia, res);
par->residual_before = par->residual =
- gfs_domain_norm_variable (domain, res, FTT_TRAVERSE_LEAFS, -1);
+ gfs_domain_norm_variable (domain, res, NULL, FTT_TRAVERSE_LEAFS, -1);
par->niter = 0;
while (par->niter < par->nitermin ||
(par->residual.infty > par->tolerance && par->niter < par->nitermax)) {
gfs_diffusion_cycle (domain, minlevel, maxlevel, par->nrelax, v, rhs, dia, res);
- par->residual = gfs_domain_norm_variable (domain, res, FTT_TRAVERSE_LEAFS, -1);
+ par->residual = gfs_domain_norm_variable (domain, res, NULL, FTT_TRAVERSE_LEAFS, -1);
par->niter++;
}
diff --git a/tools/gfscompare.c b/tools/gfscompare.c
index b6f2d29..cb55e73 100644
--- a/tools/gfscompare.c
+++ b/tools/gfscompare.c
@@ -564,7 +564,7 @@ int main (int argc, char * argv[])
GtsRange s;
norm = gfs_domain_norm_variable (GFS_DOMAIN (s1),
- var1, FTT_TRAVERSE_LEAFS, -1);
+ var1, NULL, FTT_TRAVERSE_LEAFS, -1);
s = gfs_domain_stats_variable (GFS_DOMAIN (s1),
var1, FTT_TRAVERSE_LEAFS, -1);
fprintf (stderr,
@@ -575,7 +575,7 @@ int main (int argc, char * argv[])
norm.first, norm.second, norm.infty, norm.w,
s.min, s.mean, s.stddev, s.max);
norm = gfs_domain_norm_variable (GFS_DOMAIN (s2),
- var2, FTT_TRAVERSE_LEAFS, -1);
+ var2, NULL, FTT_TRAVERSE_LEAFS, -1);
s = gfs_domain_stats_variable (GFS_DOMAIN (s2),
var2, FTT_TRAVERSE_LEAFS, -1);
fprintf (stderr,
@@ -689,7 +689,7 @@ int main (int argc, char * argv[])
norm.first, norm.second, norm.infty, norm.w);
if (refined_error) {
norm = gfs_domain_norm_variable (GFS_DOMAIN (s1),
- e, FTT_TRAVERSE_LEVEL,
+ e, NULL, FTT_TRAVERSE_LEVEL,
gfs_domain_depth (GFS_DOMAIN (s1)));
fprintf (stderr,
"refined err first: %10.3e second: %10.3e infty: %10.3e w: %g\n",
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list