aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/gh.hh
blob: ef6198e0f356b2c26dd3ff9fdaeacdb89fe69a7e (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
#ifndef GH_HH
#define GH_HH

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

#include "bbox.hh"
#include "bboxset.hh"
#include "defs.hh"
#include "dist.hh"
#include "region.hh"
#include "vect.hh"

using namespace std;



// Forward declaration
class dh;
class th;
class gh;



// A refinement hierarchy, where higher levels are finer than the base
// level.  The extents do not include ghost zones.
class gh {
  
  static list<gh*> allgh;
  list<gh*>::iterator allghi;
  
public:
  
  // Types
  typedef vector<region_t> cregs; // ... for each component
  typedef vector<cregs> rregs;    // ... for each refinement level
  typedef vector<rregs> mregs;    // ... for each multigrid level
  
public:				// should be readonly
  
  // Fields
  const vector<ivect> reffacts; // refinement factors
  const centering refcent;	// vertex or cell centered
 
  const int mgfact;		// default multigrid factor
  const centering mgcent;	// default (vertex or cell centered)
  
  vector<vector<ibbox> > baseextents; // [ml][rl]
  const i2vect boundary_width;
  
private:
  vector<vector<int> > global_components_; // [rl][lc]
  vector<vector<int> > local_components_;  // [rl][c]
  vector<vector<int> > old_global_components_; // [rl][lc]
  vector<vector<int> > old_local_components_;  // [rl][c]
public:
  
  // Extents of the regions before distributing them over the
  // processes
  rregs superregions;
  
  mregs regions;                // extents and properties of all grids
  mregs oldregions;             // extents and properties of all grids
  
  typedef list<th*>::iterator th_handle;
  list<th*> ths;		// list of all time hierarchies
  typedef list<dh*>::iterator dh_handle;
  list<dh*> dhs;		// list of all data hierarchies
  
public:
  
  // Constructors
  gh (vector<ivect> const & reffacts, centering refcent,
      int mgfact, centering mgcent,
      vector<vector<ibbox> > const & baseextents, 
      i2vect const & boundary_width);
  
  // Destructors
  ~gh ();
  
  // Modifiers
  void regrid (rregs const & superregs, mregs const & regs, bool do_init);
  void regrid_free (bool do_init);
  bool recompose (int rl, bool do_prolongate);
  
private:
  
  bool level_did_change (int rl) const CCTK_MEMBER_ATTRIBUTE_PURE;
  
  // Accessors
  
public:
  
  ibbox const & extent (const int ml, const int rl, const int c) const
  {
    return regions.AT(ml).AT(rl).AT(c).extent;
  }
  
  ibbox const & baseextent (const int ml, const int rl) const
  {
    return baseextents.AT(ml).AT(rl);
  }
  
  b2vect const & outer_boundaries (const int rl, const int c) const
  {
    return regions.AT(0).AT(rl).AT(c).outer_boundaries;
  }
  
  int processor (const int rl, const int c) const CCTK_MEMBER_ATTRIBUTE_PURE
  {
    return regions.AT(0).AT(rl).AT(c).processor;
  }

  int old_processor (const int rl, const int c) const CCTK_MEMBER_ATTRIBUTE_PURE
  {
    return oldregions.AT(0).AT(rl).AT(c).processor;
  }

  int mglevels () const CCTK_MEMBER_ATTRIBUTE_PURE
  {
    return (int)regions.size();
  }
  
  int reflevels () const CCTK_MEMBER_ATTRIBUTE_PURE
  {
    if (mglevels() == 0) return 0;
    return (int)regions.AT(0).size();
  }
  
  int components (const int rl) const CCTK_MEMBER_ATTRIBUTE_PURE
  {
    return (int)regions.AT(0).AT(rl).size();
  }
  
  bool is_local (const int rl, const int c) const CCTK_MEMBER_ATTRIBUTE_PURE
  {
    return processor(rl,c) == dist::rank();
  }
  
  int local_components (int rl) const CCTK_MEMBER_ATTRIBUTE_PURE;
  int get_component (int rl, int lc) const CCTK_MEMBER_ATTRIBUTE_PURE;
  int get_local_component (int rl, int c) const CCTK_MEMBER_ATTRIBUTE_PURE;
  
  bool old_is_local (const int rl, const int c) const CCTK_MEMBER_ATTRIBUTE_PURE
  {
    return old_processor(rl,c) == dist::rank();
  }
  
  int old_local_components (int rl) const CCTK_MEMBER_ATTRIBUTE_PURE;
  int get_old_component (int rl, int lc) const CCTK_MEMBER_ATTRIBUTE_PURE;
  int get_old_local_component (int rl, int c) const CCTK_MEMBER_ATTRIBUTE_PURE;
  
#if 0
  // Convert between index positions and coordinate positions
  rvect ipos2rpos (ivect const & ipos,
                   rvect const & origin, rvect const & scale,
                   int const ml, int const rl) const CCTK_MEMBER_ATTRIBUTE_PURE;
  ivect rpos2ipos (rvect const & rpos,
                   rvect const & origin, rvect const & scale,
                   int const ml, int const rl) const CCTK_MEMBER_ATTRIBUTE_PURE;
  ivect rpos2ipos1 (rvect const & rpos,
                    rvect const & origin, rvect const & scale,
                    int const ml, int const rl) const
    CCTK_MEMBER_ATTRIBUTE_PURE;
#endif
  
  void locate_position (rvect const & rpos,
                        int const ml,
                        int const minrl, int const maxrl,
                        int & rl, int & c, ivect & aligned_ipos) const
    CCTK_MEMBER_ATTRIBUTE_PURE;
  
  void locate_position (ivect const & ipos,
                        int const ml,
                        int const minrl, int const maxrl,
                        int & rl, int & c, ivect & aligned_ipos) const
    CCTK_MEMBER_ATTRIBUTE_PURE;
  
  // Time hierarchy management
  th_handle add (th * t);
  void erase (th_handle ti);
  
  // Data hierarchy management
  dh_handle add (dh * d);
  void erase (dh_handle di);
  
  // Output
  size_t memory () const CCTK_MEMBER_ATTRIBUTE_PURE;
  static size_t allmemory () CCTK_MEMBER_ATTRIBUTE_PURE;
  ostream & output (ostream & os) const;

private:
  void do_output_bboxes (ostream & os) const;
  void do_output_bases (ostream & os) const;

};



inline size_t memoryof (gh const & g)
{
  return g.memory ();
}

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



#endif // GH_HH