diff options
Diffstat (limited to 'src/OutputScalar.c')
-rw-r--r-- | src/OutputScalar.c | 188 |
1 files changed, 139 insertions, 49 deletions
diff --git a/src/OutputScalar.c b/src/OutputScalar.c index 4ac6c5f..e83a065 100644 --- a/src/OutputScalar.c +++ b/src/OutputScalar.c @@ -9,11 +9,13 @@ /* #define IOBASIC_DEBUG 1 */ +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "cctk.h" +#include "cctk_Arguments.h" #include "cctk_Parameters.h" #include "util_String.h" #include "iobasicGH.h" @@ -26,14 +28,75 @@ CCTK_FILEVERSION(CactusBase_IOBasic_OutputScalar_c) /******************************************************************** ******************** Static Variables ************************ ********************************************************************/ -/* flag whether CheckSteerableParameters() needs to be called */ -static int check_steerable_parameters = 1; /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ static void CheckSteerableParameters (iobasicGH *myGH); +static int TimeForOutput (const cGH *cctkGH); + + +static int TimeForOutput (const cGH *cctkGH) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + iobasicGH *myGH; + + + /* get the GH extensions for IOBasic */ + myGH = CCTK_GHExtension (cctkGH, "IOBasic"); + + /* check if steerable parameters changed */ + CheckSteerableParameters (myGH); + + /* how to decide when to output? */ + /* (return if no output is required) */ + if (CCTK_EQUALS(outScalar_criterion, "never")) + { + return 0; + } + else if (CCTK_EQUALS(outScalar_criterion, "iteration")) + { + if (myGH->outScalar_every <= 0 || cctk_iteration % myGH->outScalar_every) + { + return 0; + } + } + else if (CCTK_EQUALS(outScalar_criterion, "time")) + { + if (myGH->outScalar_dt < 0) + { + return 0; + } + if (myGH->outScalar_dt > 0) + { + static int output_iteration = -1; + static int output_this_iteration; + assert (cctk_iteration >= output_iteration); + if (cctk_iteration > output_iteration) + { + output_iteration = cctk_iteration; + output_this_iteration + = cctk_time >= *next_scalar_output_time - 1.0e-12 * cctk_delta_time; + if (output_this_iteration) + { + *next_scalar_output_time += myGH->outScalar_dt; + } + } + if (! output_this_iteration) + { + return 0; + } + } + } + else + { + assert (0); + } + + return 1; +} /******************************************************************** @@ -67,21 +130,16 @@ int IOBasic_ScalarOutputGH (const cGH *GH) iobasicGH *myGH; - /* check if any steerable parameters have changed */ + /* get the GH extensions for IOBasic */ myGH = CCTK_GHExtension (GH, "IOBasic"); + + /* check if steerable parameters changed */ CheckSteerableParameters (myGH); - /* return if no output is required */ - if (myGH->outScalar_every <= 0) - { - return (0); - } + if (! TimeForOutput(GH)) return 0; retval = 0; - /* disable the check for steerable parameters during the following loop */ - check_steerable_parameters = 0; - /* loop over all variables */ for (vindex = CCTK_NumVars () - 1; vindex >= 0; vindex--) { @@ -94,9 +152,6 @@ int IOBasic_ScalarOutputGH (const cGH *GH) } } - /* enable the check for steerable parameters for following calls */ - check_steerable_parameters = 1; - return (retval); } @@ -227,41 +282,38 @@ int IOBasic_OutputVarAs (const cGH *GH, const char *fullname, const char *alias) @@*/ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex) { - int retval; char *fullname; iobasicGH *myGH; - /* Get the GH extension for IOBasic */ + /* get the GH extensions for IOBasic */ myGH = CCTK_GHExtension (GH, "IOBasic"); - /* only need to check steerable parameters if this flag is set */ - if (check_steerable_parameters) + /* check if steerable parameters changed */ + CheckSteerableParameters (myGH); + + if (myGH->scalar_reductions[vindex].num_reductions == 0) { - CheckSteerableParameters (myGH); + return 0; } - /* check if any output was requested */ - if (myGH->outScalar_every <= 0 || GH->cctk_iteration % myGH->outScalar_every - || myGH->scalar_reductions[vindex].num_reductions == 0) + if (! TimeForOutput(GH)) { - retval = 0; + return 0; } - else + + /* Check if variable wasn't already output this iteration */ + if (myGH->outScalar_last[vindex] == GH->cctk_iteration) { - /* Check if variable wasn't already output this iteration */ - retval = myGH->outScalar_last[vindex] != GH->cctk_iteration; - if (! retval) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, - "Already done scalar output for '%s' in current iteration " - "(probably via triggers)", fullname); - free (fullname); - } + fullname = CCTK_FullName (vindex); + CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, + "Already done scalar output for '%s' in current iteration " + "(probably via triggers)", fullname); + free (fullname); + return 0; } - return (retval); + return 1; } @@ -344,6 +396,7 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex) static void CheckSteerableParameters (iobasicGH *myGH) { int vindex, out_old, times_set, update_reductions_list, num_vars; + CCTK_REAL outdt_old; iobasic_reduction_t *reduction, *next; static int outScalar_vars_lastset = -1; static int outScalar_reductions_lastset = -1; @@ -352,28 +405,65 @@ static void CheckSteerableParameters (iobasicGH *myGH) DECLARE_CCTK_PARAMETERS - /* how often to output */ - out_old = myGH->outScalar_every; - myGH->outScalar_every = outScalar_every >= 0 ? outScalar_every : out_every; - - /* report if frequency changed */ - if (myGH->outScalar_every != out_old && ! CCTK_Equals (verbose, "none")) + if (CCTK_EQUALS(outScalar_criterion, "never")) { - if (myGH->outScalar_every > 0) + return ; + } + else if (CCTK_EQUALS(outScalar_criterion, "iteration")) + { + /* how often to output */ + out_old = myGH->outScalar_every; + myGH->outScalar_every = outScalar_every >= 0 ? outScalar_every : out_every; + + /* report if frequency changed */ + if (myGH->outScalar_every != out_old && ! CCTK_Equals (verbose, "none")) { - CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Periodic output every %d " - "iterations", myGH->outScalar_every); + if (myGH->outScalar_every > 0) + { + CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Periodic output every %d iterations", + myGH->outScalar_every); + } + else + { + CCTK_INFO ("Scalar: Periodic output turned off"); + } } - else + + /* return if there's nothing to do */ + if (myGH->outScalar_every <= 0) { - CCTK_INFO ("Scalar: Periodic output turned off"); + return; } } + else if (CCTK_EQUALS(outScalar_criterion, "time")) + { + /* how often to output */ + outdt_old = myGH->outScalar_dt; + myGH->outScalar_dt = outScalar_dt >= 0 ? outScalar_dt : out_dt; + + /* report if frequency changed */ + if (myGH->outScalar_dt != outdt_old && ! CCTK_Equals (verbose, "none")) + { + if (myGH->outScalar_dt >= 0) + { + CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Periodic output dt %g", + (double)myGH->outScalar_dt); + } + else + { + CCTK_INFO ("Scalar: Periodic output turned off"); + } + } - /* return if there's nothing to do */ - if (myGH->outScalar_every <= 0) + /* return if there's nothing to do */ + if (myGH->outScalar_dt < 0) + { + return; + } + } + else { - return; + assert (0); } /* check if the 'outScalar_reductions' parameter if it was changed */ |