diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/OutputInfo.c | 183 | ||||
-rw-r--r-- | src/OutputScalar.c | 188 | ||||
-rw-r--r-- | src/Startup.c | 25 | ||||
-rw-r--r-- | src/WriteScalar.c | 6 | ||||
-rw-r--r-- | src/iobasicGH.h | 5 |
5 files changed, 309 insertions, 98 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 */ 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 */ diff --git a/src/Startup.c b/src/Startup.c index d862003..7101634 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -8,11 +8,14 @@ @version $Id$ @@*/ +#include <assert.h> +#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include "cctk.h" +#include "cctk_Arguments.h" #include "cctk_Parameters.h" #include "util_Table.h" #include "CactusBase/IOUtil/src/ioutil_Utils.h" @@ -27,6 +30,7 @@ CCTK_FILEVERSION(CactusBase_IOBasic_Startup_c) ******************** External Routines ************************ ********************************************************************/ void IOBasic_Startup (void); +void IOBasic_Init (CCTK_ARGUMENTS); /******************************************************************** @@ -60,6 +64,22 @@ void IOBasic_Startup (void) } + /*@@ + @routine IOBasic_Init + @date Tue 30 Dec 2003 + @author Erik Schnetter + @desc + Initialise the next_*_output_time variables. + @enddesc +@@*/ +void IOBasic_Init (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + *next_info_output_time = cctk_time; + *next_scalar_output_time = cctk_time; +} + + /****************************************************************************/ /* local routines */ /****************************************************************************/ @@ -103,6 +123,7 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) int i; iobasicGH *myGH; const char *my_out_dir; + char dirname[1000]; DECLARE_CCTK_PARAMETERS @@ -148,9 +169,9 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) to the current parameter values this forces info output about periodic output */ myGH->outInfo_every = outInfo_every >= 0 ? outInfo_every : out_every; - myGH->outInfo_every--; myGH->outScalar_every = outScalar_every >= 0 ? outScalar_every : out_every; - myGH->outScalar_every--; + myGH->outInfo_dt = outInfo_dt >= 0 ? outInfo_dt : out_dt; + myGH->outScalar_dt = outScalar_dt >= 0 ? outScalar_dt : out_dt; memset (myGH->outInfo_last, -1, 2 * i * sizeof (int)); diff --git a/src/WriteScalar.c b/src/WriteScalar.c index 235f8bb..02e64b8 100644 --- a/src/WriteScalar.c +++ b/src/WriteScalar.c @@ -40,7 +40,7 @@ static FILE *OpenScalarFile (const cGH *GH, @author Thomas Radke @desc Write a scalar value of a CCTK variable into an ASCII file - suitable for postprocessing by either gluplot or xgraph. + suitable for postprocessing by either gnuplot or xgraph. This routine just calls the appropriate output routine according to the variable type. @enddesc @@ -110,7 +110,7 @@ int IOBasic_WriteScalar (const cGH *GH, int vindex, const char *alias) @desc Apply the given reduction operators on the CCTK_ARRAY or CCTK_GF variable and output the result into a text file - suitable for postprocessing by either gluplot or xgraph. + suitable for postprocessing by either gnuplot or xgraph. @enddesc @calls CCTK_Reduce @@ -246,7 +246,7 @@ static int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) @author Thomas Radke @desc Output the value of a CCTK_SCALAR variable into an ASCII file - suitable for postprocessing by either gluplot or xgraph. + suitable for postprocessing by either gnuplot or xgraph. @enddesc @calls CCTK_MyProc diff --git a/src/iobasicGH.h b/src/iobasicGH.h index a77cb0c..5c3cb99 100644 --- a/src/iobasicGH.h +++ b/src/iobasicGH.h @@ -38,8 +38,9 @@ typedef struct IOBASIC_PARSEINFO typedef struct IOBASIC_GH { /* how often to output */ - int outScalar_every, outInfo_every; - char info_reductions_changed; + int outScalar_every, outInfo_every; + CCTK_REAL outScalar_dt, outInfo_dt; + char info_reductions_changed; /* directory in which to place scalar output */ char *out_dir; |