diff options
Diffstat (limited to 'src/OutputInfo.c')
-rw-r--r-- | src/OutputInfo.c | 183 |
1 files changed, 141 insertions, 42 deletions
diff --git a/src/OutputInfo.c b/src/OutputInfo.c index 524b426..c704ac2 100644 --- a/src/OutputInfo.c +++ b/src/OutputInfo.c @@ -8,11 +8,14 @@ @version $Id$ @@*/ +#include <assert.h> #include <math.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" @@ -56,6 +59,68 @@ CCTK_FILEVERSION(CactusBase_IOBasic_OutputInfo_c) ********************************************************************/ static void CheckSteerableParameters (iobasicGH *myGH); static void PrintHeader (iobasicGH *myGH, int num_vars); +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(outInfo_criterion, "never")) + { + return 0; + } + else if (CCTK_EQUALS(outInfo_criterion, "iteration")) + { + if (myGH->outInfo_every <= 0 || cctk_iteration % myGH->outInfo_every) + { + return 0; + } + } + else if (CCTK_EQUALS(outInfo_criterion, "time")) + { + if (myGH->outInfo_dt < 0) + { + return 0; + } + if (myGH->outInfo_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_info_output_time - 1.0e-12 * cctk_delta_time; + if (output_this_iteration) + { + *next_info_output_time += myGH->outInfo_dt; + } + } + if (! output_this_iteration) + { + return 0; + } + } + } + else + { + assert (0); + } + + return 1; +} /*@@ @@ -86,7 +151,6 @@ int IOBasic_InfoOutputGH (const cGH *GH) int vindex, num_vars, retval; iobasic_reduction_t *reduction; iobasicGH *myGH; - DECLARE_CCTK_PARAMETERS /* get the GH extensions for IOBasic */ @@ -95,11 +159,9 @@ int IOBasic_InfoOutputGH (const cGH *GH) /* check if steerable parameters changed */ CheckSteerableParameters (myGH); - /* return if no output is required */ - if (myGH->outInfo_every <= 0 || GH->cctk_iteration % myGH->outInfo_every) - { - return (0); - } + if (! TimeForOutput(GH)) return 0; + + retval = 0; /* print header if neccessary */ num_vars = CCTK_NumVars (); @@ -119,7 +181,7 @@ int IOBasic_InfoOutputGH (const cGH *GH) } /* loop over all variables */ - for (vindex = retval = 0; vindex < num_vars; vindex++) + for (vindex = 0; vindex < num_vars; vindex++) { /* check this variable should be output */ if (myGH->info_reductions[vindex].num_reductions == 0) @@ -190,35 +252,35 @@ int IOBasic_InfoOutputGH (const cGH *GH) @@*/ int IOBasic_TimeForInfoOutput (const cGH *GH, int vindex) { - int retval; char *fullname; iobasicGH *myGH; - DECLARE_CCTK_PARAMETERS - /* check if steerable parameters changed */ + /* get the GH extensions for IOBasic */ myGH = CCTK_GHExtension (GH, "IOBasic"); + + /* check if steerable parameters changed */ CheckSteerableParameters (myGH); - /* check if this variable should be output */ - retval = myGH->outInfo_every > 0 && - (GH->cctk_iteration % myGH->outInfo_every == 0) && - myGH->info_reductions[vindex].num_reductions > 0; - if (retval) + if (myGH->info_reductions[vindex].num_reductions == 0) { - /* check if variable was not already output this iteration */ - if (myGH->outInfo_last[vindex] == GH->cctk_iteration) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, - "Already done Info output for '%s' in current iteration " - "(probably via triggers)", fullname); - free (fullname); - retval = 0; - } + return 0; } - return (retval); + if (! TimeForOutput(GH)) return 0; + + /* check if variable was not already output this iteration */ + if (myGH->outInfo_last[vindex] == GH->cctk_iteration) + { + fullname = CCTK_FullName (vindex); + CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, + "Already done Info output for '%s' in current iteration " + "(probably via triggers)", fullname); + free (fullname); + return 0; + } + + return 1; } @@ -251,7 +313,6 @@ int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex) { int retval; iobasicGH *myGH; - DECLARE_CCTK_PARAMETERS /* get the GH extension for IOBasic */ @@ -268,7 +329,7 @@ int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex) if (retval == 0) { - /* gegister variable as having Info output at this iteration */ + /* register variable as having Info output at this iteration */ myGH->outInfo_last[vindex] = GH->cctk_iteration; } @@ -301,6 +362,7 @@ int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex) static void CheckSteerableParameters (iobasicGH *myGH) { int vindex, out_old, times_set, update_reductions_list; + CCTK_REAL outdt_old; iobasic_reduction_t *reduction, *next; static int outInfo_vars_lastset = -1; static int outInfo_reductions_lastset = -1; @@ -308,28 +370,65 @@ static void CheckSteerableParameters (iobasicGH *myGH) DECLARE_CCTK_PARAMETERS - /* how often to output */ - out_old = myGH->outInfo_every; - myGH->outInfo_every = outInfo_every >= 0 ? outInfo_every : out_every; - - /* report if frequency changed */ - if (myGH->outInfo_every != out_old && ! CCTK_Equals (verbose, "none")) + if (CCTK_EQUALS(outInfo_criterion, "never")) + { + return ; + } + else if (CCTK_EQUALS(outInfo_criterion, "iteration")) { - if (myGH->outInfo_every > 0) + /* how often to output */ + out_old = myGH->outInfo_every; + myGH->outInfo_every = outInfo_every >= 0 ? outInfo_every : out_every; + + /* report if frequency changed */ + if (myGH->outInfo_every != out_old && ! CCTK_Equals (verbose, "none")) { - CCTK_VInfo (CCTK_THORNSTRING, "Info: Periodic output every %d iterations", - myGH->outInfo_every); + if (myGH->outInfo_every > 0) + { + CCTK_VInfo (CCTK_THORNSTRING, "Info: Periodic output every %d iterations", + myGH->outInfo_every); + } + else + { + CCTK_INFO ("Info: Periodic output turned off"); + } } - else + + /* return if there's nothing to do */ + if (myGH->outInfo_every <= 0) { - CCTK_INFO ("Info: Periodic output turned off"); + return; } } + else if (CCTK_EQUALS(outInfo_criterion, "time")) + { + /* how often to output */ + outdt_old = myGH->outInfo_dt; + myGH->outInfo_dt = outInfo_dt >= 0 ? outInfo_dt : out_dt; - /* return if there's nothing to do */ - if (myGH->outInfo_every <= 0) + /* report if frequency changed */ + if (myGH->outInfo_dt != outdt_old && ! CCTK_Equals (verbose, "none")) + { + if (myGH->outInfo_dt >= 0) + { + CCTK_VInfo (CCTK_THORNSTRING, "Info: Periodic output dt %g", + (double)myGH->outInfo_dt); + } + else + { + CCTK_INFO ("Info: Periodic output turned off"); + } + } + + /* return if there's nothing to do */ + if (myGH->outInfo_dt < 0) + { + return; + } + } + else { - return; + assert (0); } /* check if the 'outInfo_reductions' parameter if it was changed */ |