Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
DataFieldInfo.h
Go to the documentation of this file.
1 //===-- serialbox/core/frontend/stella/DataFieldInfo.h ------------------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
15 #ifndef SERIALBOX_CORE_FRONTEND_STELLA_DATAFIELDINFO_H
16 #define SERIALBOX_CORE_FRONTEND_STELLA_DATAFIELDINFO_H
17 
23 
24 namespace serialbox {
25 
26 namespace stella {
27 
32 public:
34  DataFieldInfo();
35 
37  DataFieldInfo(const boost::shared_ptr<FieldMetainfoImpl>& fieldMetainfoImpl);
38 
40  DataFieldInfo(const DataFieldInfo& other);
41 
43  DataFieldInfo& operator=(const DataFieldInfo& other);
44 
50  template <typename TDataField>
51  void Init(const TDataField& dataField) {
52  Init(dataField, dataField.name());
53  }
54 
61  template <typename TDataField>
62  void Init(const TDataField& dataField, std::string name) {
63  // Get the calculation domain
64  IJKSize domain;
65  domain.Init(dataField.calculationDomain().iSize(), dataField.calculationDomain().jSize(),
66  dataField.calculationDomain().kSize());
67 
68  IJKSize size;
69  size.Init(dataField.storage().allocatedSize().iSize(),
70  dataField.storage().allocatedSize().jSize(),
71  dataField.storage().allocatedSize().kSize());
72 
73  // Get the size of the halo
75  boundary.Init(dataField.boundary().iMinusOffset(), dataField.boundary().iPlusOffset(),
76  dataField.boundary().jMinusOffset(), dataField.boundary().jPlusOffset(),
77  dataField.boundary().kMinusOffset(), dataField.boundary().kPlusOffset());
78 
79  // Workaround for boundary() not returning what it should
80  const bool haloInI = !(size.iSize() <= domain.iSize());
81  const bool haloInJ = !(size.jSize() <= domain.jSize());
82  const bool haloInK = !(size.kSize() <= domain.kSize());
83  const int iMinus = haloInI ? -boundary.iMinusOffset() : 0;
84  const int iPlus = haloInI ? boundary.iPlusOffset() : 0;
85  const int jMinus = haloInJ ? -boundary.jMinusOffset() : 0;
86  const int jPlus = haloInJ ? boundary.jPlusOffset() : 0;
87  const int kMinus = haloInK ? -boundary.kMinusOffset() : 0;
88  const int kPlus = haloInK ? boundary.kPlusOffset() : 0;
89 
90  // Delegate the initialization
91  Init(name, type_name<typename TDataField::ValueType>(), sizeof(typename TDataField::ValueType),
92  dataField.storage().rank(), size.iSize(), size.jSize(), size.kSize(), 1, iMinus, iPlus,
93  jMinus, jPlus, kMinus, kPlus, 0, 0);
94  }
95 
116  void Init(std::string name, std::string type, int bytesPerElement, int rank, int iSize, int jSize,
117  int kSize, int lSize, int iMinusHalo, int iPlusHalo, int jMinusHalo, int jPlusHalo,
118  int kMinusHalo, int kPlusHalo, int lMinusHalo, int lPlusHalo);
119 
121  const MetainfoSet& metainfo() const { return metainfo_; }
122 
124  std::string name() const;
125 
127  std::string type() const;
128 
130  int dataSize() const { return bytesPerElement() * iSize() * jSize() * kSize() * lSize(); }
131 
133  int bytesPerElement() const;
134 
136  int rank() const;
137 
139  int iSize() const;
140 
142  int jSize() const;
143 
145  int kSize() const;
146 
148  int lSize() const;
149 
151  int iMinusHaloSize() const;
152 
154  int iPlusHaloSize() const;
155 
157  int jMinusHaloSize() const;
158 
160  int jPlusHaloSize() const;
161 
163  int kMinusHaloSize() const;
164 
166  int kPlusHaloSize() const;
167 
169  int lMinusHaloSize() const;
170 
172  int lPlusHaloSize() const;
173 
175  int fieldLength() const { return bytesPerElement() * iSize() * jSize() * kSize() * lSize(); }
176 
179  IJKSize size;
180  size.Init(iSize() - iMinusHaloSize() - iPlusHaloSize(),
183  return size;
184  }
185 
187  IJKSize size() const {
188  IJKSize size;
189  size.Init(iSize(), jSize(), kSize());
190  return size;
191  }
192 
198  return boundary;
199  }
200 
202  template <typename ValueType>
203  void AddMetainfo(const std::string& key, const ValueType& value) {
204  metainfo_.AddMetainfo(key, value);
205  }
206 
208  bool operator==(const DataFieldInfo& other) const;
209 
211  inline bool operator!=(const DataFieldInfo& other) const { return !(*this == other); }
212 
214  std::string ToString() const;
215 
217  void setImpl(const boost::shared_ptr<FieldMetainfoImpl>& fieldMetainfoImpl);
218 
220  boost::shared_ptr<FieldMetainfoImpl>& getImpl();
221  const boost::shared_ptr<FieldMetainfoImpl>& getImpl() const;
222 
223 private:
224  boost::shared_ptr<FieldMetainfoImpl> fieldMetainfoImpl_;
225  MetainfoSet metainfo_; // Allow refrence access
226 };
227 
228 } // namespace stella
229 
230 } // namespace serialbox
231 
232 #endif
boost::shared_ptr< FieldMetainfoImpl > & getImpl()
Get implementation pointer.
std::string name() const
The field name.
int iSize() const
The size of the field in i-direction, including the halo.
int kPlusHaloSize() const
The size of the halo in positive k-direction.
int kSize() const
The size of the field in k-direction, including the halo.
Information of a data-field.
Definition: DataFieldInfo.h:31
int kMinusOffset() const
Offset in k-minus direction.
Definition: IJKBoundary.h:98
int lSize() const
The size of the field in l-direction, including the halo.
bool operator!=(const DataFieldInfo &other) const
Comparator operator.
int jSize() const
Size in j dimension.
Definition: IJKSize.h:66
bool operator==(const DataFieldInfo &other) const
Comparator operator.
int jPlusOffset() const
Offset in j-plus direction.
Definition: IJKBoundary.h:95
IJKSize size() const
The total storage of the field (calculation domain and boundary)
std::string type() const
The field scalar type.
const MetainfoSet & metainfo() const
Gives read-only access to the metainformation associated with the field.
int dataSize() const
The size of the field data in bytes is returned.
int kMinusHaloSize() const
The size of the halo in negative k-direction.
IJKSize calculationDomain() const
The calculation domain of the field.
Namespace of the STELLA frontend.
Definition: ForwardDecl.h:27
Namespace of the serialbox library.
Definition: Archive.h:25
Meta-information set.
Definition: MetainfoSet.h:36
void Init(const TDataField &dataField)
Initialize with field.
Definition: DataFieldInfo.h:51
int lMinusHaloSize() const
The size of the halo in negative l-direction.
int jMinusOffset() const
Offset in j-minus direction.
Definition: IJKBoundary.h:92
int fieldLength() const
The number of bytes occupied by the field.
int lPlusHaloSize() const
The size of the halo in positive l-direction.
void AddMetainfo(const std::string &key, const ValueType &value)
Add new metainformation.
int jMinusHaloSize() const
The size of the halo in negative j-direction.
void Init(const int iMinusOffset, const int iPlusOffset, const int jMinusOffset, const int jPlusOffset, const int kMinusOffset, const int kPlusOffset)
Init the container.
Definition: IJKBoundary.h:75
int iMinusHaloSize() const
The size of the halo in negative i-direction.
int iPlusHaloSize() const
The size of the halo in positive i-direction.
void Init(const TDataField &dataField, std::string name)
Initializer with field and new name.
Definition: DataFieldInfo.h:62
int kPlusOffset() const
Offset in k-plus direction.
Definition: IJKBoundary.h:101
int bytesPerElement() const
The dimension in bytes of a single element.
DataFieldInfo & operator=(const DataFieldInfo &other)
Assignment operator.
int iSize() const
Size in i dimension.
Definition: IJKSize.h:63
Container for i, j, k Size.
Definition: IJKSize.h:27
IJKBoundary boundary() const
The size of the halo of the field.
void Init(const int iSize, const int jSize, const int kSize)
Init the container.
Definition: IJKSize.h:55
Container for the boundary size.
Definition: IJKBoundary.h:36
std::string ToString() const
Gives a string representation of the object, useful for debugging.
int kSize() const
Size in k dimension.
Definition: IJKSize.h:69
int iPlusOffset() const
Offset in i-plus direction.
Definition: IJKBoundary.h:89
int iMinusOffset() const
Offset in i-minus direction.
Definition: IJKBoundary.h:86
int rank() const
The number of dimensions of the field.
void AddMetainfo(const std::string &key, const int &value)
Add a new key-value pair into the set. The key must not exist yet.
Definition: MetainfoSet.cpp:58
DataFieldInfo()
Default constructor.
void setImpl(const boost::shared_ptr< FieldMetainfoImpl > &fieldMetainfoImpl)
Set implementation pointer.
int jPlusHaloSize() const
The size of the halo in positive j-direction.
int jSize() const
The size of the field in j-direction, including the halo.