pointField.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 __pointField_hpp__
22 #define __pointField_hpp__
23 
24 
25 #include "Field.hpp"
26 #include "pointStructure.hpp"
27 #include "error.hpp"
28 
29 namespace pFlow
30 {
31 
32 
33 
34 template<template<class, class> class VectorField, class T, class MemorySpace=void>
36 :
37  public eventObserver,
38  public Field<VectorField, T, MemorySpace>
39 {
40 public:
41 
43 
45 
47 
48  using iterator = typename FieldType::iterator;
49 
51 
52  using reference = typename FieldType::reference;
53 
55 
56  using valueType = typename FieldType::valueType;
57 
58  using pointer = typename FieldType::pointer;
59 
61 
62 protected:
63 
66 
67  // - value when a new item is added to field
69 
70 
71 public:
72 
73  // - type info
74  TypeInfoTemplateNV2("pointField", T, VectorType::memoerySpaceName());
75 
76 
78 
79  // - construct a field from pointStructure and set defaultValue_ and field value to defVal
80  pointField( const pointStructure& pStruct, const T& defVal, bool subscribe = true);
81 
82  // - construct from iIOEntity, pointStructure and a value
83  pointField( const pointStructure& pStruct, const T& val, const T& defVal, bool subscribe = true);
84 
85  // - construct from another pointField
86  // subscribe to events if true
87  pointField( const pointField& src, bool subscribe);
88 
89 
90  // - copy construct
91  pointField(const pointField& src);
92 
93  // - no move construct
94  pointField(pointField&& src) = delete;
95 
96 
97  // assignment, only assign the VectorField and preserve other parts of this
98  pointField& operator = (const pointField& rhs);
99 
100  // no move assignment
101  pointField& operator = (pointField&&) = delete;
102 
103 
105  {
106  return makeUnique<pointFieldType>(*this);
107  }
108 
109  inline pointFieldType* clonePtr()const
110  {
111  return new pointFieldType(*this);
112  }
113 
115 
116  // - reference to pointStructure
117  inline const pointStructure& pStruct()const {
118  return pStruct_;
119  }
120 
121  // if all points are active
123  bool allActive()const {
124  return pStruct_.allActive();
125  }
126 
127 
129  bool isActive(label i)const {
130  return pStruct_.isActive(i);
131  }
132 
133  const auto& pointFlag()const
134  {
135  return pStruct_.pointFlag();
136  }
137 
139  {
140  return pStruct_.activeRange();
141  }
142 
143  // - update the field if any changes occure in pStruct
144  // for now it checks for deleted points
145  bool update(const eventMessage& msg);
146 
147 
149  bool readPointField(iIstream& is);
150 
151  bool writePointField(iOstream& os)const;
152 
153 
154  bool read(iIstream& is)
155  {
156  return readPointField(is);
157  }
158 
159  bool write(iOstream& os)const
160  {
161  return writePointField(os);
162  }
163 };
164 
165 template<template<class, class> class VectorField, class T, class MemorySpace>
167 {
168  if( !pF.read(is))
169  {
170  ioErrorInFile( is.name(), is.lineNumber() ) <<
171  "error in reading pointField from file. \n";
172  fatalExit;
173  }
174 
175  return is;
176 }
177 
178 template<template<class, class> class VectorField, class T, class MemorySpace>
180 {
181  if(! pF.write(os) )
182  {
183  ioErrorInFile( os.name(), os.lineNumber() )<<
184  "error in writing pointField into file. \n";
185  fatalExit;
186  }
187 
188  return os;
189 }
190 
191 }
192 
193 #include "pointField.cpp"
194 #include "pointFieldAlgorithms.hpp"
195 
196 #endif // __pointField_hpp__
pFlow::pointField::writePointField
bool writePointField(iOstream &os) const
Definition: pointField.cpp:34
pFlow::Field< T, T, void >::constReference
typename VectorType::constReference constReference
Definition: Field.hpp:50
pFlow::eventObserver::subscribe
bool subscribe(const eventSubscriber &subscriber)
Definition: eventObserver.cpp:50
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::eventMessage
Definition: eventMessage.hpp:29
pFlow::pointField::isActive
INLINE_FUNCTION_H bool isActive(label i) const
Definition: pointField.hpp:129
pFlow::pointField::pStruct
const pointStructure & pStruct() const
Definition: pointField.hpp:117
pFlow::pointStructure::pointFlag
FUNCTION_H int8Field_HD & pointFlag()
Definition: pointStructure.cpp:70
pFlow::Field< T, T, void >::constPointer
typename VectorType::constPointer constPointer
Definition: Field.hpp:56
pFlow::pointStructure::activeRange
INLINE_FUNCTION_H range activeRange() const
Definition: pointStructure.hpp:281
pFlow::pointField::TypeInfoTemplateNV2
TypeInfoTemplateNV2("pointField", T, VectorType::memoerySpaceName())
pFlow::pointField::defaultValue_
T defaultValue_
Definition: pointField.hpp:68
pFlow::eventObserver
Definition: eventObserver.hpp:33
pFlow::pointField::read
bool read(iIstream &is)
Definition: pointField.hpp:154
pFlow::Field
Definition: Field.hpp:33
pFlow
Definition: demComponent.hpp:28
pFlow::pointField::pointFieldType
pointField< VectorField, T, MemorySpace > pointFieldType
Definition: pointField.hpp:42
pFlow::pointStructure::isActive
INLINE_FUNCTION_H bool isActive(label i) const
Definition: pointStructure.hpp:287
pFlow::pointStructure::allActive
FUNCTION_H bool allActive() const
Definition: pointStructure.cpp:228
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::pointField::clonePtr
pointFieldType * clonePtr() const
Definition: pointField.hpp:109
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::pointField::write
bool write(iOstream &os) const
Definition: pointField.hpp:159
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField.hpp:138
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::pointField::allActive
INLINE_FUNCTION_H bool allActive() const
Definition: pointField.hpp:123
pFlow::pointField::readPointField
bool readPointField(iIstream &is)
Definition: pointField.cpp:24
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::Field< T, T, void >::pointer
typename VectorType::pointer pointer
Definition: Field.hpp:54
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
Field.hpp
pFlow::pointField::clone
uniquePtr< pointFieldType > clone() const
Definition: pointField.hpp:104
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::Field< T, T, void >::valueType
typename VectorType::valueType valueType
Definition: Field.hpp:52
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::pointField::operator=
pointField & operator=(const pointField &rhs)
Definition: pointField.cpp:99
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::Field< T, T, void >::iterator
typename VectorType::iterator iterator
Definition: Field.hpp:44
pointField.cpp
pFlow::pointField::update
bool update(const eventMessage &msg)
Definition: pointField.cpp:111
pFlow::pointField::pointField
pointField(const pointStructure &pStruct, const T &defVal, bool subscribe=true)
Definition: pointField.cpp:45
pointFieldAlgorithms.hpp
pFlow::Field< T, T, void >::constIterator
typename VectorType::constIterator constIterator
Definition: Field.hpp:46
pointStructure.hpp
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::pointField::pStruct_
const pointStructure & pStruct_
Definition: pointField.hpp:65
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::Field< T, T, void >::VectorType
T< T, void > VectorType
Definition: Field.hpp:40
pFlow::pointField::pointFlag
const auto & pointFlag() const
Definition: pointField.hpp:133
pFlow::Field< T, T, void >::reference
typename VectorType::reference reference
Definition: Field.hpp:48
error.hpp