www.cemf.ir
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 
25 #include "types.hpp"
26 #include "VectorSingle.hpp"
27 #include "wordVectorHost.hpp"
28 #include "Vector.hpp"
29 #include "streams.hpp"
30 
31 namespace pFlow
32 {
33 
34 
35 template<class T, class MemorySpace = void>
36 class Field
37 :
38  public VectorSingle<T, MemorySpace>
39 {
40 public:
41 
43 
45 
47 
49 
51 
52  using iterator = typename VectorType::iterator;
53 
55 
56  using reference = typename VectorType::reference;
57 
59 
61 
62  using pointer = typename VectorType::pointer;
63 
65 
66 
67 private:
68 
69  static const inline word FKey = "value";
70 
71  const word fieldKey_ = FKey;
72 
73 public:
74 
77 
79 
82  :
83  VectorType()
84  {}
85 
86  Field(const word& name)
87  :
89  {}
90 
92  Field(const word& name, const word& fieldKey)
93  :
96  {}
97 
99  Field(const word& name, const word& fieldKey, size_t len)
100  :
101  VectorType(name, len),
103  {}
104 
105 
108  Field(const word& name, const word& fieldKey, size_t len, const T& val)
109  :
110  VectorType(name, len, val),
112  {}
113 
114  Field(const word& name, const word& fieldKey, size_t capacity, size_t len, const T& val)
115  :
116  VectorType(name, len, len, RESERVE()),
118  {
119  VectorType::fill(val);
120  }
121 
123  Field(const word& name, const word& fieldKey, size_t capacity, size_t len, RESERVE)
124  :
125  VectorType(name, capacity, len, RESERVE()),
127  {}
128 
130  Field(const word& fieldKey, const Vector<T>& vec)
131  :
132  VectorType(vec.name(), vec.vectorField()),
134  {}
135 
137  Field(const word& name, const word& fieldKey, const Vector<T>& vec)
138  :
139  VectorType(name, vec.vectorField()),
141  {}
142 
144  Field(const word& name, const word& fieldKey, const std::vector<T>& vec)
145  :
146  VectorType(name, vec),
148  {}
149 
151  Field(const word& name, const word& fieldKey, const FieldType& src):
152  VectorType(name, src),
154  {}
155 
157  Field(const FieldType&) = default;
158 
162  {
163  if(&rhs == this) return *this;
165  return *this;
166  }
167 
169  Field(FieldType&&) = default;
170 
172  FieldType& operator = (FieldType&&) = default;
173 
175 
177  word fieldKey()const
178  {
179  return fieldKey_;
180  }
181 
182  word name()const
183  {
184  return VectorType::name();
185  }
186 
187 
188  void fillField(rangeU32 span, const T& val)
189  {
190  this->fill(span, val);
191  }
192 
193  void fillField(const T& val)
194  {
195  this->fill(val);
196  }
197 
199 
200  bool read(iIstream& is);
201 
202  bool write(iOstream& os)const;
203 
204 
205  bool read(iIstream& is, const IOPattern& iop, bool resume = false);
206 
207 
208  bool write(iOstream& os, const IOPattern& iop )const;
209 
210 };
211 
212 
213 template<class T, class MemorySpace>
215 {
216  if( !ifld.read(is, IOPattern::MasterProcessorOnly) )
217  {
218  ioErrorInFile (is.name(), is.lineNumber());
219  fatalExit;
220  }
221  return is;
222 }
223 
224 template<typename T, typename MemorySpace>
226 {
227 
229  {
230  ioErrorInFile(os.name(), os.lineNumber());
231  fatalExit;
232  }
233 
234  return os;
235 }
236 
237 
238 }
239 
240 #include "Field.cpp"
241 
242 
243 #endif //__Field_hpp__
pFlow::span
Definition: span.hpp:31
pFlow::VectorSingle::fill
INLINE_FUNCTION_H void fill(const T &val)
Fill the range [0,size) with val.
Definition: VectorSingle.cpp:365
pFlow::VectorSingle::const_pointer
const T * const_pointer
Definition: VectorSingle.hpp:66
wordVectorHost.hpp
pFlow::VectorSingle::iterator
T * iterator
Definition: VectorSingle.hpp:54
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len)
Construct a field with name and fieldKey and specified len.
Definition: Field.hpp:99
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::Field::fillField
void fillField(const T &val)
Definition: Field.hpp:193
types.hpp
pFlow::Field::fieldKey_
const word fieldKey_
Definition: Field.hpp:71
pFlow::Field::Field
Field()
construct an empty Filed with default fieldKey
Definition: Field.hpp:81
pFlow::Field::fieldKey
word fieldKey() const
return field key
Definition: Field.hpp:177
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::Field::read
bool read(iIstream &is)
Definition: Field.cpp:23
pFlow::Field::FieldType
Field< T, MemorySpace > FieldType
Definition: Field.hpp:44
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t capacity, size_t len, RESERVE)
Construct a field with name, fieldKey, capacity and len.
Definition: Field.hpp:123
pFlow::Field::FKey
static const word FKey
Definition: Field.hpp:69
pFlow::Field
Definition: Field.hpp:36
pFlow::Field::name
word name() const
Definition: Field.hpp:182
pFlow::VectorSingle::memory_space
typename viewType::memory_space memory_space
Definition: VectorSingle.hpp:74
pFlow::Field< uint32x3 >::const_pointer
typename VectorType::const_pointer const_pointer
Definition: Field.hpp:64
pFlow::VectorSingle::pointer
T * pointer
Definition: VectorSingle.hpp:64
pFlow
Definition: demGeometry.hpp:27
pFlow::VectorSingle::execution_space
typename viewType::execution_space execution_space
Definition: VectorSingle.hpp:76
pFlow::VectorSingle::name
INLINE_FUNCTION_H word name() const
Name of the vector.
Definition: VectorSingle.cpp:290
RESERVE
Definition: Vector.hpp:40
pFlow::VectorSingle::reference
T & reference
Definition: VectorSingle.hpp:58
pFlow::Field::write
bool write(iOstream &os) const
Definition: Field.cpp:95
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::Field< uint32x3 >::value_type
typename VectorType::value_type value_type
Definition: Field.hpp:60
pFlow::IOPattern::AllProcessorsDifferent
@ AllProcessorsDifferent
Definition: IOPattern.hpp:57
VectorSingle.hpp
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len, const T &val)
Construct a field with name, fieldKey and set length to len and value to val.
Definition: Field.hpp:108
pFlow::Field::TypeInfoTemplateNV111
TypeInfoTemplateNV111("Field", T, VectorType::memoerySpaceName())
type info
pFlow::VectorSingle::const_iterator
const T * const_iterator
Definition: VectorSingle.hpp:56
pFlow::Field< uint32x3 >::const_reference
typename VectorType::const_reference const_reference
Definition: Field.hpp:58
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::Field< uint32x3 >::const_iterator
typename VectorType::const_iterator const_iterator
Definition: Field.hpp:54
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)
Construct a field with fieldKey and Vector vec.
Definition: Field.hpp:130
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::Range< uint32 >
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
streams.hpp
pFlow::Field::operator=
FieldType & operator=(const FieldType &rhs)
Copy assignment, name and fieldKey on the left hand side are preserved.
Definition: Field.hpp:161
pFlow::Field< uint32x3 >::pointer
typename VectorType::pointer pointer
Definition: Field.hpp:62
pFlow::VectorSingle::memoerySpaceName
static constexpr const char * memoerySpaceName()
Name of the memory space.
Definition: VectorSingle.hpp:469
Field.cpp
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t capacity, size_t len, const T &val)
Definition: Field.hpp:114
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::VectorSingle< T, void >::capacity
INLINE_FUNCTION_H uint32 capacity() const
Definition: VectorSingle.cpp:304
pFlow::Field::Field
Field(const word &name, const word &fieldKey)
Construct an empty field with name and fieldKey.
Definition: Field.hpp:92
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::Field< uint32x3 >::iterator
typename VectorType::iterator iterator
Definition: Field.hpp:52
pFlow::Field< uint32x3 >::memory_space
typename VectorType::memory_space memory_space
Definition: Field.hpp:48
pFlow::Vector
Definition: Vector.hpp:48
pFlow::VectorSingle::operator=
VectorSingle & operator=(const VectorSingle &rhs)
Copy assignment (perform deep copy from rhs to *this)
Definition: VectorSingle.cpp:204
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const FieldType &src)
Copy construct with new name and fieldkey.
Definition: Field.hpp:151
pFlow::VectorSingle::const_reference
const T & const_reference
Definition: VectorSingle.hpp:60
pFlow::IOPattern::MasterProcessorOnly
@ MasterProcessorOnly
Definition: IOPattern.hpp:54
pFlow::Field::Field
Field(const word &name)
Definition: Field.hpp:86
Vector.hpp
pFlow::Field< uint32x3 >::execution_space
typename VectorType::execution_space execution_space
Definition: Field.hpp:50
pFlow::Field< uint32x3 >::reference
typename VectorType::reference reference
Definition: Field.hpp:56
pFlow::Field::fillField
void fillField(rangeU32 span, const T &val)
Definition: Field.hpp:188
pFlow::VectorSingle::value_type
T value_type
Definition: VectorSingle.hpp:62
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const std::vector< T > &vec)
Construct a field with name and fieldKey and std::vector.
Definition: Field.hpp:144
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const Vector< T > &vec)
Construct a field with name, fieldKey and Vector vec.
Definition: Field.hpp:137