aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/carpet_public.hh
blob: c16fd743afea9d51f24b74c6a5c55a5c4f1a2574 (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
// $Header: /home/eschnett/C/carpet/Carpet/Carpet/Carpet/src/carpet_public.hh,v 1.14 2002/01/09 17:45:40 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 "Carpet/CarpetLib/src/dh.hh"
#include "Carpet/CarpetLib/src/gf.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;
  
  // 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;
  
  // Refinement factor
  extern int reffact;
  
  // 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 mglevel;
  extern int reflevel;
  extern int component;
  
  // Current multigrid factor
  extern int mglevelfact;
  
  // Current refinement factor
  extern int reflevelfact;
  
  // Time step on base grid
  extern CCTK_REAL base_delta_time;
  
  
  
  // Data for grid functions
  
  // The grid hierarchy
  extern gh<dim>* hh;
  extern th* tt;
  extern dh<dim>* dd;
  
  // Data for scalars
  extern gh<dim>* hh0;
  extern th* tt0;
  extern dh<dim>* dd0;
  
  // Data for everything
  struct arrdesc {
    // points to hh etc. for GF, and to hh0 etc. for SCALAR
    // is unique for ARRAY
    cGroupDynamicData info;
    gh<dim>* hh;
    th* tt;
    dh<dim>* dd;
    vector<generic_gf<dim>* > data; // [var]
  };
  extern vector<arrdesc> arrdata; // [group]
  
  
  
  // Checksums
  struct ckdesc {
    bool valid;
    int sum;
  };
  extern vector<vector<vector<vector<ckdesc> > > > checksums; // [n][rl][tl][c]
  
  
  
  // Stuff with C linkage
  extern "C" {
#include "carpet_public.h"
  }
  
  
  
  // 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 (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 RegisterRecomposeRegions (const gh<dim>::rexts& bbsss,
				 const gh<dim>::rprocs& pss);
  
  void SplitRegions (const cGH* cgh, vector<bbox<int,dim> >& bbs);
  
  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);
  
  
  
  // Multigrid level iterator
  
#define BEGIN_MGLEVEL_LOOP(cgh)			\
  do {						\
    int _mgl;					\
    assert (mglevel==0);			\
    for (int _ml=mglevels-1; _ml>=0; --_ml) {	\
      set_mglevel ((cGH*)(cgh), _ml);		\
      {
#define END_MGLEVEL_LOOP(cgh)			\
      }						\
    }						\
    assert (mglevel==0);			\
    _mgl = 0;					\
  } while (0)
  
  
  
  // Refinement level iterator
  
#define BEGIN_REFLEVEL_LOOP(cgh)			\
  do {							\
    int _rll;						\
    assert (reflevel==0);				\
    for (int _rl=0; _rl<hh->reflevels(); ++_rl) {	\
      set_reflevel ((cGH*)(cgh), _rl);			\
      {
#define END_REFLEVEL_LOOP(cgh)			\
      }						\
    }						\
    set_reflevel ((cGH*)(cgh), 0);		\
    assert (reflevel==0);			\
    _rll = 0;					\
  } while (0)
  
  
  
  // Reverse refinement level iterator
  
#define BEGIN_REVERSE_REFLEVEL_LOOP(cgh)		\
  do {							\
    int _rrll;						\
    assert (reflevel==0);				\
    for (int _rl=hh->reflevels()-1; _rl>=0; --_rl) {	\
      set_reflevel ((cGH*)(cgh), _rl);			\
      {
#define END_REVERSE_REFLEVEL_LOOP(cgh)		\
      }						\
    }						\
    assert (reflevel==0);			\
    _rrll = 0;					\
  } while (0)
  
  
  
  // Component iterator
  
#define BEGIN_COMPONENT_LOOP(cgh)			\
  do {							\
    int _cl;						\
    assert (reflevel>=0 && reflevel<hh->reflevels());	\
    assert (component==-1);				\
    for (int _c=0; _c<hh->components(reflevel); ++_c) {	\
      set_component ((cGH*)(cgh), _c);			\
      {
#define END_COMPONENT_LOOP(cgh)			\
      }						\
    }						\
    set_component ((cGH*)(cgh), -1);		\
    assert (component==-1);			\
    _cl = 0;					\
  } while (0)


  
#define BEGIN_LOCAL_COMPONENT_LOOP(cgh)			\
  do {							\
    int _lcl;						\
    assert (reflevel>=0 && reflevel<hh->reflevels());	\
    assert (component==-1);				\
    for (int _c=0; _c<hh->components(reflevel); ++_c) {	\
      if (hh->is_local(reflevel,_c)) {			\
	set_component ((cGH*)(cgh), _c);		\
	{
#define END_LOCAL_COMPONENT_LOOP(cgh)		\
	}					\
      }						\
    }						\
    set_component ((cGH*)(cgh), -1);		\
    assert (component==-1);			\
    _lcl = 0;					\
  } while (0)
  
} // namespace Carpet

#endif // ! defined(CARPET_PUBLIC_HH)