[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203
Stephane Popinet
s.popinet at niwa.co.nz
Fri May 15 02:51:56 UTC 2009
The following commit has been merged in the upstream branch:
commit 6c95e70dc6e474898e17f673f6f56f2d8cc48c84
Author: Stephane Popinet <s.popinet at niwa.co.nz>
Date: Thu Jun 9 14:44:24 2005 +1000
GfsFunction recognises domain variables directly
darcs-hash:20050609044424-fbd8f-a7e97235616f2578399f9803e87719300bee65c1.gz
diff --git a/src/timestep.c b/src/timestep.c
index 3996053..b977b84 100644
--- a/src/timestep.c
+++ b/src/timestep.c
@@ -834,11 +834,11 @@ static void gfs_surface_bc_read (GtsObject ** o, GtsFile * fp)
if (fp->type == GTS_ERROR)
return;
if (!strcmp (fp->token->str, "Neumann")) {
- bc->type->val = 0.;
+ gfs_function_set_constant_value (bc->type, 0.);
gts_file_next_token (fp);
}
else if (!strcmp (fp->token->str, "Dirichlet")) {
- bc->type->val = 1.;
+ gfs_function_set_constant_value (bc->type, 1.);
gts_file_next_token (fp);
}
else {
@@ -852,11 +852,12 @@ static void gfs_surface_bc_read (GtsObject ** o, GtsFile * fp)
static void gfs_surface_bc_write (GtsObject * o, FILE * fp)
{
GfsSurfaceBc * bc = GFS_SURFACE_BC (o);
+ gdouble val;
if (GTS_OBJECT_CLASS (gfs_surface_bc_class ())->parent_class->write)
(* GTS_OBJECT_CLASS (gfs_surface_bc_class ())->parent_class->write) (o, fp);
- if (!bc->type->f)
- fprintf (fp, " %s", bc->type->val ? "Dirichlet" : "Neumann");
+ if ((val = gfs_function_get_constant_value (bc->type)) < G_MAXDOUBLE)
+ fprintf (fp, " %s", val ? "Dirichlet" : "Neumann");
else
gfs_function_write (bc->type, fp);
gfs_function_write (bc->val, fp);
diff --git a/src/utils.c b/src/utils.c
index 4837f14..1cbfa5b 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -29,6 +29,20 @@
/* GfsFunction: Object */
+struct _GfsFunction {
+ /*< private >*/
+ GtsObject parent;
+ GString * expr;
+ GModule * module;
+ gdouble (* f) (FttCell *, gdouble x, gdouble y, gdouble z, gdouble t);
+ gchar * sname;
+ GtsSurface * s;
+ GfsVariable * v;
+ gdouble val;
+
+ /*< public >*/
+};
+
static GtsSurface * read_surface (gchar * name, GtsFile * fp)
{
FILE * fptr = fopen (name, "r");
@@ -77,12 +91,14 @@ static void function_read (GtsObject ** o, GtsFile * fp)
{
GfsFunction * f = GFS_FUNCTION (*o);
GtsTokenType type;
+ GfsDomain * domain;
if (GTS_OBJECT_CLASS (gfs_function_class ())->parent_class->read)
(* GTS_OBJECT_CLASS (gfs_function_class ())->parent_class->read) (o, fp);
if (fp->type == GTS_ERROR)
return;
+ domain = GFS_DOMAIN (gfs_object_simulation (*o));
type = fp->type;
switch (type) {
/* constant value */
@@ -90,7 +106,6 @@ static void function_read (GtsObject ** o, GtsFile * fp)
f->val = atof (fp->token->str);
break;
- /* load GTS file */
case GTS_STRING:
if (strlen (fp->token->str) > 3 &&
!strcmp (&(fp->token->str[strlen (fp->token->str) - 4]), ".gts")) {
@@ -99,6 +114,8 @@ static void function_read (GtsObject ** o, GtsFile * fp)
f->sname = g_strdup (fp->token->str);
break;
}
+ else if ((f->v = gfs_variable_from_name (domain->variables, fp->token->str)))
+ break;
/* fall through */
/* compile C expression */
@@ -140,14 +157,14 @@ static void function_read (GtsObject ** o, GtsFile * fp)
"double f (FttCell * cell, double x, double y, double z, double t) {\n"
" double ",
fin);
- v = GFS_DOMAIN (gfs_object_simulation (*o))->variables;
+ v = domain->variables;
fprintf (fin, "%s", v->name);
while ((v = v->next)) {
if (v->name)
fprintf (fin, ", %s", v->name);
}
fputs (";\n if (cell) {\n", fin);
- v = GFS_DOMAIN (gfs_object_simulation (*o))->variables;
+ v = domain->variables;
while (v) {
if (v->name)
fprintf (fin, " %s = GFS_VARIABLE (cell, %d);\n", v->name, v->i);
@@ -272,6 +289,8 @@ static void function_write (GtsObject * o, FILE * fp)
fprintf (fp, " %s", f->expr->str);
else if (f->module)
fprintf (fp, " %s", g_module_name (f->module));
+ else if (f->v)
+ fprintf (fp, " %s", f->v->name);
else if (f->s)
fprintf (fp, " %s", f->sname);
else
@@ -368,6 +387,8 @@ gdouble gfs_function_value (GfsFunction * f, FttCell * cell, FttVector * p, gdou
else
return (* f->f) (cell, 0., 0., 0., t);
}
+ else if (f->v)
+ return GFS_VARIABLE (cell, f->v->i);
else
return f->val;
}
@@ -401,6 +422,40 @@ gdouble gfs_function_face_value (GfsFunction * f, FttCellFace * fa,
ftt_face_pos (fa, &p);
return (* f->f) (fa->cell, p.x, p.y, p.z, t);
}
+ else if (f->v)
+ return gfs_face_interpolated_value (fa, f->v->i);
+ else
+ return f->val;
+}
+
+/**
+ * gfs_function_set_constant_value:
+ * @f: a #GfsFunction.
+ * @val: the value.
+ *
+ * Sets the value of the constant function @f to @val.
+ */
+void gfs_function_set_constant_value (GfsFunction * f, gdouble val)
+{
+ g_return_if_fail (f != NULL);
+ g_return_if_fail (!f->f && !f->s && !f->v);
+
+ f->val = val;
+}
+
+/**
+ * gfs_function_get_constant_value:
+ * @f: a #GfsFunction.
+ *
+ * Returns: the value of function @f if @f is constant, G_MAXDOUBLE
+ * otherwise.
+ */
+gdouble gfs_function_get_constant_value (GfsFunction * f)
+{
+ g_return_val_if_fail (f != NULL, G_MAXDOUBLE);
+
+ if (f->f || f->s || f->v)
+ return G_MAXDOUBLE;
else
return f->val;
}
diff --git a/src/utils.h b/src/utils.h
index 1d0e023..81af0a2 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -33,19 +33,6 @@ extern "C" {
typedef struct _GfsFunction GfsFunction;
-struct _GfsFunction {
- /*< private >*/
- GtsObject parent;
- GModule * module;
- GString * expr;
- gdouble (* f) (FttCell *, gdouble x, gdouble y, gdouble z, gdouble t);
- gchar * sname;
- GtsSurface * s;
- gdouble val;
-
- /*< public >*/
-};
-
typedef struct _GfsFunctionClass GfsFunctionClass;
struct _GfsFunctionClass {
@@ -71,6 +58,9 @@ gdouble gfs_function_value (GfsFunction * f,
FttCell * cell,
FttVector * p,
gdouble t);
+void gfs_function_set_constant_value (GfsFunction * f,
+ gdouble val);
+gdouble gfs_function_get_constant_value (GfsFunction * f);
void gfs_function_read (GfsFunction * f,
gpointer domain,
GtsFile * fp);
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list