aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/Cycle.cc
blob: acf4d19db19a7aadcecb1807b9e1708073ae1f3c (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
#include <cassert>
#include <cstdlib>

#include <cctk.h>
#include <cctk_Parameters.h>

#include <ggf.hh>
#include <gh.hh>

#include <carpet.hh>



namespace Carpet {
  
  using namespace std;
  
  
  
  void CycleTimeLevels (const cGH* cgh)
  {
    DECLARE_CCTK_PARAMETERS;
    
    Checkpoint ("CycleTimeLevels");
    assert (is_level_mode());
    
    for (int group=0; group<CCTK_NumGroups(); ++group) {
      if (CCTK_QueryGroupStorageI(cgh, group)) {
        
        int const activetimelevels = CCTK_ActiveTimeLevelsGI (cgh, group);
        if (activetimelevels > 1) {
          if (activetimelevels < prolongation_order_time+1) {
            char * const groupname = CCTK_GroupName (group);
            CCTK_VWarn (CCTK_WARN_ABORT, __LINE__, __FILE__, CCTK_THORNSTRING,
                        "Group \"%s\" has %d only active time levels.  Groups with more than one active time level need at least %d active time levels for prolongation_order_time=%d",
                        groupname,
                        activetimelevels, int(prolongation_order_time+1),
                        int(prolongation_order_time));
            free (groupname);
          }
        }
        
        switch (CCTK_GroupTypeI(group)) {
          
        case CCTK_GF:
          assert (reflevel>=0 and reflevel<reflevels);
	  for (int m=0; m<(int)arrdata.AT(group).size(); ++m) {
	    for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
              arrdata.AT(group).AT(m).data.AT(var)->
                cycle_all (reflevel, mglevel);
            }
          }
          break;
          
        case CCTK_SCALAR:
        case CCTK_ARRAY:
          if (do_global_mode) {
	    int const numtimelevels = CCTK_NumTimeLevelsI (group);
	    int const firstvarindex = CCTK_FirstVarIndexI (group);
            for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
              arrdata.AT(group).AT(0).data.AT(var)->cycle_all (0, mglevel);
	      {
                int const varindex = firstvarindex + var;
		for (int tl=0; tl<numtimelevels; ++tl) {
		  cgh->data[varindex][tl]
		    = (tl < groupdata.AT(group).info.activetimelevels
		       ? ((*arrdata.AT(group).AT(0).data.AT(var))
			  (tl, 0, 0, 0)->storage())
		       : NULL);
		}
	      }
            }
          }
          break;
          
        default:
          assert (0);
        } // switch grouptype
      } // if storage
    } // for group
  }
  
  
  
  void FlipTimeLevels (const cGH* cgh)
  {
    DECLARE_CCTK_PARAMETERS;
    
    Checkpoint ("FlipTimeLevels");
    assert (is_level_mode());
    
    for (int group=0; group<CCTK_NumGroups(); ++group) {
      if (CCTK_QueryGroupStorageI(cgh, group)) {
        
        int const activetimelevels = CCTK_ActiveTimeLevelsGI (cgh, group);
        if (activetimelevels > 1) {
          if (activetimelevels < prolongation_order_time+1) {
            char * const groupname = CCTK_GroupName (group);
            CCTK_VWarn (CCTK_WARN_ABORT, __LINE__, __FILE__, CCTK_THORNSTRING,
                        "Group \"%s\" has %d only active time levels.  Groups with more than one active time level need at least %d active time levels for prolongation_order_time=%d",
                        groupname,
                        activetimelevels, int(prolongation_order_time+1),
                        int(prolongation_order_time));
            free (groupname);
          }
        }
        
        switch (CCTK_GroupTypeI(group)) {
          
        case CCTK_GF:
          assert (reflevel>=0 and reflevel<reflevels);
          for (int m=0; m<(int)arrdata.AT(group).size(); ++m) {
            for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
              arrdata.AT(group).AT(m).data.AT(var)->
                flip_all (reflevel, mglevel);
            }
          }
          break;
          
        case CCTK_SCALAR:
        case CCTK_ARRAY:
          if (do_global_mode) {
	    int const numtimelevels = CCTK_NumTimeLevelsI (group);
	    int const firstvarindex = CCTK_FirstVarIndexI (group);
            for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
              arrdata.AT(group).AT(0).data.AT(var)->flip_all (0, mglevel);
	      {
                int const varindex = firstvarindex + var;
		for (int tl=0; tl<numtimelevels; ++tl) {
		  cgh->data[varindex][tl]
		    = (tl < groupdata.AT(group).info.activetimelevels
		       ? ((*arrdata.AT(group).AT(0).data.AT(var))
			  (tl, 0, 0, 0)->storage())
		       : NULL);
		}
	      }
            }
          }
          break;
          
        default:
          assert (0);
        } // switch grouptype
      } // if storage
    } // for group
  }
  
  
  
  void FillTimeLevels (const cGH* cgh)
  {
    Checkpoint ("FillTimeLevels");
    assert (is_level_mode());
    
    for (int group=0; group<CCTK_NumGroups(); ++group) {
      if (CCTK_QueryGroupStorageI(cgh, group)) {
        switch (CCTK_GroupTypeI(group)) {
          
        case CCTK_GF:
          assert (reflevel>=0 and reflevel<reflevels);
	  for (int m=0; m<(int)arrdata.AT(group).size(); ++m) {
	    for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
              arrdata.AT(group).AT(m).data.AT(var)->
                fill_all (reflevel, mglevel);
            }
          }
          break;
          
        case CCTK_SCALAR:
        case CCTK_ARRAY:
          if (do_global_mode) {
            for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
              arrdata.AT(group).AT(0).data.AT(var)->fill_all (0, mglevel);
            }
          }
          break;
          
        default:
          assert (0);
        } // switch grouptype
      } // if storage
    } // for group
  }
  
} // namespace Carpet