Chombo + EB  3.0
IrregTag.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 // ANAG, LBNL
12 
13 #ifndef _IRREGTAG_H_
14 #define _IRREGTAG_H_
15 
16 #include "Vector.H"
17 #include "VolIndex.H"
18 #include "IntVectSet.H"
19 #include <list>
20 #include "SPMD.H"
21 #include "NamespaceHeader.H"
22 
23 class HDF5Handle;
24 class IrregTag;
25 
26 /**
27  class used as return type of IrregTag access functions to
28  encapsulate the implementation. Also provide a lightweight
29  return object.
30 */
31 
32 class TagSet
33 {
34 public:
36  :
37  index(0),
38  list(NULL),
39  value(NULL)
40  {
41  }
42 
43  TagSet(const Vector<int>* l, const Vector<double>* d);
44 
45  void begin()
46  {
47  index=0;
48  }
49 
50  bool ok() const
51  {
52  return index < list->size();
53  }
54 
55  void operator++()
56  {
57  index++;
58  }
59 
60  int operator()() const
61  {
62  return (*list)[index];
63  }
64 
65  double val() const
66  {
67  return (*value)[index];
68  }
69 
70 private:
71  int index;
72  const Vector<int>* list;
74  friend class IrregTag;
75 };
76 
77 class IrregTag
78 {
79 public:
80 
81  /**
82  */
83  IrregTag();
84 
85  /**
86  */
87  ~IrregTag();
88 
89  /*==============================*/
90 
91  /**
92  /name I/O routines
93  */
94  /*@{*/
95 
96  void read(const std::string& a_filename);
97  void read(HDF5Handle& handle);
98 
99  /** IrregTag class must be closed before writing
100  @see close
101  */
102  void write(const std::string& a_filename);
103 
104  /** IrregTag class must be closed before writing
105  @see close
106  */
107  void write(HDF5Handle& handle);
108  /*@}*/
109 
110  /*==============================*/
111 
112  /**
113  /name Construction routines
114  */
115  /*@{*/
116 
117  void setTags(const VolIndex& a_vol, const Vector<int>& tags,
118  const Vector<double>& values);
119 
120  /** Called when no more calls to setTags will be performed.
121  */
122  void close();
123 
124  /*@}*/
125 
126  /*==============================*/
127 
128  /**
129  /name Access routines
130 
131  IrregTag object must be 'closed' before these operations can
132  be performed.
133  @see close()
134  */
135  /*@{*/
136  TagSet tags(const VolIndex& a_index) const ;
137 
138  int numVol() const ;
139 
140  TagSet tags(int a_tagsetIndex) const;
141 
142  /*@}*/
143 
144 private:
145 
146  class Entry
147  {
148  public:
152 
154  {
155  }
156 
158  const Vector<int>& tags,
159  const Vector<double>& values)
160  :
161  m_index(index),
162  m_tags(tags),
163  m_values(values)
164  {
165  }
166 
167  void define(const VolIndex& index,
168  const Vector<int>& tags,
169  const Vector<double>& values)
170  {
171  m_index = index;
172  m_tags = tags;
173  m_values = values;
174  }
175 
176  bool operator < (const Entry& rhs) const
177  {
178  return m_index < rhs.m_index;
179  }
180 
181  int linearSize() const
182  {
183  return m_index.linearSize() + CH_XD::linearListSize(m_tags) + CH_XD::linearListSize(m_values);
184  }
185 
186  void linearOut(void* const a_outBuf) const
187  {
188  char* buf = (char*)a_outBuf;
189  buf+=m_index.linearSize();
190  m_index.linearOut(a_outBuf);
191  CH_XD::linearOut(buf, m_tags);
192  buf += CH_XD::linearSize(m_tags);
193  CH_XD::linearOut(buf, m_values);
194  }
195 
196  void linearIn(void* const inBuf)
197  {
198  const char* buf = (const char*)inBuf;
199  buf+=m_index.linearSize();
200  m_index.linearIn(inBuf);
201  CH_XD::linearIn(m_tags, buf);
202  buf += CH_XD::linearSize(m_tags);
203  CH_XD::linearIn(m_values, buf);
204 
205  }
206  };
207 
208  bool m_closed;
210  std::list<Entry> m_accumulator;
212 };
213 
214 #include "NamespaceFooter.H"
215 #endif
void operator++()
Definition: IrregTag.H:55
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
bool m_closed
Definition: IrregTag.H:208
bool ok() const
Definition: IrregTag.H:50
TagSet()
Definition: IrregTag.H:35
const Vector< int > * list
Definition: IrregTag.H:72
int linearSize() const
Definition: IrregTag.H:181
void begin()
Definition: IrregTag.H:45
VolIndex m_index
Definition: IrregTag.H:149
Vector< int > m_tags
Definition: IrregTag.H:150
Entry()
Definition: IrregTag.H:153
IntVectSet m_ivs
Definition: IrregTag.H:209
void define(const VolIndex &index, const Vector< int > &tags, const Vector< double > &values)
Definition: IrregTag.H:167
double val() const
Definition: IrregTag.H:65
Definition: IrregTag.H:146
void linearIn(const void *const inBuf)
void linearOut(void *const a_outBuf) const
const Vector< double > * value
Definition: IrregTag.H:73
Entry(const VolIndex &index, const Vector< int > &tags, const Vector< double > &values)
Definition: IrregTag.H:157
void linearOut(void *const a_outBuf, const T &inputT)
Definition: SPMDI.H:32
bool operator<(const FaceIndex &f1, const FaceIndex &f2)
Definition: FaceIndex.H:204
int operator()() const
Definition: IrregTag.H:60
int linearSize(const T &inputT)
Definition: SPMDI.H:20
Definition: IrregTag.H:77
size_t size() const
Definition: Vector.H:177
Vector< Entry > m_set
Definition: IrregTag.H:211
int write(HDF5Handle &a_handle, const BoxLayout &a_layout, const std::string &name="boxes")
writes BoxLayout to HDF5 file.
std::list< Entry > m_accumulator
Definition: IrregTag.H:210
int linearSize() const
void linearIn(void *const inBuf)
Definition: IrregTag.H:196
Definition: IrregTag.H:32
void linearOut(void *const a_outBuf) const
Definition: IrregTag.H:186
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:267
int linearListSize(const Vector< T > &a_input)
Definition: SPMDI.H:287
Volume of Fluid Index.
Definition: VolIndex.H:31
friend class IrregTag
Definition: IrregTag.H:74
Vector< double > m_values
Definition: IrregTag.H:151
void linearIn(T &a_outputT, const void *const inBuf)
Definition: SPMDI.H:26
int index
Definition: IrregTag.H:71
void read(T &item, Vector< Vector< char > > &a_allocatedBuffers, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:47