aboutsummaryrefslogtreecommitdiff
path: root/src/OutputScalar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/OutputScalar.c')
-rw-r--r--src/OutputScalar.c249
1 files changed, 100 insertions, 149 deletions
diff --git a/src/OutputScalar.c b/src/OutputScalar.c
index 1281cff..9169821 100644
--- a/src/OutputScalar.c
+++ b/src/OutputScalar.c
@@ -27,7 +27,6 @@ CCTK_FILEVERSION(CactusBase_IOBasic_OutputScalar_c)
******************** Internal Routines ************************
********************************************************************/
static void CheckSteerableParameters (iobasicGH *myGH);
-static void SetOutputFlag (int vindex, const char *optstring, void *arg);
/*@@
@@ -38,8 +37,7 @@ static void SetOutputFlag (int vindex, const char *optstring, void *arg);
Loops over all variables and outputs them if necessary
@enddesc
@calls IOBasic_TimeForScalarOutput
- IOBasic_WriteScalarGS
- IOBasic_WriteScalarGA
+ IOBasic_WriteScalar
@var GH
@vdesc Pointer to CCTK GH
@@ -55,7 +53,7 @@ static void SetOutputFlag (int vindex, const char *optstring, void *arg);
@@*/
int IOBasic_ScalarOutputGH (const cGH *GH)
{
- int i, vindex, retval;
+ int vindex, retval;
const char *name;
iobasicGH *myGH;
@@ -91,15 +89,7 @@ int IOBasic_ScalarOutputGH (const cGH *GH)
#endif
/* Make the IO call */
- if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
- {
- i = IOBasic_WriteScalarGS (GH, vindex, name);
- }
- else
- {
- i = IOBasic_WriteScalarGA (GH, vindex, name);
- }
- if (i == 0)
+ if (IOBasic_WriteScalar (GH, vindex, name) == 0)
{
/* Register GF as having 0D output this iteration */
myGH->outScalar_last [vindex] = GH->cctk_iteration;
@@ -111,66 +101,6 @@ int IOBasic_ScalarOutputGH (const cGH *GH)
}
-/*@@
- @routine IOBasic_ScalarOutputVarAs
- @date Sat March 6 1999
- @author Gabrielle Allen
- @desc
- Unconditional output of a variable using IOBasic's SCALAR
- output method
- @enddesc
- @calls IOBasic_WriteScalarGS
- IOBasic_WriteScalarGA
-
- @var GH
- @vdesc Pointer to CCTK GH
- @vtype const cGH *
- @vio in
- @endvar
- @var fullname
- @vdesc complete name of variable to output
- @vtype const char *
- @vio in
- @endvar
- @var alias
- @vdesc alias name of variable to output (used to generate output filename)
- @vtype const char *
- @vio in
- @endvar
-
- @returntype int
- @returndesc
- return code of @seeroutine IOBasic_WriteScalarGS or
- @seeroutine IOBasic_WriteScalarGA
- @endreturndesc
-@@*/
-int IOBasic_ScalarOutputVarAs (const cGH *GH, const char *fullname, const char *alias)
-{
- int vindex, retval;
-
-
- vindex = CCTK_VarIndex (fullname);
-
-#ifdef IOBASIC_DEBUG
- printf("\nIn IOBasic_ScalarOutputVarAs\n-------------------\n");
- printf(" Fullname = -%s-\n",fullname);
- printf(" Alias = -%s-\n",alias);
- printf(" Index = %d\n",vindex);
-#endif
-
- if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
- {
- retval = IOBasic_WriteScalarGS (GH, vindex, alias);
- }
- else
- {
- retval = IOBasic_WriteScalarGA (GH, vindex, alias);
- }
-
- return (retval);
-}
-
-
/*@@
@routine IOBasic_TimeForScalarOutput
@date Sat March 6 1999
@@ -198,45 +128,37 @@ int IOBasic_ScalarOutputVarAs (const cGH *GH, const char *fullname, const char *
@@*/
int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex)
{
- int return_type;
- iobasicGH *myGH;
+ int retval;
char *fullname;
+ iobasicGH *myGH;
- /* Default is do not do output */
- return_type = 0;
-
/* Get the GH extension for IOBasic */
myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
CheckSteerableParameters (myGH);
/* check if any output was requested */
- if (myGH->outScalar_every <= 0)
+ if (myGH->outScalar_every <= 0 || GH->cctk_iteration % myGH->outScalar_every
+ || myGH->scalar_reductions[vindex].num_reductions == 0)
{
- return (0);
+ retval = 0;
}
-
- /* Check if this variable should be output */
- if (myGH->do_outScalar [vindex] &&
- (GH->cctk_iteration % myGH->outScalar_every) == 0)
+ else
{
/* Check if variable wasn't already output this iteration */
- if (myGH->outScalar_last [vindex] == GH->cctk_iteration)
+ retval = myGH->outScalar_last [vindex] != GH->cctk_iteration;
+ if (! retval)
{
fullname = CCTK_FullName (vindex);
CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Already done IOBasic scalar output for '%s' in "
- "current iteration (probably via triggers)", fullname);
+ "Already done scalar output for '%s' in current iteration "
+ "(probably via triggers)", fullname);
free (fullname);
}
- else
- {
- return_type = 1;
- }
}
- return (return_type);
+ return (retval);
}
@@ -262,8 +184,7 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex)
@returntype int
@returndesc
- return code of @seeroutine IOBasic_WriteScalarGS or
- @seeroutine IOBasic_WriteScalarGA
+ return code of @seeroutine IOBasic_WriteScalar
@endreturndesc
@@*/
int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex)
@@ -285,14 +206,7 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex)
#endif
/* Do the Scalar output */
- if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
- {
- retval = IOBasic_WriteScalarGS (GH, vindex, name);
- }
- else
- {
- retval = IOBasic_WriteScalarGA (GH, vindex, name);
- }
+ retval = IOBasic_WriteScalar (GH, vindex, name);
if (retval == 0)
{
@@ -304,62 +218,120 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex)
}
-/**************************** local functions ******************************/
-/* check if steerable parameters have changed */
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+ /*@@
+ @routine CheckSteerableParameters
+ @date Tue 31 Jul 2001
+ @author Thomas Radke
+ @desc
+ Re-evaluates 'IOBasic::outScalar_every' and/or 'IO::out_every'
+ resp. to set myGH->outScalar_every to the frequency of scalar
+ output. Re-evaluates 'IOBasic::outScalar_vars' and
+ 'IOBasic::outScalar_reductions'.
+ @enddesc
+ @calls CCTK_ParameterQueryTimesSet
+
+ @var myGH
+ @vdesc Pointer to IOBasic's GH extension
+ @vtype iobasicGH *
+ @vio in
+ @endvar
+@@*/
static void CheckSteerableParameters (iobasicGH *myGH)
{
- int i, num_vars, out_old;
- int times_set;
- char *fullname, *msg, *oldmsg;
- static int outScalar_vars_lastset = -1;
+ int vindex, out_old, times_set, update_reductions_list, num_vars;
+ iobasic_reduction_t *reduction, *next;
+ static int outScalar_vars_lastset = -1;
+ static int outScalar_reductions_lastset = -1;
+ iobasic_parseinfo_t info;
+ char *msg, *oldmsg, *fullname;
DECLARE_CCTK_PARAMETERS
- /* How often to output */
+ /* how often to output */
out_old = myGH->outScalar_every;
myGH->outScalar_every = out_every > 0 ? out_every : -1;
if (outScalar_every > 0)
{
myGH->outScalar_every = outScalar_every;
}
-
- if (myGH->outScalar_every != out_old)
+ if (myGH->outScalar_every != out_old && ! CCTK_Equals (newverbose, "none"))
{
- if (CCTK_Equals (newverbose, "standard") ||
- CCTK_Equals (newverbose, "full"))
+ if (myGH->outScalar_every > 0)
+ {
+ CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Periodic output every %d "
+ "iterations", myGH->outScalar_every);
+ }
+ else
{
- CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Output every %d iterations",
- myGH->outScalar_every);
+ CCTK_INFO ("Scalar: Periodic output turned off");
}
}
- /* re-parse the 'outScalar_vars' parameter if it was changed */
+ /* return if there's nothing to do */
+ if (myGH->outScalar_every <= 0)
+ {
+ return;
+ }
+
+ /* check if the 'outScalar_reductions' parameter if it was changed */
+ times_set = CCTK_ParameterQueryTimesSet ("outScalar_reductions",
+ CCTK_THORNSTRING);
+ update_reductions_list = times_set != outScalar_reductions_lastset;
+ outScalar_reductions_lastset = times_set;
+
+ /* check if the 'outScalar_vars' parameter if it was changed */
times_set = CCTK_ParameterQueryTimesSet ("outScalar_vars", CCTK_THORNSTRING);
- if (times_set != outScalar_vars_lastset)
+ update_reductions_list |= times_set != outScalar_vars_lastset;
+ outScalar_vars_lastset = times_set;
+
+ if (update_reductions_list)
{
+ /* free old reduction lists ... */
num_vars = CCTK_NumVars ();
- memset (myGH->do_outScalar, 0, num_vars);
- CCTK_TraverseString (outScalar_vars, SetOutputFlag, myGH->do_outScalar,
- CCTK_GROUP_OR_VAR);
+ for (vindex = 0; vindex < num_vars; vindex++)
+ {
+ if (myGH->scalar_reductions[vindex].num_reductions > 0)
+ {
+ myGH->scalar_reductions[vindex].num_reductions = 0;
+ reduction = myGH->scalar_reductions[vindex].reductions;
+ while (reduction)
+ {
+ next = reduction->next;
+ free (reduction->name);
+ free (reduction);
+ reduction = next;
+ }
+ }
+ }
- if (myGH->outScalar_every &&
- (CCTK_Equals (newverbose, "standard") ||
- CCTK_Equals (newverbose, "full")))
+ /* ... and create new ones */
+ info.reduction_list = myGH->scalar_reductions;
+ info.reductions_string = outScalar_reductions;
+ if (CCTK_TraverseString (outScalar_vars, IOBasic_AssignReductionList, &info,
+ CCTK_GROUP_OR_VAR) < 0)
+ {
+ CCTK_WARN (1, "Failed to parse 'IOBasic::outScalar_vars' parameter");
+ }
+ else if (! CCTK_Equals (newverbose, "none"))
{
msg = NULL;
- for (i = 0; i < num_vars; i++)
+ for (vindex = 0; vindex < num_vars; vindex++)
{
- if (myGH->do_outScalar[i])
+ if (myGH->scalar_reductions[vindex].num_reductions)
{
- fullname = CCTK_FullName (i);
+ fullname = CCTK_FullName (vindex);
if (! msg)
{
- Util_asprintf (&msg, "Scalar: Output requested for %s", fullname);
+ Util_asprintf (&msg, "Scalar: Periodic output requested for '%s'",
+ fullname);
}
else
{
oldmsg = msg;
- Util_asprintf (&msg, "%s %s", oldmsg, fullname);
+ Util_asprintf (&msg, "%s, '%s'", oldmsg, fullname);
free (oldmsg);
}
free (fullname);
@@ -371,26 +343,5 @@ static void CheckSteerableParameters (iobasicGH *myGH)
free (msg);
}
}
-
- /* Save the last setting of 'outScalar_vars' parameter */
- outScalar_vars_lastset = times_set;
- }
-
-}
-
-
-/* callback for CCTK_TraverseString() to set the output flag
- for the given variable */
-static void SetOutputFlag (int vindex, const char *optstring, void *arg)
-{
- char *flags = (char *) arg;
-
-
- flags[vindex] = 1;
-
- if (optstring)
- {
- CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Optional string '%s' in variable name ignored", optstring);
}
}