diff options
author | tradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2002-11-08 12:43:29 +0000 |
---|---|---|
committer | tradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2002-11-08 12:43:29 +0000 |
commit | 5c055f4347f4eab78b228796a88ed290b53dc501 (patch) | |
tree | b3b65a7b30638969a5ea7889480a42ecb583d929 /src/Evolve.c | |
parent | f88c4ed4c6e900fb6c921c23e0dc667c9883ad9b (diff) |
Support additional termination condition using the new cactus::max_runtime
integer parameter and the extended keyword parameter cactus::terminate
to select this condition.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@399 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/Evolve.c')
-rw-r--r-- | src/Evolve.c | 108 |
1 files changed, 79 insertions, 29 deletions
diff --git a/src/Evolve.c b/src/Evolve.c index 9448b7a..910ce43 100644 --- a/src/Evolve.c +++ b/src/Evolve.c @@ -3,9 +3,9 @@ @date Thu Oct 8 17:28:46 1998 @author Tom Goodale @desc - PUGH evolution stuff. + PUGH evolution stuff. @enddesc - @version $Header$ + @version $Id$ @hdate Tue Mar 28 22:41:15 2000 @hauthor Ed Evans @hdesc Moved into PUGH and added time level rotation @hdate Tue Mar 28 22:41:45 2000 @hauthor Tom Goodale @@ -21,6 +21,13 @@ #include "pugh.h" #include "pughi.h" +#ifdef HAVE_TIME_GETTIMEOFDAY +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#include <unistd.h> +#endif + static const char *rcsid="$Header$"; CCTK_FILEVERSION(CactusPUGH_PUGH_Evolve_c); @@ -149,7 +156,12 @@ int PUGH_Evolve(tFleshConfig *config) @desc Check the termination conditions for the evolution loop @enddesc - @calls + @calls CCTK_TerminationReached + @history + @hdate Thu 6 Nov 2002 + @hauthor Thomas Radke + @hdesc Added max_runtime condition test + @endhistory @var GH @vdesc pointer to CCTK grid hierarchy @@ -157,7 +169,7 @@ int PUGH_Evolve(tFleshConfig *config) @vio in @endvar @var time - @vdesc coordinate time + @vdesc current physical simulation time @vtype CCTK_REAL @vio in @endvar @@ -169,46 +181,84 @@ int PUGH_Evolve(tFleshConfig *config) @returntype int @returndesc - 1 - condition for evolution loop termination is true - 0 - condition for evolution loop termination is false + true (1) or false (0) for done/not done with evolution loop @endreturndesc @@*/ -static int DoneMainLoop (const cGH *GH, CCTK_REAL time, int iteration) +static int DoneMainLoop (const cGH *GH, CCTK_REAL simulation_time,int iteration) { + int max_iteration_reached, max_simulation_time_reached, max_runtime_reached; int retval; +#ifdef HAVE_TIME_GETTIMEOFDAY + struct timeval runtime; + static struct timeval starttime = {0, 0}; +#endif DECLARE_CCTK_PARAMETERS +#ifdef HAVE_TIME_GETTIMEOFDAY + /* on the first time through, get the start time */ + if (starttime.tv_sec == 0 && starttime.tv_usec == 0) + { + gettimeofday (&starttime, NULL); + } +#endif + retval = terminate_next || CCTK_TerminationReached (GH); - if (! retval) + if (! retval && ! CCTK_Equals (terminate, "never")) { - if (CCTK_Equals (terminate, "never")) + max_iteration_reached = iteration >= cctk_itlast; + + if (cctk_initial_time < cctk_final_time) { - retval = 0; + max_simulation_time_reached = simulation_time >= cctk_final_time; } - else if (CCTK_Equals (terminate, "iteration")) + else { - retval = iteration >= cctk_itlast; + max_simulation_time_reached = simulation_time <= cctk_final_time; } - else + + max_runtime_reached = 0; +#ifdef HAVE_TIME_GETTIMEOFDAY + if (max_runtime > 0) { - if (cctk_initial_time < cctk_final_time) - { - retval = time >= cctk_final_time; - } - else - { - retval = time <= cctk_final_time; - } + /* get the elapsed runtime in minutes and compare with max_runtime */ + gettimeofday (&runtime, NULL); + runtime.tv_sec -= starttime.tv_sec; + runtime.tv_sec /= 60; + max_runtime_reached = runtime.tv_sec >= max_runtime; + } +#endif - if (CCTK_Equals (terminate, "either")) - { - retval |= iteration >= cctk_itlast; - } - else if (CCTK_Equals (terminate, "both")) - { - retval &= iteration >= cctk_itlast; - } + if (CCTK_Equals (terminate, "iteration")) + { + retval = max_iteration_reached; + } + else if (CCTK_Equals (terminate, "time")) + { + retval = max_simulation_time_reached; + } + else if (CCTK_Equals (terminate, "runtime")) + { + retval = max_runtime_reached; + } + else if (CCTK_Equals (terminate, "any")) + { + retval = max_iteration_reached || max_simulation_time_reached || + max_runtime_reached; + } + else if (CCTK_Equals (terminate, "all")) + { + retval = max_iteration_reached && max_simulation_time_reached && + max_runtime_reached; + } + /* the following two conditions are deprecated in BETA14 */ + else if (CCTK_Equals (terminate, "either")) + { + retval = max_iteration_reached || max_simulation_time_reached; + } + else /* if (CCTK_Equals (terminate, "both")) */ + { + retval = max_iteration_reached && max_simulation_time_reached; } } |