aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/th.hh
blob: 6089e37cd14936bc634ff23263a89506d5488a47 (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
/***************************************************************************
                          th.hh  -  Time Hierarchy
                          information about time levels
                             -------------------
    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/th.hh,v 1.1 2001/03/01 13:40:10 eschnett 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 TH_HH
#define TH_HH

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

#include "defs.hh"
#include "gh.hh"



// Forward declaration
template<int D> class th;

// Output
template<int D>
ostream& operator<< (ostream& os, const th<D>& t);



// The time hierarchy (information about the current time)
template<int D>
class th {
  
public:				// should be readonly
  
  // Fields
  gh<D> &h;			// hierarchy
  
private:
  
  int delta;			// time step
  vector<vector<int> > times;	// current times
  vector<vector<int> > deltas;	// time steps
  
public:
  
  // Constructors
  th (gh<D>& h, const int basedelta);
  
  // Destructors
  ~th ();
  
  // Modifiers
  void recompose ();
  
  // Time management
  int get_time (const int rl, const int ml) const {
    assert (rl>=0 && rl<h.reflevels());
    assert (ml>=0 && ml<h.mglevels(rl,0));
    return times[rl][ml];
  }
  
  void set_time (const int rl, const int ml, const int t) {
    assert (rl>=0 && rl<h.reflevels());
    assert (ml>=0 && ml<h.mglevels(rl,0));
    times[rl][ml] = t;
  }
  
  void advance_time (const int rl, const int ml) {
    set_time(rl,ml, get_time(rl,ml) + get_delta(rl,ml));
  }
  
  int get_delta (const int rl, const int ml) const {
    assert (rl>=0 && rl<h.reflevels());
    assert (ml>=0 && ml<h.mglevels(rl,0));
    return deltas[rl][ml];
  }
  
  int time (const int tl, const int rl, const int ml) const {
    assert (rl>=0 && rl<h.reflevels());
    assert (ml>=0 && ml<h.mglevels(rl,0));
    return get_time(rl, ml) + tl * get_delta(rl, ml);
  }
  
  // Output
  friend ostream& operator<< <> (ostream& os, const th& d);
};



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

#endif // TH_HH