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<template<class, class> class VectorField, class T, class PropType>
23 (
24  iIstream& is,
25  size_t len,
26  bool readLength
27 )
28 {
29  size_t flen = 0;
30  if( readLength )
31  {
32  is>>flen;
33 
34  if(is.bad() || is.eof() )
35  {
36  ioErrorInFile( is.name(), is.lineNumber() ) <<
37  "expected integer value to specify field length \n";
38  return false;
39  }
40  }
41  else
42  {
43  flen = len;
44  }
45 
46  // create a vector with one element and read it in
47  T bF;
48 
49  is >> bF;
50 
51  VectorType::assign(flen, bF);
52 
53  // read end statement char ;
54  is.readEndStatement("readField");
55 
56  return true;
57 }
58 
59 
60 template<template<class, class> class VectorField, class T, class PropType>
62 (
63  iIstream& is,
64  size_t len
65 )
66 {
67  size_t flen = 0;
68 
69 
70  is >> flen;
71  if(is.bad() || is.eof() )
72  {
73  ioErrorInFile( is.name(), is.lineNumber() ) <<
74  " expected integer value to specify field length \n";
75  return false;
76  }
77 
78  if( len!=0 && flen != len )
79  {
80  ioErrorInFile( is.name(), is.lineNumber() ) <<
81  " expected "<< len <<" as the field length but found "<< flen <<" \n";
82  return false;
83  }
84 
85  this->clear();
86  VectorType::read(is);
87 
88  is.readEndStatement("readField");
89 
90  if( this->size() != flen )
91  {
92  ioErrorInFile( is.name(), is.lineNumber() ) <<
93  " expected " << flen << " elements, but supplied "<<
94  this->size() << " elements in file "<< is.name() <<endl;
95  return false;
96  }
97 
98  return true;
99 }
100 
101 
102 template<template<class, class> class VectorField, class T, class PropType>
104 (
105  iIstream& is,
106  const size_t len,
107  bool readLength
108 )
109 {
110  if( !is.findToken(fieldKey_) )
111  {
112  ioErrorInFile( is.name(), is.lineNumber() ) <<
113  " error in searching for filedkey " << fieldKey_<<endl;
114  return false;
115  }
116 
117  word fieldU;
118 
119  is >> fieldU;
120 
121  if(is.bad() || is.eof())
122  {
123  ioErrorInFile( is.name(), is.lineNumber()) <<
124  " error in reading keyword from file.";
125  return false;
126  }
127 
128  if( fieldU == uniform__ )
129  {
130 
131  return readUniform(is, len, readLength);
132 
133  }
134  else if( fieldU == nonUniform__ )
135  {
136 
137  return readNonUniform(is, len);
138 
139  }
140  else
141  {
142  ioErrorInFile( is.name(), is.lineNumber() ) <<
143  "unknown keyword, expected uniform/nonUniform, but found " <<
144  fieldU << endl;
145  return false;
146  }
147 
148  return true;
149 }
150 
151 
152 template<template<class, class> class VectorField, class T, class PropType>
154 (
155  iIstream& is
156 )
157 {
158  return readField(is, 0, true);
159 }
160 
161 
162 template<template<class, class> class VectorField, class T, class PropType>
164 {
165  os.writeWordKeyword(fieldKey_) << nonUniform__<<endl;
166  os<< this->size()<<endl;
167  VectorType::write(os);
168  os.endEntry();
169  return true;
170 }
pFlow::IOstream::eof
bool eof() const
Definition: IOstream.hpp:156
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
Definition: iIstream.cpp:324
pFlow::uniform__
const char * uniform__
Definition: vocabs.hpp:52
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::nonUniform__
const char * nonUniform__
Definition: vocabs.hpp:53
pFlow::Field::readNonUniform
bool readNonUniform(iIstream &is, size_t len)
Definition: Field.cpp:62
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::IOstream::bad
bool bad() const
Definition: IOstream.hpp:168
pFlow::iOstream::endEntry
virtual iOstream & endEntry()
Definition: iOstream.cpp:97
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::Field::readField
bool readField(iIstream &is, const size_t len, bool readLength=true)
Definition: Field.cpp:104
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::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
Definition: iIstream.cpp:60
pFlow::Field::writeField
bool writeField(iOstream &os) const
Definition: Field.cpp:163
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::iOstream::writeWordKeyword
virtual iOstream & writeWordKeyword(const word &kw)
Definition: iOstream.cpp:41