www.cemf.ir
line.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 #include "line.hpp"
23 #include "dictionary.hpp"
24 
25 
28 (
29  const realx3 &lp1,
30  const realx3 &lp2
31 )
32 {
33  set(lp1, lp2);
34 }
35 
38 (
39  const dictionary& dict
40 )
41 {
42  if(!read(dict))
43  {
44  fatalExit;
45  }
46 }
47 
50 (
51  const dictionary& dict
52 )
53 {
54  realx3 p1 = dict.getVal<realx3>("p1");
55  realx3 p2 = dict.getVal<realx3>("p2");
56  set(p1, p2);
57  return true;
58 }
59 
61 bool pFlow::line::write(dictionary& dict) const
62 {
63  if(!dict.add("p1", point1()))
64  {
66  " error in writing p1 to dictionary " << dict.globalName()<<endl;
67  return false;
68  }
69 
70  if(!dict.add("p2", point2()))
71  {
73  " error in writing p2 to dictionary " << dict.globalName()<<endl;
74  return false;
75  }
76 
77  return true;
78 }
79 
82 (
83  iIstream& is
84 )
85 {
86  word p1w;
87  realx3 p1;
88  is >> p1w >> p1;
89  if( !is.check(FUNCTION_NAME))
90  {
91  ioErrorInFile(is.name(), is.lineNumber());
92  return false;
93  }
94  if(p1w != "p1")
95  {
96  ioErrorInFile(is.name(), is.lineNumber())<<
97  " expected p1 but found "<< p1w<<endl;
98  return false;
99  }
101 
102  word p2w;
103  realx3 p2;
104  is >> p2w >> p2;
105 
106  if( !is.check(FUNCTION_NAME))
107  {
108  ioErrorInFile(is.name(), is.lineNumber());
109  return false;
110  }
111  if(p2w != "p2")
112  {
113  ioErrorInFile(is.name(), is.lineNumber())<<
114  " expected p2 but found "<< p2w<<endl;
115  return false;
116  }
118  set(p1,p2);
119  return true;
120 }
121 
124 (
125  iOstream& os
126 )const
127 {
128  os.writeWordEntry("p1", point1());
129  os.writeWordEntry("p2", point2());
130  return os.check(FUNCTION_NAME);
131 }
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::line::write
FUNCTION_H bool write(dictionary &ditc) const
Definition: line.cpp:61
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::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::line::line
FUNCTION_HD line()
Definition: line.hpp:52
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::line::read
FUNCTION_H bool read(const dictionary &dict)
Definition: line.cpp:50
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::line::point2
INLINE_FUNCTION_HD realx3 point2() const
Definition: line.hpp:98
dictionary.hpp
FUNCTION_HD
#define FUNCTION_HD
Definition: pFlowMacros.hpp:61
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
pFlow::line::point1
INLINE_FUNCTION_HD realx3 point1() const
Definition: line.hpp:94
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::triple< real >
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
line.hpp
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