[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203
Stephane Popinet
s.popinet at niwa.co.nz
Fri May 15 02:51:38 UTC 2009
The following commit has been merged in the upstream branch:
commit ae253316c14e314c90aa9e4786c9a6a803559932
Author: Stephane Popinet <s.popinet at niwa.co.nz>
Date: Fri Feb 11 13:26:48 2005 +1100
GfsFunction can now use model variables
This can be used for example to define source terms dependent on other
variables.
darcs-hash:20050211022648-fbd8f-d14bf2412e5fb44fc815927294a957e6c054fe4a.gz
diff --git a/src/adaptive.c b/src/adaptive.c
index 6e80b0f..423ddee 100644
--- a/src/adaptive.c
+++ b/src/adaptive.c
@@ -724,7 +724,7 @@ static guint minlevel (FttCell * cell, GfsSimulation * sim)
GfsAdapt * a = i->data;
guint l;
- if (a->active && (l = gfs_function_value (a->minlevel, &p, sim->time.t)) > minlevel)
+ if (a->active && (l = gfs_function_value (a->minlevel, NULL, &p, sim->time.t)) > minlevel)
minlevel = l;
i = i->next;
}
@@ -742,7 +742,7 @@ static guint maxlevel (FttCell * cell, GfsSimulation * sim)
GfsAdapt * a = i->data;
guint l;
- if (a->active && (l = gfs_function_value (a->maxlevel, &p, sim->time.t)) < maxlevel)
+ if (a->active && (l = gfs_function_value (a->maxlevel, NULL, &p, sim->time.t)) < maxlevel)
maxlevel = l;
i = i->next;
}
diff --git a/src/event.c b/src/event.c
index ea1da94..813c04a 100644
--- a/src/event.c
+++ b/src/event.c
@@ -537,7 +537,7 @@ static void init_vf (FttCell * cell, gpointer * data)
ftt_cell_pos (cell, &p);
else
gfs_cell_cm (cell, &p);
- GFS_VARIABLE (cell, v->i) = gfs_function_value (f, &p, sim->time.t);
+ GFS_VARIABLE (cell, v->i) = gfs_function_value (f, NULL, &p, sim->time.t);
}
static void init_f (GfsVariable * v, GfsFunction * f, GfsDomain * domain)
diff --git a/src/output.c b/src/output.c
index ef32fcd..4762422 100644
--- a/src/output.c
+++ b/src/output.c
@@ -1912,7 +1912,7 @@ static void compute_error (FttCell * cell, GfsOutputScalar * o)
else
gfs_cell_cm (cell, &p);
GFS_VARIABLE (cell, GFS_OUTPUT_ERROR_NORM (o)->v->i) = GFS_VARIABLE (cell, o->v->i) -
- gfs_function_value (GFS_OUTPUT_ERROR_NORM (o)->s, &p, sim->time.t);
+ gfs_function_value (GFS_OUTPUT_ERROR_NORM (o)->s, NULL, &p, sim->time.t);
}
static void remove_bias (FttCell * cell, gpointer * data)
@@ -2011,7 +2011,7 @@ static void compute_correlation (FttCell * cell, gpointer * data)
ftt_cell_pos (cell, &p);
else
gfs_cell_cm (cell, &p);
- ref = gfs_function_value (GFS_OUTPUT_ERROR_NORM (o)->s, &p, sim->time.t);
+ ref = gfs_function_value (GFS_OUTPUT_ERROR_NORM (o)->s, NULL, &p, sim->time.t);
v = GFS_VARIABLE (cell, o->v->i) - *bias;
w = ftt_cell_volume (cell)*(GFS_IS_MIXED (cell) ? GFS_STATE (cell)->solid->a : 1.);
*sumref += ref*ref*w;
diff --git a/src/refine.c b/src/refine.c
index d15d884..8f63fbf 100644
--- a/src/refine.c
+++ b/src/refine.c
@@ -29,7 +29,7 @@ static gboolean refine_maxlevel (FttCell * cell, GfsFunction * maxlevel)
FttVector p;
ftt_cell_pos (cell, &p);
- return (ftt_cell_level (cell) < gfs_function_value (maxlevel, &p, 0.));
+ return (ftt_cell_level (cell) < gfs_function_value (maxlevel, cell, &p, 0.));
}
static void refine_box (GfsBox * box, GfsFunction * maxlevel)
@@ -146,7 +146,7 @@ static void refine_cut_cell (FttCell * cell, GtsSurface * s, gpointer * data)
FttVector p;
ftt_cell_pos (cell, &p);
- if (ftt_cell_level (cell) < gfs_function_value (refine->maxlevel, &p, 0.))
+ if (ftt_cell_level (cell) < gfs_function_value (refine->maxlevel, cell, &p, 0.))
ftt_cell_refine_single (cell, (FttCellInitFunc) gfs_cell_fine_init, domain);
}
@@ -342,7 +342,7 @@ static gboolean refine_distance_maxlevel (FttCell * cell, GfsRefine * refine)
p.x = pos.x; p.y = pos.y; p.z = pos.z;
d = gts_bb_tree_point_distance (GFS_REFINE_DISTANCE (refine)->stree, &p,
(GtsBBoxDistFunc) gts_point_triangle_distance, NULL);
- return (ftt_cell_level (cell) < gfs_function_value (refine->maxlevel, &pos, d));
+ return (ftt_cell_level (cell) < gfs_function_value (refine->maxlevel, cell, &pos, d));
}
static void refine_distance (GfsBox * box, gpointer data)
@@ -409,7 +409,7 @@ static gboolean height_maxlevel (GtsPoint * p, guint level, GfsRefine * refine,
*guess = f;
gts_triangle_interpolate_height (GTS_TRIANGLE (f), p);
pos.x = p->x; pos.y = p->y; pos.z = p->z;
- return (level < gfs_function_value (refine->maxlevel, &pos, p->z));
+ return (level < gfs_function_value (refine->maxlevel, NULL, &pos, p->z));
}
return FALSE;
}
diff --git a/src/source.c b/src/source.c
index 2f1a42e..595f673 100644
--- a/src/source.c
+++ b/src/source.c
@@ -297,7 +297,7 @@ static gdouble source_value (GfsSourceGeneric * s,
ftt_cell_pos (cell, &p);
else
gfs_cell_cm (cell, &p);
- return gfs_function_value (GFS_SOURCE (s)->intensity, &p,
+ return gfs_function_value (GFS_SOURCE (s)->intensity, cell, &p,
gfs_object_simulation (s)->time.t);
}
@@ -901,7 +901,8 @@ static gdouble gfs_source_coriolis_mac_value (GfsSourceGeneric * s,
gdouble f;
gfs_cell_cm (cell, &p);
- f = gfs_function_value (GFS_SOURCE_CORIOLIS (s)->omegaz, &p, gfs_object_simulation (s)->time.t);
+ f = gfs_function_value (GFS_SOURCE_CORIOLIS (s)->omegaz, NULL, &p,
+ gfs_object_simulation (s)->time.t);
switch (GFS_VELOCITY_COMPONENT (v->i)) {
case FTT_X: return f*GFS_STATE (cell)->v;
case FTT_Y: return - f*GFS_STATE (cell)->u;
@@ -917,7 +918,7 @@ static void save_coriolis (FttCell * cell, GfsSourceCoriolis * s)
gdouble f;
gfs_cell_cm (cell, &p);
- f = gfs_function_value (s->omegaz, &p, gfs_object_simulation (s)->time.t)/2.;
+ f = gfs_function_value (s->omegaz, NULL, &p, gfs_object_simulation (s)->time.t)/2.;
for (c = 0; c < 2; c++)
GFS_VARIABLE (cell, s->u[c]->i) = c == FTT_X ? f*GFS_STATE (cell)->v : -f*GFS_STATE (cell)->u;
}
@@ -981,7 +982,7 @@ static void implicit_coriolis (FttCell * cell, GfsSourceCoriolis * s)
GfsSimulation * sim = gfs_object_simulation (s);
gfs_cell_cm (cell, &p);
- c = sim->advection_params.dt*gfs_function_value (s->omegaz, &p, sim->time.t)/2.;
+ c = sim->advection_params.dt*gfs_function_value (s->omegaz, NULL, &p, sim->time.t)/2.;
u = GFS_STATE (cell)->u;
v = GFS_STATE (cell)->v;
GFS_STATE (cell)->u = (u + c*v)/(1. + c*c);
diff --git a/src/timestep.c b/src/timestep.c
index e785ed6..10930d9 100644
--- a/src/timestep.c
+++ b/src/timestep.c
@@ -868,9 +868,9 @@ static void gfs_surface_bc_bc (FttCell * cell, GfsSurfaceGenericBc * b)
{
GfsSurfaceBc * bc = GFS_SURFACE_BC (b);
gdouble t = gfs_object_simulation (bc)->time.t;
- gdouble val = gfs_function_value (bc->val, &GFS_STATE (cell)->solid->ca, t);
+ gdouble val = gfs_function_value (bc->val, cell, &GFS_STATE (cell)->solid->ca, t);
- if (gfs_function_value (bc->type, &GFS_STATE (cell)->solid->ca, t) > 0.) {
+ if (gfs_function_value (bc->type, cell, &GFS_STATE (cell)->solid->ca, t) > 0.) {
cell->flags |= GFS_FLAG_DIRICHLET;
GFS_STATE (cell)->solid->fv = val;
}
diff --git a/src/utils.c b/src/utils.c
index 06e27ed..429fcb8 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -22,6 +22,8 @@
#include <unistd.h>
#include <math.h>
#include "utils.h"
+#include "solid.h"
+#include "simulation.h"
/* GfsFunction: Object */
@@ -51,8 +53,7 @@ static void function_read (GtsObject ** o, GtsFile * fp)
GfsFunction * f = GFS_FUNCTION (*o);
if (GTS_OBJECT_CLASS (gfs_function_class ())->parent_class->read)
- (* GTS_OBJECT_CLASS (gfs_function_class ())->parent_class->read)
- (o, fp);
+ (* GTS_OBJECT_CLASS (gfs_function_class ())->parent_class->read) (o, fp);
if (fp->type == GTS_ERROR)
return;
@@ -79,8 +80,14 @@ static void function_read (GtsObject ** o, GtsFile * fp)
return;
}
else {
- gchar cccommand[] = "gcc -fPIC -shared -x c";
- gchar finname[] = "/tmp/gfsXXXXXX";
+#if FTT_2D
+ gchar cccommand[] = "gcc `pkg-config gerris2D --cflags --libs` -O -fPIC -shared -x c";
+#elif FTT_2D3
+ gchar cccommand[] = "gcc `pkg-config gerris2D3 --cflags --libs` -O -fPIC -shared -x c";
+#else /* 3D */
+ gchar cccommand[] = "gcc `pkg-config gerris3D --cflags --libs` -O -fPIC -shared -x c";
+#endif
+ gchar finname[] = "/tmp/gfsXXXXXX";
gchar foutname[] = "/tmp/gfsXXXXXX";
gchar ferrname[] = "/tmp/gfsXXXXXX";
gchar ftmpname[] = "/tmp/gfsXXXXXX";
@@ -89,6 +96,7 @@ static void function_read (GtsObject ** o, GtsFile * fp)
guint scope;
gchar * cc;
gint status, c;
+ GfsVariable * v;
find = mkstemp (finname);
if (find < 0) {
@@ -96,15 +104,29 @@ static void function_read (GtsObject ** o, GtsFile * fp)
return;
}
fin = fdopen (find, "w");
- fprintf (fin,
- "#include <stdlib.h>\n"
- "#include <stdio.h>\n"
- "#include <math.h>\n"
- "static double Dirichlet = 1.;\n"
- "static double Neumann = 0.;\n"
- "double f (double x, double y, double z, double t) {\n"
- "#line %d \"GfsFunction\"\n",
- fp->line);
+ fputs ("#include <stdlib.h>\n"
+ "#include <stdio.h>\n"
+ "#include <math.h>\n"
+ "#include <gfs.h>\n"
+ "static double Dirichlet = 1.;\n"
+ "static double Neumann = 0.;\n"
+ "double f (FttCell * cell, double x, double y, double z, double t) {\n"
+ " double ",
+ fin);
+ v = GFS_DOMAIN (gfs_object_simulation (*o))->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;
+ while (v) {
+ if (v->name)
+ fprintf (fin, " %s = GFS_VARIABLE (cell, %d);\n", v->name, v->i);
+ v = v->next;
+ }
+ fprintf (fin, " }\n#line %d \"GfsFunction\"\n", fp->line);
f->expr = g_string_new ("{");
scope = fp->scope_max;
c = gts_file_getc (fp);
@@ -256,18 +278,19 @@ GfsFunction * gfs_function_new (GfsFunctionClass * klass,
/**
* gfs_function_value:
* @f: a #GfsFunction.
+ * @cell: a #FttCell or %NULL.
* @p: a #FttVector.
* @t: the time.
*
- * Returns: the value of function @f at location @p.
+ * Returns: the value of function @f at location @p of @cell.
*/
-gdouble gfs_function_value (GfsFunction * f, FttVector * p, gdouble t)
+gdouble gfs_function_value (GfsFunction * f, FttCell * cell, FttVector * p, gdouble t)
{
g_return_val_if_fail (f != NULL, 0.);
if (f->f) {
g_return_val_if_fail (p != NULL, 0.);
- return (* f->f) (p->x, p->y, p->z, t);
+ return (* f->f) (cell, p->x, p->y, p->z, t);
}
else
return f->val;
@@ -292,7 +315,7 @@ gdouble gfs_function_face_value (GfsFunction * f, FttCellFace * fa,
g_return_val_if_fail (fa != NULL, 0.);
ftt_face_pos (fa, &p);
- return (* f->f) (p.x, p.y, p.z, t);
+ return (* f->f) (NULL, p.x, p.y, p.z, t);
}
else
return f->val;
@@ -307,10 +330,12 @@ gdouble gfs_function_face_value (GfsFunction * f, FttCellFace * fa,
*/
void gfs_function_read (GfsFunction * f, GtsFile * fp)
{
+ GtsObject * o = (GtsObject *) f;
+
g_return_if_fail (f != NULL);
g_return_if_fail (fp != NULL);
- (* GTS_OBJECT (f)->klass->read) ((GtsObject **) &f, fp);
+ (* GTS_OBJECT (f)->klass->read) (&o, fp);
}
/**
diff --git a/src/utils.h b/src/utils.h
index eea8470..8dcbdd8 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -38,7 +38,7 @@ struct _GfsFunction {
GtsObject parent;
GModule * module;
GString * expr;
- gdouble (* f) (gdouble x, gdouble y, gdouble z, gdouble t);
+ gdouble (* f) (FttCell *, gdouble x, gdouble y, gdouble z, gdouble t);
gdouble val;
/*< public >*/
@@ -62,10 +62,11 @@ struct _GfsFunctionClass {
GfsFunctionClass * gfs_function_class (void);
GfsFunction * gfs_function_new (GfsFunctionClass * klass,
gdouble val);
-gdouble gfs_function_face_value (GfsFunction * f,
+gdouble gfs_function_face_value (GfsFunction * f,
FttCellFace * fa,
gdouble t);
-gdouble gfs_function_value (GfsFunction * f,
+gdouble gfs_function_value (GfsFunction * f,
+ FttCell * cell,
FttVector * p,
gdouble t);
void gfs_function_read (GfsFunction * f,
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list