aboutsummaryrefslogtreecommitdiff
path: root/src/Counter.c
blob: 0093f1fcccb2a32aee0f9568cedfc632a5cfccdc (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
 /*@@
   @file      Counter.c
   @date      Mon May 20 09:52:33 2002
   @author    Ian Hawke
   @desc 
   Routines setting and altering the loop counter.
   @enddesc 
   @version   $Header$
 @@*/

#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"

/* #include "carpet.h" */

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusBase_MoL_Counter_c);

/********************************************************************
 *********************     Local Data Types   ***********************
 ********************************************************************/

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 ***************** Scheduled Routine Prototypes *********************
 ********************************************************************/

void MoL_SetCounter(CCTK_ARGUMENTS);

void MoL_DecrementCounter(CCTK_ARGUMENTS);

/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    MoL_SetCounter
   @date       Mon May 20 09:54:39 2002
   @author     Ian Hawke
   @desc 
   Initially set the counter to the number of intermediate steps.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/

void MoL_SetCounter(CCTK_ARGUMENTS)
{

  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;

  *MoL_Intermediate_Step = MoL_Intermediate_Steps;

  // Always indicate execution of slow steps.
  // If multirate methods are used, they are set to zero
  // for certain substeps.
  // In any case, outside the MoL loop, these scalars are guaranteed to be 1
  *MoL_SlowStep = 1;
  *MoL_SlowPostStep = 1;
  
/* #ifdef HAVE_CARPET */
  if ((*MoL_Intermediate_Step))
  {
    /* Disable prolongating during the iterations */
/*     CarpetEnableProlongating (0); */
    if (disable_prolongation)
    {
      if (CCTK_IsFunctionAliased("EnableProlongating"))
      {
        EnableProlongating(0);
      }
      else
      {
        CCTK_WARN(4, "Cannot disable prolongation as function"
                  " \"EnableProlongating\" is not provided by any thorn!");
      }
    }
  }
/* #endif */
}

 /*@@
   @routine    MoL_DecrementCounter
   @date       Mon May 20 09:55:13 2002
   @author     Ian Hawke
   @desc 
   During the loop decrement the counter
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/

void MoL_DecrementCounter(CCTK_ARGUMENTS)
{

  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;
  
  (*MoL_Intermediate_Step) --;


  if (CCTK_EQUALS(ODE_Method, "RK2-MR-2:1"))
  {
     switch (MoL_Intermediate_Steps - *MoL_Intermediate_Step)
     {
        case 2:
        case 4:
           if (*MoL_SlowStep)
              *MoL_SlowPostStep = 1;
           else
              *MoL_SlowPostStep = 0;
           // don't do slow step
           *MoL_SlowStep = 0;
           break;
        default:
           if (!(*MoL_SlowStep))
              *MoL_SlowPostStep = 0;
           else
              *MoL_SlowPostStep = 1;
           // do a slow step!
           *MoL_SlowStep = 1;
     }
  }

  if (CCTK_EQUALS(ODE_Method, "RK4-MR-2:1"))
  {
     switch (MoL_Intermediate_Steps - *MoL_Intermediate_Step)
     {
        case 2:
        case 4:
        case 7:
        case 9:
           // don't do slow step
           *MoL_SlowStep = 0;
           break;
        default:
           // do a slow step!
           *MoL_SlowStep = 1;
     }
  }

  if (CCTK_EQUALS(ODE_Method, "RK4-RK2"))
  {
     switch (MoL_Intermediate_Steps - *MoL_Intermediate_Step)
     {
        case 0:
           // do a slow step!
           *MoL_SlowStep = 1;
           // don't sync!
           *MoL_SlowPostStep = 0;
           break;
        case 1:
        case 2:
           // don't do slow step
           *MoL_SlowStep = 0;
           *MoL_SlowPostStep = 0;
           break;
        case 3:
           // do a slow step!
           *MoL_SlowStep = 1;
           // sync!
           *MoL_SlowPostStep = 1;
     }
  }

/* #ifdef HAVE_CARPET */
  if (! (*MoL_Intermediate_Step))
  {
    /* Re-enable prolongating before the final PostStep */
/*     CarpetEnableProlongating (1); */
    if (disable_prolongation)
    {
      if (CCTK_IsFunctionAliased("EnableProlongating"))
      {
        EnableProlongating(1);
      }
      else
      {
        CCTK_WARN(4, "Cannot enable prolongation as function"
                  " \"EnableProlongating\" is not provided by any thorn!");
      }
    }
  }
/* #endif */
}

/********************************************************************
 *********************     Local Routines   *************************
 ********************************************************************/