aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/carpet.hh
blob: f3005fb4912ef0d336d433b7479b736ef8bb6e1a (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
// $Header: /home/eschnett/C/carpet/Carpet/Carpet/Carpet/src/carpet.hh,v 1.11 2001/07/04 12:29:48 schnetter Exp $

// It is assumed that the number of components of all arrays is equal
// to the number of components of the grid functions, and that their
// distribution onto the processors is the same, and that all
// processors own the same number of components.

// TODO: treat scalars as arrays with a dimension of zero

#include <vector>

#include "cctk.h"
#include "cctk_Schedule.h"

#include "Carpet/CarpetLib/src/dh.hh"
#include "Carpet/CarpetLib/src/ggf.hh"
#include "Carpet/CarpetLib/src/gh.hh"
#include "Carpet/CarpetLib/src/th.hh"

namespace Carpet {
  
  
  
  const int dim = 3;
  
  
  
  // Handle from CCTK_RegisterGHExtension
  extern int GHExtension;
  
  // Maximum number of refinement levels
  extern int maxreflevels;
  
  // Refinement factor on finest grid
  extern int maxreflevelfact;
  
  // Current iteration per refinement level
  extern vector<int> iteration;
  
  // Current position on the grid hierarchy
  extern int reflevel;
  extern int mglevel;
  extern int component;
  
  // Current refinement factor
  extern int reflevelfact;
  
  // Time step on base grid
  extern CCTK_REAL base_delta_time;
  
  
  
  // Data for scalars
  struct scdesc {
    vector<vector<vector<void*> > > data; // [var][rl][tl]
  };
  extern vector<scdesc> scdata;	// group
  
  // Data for arrays
  struct arrdesc {
    gh<dim>* hh;
    th* tt;
    dh<dim>* dd;
    vector<generic_gf<dim>* > data; // [var]
    int size[dim];
  };
  extern vector<arrdesc> arrdata; // [group]
  
  // Data for grid functions
  
  // The grid hierarchy
  extern gh<dim>* hh;
  extern th* tt;
  extern dh<dim>* dd;
  extern int gfsize[dim];
  
  struct gfdesc {
    vector<generic_gf<dim>*> data; // [var]
  };
  extern vector<gfdesc> gfdata;	// [group]
  
  // Checksums
  struct ckdesc {
    bool valid;
    int sum;
  };
  extern vector<vector<vector<vector<ckdesc> > > > checksums; // [n][rl][tl][c]
  
  
  
  // Scheduled functions
  extern "C" {
    int CarpetStartup();
  }
  
  // Registered functions
  void* SetupGH (tFleshConfig* fc, int convLevel, cGH* cgh);
  
  int Initialise (tFleshConfig* config);
  int Evolve (tFleshConfig* config);
  int Shutdown (tFleshConfig* config);
  int CallFunction (void* function, cFunctionData* attribute, void* data);
  
  int SyncGroup (cGH* cgh, const char* groupname);
  int EnableGroupStorage (cGH* cgh, const char* groupname);
  int DisableGroupStorage (cGH* cgh, const char* groupname); 
  int EnableGroupComm (cGH* cgh, const char* groupname);
  int DisableGroupComm (cGH* cgh, const char* groupname);
  int Barrier (cGH* cgh);
  int Exit (cGH* cgh, int retval);
  int Abort (cGH* cgh, int retval);
  int MyProc (cGH* cgh);
  int nProcs (cGH* cgh);
  const int* ArrayGroupSizeB (cGH* cgh, int dir, int group,
			      const char* groupname);
  int QueryGroupStorageB (cGH* cgh, int group, const char* groupname);
  
  
  
  // Helper functions
  void set_reflevel (cGH* cgh, int rl);
  void set_mglevel (cGH* cgh, int ml);
  void set_component (cGH* cgh, int c);
  
  
  
  // Refinement level iterator
  
#define BEGIN_REFLEVEL_LOOP(cgh)		\
  do {						\
    int _rl;					\
    assert (reflevel==0);			\
    for (;;) {					\
      {
#define END_REFLEVEL_LOOP(cgh)			\
      }						\
      if (reflevel==maxreflevels-1) break;	\
      set_reflevel ((cgh), reflevel+1);		\
    }						\
    set_reflevel ((cgh), 0);			\
    assert (reflevel==0);			\
    _rl = 0;					\
  } while (0)
  
  
  
  // Reverse refinement level iterator
  
#define BEGIN_REVERSE_REFLEVEL_LOOP(cgh)	\
  do {						\
    int _rrl;					\
    assert (reflevel==0);			\
    set_reflevel ((cgh), maxreflevels-1);	\
    for (;;) {					\
      {
#define END_REVERSE_REFLEVEL_LOOP(cgh)		\
      }						\
      if (reflevel==0) break;			\
      set_reflevel ((cgh), reflevel-1);		\
    }						\
    assert (reflevel==0);			\
    _rrl = 0;					\
  } while (0)
  
  
  
  // Component iterator
  
#define BEGIN_COMPONENT_LOOP(cgh)		\
  do {						\
    int _cl;					\
    assert (component==-1);			\
    set_component ((cgh), 0);			\
    for (;;) {					\
      {
#define END_COMPONENT_LOOP(cgh)				\
      }							\
      if (component==hh->components(reflevel)-1) break;	\
      set_component ((cgh), component+1);		\
    }							\
    set_component ((cgh), -1);				\
    assert (component==-1);				\
    _cl = 0;						\
  } while (0)
  
  
  
  extern "C" {
    MPI_Comm CarpetMPICommunicator();
  }
  
  
  
  // These are private; don't use these from the outside
  
  void Recompose (cGH* cgh);
  void CycleTimeLevels (cGH* cgh);
  void Restrict (cGH* cgh);
  
  enum checktimes { currenttime,
		    currenttimebutnotifonly,
		    allbutlasttime,
		    allbutcurrenttime,
		    alltimes };
  
  int mintl (checktimes where, int num_tl);
  int maxtl (checktimes where, int num_tl);
  
  void Poison (cGH* cgh, checktimes where);
  void PoisonGroup (cGH* cgh, int group, checktimes where);
  void PoisonCheck (cGH* cgh, checktimes where);
  
  void CalculateChecksums (cGH* cgh, checktimes where);
  void CheckChecksums (cGH* cgh, checktimes where);
  
  // Debugging output
  void Checkpoint (const char* fmt, ...);
  
  // Error output
  void UnsupportedVarType (int vindex);
  
} // namespace Carpet