[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203
Stephane Popinet
popinet at users.sf.net
Fri May 15 02:54:56 UTC 2009
The following commit has been merged in the upstream branch:
commit 0cdfa4484ff1a4fe197dd2a9e84f995d9f11ebb4
Author: Stephane Popinet <popinet at users.sf.net>
Date: Mon Jan 14 15:13:25 2008 +1100
Fix for missing variable descriptions
darcs-hash:20080114041325-d4795-411e06ac00ec38ff4f2c560f252e5ebdbd66c741.gz
diff --git a/src/adaptive.c b/src/adaptive.c
index 094a405..fb189a0 100644
--- a/src/adaptive.c
+++ b/src/adaptive.c
@@ -190,13 +190,11 @@ static void gfs_adapt_read (GtsObject ** o, GtsFile * fp)
return;
}
domain = GFS_DOMAIN (gfs_object_simulation (*o));
- a->c = gfs_variable_from_name (domain->variables, fp->token->str);
- if (!a->c && !(a->c = gfs_domain_add_variable (domain, fp->token->str,
- "Adaptive refinement cost"))) {
+ a->c = gfs_domain_get_or_add_variable (domain, fp->token->str, "Adaptive refinement cost");
+ if (!a->c) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
- g_assert (a->c);
a->c->fine_coarse = none;
gts_file_next_token (fp);
}
diff --git a/src/domain.c b/src/domain.c
index 2f5e396..91a71db 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -2666,6 +2666,39 @@ GfsVariable * gfs_domain_add_variable (GfsDomain * domain,
return v;
}
+/**
+ * gfs_domain_get_or_add_variable:
+ * @domain: a #GfsDomain.
+ * @name: the name of the variable to add or get.
+ * @description: the variable description or %NULL.
+ *
+ * Adds a new variable @name to @domain or returns the variable of
+ * @domain with the same name. In either case the description of the
+ * variable name is set to @description.
+ *
+ * Returns: the new or already existing variable or %NULL if @name is a
+ * reserved variable name.
+ */
+GfsVariable * gfs_domain_get_or_add_variable (GfsDomain * domain,
+ const gchar * name,
+ const gchar * description)
+{
+ GfsVariable * v;
+
+ g_return_val_if_fail (domain != NULL, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ v = gfs_variable_from_name (domain->variables, name);
+ if (v != NULL) {
+ if (v->description)
+ g_free (v->description);
+ v->description = description ? g_strdup (description) : NULL;
+ }
+ else
+ v = gfs_domain_add_variable (domain, name, description);
+ return v;
+}
+
static void add_pressure_force (FttCell * cell, gpointer * data)
{
gdouble * f = data[0];
diff --git a/src/domain.h b/src/domain.h
index 07e7dbe..b84a7fd 100644
--- a/src/domain.h
+++ b/src/domain.h
@@ -240,6 +240,9 @@ void gfs_domain_free (GfsDomain * domain,
GfsVariable * gfs_domain_add_variable (GfsDomain * domain,
const gchar * name,
const gchar * description);
+GfsVariable * gfs_domain_get_or_add_variable (GfsDomain * domain,
+ const gchar * name,
+ const gchar * description);
void gfs_domain_solid_force (GfsDomain * domain,
FttVector * pf,
FttVector * vf,
diff --git a/src/event.c b/src/event.c
index f66a039..8b011a0 100644
--- a/src/event.c
+++ b/src/event.c
@@ -516,10 +516,10 @@ static void gfs_init_read (GtsObject ** o, GtsFile * fp)
else {
GfsInit * init = GFS_INIT (*o);
GfsDomain * domain = GFS_DOMAIN (gfs_object_simulation (*o));
- GfsVariable * v = gfs_variable_from_name (domain->variables, fp->token->str);
+ GfsVariable * v = gfs_domain_get_or_add_variable (domain, fp->token->str, NULL);
GfsFunction * f;
- if (!v && !(v = gfs_domain_add_variable (domain, fp->token->str, NULL))) {
+ if (!v) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
@@ -889,8 +889,7 @@ static void gfs_event_sum_read (GtsObject ** o, GtsFile * fp)
gts_file_error (fp, "expecting a string (sv)");
return;
}
- if (!(s->sv = gfs_variable_from_name (domain->variables, fp->token->str)) &&
- !(s->sv = gfs_domain_add_variable (domain, fp->token->str, "Sum"))) {
+ if (!(s->sv = gfs_domain_get_or_add_variable (domain, fp->token->str, "Sum"))) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
@@ -1117,8 +1116,8 @@ static void gfs_event_harmonic_read (GtsObject ** o, GtsFile * fp)
gts_file_error (fp, "expecting a string (Z)");
return;
}
- if (!(s->z = gfs_variable_from_name (domain->variables, fp->token->str)) &&
- !(s->z = gfs_domain_add_variable (domain, fp->token->str, "Offset of harmonic decomposition"))) {
+ if (!(s->z = gfs_domain_get_or_add_variable (domain, fp->token->str,
+ "Offset of harmonic decomposition"))) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
@@ -1129,9 +1128,8 @@ static void gfs_event_harmonic_read (GtsObject ** o, GtsFile * fp)
gts_file_error (fp, "expecting a string (E)");
return;
}
- if (!(s->e = gfs_variable_from_name (domain->variables, fp->token->str)) &&
- !(s->e = gfs_domain_add_variable (domain, fp->token->str,
- "Remainder of harmonic decomposition"))) {
+ if (!(s->e = gfs_domain_get_or_add_variable (domain, fp->token->str,
+ "Remainder of harmonic decomposition"))) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
@@ -1163,16 +1161,14 @@ static void gfs_event_harmonic_read (GtsObject ** o, GtsFile * fp)
gchar * u;
u = g_strdup_printf ("%s%d", s->Aname, i);
- if (!(s->A[i] = gfs_variable_from_name (domain->variables, u)) &&
- !(s->A[i] = gfs_domain_add_variable (domain, u,
- "In-phase component of the harmonic decomposition"))) {
+ if (!(s->A[i] = gfs_domain_get_or_add_variable (domain, u,
+ "In-phase component of the harmonic decomposition"))) {
gts_file_error (fp, "`%s' is a reserved keyword", u);
return;
}
g_free (u);
u = g_strdup_printf ("%s%d", s->Bname, i);
- if (!(s->B[i] = gfs_variable_from_name (domain->variables, u)) &&
- !(s->B[i] = gfs_domain_add_variable (domain, u,
+ if (!(s->B[i] = gfs_domain_get_or_add_variable (domain, u,
"Out-of-phase component of the harmonic decomposition"))) {
gts_file_error (fp, "`%s' is a reserved keyword", u);
return;
@@ -1431,9 +1427,8 @@ static void gfs_event_stop_read (GtsObject ** o, GtsFile * fp)
*/
if (fp->type == GTS_STRING) {
- if (!(s->diff = gfs_variable_from_name (domain->variables, fp->token->str)) &&
- !(s->diff = gfs_domain_add_variable (domain, fp->token->str,
- "Stopping field difference"))) {
+ if (!(s->diff = gfs_domain_get_or_add_variable (domain, fp->token->str,
+ "Stopping field difference"))) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
diff --git a/src/ocean.c b/src/ocean.c
index d04e4cd..7717024 100644
--- a/src/ocean.c
+++ b/src/ocean.c
@@ -865,8 +865,7 @@ static void gfs_source_hydrostatic_read (GtsObject ** o, GtsFile * fp)
gts_file_error (fp, "expecting a string (ph)");
return;
}
- if (!(sh->ph = gfs_variable_from_name (domain->variables, fp->token->str)) &&
- !(sh->ph = gfs_domain_add_variable (domain, fp->token->str, "Hydrostatic pressure"))) {
+ if (!(sh->ph = gfs_domain_get_or_add_variable (domain, fp->token->str, "Hydrostatic pressure"))) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
diff --git a/src/output.c b/src/output.c
index c5cf188..7927c0b 100644
--- a/src/output.c
+++ b/src/output.c
@@ -2249,10 +2249,13 @@ static void gfs_output_droplet_stats_read (GtsObject ** o, GtsFile * fp)
}
gts_file_next_token (fp);
- if (fp->type == GTS_STRING &&
- ((d->tag = gfs_variable_from_name (domain->variables, fp->token->str)) ||
- (d->tag = gfs_domain_add_variable (domain, fp->token->str, "Droplet index"))))
+ if (fp->type == GTS_STRING) {
+ if (!(d->tag = gfs_domain_get_or_add_variable (domain, fp->token->str, "Droplet index"))) {
+ gts_file_error (fp, "`%s' is a reserved variable name", fp->token->str);
+ return;
+ }
gts_file_next_token (fp);
+ }
}
static void gfs_output_droplet_stats_write (GtsObject * o, FILE * fp)
@@ -2418,8 +2421,7 @@ static void output_error_norm_read (GtsObject ** o, GtsFile * fp)
gts_file_error (fp, "expecting a variable name");
return;
}
- if (!(n->v = gfs_variable_from_name (domain->variables, fp->token->str)) &&
- !(n->v = gfs_domain_add_variable (domain, fp->token->str, "Error field"))) {
+ if (!(n->v = gfs_domain_get_or_add_variable (domain, fp->token->str, "Error field"))) {
gts_file_error (fp, "`%s' is a reserved keyword", fp->token->str);
return;
}
diff --git a/src/tension.c b/src/tension.c
index 1b03773..697f7fc 100644
--- a/src/tension.c
+++ b/src/tension.c
@@ -388,12 +388,16 @@ static void variable_curvature_read (GtsObject ** o, GtsFile * fp)
v->f->name, NULL);
gts_file_next_token (fp);
if (fp->type == GTS_STRING) {
- if ((v->kmax = gfs_variable_from_name (domain->variables, fp->token->str)) ||
- (v->kmax = gfs_domain_add_variable (domain, fp->token->str, "Maximum curvature"))) {
+ v->kmax = gfs_domain_get_or_add_variable (domain, fp->token->str, "Maximum curvature");
+ if (v->kmax) {
v->kmax->coarse_fine = curvature_coarse_fine;
v->kmax->fine_coarse = curvature_fine_coarse;
gts_file_next_token (fp);
}
+ else if (!GFS_IS_VARIABLE_POSITION (v)) {
+ gts_file_error (fp, "`%s' is a reserved variable name", fp->token->str);
+ return;
+ }
}
}
else if (GFS_IS_VARIABLE_DISTANCE (v->f)) {
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list