www.cemf.ir
iBox.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 
22 template<typename intType>
25 :
26  min_(0),
27  max_(1)
28 {}
29 
30 
31 template<typename intType>
34  const triple<intType>& minP,
35  const triple<intType>& maxP)
36 :
37  min_(minP),
38  max_(maxP)
39 {}
40 
41 template<typename intType>
44 (
45  const dictionary & dict
46 )
47 :
48  min_
49  (
50  dict.getVal<triple<intType>>("min")
51  ),
52  max_
53  (
54  dict.getVal<triple<intType>>("max")
55  )
56 {}
57 
58 template<typename intType>
61 (
62  iIstream& is
63 )
64 {
65  if( !read(is))
66  {
67  ioErrorInFile(is.name(), is.lineNumber())<<
68  "error in reading iBox from file. \n";
69  fatalExit;
70  }
71 }
72 
73 template<typename intType>
76 (
77  const triple<intType>& point
78 )const
79 {
80  return point >= min_ && point <= max_;
81 }
82 
83 template<typename intType>
86 {
87  if(!is.nextData<triple<intType>>("min", min_)) return false;
88  if(!is.nextData<triple<intType>>("max", max_)) return false;
89  return true;
90 }
91 
92 template<typename intType>
95 {
96  os.writeWordEntry("min", min_);
97  os.writeWordEntry("max", max_);
98  return os.check(FUNCTION_NAME);
99 }
100 
101 template<typename intType>
104 (
105  const dictionary& dict
106 )
107 {
108  min_ = dict.getVal<triple<intType>>("min");
109  max_ = dict.getVal<triple<intType>>("max");
110  return true;
111 }
112 
113 template<typename intType>
116 (
117  dictionary& dict
118 )const
119 {
120  if(!dict.add("min", min_))
121  {
123  " error in writing min to dictionary "<<dict.globalName()<<endl;
124  return false;
125  }
126 
127  if(!dict.add("max", max_))
128  {
130  " error in writing max to dictionary "<<dict.globalName()<<endl;
131  return false;
132  }
133 
134  return true;
135 }
136 
137 template<typename intType>
140 {
141  if(! b.read(is))
142  {
143  ioErrorInFile(is.name(), is.lineNumber())<<
144  "error in reading iBox. \n";
145  fatalExit;
146  }
147  return is;
148 }
149 
150 template<typename intType>
152 pFlow::iOstream& pFlow::operator << (iOstream& os, const iBox<intType>& b)
153 {
154 
155  if(! b.write(os))
156  {
157  ioErrorInFile(os.name(), os.lineNumber())<<
158  "error in writing iBox. \n";
159  fatalExit;
160  }
161  return os;
162 }
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::iBox::isInside
INLINE_FUNCTION_HD bool isInside(const triple< intType > &point) const
Definition: iBox.cpp:76
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
add a float dataEntry
Definition: dictionary.cpp:435
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::iBox::iBox
INLINE_FUNCTION_HD iBox()
Definition: iBox.cpp:24
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:62
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::iIstream::nextData
bool nextData(const word &keyword, T &data)
read the data next to keword keyword data; check the keyword is correct or not
Definition: iIstreamI.hpp:81
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::iBox::write
FUNCTION_H bool write(iOstream &os) const
Definition: iBox.cpp:94
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
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::iBox
Definition: iBox.hpp:33
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple< intType >
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::iOstream::writeWordEntry
iOstream & writeWordEntry(const word &key, const T &value)
Write a keyword/value entry.
Definition: iOstream.hpp:239
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67
pFlow::iBox::read
FUNCTION_H bool read(iIstream &is)
Definition: iBox.cpp:85