Schnek
hdfdiagnostic.hpp
1 /*
2  * hdfdiagnostic.hpp
3  *
4  * Created on: 23 Oct 2012
5  * Author: hschmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef SCHNEK_HDFDIAGNOSTIC_HPP_
28 #define SCHNEK_HDFDIAGNOSTIC_HPP_
29 
30 #include "../schnek_config.hpp"
31 #ifdef SCHNEK_HAVE_HDF5
32 
33 #include "../grid/grid.hpp"
34 #include "diagnostic.hpp"
35 
36 #include <hdf5.h>
37 
38 namespace schnek {
39 
40 template<typename FieldType>
41 struct GridContainer
42 {
43  FieldType *grid;
44  typename FieldType::IndexType global_min;
45  typename FieldType::IndexType global_max;
46  typename FieldType::IndexType local_min;
47  typename FieldType::IndexType local_max;
48 };
49 
55 class HdfStream {
56  protected:
58  hid_t file_id;
59 
61  herr_t status;
62 
64  std::string blockname;
66  int sets_count;
67 
69  bool active;
70  bool activeModified;
71 
72  public:
74  HdfStream();
76  HdfStream(const HdfStream&);
78  virtual ~HdfStream();
79 
81  virtual int open(const char*)=0;
82 
84  virtual void close();
85 
87  virtual bool good() const;
88 
89  void setBlockName(std::string blockname_);
91  HdfStream& operator = (const HdfStream&);
92 
93  void setActive(bool active_) { active = active_; activeModified = true; }
94 
95  protected:
96  std::string getNextBlockName();
97 
98 #if defined (H5_HAVE_PARALLEL) && defined (SCHNEK_USE_HDF_PARALLEL)
99  void makeMPIGroup();
100 
101  MPI_Comm mpiComm;
102  bool commSet;
103 #endif
104 
105 };
106 
107 
109 class HdfIStream : public HdfStream {
110  public:
112  HdfIStream();
113 
115  HdfIStream(const HdfIStream&);
116 
118  HdfIStream(const char* fname);
119 
121  int open(const char*);
122 
124  template<typename FieldType>
125  void readGrid(GridContainer<FieldType> &g);
126 };
127 
128 
130 class HdfOStream : public HdfStream {
131  private:
132  hid_t dxpl_id;
133  public:
135  HdfOStream();
136 
138  HdfOStream(const HdfOStream&);
139 
141  HdfOStream(const char* fname);
142 
144  int open(const char*);
145 
147  template<typename FieldType>
148  void writeGrid(GridContainer<FieldType> &g);
149 };
150 
151 template<typename TYPE>
152 struct H5DataType{
153  static const hid_t type;
154 };
155 
156 template<typename Type, typename PointerType = boost::shared_ptr<Type>, class DiagnosticType = IntervalDiagnostic >
157 class HDFGridDiagnostic : public SimpleDiagnostic<Type, PointerType, DiagnosticType> {
158  protected:
159  HdfOStream output;
160  GridContainer<Type> container;
161  protected:
162  typedef typename Type::IndexType IndexType;
163  void open(const std::string &);
164  void write();
165  void close();
166  void init();
167  virtual IndexType getGlobalMin() = 0;
168  virtual IndexType getGlobalMax() = 0;
169  public:
170  virtual ~HDFGridDiagnostic() {}
171 };
172 
173 } // namespace schnek
174 
175 #include "hdfdiagnostic.t"
176 
177 #endif
178 
179 #endif // SCHNEK_HDFDIAGNOSTIC_HPP_
Definition: algo.hpp:30