aboutsummaryrefslogtreecommitdiff
path: root/CarpetDev/CarpetIOF5/src/timestep.cc
blob: 73d106a9297dbc65d8e0e351c9f9ae46b5c43d94 (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
#include <cassert>
#include <iomanip>
#include <limits>
#include <string>
#include <sstream>

#include <hdf5.h>

#include "cctk.h"
#include "cctk_Functions.h"

#include "timestep.hh"
#include "utils.hh"



namespace CarpetIOF5 {
  
  namespace F5 {
    
    using std::numeric_limits;
    using std::setprecision;
    using std::ostringstream;
    
    
    
    timestep_t::
    timestep_t (file_t & file,
                CCTK_REAL const time,
                char const * const name)
      : m_file (file),
        m_time (time)
    {
      // Construct a group name from the simulation time
      ostringstream buf;
      if (name != 0)
      {
        // Use the name argument if it is present
        buf << name;
      }
      else
      {
        // Create a string from the time without losing information
        int const precision = numeric_limits<CCTK_REAL>::digits10 + 2;
        buf << setprecision (precision) << "t=" << time;
      }
      m_name = buf.str();
      
      m_hdf5_timestep
        = open_or_create_group (m_file.get_hdf5_file(), m_name.c_str());
      assert (m_hdf5_timestep >= 0);
      write_or_check_attribute (m_hdf5_timestep, "time", time);
      
      if (CCTK_IsFunctionAliased ("UniqueSimulationID")) {
        cGH const * const cctkGH = get_file().get_cctkGH();
        char const * const job_id
          = static_cast<char const *> (UniqueSimulationID (cctkGH));
        write_or_check_attribute (m_hdf5_timestep, "simulation id", job_id);
      }
      
      assert (invariant());
    }
    
    
    
    timestep_t::
    ~ timestep_t()
    {
      herr_t const herr = H5Gclose (m_hdf5_timestep);
      assert (not herr);
    }
    
    
      
    file_t & timestep_t::
    get_file ()
      const
    {
      return m_file;
    }
    
    
    
    CCTK_REAL timestep_t::
    get_time ()
      const
    {
      return m_time;
    }
    
    
    
    hid_t timestep_t::
    get_hdf5_timestep()
      const
    {
      return m_hdf5_timestep;
    }
    
    
    
    void timestep_t::
    get_link_destination (string & filename,
                          string & objectname)
      const
    {
      static bool initialised = false;
      static string l_filename;
      static string l_objectname;
      if (not initialised)
      {
        initialised = true;
        get_file().get_link_destination (l_filename, l_objectname);
        l_objectname += string ("/") + m_name;
      }
      filename = l_filename;
      objectname = l_objectname;
    }
    
    
    
    bool timestep_t::
    invariant()
      const
    {
      return m_hdf5_timestep >= 0;
    }
    
  } // namespace F5

} // namespace CarpetIOF5