aboutsummaryrefslogtreecommitdiff
path: root/src/Evolve.c
blob: 7f9b9c43597c4e6eb43176e78a0b2d6457da34e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
 /*@@
   @file      PUGH_Evolve.c
   @date      Thu Oct  8 17:28:46 1998
   @author    Tom Goodale
   @desc 
   PUGH evolution stuff.
   @enddesc 
   @version $Header$
   @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
   @hdesc Tidied up
 @@*/

#include <stdio.h>

#include "cctk_Flesh.h"
#include "cctk_Parameters.h"
#include "cctk_Groups.h"
#include "CactusIOFunctions.h"

#include "pugh.h"

static char *rcsid="$Header$";

CCTK_FILEVERSION(CactusPUGH_PUGH_Evolve_c)

/* Define some macros for convenience. */

#define ForallConvLevels(iteration, conv_level)  {                     \
                                        int factor = 1;                \
                                        for(conv_level = 0 ;           \
                                            conv_level < config->nGHs; \
                                            conv_level++)              \
                                        {                              \
                                          if(iteration%factor == 0)    \
                                          {
                            
#define EndForallConvLevels                                            \
                                          };                           \
                                          factor *=2;                  \
                                        };                             \
                                     }


/* Local function prototypes. */

static int DoneMainLoop (CCTK_REAL cctk_time, int iteration);
static int StepGH(cGH *GH);
static void RotateTimeLevelsGH(cGH *cgh); 


 /*@@
   @routine    PUGH_Evolve
   @date       Thu Oct  8 17:30:15 1998
   @author     Tom Goodale
   @desc 
   PUGH's evolution routine.
   @enddesc 
   @calls     
   @calledby   
   @history 
   @hdate Tue Mar 28 22:42:47 2000 @hauthor Ed Evans
   @hdesc  Copied from CactusDefaultEvolve and added rotation
   @hdate Tue Mar 28 22:43:18 2000 @hauthor Tom Goodale
   @hdesc Tidied
   @hdate Fri May 12 2000 @hauthor Thomas Radke
   @hdesc  Moved evolution loop termination check into DoneMainLoop() 
   @endhistory 

@@*/
int PUGH_Evolve(tFleshConfig *config)
{
  int convergence_level;
  int iteration=CCTK_MainLoopIndex();

  /*** Call OUTPUT for this GH (this routine    ***/
  /*** checks if output is necessary) and makes ***/
  /*** a Traverse with CCTK_ANALYSIS      ***/
  ForallConvLevels(iteration, convergence_level)
  {
      CCTK_Traverse(config->GH[convergence_level], "CCTK_ANALYSIS");
      CCTK_OutputGH(config->GH[convergence_level]);
  }
  EndForallConvLevels;

  while (! DoneMainLoop (config->GH[0]->cctk_time, iteration))
  {
    iteration = CCTK_SetMainLoopIndex(++iteration);

    /* Step each convergence level */

    ForallConvLevels(iteration, convergence_level)
    {

      StepGH(config->GH[convergence_level]);
      /*
      CCTK_InfoOutput(config->GH[convergence_level], convergence_level);
      */
    }
    EndForallConvLevels;
  
    ForallConvLevels(iteration, convergence_level)
    {

      RotateTimeLevelsGH(config->GH[convergence_level]);
      /*
      CCTK_InfoOutput(config->GH[convergence_level], convergence_level);
      */
    }
    EndForallConvLevels;
 
    /* Dump out checkpoint data on all levels */
    ForallConvLevels(iteration, convergence_level)
    {
      CCTK_Traverse(config->GH[convergence_level], "CCTK_CHECKPOINT");
    }
    EndForallConvLevels;

    /* Output perhaps */

    /*** Call OUTPUT for this GH (this routine    ***/
    /*** checks if output is necessary) and makes ***/
    /*** an Traverse with CCTK_ANALYSIS      ***/
    ForallConvLevels(iteration, convergence_level)
    {
        CCTK_Traverse(config->GH[convergence_level], "CCTK_ANALYSIS");
        CCTK_OutputGH(config->GH[convergence_level]);
    }
    EndForallConvLevels;

#if 0      
    /* Termination has been raised and broadcasted, exit loop*/
    if (cactus_terminate==TERMINATION_RAISED_BRDCAST) break;
#endif

  } /*** END OF MAIN ITERATION LOOP ***/

  return 0;
}

/************************************************************************/

 /*@@
   @routine    DoneMainLoop
   @date       Fri May 12 2000
   @author     Thomas Radke
   @desc 
   Check the termination conditions for the evolution loop
   @enddesc 
   @calls     
   @calledby   
   @history 
   @endhistory 

@@*/
static int DoneMainLoop (CCTK_REAL cctk_time, int iteration)
{
  DECLARE_CCTK_PARAMETERS

  return (! (iteration < cctk_itlast ||
            (cctk_final_time > cctk_initial_time ?
             cctk_time < cctk_final_time : 0)));
}


 /*@@
   @routine    StepGH
   @date       Fri Aug 14 12:39:49 1998
   @author     Gerd Lanfermann
   @desc 
     The full set of routines used to execute all schedule point 
     int the main iteration loop. Makes calls to the individual 
     routines for each schedule point.
   @enddesc 
   @calls  CCTK_Traverse
   @calledby main   
 @@*/

static int StepGH(cGH *GH) 
{
  /* Advance GH->iteration BEFORE evolving */

  GH->cctk_iteration++;

  CCTK_Traverse(GH, "CCTK_PRESTEP");
  CCTK_Traverse(GH, "CCTK_EVOL");


  /* Advance GH->time AFTER evolving */

  GH->cctk_time = GH->cctk_time + GH->cctk_delta_time;

  CCTK_Traverse(GH, "CCTK_POSTSTEP"); 

  return 0;
}


 /*@@
   @routine    RotateTimeLevelsGH
   @date       Tue Mar 28 22:43:49 2000
   @author     Ed Evans
   @desc 
   Rotates the time levels
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static void RotateTimeLevelsGH(cGH *cgh)
{
  int var;
  int numtimelevels;
  int i;
  void *temp;
  pGH *pughGH;

  pughGH = PUGH_pGH(cgh);

  for(var = 0; var < pughGH->nvariables; var++)
  {    
    numtimelevels = CCTK_NumTimeLevelsFromVarI(var);

    if(numtimelevels>1) 
    {
      temp=pughGH->variables[var][0];

      for(i = 0 ; i < numtimelevels -1 ; i++)
      {
	pughGH->variables[var][i]=pughGH->variables[var][i+1];
      }

      pughGH->variables[var][numtimelevels-1]=temp;
    }
  }

  return;
}