aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/carpet_public.hh
blob: 61e4fbe28768939468830a33d8c34cdf58480aea (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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// $Header: /home/eschnett/C/carpet/Carpet/Carpet/Carpet/src/carpet_public.hh,v 1.38 2003/10/13 11:44:51 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.

#ifndef CARPET_PUBLIC_HH
#define CARPET_PUBLIC_HH

#include <vector>

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

#include "dh.hh"
#include "gf.hh"
#include "ggf.hh"
#include "gh.hh"
#include "th.hh"
  
#include "carpet_public.h"
  
  
  
// Stuff with C linkage
#include "carpet_public.h"

  
  
namespace Carpet {
  
  
  
  const int dim = 3;
  
  
  
  // Handle from CCTK_RegisterGHExtension
  extern int GHExtension;
  
  // Refinement factor
  extern int reffact;
  
  // Refinement factor on finest grid
  extern int maxreflevelfact;
  
  // Multigrid levels
  extern int mglevels;
  
  // Multigrid factor
  extern int mgfact;
  
  // Maximum number of refinement levels
  extern int maxreflevels;
  
  // Multigrid factor on coarsest grid
  extern int maxmglevelfact;
  
  
  
  // Current position on the grid hierarchy
  extern int reflevel;
  extern int mglevel;
  extern int component;
  
  // Current refinement factor
  extern int reflevelfact;
  
  // Current multigrid factor
  extern int mglevelfact;
  
  // Is this the time for a global mode call?
  extern bool do_global_mode;
  
  // Is prolongation enabled?
  extern bool do_prolongate;
  
  // Current times on the refinement levels
  extern vector<CCTK_REAL> refleveltimes;
  extern CCTK_REAL delta_time;
  
  
  
  // Data for grid functions
  
  // The grid hierarchy
  extern gh<dim>* hh;
  extern th<dim>* tt;
  extern dh<dim>* dd;
  
  // Data for everything
  struct arrdesc {
    // points to hh etc. for GF, and is unique for SCALAR and ARRAY
    cGroupDynamicData info;
    gh<dim>* hh;
    th<dim>* tt;
    dh<dim>* dd;
    vector<ggf<dim>*> data;     // [var]
    bool do_transfer;           // prolongate and restrict
    // VGF
  };
  extern vector<arrdesc> arrdata; // [group]
  
  
  
  // Checksums
  struct ckdesc {
    bool valid;
    unsigned int sum;
  };
  // [rl][c][group][var][tl]
  extern vector<vector<vector<vector<vector<ckdesc> > > > > checksums;
  
  
  
  // 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 (const cGH* cgh, const char* groupname);
  int EnableGroupStorage (const cGH* cgh, const char* groupname);
  int DisableGroupStorage (const cGH* cgh, const char* groupname); 
  int EnableGroupComm (const cGH* cgh, const char* groupname);
  int DisableGroupComm (const cGH* cgh, const char* groupname);
  int Barrier (const cGH* cgh);
  int Exit (cGH* cgh, int retval);
  int Abort (cGH* cgh, int retval);
  int MyProc (const cGH* cgh);
  int nProcs (const cGH* cgh);
  const int* ArrayGroupSizeB (const cGH* cgh, int dir, int group,
			      const char* groupname);
  int QueryGroupStorageB (const cGH* cgh, int group, const char* groupname);
  int GroupDynamicData (const cGH* cgh, int group, cGroupDynamicData* data);
  
  
  
  // Functions for recomposing the grid hierarchy
  void RegisterRegridRoutine (int (*routine)(const cGH * cckgGH,
					     gh<dim>::rexts& bbsss,
					     gh<dim>::rbnds& obss,
					     gh<dim>::rprocs& pss));
  
  void SplitRegions (const cGH* cgh, vector<bbox<int,dim> >& bbs,
		     vector<vect<vect<bool,2>,dim> >& obs);
  void SplitRegions_AlongZ (const cGH* cgh, vector<bbox<int,dim> >& bbs,
			    vector<vect<vect<bool,2>,dim> >& obs);
  
  void MakeProcessors (const cGH* cgh, const gh<dim>::rexts& bbsss,
		       gh<dim>::rprocs& pss);
  
  
  
  // 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)                        \
  if (true) {                                           \
    int _rll;                                           \
    cGH * const _cgh = const_cast<cGH*>(cgh);           \
    assert (reflevel==-1);                              \
    for (int _rl=0; _rl<hh->reflevels(); ++_rl) {       \
      set_reflevel (_cgh, _rl);                         \
      {
#define END_REFLEVEL_LOOP                       \
      }                                         \
    }                                           \
    set_reflevel (_cgh, -1);                    \
    _rll = 0;                                   \
  } else
  
  
  
  // Reverse refinement level iterator
  
#define BEGIN_REVERSE_REFLEVEL_LOOP(cgh)                \
  if (true) {                                           \
    int _rrll;                                          \
    cGH * const _cgh = const_cast<cGH*>(cgh);           \
    assert (reflevel==-1);                              \
    for (int _rl=hh->reflevels()-1; _rl>=0; --_rl) {    \
      set_reflevel (_cgh, _rl);                         \
      {
#define END_REVERSE_REFLEVEL_LOOP               \
      }                                         \
    }                                           \
    set_reflevel (_cgh, -1);                    \
    _rrll = 0;                                  \
  } else
  
  
  
  // Multigrid level iterator
  
#define BEGIN_MGLEVEL_LOOP(cgh)                         \
  if (true) {                                           \
    int _mgl;                                           \
    cGH * const _cgh = const_cast<cGH*>(cgh);           \
    assert (reflevel>=0 && reflevel<hh->reflevels());   \
    assert (mglevel==-1);                               \
    for (int _ml=mglevels-1; _ml>=0; --_ml) {           \
      set_mglevel (_cgh, _ml);                          \
      {
#define END_MGLEVEL_LOOP                        \
      }                                         \
    }                                           \
    set_mglevel (_cgh, -1);                     \
    _mgl = 0;                                   \
  } else
  
  
  
  // Component iterator
  
  // Loop over all components.  If grouptype is CCTK_GF, then loop
  // over grid function components.  If grouptype is CCTK_ARRAY (or
  // CCTK_SCALAR), then loop over grid array (or grid scalar)
  // components.  In the latter case, component denotes the current
  // grid array component, i.e. it cannot be used to index grid
  // functions.
#define BEGIN_COMPONENT_LOOP(cgh, grouptype)            \
  if (true) {                                           \
    int _cl;                                            \
    cGH * const _cgh = const_cast<cGH*>(cgh);           \
    int const _grouptype = (grouptype);                 \
    int const _savec = (component);                     \
    int _minc, _maxc;                                   \
    if (_grouptype == CCTK_GF) {                        \
      assert (reflevel>=0 && reflevel<hh->reflevels()); \
      assert (mglevel>=0 && mglevel<mglevels);          \
      assert (component==-1);                           \
      _minc=0;                                          \
      _maxc=hh->components(reflevel);                   \
    } else {                                            \
      _minc=0;                                          \
      _maxc=CCTK_nProcs(_cgh);                          \
    }                                                   \
    for (int _c=_minc; _c<_maxc; ++_c) {                \
      if (component!=_c) set_component (_cgh, _c);      \
      {
#define END_COMPONENT_LOOP                              \
      }                                                 \
    }                                                   \
    if (component!=_savec) set_component (_cgh, -1);    \
    _cl = 0;                                            \
  } else


  
  // Loop over all processor-local components.  If grouptype is
  // CCTK_GF, then loop over grid function components.  If grouptype
  // is CCTK_ARRAY (or CCTK_SCALAR), then loop over grid array (or
  // grid scalar) components, i.e. execute the loop just once.  In the
  // latter case, component denotes the current grid array component,
  // i.e. it cannot be used to index grid functions.
#define BEGIN_LOCAL_COMPONENT_LOOP(cgh, grouptype)                      \
  if (true) {                                                           \
    int _lcl;                                                           \
    cGH * const _cgh = const_cast<cGH*>(cgh);                           \
    int const _grouptype = (grouptype);                                 \
    int const _savec = component;                                       \
    int _minc, _maxc;                                                   \
    if (_grouptype == CCTK_GF) {                                        \
      assert (reflevel>=0 && reflevel<hh->reflevels());                 \
      assert (mglevel>=0 && mglevel<mglevels);                          \
      assert (hh->local_components(reflevel)==1 || component==-1);      \
      _minc=0;                                                          \
      _maxc=hh->components(reflevel);                                   \
    } else {                                                            \
      _minc=component;                                                  \
      _maxc=_minc+1;                                                    \
    }                                                                   \
    for (int _c=_minc; _c<_maxc; ++_c) {                                \
      if (_grouptype!=CCTK_GF || hh->is_local(reflevel,_c)) {           \
        if (component!=_c) set_component (_cgh, _c);                    \
        {
#define END_LOCAL_COMPONENT_LOOP                                \
        }                                                       \
      }                                                         \
    }                                                           \
    if (component!=_savec) set_component (_cgh, _savec);        \
    _lcl = 0;                                                   \
  } else
  
} // namespace Carpet

#endif // !defined(CARPET_PUBLIC_HH)