aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/data.hh
blob: 983f7f141d29ed58e7d9c49396e532de4aec1c83 (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
/***************************************************************************
                          data.hh  -  Data storage
                             -------------------
    begin                : Sun Jun 11 2000
    copyright            : (C) 2000 by Erik Schnetter
    email                : schnetter@astro.psu.edu

    $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/data.hh,v 1.10 2002/05/05 22:16:59 schnetter Exp $

 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DATA_HH
#define DATA_HH

#include <assert.h>

#include <iostream>
#include <string>

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

using namespace std;



// A real data storage
template<class T,int D>
class data: public generic_data<D> {
  
  // Types
  typedef vect<int,D> ivect;
  typedef bbox<int,D> ibbox;

  // Fields
  T* _storage;			// the data (if located on this processor)

public:
  
  // Constructors
  data ();
  data (const ibbox& extent, const int proc);

  // Destructors
  virtual ~data ();

  // Pseudo constructors
  virtual data* make_typed () const;

  // Storage management
  virtual void allocate (const ibbox& extent, const int proc,
			 void* const mem=0);
  virtual void free ();
  virtual void transfer_from (generic_data<D>* gsrc);

  // Processor management
  virtual void change_processor (const int newproc, void* const mem=0);

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

  virtual void* storage () {
    assert (_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
  void copy_from_innerloop (const generic_data<D>* gsrc,
			    const ibbox& box);
  void interpolate_from_innerloop (const vector<const generic_data<D>*> gsrcs,
				   const vector<int> tls,
				   const ibbox& box, const int tl,
				   const int order_space,
				   const int order_time);
  
public:

  // Output
  ostream& output (ostream& os) const;
};



#endif // DATA_HH