aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--param.ccl40
-rw-r--r--src/Server.c234
2 files changed, 272 insertions, 2 deletions
diff --git a/param.ccl b/param.ccl
index 444cdd3..7b0266d 100644
--- a/param.ccl
+++ b/param.ccl
@@ -68,3 +68,43 @@ BOOLEAN terminate "Kill the simulation ?" STEERABLE = ALWAYS
{
} "no"
+###################################################################
+# Dynamic control
+
+
+BOOLEAN single_step "Do one step then pause ?" STEERABLE = ALWAYS
+{
+} "no"
+
+# Interate until
+
+BOOLEAN until_it_active "Use until_it parameter ?" STEERABLE = ALWAYS
+{
+} "no"
+
+INT until_it "Pause at this iteration" STEERABLE = ALWAYS
+{
+ : :: "Any iteration"
+} -1
+
+# Run until
+
+BOOLEAN until_time_active "Use until_time parameter ?" STEERABLE = ALWAYS
+{
+} "no"
+
+REAL until_time "Pause after this simulation time" STEERABLE = ALWAYS
+{
+ : :: "Any time"
+} -1
+
+# Run until expression
+
+BOOLEAN until_expression_active "Use until_expression parameter ?" STEERABLE = ALWAYS
+{
+} "no"
+
+STRING until_expression "Pause if this expression evaluates to true." STEERABLE = ALWAYS
+{
+ ".*" :: "Any expression"
+} ""
diff --git a/src/Server.c b/src/Server.c
index d3d865d..6c1da0b 100644
--- a/src/Server.c
+++ b/src/Server.c
@@ -12,10 +12,19 @@
#include <stdlib.h>
#include "cctk.h"
+
+#include "cctk_Constants.h"
+#include "cctk_Groups.h"
+#include "cctk_GroupsOnGH.h"
+#include "cctk_Parameter.h"
+
#include "util_Hash.h"
+#include "util_String.h"
#include "httpd.h"
+#include "http_Expression.h"
+
static char *rcsid = "$Header$";
CCTK_FILEVERSION(DevThorns_httpd_Server_c)
@@ -37,6 +46,13 @@ typedef struct
static httpPage *CreatePageData(int (*function)(cGH *,httpRequest *, void *), void *data);
static httpPage *FindPage(char *path, char **residual);
+static int StatusUntilIt(cGH *cctkGH);
+static int StatusUntilTime(cGH *cctkGH);
+static int StatusUntilExpression(cGH *cctkGH);
+
+static double evaluator(const char *name, void *data);
+
+
/********************************************************************
********************* Other Routine Prototypes *********************
********************************************************************/
@@ -207,13 +223,49 @@ int HTTP_UpdateState(cGH *cctkGH, httpState *state)
{
int type;
CCTK_INT *value;
+ int pause_selected;
+ int until_it_selected;
+ int until_time_selected;
+ int until_expression_selected;
+ int stepping;
static int steering = 1;
static int last_steered = -1;
+ value = (CCTK_INT *)CCTK_ParameterGet("single_step",CCTK_THORNSTRING, &type);
+
+ stepping = *value;
+
value = (CCTK_INT *)CCTK_ParameterGet("pause",CCTK_THORNSTRING, &type);
- state->paused = *value;
+ pause_selected = *value;
+
+ value = (CCTK_INT *)CCTK_ParameterGet("until_it_active",CCTK_THORNSTRING, &type);
+
+ until_it_selected = *value;
+
+ value = (CCTK_INT *)CCTK_ParameterGet("until_time_active",CCTK_THORNSTRING, &type);
+
+ until_time_selected = *value;
+
+ value = (CCTK_INT *)CCTK_ParameterGet("until_expression_active",CCTK_THORNSTRING, &type);
+
+ until_expression_selected = *value;
+
+ state->paused = (! stepping) &&
+ (pause_selected || (cctkGH &&
+ ((until_it_selected && StatusUntilIt(cctkGH)) ||
+ (until_time_selected && StatusUntilTime(cctkGH)) ||
+ (until_expression_selected && StatusUntilExpression(cctkGH)))));
+
+ /* If single step is selected, need to reset the parameter to force a pause
+ * next time.
+ */
+ if(stepping)
+ {
+ HTTP_SteerQueue(CCTK_THORNSTRING, "single_step", "no");
+ }
+
if(cctkGH && ! state->paused)
{
@@ -246,7 +298,6 @@ int HTTP_UpdateState(cGH *cctkGH, httpState *state)
}
-
value = (CCTK_INT *)CCTK_ParameterGet("terminate",CCTK_THORNSTRING, &type);
state->terminate = *value;
@@ -411,3 +462,182 @@ static httpPage *FindPage(char *path, char **residual)
return pagedata;
}
+
+ /*@@
+ @routine StatusUntilIt
+ @date Tue Sep 19 22:59:34 2000
+ @author Tom Goodale
+ @desc
+ Is the iteration greater than the desired stop value ?
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+static int StatusUntilIt(cGH *cctkGH)
+{
+ int retval;
+ CCTK_INT *value;
+ int type;
+
+ value = (CCTK_INT *)CCTK_ParameterGet("until_it",CCTK_THORNSTRING, &type);
+
+ if(cctkGH && *value <= cctkGH->cctk_iteration)
+ {
+ retval = 1;
+ }
+ else
+ {
+ retval = 0;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine StatusUntilTime
+ @date Tue Sep 19 23:00:16 2000
+ @author Tom Goodale
+ @desc
+ Is the simulation time greater than the stop value ?
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+static int StatusUntilTime(cGH *cctkGH)
+{
+ int retval;
+ CCTK_REAL *value;
+ int type;
+
+ value = (CCTK_REAL *)CCTK_ParameterGet("until_time",CCTK_THORNSTRING, &type);
+
+ if(cctkGH && *value <= cctkGH->cctk_time)
+ {
+ retval = 1;
+ }
+ else
+ {
+ retval = 0;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine StatusUntilExpression
+ @date Tue Sep 19 23:00:47 2000
+ @author Tom Goodale
+ @desc
+ Is the stop expression true ?
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+static int StatusUntilExpression(cGH *cctkGH)
+{
+ static char *parsed_expression = NULL;
+ static int times_set = -1;
+
+ int new_times_set;
+ int retval;
+
+ const char *value;
+ int type;
+ char *copy;
+
+ /* See if we need to parse the expression again. */
+ new_times_set = CCTK_ParameterQueryTimesSet("until_expression",
+ CCTK_THORNSTRING);
+
+ if(new_times_set > times_set)
+ {
+ times_set = new_times_set;
+ value = (const char *)CCTK_ParameterGet("until_expression",CCTK_THORNSTRING, &type);
+
+ if(parsed_expression)
+ {
+ free(parsed_expression);
+
+ parsed_expression = HTTP_ExpressionParse(value);
+ }
+ }
+
+ /* Make a copy */
+ copy = Util_Strdup(parsed_expression);
+
+ if(cctkGH)
+ {
+ /* Evaluate the expression */
+ retval = HTTP_ExpressionEvaluate(copy, evaluator, (void *)cctkGH);
+ }
+ else
+ {
+ retval = 0;
+ }
+ /* Free the copy */
+ free(copy);
+
+ return retval;
+}
+
+
+ /*@@
+ @routine evaluator
+ @date Tue Sep 19 23:07:20 2000
+ @author Tom Goodale
+ @desc
+ Takes the name of a gridscalar and returns its value.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+static double evaluator(const char *expression, void *data)
+{
+ double retval;
+ cGH *cctkGH;
+ void *pointer;
+ int varindex;
+ int vartype;
+
+ cctkGH = (cGH *)data;
+
+
+ varindex = CCTK_VarIndex(expression);
+ vartype = CCTK_VarTypeI(varindex);
+
+ pointer = CCTK_VarDataPtrI(cctkGH, 0, varindex);
+
+ switch(vartype)
+ {
+ case CCTK_VARIABLE_CHAR :
+ retval = *((CCTK_CHAR *)pointer);
+ break;
+ case CCTK_VARIABLE_INT :
+ retval = *((CCTK_INT *)pointer);
+ break;
+ case CCTK_VARIABLE_REAL :
+ retval = *((CCTK_REAL *)pointer);
+ break;
+ default :
+ fprintf(stderr, "Unsupported variable type %d\n", vartype);
+ retval = 0;
+ }
+
+ return retval;
+}