www.cemf.ir
Field.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 
21 template<class T, class MemorySpace>
23 (
24  iIstream& is
25 )
26 {
27 
28  bool tokenFound = true;
29 
30  tokenFound = is.findToken(fieldKey_);
31 
32  if( !tokenFound )
33  {
34  ioErrorInFile( is.name(), is.lineNumber() ) <<
35  " error in searching for filedkey " << fieldKey_<<endl;
36  return false;
37  }
38 
39  if( !VectorType::read(is) )
40  {
41  ioErrorInFile(is.name(), is.lineNumber())<<
42  "error in reading field data from field "<< this->name()<<endl;
43  return false;
44  }
45 
46  is.readEndStatement("Field::read");
47 
48  return true;
49 }
50 
51 
52 template<class T, class MemorySpace>
54 (
55  iIstream& is,
56  const IOPattern& iop,
57  bool resume
58 )
59 {
60 
61  bool tokenFound = true;
62  if(resume)
63  {
64  if(iop.thisProcReadData())
65  tokenFound = is.findTokenResume(fieldKey_);
66  }
67  else
68  {
69  if(iop.thisProcReadData())
70  tokenFound = is.findToken(fieldKey_);
71  }
72 
73  if( !tokenFound )
74  {
75  ioErrorInFile( is.name(), is.lineNumber() ) <<
76  " error in searching for filedkey " << fieldKey_<<endl;
77  return false;
78  }
79 
80  if( !VectorType::read(is, iop) )
81  {
82  ioErrorInFile(is.name(), is.lineNumber())<<
83  "error in reading field data from field "<< this->name()<<endl;
84  return false;
85  }
86 
87  if(iop.thisProcReadData())
88  is.readEndStatement("Field::read");
89 
90  return true;
91 }
92 
93 template<class T, class MemorySpace>
95 (
96  iOstream& os
97 )const
98 {
99 
100  os.writeWordKeyword(fieldKey_)<<endl;
101 
102  if(!os.check(FUNCTION_NAME))return false;
103 
104  if(!VectorType::write(os)) return false;
105 
106  os.endEntry();
107  if(!os.check(FUNCTION_NAME))return false;
108 
109  return true;
110 }
111 
112 
113 
114 template<class T, class MemorySpace>
116 (
117  iOstream& os,
118  const IOPattern& iop
119 )const
120 {
121 
122  if(iop.thisProcWriteData())
123  os.writeWordKeyword(fieldKey_)<<endl;
124 
125  if(!os.check(FUNCTION_NAME))return false;
126 
127  if(!VectorType::write(os, iop)) return false;
128 
129  if(iop.thisProcWriteData())
130  {
131  os.endEntry();
132  os.newLine();
133  }
134 
135  if(!os.check(FUNCTION_NAME))return false;
136 
137  return true;
138 }
139 
140 
141 
142 
143 /*template<template<class, class> class VectorField, class T, class PropType>
144 bool pFlow::Field<VectorField, T, PropType>::readUniform
145 (
146  iIstream& is,
147  size_t len,
148  bool readLength
149 )
150 {
151  size_t flen = 0;
152  if( readLength )
153  {
154  is>>flen;
155 
156  if(is.bad() || is.eof() )
157  {
158  ioErrorInFile( is.name(), is.lineNumber() ) <<
159  "expected integer value to specify field length \n";
160  return false;
161  }
162  }
163  else
164  {
165  flen = len;
166  }
167 
168  // create a vector with one element and read it in
169  T bF;
170 
171  is >> bF;
172 
173  VectorType::assign(flen, bF);
174 
175  // read end statement char ;
176  is.readEndStatement("readField");
177 
178  return true;
179 }
180 
181 
182 template<template<class, class> class VectorField, class T, class PropType>
183 bool pFlow::Field<VectorField, T, PropType>::readNonUniform
184 (
185  iIstream& is,
186  size_t len
187 )
188 {
189  size_t flen = 0;
190 
191 
192  is >> flen;
193  if(is.bad() || is.eof() )
194  {
195  ioErrorInFile( is.name(), is.lineNumber() ) <<
196  " expected integer value to specify field length \n";
197  return false;
198  }
199 
200  if( len!=0 && flen != len )
201  {
202  ioErrorInFile( is.name(), is.lineNumber() ) <<
203  " expected "<< len <<" as the field length but found "<< flen <<" \n";
204  return false;
205  }
206 
207  VectorType::readVector(is, flen);
208  is.readEndStatement("readField");
209  if( this->size() != flen )
210  {
211  ioErrorInFile( is.name(), is.lineNumber() ) <<
212  " expected " << flen << " elements, but supplied "<<
213  this->size() << " elements in file "<< is.name() <<endl;
214  return false;
215  }
216 
217 
218  return true;
219 }*/
220 
221 
222 /*template<template<class, class> class VectorField, class T, class PropType>
223 bool pFlow::Field<VectorField, T, PropType>::readField
224 (
225  iIstream& is,
226  const size_t len,
227  bool resume,
228  bool readLength
229 )
230 {
231 
232  bool tokenFound;
233  if( resume )
234  tokenFound = is.findTokenResume(fieldKey_);
235  else
236  tokenFound = is.findToken(fieldKey_);
237 
238  if( !tokenFound )
239  {
240  ioErrorInFile( is.name(), is.lineNumber() ) <<
241  " error in searching for filedkey " << fieldKey_<<endl;
242  return false;
243  }
244 
245  word fieldU;
246 
247  is >> fieldU;
248 
249  if(is.bad() || is.eof())
250  {
251  ioErrorInFile( is.name(), is.lineNumber()) <<
252  " error in reading keyword from file.";
253  return false;
254  }
255 
256  if( fieldU == uniform__ )
257  {
258 
259  return readUniform(is, len, readLength);
260 
261  }
262  else if( fieldU == nonUniform__ )
263  {
264 
265  return readNonUniform(is, len);
266 
267  }
268  else
269  {
270  ioErrorInFile( is.name(), is.lineNumber() ) <<
271  "unknown keyword, expected uniform/nonUniform, but found " <<
272  fieldU << endl;
273  return false;
274  }
275 
276  return true;
277 }
278 
279 
280 template<template<class, class> class VectorField, class T, class PropType>
281 bool pFlow::Field<VectorField, T, PropType>::readField
282 (
283  iIstream& is,
284  bool resume
285 )
286 {
287  return readField(is, 0, resume ,true);
288 }
289 
290 
291 template<template<class, class> class VectorField, class T, class PropType>
292 bool pFlow::Field<VectorField, T, PropType>::writeField(iOstream& os)const
293 {
294 
295  os.writeWordKeyword(fieldKey_) << nonUniform__<<endl;
296  os<< this->size()<<endl;
297 
298  VectorType::write(os);
299 
300  os.endEntry();
301 
302  return true;
303 }*/
pFlow::iOstream::newLine
virtual iOstream & newLine()
Write a newLine to stream.
Definition: iOstream.cpp:112
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
End statement character ;.
Definition: iIstream.cpp:359
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::Field::read
bool read(iIstream &is)
Definition: Field.cpp:23
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
pFlow::iIstream::findTokenResume
virtual bool findTokenResume(const word &w)
search for all tokesn after the current file position and find the first word token tbat matchs w
Definition: iIstream.cpp:90
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::IOPattern
Definition: IOPattern.hpp:32
pFlow::iOstream::endEntry
virtual iOstream & endEntry()
Write end entry (';') followed by newline.
Definition: iOstream.cpp:104
pFlow::IOPattern::thisProcReadData
bool thisProcReadData() const
Definition: IOPattern.hpp:138
pFlow::IOPattern::thisProcWriteData
bool thisProcWriteData() const
Definition: IOPattern.hpp:146
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
search for all tokesn and find the first word token tbat matchs w
Definition: iIstream.cpp:84
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::iOstream::writeWordKeyword
virtual iOstream & writeWordKeyword(const word &kw)
Write the keyword followed by an appropriate indentation.
Definition: iOstream.cpp:48