aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/dh.hh
blob: a4df5a51677c45aa475fcf04ec22404121e751a1 (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
#ifndef DH_HH
#define DH_HH

#include <cassert>
#include <iostream>
#include <list>
#include <string>
#include <vector>

#include "bbox.hh"
#include "bboxset.hh"
#include "defs.hh"
#include "gh.hh"
#include "vect.hh"

using namespace std;



// A pseudoregion is almost a region; it is a bbox that lives on a
// certain processor.  Pseudoregions are a compact way to store
// information about what processors needs to send data to what other
// processor during synchronisation or regridding.
struct pseudoregion {
  ibbox extent;
  int processor;
};



// Forward declaration
class ggf;
class dh;



// A data hierarchy (grid hierarchy plus ghost zones)
class dh {
  
  // Types
public:
  typedef list<ibbox>    iblist;
  typedef vector<iblist> iblistvect; // vector of lists
  
  typedef vector <pseudoregion> pvect;
  
  
  
  struct dboxes {
    
    // Region description:
    
    ibbox exterior;             // whole region (including boundaries)
    
    b2vect is_outer_boundary;
    ibset outer_boundaries;     // outer boundary
    ibbox communicated;         // exterior without outer boundary
    
    ibset boundaries;           // ghost zones
    ibbox owned;                // evolved in time
    
    ibset buffers;              // buffer zones
    ibset active;               // owned minus buffers
    
    ibset sync;                 // filled by synchronisation
    ibset bndref;               // filled by boundary prolongation
    
    // For Cactus: (these are like boundary or owned, but include the
    // outer boundary)
    ibset ghosts;               // ghost zones, as seen from Cactus
    ibbox interior;             // interior (without ghost zones)
    
    // Communication schedule:
    
    // ref_prol_recv[cc] and ref_rest_send[cc] determine what needs to
    // be sent from and received from cc for prolongation to this box
    
    iblist mg_rest_recv;
    iblist mg_rest_send;
    iblist mg_prol_recv;
    iblist mg_prol_send;
    iblistvect ref_prol_recv;
    iblistvect ref_prol_send;
    iblistvect ref_rest_recv;
    iblistvect ref_rest_send;
    iblistvect sync_recv;
    iblistvect sync_send;
    iblistvect ref_bnd_prol_recv;
    iblistvect ref_bnd_prol_send;
    
    pvect fast_mg_rest_recv;
    pvect fast_mg_rest_send;
    pvect fast_mg_prol_recv;
    pvect fast_mg_prol_send;
    pvect fast_ref_prol_recv;
    pvect fast_ref_prol_send;
    pvect fast_ref_rest_recv;
    pvect fast_ref_rest_send;
    pvect fast_sync_recv;
    pvect fast_sync_send;
    pvect fast_ref_bnd_prol_recv;
    pvect fast_ref_bnd_prol_send;
    
    // Regridding schedule:
    
    iblistvect old2new_sync_recv;
    iblistvect old2new_sync_send;
    iblistvect old2new_ref_prol_recv;
    iblistvect old2new_ref_prol_send;
    
    pvect fast_old2new_sync_recv;
    pvect fast_old2new_sync_send;
    pvect fast_old2new_ref_prol_recv;
    pvect fast_old2new_ref_prol_send;
    
    ostream & output (ostream & os) const;
  };
  
private:
  
  typedef vector<dboxes> cboxes; // ... for each component
  typedef vector<cboxes> rboxes; // ... for each refinement level
  typedef vector<rboxes> mboxes; // ... for each multigrid level
  
  
  
  void
  setup_bboxes ();
  
  static
  void
  optimise_field (dboxes & b,
                  iblistvect const dboxes::* field,
                  pvect dboxes::* fast_field);
  static
  void
  optimise_field (dboxes & b,
                  int proc,
                  iblist const dboxes::* field,
                  pvect dboxes::* fast_field);
  
public:                         // should be readonly
  
  // Fields
  gh & h;                       // hierarchy
  i2vect ghost_width;           // number of ghost zones
  i2vect buffer_width;          // number of buffer zones
  
  int prolongation_order_space; // order of spatial prolongation operator
  
  mboxes boxes;                 // grid hierarchy
  mboxes oldboxes;              // old grid hierarchy, used during regridding
  
  list<ggf*> gfs;               // list of all grid functions
  
public:
  
  // Constructors
  dh (gh & h,
      i2vect const & ghosts, i2vect const & buffers,
      int prolongation_order_space);
  
  // Destructors
  ~dh ();
  
  // Helpers
  int prolongation_stencil_size () const;
  
  // Modifiers
  void regrid ();
  void recompose (int rl, bool do_prolongate);
  
  // Grid function management
  void add (ggf * f);
  void remove (ggf * f);
  
  // Output
  ostream & output (ostream & os) const;
};



inline ostream & operator<< (ostream & os, dh::dboxes const & b)
{
  return b.output (os);
}

inline ostream & operator<< (ostream & os, dh const & d)
{
  return d.output (os);
}



#endif // DH_HH