aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/gdata.hh
blob: d9f6fb84246ea7ca25a16e5388f9e797493ed6ed (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
/***************************************************************************
                          gdata.hh  -  description
                             -------------------
    begin                : Wed Jul 19 2000
    copyright            : (C) 2000 by Erik Schnetter
    email                : schnetter@astro.psu.edu

    $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/gdata.hh,v 1.12 2002/01/08 12:03:55 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 GDATA_HH
#define GDATA_HH

#include <assert.h>
#include <stdlib.h>

#include <iostream>
#include <string>

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

using namespace std;



// A generic data storage without type information
template<int D>
class generic_data: public dimgeneric_data {

  // Types
  typedef vect<int,D> ivect;
  typedef bbox<int,D> ibbox;

protected:                      // should be readonly

  // Fields
  ivect _shape, _stride;      	// shape and index order
  
  ibbox _extent;		// bbox for all data

public:

  // Constructors
  generic_data ();

  // Destructors
  virtual ~generic_data ();

  // Pseudo constructors
  virtual generic_data<D>* make_typed () const = 0;

  // Storage management
  virtual void transfer_from (generic_data<D>* src) = 0;
  
  virtual void allocate (const ibbox& extent, const int proc,
			 void* const mem=0) = 0;
  virtual void free () = 0;
  
  // Accessors
  
  const ivect& shape () const {
    assert (_has_storage);
    return _shape;
  }

  const ivect& stride () const {
    assert (_has_storage);
    return _stride;
  }
  
  const ibbox& extent () const {
    assert (_has_storage);
    return _extent;
  }

  // Data accessors
  int offset (const ivect& index) const {
    assert (_has_storage);
    assert (all((index-extent().lower()) % extent().stride() == 0));
    ivect ind = (index-extent().lower()) / extent().stride();
    assert (all(ind>=0 && ind<=shape()));
    return dot(ind, stride());
  }

  // Data manipulators
  void copy_from (const generic_data* src, const ibbox& box);
  void interpolate_from (const vector<const generic_data*> srcs,
			 const vector<int> tls,
			 const ibbox& box, const int tl,
			 const int order_space,
			 const int order_time);
protected:
  virtual void
  copy_from_innerloop (const generic_data* src, const ibbox& box) = 0;
  virtual void
  interpolate_from_innerloop (const vector<const generic_data*> srcs,
			      const vector<int> tls,
			      const ibbox& box, const int tl,
			      const int order_space,
			      const int order_time) = 0;
  
public:
  
  // Output
  template<int DD>
  void write_ascii (ostream& os, const int time,
                    const vect<int,D>& org, const vect<int,DD>& dirs,
		    const int tl, const int rl,
                    const int c, const int ml,
		    const double ctime,
		    const vect<double,D>& coord_lower,
		    const vect<double,D>& coord_upper)
    const;
protected:
  virtual void write_ascii_output_element (ostream& os, const ivect& index)
    const = 0;
public:
//   void write_ieee (const string name, const int time,
// 		   const int tl, const int rl, const int c, const int ml)
//     const;
//   void write_hdf (const string name, const int time,
// 		  const int tl, const int rl, const int c, const int ml)
//     const;
//   void write_h5 (const string name, const int time,
// 		 const int tl, const int rl, const int c, const int ml)
//     const;
public:
};



#if defined(TMPL_IMPLICIT)
#  include "gdata.cc"
#endif

#endif // GDATA_HH