www.cemf.ir
pointField.cpp
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 template<class T, class MemorySpace>
22 (
23  const objectFile& objf,
25  const T& defVal
26 )
27 :
28  IOobject
29  (
30  objf,
31  pStruct.ioPattern(),
32  pStruct.owner()
33  ),
35  (
36  objf.name(),
37  pStruct,
38  defVal
39  ),
40  boundaryFieldList_(pStruct.boundaries(), *this),
41  pStruct_(pStruct)
42 {
43 
44  if(IOobject::implyRead())
45  {
46  REPORT(1)<< "Reading field "<< Green_Text(IOobject::name())<<
47  " from "<<IOobject::path()<<END_REPORT;
48  }
49  else
50  {
51  REPORT(1)<< "Creating field "<< Green_Text(IOobject::name())<<END_REPORT;
52  }
53  if( !IOobject::readObject() )
54  {
56  "Error in reading from file "<<IOobject::path()<<endl;
57  fatalExit;
58  }
59 
60 }
61 
62 template<class T, class MemorySpace>
64 (
65  const objectFile& objf,
66  repository* owner,
68  const T& defVal
69 )
70 :
71  IOobject
72  (
73  objf,
74  pStruct.ioPattern(),
75  owner
76  ),
78  (
79  objf.name(),
80  pStruct,
81  defVal
82  ),
83  boundaryFieldList_(pStruct.boundaries(), *this),
84  pStruct_(pStruct)
85 {
86  if(IOobject::implyRead())
87  {
88  REPORT(1)<< "Reading field "<< Green_Text(IOobject::name())<<
89  " from "<<IOobject::path()<<END_REPORT;
90  }
91  else
92  {
93  REPORT(1)<< "Creating field "<< Green_Text(IOobject::name())<<END_REPORT;
94  }
95  if( !IOobject::readObject() )
96  {
98  "Error in reading from file "<<IOobject::path()<<endl;
99  fatalExit;
100  }
101 }
102 
103 template<class T, class MemorySpace>
105 (
106  const objectFile &objf,
108  const T& defVal,
109  const T& val
110 )
111 :
112  IOobject
113  (
114  objectFile
115  (
116  objf.name(),
117  objf.localPath(),
118  objectFile::READ_NEVER,
119  objf.wFlag()
120  ),
121  pStruct.ioPattern(),
122  pStruct.owner()
123  ),
125  (
126  objf.name(),
127  pStruct,
128  defVal,
129  val
130  ),
131  boundaryFieldList_(pStruct.boundaries(), *this),
132  pStruct_(pStruct)
133 {
134 
135 }
136 
137 
138  /*
139 
140 
141 
142  template<class T, class MemorySpace>
143  pFlow::pointField<T, MemorySpace>::pointField
144  (
145  const pointStructure& pStruct,
146  const T& defVal,
147  bool subscribe
148  )
149  :
150  eventObserver(pStruct, subscribe),
151  FieldType(pStruct.capacity(), pStruct.size(), RESERVE()),
152  pStruct_(pStruct),
153  defaultValue_(defVal)
154  {
155  // set value
156  this->fill(defVal);
157  }
158 
159  template<class T, class MemorySpace>
160  pFlow::pointField<T, MemorySpace>::pointField
161  (
162  const pointStructure& pStruct,
163  const T& val,
164  const T& defVal,
165  bool subscribe
166  )
167  :
168  eventObserver(pStruct, subscribe),
169  FieldType(pStruct.capacity(), pStruct.size(), RESERVE()),
170  pStruct_(pStruct),
171  defaultValue_(defVal)
172  {
173  this->fill(val);
174  }
175 
176  template<class T, class MemorySpace>
177  pFlow::pointField<T, MemorySpace>::pointField
178  (
179  const pointField& src,
180  bool subscribe
181  )
182  :
183  eventObserver(src.pStruct(), subscribe),
184  FieldType(src),
185  pStruct_(src.pStruct()),
186  defaultValue_(src.defaultValue_)
187  {}
188 
189  template<class T, class MemorySpace>
190  pFlow::pointField<T, MemorySpace>::pointField(const pointField& src)
191  :
192  pointField<T, MemorySpace>(src, src.subscribed())
193  {}
194 
195 
196  template<class T, class MemorySpace>
197  pFlow::pointField<T, MemorySpace>& pFlow::pointField<T, MemorySpace>::operator =
198  (
199  const pointField& rhs
200  )
201  {
202  if(this == &rhs) return *this;
203 
204  this->VectorField() = rhs.VectorField();
205  return *this;
206  }
207 
208 
209  template<class T, class MemorySpace>
210  bool pFlow::pointField<T, MemorySpace>::update(const eventMessage& msg)
211  {
212 
213  if( msg.isDeleted() )
214  {
215 
216  }
217  else if( msg.isInsert())
218  {
219  const auto newElems = pStruct().insertedPointIndex();
220  //Vector<T> vals( newElems.size(), defaultValue_);
221  return this->insertSetElement(newElems, defaultValue_);
222  }
223 
224  if(msg.isRearranged())
225  {
226  auto sortedIndex = pStruct().mortonSortedIndex();
227  this->sortItems(sortedIndex);
228  return true;
229  }
230 
231  return true;
232  }*/
233 
234 template <class T, class MemorySpace>
236 (
237  iIstream &is,
238  const IOPattern &iop
239 )
240 {
241  typename InternalFieldType::FieldTypeHost fRead
242  (
243  InternalFieldType::name(),
244  InternalFieldType::fieldKey()
245  );
246 
247  if( !fRead.read(is, iop))
248  {
250  "Error in reading pointPosition from stream "<< is.name()<<endl;
251  return false;
252  }
253 
254  auto thisN = pStruct_.simDomain().initialNumberInThis();
255 
256  typename InternalFieldType::FieldTypeHost internal
257  (
258  InternalFieldType::name(),
259  InternalFieldType::fieldKey(),
260  thisN,
261  thisN,
262  RESERVE()
263  );
264 
265  auto pSpan = fRead.getSpan();
266  auto iSpan = internal.getSpan();
267 
268  if(!pStruct_.simDomain().initialTransferBlockData(pSpan, iSpan))
269  {
271  "Error in transfering the block data for field "<<
272  InternalFieldType::name()<<endl;
273  return false;
274  }
275 
276  this->field_.assignFromHost(internal);
277 
278  return true;
279 }
280 
281 template<class T, class MemorySpace>
283 (
284  iOstream& os,
285  const IOPattern& iop
286 )const
287 {
288  return InternalFieldType::write(os, iop);
289 }
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::Field::read
bool read(iIstream &is)
Definition: Field.cpp:23
pFlow::pointField::pointField
pointField(const objectFile &objf, pointStructure &pStruct, const T &defVal)
Definition: pointField.cpp:22
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::Field
Definition: Field.hpp:36
pFlow::IOobject
Definition: IOobject.hpp:35
RESERVE
Definition: Vector.hpp:40
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::pointField::writePointField
bool writePointField(iOstream &os, const IOPattern &iop) const
Definition: pointField.cpp:283
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::VectorSingle::getSpan
INLINE_FUNCTION_H auto getSpan()
Definition: VectorSingle.cpp:569
pFlow::objectFile::name
virtual const word & name() const
Definition: objectFile.hpp:101
pFlow::IOPattern
Definition: IOPattern.hpp:32
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::internalField< pFlow::VectorSingle, pFlow::AB3History >
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::pointField::readPointField
bool readPointField(iIstream &is, const IOPattern &iop)
Definition: pointField.cpp:236
pFlow::objectFile::localPath
virtual const fileSystem & localPath() const
Definition: objectFile.hpp:107
pFlow::repository
Definition: repository.hpp:34
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::objectFile::wFlag
writeFlag wFlag() const
Definition: objectFile.hpp:119