aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/data.hh
blob: f9c6d55d566066251ed36e7fe19c0fb4fd670645 (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
#ifndef DATA_HH
#define DATA_HH

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

#include "cctk.h"

#include "defs.hh"
#include "dist.hh"
#include "bbox.hh"
#include "gdata.hh"
#include "vect.hh"

using namespace std;



// A distributed multi-dimensional array
template<class T,int D>
class data: public gdata<D>
{
  
  // Types
  typedef vect<int,D> ivect;
  typedef bbox<int,D> ibbox;

  // Fields
  T* _storage;			// the data (if located on this processor)
  size_t _allocated_bytes;      // number of allocated bytes
  
  // For vector groups with contiguous storage
  int vectorlength;             // number of vector elements
  int vectorindex;              // index of this vector element
  data* vectorleader;           // if index!=0: first vector element
  vector<bool> vectorclients;   // if index==0: registered elements
  
  void register_client (int index);
  void unregister_client (int index);
  bool has_clients ();
  
public:
  
  // Constructors
  data (const int varindex = -1,
        const operator_type transport_operator = op_error,
        const int vectorlength = 1, const int vectorindex = 0,
        data* const vectorleader = NULL);
  data (const int varindex, const operator_type transport_operator,
        const int vectorlength, const int vectorindex,
        data* const vectorleader,
        const ibbox& extent, const int proc);

  // Destructors
  virtual ~data ();

  // Pseudo constructors
  virtual data* make_typed (const int varindex,
                            const operator_type transport_operator) const;

  // Storage management
private:
  void getmem (const size_t nelems);
  void freemem ();
public:
  virtual void allocate (const ibbox& extent, const int proc,
			 void* const mem=0);
  virtual void free ();
  virtual void transfer_from (gdata<D>* gsrc);

private:
  T* vectordata (const int vectorindex) const;
public:

  // Processor management
private:
  virtual void change_processor_recv (comm_state<D>& state,
                                      const int newproc,
                                      void* const mem=0);
  virtual void change_processor_send (comm_state<D>& state,
                                      const int newproc,
                                      void* const mem=0);
  virtual void change_processor_wait (comm_state<D>& state,
                                      const int newproc,
                                      void* const mem=0);
public:

  // Accessors
  virtual const void* storage () const
  {
    assert (this->_has_storage);
    return _storage;
  }

  virtual void* storage () {
    assert (this->_has_storage);
    return _storage;
  }
  
  // Data accessors
  const T& operator[] (const ivect& index) const
  {
    assert (_storage);
    return _storage[offset(index)];
  }
  
  T& operator[] (const ivect& index)
  {
    assert (_storage);
    return _storage[offset(index)];
  }
  
  // Data manipulators
private:
  static void
  fill_bbox_arrays (int srcshp[D], int dstshp[D],
                    int srcbbox[D][D], int dstbbox[D][D], int regbbox[D][D],
                    const ibbox & box, const ibbox & sext, const ibbox & dext);
public:
  void copy_from_innerloop (const gdata<D>* gsrc,
			    const ibbox& box);
  void interpolate_from_innerloop (const vector<const gdata<D>*> gsrcs,
				   const vector<CCTK_REAL> times,
				   const ibbox& box, const CCTK_REAL time,
				   const int order_space,
				   const int order_time);
  
  
public:

  // Output
  ostream& output (ostream& os) const;
private:
  bool interpolate_in_time (const vector<const gdata<D>*> & gsrcs,
                                   const vector<CCTK_REAL> & times,
                                   const ibbox& box, const CCTK_REAL time,
                                   const int order_space,
                                   const int order_time);
  void interpolate_restrict (const vector<const data<T,D>*> & gsrcs,
                              const vector<CCTK_REAL> & times,
                              const ibbox& box);
  void interpolate_prolongate (const vector<const data<T,D>*> & gsrcs,
                              const vector<CCTK_REAL> & times,
                              const ibbox& box, const CCTK_REAL time,
                              const int order_space,
                              const int order_time);
  void Check_that_the_times_are_consistent ( const vector<CCTK_REAL> & times,
                              const CCTK_REAL time );

};



// Declare a specialisation
template<>
void data<CCTK_REAL8,3>
::interpolate_from_innerloop (const vector<const gdata<3>*> gsrcs,
                              const vector<CCTK_REAL> times,
                              const ibbox& box, const CCTK_REAL time,
                              const int order_space,
                              const int order_time);



#endif // DATA_HH