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
|
#ifndef TH_HH
#define TH_HH
#include <cassert>
#include <iostream>
#include <vector>
#include "cctk.h"
#include "defs.hh"
#include "gh.hh"
using namespace std;
// Forward declaration
class th;
// Output
ostream& operator<< (ostream& os, const th& t);
// The time hierarchy (information about the current time)
class th {
public: // should be readonly
// Fields
gh& h; // hierarchy
private:
const vector<int> reffacts;
CCTK_REAL delta; // time step
vector<vector<CCTK_REAL> > times; // current times [ml][rl]
vector<vector<CCTK_REAL> > deltas; // time steps [ml][rl]
public:
// Constructors
th (gh& h, const vector<int> & reffacts, const CCTK_REAL basedelta);
// Destructors
~th ();
// Modifiers
void recompose ();
// Time management
CCTK_REAL get_time (const int rl, const int ml) const
{
assert (rl>=0 and rl<h.reflevels());
assert (ml>=0 and ml<h.mglevels());
return times.at(ml).at(rl);
}
void set_time (const int rl, const int ml, const CCTK_REAL t)
{
assert (rl>=0 and rl<h.reflevels());
assert (ml>=0 and ml<h.mglevels());
times.at(ml).at(rl) = t;
}
void advance_time (const int rl, const int ml)
{
set_time(rl,ml, get_time(rl,ml) + get_delta(rl,ml));
}
CCTK_REAL get_delta (const int rl, const int ml) const
{
assert (rl>=0 and rl<h.reflevels());
assert (ml>=0 and ml<h.mglevels());
return deltas.at(ml).at(rl);
}
void set_delta (const int rl, const int ml, const CCTK_REAL dt)
{
assert (rl>=0 and rl<h.reflevels());
assert (ml>=0 and ml<h.mglevels());
deltas.at(ml).at(rl) = dt;
}
CCTK_REAL time (const int tl, const int rl, const int ml) const
{
assert (rl>=0 and rl<h.reflevels());
assert (ml>=0 and ml<h.mglevels());
return get_time(rl, ml) - tl * get_delta(rl, ml);
}
// Output
void output (ostream& os) const;
};
inline ostream& operator<< (ostream& os, const th& t) {
t.output(os);
return os;
}
#endif // TH_HH
|