Field.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __Field_hpp__
22 #define __Field_hpp__
23 
24 #include "VectorSingle.hpp"
25 #include "vocabs.hpp"
26 
27 namespace pFlow
28 {
29 
30 
31 
32 template<template<class, class> class VectorField, class T, class PropType=void>
33 class Field
34 :
35  public VectorField<T, PropType>
36 {
37 public:
38 
39 
40  using VectorType = VectorField<T,PropType>;
41 
43 
44  using iterator = typename VectorType::iterator;
45 
47 
48  using reference = typename VectorType::reference;
49 
51 
52  using valueType = typename VectorType::valueType;
53 
54  using pointer = typename VectorType::pointer;
55 
57 
58 
59 protected:
60 
61  static const inline word FKey = "value";
62 
63  const word fieldKey_ = FKey;
64 
65  bool readUniform( iIstream& is, size_t len, bool readLength = true);
66 
67  bool readNonUniform( iIstream& is, size_t len);
68 
69 public:
70 
71  // - type info
72  TypeInfoTemplateNV2("Field", T, VectorType::memoerySpaceName());
73 
75 
76  // construct an empty Filed with default fieldKey
78  :
79  VectorType()
80  {}
81 
82  // construct an empty Field with fieldKey
84  :
85  VectorType(),
87  {}
88 
89  // construct an empty field with name and fieldKey
90  Field(const word& name, const word& fieldKey)
91  :
92  VectorType(name),
94  {}
95 
96  // construct an empty Filed with default fieldKey
97  Field(size_t len)
98  :
99  VectorType(len)
100  {}
101 
102  // construct an empty Field with fieldKey
103  Field(const word& fieldKey, size_t len)
104  :
105  VectorType(len),
107  {}
108 
109  // construct an empty field with name and fieldKey
110  Field(const word& name, const word& fieldKey, size_t len)
111  :
112  VectorType(name, len),
114  {}
115 
116  // construct an empty Filed with default fieldKey and set vector to val
117  Field(size_t len, const T& val)
118  :
119  VectorType(len, val)
120  {}
121 
122  // construct an empty Field with fieldKey and set vector to val
123  Field(const word& fieldKey, size_t len, const T& val)
124  :
125  VectorType(len, val),
127  {}
128 
129  // construct an empty field with name and fieldKey and set vector to val
130  Field(const word& name, const word& fieldKey, size_t len, const T& val)
131  :
132  VectorType(name, len, val),
134  {}
135 
136  // construct a field with capacity and len and default fieldKey
137  Field(size_t capacity, size_t len, RESERVE)
138  :
139  VectorType(capacity, len, RESERVE())
140  {}
141 
142  // construct an empty Field with fieldKey
143  Field(const word& fieldKey, size_t capacity, size_t len, RESERVE)
144  :
145  VectorType(capacity, len, RESERVE()),
147  {}
148 
149  // construct an empty field with name and fieldKey
150  Field(const word& name, const word& fieldKey, size_t capacity, size_t len, RESERVE)
151  :
152  VectorType(name, capacity, len, RESERVE()),
154  {}
155 
156  // construct with vec and default fieldKey
157  Field(const Vector<T>& vec)
158  :
159  VectorType(vec)
160  {}
161 
162  // construct an empty Field with fieldKey
163  Field(const word& fieldKey, const Vector<T>& vec)
164  :
165  VectorType(vec),
167  {}
168 
169  // construct an empty field with name and fieldKey
170  Field(const word& name, const word& fieldKey, const Vector<T>& vec)
171  :
172  VectorType(name, vec),
174  {}
175 
176 
177  // - copy construct with new name and fieldkey
178  Field(const word& name, const word& fieldKey, const FieldType& src):
179  VectorType(name, src),
181  {}
182 
183  // - default copy constructor
184  Field(const FieldType&) = default;
185 
186  // - default copy assignment
187  FieldType& operator = (const FieldType&) = default;
188 
189  // - no move constructor
190  Field(FieldType&&) = delete;
191 
192  // - no move assignment
193  FieldType& operator = (FieldType&&) = delete;
194 
195  // - clone as a uniquePtr
198  {
199  return makeUnique<FieldType>(*this);
200  }
201 
202  // - clone as a raw pointer
205  {
206  return new FieldType(*this);
207  }
208 
210 
211  const word& fieldKey()const
212  {
213  return fieldKey_;
214  }
215 
217  bool readField(iIstream& is, const size_t len, bool readLength = true);
218 
219 
220  bool readField(iIstream& is );
221 
222 
223  bool writeField(iOstream& os)const;
224 
225 
226  bool read(iIstream& is)
227  {
228  return readField(is);
229  }
230 
231  bool write(iOstream& os)const
232  {
233  return writeField(os);
234  }
235 
236 
237 };
238 
239 
240 template<template<class, class> class VectorField, class T, class PropType>
242 {
243  if( !ifld.readField(is) )
244  {
245  ioErrorInFile (is.name(), is.lineNumber());
246  fatalExit;
247  }
248  return is;
249 }
250 
251 template<template<class, class> class VectorField, class T, class PropType>
253 {
254 
255  if( !ofld.writeField(os) )
256  {
257  ioErrorInFile(os.name(), os.lineNumber());
258  fatalExit;
259  }
260 
261  return os;
262 }
263 
264 
265 }
266 
267 #include "Field.cpp"
268 
269 
270 #endif //__Field_hpp__
pFlow::Field::Field
Field(const Vector< T > &vec)
Definition: Field.hpp:157
pFlow::VectorDual< int8, void >::iterator
int8 * iterator
Definition: VectorDual.hpp:51
pFlow::Field::TypeInfoTemplateNV2
TypeInfoTemplateNV2("Field", T, VectorType::memoerySpaceName())
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len)
Definition: Field.hpp:110
pFlow::Field< VectorDual, int8 >::constReference
typename VectorType::constReference constReference
Definition: Field.hpp:50
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::Field::fieldKey_
const word fieldKey_
Definition: Field.hpp:63
pFlow::Field::Field
Field()
Definition: Field.hpp:77
pFlow::Field::Field
Field(const word &fieldKey, size_t len, const T &val)
Definition: Field.hpp:123
pFlow::Field< VectorDual, int8 >::constPointer
typename VectorType::constPointer constPointer
Definition: Field.hpp:56
pFlow::Field::clonePtr
INLINE_FUNCTION_H FieldType * clonePtr() const
Definition: Field.hpp:204
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Field::read
bool read(iIstream &is)
Definition: Field.hpp:226
pFlow::Field::Field
Field(size_t len)
Definition: Field.hpp:97
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t capacity, size_t len, RESERVE)
Definition: Field.hpp:150
pFlow::Field::FKey
static const word FKey
Definition: Field.hpp:61
pFlow::Field::FieldType
Field< VectorField, T, PropType > FieldType
Definition: Field.hpp:42
pFlow::Field
Definition: Field.hpp:33
pFlow
Definition: demComponent.hpp:28
RESERVE
Definition: Vector.hpp:38
pFlow::VectorDual< int8, void >::pointer
int8 * pointer
Definition: VectorDual.hpp:61
pFlow::Field::readNonUniform
bool readNonUniform(iIstream &is, size_t len)
Definition: Field.cpp:62
pFlow::Field::Field
Field(const word &fieldKey, size_t len)
Definition: Field.hpp:103
pFlow::Field::write
bool write(iOstream &os) const
Definition: Field.hpp:231
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::VectorDual< int8, void >
pFlow::VectorDual< int8, void >::valueType
int8 valueType
Definition: VectorDual.hpp:59
pFlow::VectorDual< int8, void >::reference
int8 & reference
Definition: VectorDual.hpp:55
VectorSingle.hpp
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len, const T &val)
Definition: Field.hpp:130
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::Field::Field
Field(const word &fieldKey, const Vector< T > &vec)
Definition: Field.hpp:163
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::VectorDual< int8, void >::constIterator
const int8 * constIterator
Definition: VectorDual.hpp:53
pFlow::VectorDual< int8, void >::constReference
const int8 & constReference
Definition: VectorDual.hpp:57
pFlow::Field::Field
Field(const word &fieldKey)
Definition: Field.hpp:83
pFlow::Field::fieldKey
const word & fieldKey() const
Definition: Field.hpp:211
pFlow::Field::readField
bool readField(iIstream &is, const size_t len, bool readLength=true)
Definition: Field.cpp:104
pFlow::Field::Field
Field(const word &fieldKey, size_t capacity, size_t len, RESERVE)
Definition: Field.hpp:143
pFlow::Field::Field
Field(size_t len, const T &val)
Definition: Field.hpp:117
pFlow::Field< VectorDual, int8 >::pointer
typename VectorType::pointer pointer
Definition: Field.hpp:54
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
Field.cpp
pFlow::Field::Field
Field(size_t capacity, size_t len, RESERVE)
Definition: Field.hpp:137
pFlow::Field::readUniform
bool readUniform(iIstream &is, size_t len, bool readLength=true)
Definition: Field.cpp:23
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::Field< VectorDual, int8 >::valueType
typename VectorType::valueType valueType
Definition: Field.hpp:52
pFlow::VectorDual< int8, void >::constPointer
const int8 * constPointer
Definition: VectorDual.hpp:63
pFlow::Field::Field
Field(const word &name, const word &fieldKey)
Definition: Field.hpp:90
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::Field< VectorDual, int8 >::iterator
typename VectorType::iterator iterator
Definition: Field.hpp:44
pFlow::Field::operator=
FieldType & operator=(const FieldType &)=default
pFlow::Field::writeField
bool writeField(iOstream &os) const
Definition: Field.cpp:163
vocabs.hpp
pFlow::Vector
Definition: Vector.hpp:46
pFlow::Field< VectorDual, int8 >::constIterator
typename VectorType::constIterator constIterator
Definition: Field.hpp:46
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const FieldType &src)
Definition: Field.hpp:178
pFlow::Field< VectorDual, int8 >::reference
typename VectorType::reference reference
Definition: Field.hpp:48
pFlow::Field::clone
INLINE_FUNCTION_H uniquePtr< FieldType > clone() const
Definition: Field.hpp:197
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const Vector< T > &vec)
Definition: Field.hpp:170