aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/carpet_public.hh
blob: 5c12b3ce32f480322296c51cda886c61afe39570 (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
// $Header: /home/eschnett/C/carpet/Carpet/Carpet/Carpet/src/carpet_public.hh,v 1.1 2001/07/09 09:00:14 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.

#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 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 (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);
  int GroupDynamicData (cGH* cgh, int group, cGroupDynamicData* data);
  
  
  
  // 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)
  
} // namespace Carpet